Skip to content

feat(desktop): decouple first paint from Runtime Host readiness #5488

Closed

Description

@Astro-Han

Problem

Desktop serializes its entire startup on Runtime Host readiness: connect, handshake, and the generation check all run before the first pixel, and on a version mismatch the full managed update pipeline (npm download, package staging — copy plus per-file fsync of ~124 MB / ~6,800 files — retirement, activation, verification) executes inside a modal startup-progress window. On a slow network or disk this is minutes of blocked startup, and in degraded cases (#5476) it reads as an indefinite hang. This is structural rather than a version regression — the handoff/update path is byte-identical between dev.37 and dev.39. The progress window exists because the UI cannot do anything without the host today, but most of the first screen (shell, navigation, model picker, empty composer, and arguably the session list projection) does not actually need it.

Desired outcome

  • First paint renders without waiting for the Runtime Host: app shell plus an empty-state home (model picker + composer) immediately; the session list hydrates afterwards, either from a direct reader lease on the State Root stores (readers do not need the root owner) or from a cached projection.
  • Host reconciliation (connect, upgrade handoff, staging, replacement) starts in the background at launch and reports progress through a non-modal status surface instead of a blocking modal.
  • Only actions that genuinely need the host — sending a message, mutating a session, viewing live task state — wait on readiness, which by then has usually already finished.
  • The authority model is unchanged: the Runtime Host remains the sole write authority; this removes it only from the first-paint critical path.

Alternatives or workarounds

  • Keep the blocking handoff and only add heartbeats plus finer-grained phases (the narrower ask in fix(runtime-host): desktop handoff hangs indefinitely in staging phase during background service replacement #5476): improves observability but keeps the startup serialization.
  • Connect lazily on the first host-dependent action: moves the entire wait onto the first message, which is worse than background reconciliation.
  • Allow a version-mismatched but protocol-accepted host to serve degraded read-only traffic: the handshake is already accepted at the protocol level and the generation gate is what forces replacement — a wider discussion, not required for the first two outcomes.

Activity

  1. added
    enhancement
    on Sep 18, 2026
  2. Astro-Han commented on Sep 18, 2026

    @Astro-Han
    ContributorAuthor

    @M4n5ter M4 师傅看看

  3. M4n5ter commented on Sep 18, 2026

    @M4n5ter
    Member
    English

    I support this direction. The Desktop main UI should not wait for the Host to connect or finish updating. Prepare the Host in the background, show progress non-modally, and gate only actions that actually require it, such as sending messages.

    For the initial scope, I suggest avoiding direct Desktop reads of the State Root. Use an empty state or a cache marked as stale for the session list, then refresh after connection. This avoids additional database-version and migration coupling and works consistently with remote Hosts.

    The timeout and recovery problems in #5476 still need to be fixed; we should not simply move an indefinite wait into the background. Acceptance should verify that, even if the Host never becomes available, users can still edit and retain drafts, retry the connection, and quit normally.

    简体中文

    认同这个方向,Desktop 主界面不应等待 Host 连接或更新完成。Host 在后台准备,通过非模态状态提示进度,只限制发送消息等真正依赖 Host 的操作。

    建议首版不引入 Desktop 直接读取 State Root:会话列表使用空态或标明过期的缓存,连接后刷新,避免增加数据库版本和迁移耦合,也便于统一支持远程 Host。

    另外,#5476 的超时与恢复问题仍需解决,不能只是把无限等待移到后台。验收应确保:即使 Host 始终不可用,用户仍能编辑并保留草稿、重试连接和正常退出。

  4. Astro-Han commented on Sep 18, 2026

    @Astro-Han
    ContributorAuthor

    Following up — after tracing the startup path in code and comparing with how LobeHub's desktop app handles first paint, here is the concrete plan I'd like to implement. Feedback welcome.

    Decisions

    • No separate progress window. StartupProgressWindow and the startup-presentation reuse machinery are deleted entirely. Host reconciliation (connect, handoff, staging, replacement) runs silently in the background and only surfaces when it reaches an attention state that genuinely needs a user decision (retry / interrupt / recovery), rendered inside the main window.
    • First frame may be a loading state. The existing .maka-preload skeleton in index.html covers until React mounts — the same pattern LobeHub uses (#loading-screen in index.html, theme resolved synchronously from localStorage + prefers-color-scheme). prefetchOnboardingSnapshot (retry + 2.5s timeout + prop threading) is deleted; onboarding and model options hydrate asynchronously with explicit loading states so "not loaded yet" is never rendered as "not configured".
    • Drop pre-dev.9 update compatibility. The legacy lock half-layer — withLegacyFileUpdateLockLease, .lock directory markers, .supervised recovery, withLegacyOperatorLeases — exists only for managed hosts older than v0.2.0-dev.9 (before feat(runtime-host): add safe managed Host updates #3591). Those builds are no longer a supported update source; the PR will call this out explicitly.
    • Fix progress-view field leakage. The ...current spread in host-handoff.ts leaks attention-state fields (reason, diagnostic, operation, ...) into progress views — this is exactly the misleading staging + retry_required combination reported in fix(runtime-host): desktop handoff hangs indefinitely in staging phase during background service replacement #5476. Progress views get explicit fields.

    What stays

    • Runtime Host remains the sole write authority. The handoff state machine, identity fencing, and cancel/retry semantics are unchanged — only the presentation surface is replaced via the existing openSurface seam.
    • The session list before readiness hydrates from the existing session-experience.sqlite cache (which already distinguishes cached vs authoritative and already supports targets without a live submit). Reader-lease direct reads are ruled out — readers take a shared flock on the same file the owner locks exclusively, so a read lease cannot coexist with a running Host.
    • Reconciliation still starts at launch; only host-dependent operations (send, mutate, live state) await readiness. Pure lazy start is rejected — it just moves the wait onto the first message.

    Implementation sketch

    1. runtime-host-boot: create the main window and register all IPC up front; start reconciliation fire-and-forget.
    2. IPC handlers that need the host await a single readiness promise instead of gating registration.
    3. Replace openSurface's modal window with an in-window attention surface.
    4. Hydrate the session list from session-experience.sqlite, refreshed authoritatively when the host is ready.
    5. Delete prefetchOnboardingSnapshot, StartupProgressWindow, startup-presentation, and the legacy lock half-layer.

    I am taking this one; will open a draft PR.

  5. self-assigned this
    on Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions