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.
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, asfirstLoadreads 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 mentiondistinct); no inert stubs. - Commands from
backend/. Unit:npx vitest run <file>. Integration:npx vitest run --config vitest.super-tabs.config.ts <file>.
Review Focus
- A Buddy reading
changesafter the change: replies still carry no machine or start ids (changesForbuddy rules) — Task 5 equality test includes a Buddy reader. - A reader tagged in a conversation they can no longer read (removed from a private project): the tag's conversation is loaded but
readablemust not count it — Task 5 test. - 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).
- A cache entry for a conversation id that does not exist: held as "none", read once per stamp, never throws — Task 4 test.
- 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);dropnow touches only that Swarm's entries.Step 1: Write the failing test in
describe('SwarmCache'):
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 ifdrop('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). StoretabIdonEntry. Add to the set inload; remove indrop1, the stale branch ofheld, the eviction loop anddrop; delete a Swarm's set when it empties.dropiteratesbySwarm.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 --statshows onlycache.tsandcache.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(LoadOptionslosesrecentStartGroups) - Test:
backend/integration/superTabRead.test.ts(newdescribe('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 })—recentStartGroupsremoved; returnedprogressis always[].Step 1: Write the failing tests (use the file's
scene,get,keys,clockhelpers):
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 asmodel.ts awaitingWorkers.loadLight: deleterecentStartGroupsand thedistinctonSwarmStart;workingtakesstarts.map(s => s.data!.request.conversationId).loadLight,groups === 'working'only: after members/agents load, add active conversations of agents with nodata.projectIdthrough['agents', { agentIds: { $in: legacy }, dormant: false }](asparts/load.ts loadObserved); run it besideundecidedWorkin onePromise.all; no query whenlegacyis empty.loadLight: noSwarmProgressread; returnprogress: [].
Step 4: Run
npx vitest run --config vitest.super-tabs.config.ts integration/superTabRead.test.ts integration/superTabGroupPlans.test.tsandnpx vitest run src/superTabs/parts/light.test.ts src/superTabs/read— all pass, includingan 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 besidereadable) - Test:
backend/integration/superTabRead.test.ts(same new describe)
Interfaces:
Produces:
waitingTagConversations(tx: Tx, tabId: string, personId: string, now: number): Promise<string[]>— distinctconversationIds of the rowsreadable(..., open = true)reads:tabId,personId,createdAt > now - MENTION_EXPIRY_MS,waiting, newest first,take: 500.readableuses the samewhere(one shared constant, not a copy).Step 1: Write the failing test:
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
wherewithreadable. - 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 namedlight-group:<id>, scope'main', valuePart<GroupData> | null(null = deleted or unknown); misses of one call batched into one query, asreadLastChangedAtsbatches; result inidsorder, nulls left out; without stamps reads Mongo directly.Step 1: Write the failing test:
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(norecentStartGroups), Task 3waitingTagConversations, Task 4readLightGroups.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 toloadreturnswithStarts(withGroups(base, await readLightGroups(tx, cached, tabId, ids not in base)), extra), wherewithGroups(parts, groups)is a pure helper besidewithStarts;unheldalso takes the conversation ids ofextra(thepollStartsstarts). No call inchangespassesgroupIdstoreadLight.Step 1: Write the failing tests. In
superTabCache.test.ts, extendpartReadsto also return reads by collection (byCollection: Record<string, number>), then:
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):
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
-ton the new names — FAIL (SwarmHead reads are 3; second reader reads parts). - Step 3: Implement the
changesrewiring above; delete the all-timesuperTabMention.findMany(... distinct ...)atservice.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.tsandnpx vitest run src/superTabs src/routes/superTabs.test.ts— all pass, including #2247'sa 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 typecheckinbackend/— no errors. - Step 2: Run
npm run test:super-tabsandnpm testinbackend/— compare failures with a cleanorigin/mainworktree; 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; fromcpu 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 $in52/244/6.97,SwarmProgress33/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+SwarmProgressunder the route are under 1 MB a minute per pod; report the route's busy-time before/after beside it.