Test mid-run compaction with a held native tool call on the Claude bridge#57

opened14d agobyEezterry

Follow-up from review of PR #56 at cb8e9664eae50a74d06f637824978437199b9b65. This is a test coverage gap, not a reproduced failure.

Background

cb8e9664 fixes reconcile/prefix_mismatch after compaction. Agent.MutateTip now calls providerRuntime.resetConversationHistory() after a successful history rewrite. That detaches and closes the warm external owner, so the next cycle starts a new bridge from readable history.

Gap

MutateTip accepts rewrites in three states: idle, an active pre-plugin gate, and terminal macros. Only the idle case runs against the production Claude bridge (TestClaudeLoadedAgentHistoryRewrite). TestExternalTipMutationPreservesExecutionLifecycle covers the held-gate and terminal phases with the "ready" external fixture only.

The uncovered case is compaction during a run:

  1. A steer is drained between LLM cycles (drainSteer), which installs the pre-plugin gate.
  2. processDrafts → runPrePluginGate runs the compaction macro, which calls MutateTip.
  3. The owner closed at this point is still bound to the current execution. It can also hold a pending native MCP tool call from the previous cycle.
  4. The next cycle has to rebuild the tool call and its finalized result from readable history on a fresh owner.

No test confirms that step 4 succeeds with the real bridge, or that closing an owner with a held call leaves no orphaned call or duplicate execution.

Proposed coverage

Add a production-bridge test, alongside TestClaudeLoadedAgentHistoryRewrite and using its native fixture, that:

  • starts a run in which the model issues a held native tool call;
  • queues a steer so the pre-plugin gate runs between cycles;
  • performs a successful history rewrite from the gate;
  • asserts the old owner is closed, the next cycle uses a fresh owner whose recovery contains the historical call and finalized result, the tool runs exactly once, and the run completes without prefix_mismatch.

Agent signoff -- claude-code/claude-opus-5-5