feat(agent): unprepared scoped ToolHost seam and receipt witness (S18a)

Merged
CO
24d ago
+433-7

Part of #4360. Reworks the first part of #4361.

Stacked on #5004. Merge after PGATE-P0. Review and merge are parent-owned.

Summary

Adds an unprepared ToolHost boundary around the model-issued batch. The host receives raw calls, execution mode and an opaque scope before local name resolution, argument preparation, validation or hooks. The default adapter invokes the existing legacy scheduler.

AgentSession binds the execution root and opaque per-session scope. Pipeline receipts are opt-in through an explicitly configured Agent.onExecutionPipeline sink. Session construction does not install a receipt writer or replace a configured sink. With no sink configured, the default session writes no execution-pipeline entries and retains its existing conversation entry order and tool-result parent links.

The witness reader can project explicitly recorded receipts separately; O7 excludes only witness metadata and follows its parent links without dropping unrelated custom entries. Default sessions do not provide receipt-entry evidence.

The prepared executor and coordinator remain S09/S18b. Nested-call, Cursor and harness bypasses remain S19a/S19b/S19c.

Review HIGH fix

The review at 91225eae118a34eed3759dfc5d65a37b5cda602a identified an unconditional transcript writer in bindPipelineWitness. The default host called that writer before each tool result, inserting a custom entry and changing the result's parent.

Commit f3eb28b869eae568ed66e55b8e29f9a681476481 removes that writer installation at its source. It uses the existing optional Agent callback as the explicit sink rather than adding a session-format option, catching the failure, or filtering it out of the characterization.

4360-pipeline-witness.test.ts now covers both modes using real AgentSession persistence:

  • Default: no witness entry in the branch or persisted session bytes; the tool result points directly to its assistant entry.
  • Configured sink: one legacy witness with the correct tool-call ID is persisted; the sink remains configured.
  • Both: opaque scope remains stable, with no pipeline fields on public messages or events.

The characterization suite and session format were not changed. RED on the reviewed implementation: the default case failed with expected [Function] to be undefined; the configured case passed. The final regression also checks the persisted bytes and parent link.

Acceptance mapping

ObligationEvidence and limits
R10.b, S18a projectionRaw-call seam, agent-loop, real session, nested orchestration, and persistence characterization tests. Phase-level CLI EQ remains blocked below.
R19/F42, seam portionHost receives unprepared calls and scope; sequential/parallel hook order remains covered by the seam and agent-loop suites.
Section 6.3 witness isolationExplicit-sink persistence is covered; default sessions have no witness writes. O7 projection preserves unrelated entries and parent links.
Change-log witness sourcesource: entries requires an explicitly configured sink and an eligible tool call. No default-session witness evidence is claimed.
Z1.GNo default receipt writer, no prepared-pipeline switch, unchanged characterization suite and session format.
Z3.prRoot typecheck, scoped lint/format, and changelog gate. No new dependencies, suppressions, or skipped tests; full knip remains parent-owned.
MA-TBoundary stays above preparation. Full host conformance, mutation and independent review remain parent gates.
C1.bExisting public workspace dependencies only; no private dependency or service added.

Deferred LOWs: next stack PR

Per the parent low-fold ruling, these two review LOWs are not folded into this HIGH fix:

  1. Route explicitly configured witness-write failures through the transcript-failure path rather than aborting the tool batch directly.
  2. Scope root is currently captured once per session; address root freshness in the next stack PR.

Exact-head validation and publication

All eight commands below ran at f3eb28b869eae568ed66e55b8e29f9a681476481 as separate gates in gated-push.sh. Every gate returned 0, followed by GATED_PUSH push rc=0.

GateCommandObserved result
TypesRoot bun check --no-script --all -p tsconfig.jsonNo type errors in 7,676 files
Lintoxlint --deny-warnings on the eight PR TypeScript paths0 warnings, 0 errors
Formatoxfmt --check on the PR TypeScript paths and fragmentAll matched files correctly formatted
AgentFrom packages/agent: bun run test -- test/tool-host-seam.test.ts test/agent-loop.test.ts2 files, 68 tests passed
SessionFrom packages/coding-agent: bun run test -- test/suite/regressions/4360-pipeline-witness.test.ts test/suite/agent-session-tool-orchestration.test.ts2 files, 4 tests passed
CharacterizationFrom packages/coding-agent: bun run test -- test/suite/agent-session-bash-persistence.test.ts1 file, 17 tests passed
Projectionnode --test .agents/skills/senpi-qa/scripts/lib/execution-witness.test.mjs1 passed, 0 failed
ChangelogCHANGELOG_GATE_BASE=889b94d038f3f084ed15d5222b83c229a6bfcad4 node scripts/check-pr-changelog.mjsPASS; all 4 upstream-owned production paths covered

Total: 90 targeted tests passed. The characterization test, session manager and session-format documentation have no changes relative to the reviewed head. The push advanced feat/bh-s18a-toolhost-seam from 91225eae11 to f3eb28b869; no merge was performed.

Test setup required building the existing telemetry and AI workspace exports after the frozen, lifecycle-disabled install. Before that build, the agent tests could not load pi-ai/utils/oauth-refresh-error; after building those dependencies, the targeted runs and exact-head gates passed. No test configuration was changed.

Prior real CLI EQ blocker

The earlier S18a run failed before producing observations: RPC child exited (0) (stderr: ). The same E01 startup failure reproduced on unchanged S08 head 889b94d038f3f084ed15d5222b83c229a6bfcad4 with the documented Node driver and a Bun child. This HIGH fix does not rerun or claim phase-level EQ, and no golden was changed. Prior baseline and candidate receipts are held locally by the parent.

E13 has no tool calls, while Cursor-only E19 belongs to S19b. This PR does not count the existing no-seam fallback as witness evidence.