feat(agent): unprepared scoped ToolHost seam and receipt witness (S18a)
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
| Obligation | Evidence and limits |
|---|---|
| R10.b, S18a projection | Raw-call seam, agent-loop, real session, nested orchestration, and persistence characterization tests. Phase-level CLI EQ remains blocked below. |
| R19/F42, seam portion | Host receives unprepared calls and scope; sequential/parallel hook order remains covered by the seam and agent-loop suites. |
| Section 6.3 witness isolation | Explicit-sink persistence is covered; default sessions have no witness writes. O7 projection preserves unrelated entries and parent links. |
| Change-log witness source | source: entries requires an explicitly configured sink and an eligible tool call. No default-session witness evidence is claimed. |
| Z1.G | No default receipt writer, no prepared-pipeline switch, unchanged characterization suite and session format. |
| Z3.pr | Root typecheck, scoped lint/format, and changelog gate. No new dependencies, suppressions, or skipped tests; full knip remains parent-owned. |
| MA-T | Boundary stays above preparation. Full host conformance, mutation and independent review remain parent gates. |
| C1.b | Existing 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:
- Route explicitly configured witness-write failures through the transcript-failure path rather than aborting the tool batch directly.
- 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.
| Gate | Command | Observed result |
|---|---|---|
| Types | Root bun check --no-script --all -p tsconfig.json | No type errors in 7,676 files |
| Lint | oxlint --deny-warnings on the eight PR TypeScript paths | 0 warnings, 0 errors |
| Format | oxfmt --check on the PR TypeScript paths and fragment | All matched files correctly formatted |
| Agent | From packages/agent: bun run test -- test/tool-host-seam.test.ts test/agent-loop.test.ts | 2 files, 68 tests passed |
| Session | From packages/coding-agent: bun run test -- test/suite/regressions/4360-pipeline-witness.test.ts test/suite/agent-session-tool-orchestration.test.ts | 2 files, 4 tests passed |
| Characterization | From packages/coding-agent: bun run test -- test/suite/agent-session-bash-persistence.test.ts | 1 file, 17 tests passed |
| Projection | node --test .agents/skills/senpi-qa/scripts/lib/execution-witness.test.mjs | 1 passed, 0 failed |
| Changelog | CHANGELOG_GATE_BASE=889b94d038f3f084ed15d5222b83c229a6bfcad4 node scripts/check-pr-changelog.mjs | PASS; 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.