Skip to content

feat(engine): ask-correlation surface — PendingAsk.Call (#148) + host-supplied reconstructable askID (ADR-0044, #117) - #149

Merged
JAORMX merged 2 commits into
mainfrom
feat/askid-correlation-148-117
Jun 22, 2026
Merged

JAORMX merged 2 commits into
mainfrom
feat/askid-correlation-148-117

Conversation

@JAORMX

@JAORMX JAORMX commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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 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 (strings.Split(askID, ":")[2], which 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). The EvPermissionRetract sites are left untouched (AskID-only by contract).
  • Opaque correlation data already implicitly inside the askID → no new leak surface (gauntlet ACP: accept client-provided streaming-HTTP MCP servers #7).
  • Carries a normal json tag (json:"call,omitempty") and round-trips in the sessnap snapshot (durable correlation data, unlike the run-scoped ConfiguredAsk/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 trailing r<serial> is not — runSerial is a process-global atomic.Int64 reset 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 own resumeAskID and 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 in startRun onto Run.askDiscriminator; newAskID consumes the resolved value. Empty preserves the r<serial> fallback — no behaviour change.

Hard constraints (in the ADR, pinned by tests):

  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 ADR-0044 §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.

Same opt-in RunOptions seam pattern as MaxRunTokensOverride/ExtraTools. Unblocks stacklok/atrium#581 (pass the durable RunID, drop resumeAskID + the grammar parse).

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).

Tests

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}.txt regenerated; both additions are Added = minor per COMPATIBILITY.md; engine/CHANGELOG.md [Unreleased] → Added carries both; llms.txt regenerated.

Each commit builds and tests green independently.

🤖 Generated with Claude Code

JAORMX and others added 2 commits June 22, 2026 19:48
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
@JAORMX
JAORMX merged commit 9ceade9 into main Jun 22, 2026
12 checks passed
@JAORMX
JAORMX deleted the feat/askid-correlation-148-117 branch June 22, 2026 20:16
@JAORMX

JAORMX commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Post-merge review — verdict: correct fix, would have approved

Reviewing 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 — PendingAsk.Call

  • Populated at the main mint site (engine/agent/dispatch.go, in authorize — Call: c.ID) and the surfaced-child site (in parentCaps — Call: ask.Call, propagated from the child engine's own authorize). Both paths, as required.
  • Round-trips in the snapshot — sessnap_test.go TestRoundTripAwaitingPreservesPendingAsk sets Call and asserts it survives.
  • The retract sites (childregistry.go:731,807) are correctly left alone — childregistry.go isn't in the diff.

#117 — RunOptions.AskIDDiscriminator

  • Opt-in, resolved once in startRun (loop.go): host value when non-empty and colon-free, else fmt.Sprintf("r%d", serial). Empty reproduces today's r<serial> byte-for-byte, so mecatui / tests / in-memory hosts are untouched.
  • newAskID reads the resolved r.askDiscriminator, and the field doc-comment carries a "FOOTGUN GUARD" steering future callers away from the raw, un-validated r.opts.AskIDDiscriminator. Nice.
  • The <sessionID>: prefix is preserved (suffix-only change); cmd/mecatui isChildAsk and its comment are updated in lockstep.

The two judgment calls are both right:

  • Colon handling ignores the value and falls back with a WARN rather than stripping it — stripping could collapse two distinct host ids onto one askID and re-open the replay collision. Correct, and TestRunOptionsAskIDDiscriminatorColonFallsBack even asserts the WARN fires.
  • The CWE-863 contract is documented as unique-per-attempt AND stable-per-attempt, with the per-session-stable trap called out explicitly (a per-session value would re-mint an identical askID after cancel-then-resume). That subtlety is exactly the thing a host adopting this would get wrong.

Bonus beyond the brief: corrected the stale callIDFromAskID claim across the docs (approval-replay correlates via the structured ApprovalPayload.Call, not a grammar parse) and tied the new request-half field to the existing verdict-half correlation.

Gates present: ADR-0044, named enforcement tests, engine/api/*.txt snapshots, CHANGELOG. Released in engine/v0.1.0.

Atrium adoption now unblocked — stacklok/atrium#581: bump the pin v0.0.3 → v0.1.0, pass the durable RunID as the discriminator, and drop both resumeAskID and the gatedToolCallID grammar parse.

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.

Expose the gated tool-call id on session.PendingAsk

1 participant