The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
docs(swarm): spec and plan for a small, shared light read in Desktop/web changes (DB roadmap 2.3)
0xken1594a10a249322
diff --git a/docs/superpowers/plans/2026-10-30-swarm-changes-shared-light-read.md b/docs/superpowers/plans/2026-10-30-swarm-changes-shared-light-read.mdnew file mode 100644index 000000000..ad565bacf--- /dev/null+++ b/docs/superpowers/plans/2026-10-30-swarm-changes-shared-light-read.md@@ -0,0 +1,193 @@+# Swarm `changes`: a small, shared light read — Implementation Plan++> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.++**Goal:** A Desktop/web `GET /api/super-tabs/:tabId/changes` miss reads only what its reply needs, once per Swarm per stamp per pod, whoever reads.++**Architecture:** `loadLight` stops loading every live start's conversation and the progress part; it adds legacy agents' active conversations and matches `awaitingWorkers`' busy rule. The poll reads one shared light base (no per-person ids in its cache name) and adds per-reader conversations (waiting tags, `unheld`) through a new per-group cached read. `SwarmCache` indexes entries per Swarm so per-group entries do not slow every bump.++**Tech Stack:** TypeScript, Fastify, Prisma on MongoDB, vitest, `mongodb-memory-server` for integration tests.++**Spec:** `docs/superpowers/specs/2026-10-30-swarm-changes-shared-light-read-design.md`++## Global Constraints++- The reference reply is what the full state gives (`readParts`, as `firstLoad` reads it): active conversations only (spec section 0).+- No stored data changes; no migration; no client change; reply shapes unchanged.+- Held cache values stay the stored state, the same for every reader; permissions stay after the cache (`readerView`, `changesFor`, `readableMarks`).+- Do not commit. Ken commits; each task ends with a diff checkpoint instead.+- Remove what becomes dead (`recentStartGroups`, the all-time mention `distinct`); no inert stubs.+- Commands from `backend/`. Unit: `npx vitest run <file>`. Integration: `npx vitest run --config vitest.super-tabs.config.ts <file>`.++## Review Focus++1. A Buddy reading `changes` after the change: replies still carry no machine or start ids (`changesFor` buddy rules) — Task 5 equality test includes a Buddy reader.+2. A reader tagged in a conversation they can no longer read (removed from a private project): the tag's conversation is loaded but `readable` must not count it — Task 5 test.+3. A finished start, listed by a machine record, whose conversation is dormant and private: the collaborator's reply must not name it (existing #2247 test, must stay green; Task 5 re-runs it).+4. A cache entry for a conversation id that does not exist: held as "none", read once per stamp, never throws — Task 4 test.+5. A Swarm bumped many times while other Swarms hold entries: other Swarms' entries and the byte/entry counts survive — Task 1 test.++---++### Task 1: `SwarmCache` indexes its entries per Swarm++**Files:**+- Modify: `backend/src/superTabs/cache.ts` (`SwarmCache`: `drop`, `held`, `load`, `drop1`, eviction loop)+- Test: `backend/src/superTabs/cache.test.ts`++**Interfaces:**+- Produces: unchanged public API (`drop(tabId, scopes)`, `held`, `load`, `size`); `drop` now touches only that Swarm's entries.++- [ ] **Step 1: Write the failing test** in `describe('SwarmCache')`:++```ts+it('drops only the bumped Swarm\'s entries, keeping counts right through drops, evictions and expiry', async () => {+ // Fill tabs 'a' and 'b' with 3 entries each at their stamps; drop('a').+ // expect(cache.size.entries).toBe(3); expect(cache.size.bytes).toBe(bytesOfB)+ // Then: a machine-only drop('b', ['machine']) keeps b's 'main'-scoped entries.+ // Then: exceed maxBytes so the oldest of b is evicted; expire one past maxAgeMs and read it (held removes it);+ // after each, size.entries and size.bytes equal the sums over what get() still serves without loading.+})+```++- [ ] **Step 2: Run** `npx vitest run src/superTabs/cache.test.ts` — the new test passes or fails only on counts; it must fail if `drop('a')` touched b. If it already passes (behaviour is the same today), keep it as the guard and continue: this task is a cost change.++- [ ] **Step 3: Implement** a `private readonly bySwarm = new Map<string, Set<string>>()` (tabId → entry keys). Store `tabId` on `Entry`. Add to the set in `load`; remove in `drop1`, the stale branch of `held`, the eviction loop and `drop`; delete a Swarm's set when it empties. `drop` iterates `bySwarm.get(tabId)` only.++- [ ] **Step 4: Run** `npx vitest run src/superTabs/cache.test.ts src/superTabs/cacheRedis.test.ts` — all pass.++- [ ] **Step 5: Checkpoint** `git diff --stat` shows only `cache.ts` and `cache.test.ts`.++### Task 2: `loadLight` reads only what light readers need++**Files:**+- Modify: `backend/src/superTabs/parts/light.ts` (`undecidedWork`, `loadLight`)+- Modify: `backend/src/superTabs/read/service.ts:35` (`LoadOptions` loses `recentStartGroups`)+- Test: `backend/integration/superTabRead.test.ts` (new `describe('a change poll reads only what its reply needs (DB 2.3)')`)++**Interfaces:**+- Produces: `loadLight(tx, tabId, opts: { groupIds?; agentIds?; projectIds?; includeRecentStarts?; groups?: 'active' | 'working'; machines?: boolean })` — `recentStartGroups` removed; returned `progress` is always `[]`.++- [ ] **Step 1: Write the failing tests** (use the file's `scene`, `get`, `keys`, `clock` helpers):++```ts+it('reads an agent that is only a member of running work as awaiting its decision, as a full read does', async () => {+ // Scene: agent X has no stored workDecision; X is assignee of finished (status 'done') work in active conversation A+ // with no start; X is in agentIds (not assignee) of running conversation B.+ // After a post (cursor before it): changes.derived.agents[X].workDecision === 'awaiting'+ // and equals (await get(`/api/super-tabs/${tabId}/parts`, owner)).body.data.derived.agents[X].workDecision+})+```++- [ ] **Step 2: Run** `npx vitest run --config vitest.super-tabs.config.ts integration/superTabRead.test.ts -t "member of running work"` — FAIL once Step 3's start-conversation removal is in (today the start conversations can mask it; if it passes today, keep it as the guard).++- [ ] **Step 3: Implement in `parts/light.ts`:**+ - `undecidedWork`: busy = Lead of a loaded conversation, or assignee of its active work (drop `...g.data!.agentIds`); Reviewers (`agentRole(a) === 'reviewer'`) are never undecided — the same rule as `model.ts awaitingWorkers`.+ - `loadLight`: delete `recentStartGroups` and the `distinct` on `SwarmStart`; `working` takes `starts.map(s => s.data!.request.conversationId)`.+ - `loadLight`, `groups === 'working'` only: after members/agents load, add active conversations of agents with no `data.projectId` through `['agents', { agentIds: { $in: legacy }, dormant: false }]` (as `parts/load.ts loadObserved`); run it beside `undecidedWork` in one `Promise.all`; no query when `legacy` is empty.+ - `loadLight`: no `SwarmProgress` read; return `progress: []`.++- [ ] **Step 4: Run** `npx vitest run --config vitest.super-tabs.config.ts integration/superTabRead.test.ts integration/superTabGroupPlans.test.ts` and `npx vitest run src/superTabs/parts/light.test.ts src/superTabs/read` — all pass, including `an agent stored with no project stays hidden from a collaborator…` and the host-form tests.++- [ ] **Step 5: Checkpoint** `git diff --stat`.++### Task 3: A person's waiting-tag conversations++**Files:**+- Modify: `backend/src/superTabs/mentions.ts` (export a helper beside `readable`)+- Test: `backend/integration/superTabRead.test.ts` (same new describe)++**Interfaces:**+- Produces: `waitingTagConversations(tx: Tx, tabId: string, personId: string, now: number): Promise<string[]>` — distinct `conversationId`s of the rows `readable(..., open = true)` reads: `tabId`, `personId`, `createdAt > now - MENTION_EXPIRY_MS`, `waiting`, newest first, `take: 500`. `readable` uses the same `where` (one shared constant, not a copy).++- [ ] **Step 1: Write the failing test:**++```ts+it('names only the conversations of a person\'s waiting tags', async () => {+ // Tags for owner: waiting in C1, resolved in C2, waiting but older than 30 days in C3.+ // expect(await waitingTagConversations(db, tabId, owner.sub, clock)).toEqual([C1])+})+```++- [ ] **Step 2: Run** `-t "waiting tags"` — FAIL: not exported.+- [ ] **Step 3: Implement** the helper and share the `where` with `readable`.+- [ ] **Step 4: Run** the test and the file's existing tag tests (`marks which tags wait…`) — PASS.+- [ ] **Step 5: Checkpoint** `git diff --stat`.++### Task 4: `readLightGroups`: named conversations held per group++**Files:**+- Modify: `backend/src/superTabs/cachedReads.ts`+- Test: `backend/integration/superTabCache.test.ts` (`describe('composing a read from what the cache holds')`)++**Interfaces:**+- Consumes: `parts/light.ts loadLightGroups(tx, tabId, 'key', { key: { $in: ids } })`; `CacheView.get`.+- Produces: `readLightGroups(db: Db, view: CacheView, tabId: string, ids: readonly string[]): Promise<Part<GroupData>[]>` — one entry per id named `light-group:<id>`, scope `'main'`, value `Part<GroupData> | null` (null = deleted or unknown); misses of one call batched into one query, as `readLastChangedAts` batches; result in `ids` order, nulls left out; without stamps reads Mongo directly.++- [ ] **Step 1: Write the failing test:**++```ts+it('holds named light conversations per group: a second reader and an unknown id read nothing at the same stamp', async () => {+ // privateScene(); pick a dormant conversation D (make one dormant via a command or guardedWrite).+ // const { cache } = pod(); view = await cache.at([tabId])+ // first = await partReads(() => readLightGroups(db, view, tabId, [D, 'nope'])) -> first.reads === 1, value keys [D]+ // again with a fresh view at the same stamp -> reads === 0+ // after a bump (send a message) -> one read again+})+```++- [ ] **Step 2: Run** `npx vitest run --config vitest.super-tabs.config.ts integration/superTabCache.test.ts -t "named light"` — FAIL: not exported.+- [ ] **Step 3: Implement** `readLightGroups`.+- [ ] **Step 4: Run** the whole `integration/superTabCache.test.ts` — PASS.+- [ ] **Step 5: Checkpoint** `git diff --stat`.++### Task 5: The `changes` poll reads one shared base++**Files:**+- Modify: `backend/src/superTabs/read/service.ts` (`changes`, lines 114-145)+- Test: `backend/integration/superTabCache.test.ts`, `backend/integration/superTabRead.test.ts`++**Interfaces:**+- Consumes: Task 2 `loadLight` (no `recentStartGroups`), Task 3 `waitingTagConversations`, Task 4 `readLightGroups`.+- Produces: no new exports. Inside `changes`: `const LIGHT = { groups: 'working' as const }`; `base = await readLight(tx, cached, tabId, LIGHT)`; named ids = `asAgentId ? [] : await waitingTagConversations(tx, tabId, user.sub, t0)`; the loader passed to `load` returns `withStarts(withGroups(base, await readLightGroups(tx, cached, tabId, ids not in base)), extra)`, where `withGroups(parts, groups)` is a pure helper beside `withStarts`; `unheld` also takes the conversation ids of `extra` (the `pollStarts` starts). No call in `changes` passes `groupIds` to `readLight`.++- [ ] **Step 1: Write the failing tests.** In `superTabCache.test.ts`, extend `partReads` to also return reads by collection (`byCollection: Record<string, number>`), then:++```ts+it('three readers polling one Swarm at one stamp load its light base once, and once more after a write', async () => {+ // privateScene(); one pod; firstLoad for owner and peer (cursors); also an agent reader via asAgentId.+ // m = await partReads(() => Promise.all([owner, peer, agent].map(r => reads.changes(...))))+ // expect(m.byCollection.SwarmHead).toBe(1); expect(m.byCollection.SwarmProgress ?? 0).toBe(0)+ // send(...) then the same three polls: SwarmHead === 1 again+})+it('a second reader tagged in the same dormant conversation reads no part at the same stamp', async () => {+ // owner and peer each hold a waiting tag in dormant D; owner polls, then peer polls: peer's partReads.reads === 0+})+```++In `superTabRead.test.ts` (Task 2's describe):++```ts+it('gives every reader the derived values a full read gives', async () => {+ // Scene with owner, peer (outside the secret project), a Buddy reader, and an agent via asAgentId; waiting tags in an+ // active and a dormant conversation; a tag in a secret-project conversation for peer (Review Focus 2); a moved read mark;+ // a progress change; finished starts in a dormant conversation.+ // For each reader: const { readMarks: _a, avatars: _b, ...derived } = changes.derived, and the same from /parts:+ // expect(derived).toEqual(fullDerived); peer's mentionsWaiting excludes the secret tag.+ // Changed progress part appears in changes.progress exactly as before.+})+```++- [ ] **Step 2: Run** both files with `-t` on the new names — FAIL (SwarmHead reads are 3; second reader reads parts).+- [ ] **Step 3: Implement** the `changes` rewiring above; delete the all-time `superTabMention.findMany(... distinct ...)` at `service.ts:120`.+- [ ] **Step 4: Run** `npx vitest run --config vitest.super-tabs.config.ts integration/superTabRead.test.ts integration/superTabCache.test.ts integration/superTabHotReads.test.ts integration/superTabReadMarks.test.ts integration/superTabBuddies.test.ts` and `npx vitest run src/superTabs src/routes/superTabs.test.ts` — all pass, including #2247's `a change poll of a Swarm with 1000 finished starts reads a few tens of KB`.+- [ ] **Step 5: Checkpoint** `git diff --stat`.++### Task 6: Whole-backend checks and the prod measurement++**Files:** none new.++- [ ] **Step 1: Run** `npm run typecheck` in `backend/` — no errors.+- [ ] **Step 2: Run** `npm run test:super-tabs` and `npm test` in `backend/` — compare failures with a clean `origin/main` worktree; only pre-existing failures allowed, listed in the PR.+- [ ] **Step 3: Record the baseline** before deploy, same weekday hours (07:00–16:00 VN), 30 min of logs: `argocd app logs production-autonomous-code-be --kind Pod --since-seconds 1800 --grpc-web`; from `cpu by kind`, `db by shape`, `route latency`, `cpu profile`: the route's busy ms per pod-minute (2026-10-30 baseline 2.06 s), calls/docs/MB per shape under the route (`SwarmGroup key $in` 52/244/6.97, `SwarmProgress` 33/1/1.85), Prisma and GC shares. Put the table in the PR.+- [ ] **Step 4: After release**, the same 30-minute read. Done when `SwarmGroup key $in` + `SwarmProgress` under the route are under 1 MB a minute per pod; report the route's busy-time before/after beside it.diff --git a/docs/superpowers/specs/2026-10-30-swarm-changes-shared-light-read-design.md b/docs/superpowers/specs/2026-10-30-swarm-changes-shared-light-read-design.mdnew file mode 100644index 000000000..91f62de16--- /dev/null+++ b/docs/superpowers/specs/2026-10-30-swarm-changes-shared-light-read-design.md@@ -0,0 +1,215 @@+# Design: a small, shared light read for Desktop/web Swarm `changes` (DB roadmap 2.3)++Date: 2026-10-30. Code read at `origin/main` (2bbcad4c4). Spec 1 of 8 in the CPU-ranked list of unfinished items from+the database roadmap (`.vscode/2026-10-29-database-optimization-roadmap.md`, Phase 2 item 3) and the+[WebSocket roadmap](../../plans/2026-10-28-websocket-optimization-roadmap.md). Each spec is approved before the next+one is written.++## Why++`GET /api/super-tabs/:tabId/changes` is the read every open Desktop window and web tab makes for each Swarm it shows,+now mostly right after a `swarm_changed` push (`lib/swarmClientPushes.ts`, coalesced to one a second). It is the most+expensive unfinished item.++**Prod, 2026-10-30, 3 pods, v1.3.6x, 17 minutes of logs:**+- The route takes about 2.06 s of event-loop time per minute per pod, 20% of all busy time, at about 110 reads per+ minute per pod.+- About 30% of reads (32 a minute per pod) miss the read cache and run a full `loadLight`. Those loads are about+ 9.5 MB a minute per pod, 70% of the bytes the route reads:++ | Shape under the route (per pod) | Calls/min | Docs/call | MB/min |+ |---|---|---|---|+ | `SwarmGroup` by `key $in` (light projection) | 52 | 244 | 6.97 |+ | `SwarmProgress.findMany` | 33 | 1 | 1.85 |+ | `SwarmAgent.findMany` | 32 | 11 | 0.42 |+ | `SwarmGroup` running work | 31 | 6 | 0.20 |+ | change feed, machines + groups | 140 | 2–5 | 2.6 |++- **Where backend CPU goes** (the `cpu profile` log, all routes): Prisma decoding results 33%, garbage collection+ about 10%, `structuredClone` 9%, the cache's `freeze` 2.6%. The Swarm logic itself (reassemble, views,+ `changesFor`) is under 3%. **CPU follows the bytes read from Mongo and copied, not the number of readers.** The+ way to cut it is to read fewer bytes.++**Why each miss is so large.** On the busiest Swarm (`c51479bd…`, openharness: 6 members, 126 live and 1,080 dormant+conversations, 396 commands an hour):+1. **Conversations of every live start.** `loadLight` with `recentStartGroups` loads the conversation of every live+ start (`parts/light.ts:129-132`). Finished starts are kept 7 days: 837 live starts, 0 unfinished, in 623+ conversations, most of them dormant. #2247 kept this load for one reason only: an agent stored with no+ `projectId` takes its project from the first conversation it is in (`projects.ts:98-100 agentProjectId`).+ That Swarm has no such agent. All of prod has 6 of 66 live agents, in 6 Swarms, last changed 27–29 Oct.+2. **The progress part.** One `SwarmProgress` document of 81 KB, read on every miss. A `changes` reply sends progress+ only from the change feed (`read/changes.ts`), never from the loaded base.+3. **One entry per reader.** `read/service.ts:120-125` passes `groupIds: mentioned` (every conversation the person+ was tagged in) to `readLight`, whose cache name includes them (`cachedReads.ts:64-65`). Every reader has their own+ entry, so each `main` stamp costs one full load per reader per pod. Reads land on pods at random.++## Goals++- A `changes` miss reads only what the reply needs: no conversations of finished starts, no progress part.+- One light base per Swarm per `main` stamp per pod, shared by every reader.+- The reply of every `changes` call is what the full state gives, for every reader (person, agent via `asAgentId`,+ Buddy): unchanged wherever today's light reply already was.++## Non-goals++- Keeping the base across writes by patching it with the change feed. With the base this small, a reload per write+ is cheap; patching adds risk for little.+- The per-person reads in a poll (`superTabMention` distinct list, `waitingMentions`, `decisionsWaiting`,+ `readMarks`): small indexed reads, per person by nature.+- The change feed's own cost (machine bumps reload it). Measured here, decided later.+- `structuredClone` of whole states (DB 2.6), the `lastChangedAt` aggregates (DB 2.4): specs 2 and 5 of this series.+- Retention of finished starts (DB roadmap Phase 5).+- Any client change.++## Anti-goals++- A reader seeing a conversation, agent, start, read mark or machine record that a first load would not show them,+ or missing one it would. The checks (`read/views.ts readerView`, `read/changes.ts changesFor`, `readableMarks`) keep the+ inputs they need for every reader.+- An agent stored without a `projectId` landing in a different project in a reply than it does today.+- A cache entry whose content depends on who read it.++## Design decided++### 0. The reference answer++*(Author's call after the builder check.)* Today's light reply is not one fixed answer: what it derives (an agent's+project, who awaits a decision) depends on which conversations happened to be loaded, including that reader's+mentions and every start of the last 7 days. The reference for every reply is therefore **the answer the full state+gives**, as commands and `firstLoad` see it: the Swarm's active conversations (`loadActive`). Where today's light reply+differs from that, the new reply follows the full state, and the equality tests compare against a reply built from+the full state, not against today's light reply.++### 1. Legacy agents: load only their own active conversations++- `agentProjectId` keeps its fallback (lowest-ordinal conversation the agent is in, else `'lead'`).+- The light base no longer loads every start's conversation to serve that fallback.+- Prod, 2026-10-30: the 6 live agents stored without a `projectId` are all in Swarms whose head has no `projects`.+ There every conversation has no project, so the answer is always `'lead'` and nothing needs loading. New agents+ without a `projectId` are still created only in such Swarms (`commands.ts:1476-1477`, `1744-1745`).+- So the base adds, through the `agents` index, the **active** conversations of the live agents stored without a+ `projectId`, as commands see them, and exactly as a machine report's load already does (`parts/load.ts+ loadObserved`, `legacy`). With no such agent, as on every Swarm but six today, no query runs.+- *(Author's call.)* No backfill and no change to stored data.++### 2. The light base reads only what a poll needs++- `loadLight`'s `recentStartGroups` option goes, with its `distinct` over every live start. The base holds the Lead+ conversations, running work, conversations of unfinished starts, invitations' conversations, and `undecidedWork`,+ as the `'working'` selection already does.+- The starts a poll adds after the base (`pollStarts`: changed starts from the feed, and finished starts a machine+ record still lists) need their conversations for the visibility checks. Their conversation ids join `unheld`+ (`read/service.ts:137`), which already loads the conversations of changed starts and moved read marks. No other+ reader of `loadLight` used `recentStartGroups`.+- The light base reads no progress parts (`machines: false` already shows the pattern). The change feed still carries+ changed progress parts, and `changesFor` sends them as today. If anything on the `changes` path reads+ `parts.progress` or `state.projects[].progress` from the base, the builder moves it to the feed's part or proves it+ unused; the response equality tests decide.++### 2b. Who awaits a decision: the base's busy rule matches `awaitingWorkers`++- `derived.agents[].workDecision` comes from `model.ts awaitingWorkers`: an agent with no stored decision awaits one+ if an active conversation shows its finished, non-lost work, unless it is a Reviewer, leads a conversation, or is+ the assignee of active work.+- `undecidedWork` (`parts/light.ts:63-71`) counts as busy also every member (`agentIds`) of running work, so it skips+ loading the finished work of an agent that is only a member of running work. Today the start conversations+ happen to cover that case; without them the reply would lose an `'awaiting'`.+- *(Author's call after the builder check.)* `undecidedWork`'s busy rule becomes the same as `awaitingWorkers`'+ (Lead of a conversation, or assignee of active work; Reviewers never wait), so the base holds every active+ conversation `awaitingWorkers` reads. This adds a few active conversations on some Swarms.++### 3. One shared base, named groups held per group++- The poll calls `readLight` with no `groupIds`, so its cache name is the same for every reader.+- *(Author's call after the builder check.)* A person's named conversations are those of their **waiting** tags+ (unresolved, under 30 days: the rows `mentions.ts readable` counts), not every conversation they were ever tagged+ in. Only the waiting count needs them, and `readable` reads any it lacks itself. The all-time `distinct` query at+ `service.ts:120` goes. (Prod: 2–15 tagged conversations per person on the busiest Swarm, so the bulk of today's+ 244 docs a call is the start conversations of section 2.)+- A new read in `cachedReads.ts` (working name `readLightGroups(db, view, tabId, ids)`) returns the light groups for+ ids the base lacks (a reader's waiting-tag conversations, and `unheld`):+ - one cache entry per id at the `main` stamp (for example `light-group:<id>`), holding the group or "none" for a+ deleted or unknown id;+ - one query for the misses of a call, through the `key` index with the light projection+ (`parts/light.ts loadLightGroups(tx, tabId, 'key', { key: { $in: ids } })`, which exists), batched as+ `readLastChangedAts` batches its misses.+- `cache.ts` keeps an index of entry names per Swarm, so `drop`, `held` and eviction touch only that Swarm's entries.+ Today `drop` scans every entry of every Swarm on each bump, machine-only bumps included, and per-group entries+ would multiply the entry count.+- The loader the poll gives `load` returns the shared base, plus the named groups it lacks, plus the poll's own+ starts (`withStarts`). Both loads of a poll (`service.ts:132` and `:139`) use it. No per-person `readLight` name+ remains.++### 4. Equal responses++- The composed parts must give, for every reader, the reply the full state gives (section 0). Today's light reply+ already does in the common case; the tests below pin the cases where it did not.+- `undecidedWork` may now hold a few extra active conversations; extra active conversations never change a reply+ built from the full state, which holds them all.+- Group order: `reassemble` sorts by ordinal (`parts/shape.ts`), so composition order does not matter.+- Snapshot: named groups may be read outside the base's read transaction, as `readParts` already reads+ `group:<id>`. A write between the two moves the stamp; the cursor's `T0`, taken before any read, makes the next+ poll see it.++## Left to the builder++- Names, cache entry names, and removing whatever becomes dead (`recentStartGroups`, `readLight`'s per-person options+ if no caller is left, the start `distinct`).+- Whether `undecidedWork` keeps loading members' conversations once its busy rule matches `awaitingWorkers`, as long+ as the replies match the full state.++## Tests++- **Same reply as the full state.** A scene with several readers (owner, a member of a private project, a member+ outside it, an agent via `asAgentId`, a Buddy) and: waiting and resolved tags in active and dormant conversations;+ finished starts in dormant conversations, one changed since the cursor and one listed by a machine record; a moved+ read mark; a progress change; an agent with no stored decision that is a member (not assignee) of running work and+ has finished work in another active conversation; an agent stored without `projectId` in a Swarm with projects and+ in one without. Each reader's `changes` reply under the new code equals the reply built from the full state+ (`readParts`, as `firstLoad` reads it), and equals today's reply wherever today's already did.+- **Small miss.** A Swarm with hundreds of finished starts in dormant conversations: a `changes` miss reads none of+ those conversations and no progress part (count part reads, as `integration/superTabCache.test.ts` does).+- **Shared load.** Three people polling one Swarm at one stamp run `loadLight` once; after a write, once more in total.+- **Named groups.** Two readers mentioned in one dormant conversation read it once per stamp; an unknown id once.+- **Per-Swarm drop.** A bump of one Swarm drops only its entries; byte and entry counts stay right after drops,+ evictions and expiry.+- Existing suites stay green: `read/changes.test.ts`, `read/views.test.ts`, `parts/light.test.ts`,+ `integration/superTabCache.test.ts`, `integration/superTabRead.test.ts`, `integration/superTabHotReads.test.ts`,+ and the `projects` / `commands` unit tests.++## Measuring++Before and after, same weekday hours, from prod logs (`cpu by kind`, `db by shape`, `route latency`, `cpu profile`):+- the route's busy ms per pod per minute (baseline 2.06 s);+- calls, docs and bytes of each shape under the route (baseline table above);+- Prisma's and GC's share in `cpu profile`;+- the read cache's entry count per pod (`SwarmCache.size`).++**Done when:** tests show no reply change and one `loadLight` per Swarm, stamp and pod; and prod shows the+`SwarmGroup key $in` and `SwarmProgress` shapes under the route falling from about 8.8 MB to under 1 MB a minute per+pod. The CPU before/after is reported with it (expected: the route's busy time about halves; an estimate, since the+log does not split a read's time between loading and the rest).++## Design (AGENTS.md rules)++- **Growth:** the LRU (`SWARM_CACHE_MB`, 64 MB, 60 s max age) holds the new per-group entries; every `main` bump drops+ a Swarm's entries. Per-reader light entries go, and the base itself shrinks from hundreds of conversations to+ tens. The per-Swarm name index keeps bumps proportional to one Swarm's entries.+- **Concurrency:** no locks, as the read cache: entries are held under the stamp read before loading; concurrent+ misses of one entry share one load.+- **Read cost:** a hit costs the stamp `HMGET`, as today. A miss costs one small `loadLight` per pod per stamp, plus+ one batched group read for named ids that miss.+- **Scale:** at 10× readers per Swarm the base stays one load per stamp per pod; the per-person indexed reads grow+ linearly and are the first to watch in `db by shape`. At 10× live starts the base no longer grows with them.+ At 10× writes, the reload per write is the limit; the route's `cpu by kind` warns first.+- **Compatibility:** reply shapes are unchanged, so every client is unaffected. Values change only where today's+ light reply disagreed with the full state (section 0), toward what `firstLoad` already sends. During a rolling deploy old pods keep+ their per-person entries under other names; all pods read the same stamps.+- **Migration + rollback:** nothing stored changes. Roll back by deploying the previous release; the read cache can+ be turned off with `SWARM_READ_CACHE=off`.+- **Audience:** permissions stay after the cache; held values are the stored state, the same for every reader. The+ equality tests enforce it per reader kind.+- **Identity:** N/A because nothing here acts as or reads the machine owner's login.+- **Failure:** without stamps every read goes to Mongo, as today. A failed group read fails the poll as a failed+ `loadLight` does today.+- **Platforms:** backend only.