Skip to content

fix(core): ignore a staged revert whose boundary a commit deleted - #66405

Open
ccclucky wants to merge 1 commit into
anomalyco:devfrom
ccclucky:revert-stage-commit-race
Open

ccclucky wants to merge 1 commit into
anomalyco:devfrom
ccclucky:revert-stage-commit-race

Conversation

@ccclucky

Copy link
Copy Markdown

Issue for this PR

Closes #63282

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A revert stage keeps its snapshot work between the boundary check in plan and the RevertEvent.Staged publication. If a commit runs in that window, the late Staged write puts the revert pointer back on the boundary the commit just deleted. Every later send starts with a commit, and each one dies with Revert boundary message not found, so the session is blocked until it is deleted.

Projections for one session already run serialized under the durable lock, so this fixes both halves in the projector:

  • Staged writes the pointer only while its boundary message still exists, so a late stage cannot resurrect a deleted boundary.
  • Committed whose boundary is already gone is treated as applied and clears the pointer instead of dying, which also recovers sessions an older build left blocked.

How did you verify your code works?

  • bun test test/session-projector.test.ts in packages/core: 48 pass. Two new tests replay the interleaving through the bus: a Staged published after the commit leaves revert null, and a commit whose boundary row is already missing clears the pointer. Both fail before the change (2 fail, 4 pass with only the source reverted).
  • bun typecheck in packages/core: no type errors.
  • Rebased on current dev (a75fcac14c); the bot reproduction in core: committed revert can leave session_v2.revert pointing at deleted boundary, permanently blocking sends #63282 still matches the source on that revision.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

A stage keeps the snapshot work between its boundary check and its Staged
publication. If a commit runs in that window, the late Staged write puts the
revert pointer back on the boundary the commit just deleted, and every later
commit (which each send performs first) fails with "Revert boundary message
not found", permanently blocking the session.

Projections for one session already run serialized under the durable lock, so
the Staged projection now writes only while its boundary message still exists.
A commit whose boundary is already gone is treated as applied and clears the
pointer, which also recovers sessions blocked by an older build.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd approve this. It fixes the stuck session from #63282, which I reproduced on the base branch first.

To reproduce it, I added a test-only 1.5 s pause just before stage publishes RevertEvent.Staged (the same pause the bot used in #63282). Then I staged a revert twice and committed while the second stage was still running.

  • Base branch: the late stage set session.revert back to the deleted message. The next revert/commit returned 500, and the next TUI send failed with "Failed to commit revert".
  • This pull request: session.revert stays null, the second commit succeeds, and the next send goes through.

The projector tests pass (48), and the two new ones fail against the base source. tsc passes for packages/core.

Skipping the inbox, instruction-state and blob cleanup when the boundary is already gone looks right: the commit that deleted the boundary already did that work.

The public API is unchanged: no new endpoints, events, payloads or config.

I have no blocking concerns.

Before

After

@ccclucky

Copy link
Copy Markdown
Author

The repository checks on this head are still waiting for workflow approval from a maintainer. Nothing else is pending from my side: the review above reproduced the same interleaving on the base branch.

This branch has not been deployed

No deployments
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.

core: committed revert can leave session_v2.revert pointing at deleted boundary, permanently blocking sends

1 participant