Add a live-session registry and private control socket to `clai2`
Why we make these changes
Independent CLAI processes cannot discover each other's live sessions, including idle ones. Add a private per-process registry and same-UID Unix control socket as PR 2 of David's approved peers roadmap. No linked GitHub issue: David requested this feature. Messaging, the session overview, and attach remain outside this PR.
[!NOTE]
This branch includes main (merge c3ddeb4461 resolved eight conflicts keeping both sides; later merges had none). The follow-up fixes from #13127 (registry file-system calls off the event loop, cli/cli.py back under the complexity limit) are now on this branch by fast-forward, as douwebot asked, so main never sees a red head. This PR also adds a THREAT_MODEL.md row for the live-session socket and routes live_registry.py to the ui review check, so it touches THREAT_MODEL.md and .github/scripts/ besides clai2.
New public surface
clai2 sessionslists live sessions on this machine.LiveSession.waiting_for(str | None) andLiveSession.wait_for_user(reason)expose scoped user waits; the runtime tracksask_userautomatically.- Protocol 1 uses typed
HelloRequest,Hello, andControlErrorframes; there is nolistoperation or features field.
User-visible behavior
Before: only sessions in the current process were discoverable as live. Now clai2 sessions fetches fresh sessions in typed hello replies and prints unique live-session ID prefixes, display-only folder names, status, title, and workspace, without resuming a session or starting a turn.
Verification
- Registry tests:
tests/clai2/test_live_registry.py; lifecycle/question-status tests:tests/clai2/test_live_runtimes.py. - Local checks on fde4f7bb1e:
ruff format,ruff checkand Pyright clean on changed Python files; the complexity check passes againstmain; the registry, live-runtime, CLI and review-check tests pass;live_registry.py,live_runtimes.pyand their tests are at 100% line and branch coverage. The fulltests/clai2suite passed on Python 3.13 with the blocking-call detector on, at the #13127 head. - The installed-entry-point smoke test exceeded its 15-second timeout locally; an isolated main-baseline launch also exceeded that limit (15.53 seconds). A diagnostic candidate launch exited successfully. No timeout workaround is included.
What changes for existing users
Unix CLAI processes write private pid/instance/socket metadata once and answer same-user typed hello requests with current sessions; discovery failure does not prevent chat from starting. No list op, features field, messaging tools, or attach support is added.
PR decisions
2026-10-26 · Process-scoped question status observer · iter -
- Decision: Use a default-on process-scoped built-in to track live ask_user waits in the registry; leave messaging and delivery to PR 3.
- Why: Only process-scoped plugin hosts have access to the live-session catalog; hooks clear waits on answer or turn end.
- Source: https://github.com/pydantic/pydantic-ai/tree/clai2-peers-registry-socket
2026-10-27 · pre-push review 1 of 3 at 76dd02da057578073877dd761e0729aec9148dfa · iter -
- Decision: Reserved isolated Review dispatch on light (Luna); outcome pending.
- Why: Candidate tree d59574b16121739b79a60d1e96cc3ca5d8299667; full scope 8876e7d139e197fd86e0d9dd10addd56cd65e1f7..76dd02da057578073877dd761e0729aec9148dfa; policy base 8876e7d139e197fd86e0d9dd10addd56cd65e1f7.
- Source: https://github.com/pydantic/pydantic-ai/tree/76dd02da057578073877dd761e0729aec9148dfa
2026-10-27 · pre-push review 1 of 3 at 76dd02da057578073877dd761e0729aec9148dfa · iter -
- Decision: Dispatch failed before candidate inspection: file tools refused the bundle outside the policy checkout; no verdict.
- Why: Tree d59574b16121739b79a60d1e96cc3ca5d8299667 unchanged; fix is moving the same bundle inside isolated policy checkout.
- Source: https://github.com/pydantic/pydantic-ai/tree/76dd02da057578073877dd761e0729aec9148dfa
2026-10-27 · pre-push review 2 of 3 at 76dd02da057578073877dd761e0729aec9148dfa · iter -
- Decision: Reserved isolated Review on light (Luna), with bundle inside the reviewer root; outcome pending.
- Why: Full scope 8876e7d139e197fd86e0d9dd10addd56cd65e1f7..76dd02da057578073877dd761e0729aec9148dfa; tree d59574b16121739b79a60d1e96cc3ca5d8299667; policy base 8876e7d139e197fd86e0d9dd10addd56cd65e1f7.
- Source: https://github.com/pydantic/pydantic-ai/tree/76dd02da057578073877dd761e0729aec9148dfa
2026-10-27 · pre-push review 2 of 3 at 76dd02da057578073877dd761e0729aec9148dfa · iter -
- Decision: Remediated reproduced stale-socket replacement race by capturing inode before hello; dismissed malformed-JSON claim: ValidationError subclasses already-caught ValueError and both invalid-frame tests pass.
- Why: Reviewed tree d59574b16121739b79a60d1e96cc3ca5d8299667; regression test failed before fix, then registry9 tests passed. Candidate correction needs scoped final review.
- Source: https://github.com/pydantic/pydantic-ai/tree/76dd02da057578073877dd761e0729aec9148dfa
2026-10-27 · pre-push review 3 of 3 at 835e301e5fbff966cbdcfb7e9e9977c81f28bb8a · iter -
- Decision: Reserved final scoped Review on light (Luna); outcome pending.
- Why: Tree e76770d66c8acf854ad9bc036a7209a27edabf98; scope 76dd02da057578073877dd761e0729aec9148dfa..835e301e5fbff966cbdcfb7e9e9977c81f28bb8a; full branch mergebase 8876e7d139e197fd86e0d9dd10addd56cd65e1f7; policy base 2c99448f3cccb4f94663bc369aad0eaffc4c68a1.
- Source: https://github.com/pydantic/pydantic-ai/tree/835e301e5fbff966cbdcfb7e9e9977c81f28bb8a
2026-10-27 · pre-push review 3 of 3 at 835e301e5fbff966cbdcfb7e9e9977c81f28bb8a · iter -
- Decision: No findings: current at 835e301e5fbff966cbdcfb7e9e9977c81f28bb8a.
- Why: Reviewed tree e76770d66c8acf854ad9bc036a7209a27edabf98; scoped76dd02da057578073877dd761e0729aec9148dfa..835e301e5fbff966cbdcfb7e9e9977c81f28bb8a and affected invariants under policy2c99448f3cccb4f94663bc369aad0eaffc4c68a1.
- Source: https://github.com/pydantic/pydantic-ai/tree/835e301e5fbff966cbdcfb7e9e9977c81f28bb8a
2026-10-27 · Expose user-wait status through LiveSession · iter -
- Decision: David selected the public waiting contract: LiveSession.waiting_for and wait_for_user(reason) expose scoped user waits; shell run plumbing tracks ask_user automatically, without a disableable plugin.
- Why: Removes concrete-runtime access and conversation scans from plugin code while documenting a supported extension for approval dialogs; overlapping waits have independent idempotent teardown.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4394384128
- Supersedes: Process-scoped question status observer
2026-10-27 · Preserve private-writer compatibility during consolidation · iter -
- Decision: Use one atomic implementation in config/private_files; retain thin workspace text-keyword and credential keyword-only wrappers, with stale-token cleanup only at the credential boundary.
- Why: Addresses the reproduced workspace failure without widening credential-specific stale-temp cleanup to concurrent state writers.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4394382898
2026-10-27 · Review budget exhausted before 0a1f868a06e1987654e56638b83d33c9d3af1019 · iter -
- Decision: Proceed under the three-dispatch cap: no fourth local pre-push review. Current remediation and main-merge commit is locally checked; obtain fresh hosted review on the pushed head.
- Why: Last reviewed835e301e5fbff966cbdcfb7e9e9977c81f28bb8a; current tree54737f16aaa9fc86ba40b3a46f49f876b17cd5ed; 161 focused tests pass, touched-file Pyright and format/lint pass. Runtime/API corrections follow reproduced feedback and David-selected public waiting contract.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673
2026-10-27 · Normalize socket roots without resolving managed symlinks · iter -
- Decision: Use an absolute environment base while retaining lstat rejection of a symlinked managed directory.
- Why: Both relative TMPDIR and XDG_RUNTIME_DIR reproduced missing discovery before the fix; regression tests cover both and verify a planted socket-directory symlink is still rejected.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4395049426
2026-10-27 · Retain one question observer per runtime · iter -
- Decision: Store the question-status capability once on SessionRuntime so successive turns preserve the stock agent identity; incomplete-reply test servers read the request before closing, and wrong-UID tests accept EOF or reset.
- Why: CI reproduced stock-agent rebuilding and Linux reset semantics. The existing system-prompt regression and 182 focused tests pass; no further local review dispatch is made after the three-call budget.
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/40597702229
2026-10-28 · Static discovery metadata and fresh typed hello · iter -
- Decision: David chose a static file containing only pid, instance, socket; hello returns current sessions; drop list and features; preserve in-memory status-transition subscription, remove flush/timer/per-change writes.
- Why: Follows David separate design review; typed frames are validated at the socket boundary, and oversized replies must fail visibly rather than silently skip a process.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4395246425
2026-10-28 · Machine-wide unique session-id prefixes · iter -
- Decision: David chose short live-session-id prefixes, extended until unique across discovered processes; folder name is display only.
- Why: Identifies same-folder sessions without a central handle allocator or PID-based address.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4395247898
2026-10-28 · Verify b1d8d31b983d6e7017e3e4c55e930784094ea9de after hosted feedback · iter -
- Decision: No additional local review beyond the exhausted three-dispatch budget; push the locally checked maintainer-selected redesign for fresh hosted review.
- Why: Tree3ba41f53c2ff61a8f760daf6b4b421e0443c6d5f; 212 focused tests pass, touched-file Pyright and format/lint pass. Focused registry/lifecycle test-code coverage is100%; previous CI test jobs passed but coverage failed on the removed unused callback.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673
2026-10-28 · Merge current main to restore PR CI at b8e9025eed3c953c090b80fd0869e065e9dbc74c · iter -
- Decision: Resolve the FILE_MAP conflict by retaining current-main descriptions plus the two registry/question-status entries; no fourth local review dispatch after budget exhaustion.
- Why: Current tree1e1fb39cb4e2b7c79f520af4ef23b53f3930aa7b; 73 affected focused tests and touched-file Pyright pass after merge, commit format/lint pass. Branch conflict had prevented a current-head CI run.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673
2026-10-29 · Public waiting contract is required in PR2 · iter -
- Decision: David explicitly chose Public waiting contract against the agent recommendation: expose waiting status through LiveSession/LiveSessions as a documented supported plugin contract; public API docs and tests belong in this same PR.
- Why: Runtime-bound ask_user observation is implementation plumbing and does not replace the public waiting_for/wait_for_user contract or LiveSessions subscription notifications.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4394384128
2026-10-29 · Use None for absent public user waits · iter -
- Decision: David chose waiting_for: str | None with None for no active wait; keep empty reasons invalid and share bookkeeping between live-session adapters.
- Why: Makes absence consistent with optional values on the supported plugin contract; docs and public-path tests change in this PR.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4396374862
2026-10-29 · Treat the workspace-local writer as internal · iter -
- Decision: David chose Internal; remove wrapper: delete the workspace-local compatibility shim/test and call config/private_files directly; keep credential cleanup behavior at its own boundary.
- Why: Maintainer settled the stable-facade boundary; this supersedes the earlier conservative keyword compatibility decision.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4396375843
- Supersedes: Preserve private-writer compatibility during consolidation
2026-10-29 · Reject unknown control protocol versions · iter -
- Decision: David chose strict ProtocolVersion = Literal[1] for request/reply frames; unknown versions receive typed unsupported errors instead of version negotiation.
- Why: Supersedes the original design negotiation behavior by explicit maintainer choice and centralizes the version in one typed constant.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4396375472
2026-10-29 · Exact hybrid dialog confirmation · iter -
- Decision: David confirmed Q1 is the exact hybrid in local-notes/david-decision-source-of-truth.md, not either offered option: only pid/instance/socket written once, hello returns sessions, no list, in-memory status subscription. Q2 is kw-only frames and ONE discriminated-union TypeAdapter; DROP features with no feature negotiation. Q3 is a short session-ID prefix unique MACHINE-WIDE; folder name is display only.
- Why: Explicit confirmation prevents the earlier option wording from overriding the authored design; the public waiting contract remains settled and in this same PR.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4395246425
2026-10-29 · Keep Windows clipboard tests independent of Unix runtime paths · iter -
- Decision: Use a short private /tmp runtime root on POSIX and the native temporary directory on other platforms; session teardown still runs after test OS monkeypatches are restored.
- Why: Windows clipboard CI reproduced FileNotFoundError for /tmp at fixture setup; local clipboard/input checks pass, with actual Windows verification delegated to the CI job.
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/40621996348/job/122598020698
2026-10-29 · Verify public waiting contract at 71a72d84bd5b3a1bc6a0c719e819c543d5d0b27c · iter -
- Decision: Keep the public LiveSession/LiveSessions contract, docs, and tests in PR2; push the checked review corrections without a fourth local pre-push dispatch.
- Why: Tree d0a0ebb862eb2a949c6705a3ca712f118b76917d; 200 focused tests passed before latest main merge;133 affected tests pass after merge,2 native clipboard cases skip locally. Touched-file Pyright, commit format/lint, and the public plugin docs snippet pass. Actual Windows clipboard verification remains CI-owned.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673
2026-10-29 · Decode Linux peer UIDs without sign loss · iter -
- Decision: Decode ucred as signed pid_t plus unsigned uid_t/gid_t (iII), preserving the full UID before the same-user comparison.
- Why: The targeted parser test reproduced4294967294 becoming-2 with3i; both ordinary and high unsigned UID cases now pass. Registry34 tests, touched-file Pyright, and commit format/lint pass. No fourth local review dispatch is made after the logged three-call budget.
- Source: https://github.com/pydantic/pydantic-ai/commit/c003457067104f9f4f662efbe37e0c7859dfcdac
2026-11-10 · Merge main at c3ddeb4461 · iter -
- Decision: Resolved eight conflicts by keeping both sides: main's
busy,updatesubcommand, permissions capabilities and reworded FILE_MAP rows, plus this PR'ssessionssubcommand, waiting contract and question-status capability; dropped this PR's duplicate_resolve_pathsin favour of main's. - Why: The PR conflicted with main. An independent review of the resolution reported no findings.
- Source: https://github.com/pydantic/pydantic-ai/commit/c3ddeb446116a5a7b23e2940f49a6e028fa47ed1
2026-11-10 · Blocking-call fix goes in a stacked PR · iter -
- Decision: This branch takes only the main merge; the event-loop fix for main's blocking-call detector is in #13127, stacked on this branch.
- Why: Standing workflow for this repo: an open PR gets no further commits beyond main merges, so follow-up changes are reviewed in isolation. Until #13127 lands, the registry tests fail on this head.
- Source: https://github.com/pydantic/pydantic-ai/pull/13127
2026-11-10 · Complexity fix also goes in the stacked PR · iter -
- Decision: The
cli/cli.pyextraction that bringsrun()and_list_live_sessions()back under the limit is in #13127, not here. - Why: Same workflow rule. The request for this work was to keep everything on this branch; the standing workflow rule took precedence, so this PR cannot go green on its own.
- Source: https://github.com/pydantic/pydantic-ai/pull/13127
2026-11-10 · 2026-10-29 review findings were already fixed · iter -
- Decision: No new code for the CHANGES_REQUESTED review. Replied to and resolved its three open threads; the review itself is not dismissed.
- Why: Terminal escapes and the
OSErrorexit, the reference rewrite and concurrent probing are in bee4826cfb; the boundeddrain()is in 15f64e9e38. Each has a test on this head. - Source: https://github.com/pydantic/pydantic-ai/pull/11673#pullrequestreview-5705882582
2026-11-10 · Blocking-call finding stays open here · iter -
- Decision: Replied to the 2026-11-10
tests-and-dependenciesfinding and left its thread unresolved. - Why: The finding is correct for this head; the fix is in #13127.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4528316345
2026-11-10 · Merge main again at b75225328a · iter -
- Decision: Merged
origin/main(fe3bf389c4); no conflicts. - Why: v2.67.0 was released after the first merge, so the API compatibility check would report its new public objects as removed on the older head.
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/42917955546/job/130193378138
2026-11-10 · Stacked PR is #13127, replacing #13078 · iter -
- Decision: Closed #13078 and reopened its five commits as #13127 on top of this branch's head.
- Why: Merging
maininto both stacked branches separately mademaintheir merge base, so #13078 showed all of this PR's files and was reported as conflicting. - Source: https://github.com/pydantic/pydantic-ai/pull/13127
2026-11-11 · Fold #13127 into this branch · iter -
- Decision: Fast-forwarded this branch to #13127's head (09640f54e0); GitHub marks #13127 merged. Supersedes the stacked-PR entries above.
- Why: douwebot blocked merging the stack bottom-first, because #11673 alone would land a red
main. It is also what the task asked for originally. - Source: https://github.com/pydantic/pydantic-ai/pull/11673#pullrequestreview (douwebot run 43064733422)
2026-11-11 · Windows: no discovery, no warning · iter -
- Decision:
LiveRegistry.serving()runs the block unpublished whenos.name != 'posix'instead of raisingOSError. - Why: The raise made every Windows launch log a warning to stderr. Unix failures still warn.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4540918793
2026-11-11 · Threat model and review routing · iter -
- Decision: Added a "CLAI 2 live-session socket" row to
THREAT_MODEL.mdandlive_registry.pyto theuicheck's trigger paths. - Why:
THREAT_MODEL.mdrequires both in the PR that adds an input path. - Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4540918808
2026-11-11 · Keep the unused hello fields · iter -
- Decision: Declined douwebot's optional finding to drop
conversation_id,model,waiting_forandstatus_since. - Why: The next peers-roadmap PRs consume them; removing and re-adding is churn.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4540918816
2026-11-11 · Clear douwebot's optional findings · iter -
- Decision: 9bf7c40945 treats a same-UID listener that answers outside the protocol as an active socket (
OSError, logged), makesQuestionStatus.waitsinit=False, repr=False, and adds theconfig/private_files.pyrow toFILE_MAP.md. - Why: Each is a one-line fix, and the clean-approval gate needs a head with no douwebot inline findings, optional ones included.
- Source: https://github.com/pydantic/pydantic-ai/pull/11673#discussion_r4541033914
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. (None.)
- PR title is fit for the release changelog.