Skip to content

Fix OpenCode ownership and restart recovery#336

Merged
danshapiro merged 104 commits into
mainfrom
fix/opencode-ambiguous-ownership
May 18, 2026
Merged

Fix OpenCode ownership and restart recovery#336
danshapiro merged 104 commits into
mainfrom
fix/opencode-ambiguous-ownership

Conversation

@danshapiro
Copy link
Copy Markdown
Owner

@danshapiro danshapiro commented May 10, 2026

Summary

  • Add the OpenCode ownership control plane, including child-session filtering from /session/status, session.created handling, reducer fixes, and stricter ambiguous-warning emission.
  • Wire the OpenCode root resolver in production so child IDs resolve through the provider database instead of the identity-map fallback.
  • Restore OpenCode panes across server restarts by clearing stale terminals, recreating provider restores, preserving extension registry refresh state, and aligning restore fallback coverage.
  • Capture the restart postmortem/recovery handoff and refresh the OpenCode session contract notes.

Dev Parity

This PR now carries or supersedes the dev-only restart recovery commits:

  • ef3f07ae -> af8d07cb docs: capture opencode restart postmortem
  • 2ec8316a -> 25f4e419 docs: add opencode restart resilience handoff
  • 2b4c4241 -> 56f97ab3 fix: wire opencode root resolver in production
  • 7b2d431b -> 8cac280c fix: restore opencode sessions across restarts
  • fab3305a -> 3d382483 fix: preserve extension registry during restart refresh

It also still includes the earlier OpenCode ownership-control-plane commits already present on this PR branch.

Root Cause

Two commits (29dc693, c1f76b1) introduced an ownership reducer with ambiguous state. Child sessions appear as separate busy sessions in /session/status but were not being filtered. The session.created SSE path was also dead code due to a schema mismatch with the SDK.

The later restart work fixed the production root-resolver wiring and client/server restore flow so OpenCode panes can recover after stale terminal handles disappear during a server restart.

Changes

  • server/coding-cli/providers/opencode.ts - expose root resolution and database/WAL watching behavior.
  • server/coding-cli/opencode-ownership-reducer.ts - fix UNION behavior, ambiguous-to-known transitions, and strict warnAmbiguous emission.
  • server/coding-cli/opencode-activity-tracker.ts and wiring - filter children via DB resync/SSE and pass the production root resolver.
  • server/terminal-registry.ts, server/ws-handler.ts, and client restore paths - recover OpenCode panes after restart and keep restore fallback diagnostics explicit.
  • Tests - reducer, tracker, provider, wiring, restart recovery, extension registry, and fallback coverage.

Dan Shapiro added 30 commits May 6, 2026 00:10
OpenCode CLI's TUI enables mouse tracking for click-handling, which
caused the fallbackToCursorKeysWhenAltScreenMouseCapture policy to
intercept scroll events and send up/down arrow keys instead. The CLI
doesn't interpret arrow keys as scroll commands, so scrolling broke.

Change scrollInputPolicy to 'native' so xterm.js passes mouse scroll
SGR sequences through to the CLI, letting it handle them natively.
…creen

- Skip term.scrollLines() in alt screen for touch scrolling (it's a no-op
  since alternate buffer has no scrollback)
- Update opencode scroll/touch test fixtures and assertions to match the
  new native policy: OpenCode no longer translates scroll events to cursor
  keys
# Conflicts:
#	server/coding-cli/codex-app-server/launch-planner.ts
#	server/coding-cli/codex-app-server/runtime.ts
#	server/index.ts
#	test/unit/server/coding-cli/codex-app-server/launch-planner.test.ts
#	test/unit/server/coding-cli/codex-app-server/runtime.test.ts
@danshapiro danshapiro force-pushed the fix/opencode-ambiguous-ownership branch from 9324c5b to 6b7b4fb Compare May 16, 2026 23:36
@danshapiro danshapiro changed the title fix: filter child sessions from OpenCode snapshots to resolve false ambiguous ownership warnings Fix OpenCode ownership and restart recovery May 18, 2026
Dan Shapiro added 14 commits May 18, 2026 00:46
…ain-parity-20260518-004614

# Conflicts:
#	server/ws-handler.ts
#	src/components/agent-chat/AgentChatView.tsx
…ain-parity-20260518-004614

# Conflicts:
#	docs/lab-notes/2026-04-20-coding-cli-session-contract.md
#	server/coding-cli/opencode-activity-tracker.ts
#	server/coding-cli/opencode-activity-wiring.ts
#	server/coding-cli/opencode-session-controller.ts
#	server/coding-cli/providers/opencode.ts
#	server/index.ts
#	server/mcp/freshell-tool.ts
#	server/session-observability.ts
#	server/terminal-registry.ts
#	server/ws-handler.ts
#	src/components/TerminalView.tsx
#	src/store/paneTypes.ts
#	src/store/selectors/paneTerminalSelectors.ts
#	test/e2e/codex-refresh-rehydrate-flow.test.tsx
#	test/e2e/terminal-restart-recovery.test.tsx
#	test/server/session-association.test.ts
#	test/unit/client/components/TerminalView.lifecycle.test.tsx
#	test/unit/server/coding-cli/opencode-activity-tracker.test.ts
#	test/unit/server/coding-cli/opencode-activity-wiring.test.ts
#	test/unit/server/coding-cli/opencode-provider.test.ts
#	test/unit/server/coding-cli/opencode-session-controller.test.ts
@danshapiro danshapiro merged commit 072f2d7 into main May 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant