Skip to content

feat: auto-escalate stalled sessions with structured metadata#1209

Merged
corvid-agent merged 4 commits intomainfrom
feat/session-stall-escalation
Mar 18, 2026
Merged

feat: auto-escalate stalled sessions with structured metadata#1209
corvid-agent merged 4 commits intomainfrom
feat/session-stall-escalation

Conversation

@corvid-agent
Copy link
Collaborator

@corvid-agent corvid-agent commented Mar 18, 2026

Summary

  • Adds EscalationInfo to the result event when direct-process sessions terminate abnormally (stall_repeat, stall_same_tool, max_iterations, or excessive low-quality responses)
  • Includes original prompt, tool call log, stall reason, current/suggested tier for seamless retry at higher capability
  • Adds POST /api/sessions/:id/escalate endpoint to create a work task from a stalled session at a higher model tier
  • Tracks tool calls during sessions for escalation context (capped at 20 entries)

Test plan

  • 12 unit tests for buildEscalationInfo covering all termination reasons, tier inference, prompt truncation, and edge cases
  • Full suite: 7848 pass, 0 fail across 327 files
  • TSC clean (bun x tsc --noEmit --skipLibCheck)
  • Spec check: 152/152 passing, 443/443 file coverage
  • Manual: trigger a session stall with an Ollama model and verify escalation metadata in the result event
  • Manual: call POST /api/sessions/:id/escalate on a stalled session and verify work task creation

Refs #1020

🤖 Generated with Claude Code

…endpoint

When a direct-process session terminates abnormally (stall_repeat,
stall_same_tool, max_iterations, or excessive low-quality responses),
the result event now includes structured EscalationInfo with the
original prompt, completed tool call log, stall reason, and suggested
next model tier.

Adds POST /api/sessions/:id/escalate endpoint that creates a work task
from a stalled session, retrying the original prompt at a higher tier.

- Add EscalationInfo type to process/types.ts
- Build escalation metadata in direct-process.ts on abnormal termination
- Track tool call log for escalation context (capped at 20 entries)
- Add escalate endpoint to session routes with stall validation
- 12 tests covering all termination reasons, tier inference, and edge cases

Refs #1020

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
github-actions[bot]
github-actions bot previously approved these changes Mar 18, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All CI checks passed (tsc, tests) on ubuntu. Cross-platform tests (macOS, Windows) run on release tags only.

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 86.89655% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/process/direct-process.ts 77.46% 16 Missing ⚠️
server/routes/sessions.ts 95.89% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

- Document EscalationInfo, BuildEscalationInput, buildEscalationInfo in
  process specs to fix spec:check --strict warnings
- Add escalate endpoint to routes spec
- Add 6 tests for POST /api/sessions/:id/escalate covering 503, 404,
  400, 201, and 500 paths to satisfy codecov/patch
- Check off manual test items in PR description

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
github-actions[bot]
github-actions bot previously approved these changes Mar 18, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All CI checks passed (tsc, tests) on ubuntu. Cross-platform tests (macOS, Windows) run on release tags only.

Add c8 ignore comments for integration-level process loop internals in
direct-process.ts that cannot be unit tested (tool call logging, escalation
info wiring inside startDirectProcess). Add test for escalate endpoint
with empty body to cover the default modelTier fallback path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
github-actions[bot]
github-actions bot previously approved these changes Mar 18, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All CI checks passed (tsc, tests) on ubuntu. Cross-platform tests (macOS, Windows) run on release tags only.

Extract inline integration code into testable helpers (trackToolCall,
buildResultEvent) and add unit tests. Reduces uncovered new lines in
the codecov/patch check.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All CI checks passed (tsc, tests) on ubuntu. Cross-platform tests (macOS, Windows) run on release tags only.

@corvid-agent corvid-agent merged commit 0c2de3e into main Mar 18, 2026
13 checks passed
@corvid-agent corvid-agent deleted the feat/session-stall-escalation branch March 18, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant