Skip to content

fix(a2a): inbound correlation test fails intermittently on unrelated PRs - #199882

Merged
fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/a2a-inbound-interleaved-order-test
Nov 16, 2026
Merged

fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/a2a-inbound-interleaved-order-test

Conversation

@fuller-stack-dev

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes: the A2A test "correlates interleaved same-context replies from hermes/crew" in extensions/a2a/src/inbound.test.ts fails intermittently on PRs that do not touch A2A, and blocks them from landing.

Seen in CI shard changed-extensions-config-32 (project extension-database-workers, job checks-node-changed-extensions-bundle-31-1):

PR Job Failed case Failed assertion
#198835 133002384788 hermes, crew line 181: got [{text:'second reply'}], wanted [{text:'first reply'}]. Line 175: got ['a2a:crew','a2a:hermes'], wanted ['a2a:hermes','a2a:crew']
#198835, same job rerun 133011401108 crew line 175
#185851 133006876279 hermes line 181

Neither PR changes extensions/a2a.

User Impact

User impact: none for people running OpenClaw. Contributors stop getting this red check on unrelated PRs. A2A reply correlation in production is unchanged, and the evidence below shows it was never wrong.

Why This Change Was Made

The case starts two inbound runs with Promise.all, then treated dispatch.mock.calls[0] as the first run and [1] as the second. Nothing guarantees that order. Before a run calls dispatch it awaits a session-entry read in a worker (createChannelInboundEnvelopeBuilderAsync calls readSessionUpdatedAtInWorker).

Until #198194 (67ecf6b, merged 2026-11-14) those reads used the "Session projection" lane, which had one worker, so they finished in the order they started. That commit folded the lane into "Session store", which gets two workers on any host with three or more cores. Two concurrent reads now run on separate threads and either one can finish first.

The case now finds each turn by the message it carries (ctxPayload.MessageSid) and asserts that dispatch ran exactly twice. The message id reaches the turn through buildContext, and the task id reaches it through the delivery closure, so matching on one does not presuppose the other. The rest of the case is untouched: the session-key comparison, the From values, replies delivered in reverse order, and the per-task artifact checks.

I left production alone. docs/channels/a2a.md promises that replies go to the task that started the turn, including when messages in one context finish out of order. It promises nothing about which of two concurrent requests dispatches first, and channel.ts starts each request as independent detached work with no queue.

One cleanup in the same file: the dispatched and createA2aDispatchResult helpers took a queuedFinal argument that every caller passed as false. I removed it. The helpers return the same values as before.

This PR is test-only on purpose. The failing check is the defect.

Evidence

Head f18eecf on base 7d90a90. Local runs use the pinned Bun fork, the runtime the CI shard uses. Every loop runs node scripts/run-vitest.mjs extensions/a2a/src/inbound.test.ts.

Red, unmodified main at e970cf6

  • 30 runs in sequence: 12 failed. The hermes case failed in 7 and the crew case in 7.
  • 30 runs, three at a time for CPU contention: 5 failed. Hermes 4, crew 1.
  • The failures are the two CI assertions, at lines 175 and 181.

Cause

A temporary probe, not committed, repeated the two-run scenario in one process and recorded which run reached dispatch first.

  • On e970cf6 the second run got there first in 192 of 400 rounds. Ingress resolution finished in start order in all 400, so the swap happens at the envelope read. With turns matched by message, every reply landed on its own task in all 400.
  • git bisect --first-parent with that probe, from 9151ac2 (good) to b2f5706 (bad), 2,431 commits, ends at 67ecf6b. Its parent 7f7b16c swapped 0 of 80 rounds. The commit itself swapped 40 of 80.

So the hermes failure at line 181, where the first task received "second reply", comes from the mislabelled firstTurn and secondTurn variables. Both hermes runs share a session key and a From value, so line 175 cannot notice the swap. The test then hands "second reply" to the turn that owns the first task.

Green, this change

