Repository navigation
test(mcp): each loop-tool call drains and identity-checks its own audit row — the #2807 case no longer reads its neighbour's (#2952) - #2978
Merged
Conversation
…it row (#2952) The #2807 transport cases awaited the first `run_agent_loop` row past an index sampled at test start. That is a position, not an identity: the previous test never awaited its own fire-and-forget row, so on a busy host its late `success: true` row was the first match and the refusal read as audited-as-success (CI run 35730033664 on PR #2936). Every call through `asAgent().call` now drains the row at its own call index before parsing the envelope, and checks it for tool and session (a per-session bearer the stub echoes back as `key_name`). A loud precondition (rows == calls) makes a change to withAudit's one row per call break this file on purpose. audit.ts is untouched (#2926). Evidence: the stub recording its row 50 ms late reds the dev file (5 tests / 4 pass / 1 fail, 3 of 3 runs; also at 200 ms) and leaves the fixed file 5/5 (3 of 3 at 50 ms, 1 of 1 at 200 ms). A constant key_name reds 5/5 with "row N is not this session's". Unperturbed: npm test 504/504, file alone 10/10. Also registers access-wiring.test.ts in tests/registry.json (it had no row). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…2952) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… case; the sibling's red is timing-dependent (#2952) CI run 35730033664 attempt 1 failed only the refused-loop case (464/465); the fragment claimed the sibling case chained into 'stale refusal' there. Under the 50 ms stub perturbation the original sibling case goes red on either 'first' (a late success row) or 'second' (a refusal row) depending on arrival order — say that instead. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ategory and records its #2952 update (#2952) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…cal, per the merge-train note on the PR Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
vybe
marked this pull request as ready for review
September 23, 2026 09:56
Contributor
|
merge-train: pushed one mechanical commit to this branch — merged |
vybe
approved these changes
Sep 23, 2026
vybe
left a comment
Contributor
There was a problem hiding this comment.
merge-train: validated individually (3-member queue, below train size); all checks green on the rebuilt head incl. MCP Server Tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2952
Problem
src/mcp-server/src/access-wiring.test.tslooked up its audit row as "the firstrun_agent_looprow at an index ≥auditRows.length", sampling that length at the top of the test. The MCP server's audit POST is fire-and-forget (audit.tspostAudit(entry).catch(() => {})), so the client can hold itscallToolresult before the stub has recorded the row. On a busy host, the previous test's late row (a successful self loop) lands after the sample and matches first. CI run 35730033664 attempt 1 failed#2807: a refused loop start is audited as a refusalwiththe refusal was audited as a success: {"tool":"run_agent_loop","duration_ms":1,"success":true}on a PR that touched nothing near the loop tools.Mechanism (test-only)
Every call made through
asAgent().callnow drains its own audit row before returning (call()→{ out, row }), and that row is checked two ways:call. A precondition assertsauditRows.length === callsbefore each call, so the recorder has caught up at every call boundary.${AGENT_KEY}-${name}), and the stub echoes that bearer back askey_name.auditRowAtthen assertsrow.mcp_key_name === keyandrow.details.tool === tool.The drain runs before
JSON.parse. If anisErrortext made the parse throw first, the drain would be skipped and the row would stay in flight for the next call to misread. Both#2807cases, including the deny-then-allow pair on one session, get their rows from their owncalls. Test names and every assertion on the row's contents are unchanged.audit.tsand all other production code are untouched. The diff is one test file, one learnings fragment and onetests/registry.jsonrow.Evidence
the refusal was audited as a success: {"tool":"run_agent_loop",...,"success":true}. Subtest 5 failed with a stale refusal,the permitted call inherited a stale refusal: {...,"denied":true}.first(assert.equal(first.details.denied, true)), deterministically ×3 at 50 ms and at 200 ms.key_namemakes every call fail withrow N is not this session's, so the identity check is live.cd src/mcp-server && npm run build && npm test→ build clean,# tests 504 / # pass 504 / # fail 0. Verified ×4 in the verify stage and re-run at ship.# pass 5 # fail 0).The MCP Server Tests workflow is advisory, not a required check on
dev. The local counts above are the proof.Docs
No requirements / architecture / feature-flow delta — test-only, behaviour-preserving. The audit row's contents and labelling are unchanged; only how the test finds the row changed.
Learnings fragment:
docs/memory/learnings/2026-09-22-await-is-not-identity-for-a-fire-and-forget-recorder.md. Rule: a recorder fed by a fire-and-forget side channel needs position + identity, never position alone.Follow-ups — listed, not filed
postAuditcallingfetchbefore its firstawait. Otherwiseaudit-denial.test.tsloses determinism, since it relies on that undocumented property. refactor(reliability): MCP tools that return a failure are audited as success — withAudit only sees throws #2926 must also account for this file's one-row-per-call precondition: a change towithAudit's row count breaks this file on purpose.🤖 Generated with Claude Code