Skip to content

fix(core): park execution while a revert is staged - #55394

Closed
CasualDeveloper wants to merge 1 commit into
anomalyco:devfrom
CasualDeveloper:revert-parking
Closed

CasualDeveloper wants to merge 1 commit into
anomalyco:devfrom
CasualDeveloper:revert-parking

Conversation

@CasualDeveloper

@CasualDeveloper CasualDeveloper commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Fixes #37751
Split out of #55315.

Type of change

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

What does this PR do?

I narrowed #55315 to the reported Core race. Wake/resume parks a session while a revert is staged. Staging and the drain's state read share the Inbox lock, so a wake cannot start through an in-flight snapshot restore.

Prompt preparation stays outside that lock. Finalization reloads the boundary and reconciles retries before committing, so accepted replacements don't get stranded and delayed retries don't erase the winning admission. Location/plugin initialization stays outside the lock. Same-session input waits for snapshot work; other sessions remain independent.

This is Core-only: no new API fields, plugin capability changes, or App/TUI changes. The refresh preserves upstream cooperative stopping and subagent recovery.

How did you verify your code works?

  • Independently rebased this PR onto dev at 0354362b857beae78166d4305f06c0b2f47c251e.
  • 383 Core tests pass across execution, owned-session, runner, prompt and revert suites; official Core TypeScript checking passes.
  • All four staged wake/resume and public-stage race cases fail with BASE's execution implementation and pass with this fix restored.
  • Root bun run check passes. These checks ran on this focused branch, without the other feature branches.
  • Reviewed the original-to-refreshed range-diff; one commit, five Core files, original authorship retained. No generated API changes.

Screenshots / recordings

Logic change; no visual changes.

Checklist

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

Process: human-directed, with agentic assistance from openai/gpt-6-astra.


Added by the opencode bot (AI-generated).

Related: #54150

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent 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 found nothing that blocks a merge. I ran the PR's new tests against the base and they reproduce the race: a wake or resume while a revert is staged, including one racing an in-progress staging, starts a run there, and the prepared-replacement and restage cases fail too. With this PR the run waits until the revert is cleared or committed, and the Core session/runner/execution tests (293) and Core typecheck pass. I also checked that taking the inbox lock again when finalizing a prompt can't deadlock, because admit/reconcile don't take that lock themselves, and that committing a parked revert leaves no input stuck in the queue.

Public API: unchanged (Core internals only; no API, plugin, config or event changes).

Related: #54150

Serialize staging with drain state reads and prompt finalization. Select Location services before locking, retain fresh revert snapshots when restaging, and reconcile winning admissions before committing a replacement boundary.

Cover real wake/resume and public staging races, replacement admission, restaging, and delayed pending, delivered, and conflicting retries.
@github-actions

Copy link
Copy Markdown
Contributor

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:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

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.

@CasualDeveloper

Copy link
Copy Markdown
Contributor Author

Please reopen this PR. It was closed by the November 14 age/reaction cleanup, and I’m still maintaining the fix. This is the focused Core-only split requested in #55315; the earlier automated review reproduced the races and reported no merge blocker.

On November 16 I refreshed the maintained copy onto dev at 0354362b85. The parking checkpoint preserves upstream subagent recovery and supplies the new execution-fixture dependencies. The combined source passed 473 Core tests, including staged wake/resume and public-stage races, official Core typechecking, and the root checks.

Those fresh results are from the maintained combined source. This PR still points at e29dc6a0ff and needs its own refresh before merge. I’d like to keep this review focused on staged execution parking and safe replacement finalization for #37751.

@CasualDeveloper

Copy link
Copy Markdown
Contributor Author

I’ve now refreshed this PR’s own branch onto dev at 0354362b85: 525c0f5622. It remains one Core-only commit across five files. All 383 focused Core tests, official Core typechecking and the root checks pass independently. The four staged-execution regressions fail with the base implementation and pass with the fix. I updated the description with these standalone results; please consider reopening it for review.

The fork branch is verified at the linked commit. GitHub's closed PR record still reports the older head SHA, so the link above identifies the refreshed revision.

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.

V2 session revert can race with session execution

1 participant