The loops ran on df0211ccf84, which is this commit on main at d2bb335. Main then moved eight commits to 7d90a90. None of them touch extensions/a2a, session storage, the worker runtime, the channel helpers or the Vitest config, so I rebased and ran the file once more instead of repeating the loops.

  • 30 runs in sequence: 30 passed.
  • 30 runs, three at a time: 30 passed.
  • One run on f18eecf: 15 of 15 cases passed.
  • pnpm test extensions/a2a/src/inbound.test.ts --maxWorkers=1: 15 passed, 42 s wall. Vitest reports 90% of that as transform and 1% as test time.
  • pnpm exec oxfmt --check extensions/a2a/src/inbound.test.ts and git diff --check: clean.
  • OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 node scripts/check-changed.mjs: passed, including the extension test typecheck and lint of the changed file.

The case still catches miscorrelation

Two temporary edits to extensions/a2a/src/inbound.ts, each run four times against the fixed test and then reverted:

  • Complete the most recently started task instead of the turn's own task. Both interleaved cases failed in 4 of 4 runs, at the first task's artifact check.
  • Drop the peer name from the route peer id, so two peers share one session. The crew case failed in 4 of 4 runs at the session-key check.

File audit

I read all of extensions/a2a/src/inbound.test.ts: 15 cases, the fixture, both helpers, imports and teardown.

  • Only the interleaved case starts runs concurrently. The other reads of dispatch.mock.calls follow one awaited run, or two runs awaited one after the other in "routes a stable peer binding", so their order is fixed.
  • The task store is in memory and stopped in afterEach, which also resets the plugin registry. There are no timers, sleeps, skips or unused imports.
  • Removed: the queuedFinal argument described above. No case or assertion was removed.
  • Left as is: the interleaved case passes dmScope: "per-channel-peer" but only compares the two session keys with each other, so it would not notice if A2A stopped pinning per-account-channel-peer. "routes a stable peer binding" asserts exact session keys, but without that override. I did not widen this PR to cover it.

Not done

  • The red loops were not repeated on 7d90a90. The test file and the worker lanes are identical there.
  • CI seconds for the file are not known until this PR's run finishes.
  • The dead export scan inside check-changed fails on main for resolveRollbackWorkerInputs in src/cli/update-cli/update-command-database-rollback.test-support.ts. This PR does not touch that file, so I skipped the scan for the final run.
  • The autoreview helper could not start on this machine. A separate read-only review of the diff found nothing blocking.
  • Open question for A2A owners, not answered here: since fix(gateway): reduce resident memory on constrained hosts #198194 two messages sent at the same moment in one context can reach dispatch in either order. Reply correlation holds either way. If arrival order should hold too, that needs a queue in channel.ts, not a change to this test.

The interleaved-reply case starts two inbound runs at once and read
dispatch.mock.calls[0] as the first run. Each run awaits a session-entry
read in a worker before it dispatches. Since openclaw#198194 those reads share a
two-worker lane, so either run can reach dispatch first and the case
failed in 12 of 30 local runs.

Find each turn by the message it carries and assert that dispatch ran
twice. The session-key, sender, and per-task reply assertions are
unchanged, and replies are still delivered in reverse order.

Also drop the queuedFinal argument from the two dispatch-result helpers.
Every caller passed false, so the values they return are the same.
@clawsweeper

clawsweeper Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@fuller-stack-dev
fuller-stack-dev merged commit adf70ab into openclaw:main Nov 16, 2026
94 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the fix/a2a-inbound-interleaved-order-test branch November 16, 2026 01:49
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
…PRs (openclaw#199882)

The interleaved-reply case starts two inbound runs at once and read
dispatch.mock.calls[0] as the first run. Each run awaits a session-entry
read in a worker before it dispatches. Since openclaw#198194 those reads share a
two-worker lane, so either run can reach dispatch first and the case
failed in 12 of 30 local runs.

Find each turn by the message it carries and assert that dispatch ran
twice. The session-key, sender, and per-task reply assertions are
unchanged, and replies are still delivered in reverse order.

Also drop the queuedFinal argument from the two dispatch-result helpers.
Every caller passed false, so the values they return are the same.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant