Skip to content

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: a reviewer of one security review is never handed the other, and a stuck step moves without a cancel (#4534) (#3554)

0xken150cdbac220ed0
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.ts
index dbf46a77b..10c0b8704 100644
--- a/backend/src/superTabs/commands.ts
+++ b/backend/src/superTabs/commands.ts
@@ -31,7 +31,7 @@ import { noteWriter } from './stuck.js'
import { reviewPlan, refreshStepBrief, stepOs, stepOsRefusal, type PlannedStep, type StepKind } from './reviewTable.js'
import { openReviewStep, type StepPull } from './stepOpen.js'
import { stopWaiting, testsOn, WAIT_LINE, waitFor, waits } from './osSteps.js'
-import { builtBy, reviewerCandidates, STRENGTH_RULE } from './reviewerPick.js'
+import { builtBy, otherSecurityReviewers, reviewerCandidates, stepCandidates, STRENGTH_RULE } from './reviewerPick.js'
import { checkedPullRequest, deriveCheck, recordCheckVerdict } from './checkVerdicts.js'
import { routeRecordSchema, routeTitle, startedAs, type KeptCandidate, type RouteDecision, type RouteFinal, type RouteOverride } from './routeRecord.js'
import { routingOverrideSaveSchema } from './routingPolicy.js'
@@ -1943,6 +1943,20 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
if (state.paused) fail('PAUSED', 'New work is paused in this Super Tab.')
pausedTask(group)
if (activeWork(group)) fail('WORK_ACTIVE', 'The current assignment must finish or be reconciled before reassignment.')
+ // A review step is never its task's builder's, and a security review never the other one's reviewer, by any path (task
+ // #4534: #3542 and #3545 each waited 20-30 minutes on a refused step). The refusal says who may take it now.
+ const task = isReview(group) ? state.conversations.find(c => c.id === group.reviewOf) : undefined
+ if (task) {
+ const name = worker.displayName ?? worker.name
+ const free = () => {
+ const names = stepCandidates(state, group, context.now).slice(0, 3).map(a => a.displayName ?? a.name)
+ return names.length ? ` Free to take it now: ${names.join(', ')}.` : ' No other Reviewer is free now: start one.'
+ }
+ if (builtBy(task).has(worker.id)) fail('STEP_BUILDER', `${name} built this task, so it does not review it.${free()}`)
+ if (/security/i.test(stepName(group)) && otherSecurityReviewers(state, task, group.id).has(worker.id)) {
+ fail('REVIEW_NOT_INDEPENDENT', `${name} reviewed this task's other security review, and the two are independent.${free()}`)
+ }
+ }
// Before anything changes: a task given to a closed session is lost at once, and its agent then stays listed until the
// task is handed on (closedAgents.ts removeClosedAgents). Without a task it leaves on its machine's next report.
// A crew member on its way to another machine takes work once there; an asleep one wakes for it, in place (crewKeep.ts),
@@ -2092,7 +2106,7 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
&& (check.verdicts ?? []).some(verdict => verdict.passed && (verdict as { head?: string }).head === read.head))) continue
step ??= openStep(task, planned, pulls)
const previous = step.assignment?.agentId
- const ranked = reviewerCandidates(state, task, planned.kind, read.head, context.now, planned.os)
+ const ranked = reviewerCandidates(state, task, planned.kind, read.head, context.now, planned.os, step.id)
const ordered = [...ranked.filter(a => a.id === previous), ...ranked.filter(a => a.id !== previous)]
const target = step
const worker = ordered.find(candidate => {
@@ -4826,6 +4840,19 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
projectChatWork(command.conversationId)
const group = open(state, command.conversationId)
const worker = agent(state, command.agentId)
+ // A security review stuck on a reviewer of the other one moves on without a cancel (task #4534): that reviewer may not take
+ // it and said so, so its attempt ends here, its reviewer told and freed, and assignRefusal holds the new one to the rule.
+ const stuck = group.assignment
+ const reviewed = stuck && ['blocked', 'needs_human'].includes(stuck.status) && isReview(group) && /security/i.test(stepName(group))
+ ? state.conversations.find(c => c.id === group.reviewOf) : undefined
+ if (stuck && reviewed && stuck.agentId !== worker.id && otherSecurityReviewers(state, reviewed, group.id).has(stuck.agentId)) {
+ const to = worker.displayName ?? worker.name
+ stuck.status = 'cancelled'
+ stuck.result = `Moved to ${to}: its reviewer did this task's other security review.`
+ finishWorker(state, stuck.agentId)
+ message(group.id, `This security review moved to ${to}: you did this task's other one, and the two are independent. Stop working on it.`,
+ [stuck.agentId], null, forRecipients(SYSTEM_ROW), undefined, undefined, undefined, stableId(operationId, 'step-moved'))
+ }
assignRefusal(group, worker)
const home = groupProject(state, group)
// An older client assigns in a custom role: kept for older readers, and the role name it means for a worker without
diff --git a/backend/src/superTabs/reviewSteps.test.ts b/backend/src/superTabs/reviewSteps.test.ts
index 157235366..4be1f6de0 100644
--- a/backend/src/superTabs/reviewSteps.test.ts
+++ b/backend/src/superTabs/reviewSteps.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { applyCommand, type Command, type CommandContext } from './commands.js'
-import { createSuperTab, type Actor, type AgentConfiguration } from './model.js'
+import { activeWork, createSuperTab, type Actor, type AgentConfiguration } from './model.js'
import { stepsOf } from './steps.js'
import { SEED_RULES } from './policy.js'
@@ -144,6 +144,66 @@ describe('a handed task opens its review steps', () => {
expect(f.group(second!.id).assignment!.agentId).toBe([a, b].find(id => id !== firstAgent))
})
+ /** A sign-in Ready with Reviewers a, b and c free: Security review 2's reviewer finishes it, and Security review 1 is cancelled. */
+ const otherDone = () => {
+ const f = fixture()
+ const ids = ['rev-a', 'rev-b', 'rev-c'].map(name => f.add(name, f.task, 'Reviewer'))
+ f.ready(['backend/src/routes/auth.ts'])
+ const [one, two] = stepsOf(f.state, f.task)
+ const first = one!.assignment!.agentId, second = two!.assignment!.agentId
+ const third = ids.find(id => id !== first && id !== second)!
+ f.run({ type: 'work.status', conversationId: two!.id, assignmentId: two!.assignment!.id, status: 'done', result: 'Ready to merge: Yes' } as Command, f.as(second))
+ return { f, one: one!.id, two: two!.id, first, second, third }
+ }
+
+ // Task #4534 (#3542): a cancelled Security review 1 went back out at the next head to Security review 2's reviewer.
+ it('a security review cancelled and handed out again at a new head never goes to the other one\'s reviewer', () => {
+ const { f, one, two, first, second, third } = otherDone()
+ f.run({ type: 'work.cancel', conversationId: one, assignmentId: f.group(one).assignment!.id, reason: 'Not independent' } as Command, f.as(f.lead))
+ // Its first reviewer and the third are busy elsewhere now.
+ for (const id of [first, third]) {
+ const other = f.run({ type: 'conversation.create', title: `Other ${id}`, brief: 'Other work.', checks: [{ description: 'Done', independent: false }],
+ priority: 'P2', requesterId: 'owner' }, f.as(f.lead)).result.conversationId as string
+ f.run({ type: 'work.assign', conversationId: other, agentId: id }, f.as(f.lead))
+ }
+ f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'working', result: 'Fixing' } as Command, f.as(f.dev))
+ f.tick(60_000)
+ f.ready(['backend/src/routes/auth.ts'], 'def5678')
+ const security1 = stepsOf(f.state, f.task).filter(s => s.step === 'Security review 1').map(s => activeWork(s) ? s.assignment!.agentId : null)
+ expect(security1).not.toContain(second)
+ expect(f.group(two).assignment).toMatchObject({ agentId: second, status: 'working' })
+ })
+
+ it('refuses a step to the other security review\'s reviewer and to the task\'s builder, naming who may take it', () => {
+ const { f, one, second, third } = otherDone()
+ f.run({ type: 'work.cancel', conversationId: one, assignmentId: f.group(one).assignment!.id, reason: 'Moving it' } as Command, f.as(f.lead))
+ const assign = (agentId: string) => f.run({ type: 'work.assign', conversationId: one, agentId } as Command, f.as(f.lead))
+ expect(() => assign(second)).toThrow(expect.objectContaining({ code: 'REVIEW_NOT_INDEPENDENT', message: expect.stringContaining('rev-') }))
+ expect(() => assign(f.dev)).toThrow(expect.objectContaining({ code: 'STEP_BUILDER' }))
+ expect(() => assign(third)).not.toThrow()
+ expect(f.group(one).assignment).toMatchObject({ agentId: third, status: 'working' })
+ })
+
+ // Task #4534: Ownrev6 held Security review 1 of #3545 after doing review 2, said so, and only a cancel by the PM moved it.
+ it('a security review stuck on the other one\'s reviewer moves to a free Reviewer without a cancel', () => {
+ const { f, one, second, third } = otherDone()
+ // As before #4534: the other review's reviewer holds this one, and reports that it cannot take it.
+ const held = f.group(one).assignment!
+ Object.assign(held, { agentId: second })
+ f.run({ type: 'work.status', conversationId: one, assignmentId: held.id, status: 'blocked', result: 'I did Security review 2: give this to another Reviewer' } as Command, f.as(second))
+ const moved = f.run({ type: 'work.assign', conversationId: one, agentId: third } as Command, f.as(f.dev))
+ expect(f.group(one).assignment).toMatchObject({ agentId: third, status: 'working' })
+ expect(moved.messages.some(m => m.recipients.includes(second) && /moved to rev-/.test(m.text))).toBe(true)
+ expect(f.state.agents.find(a => a.id === second)!.workDecision).toBe('awaiting')
+ })
+
+ it('a blocked step whose reviewer is independent stays its reviewer\'s', () => {
+ const { f, one, first, third } = otherDone()
+ f.run({ type: 'work.status', conversationId: one, assignmentId: f.group(one).assignment!.id, status: 'blocked', result: 'Waiting on CI' } as Command, f.as(first))
+ expect(() => f.run({ type: 'work.assign', conversationId: one, agentId: third } as Command, f.as(f.dev))).toThrow(expect.objectContaining({ code: 'WORK_ACTIVE' }))
+ expect(f.group(one).assignment!.agentId).toBe(first)
+ })
+
// Review of #3227 (Digest): a second Ready at the same head re-assigned a review that had passed there, and cleared its verdict.
it('a repeated Ready at the same head keeps a review that passed at that head', () => {
const f = fixture()
diff --git a/backend/src/superTabs/reviewerPick.test.ts b/backend/src/superTabs/reviewerPick.test.ts
index 3cedee0ba..73d532c42 100644
--- a/backend/src/superTabs/reviewerPick.test.ts
+++ b/backend/src/superTabs/reviewerPick.test.ts
@@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'
import { applyCommand, type Command, type CommandContext } from './commands.js'
import { createSuperTab, type Actor, type AgentConfiguration } from './model.js'
import type { ContributedMachine } from './machines.js'
-import { builtBy, reviewerCandidates, strengthOf } from './reviewerPick.js'
+import { builtBy, reviewerCandidates, stepCandidates, strengthOf } from './reviewerPick.js'
const owner: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'owner', email: '[email protected]' }
const opus: AgentConfiguration = { engine: 'claude', model: 'opus', effort: 'high', contextWindow: 200000, engineVersion: 'fixture' }
@@ -103,6 +103,24 @@ describe('reviewerCandidates', () => {
expect(f.pick('security', head).sort()).toEqual(['bare', 'prefix'])
})
+ // Task #4534: Ownrev6 did Security review 2 of #3542 and of #3545, then was handed Security review 1 at the next head.
+ it('never offers one security review to the agent that did or judged the other; its own it may take again', () => {
+ const f = fixture()
+ const did = f.add('did', f.task, opus, { roleName: 'Reviewer' }), judged = f.add('judged', f.task, opus, { roleName: 'Reviewer' })
+ f.add('free', f.task, opus, { roleName: 'Reviewer' })
+ const open = (name: string) => f.run({ type: 'conversation.create', title: name, reviewOf: f.task, step: name, brief: 'Read it.', checks: [] } as Command,
+ f.as(f.lead)).result.conversationId as string
+ const one = open('Security review 1'), two = open('Security review 2')
+ f.run({ type: 'work.assign', conversationId: two, agentId: did }, f.as(f.lead))
+ f.run({ type: 'work.status', conversationId: two, assignmentId: f.group(two).assignment!.id, status: 'done', result: 'Ready to merge: Yes' } as Command, f.as(did))
+ // A verdict on the other step at an older head counts too: the two reviews are of one change.
+ f.group(two).checks = [{ id: 'c', description: 'Reviewed', independent: true, evidence: null, passedBy: null,
+ verdicts: [{ by: `agent:${judged}`, passed: true, evidence: 'Yes', at: 5, head: 'fff0000' }] } as never]
+ const names = (step: string) => stepCandidates(f.state, f.group(step), f.now).map(a => a.name).sort()
+ expect(names(one)).toEqual(['free'])
+ expect(names(two)).toEqual(['did', 'free', 'judged'])
+ })
+
it('is never busy, a PM, a Buddy, or holding another step of this task', () => {
const f = fixture()
const busy = f.add('busy', f.task, opus, { roleName: 'Reviewer' })
diff --git a/backend/src/superTabs/reviewerPick.ts b/backend/src/superTabs/reviewerPick.ts
index 6abd76b89..f8a26080c 100644
--- a/backend/src/superTabs/reviewerPick.ts
+++ b/backend/src/superTabs/reviewerPick.ts
@@ -23,6 +23,18 @@ export function builtBy(task: Conversation): Set<string> {
return ids
}
+/** The agents that hold, finished or judged a security review of [task] other than [stepId], at any head (task #4534): the two
+ * security reviews are independent, so none of them takes this one. The step's own reviewer may take it again at a new head. */
+export function otherSecurityReviewers(state: SuperTabState, task: Conversation, stepId: string | undefined): Set<string> {
+ const ids = new Set<string>()
+ for (const step of stepsOf(state, task.id)) {
+ if (step.id === stepId || !/security/i.test(stepName(step))) continue
+ if (step.assignment && (activeWork(step) || step.assignment.status === 'done')) ids.add(step.assignment.agentId)
+ for (const check of step.checks) for (const verdict of check.verdicts ?? []) if (verdict.by.startsWith('agent:')) ids.add(verdict.by.slice('agent:'.length))
+ }
+ return ids
+}
+
/** The catalog's row for what [agent] runs (catalog.ts), or undefined: a grid model (never a reviewer), or a model the
* catalog does not list. An agent on its engine's own model is rated by the engine's named default. */
function catalogRow(state: SuperTabState, agent: Agent) {
@@ -67,9 +79,11 @@ const atHead = (verdict: CheckVerdict & { head?: string }, head: string | null)
* The agents that may take a [kind] step of [task] at [head], best first: the step's own role (Reviewer, Tester) before any
* other free agent, then the cheaper of equal standing, then by id. Excluded: anyone that built the task; a grid model, an
* unknown model or one weaker than the engineer; anyone busy, coordinating a conversation, a Buddy, stopping, or of another
- * project; anyone holding another open step of this task; anyone with a verdict at this head on the task or its steps.
+ * project; anyone holding another open step of this task; anyone with a verdict at this head on the task or its steps; for a
+ * security review, anyone that held, did or judged the task's other one (otherSecurityReviewers, for [stepId], the step it fills).
*/
-export function reviewerCandidates(state: SuperTabState, task: Conversation, kind: StepKind, head: string | null, now: number, os?: StepOs): Agent[] {
+export function reviewerCandidates(state: SuperTabState, task: Conversation, kind: StepKind, head: string | null, now: number, os?: StepOs,
+ stepId?: string): Agent[] {
const projectId = groupProject(state, task).id
const index = workerIndex(state)
const built = builtBy(task)
@@ -80,11 +94,12 @@ export function reviewerCandidates(state: SuperTabState, task: Conversation, kin
const holding = new Set(steps.filter(step => activeWork(step)).map(step => step.assignment!.agentId))
const judged = new Set([task, ...steps].flatMap(group => group.checks.flatMap(check => check.verdicts ?? []))
.filter(verdict => atHead(verdict, head)).map(verdict => verdict.by))
+ const otherSecurity = kind === 'security' ? otherSecurityReviewers(state, task, stepId) : new Set<string>()
const ranked = state.agents.flatMap(agent => {
if (built.has(agent.id) || index.leaders.has(agent.id) || index.working.has(agent.id) || holding.has(agent.id)) return []
// Nor a Team account's agent, which takes no new work (task #4120).
if (isBuddy(agent) || agent.workDecision === 'stop' || onTeamAccount(state, agent) || agentProjectId(state, agent) !== projectId) return []
- if (judged.has(`agent:${agent.id}`)) return []
+ if (judged.has(`agent:${agent.id}`) || otherSecurity.has(agent.id)) return []
const role = roleNameOf(state, agent)
if (NEVER.test(role) || NEVER_NAMED.test(agent.name) || NEVER_NAMED.test(agent.displayName ?? '')) return []
// Only the step's own role, Reviewer or Tester, with no other agent standing in (task #3602: #3576's Test went to an Engineer).
@@ -111,5 +126,5 @@ export function stepCandidates(state: SuperTabState, step: Conversation, now: nu
const kind: StepKind = /test/i.test(name) ? 'test' : /security/i.test(name) ? 'security' : 'review'
const latest = task.pullRequestUrls?.at(-1)
const head = latest ? task.pullRequestHeads?.[latest]?.head ?? null : null
- return reviewerCandidates(state, task, kind, head, now, stepOs(step))
+ return reviewerCandidates(state, task, kind, head, now, stepOs(step), step.id)
}
diff --git a/docs/plans/2026-11-07-security-review-independence-plan.md b/docs/plans/2026-11-07-security-review-independence-plan.md
new file mode 100644
index 000000000..30e76500c
--- /dev/null
+++ b/docs/plans/2026-11-07-security-review-independence-plan.md
@@ -0,0 +1,56 @@
+# A reviewer of one security review never gets the other — Plan (task #4534)
+
+**Goal:** A security review step is never assigned, by any path, to an agent that holds or gave a verdict on the task's other
+security review, nor to the task's builder; a step stuck on such a reviewer moves to an eligible one without a cancel.
+
+**Architecture:** The candidate filter (reviewerPick.ts `reviewerCandidates`) excludes a verdict only at the current head and
+a step only while it is worked, so a reviewer who finished Security review 2 at an older head was a candidate for Security
+review 1 at the next (#3542, #3545). `otherSecurityReviewers(state, task, stepId)` names the agents holding, done with or with a
+verdict on any security step of the task other than `stepId`. `reviewerCandidates` takes the step it fills and leaves them out
+of a security step; `stepCandidates` (dispatch, liveness) passes its step; the Ready's `openReviewSteps` passes the step it
+fills. `assignRefusal`, which every `work.assign` and the Ready pass through, refuses such an agent (`REVIEW_NOT_INDEPENDENT`)
+and the task's builder (`STEP_BUILDER`) on a step, naming who is eligible now. In `work.assign`, a step blocked or
+needing a human whose holder is not independent ends that attempt (cancelled, its holder told) and goes to the agent named.
+
+**Tech Stack:** TypeScript backend (`backend/src/superTabs`), vitest.
+
+**Spec:** task #4534's brief.
+
+This plan is implemented test first by the Engineer, task by task (test-driven development); there is no execution
+hand-off.
+
+## Global Constraints
+
+- Backend only. No change to who may review otherwise: the rule applies to security steps (independence) and to every step
+ (its builder), as the candidate filter already does for the builder.
+- Read cost: only the task's step rows the assignment already reads (`stepsOf`).
+
+## Design
+
+N/A because nothing new is stored, synced or exposed: a refusal and a reassignment use existing fields.
+
+## Review Focus
+
+- A reviewer re-asked for its own security step at a new head still may take it.
+- A blocked step whose holder is independent stays refused (`WORK_ACTIVE`), as today.
+- A step cancelled and reopened at a new head never goes to the other step's reviewer.
+
+## Task 1: the candidate filter and every assignment path
+
+**Files:** `backend/src/superTabs/reviewerPick.ts`, `backend/src/superTabs/commands.ts`; Tests
+`backend/src/superTabs/reviewerPick.test.ts`, `backend/src/superTabs/reviewSteps.test.ts`.
+
+**Interfaces:** `otherSecurityReviewers(state, task, stepId): Set<string>`; `reviewerCandidates(..., os?, stepId?)`.
+
+- [x] Tests: `stepCandidates` for Security review 1 leaves out the agent done with Security review 2, and offers it Security
+ review 2 again; a Ready after Security review 1 was cancelled never gives it to Security review 2's reviewer;
+ `work.assign` of that reviewer, or of the builder, to a step is refused naming who is eligible.
+- [x] Run `npx vitest run src/superTabs/reviewerPick.test.ts src/superTabs/reviewSteps.test.ts`: fail. Code it. Pass. Commit.
+
+## Task 2: a stuck step moves without a cancel
+
+**Files:** `backend/src/superTabs/commands.ts`; Test `backend/src/superTabs/reviewSteps.test.ts`.
+
+- [x] Test: Security review 1 held by Security review 2's reviewer, who reports it blocked: the builder's `work.assign` to a
+ free Reviewer moves it, the old holder is told and freed; a blocked step whose holder is independent is still refused.
+- [x] Run: fails. Code it. Pass. Commit.