Skip to content

fix(opencode): revert from the first removed assistant message - #9924

Merged
maria-rcks merged 3 commits into
pingdotgg:mainfrom
maria-rcks:fix/issue-2789-opencode-revert
Sep 5, 2026
Merged

fix(opencode): revert from the first removed assistant message#9924
maria-rcks merged 3 commits into
pingdotgg:mainfrom
maria-rcks:fix/issue-2789-opencode-revert

Conversation

@maria-rcks

@maria-rcks maria-rcks commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

opencode rollback used the last retained message and omitted the required id when removing all turns. target the first removed assistant message and read back the native revert boundary, including when multiple assistant messages share a preceding user message. opencode keeps its reverted history until the next prompt.

verified with all 108 opencode adapter tests, server typecheck, and scoped lint and formatting checks. the existing mock follows native inclusive revert semantics, including shared user-message boundaries and consecutive rollbacks.

opencode adapter: 108 tests passed on the final head

fixes #2789.

implemented with gpt-6-astra in codex.


Note

Medium Risk
Changes rollback/read semantics for OpenCode threads and adds a session.get on every readThread; callers that assumed pre-revert thread shape after rollback may see fewer turns.

Overview
Fixes OpenCode thread rollback so it matches native revert semantics instead of slicing messages locally or reverting to the last kept assistant turn.

readThread now loads session metadata and stops listing assistant turns at session.revert.messageID, because OpenCode keeps reverted messages in the transcript until the next prompt.

rollbackThread derives the revert target from the current snapshot: the assistant turn at index length - numTurns (the first turn being removed). It always calls session.revert with that message ID, then re-reads the thread so a boundary that lands on the preceding user message is reflected. When there is nothing to revert, it returns the snapshot without calling revert.

Tests extend the runtime mock to expose revert.messageID on session.get and simulate inclusive revert behavior, with broader coverage for numTurns, consecutive rollbacks, and shared user-message boundaries.

Reviewed by Cursor Bugbot for commit 0c7358f. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix OpenCodeAdapter rollback to revert from first removed assistant message

  • Updates the OpenCode runtime test double to model native revert as a persisted session boundary reported by session.get, instead of deleting messages immediately
  • Adds test cases covering zero through three requested turns, repeated rollback/readback, a shared user-message boundary, and an empty thread
  • Fixture now includes user messages and assistant parts so the mock can determine the native revert boundary
  • Risk: session.revert in the mock now requires a message ID and fails without one; calls without parts no longer truncate the mock message list directly

Macroscope summarized 0c7358f.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Sep 5, 2026

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1e5f04c. Configure here.

Comment thread apps/server/src/provider/Layers/OpenCodeAdapter.ts Outdated
@macroscopeapp

macroscopeapp Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 0c7358f

Macroscope's review found this PR approvable — This is a focused OpenCode rollback bug fix that preserves existing APIs while correcting native revert-boundary handling and returning the actual retained turns. The production change is confined to the adapter and is covered by detailed rollback tests.

You can add or adjust custom eligibility rules. Learn more.

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Sep 5, 2026
@macroscopeapp
macroscopeapp Bot dismissed their stale review September 5, 2026 05:39

Dismissing prior approval to re-evaluate 0c7358f

@maria-rcks
maria-rcks merged commit 4ca7146 into pingdotgg:main Sep 5, 2026
24 checks passed
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Sep 5, 2026
## What's Changed
* fix(web): align tool disclosure chevrons with expanded state by @maria-rcks in pingdotgg/t3code#9935
* fix(antigravity): distinguish session initialization auth failures by @maria-rcks in pingdotgg/t3code#9919
* fix(cursor): cache successful model discovery between refreshes by @maria-rcks in pingdotgg/t3code#9918
* fix(opencode): revert from the first removed assistant message by @maria-rcks in pingdotgg/t3code#9924
* fix(web): resume imported custom-provider threads by @juliusmarminge in pingdotgg/t3code#10184
* test(web): cancel pending highlight fixture frames during cleanup by @juliusmarminge in pingdotgg/t3code#10188


**Full Changelog**: pingdotgg/t3code@v0.0.39-nightly.20260905.1289...v0.0.39-nightly.20260905.1290

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.39-nightly.20260905.1290
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: session.revert fails with 400 'Expected object, got undefined' when rolling back all assistant turns

1 participant