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
A task with a recorded merge is never handed out again (#4032) (#3438)
harness-for-autonomous[bot]2ffec2862ae9
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex 71419c5e4..2ebfb6b8b 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -24,6 +24,7 @@ import {} from './model.js'import { jobKindOf } from './evidence/jobKind.js'import { endSteps, stepEndedRows, isStep, stepName, stepsOf, taskOwner } from './steps.js'+import { closeMerged } from './mergedTasks.js'import { reviewPlan, stepBrief, stepCheck, refreshStepBrief, type PlannedStep, type StepKind } from './reviewTable.js'import { builtBy, reviewerCandidates } from './reviewerPick.js'import { recordCheckVerdict } from './checkVerdicts.js'@@ -3002,16 +3003,10 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,// its result (the Ready line), a check's evidence or its own posts, which a merge record never writes. A merge of an unrelated// one recorded here, even twice, only links it (Aster, review of #3259). Closed whenever the record is made: a lost attempt, a// merge recorded again later (#3574).+ // Its open steps close with it (mergedTasks.ts, task #4032).if (ownPullRequest && !isStep(group) && assignment && !['done', 'cancelled'].includes(assignment.status) && builderGone(state, assignment)) {- const previous = assignment.status- assignment.status = 'done'- assignment.result = `Merged ${pullRequestUrl}. Its builder is no longer running, so the recorded merge closes the task.`- delete assignment.hold- delete assignment.askedOf- recordStatus(group, assignment, previous, context.now, operationId)+ effects.messages.push(...closeMerged(state, group, pullRequestUrl, context.now, sender, part => stableId(operationId, part), operationId))effects.closedAssignment = { assignmentId: assignment.id, outcome: 'done' }- message(group.id, `Done\n\n${assignment.result}`, [], null, { ...SYSTEM_ROW, status: 'done' }, undefined, undefined, undefined,- stableId(operationId, 'merged-done'))}break}diff --git a/backend/src/superTabs/dispatch.ts b/backend/src/superTabs/dispatch.tsindex 094ed0a93..38bc51e60 100644--- a/backend/src/superTabs/dispatch.ts+++ b/backend/src/superTabs/dispatch.ts@@ -20,6 +20,7 @@ import { modelMatches } from './rules.js'import { roleNameOf } from './instructions.js'import { reviewerCandidates } from './reviewerPick.js'import { stepName } from './steps.js'+import { ownMerge } from './mergedTasks.js'const HOUR_MS = 3_600_000@@ -134,9 +135,11 @@ export function openTasks(state: SuperTabState, projectId: string, now: number):const lostSteps = state.conversations.filter(group => {if (group.archived || group.kind || group.audience || !group.reviewOf || group.assignment?.status !== 'lost' || (group.projectId ?? 'lead') !== projectId) return falseconst task = state.conversations.find(g => g.id === group.reviewOf)- return !!task && !task.archived && (task.projectId ?? 'lead') === projectId && activeWork(task)+ // Never a step of a task whose own merge is recorded (mergedTasks.ts, task #4032): nothing is left to check.+ return !!task && !task.archived && (task.projectId ?? 'lead') === projectId && activeWork(task) && !ownMerge(task)})- const open = [...queueSiblings(state, project), ...lostSteps].filter(group => (group.task || group.brief.trim())+ // Nor a task whose own merge is recorded: finished work, which the sweep sets done (task #4032).+ const open = [...queueSiblings(state, project).filter(group => !ownMerge(group)), ...lostSteps].filter(group => (group.task || group.brief.trim())&& !activeWork(group) && !['done', 'cancelled'].includes(group.assignment?.status ?? '') && !(group.notBefore && group.notBefore > today)// Paused by someone who steers its project (boardRights.ts, task #3819): until resumed.&& !group.paused)diff --git a/backend/src/superTabs/liveness.ts b/backend/src/superTabs/liveness.tsindex c7d65f1ce..0f75637a4 100644--- a/backend/src/superTabs/liveness.ts+++ b/backend/src/superTabs/liveness.ts@@ -19,6 +19,7 @@ import { endedReply } from './taskLine.js'import { crewClock, DISPATCH_RULES, laneOf, nudgeLine, returnReason, type DispatchLookup } from './dispatch.js'import { handed, pickUp, unclaimedAt, unclaimedReason } from './handed.js'import { isBuddy } from './buddies.js'+import { closeMergedLost } from './mergedTasks.js'// Work never sits with a dead owner (design: "A Swarm that never stops", 2026-10-26). A worker's active assignment is held// by a lease that its progress renews. A dead, stalled or limited worker loses it within minutes: the assignment becomes@@ -452,7 +453,12 @@ function leadNotice(state: SuperTabState, start: AgentStart, text: string | null/** The time checks, run on the Lead's poll and on any machine's report: every worker task with a reason is lost, and* every start dispatched over 3 minutes ago that is not running fails, unless its machine is still preparing it. */export function sweepLiveness(state: SuperTabState, now: number, rulesFor: DispatchLookup = () => DISPATCH_RULES): MessageDraft[] {- const drafts = [...loseTasks(state, now, undefined, undefined, rulesFor), ...crewNudges(state, now, rulesFor), ...failStalledStarts(state, now), ...unpurged(state, now), ...staleSwitches(state, now), ...staleModelRequests(state, now)]+ const drafts = [...loseTasks(state, now, undefined, undefined, rulesFor), ...crewNudges(state, now, rulesFor), ...failStalledStarts(state, now), ...unpurged(state, now), ...staleSwitches(state, now), ...staleModelRequests(state, now),+ // A lost task whose own merge is recorded is done, never handed out again (mergedTasks.ts, task #4032); written as its PM.+ ...closeMergedLost(state, now, task => {+ const pm = projectChatOf(state, task)?.leadId, writer = state.agents.find(a => a.id === pm)+ return writer ? writtenBy(state, writer) : null+ })]// A Buddy start that timed out may have been the last on its Buddy-only machine (security review 1 of #2234).dropIdleBuddyMachines(state, now)return draftsdiff --git a/backend/src/superTabs/mergedTasks.test.ts b/backend/src/superTabs/mergedTasks.test.tsnew file mode 100644index 000000000..5fd686a8a--- /dev/null+++ b/backend/src/superTabs/mergedTasks.test.ts@@ -0,0 +1,101 @@+// Task #4032 (Stepos 11-06): the lane dispatch handed out lost tasks whose merge was already recorded. #3819 went out 9 minutes+// after PR #3384 merged and #3818 52 minutes after PR #3383, each time an agent spent only to set the task done, and their+// steps were revived the same way. A task whose own merge is recorded is never handed out again: the server sets it done.+import { describe, expect, it } from 'vitest'+import { DISPATCH_RULES, openTasks } from './dispatch.js'+import { sweepLiveness } from './liveness.js'+import { appendPullRequestUrls } from './model.js'+import { stepsOf } from './steps.js'+import { stepsFixture } from './steps.test-support.js'++const PR = 'https://github.com/acme/app/pull/7'+const OTHER = 'https://github.com/acme/app/pull/9'++/** A task in review on PR #7 with a Review step working and a Test step whose Tester was lost; its builder is still running. */+function fixture() {+ const f = stepsFixture()+ const assignment = f.group(f.task).assignment!.id+ f.run({ type: 'work.status', conversationId: f.task, assignmentId: assignment, status: 'review', result: `Ready for review: ${PR} at abc1234` }, f.as(f.dev))+ appendPullRequestUrls(f.group(f.task), [PR])+ const reviewer = f.add('rev', f.task), tester = f.add('tst', f.task)+ const review = f.step('Review', f.as(f.lead)), test = f.step('Test', f.as(f.lead))+ f.run({ type: 'work.assign', conversationId: review, agentId: reviewer }, f.as(f.lead))+ f.run({ type: 'work.assign', conversationId: test, agentId: tester }, f.as(f.lead))+ const lose = (id: string) => {+ const held = f.group(id).assignment!+ held.status = 'lost'+ held.lost = { reason: 'its machine went offline', at: f.now }+ f.group(id).lostAttempt = { id: held.id, agentId: held.agentId, machineId: 'host', engine: 'codex' }+ }+ lose(test)+ const merge = (url = PR) => f.run({ type: 'conversation.merged', conversationId: f.task, pullRequestUrl: url }, f.as(f.lead))+ const open = () => openTasks(f.state, 'lead', f.now).map(g => g.id)+ return Object.assign(f, { assignment, review, test, lose, merge, open })+}++describe('a task with a recorded merge', () => {+ it('lost after its merge, is never handed out again, and the sweep sets it done', () => {+ const f = fixture()+ f.merge()+ // Its builder was alive at the merge, so it stayed in review; then it was lost.+ f.lose(f.task)+ expect(f.open()).not.toContain(f.task)+ expect(f.open()).not.toContain(f.test)+ const rows = sweepLiveness(f.state, f.now, () => DISPATCH_RULES)+ expect(f.group(f.task).assignment).toMatchObject({ id: f.assignment, status: 'done' })+ expect(f.group(f.task).assignment!.result).toContain(PR)+ expect(rows.some(r => r.conversationId === f.task && r.text.startsWith('Done'))).toBe(true)+ // Its open steps close with the merge: the working Review and the lost Test.+ for (const step of [f.review, f.test]) expect(f.group(step).assignment).toMatchObject({ status: 'cancelled', result: expect.stringContaining('merged') })+ expect(rows.some(r => r.conversationId === f.review && /merged/i.test(r.text))).toBe(true)+ // A second sweep finds nothing to do.+ expect(sweepLiveness(f.state, f.now, () => DISPATCH_RULES).filter(r => r.conversationId === f.task)).toEqual([])+ })++ it('closes its open steps when the merge closes it', () => {+ const f = fixture()+ f.lose(f.task)+ f.merge()+ expect(f.group(f.task).assignment!.status).toBe('done')+ expect(stepsOf(f.state, f.task).map(s => s.assignment?.status)).toEqual(['cancelled', 'cancelled'])+ })++ it('in review with its merge recorded, never revives its lost step', () => {+ const f = fixture()+ f.merge()+ expect(f.group(f.task).assignment!.status).toBe('review')+ expect(f.open()).not.toContain(f.test)+ })++ // Security review 1 of #3438: a task that ships in two pull requests is merged only once both are.+ it('with one of its two code pull requests merged, is still handed on and never closed', () => {+ const f = fixture()+ const SECOND = 'https://github.com/acme/app/pull/8'+ const g = f.group(f.task)+ g.pullRequestUrls = [...g.pullRequestUrls ?? [], SECOND]+ g.codePullRequestUrls = [...g.codePullRequestUrls ?? [], SECOND]+ f.merge()+ f.lose(f.task)+ expect(f.open()).toContain(f.task)+ sweepLiveness(f.state, f.now, () => DISPATCH_RULES)+ expect(f.group(f.task).assignment!.status).toBe('lost')+ })++ it('unmerged, is still handed on when lost, and so is its lost step while it is in review', () => {+ const f = fixture()+ expect(f.open()).toContain(f.test)+ f.lose(f.task)+ expect(f.open()).toContain(f.task)+ sweepLiveness(f.state, f.now, () => DISPATCH_RULES)+ expect(f.group(f.task).assignment!.status).toBe('lost')+ })++ it('whose only recorded merge is another task\'s pull request, is still handed on and never closed', () => {+ const f = fixture()+ f.merge(OTHER)+ f.lose(f.task)+ expect(f.open()).toContain(f.task)+ sweepLiveness(f.state, f.now, () => DISPATCH_RULES)+ expect(f.group(f.task).assignment!.status).toBe('lost')+ })+})diff --git a/backend/src/superTabs/mergedTasks.ts b/backend/src/superTabs/mergedTasks.tsnew file mode 100644index 000000000..bc399669b--- /dev/null+++ b/backend/src/superTabs/mergedTasks.ts@@ -0,0 +1,63 @@+/**+ * A task whose own merge is recorded is finished work (task #4032, Stepos 11-06): the lane dispatch handed out lost tasks+ * already merged (#3819 9 minutes after PR #3384 merged, #3818 52 minutes after PR #3383), each time an agent spent only to set+ * the task done, and their steps were revived the same way. Such a task is never handed out again (dispatch.ts openTasks); a+ * lost one is set done by the sweep (liveness.ts sweepLiveness), as the merge record sets done one whose builder is gone+ * (commands.ts conversation.merged), and its open steps close with it.+ */+import { recordStatus } from './leaderboard/record.js'+import { codePullRequests, stableId, type Author, type Conversation, type MessageDraft, type SuperTabState } from './model.js'+import { endSteps, isStep, stepEndedRows, stepsOf } from './steps.js'++/** What a step of a merged task is told, and keeps as its result. */+export const STEP_MERGED = 'Its task merged, so this step is closed.'++/** The last of [group]'s own code pull requests when every one of them has its merge recorded on its card, or undefined. Its own:+ * never one only a merge record linked (cards.recorded: a merge of another task's pull request, Aster, #3259). Every one: a task+ * that ships in two pull requests is merged once both are, never while one is still open (security review 1 of #3438). */+export function ownMerge(group: Pick<Conversation, 'cards' | 'codePullRequestUrls' | 'pullRequestUrls'>): string | undefined {+ const recorded = new Set(group.cards?.recorded ?? [])+ const own = codePullRequests(group).filter(url => !recorded.has(url))+ const merged = (url: string) => !!group.cards?.pullRequests?.some(card => card.url === url && card.mergedAt !== undefined)+ return own.length && own.every(merged) ? own.at(-1) : undefined+}++/** Ends [task]'s open steps with its merge: a working one as endSteps ends it, and a lost one too, which nobody takes now. The+ * steps it ended, whose agents the caller tells (stepEndedRows). */+export function endStepsMerged(state: SuperTabState, task: Conversation): Conversation[] {+ const ended = endSteps(state, task, STEP_MERGED, false)+ for (const step of stepsOf(state, task.id)) {+ if (step.archived || step.assignment?.status !== 'lost') continue+ Object.assign(step.assignment, { status: 'cancelled', result: STEP_MERGED })+ ended.push(step)+ }+ return ended+}++/**+ * Sets [task] done with its merge of [url] as its result, its builder being gone, and ends its open steps: the rows that say so,+ * written as [author], one id each from [id]. The caller closes the attempt (effects.closedAssignment, or the store's endRuns).+ */+export function closeMerged(state: SuperTabState, task: Conversation, url: string, now: number, author: Author | null, id: (part: string) => string,+ messageId: string | null = null): MessageDraft[] {+ const assignment = task.assignment!+ const previous = assignment.status+ assignment.status = 'done'+ assignment.result = `Merged ${url}. Its builder is no longer running, so the recorded merge closes the task.`+ delete assignment.hold+ delete assignment.askedOf+ recordStatus(task, assignment, previous, now, messageId)+ const steps = endStepsMerged(state, task)+ const done: MessageDraft[] = author ? [{ id: id('merged-done'), conversationId: task.id, author, text: `Done\n\n${assignment.result}`, replyTo: null,+ recipients: [], source: { kind: 'system', status: 'done' } }] : []+ return [...done, ...stepEndedRows(state, steps, STEP_MERGED, author, step => id(`merged-step-${step.id}`))]+}++/** The lost tasks whose own merge is recorded, set done (closeMerged), each written as [authorOf] it; their rows. */+export function closeMergedLost(state: SuperTabState, now: number, authorOf: (task: Conversation) => Author | null): MessageDraft[] {+ return state.conversations.flatMap(task => {+ if (task.archived || isStep(task) || task.assignment?.status !== 'lost') return []+ const url = ownMerge(task)+ return url ? closeMerged(state, task, url, now, authorOf(task), part => stableId('merged-lost', task.assignment!.id, part)) : []+ })+}diff --git a/docs/plans/2026-11-06-merged-not-dispatched-plan.md b/docs/plans/2026-11-06-merged-not-dispatched-plan.mdnew file mode 100644index 000000000..974acebcc--- /dev/null+++ b/docs/plans/2026-11-06-merged-not-dispatched-plan.md@@ -0,0 +1,41 @@+# A task with a recorded merge is never handed out again: implementation plan++> Written by the project's Engineer way of working (project instructions, Engineer): plan first, then each task test first,+> the failing test committed before its code. No Execution Handoff.++**Goal:** A task whose own merge is recorded is never handed out again; the server sets it done and closes its open steps+(task #4032, Stepos 11-06: #3819 was handed out 9 minutes after PR #3384 merged and #3818 52 minutes after PR #3383, each an+agent spent only to set the task done; their steps were revived the same way).++**Architecture:** `mergedTasks.ts` (new): `ownMerge(task)`, the task's own code pull request whose merge is recorded (a card+with a merge on one of its code links, never one only a merge record linked, `cards.recorded`), read from what every task+already stores, so tasks merged before this change are covered. `closeMerged` sets done with the merge as its result and ends+its open steps, working and lost, with "Its task merged". Used by: `dispatch.ts openTasks` (no merged task, no step of one),+`liveness.ts sweepLiveness` (`closeMergedLost`: a lost task with its own merge is set done, as its PM), and+`commands.ts conversation.merged`'s existing close when the builder is gone (#3510), which now closes the steps too.++**Tech Stack:** TypeScript backend (vitest). **Spec:** task #4032 brief.++## Global Constraints++- Never close a task whose own merge isn't recorded; a merge of another task's pull request closes nothing (Aster, #3259).+- A live builder still closes its own task in review: only lost work is closed by the sweep.+- Owns backend/src/superTabs/.++## Design++- growth, read cost, scale: N/A because nothing new is stored; one pass over the loaded tasks the sweep already reads.+- concurrency: inside the sweep's and the command's existing writes.+- compatibility, migration and rollback: no field or contract changes; revert.+- audience, identity: N/A because no new reader or actor; rows are written as the project's PM.+- failure: the close writes a Done line in the task and a line in each closed step.+- platforms: backend only.++## Task 1: merged work is finished work++**Files:** mergedTasks.ts (new), dispatch.ts, liveness.ts, commands.ts, mergedTasks.test.ts (new).++- [ ] Tests: a lost task with its own merge recorded is not offered and the sweep sets it done, closing its working and lost+ steps, once; the merge record's close ends the steps; a merged task in review never revives its lost step; an unmerged+ lost task is still handed on; a task whose only merge is another task's pull request is never closed.+- [ ] Watch them fail; code; watch them pass; commit.