Skip to content

fix: keep the panel in step with its pi when a connection closes - #28

Merged
YishenTu merged 20 commits into
mainfrom
fix/connection-close-state
Nov 25, 2026
Merged

YishenTu merged 20 commits into
mainfrom
fix/connection-close-state

Conversation

@YishenTu

Copy link
Copy Markdown
Owner

An audit of the background, bridge and panel for implicit state turned up several places where what the panel shows could drift from what is really happening. The main one: when a bridge went away mid-run, the chat kept showing "Working…", with a ticking clock and dead queue buttons, until something replayed it. This fixes those, makes a few stages explicit in one place, and simplifies the code around them.

Fixes:

  • When a connection closes (the bridge dies, a restart, a pi-path change), the chat ends its open run with a plain run_end and empties its queue on screen. "Interrupted" stays for the user's Stop, matching how pi's history rebuilds the run. The panel's own busy flag is gone: Esc asks ChatView whether a run is showing.
  • A tool that never finished (the bridge died mid-tool) shows as failed once its run ends, live or in saved history, instead of spinning for good.
  • After a restart, the new pi's history preview shows while it starts, instead of being ignored because the old pi's history was still set.
  • Restarting a chat and switching away while its browser link is still closing no longer starts a pi for the chat you left.
  • A panel that closed before Chrome reported it no longer breaks the background: posting to it drops it. ready still saves the session file, and text handed back right then is held for the next panel instead of lost.
  • Paused jobs are kept past their time, both when a leftover alarm fires and when the browser restarts. pi's schedule_job list shows a paused job with no next run.
  • A held-text write that fails is logged (without the text), and later writes still go through.

Simplifications:

  • Ordered requests wait for startup inside inOrder, so the per-export await ready lines are gone, and a failed startup fails every request, not just the first.
  • Every request the bridge counts goes through one typed post, so "count everything but replies to pi's tools" holds by construction. Also removes a double stop in switchTo.
  • Held message-box text moves to src/background/held.ts (hold, handOver, drop).
  • PiClient's port is one connected-or-waiting state. The Scheduled screen has one mode (list, or a job's form), so the job being edited no longer outlives the form. PiInput's queue tracking replaces a null/undefined/images three-way marker with one value. ChatView tracks only the live run's tool calls. ready updates the chat before its storage write.
  • src/background/AGENTS.md now states that closing a connection must end its run and empty its queue on screen.

Left as is, on purpose:

  • Queued messages are still lost when a bridge dies or restarts. The queue now clears instead of showing dead buttons, but its text doesn't come back to the message box: those messages may also come back as unanswered prompts, so they could show up twice, and their images can't be recovered.
  • There is no separate "Connection closed" label for a lost bridge.

Each behaviour fix has a test that failed first. The startup test was also checked against the unsafe queue = ready variant, which it catches. Lint, tests (316, also randomized) and build pass. The plan came from a committee review by Fable and GPT-6.2-Astra. Astra then reviewed the implementation over three rounds; the last found no blockers. Not yet tried in the loaded extension.

@YishenTu
YishenTu merged commit 7e11792 into main Nov 25, 2026
2 checks passed
@YishenTu
YishenTu deleted the fix/connection-close-state branch November 25, 2026 04:17
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