Let the `clai2` web UI watch a session busy in another CLAI instead of silently forking it

MP
2mo ago
+186-87

Clicking a session marked with the blue dot (busy in another CLAI) in the clai2 web UI no longer drops you into a silent copy of it. You can now watch it read-only.

  • No linked issue: reported by the CLAI maintainer.

Why

The sidebar marks a session busy while another CLAI process runs a turn in it. Clicking a session sends /resume ID, and Session resume forks a conversation that another live process is busy in (ConversationConflict, then "Resumed a fork of it instead"), so two processes never write one conversation. The terminal prints that notice. The web UI showed nothing, so the click looked like it "just made a copy". I reproduced it in-process: GET /api/sessions/{id} reported a busy session as openable, so the page called /open, which saved a fork.

What changes

  • Transcript (web protocol) gains busy: whether another live CLAI runs a turn in the session, so /resume would continue a copy. The check is the sidebar's _busy (ensure_inactive), run off the event loop.
  • Sessions.saved (the host.sessions.saved the preview reads) returns a running turn's history up to the last step it saved in the step store, as /resume already reads it. A turn saves the conversation row only at its start and end. Without this change the preview could not show progress. Remote.transcript is the only caller.
  • Frontend: a busy session opens in the existing read-only preview instead of resuming. The preview re-reads the transcript every 3 s while the session stays busy. It drops stale answers and leaves the state alone when nothing changed. useStickToBottom keeps the scroll position.
  • The dot gets a title/aria-label "Running in another CLAI".
  • Docs: one sentence in clai2_web_README.md, and the saved(ID) note in PLUGINS.md.

The fork protection, the terminal, and /resume stay as they were.

User-visible behavior

  • Clicking a dotted session shows its transcript with the banner "Running in another CLAI. You can watch it here.", plus Continue in a copy (the explicit fork: the existing resume path) and Back to current.
  • The transcript updates as the other CLAI's turn saves its steps.
  • When that turn ends, the banner reads "Its turn in the other CLAI ended. You can continue it here." and offers Continue here, a normal resume with no fork.

Verification

  • New test_a_session_busy_in_another_clai_is_watched_not_copied (in-process; another process is simulated by a running summary whose owner_pid is a live process). It checks that reading the busy session saves no new conversation and shows the step-store frontier, that /open (Continue in a copy) saves exactly one fork, and that busy turns false once the turn's outcome is saved.
  • tests/clai2/test_web.py, test_sessions.py, test_resume_integration.py, test_web_session_tools.py: 96 passed. Branch coverage of the changed lines in remote.py and runtime/sessions.py is 100%. Pyright strict and ruff are clean on the touched files. npx tsc --noEmit and npm run build pass, and the bundle is committed.
  • Real run: two CLAIs share one scratch config (fail keyring, scratch XDG_*). A terminal clai2 ran a slow five-step turn (a drop-in scratch model calling shell sleep 6 per step) in tmux, alongside clai2 --web -m test. Headed Playwright Chromium:
    • the dot's tooltip reads "Running in another CLAI";
    • clicking the dot shows the banner, the transcript grows mid-turn, and the sidebar gains no copy;
    • after the turn ends, Continue here resumes the same session ID;
    • during a later turn, Continue in a copy switches to … (fork), with exactly one new session.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver. (None.)
  • PR title is fit for the release changelog.