Skip to content

fix(server): resume OpenCode sessions from resumeCursor#2302

Open
Pedro-Revez-Silva wants to merge 4 commits intopingdotgg:mainfrom
Pedro-Revez-Silva:fix/opencode-resume-cursor
Open

fix(server): resume OpenCode sessions from resumeCursor#2302
Pedro-Revez-Silva wants to merge 4 commits intopingdotgg:mainfrom
Pedro-Revez-Silva:fix/opencode-resume-cursor

Conversation

@Pedro-Revez-Silva
Copy link
Copy Markdown
Contributor

@Pedro-Revez-Silva Pedro-Revez-Silva commented Apr 23, 2026

What Changed

  • teach OpenCodeAdapter.startSession to resume an existing OpenCode session from a persisted resumeCursor instead of always creating a new native session
  • persist the resumed OpenCode session ID and resolved directory back into T3 provider session state
  • add provider-declared resumeCursorInvalidationReasons so restart cursor handling is capability-driven rather than hard-coded in the orchestration layer
  • configure OpenCode to clear stale resume cursors when runtime mode or workspace cwd changes, while preserving existing behavior for other providers by default
  • add regression tests for OpenCode resume plus provider-scoped cursor invalidation on runtime-mode and cwd restarts

Why

T3 already persists provider resume state, but the OpenCode adapter ignored that state and always started a fresh OpenCode session. That broke continuity when T3 knew the OpenCode sessionID and needed to reconnect to it.

The first fix made OpenCode reuse resumeCursor, but review correctly pointed out that some restarts make an OpenCode cursor unsafe: resuming after a permission-mode change can keep the old permission behavior, and resuming after a cwd change can keep the old workspace.

This update keeps the fix provider-compatible by moving that decision into provider capabilities. OpenCode opts into clearing cursors for runtime-mode and cwd changes. Other providers keep the previous restart behavior unless they explicitly declare additional invalidation reasons.

UI Changes

None.

Verification

  • bun fmt
  • bun lint
  • bun typecheck
  • bun run test

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes (not applicable)
  • I included a video for animation/interaction changes (not applicable)

Note

Medium Risk
Changes provider session startup and restart behavior around resumeCursor, which can affect session continuity and remote OpenCode session lifecycle on restarts. Risk is moderate due to cross-cutting impact on orchestration restart logic and provider adapter behavior.

Overview
OpenCode sessions can now be resumed using an existing resumeCursor. OpenCodeAdapter.startSession parses a resumeCursor with a sessionID and, when present, calls session.get instead of always creating a new OpenCode session; the returned ProviderSession persists the resolved directory back into the resumeCursor and uses it for cwd.

Session restart behavior now respects provider-declared cursor invalidation. ProviderAdapterCapabilities adds resumeCursorInvalidationReasons, OpenCodeAdapter declares it, and ProviderCommandReactor clears vs forwards resumeCursor on restarts based on runtime-mode, workspace (cwd), or unsupported model-change triggers; tests were added to cover cursor dropping on workspace/runtime-mode restarts and OpenCode resume behavior.

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

Note

Resume OpenCode sessions from a resume cursor in startSession

  • OpenCodeAdapter.startSession now calls client.session.get instead of client.session.create when a valid resumeCursor is provided, deriving cwd from the resumed session payload.
  • Adds ProviderResumeCursorInvalidationReason type and an optional resumeCursorInvalidationReasons field to ProviderAdapterCapabilities; OpenCode exposes ["runtime-mode-change", "cwd-change"].
  • ProviderCommandReactor clears resumeCursor before restarting a session when the provider's capabilities indicate invalidation for the relevant change (runtime mode, cwd, or unsupported model change).
  • Race-loser cleanup in startSession skips session.abort when the session being cleaned up was a resumed session.
  • Behavioral Change: sessions previously always restarted fresh; they now reuse remote state when a valid resumeCursor is present.

Macroscope summarized f4b5b36.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ec5eddb7-191a-4f0a-adfb-e970ab95c93b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Apr 23, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Apr 23, 2026

Approvability

Verdict: Needs human review

This PR introduces new session resume functionality for OpenCode, changing how sessions are created versus resumed and adding new provider capabilities for cursor invalidation. The behavioral changes to session lifecycle management and an unresolved reviewer concern about provider compatibility warrant human review.

You can customize Macroscope's approvability policy. Learn more.

@Pedro-Revez-Silva Pedro-Revez-Silva force-pushed the fix/opencode-resume-cursor branch from 9ce0606 to a52ce4a Compare April 23, 2026 15:58
Comment thread apps/server/src/provider/Layers/OpenCodeAdapter.ts
Comment thread apps/server/src/orchestration/Layers/ProviderCommandReactor.ts Outdated
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

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 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 c3e0f9e. Configure here.

Comment thread apps/server/src/orchestration/Layers/ProviderCommandReactor.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants