Skip to content

fix(tool-pair-validator): skip placeholder repair for subagent sessions#4032

Merged
code-yeongyu merged 1 commit into
code-yeongyu:devfrom
PeterPonyu:fix/3996-tool-pair-validator-background-sessions
May 15, 2026
Merged

fix(tool-pair-validator): skip placeholder repair for subagent sessions#4032
code-yeongyu merged 1 commit into
code-yeongyu:devfrom
PeterPonyu:fix/3996-tool-pair-validator-background-sessions

Conversation

@PeterPonyu

@PeterPonyu PeterPonyu commented May 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The tool-pair-validator hook inserts a synthetic placeholder tool_result when an assistant message contains an orphan tool_use. This is the right behavior for the main session (compaction can strip tool_results), but it corrupts background sub-agent sessions where the orphan is expected and the synthetic placeholder breaks downstream consumers.
  • Skip the placeholder repair when the transformed message belongs to a tracked subagent session, while keeping the existing main-session repair path intact.

Changes

  • src/hooks/tool-pair-validator/hook.ts: read the session id from the transformed message via a small getMessageSessionID helper; bail out of repairMissingToolResults if the session is tracked in subagentSessions. Import the registry from src/features/claude-code-session-state.
  • src/hooks/tool-pair-validator/hook.test.ts: new regression test asserting that a transformed assistant message owned by a tracked subagent session is left untouched, plus the existing main-session repair coverage stays green.

Rationale (from commit body)

Constraint: #3996 reports background Oracle sessions hanging after synthetic placeholder tool_result insertion.
Rejected alternative: disable tool-pair-validator globally — would regress main-session compaction/orphaned tool_use repair.
Confidence: high
Scope-risk: narrow
Directive: Keep subagent skip coverage and normal repair coverage together when changing tool-pair validation.

Testing

bun test src/hooks/tool-pair-validator/hook.test.ts src/plugin/messages-transform.test.ts
# 12 pass, 0 fail
bun run typecheck
# clean

Not tested end-to-end against a live Oracle background task — that would need a real session reproduction, which I don't have a deterministic setup for. The unit coverage exercises both the subagent-skip path and the main-session repair path.

Related Issues

Closes #3996

Guard the tool-pair validator when transformed assistant messages belong to a tracked subagent session, while keeping normal main-session orphaned tool_use repair intact.

Constraint: code-yeongyu#3996 reports background Oracle sessions hanging after synthetic placeholder tool_result insertion.
Rejected: disable tool-pair-validator globally | would regress main-session compaction/orphaned tool_use repair.
Confidence: high
Scope-risk: narrow
Directive: Keep subagent skip coverage and normal repair coverage together when changing tool-pair validation.
Tested: bun test src/hooks/tool-pair-validator/hook.test.ts src/plugin/messages-transform.test.ts
Tested: bun run typecheck
Not-tested: live Oracle background task e2e; no remote push or PR comment performed.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: The change is narrowly scoped to skip placeholder repair only when the session is a tracked subagent, the new helper and condition are correct, existing tests pass, and a regression test covers both the skip and the unchanged main-session path, so there is no risk of regressions.

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.

[Bug]: tool-pair-validator corrupts background sub-agent sessions by inserting synthetic placeholder tool results

2 participants