Skip to content

perf(tui): decouple first paint from runtime startup - #252

Draft
kingsword09 wants to merge 1 commit into
mainfrom
perf/foreground-tui-startup
Draft

kingsword09 wants to merge 1 commit into
mainfrom
perf/foreground-tui-startup

Conversation

@kingsword09

Copy link
Copy Markdown
Owner

Summary

Move interactive terminal ownership into a lightweight foreground process so synchronous initialization of the official runtime cannot block the first screen or draft editing.

Scope: this improves first paint and terminal continuity; it does not yet make every slash command available immediately.

Changes

  • Render the existing welcome frame, theme, and composer before settings bootstrap and runtime initialization. Read saved appearance without running migration so regular/fullscreen mode and palette apply from the first frame.
  • Start the unchanged official runtime in a child process. Expose the existing TUI adapter callbacks through versioned, inherited Node IPC, including streaming events, permission callbacks, cancellation signals, collections, and workflow reducers. No daemon, network listener, or credential payload is introduced.
  • Let the ready UI adopt the existing terminal instance instead of clearing, stopping, and restarting it. Preserve the latest draft, keep startup Enter presses from submitting it, and require an explicit Enter after readiness.
  • Keep terminal modes, login suspension, local shells, and validated clipboard output in the foreground. Handle backend failure and bounded native cleanup without stranding raw mode or reporting false success.
  • Preserve the existing headless/app-server paths and legacy TUI entry compatibility. Hand Bun source launches over to Node for compatible IPC framing.
  • Extract lightweight theme/screen primitives, serialize asynchronous workflow reductions, require both release entry points, and add a real-PTY startup benchmark and regression coverage.

Known Limitations / Follow-up

  • The complete command system still starts after runtime startup metadata is available. The initial shell supports draft editing, not full command execution.
  • Slash completion in the full UI currently awaits asynchronous Skill discovery, which can delay even built-in suggestions.
  • A follow-up should initialize the frontend command registry independently, show built-ins immediately, enrich Skills/plugin commands without blocking or requiring retyping, and provide explicit loading states for runtime-dependent actions.
  • This PR does not change OAuth or Coding Plan/Start Plan authorization behavior and does not claim that runtime initialization itself becomes instantaneous.

Validation

  • bun run typecheck
  • bun run test:unit — 81 passed
  • bun run test:tui — 23 passed, including blocked-runtime editing, draft safety, saved appearance, uninterrupted regular/fullscreen handoff, cancellation, and runtime death
  • bun run test:node — 17 passed
  • bun scripts/check-runtime.ts
  • bun run check:tui — real-runtime first-run, completion, settings/login, and terminal smoke coverage passed
  • bun test test/runtime/guarded-permission-tui.test.ts — native permission deny/approve regression passed against an isolated local mock provider
  • bun run sync:local and git diff --check

The full native-runtime suite is not claimed green: earlier broad runs encountered timing-sensitive timeouts; the targeted native permission regression above passes. Tests use isolated homes and mock credentials/providers, not the user's account or inference quota.

Startup Measurement

bun run bench:startup 5, Node v26.4.0, built launcher and official runtime in a real PTY:

Metric Median
First visible themed shell 219 ms
Runtime-ready model/mode status 2,122 ms

First paint ranged from 92–293 ms. The benchmark uses a temporary isolated home, disables update/catalog refresh, and submits no prompts. Its first run includes runtime data initialization; these are process-start measurements, not OS cold-cache measurements. Readiness is measured from model/mode status rather than the welcome frame, because the welcome frame now appears before the backend is ready.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

pkg-pr-new preview for commit a4561cc940d11bc49ca977f3476cf8c3cebb11ff.

npx --yes https://pkg.pr.new/zcode-app-cli@a4561cc

Full repository URL

This preview uses the selected commit. PR updates publish automatically after CI succeeds; kingsword09 can also request a preview with /pkg-pr-new.

Workflow logs

@kingsword09
kingsword09 marked this pull request as draft November 1, 2026 05:25
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