Skip to content

test(agents): await native dispatch in delivery nonce regressions - #2631

Merged
lilyshen0722 merged 1 commit into
mainfrom
fix/nonce-dispatch-test-races
Oct 24, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
fix/nonce-dispatch-test-races

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Written by Forge, a Commonly agent — https://commonly.me/v2/pods/6a692a1be833c668acdb84cf

Cause

Native dispatch is intentionally fire-and-forget. It awaits folded/raw digest reads before invoking runAgent, so enqueue/garbageCollect returning proves a claimed delivery, not an invoked runner. Several nonce tests asserted call counts immediately or gave the real Mongo reads only 500 ms. Late-settle tests also assumed two setImmediate ticks were sufficient for acknowledgement writes. Some sweep mocks resolved immediately, allowing terminal writes to race the next test's database cleanup.

Test-only correction

  • Await a checked runner-call boundary before count/settler assertions; keep exact once/twice counts.
  • Await the actual acknowledgement promise for late-settle checks; keep nonce and terminal-state assertions.
  • Leave unrelated mock turns in flight after their invocation, preventing background terminal writes during cleanup.
  • Retain the explicit projection digest barrier and real Mongo routing/lease tests.

No production files change. Tier 0: CodeRabbit threads answered and green CI before operator press.

Proof

  • Requested full file: 20 consecutive runs, 52/52 each (1,040 passing tests in aggregate) on Node 22.23.1 and MongoDB 7.0.14, --runInBand --detectOpenHandles, without --forceExit.
  • Controlled reproduction: inserting a temporary 100 ms delay before digest loading makes the former enqueue count assertion fail (expected 1, received 0). With the checked waits and the same delay, enqueue/backlog controls pass 2/2. Production source restored byte-for-byte before the 20-run batch.
  • Used MONGOMS_EXP_NET0LISTEN=true so Mongo gets an OS-assigned free port on this shared machine; an earlier control attempt hit another process on port 9010 and was excluded from the tally.
  • git diff --check passes. Only this test file changes. Local repeat logs: /tmp/nonce-repeat-01.log through 20.log and /tmp/nonce-repeat-results.json.

Co-authored-by: forge <WyJmb3JnZSIsImRlZmF1bHQiXQ@agents.commonly.invalid>
Agent-Model: codex/gpt-6.1-sol/medium
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 431775c and a64fa6f.

Files selected for processing: 1
  • backend/__tests__/unit/services/agentEventService.deliveryNonce.test.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Walkthrough

The delivery-nonce and event-sweep tests replace timing-based waits and call-count polling with helpers that wait for native dispatches and acknowledgements. Selected stranded-event tests keep mocked native runs pending.

Changes: Delivery nonce and event-sweep tests

Layer / File(s) Summary
Native dispatch and acknowledgement waits
backend/__tests__/unit/services/agentEventService.deliveryNonce.test.js
Adds helpers to wait for an exact native run call count and for a run’s acknowledgement. Updates delivery and sweep tests to await these events before checking state, and keeps selected mocked runs pending.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related PRs

  • Team-Commonly/commonly#2558: Adds wake and digest delivery paths and updates the same test suite for native dispatch and digest handling.
Merge Risk: Minimal · up to a64fa

The identified second-sweep concern does not affect this test scenario. No actionable merge-blocking issue remains after normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title "test(agents): await native dispatch in delivery nonce regressions" names the main change: the delivery nonce regression tests now await native dispatch and acknowledgement instead of assert…
Description check Passed The description explains the cause (native dispatch is fire-and-forget, so immediate call-count assertions and short delays race the real Mongo reads and acknowledgement writes), lists the test-only c…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "test(agents): await native dispatch in delivery nonce regressions" names the main change: the delivery nonce regression tests now await native dispatch and acknowledgement instead of asserting immediately. It matches the file-level summary and the PR objectives, and it uses a conventional test(...) prefix. The title is specific and not vague.

Full details: Description check

Explanation

The description explains the cause (native dispatch is fire-and-forget, so immediate call-count assertions and short delays race the real Mongo reads and acknowledgement writes), lists the test-only corrections, and gives verification evidence. It matches the changes in the raw summary and the PR objectives. It also includes a non-essential attribution line, which does not make it off-topic.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIER 0 PRESS CHECK at a64fa6f.

This PR changes one test file, backend/tests/unit/services/agentEventService.deliveryNonce.test.js, with no production code. Every CodeRabbit thread is answered (cr-unanswered: 0), and CI at this head is green.

GATE: PASS

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit c8bfddc Oct 24, 2026
22 checks passed
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.

1 participant