fix(session): harden tool-call/result replay integrity and subagent dispatch - #1528
Conversation
Sync recent upstream subagent hardening and add Atomic core replay safeguards so persisted context compaction cannot leave orphaned tool results for Anthropic-compatible providers. Refs #1527 Assistant-model: GPT-5.5
Review: fix(subagents): harden tool-result replay (#1528)Thanks for this — the defense-in-depth approach (filter reconciliation → final LLM guard) is the right shape for the Copilot/Anthropic orphan- Potential issue — synthetic
|
Flatten compact delegated tool-call summaries to text so prompt-template delegation responses cannot introduce assistant tool calls without provider-valid paired results. Document the persisted filter reconciliation contract and cover malformed dynamic chain runtime errors. Refs #1527 Assistant-model: GPT-5.5
|
Addressed in
Validation reran locally and via hooks: targeted Bun/Vitest tests, |
Review:
|
…ispatch (#1528) * fix(subagents): harden tool-result replay Sync recent upstream subagent hardening and add Atomic core replay safeguards so persisted context compaction cannot leave orphaned tool results for Anthropic-compatible providers. Refs #1527 Assistant-model: GPT-5.5 * fix(subagents): avoid synthetic orphan tool calls Flatten compact delegated tool-call summaries to text so prompt-template delegation responses cannot introduce assistant tool calls without provider-valid paired results. Document the persisted filter reconciliation contract and cover malformed dynamic chain runtime errors. Refs #1527 Assistant-model: GPT-5.5
Summary
Refs #1527. Prevents orphaned
toolResultmessages from reaching Anthropic/GitHub Copilot providers after context compaction, and hardens subagent dispatch to reject duplicate concurrent calls. The fix spans session-replay reconciliation, LLM serialization guarding, and upstream subagent sync.Changes
Session replay repair (
packages/coding-agent)session-manager-tool-dependencies.ts— reconciles persistedcontext_compactiondeletion filters during active-context rebuild so deleting one side of a tool-call/tool-result pair always deletes or preserves the paired side consistently; converges via a fixpoint loop bounded bypath.length * 2passes.repairOrphanToolResultsinmessages.ts— final LLM serialization guard that drops anytoolResultmessage whose matching assistanttoolCallis no longer the immediately preceding tool-use group, preventing provider replay failures.reconcilePersistedToolDependencyFiltersintobuildEffectiveContextDeletionFiltersinsession-manager-history.ts.compaction.mdupdated to document the tool-call/tool-result pair replay invariant and the two-layer guard strategy.Upstream subagent hardening (
packages/subagents)subagent-executor.tswrapsexecutewithexecuteWithSingleDispatchGuard— rejects concurrent subagent dispatches within the same turn with a clear error;fanout-child.tsandindex.tsinitialize the newsubagentInProgressflag in safe state.subagent-prompt-runtime.tspreserves nested subagent call/result history for fanout children (SUBAGENT_FANOUT_CHILD_ENV=1) and addssubagent-slash-text-resultto the parent-only strip set.subagent-executor-single.tsformats failed foreground run output with the error message, captured child output, and output artifact path for easier debugging.prompt-template-bridge.tsembedstoolCallcontent blocks from delegated run summaries into delegation messages as readable text; fixes a null-safety gap whenagentortaskis missing from a prompt template request.schemas.tsremoves provider-hostileallOfconditionals from the chain step schema.Regression coverage
test/unit/subagents-upstream-sync.test.ts: duplicate dispatch rejection, fanout child history preservation, compact tool-call summary embedding, failed-run output formatting, schema keyword audit, and malformed fanout shape error.test/session-manager/build-context-02.suite.ts: stale compaction split-pair replay cases (block-level and entry-level deletion).packages/coding-agent/test/messages.test.ts: orphantoolResultrepair inconvertToLlm.Validation
bun test test/unit/subagents-upstream-sync.test.ts bunx --bun --no-install vitest --run test/session-manager/build-context-01.suite.ts test/session-manager/build-context-02.suite.ts test/messages.test.ts bun run typecheck bun run check:file-length git diff --checkPre-commit/pre-push hooks:
bun run lint,bun run check:file-length,bun run test:unit