Skip to content

fix(opencode): name OpenCode 2 sessions after their thread - #17414

Open
nkoynov wants to merge 1 commit into
pingdotgg:mainfrom
nkoynov:fix/opencode-session-title
Open

nkoynov wants to merge 1 commit into
pingdotgg:mainfrom
nkoynov:fix/opencode-session-title

Conversation

@nkoynov

@nkoynov nkoynov commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Problem

T3 creates an OpenCode 2 session without a title. On the first prompt OpenCode then titles it with its own model (one extra request per thread on its small model), and opencode's session list shows that title, not the thread's name in T3. Renaming the thread in T3 never reaches the session.

On nightly 2849 with OpenCode 2.0.25 and the Cursor provider, two new OpenCode threads each made one extra tool-less title run on their session, and both sessions ended up with OpenCode's titles ("Calculate 17 times 23" for a thread T3 showed as "What is 17 times 23? Reply with just the number.").

Change

  • ProviderAdapterV2EnsureThreadInput gets an optional title; ProviderTurnStartService passes the thread's current title (the seed, at the first turn).
  • The OpenCode 2 adapter creates the session with that title. OpenCode only titles a root session while its title is unset, so it no longer runs its title model.
  • Before each turn the adapter updates the session's title if the thread's differs from the last one it set or read. That carries manual renames and T3's own generated title (which replaces the seed after the first prompt) at the next turn. The write is best effort and can't fail the turn. An empty title is never sent, since OpenCode's session.update treats an empty title as "generate one".

Other providers ignore the new field.

Scope and approval

This changes what OpenCode shows, so it needs a maintainer's yes. I proposed it in #14809, which asks for the same thing for Claude sessions: comment. No approval yet; happy to close this if you'd rather do it another way.

Verification

  • OpenCode2AdapterV2.test.ts: a new session is created with the trimmed thread title and its first turn sends no update; a renamed thread sends one session.update with the new title before its prompt, and none on the next turn under the same title.
  • OpenCode2OrchestratorV2.integration.test.ts: the scripted sessions are now created with the thread's title. Two recorded transcripts gained the one title update the change adds: opencode2_fork (the forked session carries the source's title) and opencode2_switch (the resumed session's recorded title differs from the thread's).
  • vp test run on the two files above, OrchestratorReplayFixtures.integration.test.ts, ProviderTurnStartService.test.ts and ProviderSessionManager.test.ts: all pass. Lint, fmt and typecheck pass. provider-opencode's OpenCodeServerLedger.test.ts has 5 darwin-only failures on Linux, on main too.
  • I haven't run this branch live. Live, on nightly 2849 with OpenCode 2.0.25: stock as described above; with a local workaround that names the session from T3's thread title before the first prompt, both threads made no title run, the OpenCode titles matched T3's (T3's generated title replaced the seed in both), and a rename in T3 showed up in OpenCode.

Model: Claude Opus 5.5 (1M). Harness: OpenCode in T3 Code.

OpenCode titles an untitled root session with its own model on the first
prompt, so every T3 thread cost an extra model call and showed a different
name in OpenCode than in T3. Create the session with the thread's title and
rename it before a turn when the thread was renamed since.
@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 Oct 9, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at f5a405c

Macroscope's review found this PR approvable — This is a focused OpenCode 2 bug fix that keeps native session names aligned with existing T3 thread titles and prevents an unnecessary automatic title-generation request. The implementation is localized, additive for other providers, and covered by targeted tests and updated fixtures.

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

@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 80ca146f-a58a-43c4-998f-836030e53429
📥 Commits

Reviewing files that changed from the base of the PR and between 43f8a8d and f5a405c.

📒 Files selected for processing (7)
  • apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
  • apps/server/src/orchestration-v2/OpenCode2OrchestratorV2.integration.test.ts
  • apps/server/src/orchestration-v2/ProviderTurnStartService.ts
  • apps/server/src/orchestration-v2/testkit/fixtures/opencode2_fork/opencode_transcript.ndjson
  • apps/server/src/orchestration-v2/testkit/fixtures/opencode2_switch/opencode_transcript.ndjson
  • packages/provider-core/src/server/ProviderAdapter.ts
  • packages/provider-opencode/src/server/v2/adapter.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The provider contract and orchestration now pass app thread titles to OpenCode. The adapter uses titles during session creation and synchronizes changed titles before starting turns.

Changes

OpenCode session titles

Layer / File(s) Summary
Pass titles into session creation
packages/provider-core/src/server/ProviderAdapter.ts, apps/server/src/orchestration-v2/ProviderTurnStartService.ts, packages/provider-opencode/src/server/v2/adapter.ts, apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts, apps/server/src/orchestration-v2/OpenCode2OrchestratorV2.integration.test.ts
The ensure-thread input accepts an optional title. Orchestration supplies the app thread title, and the OpenCode adapter includes a trimmed, nonempty title when creating a session. The adapter records the native title, and replay tests include session titles.
Synchronize titles before turns
packages/provider-opencode/src/server/v2/adapter.ts, apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts, apps/server/src/orchestration-v2/testkit/fixtures/opencode2_fork/opencode_transcript.ndjson, apps/server/src/orchestration-v2/testkit/fixtures/opencode2_switch/opencode_transcript.ndjson
Before a turn, the adapter attempts to update the title if the trimmed title is nonempty and differs from the tracked title. The update has a 10-second timeout, and failures are ignored. Tests and replay fixtures cover title updates.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant ProviderTurnStartService
  participant OpenCodeAdapter
  participant OpenCodeSessionAPI
  ProviderTurnStartService->>OpenCodeAdapter: Start turn with app thread title
  OpenCodeAdapter->>OpenCodeSessionAPI: Update session title when changed
  OpenCodeSessionAPI-->>OpenCodeAdapter: Update result
Loading

Suggested reviewers: juliusmarminge

Merge Risk

Merge Risk: ⚪ Minimal · up to f5a40

No established issue prevents merging this title-synchronization change after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to f5a40

Thread names will also be visible in OpenCode. The inspected changes preserve existing session access and permission behavior, but synchronization after timeouts and the full security scope are not completely established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The added exposure is application thread-name content in the corresponding OpenCode session's metadata. In the inspected path, controlling the title does not control the destination session, directory, permissions, or agent selection.

Trust Boundaries and Controls

  • observed — Title content crosses into the existing OpenCode session API as a title field. The write uses the registered state's native session ID, resolved from the provider thread inside exclusive turn setup; missing state and an already-active turn are rejected before synchronization.

Resilience and Maintainability Implications

  • inferred — The exclusive setup gate orders local title attempts, but cancellation and completion ordering of an interrupted external request are unestablished. A late write could leave the same session's displayed name stale; the inspected title-only write does not establish a cross-session or permission-state failure.
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check Warning The description covers the problem, implementation, scope, and verification. However, the required Scope and approval section links a discussion but explicitly states that no maintainer approval exist… Add an explicit maintainer approval comment or link to one. If the fix qualifies for an approval exemption, explain why it is a small, focused fix of an obvious bug.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: naming OpenCode 2 sessions after their T3 threads.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description covers the problem, implementation, scope, and verification. However, the required Scope and approval section links a discussion but explicitly states that no maintainer approval exists yet.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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

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.

1 participant