perf(client): stop thread streams when unused (#9740)

Close a thread's live detail stream when its last consumer leaves. Retain a registry-local completed state and replay cursor for five idle minutes.

Keep warm lookup independent of collectible raw atom definitions. Preserve paging and deletion state, reject stale owners, and cache only completed data/cursor updates.

Skip repeated saves of unchanged data while retaining dirty-data flushes and failed-write retries. Verify real GC/remount behavior and focused lifecycle cases.

Created with GPT-6 Astra (preview) in Codex.
This commit is contained in:
Theo Browne authored and GitHub committed 2026-09-04 11:56:05 -07:00
1 parent 0de956ed2f
commit d7cf8aaa8d
6 files changed
+911 -129

No files matched your search

+15
View File
@@ -170,6 +170,20 @@ Application code must not construct RPC clients, retry loops, or raw
orchestration commands. Persistence paths belong to the platform registration
and cache stores, with explicit migration or invalidation policy.
### Thread detail ownership
Mounted detail consumers share one live thread subscription. The subscription
ends when the last consumer leaves. Hidden routes that remain mounted still
count as consumers.
A separate registry-local atom retains the last thread state and replay cursor
for five idle minutes. A warm mount renders that state and resumes the stream
without another snapshot download. The cache holds completed state and cursor
updates together. It retains pagination data but clears canceled loading state.
An ownership token prevents an old scope from replacing its successor's cache.
Closing a thread skips snapshots that were already saved. Changed snapshots and
failed background writes still get a final save attempt.
## Verification
Core state-machine tests use `@effect/vitest` and deterministic service layers.
@@ -184,6 +198,7 @@ Required coverage includes:
- relay token reuse and refresh;
- progressive relay discovery;
- shell and thread cache hydration;
- thread stream shutdown, warm resume, and snapshot expiry;
- durable subscriptions switching sessions;
- command metadata and idempotent queued-command metadata.