Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(issue-3489): give each swarm fan-out agent its own scratch dir so PR bodies can't clobber each other
[._.]/ Adam Eivy5ba7d0fe9cd7
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 9f9fc7fcc9..200cdd18d0 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -24,6 +24,8 @@## Fixed+- **Two agents working a swarm run could overwrite each other's pull-request descriptions.** Every agent in a swarm shares one scratch directory and — by design — runs byte-identical instructions, so when two of them reached the "write the PR description to a file" step they independently picked the same obvious filename and the second quietly overwrote the first. The failure was invisible: nothing errored, the text was well-formed, and it only surfaced minutes later when the first agent re-published its now-replaced description onto its own PR. Swarm runs now hand each agent its own scratch subdirectory named for the issue it's working, so no two agents can collide on a filename, and each agent re-reads its published description after creating or editing it to confirm the right one landed. Single-issue runs are unchanged.+- **Quota burn stopped after the first family it dispatched, so a longer-windowed provider never burned at all.** A cycle selected every family whose window was inside its reset horizon, sorted them soonest-reset-first — and then returned after the first successful dispatch. Families do not share a budget: each draws down its own subscription window, against its own reserve and its own `maxDispatchesPerWindow`, so stopping early protected nothing. It just meant the soonest-resetting family took every cycle. A `claude` window resetting in 2h beat an `agy` window resetting in 21h on every tick, and the Antigravity plan sat at "93% left · 0/5 used" indefinitely while its eight configured audits never ran. A cycle now dispatches one job per *family*, records a run-log row per dispatch (so no family is hidden from the audit list), charges each window against its own key, and continues past a family whose job declines. When several plans are walked, every skip reason is prefixed with the family it came from.- **The burn-job preset picker snapped back to "Choose a preset…" the moment you picked one.** Applying a preset copies its text into the step's work prompt 60 lines further down the row, so with the control blank the click read as a no-op and people picked again. It now shows the preset whose prompt the step still matches verbatim — derived from the text rather than stored, since nothing on disk records a preset id, so it reverts to the placeholder as soon as the prompt is edited into something else and never claims a step is an audit it no longer is. Re-picking the preset a row already matches no longer raises the "replace your text?" confirm; the text *is* that preset's.diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.jsindex da940b429e..3692cd711f 100644--- a/server/services/cosTaskGenerator.js+++ b/server/services/cosTaskGenerator.js@@ -219,8 +219,8 @@ export function resolveIssueAuthorFilterBlock(promptTaskType, mode = 'self') {// forge-agnostic (partition → fan-out → serialized merge); only the PR/MR noun// and the merge command differ between GitHub (`gh`) and GitLab (`glab`).const SWARM_FORGE = {- gh: { pr: 'PR', mergeCmd: 'gh pr merge' },- glab: { pr: 'MR', mergeCmd: 'glab mr merge' }+ gh: { pr: 'PR', mergeCmd: 'gh pr merge', bodyCmd: 'gh pr view <num> --json body -q .body' },+ glab: { pr: 'MR', mergeCmd: 'glab mr merge', bodyCmd: 'glab mr view <iid> --output json | jq -r .description' }};/**@@ -235,6 +235,15 @@ const SWARM_FORGE = {* `count` independent issues. The block does NOT restate the per-issue phases —* each fan-out agent reuses the single-issue Phases 2–6 verbatim, so the swarm* layer stays a thin orchestration wrapper (never a divergent claim path).+ *+ * That verbatim-identical invariant is exactly why Phase B has to hand each agent+ * its own scratch subdirectory: N agents running identical prose independently+ * pick the same obvious filename (`pr-body.md`) in the shared session scratchpad+ * and clobber each other last-writer-wins, which once published one worker's PR+ * body onto another worker's PR. Namespacing the directory is deterministic where+ * "invent a unique filename" is not, and it covers every scratch artifact at once.+ * The trailer read-back after create/edit is the second layer, catching a wrong+ * body from any other cause.*/export function resolveSwarmBlock(promptTaskType, count) {const n = Number.isInteger(count) ? count : 0;@@ -243,7 +252,7 @@ export function resolveSwarmBlock(promptTaskType, count) {: promptTaskType === 'claim-issue' ? 'gh': null;if (!forgeKey) return ''; // plan-task / jira have no swarm flow- const { pr, mergeCmd } = SWARM_FORGE[forgeKey];+ const { pr, mergeCmd, bodyCmd } = SWARM_FORGE[forgeKey];return `# ⚡ SWARM MODE — claim and ship up to ${n} independent issues in parallel**This run operates in slashdo \`/do:next --swarm=${n}\` mode.** The single-issue framing in the task body below is your PER-AGENT playbook, not the shape of the whole run: instead of claiming ONE issue, claim up to ${n} *mutually independent* open issues and ship them concurrently, then serialize only the merges. Swarm adds exactly two things over the single-issue flow — a partition step up front and a serialized merge queue at the end; everything in between (claim, worktree, verify, implement, changelog, review gate) is the unchanged single-issue flow run once per agent. Never special-case a swarm agent's claim/ship logic.@@ -257,6 +266,10 @@ export function resolveSwarmBlock(promptTaskType, count) {## Phase B — Fan out (one subagent per picked issue)For EACH picked issue, spawn a subagent that runs the single-issue **Phases 2–6 below** for that one issue — claim (own \`claim/issue-<num>\` worktree + assignee + \`in-progress\` label) → verify → implement → changelog → open the ${pr} → run the review gate ({reviewers}) — **but with NO merge and NO Phase 7 cleanup** (the orchestrator owns those; each agent opens its ${pr} the equivalent of \`--no-merge\`). Because each agent claims through the normal Phase 2 assignee marker + race read-back, two agents can never ship the same issue.+**Each fan-out agent gets its OWN scratch subdirectory — the scratchpad root is off-limits.** Every agent in this run shares one session scratchpad path, and every agent runs these byte-identical instructions, so left to themselves two agents pick the same obvious filename (\`pr-body.md\`) and silently clobber each other — last writer wins, the command still exits 0, and the wrong text lands on the wrong ${pr}. So: **each fan-out agent writes ALL temp files under \`<scratchpad>/issue-<num>/\` (its own issue number), and NEVER writes to the scratchpad root** (the root stays the orchestrator's). That covers ${pr} body drafts, review notes, diff dumps, test output — every scratch artifact, not just the body file. Create the directory before first use (\`mkdir -p\`). Filenames inside it may be as obvious as you like; the directory is what makes them unique.++**Verify the ${pr} body's issue trailer after create AND after every edit.** The ${pr}-body flow is create-then-edit — the file is written once, then re-read minutes later during the review loop — which is a wide window for a stale or foreign body to land. Belt to the namespacing's braces: immediately after \`create\` and after each body \`edit\`, re-read the published body (\`${bodyCmd}\`) and confirm it contains this agent's own trailer (\`Closes #<num>\` or \`Refs #<num>\` for ITS issue number). If it does not, the body is wrong — rewrite it from this agent's own scratch file and re-verify before continuing. Never assume a zero exit code means the right body was published.+## Phase C — Serialize the merges (orchestrator, after all agents finish)Merge the ready ${pr}s ONE AT A TIME. For each: re-sync onto the latest default branch, gate on **required** CI (one re-run on a flaky required check, then proceed; a real failure or an irreconcilable conflict leaves that ${pr} OPEN and recorded — move to the next), then \`${mergeCmd}\`. After all merges, run Phase 7 cleanup once per merged worktree.diff --git a/server/services/cosTaskGenerator.test.js b/server/services/cosTaskGenerator.test.jsindex ea75a08e7f..f68c14861e 100644--- a/server/services/cosTaskGenerator.test.js+++ b/server/services/cosTaskGenerator.test.js@@ -440,11 +440,39 @@ describe('resolveSwarmBlock', () => {expect(block).toContain('Completion Workflow');});+ it('gives every fan-out agent its own scratch subdirectory', () => {+ // All fan-out agents share ONE session scratchpad and run byte-identical+ // instructions, so without an assigned per-agent directory two of them pick+ // the same obvious filename (pr-body.md) and clobber each other silently —+ // which once published one worker's PR body onto another worker's PR.+ const block = resolveSwarmBlock('claim-issue', 3);+ expect(block).toContain('<scratchpad>/issue-<num>/');+ expect(block).toMatch(/scratchpad root/i);+ // The scope is ALL temp files, not just the PR body that surfaced the bug.+ expect(block).toMatch(/ALL temp files/i);+ });++ it('instructs each agent to verify its own issue trailer after create and after each edit', () => {+ // Belt to the namespacing's braces: the PR-body flow is create-then-edit, so+ // a stale/foreign body can land minutes later during the review loop. `gh`+ // exits 0 either way, so only a read-back catches it.+ const block = resolveSwarmBlock('claim-issue', 3);+ expect(block).toContain('gh pr view <num> --json body -q .body');+ expect(block).toContain('Closes #<num>');+ expect(block).toContain('Refs #<num>');+ expect(block).toMatch(/after each edit|after every edit/i);+ });+it('returns a glab/MR swarm directive for the gitlab claim body', () => {const block = resolveSwarmBlock('claim-issue-gitlab', 4);expect(block).toContain('--swarm=4');expect(block).toContain('glab mr merge');expect(block).toContain('open the MR');+ // The scratch/read-back guidance is forge-agnostic — the MR body read-back+ // uses the glab command, not the gh one.+ expect(block).toContain('<scratchpad>/issue-<num>/');+ expect(block).toContain('glab mr view <iid> --output json');+ expect(block).not.toContain('gh pr view');});it('is a no-op for non-forge claim types (plan-task / jira have no swarm flow)', () => {