Skip to content

fix(cli): keep update preflight through TUI loading - #36475

Merged
kitlangton merged 3 commits into
v2from
preflight-handoff
Jul 12, 2026
Merged

kitlangton merged 3 commits into
v2from
preflight-handoff

Conversation

@kitlangton

@kitlangton kitlangton commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

What

The update preflight now remains visible until the main TUI has finished its non-terminal startup work, then hands its initialized renderer directly to the TUI.

Previously, the footer reached Ready, destroyed its renderer, and left a blank terminal while the TUI loaded config, resolved its initial directory, negotiated terminal capabilities, and created another renderer. The handoff now reads:

Keeping your session safe
Starting the new background service
Loading OpenCode
Ready

Ready remains visible through TUI mounting. The same renderer switches from the split footer to the normal alternate screen, paints the TUI, and removes the preflight root after the first TUI frame.

How

  • packages/cli/src/services/update-preflight.tsx adds an explicit loading stage and initializes the renderer with the settings the TUI will need.
  • packages/cli/src/commands/handlers/default.ts keeps the preflight mounted through TUI config loading and passes a terminal handoff callback into the TUI.
  • packages/tui/src/app.tsx completes its initial directory request, accepts the existing renderer and detected terminal mode, mounts the TUI, then retires the preflight root after the first rendered frame.
  • Preflight cleanup remains scope-safe and idempotent for failures or interruption before ownership transfers.
  • The loading stage waits only for the remainder of its minimum display time rather than adding a fresh fixed delay after preload completes.

Scope

This changes only the fresh-launch version-mismatch flow introduced in #36448 and refined in #36455. Normal TUI startup and already-connected TUI reconnection behavior are unchanged.

Testing

  • bun typecheck in packages/cli
  • bun run test in packages/cli (25 pass)
  • bun typecheck in packages/tui
  • bun run test in packages/tui (214 pass, 1 skip)
  • Push hook: full workspace typecheck (31 packages)
  • Built two native darwin-arm64 binaries from this branch with baked-in versions 0.0.1-old and 0.0.2-new
  • Started the old binary as a registered service under isolated XDG state
  • Launched the new binary in a real OpenTUI-compatible PTY and verified the complete version-mismatch replacement and TUI handoff
  • Verified /api/health reported 0.0.2-new with the replacement service PID
  • Recorded at 60fps and inspected the transition as a 10fps contact sheet

Demo

Real compiled-binary service replacement under isolated XDG state, recorded at 60fps:

handoff.mp4

Flow

sequenceDiagram
    participant Preflight as Update preflight
    participant CLI as CLI startup
    participant Server as New service
    participant TUI as Main TUI

    Server-->>CLI: healthy endpoint
    CLI->>Preflight: show Loading OpenCode
    par While preflight remains visible
        CLI->>CLI: load TUI config
        CLI->>Server: resolve initial directory
        Preflight->>Preflight: detect terminal mode
    end
    CLI->>Preflight: show Ready
    Preflight-->>TUI: transfer initialized renderer + mode
    TUI->>TUI: mount on transferred renderer
    TUI->>Preflight: retire footer root after first frame
Loading

@kitlangton
kitlangton merged commit e22e3b8 into v2 Jul 12, 2026
10 checks passed
@kitlangton
kitlangton deleted the preflight-handoff branch July 12, 2026 02:19
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant