Show a `clai2` session another CLAI runs read-only and reuse its fork instead of saving a new `(fork)` each time

Merged
MP
1mo ago
+449-89

Fixes #11585

Why we make these changes

Clicking a sidebar session that another CLAI process is running silently saved a new <title> (fork) and opened it. Every new process (a restart, the idle close, another --web) did this again, because the fork was only remembered in memory, so identical-looking rows piled up. With the user's agreement, this PR covers items 1 and 2 of the issue. The sidebar fork badge (item 3) is left for a follow-up.

  • Web: a busy session now opens as the read-only preview, with the banner "Running in another CLAI (pid N)." and a Fork to continue here button. Nothing is saved until you click it.
  • Everywhere (web, /resume, host.live.open): the copy CLAI saves to continue a busy session records forked_from. Continuing that session later reuses its newest unarchived copy that no other process runs instead of copying again. A fork the user made themselves is never reused. LiveRuntimes' in-memory copied tracking is gone.

New public surface

  • pydantic_ai_harness.step_persistence.conversations.ConversationSummary.forked_from: str | None = None (the id of the conversation a copy was made from; named to match core's ConversationStore in #10658)
  • SqliteConversationStore.listing(..., forked_from: str | None = None)
  • clai2 web protocol: Transcript.owner_pid: int | None (the other process's PID)

User-visible behavior

# before: opening a busy session from two successive CLAI processes
154591f6 running Busy
5e92f2e3 ready   Busy (fork)
fa74c77a ready   Busy (fork)
# after
6a55e1ef running Busy
7c04783d ready   Busy (fork)      <- both processes open this one

Verification

  • tests/clai2/test_live_runtimes.py::test_a_conversation_another_process_runs_has_one_copy_across_processes, ::test_a_copy_this_process_left_running_opens_without_another_copy
  • tests/clai2/test_sessions.py::test_busy_session_resumes_in_its_existing_fork, ::test_a_fork_this_process_left_running_is_continued_not_forked_again
  • tests/clai2/test_web.py::test_a_session_another_process_runs_shows_read_only_until_forked
  • tests/harness/step_persistence/test_conversations.py::test_a_fork_records_its_source_which_listing_filters_by
  • tests/clai2/browser/test_web_browser.py::test_a_session_another_clai_runs_shows_until_forked (not run locally: Chromium lacks libnspr4 here; the browser CI job runs it)

What changes for existing users

A busy session in the web UI opens read-only until you choose to fork it, and resuming one reuses its existing fork. Older builds ignore the new forked_from metadata key.

PR decisions

2026-10-27 · pre-push review 1 of 3 at 967daae45158f8edb7bff37293f56afb3738e84f · iter -

2026-10-27 · pre-push review 2 of 3 at f5c123376fd0e450a45496b28c9dbeabcbc366d4 · iter -

2026-10-27 · pre-push review 2 of 3 at f5c123376fd0e450a45496b28c9dbeabcbc366d4 · iter -

2026-10-27 · pre-push review 3 of 3 at ee19650020a8b3ccc0ace045f35fdd582e031877 · iter -

2026-10-27 · pre-push review 3 of 3 at ee19650020a8b3ccc0ace045f35fdd582e031877 · iter -

2026-10-27 · only busy-path copies record forked_from · iter -

2026-10-27 · harness field renamed forked_from -> continues · iter -

  • Decision: one narrow field ConversationSummary.continues (+ listing(continues=...)) for CLAI's continuation copies; general fork lineage left to issue item 3
  • Why: douwebot: forked_from read as lineage but meant continuation copy; a CLAI tag would be overwritten by background naming; Mike chose the rename
  • Source: https://github.com/pydantic/pydantic-ai/pull/11614#discussion_r4392145836

2026-10-27 · keep forked_from (rename to continues reverted) · iter -

  • Decision: field stays ConversationSummary.forked_from, docstring tightened to: the id of the saved conversation this one was copied from; app decides which copies record it
  • Why: Mike: match core ConversationStore.forked_from in #10658; rename reverted in a new commit, no history rewrite
  • Source: https://github.com/pydantic/pydantic-ai/pull/10658

2026-10-27 · forked_from kept despite douwebot re-block · iter -

2026-10-27 · busy sidebar rows are never openable · iter -

  • Decision: session_entry reports openable=False for a busy row, so #11618's fast path fetches the transcript (preview) instead of opening (forking)
  • Why: merge of main brought SessionEntry.openable; without this a click would silently fork again
  • Source: https://github.com/pydantic/pydantic-ai/pull/11618

Checklist

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