Skip to content

fix(opencode): adopt upstream #3617 resume robustness onto fork base#6

Merged
patroza merged 1 commit into
patroza/import-external-sessionsfrom
t3code/adopt-opencode-fixes
Jul 14, 2026
Merged

fix(opencode): adopt upstream #3617 resume robustness onto fork base#6
patroza merged 1 commit into
patroza/import-external-sessionsfrom
t3code/adopt-opencode-fixes

Conversation

@patroza

@patroza patroza commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Adopts the OpenCode session-resume hardening from upstream pingdotgg/t3code#3617 (fixes the pingdotgg#3604 class of silent context loss) onto this fork's adapter.

Why hand-ported, not cherry-picked

This fork runs ahead of upstream on @opencode-ai/sdk (1.17 vs the PR's 1.3) and passes a per-call directory to every client.session.* call, and it already had an independent, strict resume implementation. The upstream diff does not apply cleanly, so the PR's robustness was ported onto the fork's directory-aware base instead.

What changed (OpenCodeAdapter.ts)

  • Schema-versioned cursorOPENCODE_RESUME_VERSION / parseOpenCodeResume; malformed or foreign cursors are ignored (treated as "no resume") instead of throwing.
  • Robust not-foundisOpenCodeNotFound classifies only structured 404 / NotFoundError signals. A confirmed miss falls back to session.create; transport / auth / 5xx errors propagate rather than masquerading as a brand-new empty session.
  • Fork on cwd change — when the stored directory differs (e.g. thread moved into a git worktree), session.fork carries history into the requested directory instead of dropping context.
  • Permissions on resumesession.update re-applies the current runtimeMode ruleset on reuse/fork.
  • Race cleanup aborts only a session this call created; sendTurn echoes resumeCursor so ProviderService keeps the persisted cursor fresh every turn.
  • Preserves the fork's per-call directory and isOpenCodeMessageAborted.

Tests (OpenCodeAdapter.test.ts)

Regression coverage for: resume (no create), fork-on-cwd, stale-404 fallback-to-create, transient-error propagation, malformed-cursor rejection, and direct isOpenCodeNotFound classification. The two obsolete hard-error-on-directory-mismatch tests were replaced.

Validation

  • tsgo --noEmit clean
  • OpenCodeAdapter.test.ts 23/23; full src/provider + src/orchestration suites 539 pass (6 pre-existing skips)
  • vp check clean

🤖 Generated with Claude Code

…ork base

Ports the OpenCode session-resume hardening from upstream PR pingdotgg#3617
(pingdotgg#3604) onto this fork's directory-aware adapter, rather than
cherry-picking (the fork runs ahead on @opencode-ai/sdk 1.17 and passes
per-call `directory`, so the upstream diff does not apply cleanly).

- Schema-versioned resume cursor (OPENCODE_RESUME_VERSION /
  parseOpenCodeResume); malformed/foreign cursors are ignored.
- isOpenCodeNotFound classifies only structured 404 / NotFoundError
  signals; a confirmed miss falls back to session.create, while
  transport/auth/5xx errors propagate instead of masquerading as a new
  empty session.
- cwd change forks the session (session.fork) into the requested
  directory to preserve history; session.update re-applies runtimeMode
  permissions on reuse/fork.
- Race-cleanup aborts only a session this call created; sendTurn echoes
  resumeCursor so ProviderService keeps the persisted cursor fresh.
- Keeps the fork's per-call `directory` and isOpenCodeMessageAborted.

Regression tests cover resume, fork-on-cwd, stale-404 fallback,
transient-error propagation, malformed-cursor rejection, and
isOpenCodeNotFound classification. tsgo clean; adapter 23/23; full
provider + orchestration suites 539 pass; vp check clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L labels Jul 14, 2026
@patroza
patroza merged commit 0e5fb26 into patroza/import-external-sessions Jul 14, 2026
6 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 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.

1 participant