Skip to content

test(e2e): wait for the agent post's enqueue before clearing events - #3633

Merged
lilyshen0722 merged 1 commit into
mainfrom
cto/f294-e2e-late-event
Nov 6, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
cto/f294-e2e-late-event

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

clawdbot-e2e "should handle summary event from user chat activity" failed with expected 1 event, got 2, and ejected #3577 and #3624 from the merge queue.

The second event is a message.posted for "Message from Commonly Bot", from the previous test. The runtime post route doesn't wait for enqueueAgentPost, so that write can land after afterEach cleared AgentEvent, and the next poll picks it up.

The fix is in the test: afterEach now waits for those calls before it clears. The route stays as it is, because not blocking a post on its wakes is deliberate. The spy goes in beforeEach, since restoreMocks: true undoes one set in beforeAll before the first test.

How I checked: I added a delay of 60–200 ms to enqueueAgentPost in a scratch copy. Without the fix, this failure came back in 3 of 6 runs and the captured extra event was that post. With the fix, all 6 runs passed, and so did the plain file (29/29).

Not covered: the same post path has two other unawaited calls, the chat.message dispatch and maybeRecordAgentDmConclusion. Neither produced the extra event here.

🤖 Generated with Claude Code

https://claude.ai/code/session_015AKgpN1QhxGKRxQeoqFeov

The runtime post route doesn't wait for its mention enqueue, so a post at
the end of one test could write `message.posted` after afterEach cleared
AgentEvent. The next test polled it: expected 1 event, got 2. This ejected
#3577 and #3624 from the merge queue. Each test now waits for those calls
before the clear.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015AKgpN1QhxGKRxQeoqFeov

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

HEAD: 026f76e — GATE: PASS

Reviewed as local commit ee6af44c3; this head is the same tree.

  • Spy interception: holds. The route calls AgentMentionService.enqueueAgentPost(...) as a property of the required module (backend/routes/agentsRuntime.ts ~2520), and the test requires the same module. I did not compile the CJS output to confirm the export is writable, so that step is inferred, not run.
  • restoreMocks / clearMocks: no conflict. Jest restores spies at test start, before the beforeEach re-spies. The top-level afterEach runs before the next test's restore, so it still sees the current test's mock.results. The route records the call before it responds, so supertest completion means the call is already in mock.results.
  • Promise.allSettled: safe. The route attaches .catch, so rejections are handled, and allSettled accepts non-promise values. enqueueAgentPost is async, so it cannot throw synchronously.
  • Hook order: the only beforeAll is the top-level one, before any spy. There are no nested afterEach hooks, and the nested beforeEach hooks run after the spy is installed.
  • Gap, not a blocker: the same post path has other unawaited work that this does not cover. void eventHandlers.dispatch('chat.message', …) (backend/services/agentMessageService.ts ~2250) and void AgentMessageService.maybeRecordAgentDmConclusion(…) (~1483) could write events late. I did not confirm whether either writes AgentEvent in this suite. A follow-up should check that, or spy on them too.

Written by a Haiku 5.5 review subagent.
GATE: PASS

@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 43 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8ec2135 and 026f76e.

Files selected for processing: 1

  • backend/__tests__/service/clawdbot-e2e.test.js
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 0721726 Nov 6, 2026
34 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