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+449+012345678901234567890123456789-89-89-01234567890123456789
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 recordsforked_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-memorycopiedtracking is gone.
New public surface
pydantic_ai_harness.step_persistence.conversations.ConversationSummary.forked_from: str | None = None(theidof the conversation a copy was made from; named to match core'sConversationStorein #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_copytests/clai2/test_sessions.py::test_busy_session_resumes_in_its_existing_fork,::test_a_fork_this_process_left_running_is_continued_not_forked_againtests/clai2/test_web.py::test_a_session_another_process_runs_shows_read_only_until_forkedtests/harness/step_persistence/test_conversations.py::test_a_fork_records_its_source_which_listing_filters_bytests/clai2/browser/test_web_browser.py::test_a_session_another_clai_runs_shows_until_forked(not run locally: Chromium lackslibnspr4here; 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 -
- Decision: remediated: single fork lookup in Sessions.resume (Continuation passed through), stale own-pid fork continued in place, PLUGINS/reference/LiveSessions.open docs
- Why: tree 3dd9f344c098bde46a94f2d32d5dec16eff18cf1; scope origin/main de53949d5...967daae45; LiveRuntimes.open->serve double lookup kept: only a fork saved by another process in the ms between both lookups makes open raise, a retry succeeds
- Source: https://github.com/pydantic/pydantic-ai/tree/agent/clai2-11585
2026-10-27 · pre-push review 2 of 3 at f5c123376fd0e450a45496b28c9dbeabcbc366d4 · iter -
- Decision: dispatched
- Why: tree a4b8edc402ce49cea27e1442c3d4d5c454a19025; follow-up scope 967daae45..f5c123376fd0e450a45496b28c9dbeabcbc366d4
- Source: https://github.com/pydantic/pydantic-ai/tree/agent/clai2-11585
2026-10-27 · pre-push review 2 of 3 at f5c123376fd0e450a45496b28c9dbeabcbc366d4 · iter -
- Decision: remediated: stale own-pid mark is judged on the fork itself (forked_from set), so the web open path agrees; docstring/PLUGINS wrap nits
- Why: tree a4b8edc402ce49cea27e1442c3d4d5c454a19025; scope 967daae45..f5c123376; chose forked_from-keyed staleness over threading Continuation through Served.serve/Sessions.start (smaller, no protocol change)
- Source: https://github.com/pydantic/pydantic-ai/tree/agent/clai2-11585
2026-10-27 · pre-push review 3 of 3 at ee19650020a8b3ccc0ace045f35fdd582e031877 · iter -
- Decision: dispatched
- Why: tree f516847c71e945db1e3d7b50016fb63d2e5dda17; follow-up scope f5c123376..ee19650020a8b3ccc0ace045f35fdd582e031877
- Source: https://github.com/pydantic/pydantic-ai/tree/agent/clai2-11585
2026-10-27 · pre-push review 3 of 3 at ee19650020a8b3ccc0ace045f35fdd582e031877 · iter -
- Decision: remediated: stale_fork_mark shared by continuing_fork and _restore; budget exhausted, pushed f7289691b0d4aa0ab51496ce289ee583c5e3e71c after local checks
- Why: tree f516847c71e945db1e3d7b50016fb63d2e5dda17; scope f5c123376..ee1965002
- Source: https://github.com/pydantic/pydantic-ai/tree/agent/clai2-11585
2026-10-27 · only busy-path copies record forked_from · iter -
- Decision: explicit forks (row menu, host.sessions.fork) no longer set forked_from, so continuing a busy session never takes over a fork the user made
- Why: douwebot review on f7289691; review budget 3/3 already spent, local checks rerun
- Source: https://github.com/pydantic/pydantic-ai/pull/11614#discussion_r4391725276
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 -
- Decision: keep ConversationSummary.forked_from (conversation ID, set only on CLAI busy-continuation copies)
- Why: Mike decided after douwebot noted core #10658 stores an entry ID; name consistency with core preferred
- Source: https://github.com/pydantic/pydantic-ai/pull/11614#discussion_r4393240028
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.