Repository navigation
fix(core): serialize prompt settlement around event publication - #44340
sahiljagtap08 wants to merge 1 commit into
Conversation
Correct fix for a real race — the old order (publish first, settle/delete after) let a second reply slip through Two small suggestions:
|
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #34853
Type of change
What does this PR do?
QuestionV2.reply,QuestionV2.reject, andPermissionV2.replypublished their settlement event before removing the pending entry. SinceEventV2.publishruns listeners inline, a slow listener suspends the first reply while the entry still looks pending. A second concurrent reply then also passes the pending check, publishes a conflicting settlement event, and both callers get success.The fix claims the pending entry synchronously before publishing, so the second caller gets
NotFoundErrorinstead of double settling. If the publish fails, the entry is restored, which keeps the rollback behavior these services already used on the create side. The cascade loops inPermissionV2.reply(reject all in session, auto allow after "always") now re-claim each entry withpending.delete(id)before publishing, since every publish is a suspension point where another reply can win the race.This works because the claim happens with no yield point between the pending check and the delete, so only one settlement can ever proceed per request.
How did you verify your code works?
Added regression tests that block a settlement listener on a deferred and race a second reply. Both tests fail on the current code (double publish or timeout) and pass with the fix.
bun test test/question.test.ts test/permission.test.tsin packages/core: 16 pass. Typecheck and oxlint are clean.Screenshots / recordings
Not a UI change.
Checklist