Add a live-session registry and private control socket to `clai2`

Merged
DS
24d ago
+1510-77

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 sessions lists live sessions on this machine.
  • LiveSession.waiting_for (str | None) and LiveSession.wait_for_user(reason) expose scoped user waits; the runtime tracks ask_user automatically.
  • Protocol 1 uses typed HelloRequest, Hello, and ControlError frames; there is no list operation 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 check and Pyright clean on changed Python files; the complexity check passes against main; the registry, live-runtime, CLI and review-check tests pass; live_registry.py, live_runtimes.py and their tests are at 100% line and branch coverage. The full tests/clai2 suite 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 -

2026-10-27 · pre-push review 1 of 3 at 76dd02da057578073877dd761e0729aec9148dfa · iter -

2026-10-27 · pre-push review 1 of 3 at 76dd02da057578073877dd761e0729aec9148dfa · iter -

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

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

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

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

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 -

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, update subcommand, permissions capabilities and reworded FILE_MAP rows, plus this PR's sessions subcommand, waiting contract and question-status capability; dropped this PR's duplicate _resolve_paths in 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.py extraction that brings run() 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 -

2026-11-10 · Blocking-call finding stays open here · iter -

2026-11-10 · Merge main again at b75225328a · iter -

2026-11-10 · Stacked PR is #13127, replacing #13078 · iter -

2026-11-11 · Fold #13127 into this branch · iter -

2026-11-11 · Windows: no discovery, no warning · iter -

2026-11-11 · Threat model and review routing · iter -

2026-11-11 · Keep the unused hello fields · iter -

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), makes QuestionStatus.waits init=False, repr=False, and adds the config/private_files.py row to FILE_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.