Repository navigation
feat(engine): ask-correlation surface — PendingAsk.Call (#148) + host-supplied reconstructable askID (ADR-0044, #117) - #149
Conversation
Add `session.PendingAsk.Call (ToolCallID)`, the opaque gated tool-call id on the ask REQUEST half — the symmetric twin of `session.ApprovalPayload.Call` on the verdict half. A host that pauses on a `PendingAsk` now reads `Call` to correlate the ask back to its tool call, instead of parsing the askID grammar (the brittle `strings.Split(askID, ":")[2]` the engine treats as partly internal). Populated at both surfaced-ask mint sites in `engine/agent/dispatch.go`: the main `authorize` path (`Call: c.ID`) and the surfaced child/subagent path (`Call: ask.Call`, propagated from the child engine's own authorize). The EvPermissionRetract sites are left untouched (they carry AskID only by contract). The field is opaque correlation data — already implicitly encoded inside the askID — so surfacing it opens no new leak surface (gauntlet #7). It is durable correlation data, so it carries a normal json tag (`json:"call,omitempty"`) and round-trips in the sessnap snapshot, unlike the run-scoped ConfiguredAsk/FlooredConfiguredAllow. Additive = minor per COMPATIBILITY.md; `engine/api/session.txt` regenerated and a CHANGELOG [Unreleased]→Added entry added. Closes #148. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01KViefejRCc16BnjGSXUuvv
…044, #117) The askID is `<sessionID>:<n>:<callID>:r<serial>`. Three of those four components are reconstructable from persisted session state; the trailing `r<serial>` is not — `runSerial` is a process-global `atomic.Int64` reset on every process start, so a different process (or the same one after a restart) cannot reproduce it. A host with a durable run identity therefore cannot reconstruct the askID for cross-process resume/correlation, which is why Atrium today synthesizes its own `resumeAskID` and parses the grammar by hand (stacklok/atrium#552). Add an opt-in `agent.RunOptions.AskIDDiscriminator string`: when set (non-empty and colon-free) it REPLACES the trailing component, so the askID becomes `<sessionID>:<n>:<callID>:<discriminator>` — fully reconstructable from the host's persisted state. Resolved once in `startRun` onto `Run.askDiscriminator`; `newAskID` consumes the resolved value. Empty preserves the `r<serial>` fallback with no behaviour change (mecatui, tests, in-memory hosts unaffected). Hard constraints (pinned by tests, recorded in ADR-0044): 1. The `<sessionID>:` prefix is preserved — mecatui `isChildAsk` classifies main-vs-subagent on it. 2. The CWE-863 replay guard is preserved by host contract: the discriminator must be unique-per-run-ATTEMPT and stable-across-processes-for-the-same- attempt (a per-session-stable value would re-open the retract/re-mint collision). Documented on the field and in the ADR §Consequences. 3. A colon-containing value is IGNORED (fall back to `r<serial>` with a WARN), never stripped — stripping could collapse two distinct host ids onto one askID and re-open the collision. 4. No behaviour change when unset. This is the same opt-in RunOptions seam pattern as MaxRunTokensOverride/ ExtraTools. It unblocks stacklok/atrium#581 (Atrium passes its durable RunID as the discriminator and drops resumeAskID + the grammar parse). Enforcement tests: TestNewAskIDDiscriminatorReconstructable, TestNewAskIDNoDiscriminatorMatchesSerial, TestNewAskIDDiscriminatorPreservesPrefix, TestRunOptionsAskIDDiscriminatorReplacesSerial, TestRunOptionsAskIDDiscriminatorColonFallsBack, TestAskIDDiscriminatorReconstructableAcrossRuns. Also corrects stale docs (AGENTS.md, IMPLEMENTATION-NOTES.md): approval-replay correlates via the structured `ApprovalPayload.Call` field, not a `callIDFromAskID` grammar parse (that function does not exist). Additive = minor per COMPATIBILITY.md; `engine/api/agent.txt` regenerated, a CHANGELOG [Unreleased]→Added entry added, and `llms.txt` regenerated for the new ADR. Closes #117. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01KViefejRCc16BnjGSXUuvv
Post-merge review — verdict: correct fix, would have approvedReviewing on behalf of the Atrium side (this is the consumer that drove #148/#117). The PR auto-merged before review landed, so this is a post-merge verdict rather than an approval — but for the record, this is the right fix and I would have approved it. It satisfies every constraint from the ADR-0044 direction, and improves on the brief in a few places. #148 —
#117 —
The two judgment calls are both right:
Bonus beyond the brief: corrected the stale Gates present: ADR-0044, named enforcement tests, Atrium adoption now unblocked — stacklok/atrium#581: bump the pin |
Closes #148 and #117. Designs the engine's ask-correlation surface once, under one ADR, as the two issues' latest comments agreed (Atrium adoption is the separate follow-up stacklok/atrium#581).
Two commits, one logical surface:
Commit 1 —
PendingAsk.Call(#148, additive)Adds
session.PendingAsk.Call (ToolCallID)— the opaque gated tool-call id on the ask request half, the symmetric twin ofsession.ApprovalPayload.Callon the verdict half. A host that pauses on aPendingAsknow readsCallto correlate the ask back to its tool call, instead of parsing the askID grammar (strings.Split(askID, ":")[2], which the engine treats as partly internal).engine/agent/dispatch.go: the mainauthorizepath (Call: c.ID) and the surfaced child/subagent path (Call: ask.Call). TheEvPermissionRetractsites are left untouched (AskID-only by contract).json:"call,omitempty") and round-trips in the sessnap snapshot (durable correlation data, unlike the run-scopedConfiguredAsk/FlooredConfiguredAllow).Commit 2 — host-supplied reconstructable askID discriminator (#117, ADR-0044)
The askID is
<sessionID>:<n>:<callID>:r<serial>. Three of those four components are reconstructable from persisted session state; the trailingr<serial>is not —runSerialis a process-globalatomic.Int64reset on every process start, so a different process (or a restart) cannot reproduce it. A host with a durable run identity therefore cannot reconstruct the askID for cross-process resume/correlation (Atrium synthesizes its ownresumeAskIDand parses the grammar today — stacklok/atrium#552).Adds an opt-in
agent.RunOptions.AskIDDiscriminator string: when set (non-empty + colon-free) it replaces the trailing component, making the askID<sessionID>:<n>:<callID>:<discriminator>fully reconstructable from the host's persisted state. Resolved once instartRunontoRun.askDiscriminator;newAskIDconsumes the resolved value. Empty preserves ther<serial>fallback — no behaviour change.Hard constraints (in the ADR, pinned by tests):
<sessionID>:prefix is preserved — mecatuiisChildAskclassifies main-vs-subagent on it.r<serial>with a WARN), never stripped — stripping could collapse two distinct host ids onto one askID and re-open the collision.Same opt-in
RunOptionsseam pattern asMaxRunTokensOverride/ExtraTools. Unblocks stacklok/atrium#581 (pass the durable RunID, dropresumeAskID+ the grammar parse).Also corrects stale docs (
AGENTS.md,IMPLEMENTATION-NOTES.md): approval-replay correlates via the structuredApprovalPayload.Callfield, not acallIDFromAskIDgrammar parse (that function does not exist).Tests
TestPendingAskCarriesGatedCallID(main path, assertsCall == "w1"),TestE2E_SurfacedChildAskCarriesChildGatedCallID(surfaced-child path,"k1"), sessnap round-trip extended to assertCall.TestNewAskIDDiscriminatorReconstructable,TestNewAskIDNoDiscriminatorMatchesSerial,TestNewAskIDDiscriminatorPreservesPrefix(unit),TestRunOptionsAskIDDiscriminatorReplacesSerial(positive e2e),TestRunOptionsAskIDDiscriminatorColonFallsBack(colon fallback + asserts the WARN fired),TestAskIDDiscriminatorReconstructableAcrossRuns(end-to-end: two independent runs over the same session+discriminator mint a byte-identical askID).Gates
task api:check✅ ·task lint✅ (0 issues both modules) ·task test✅ (root + engine + GOWORK=off standalone) ·task docs:check✅ (0 broken links/anchors).engine/api/{session,agent}.txtregenerated; both additions are Added = minor per COMPATIBILITY.md;engine/CHANGELOG.md[Unreleased] → Addedcarries both;llms.txtregenerated.Each commit builds and tests green independently.
🤖 Generated with Claude Code