Skip to content

refactor(core): share subagent completion delivery - #46054

Merged
kitlangton merged 1 commit into
v2from
completion-delivery
Aug 29, 2026
Merged

kitlangton merged 1 commit into
v2from
completion-delivery

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Why

Live subagent completion and restart recovery independently build the same parent notification, admit it to the Session, and acknowledge the background record. Changes to the message or delivery ordering therefore need to remain synchronized across two implementations.

This is a small behavior-preserving consolidation, not a notification-lifecycle redesign.

What Changes

Both callers use SubagentCompletion.deliver for result formatting, synthetic admission, and acknowledgment. The operation receives only the Session and Job capabilities it needs; it introduces no service, registry, or owned lifetime.

flowchart LR
    Live[Live subagent completion] --> Deliver[SubagentCompletion.deliver]
    Restart[Recovered subagent result] --> Deliver
    Deliver --> Admit[Session.synthetic]
    Admit --> Ack[Job.completeBackground]
Loading
Case Preserved behavior
Completed, failed, or cancelled result Same notification text, fallbacks, metadata, and identity, including empty output strings.
Synthetic admission fails No acknowledgment; the background marker remains.
Recovery sees an already-admitted notification The same notification ID reconciles without another durable completion.
Recovery targets a suspended parent resume: false is selected at delivery time, preserving restart accounting.

Live and recovery callers keep their different preflight checks, assistant-text selection, and missing-session policies. Production changes total +55/-59, including the new 32-line module: four net lines deleted, with one shared delivery implementation.

Scope

Subagent delivery only. Shell completion, manual-shell scheduling, Job persistence, and public contracts are unchanged. Observer ownership remains plugin-scoped, so this does not fix completion loss during plugin replacement or change the direct-SDK lifetime work in #45988.

Verification

# packages/core
bun run test test/job.test.ts test/session-execution.test.ts test/tool-subagent.test.ts
bun typecheck

# repository worktree
bunx prettier --check packages/core/src/session/subagent-completion.ts packages/core/src/session/execution/restart.ts packages/core/src/tool/plugin/subagent.ts packages/core/test/session-execution.test.ts packages/core/test/tool-subagent.test.ts
git diff --check
  • All 57 focused tests pass, with 324 assertions. Core typecheck and formatting pass.
  • The TestLLM-backed regression exercises live completion and then replays its persisted background marker, verifying one durable notification and acknowledgment after admission. It passed five additional repetitions during implementation.
  • A real synthetic-admission identity conflict verifies that failed delivery retains the marker.
  • No full Core suite, live-service testing, plugin-reload lifetime test, or integration run against feat(sdk): add scoped direct Session handles #45988 was performed. Missing-session policies and other unchanged branches were source-compared and retain existing coverage.

@kitlangton
kitlangton enabled auto-merge (squash) August 29, 2026 01:05
@kitlangton
kitlangton merged commit fa5ccac into v2 Aug 29, 2026
14 of 15 checks passed
@kitlangton
kitlangton deleted the completion-delivery branch August 29, 2026 01:20
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
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