Skip to content

refactor(core): share subagent job execution with recovery - #46944

Open
kitlangton wants to merge 2 commits into
v2from
simplify-recovery
Open

refactor(core): share subagent job execution with recovery#46944
kitlangton wants to merge 2 commits into
v2from
simplify-recovery

Conversation

@kitlangton

@kitlangton kitlangton commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Why

Live subagent execution and restart recovery each build their own job and select its final answer differently: the tool reads the latest 20 messages, while recovery scans the current model context. Maintaining both definitions makes restart behavior diverge from the normal path.

Execution also retains a UserInterruptedError variant that production never constructs. User interruption already travels through fiber interruption and the coordinator's explicit reason.

What Changes

  • Both entry points call SubagentJob.start, sharing child resume, job metadata, and result selection.
  • Recovery follows the existing live rule: select the newest completed, non-error assistant message among the latest 20 messages, concatenate only its text parts, and use the shared no-text fallback when needed.
  • Recovered jobs keep their persisted job and notification IDs. Resume failures remain job errors; notification admission and acknowledgment stay with their existing owners.
  • Remove the unused error class, runner error-union member, and classification branches. Actual user/shutdown interruption behavior is unchanged.
flowchart LR
  Tool[Subagent tool] --> Start[SubagentJob.start]
  Restart[Restart recovery] --> Start
  Start --> Job[Job.start]
  Job --> Resume[Session.resume]
  Resume --> Result[Shared result selection]
Loading

Scope

This consolidates subagent job execution and removes one dead interruption path. It does not add leases, change coordinator ownership, or redesign recovery accounting. Child-claim terminal events (#46943) and the claim-column rename (#46945) are separate changes. Land the rename last and reconcile its overlapping child-claim query with #46943.

Verification

cd packages/core
bun run test test/session-execution.test.ts test/tool-subagent.test.ts test/session-run-coordinator.test.ts test/job.test.ts test/session-error.test.ts
bun typecheck

96 tests passed; Core typecheck passed, using the repository-pinned Bun 1.4.0. Result-selection tests exercise live and recovered jobs against real persisted messages, including failed/incomplete candidates, empty output, and a result outside the 20-message window. Existing tests cover interruption, recovery accounting, job lifecycle, and notification deduplication.

The unmodified pre-push typecheck hook also passed: 33 successful tasks, 27 cached. No live provider/server end-to-end run was performed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant