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: resolve an in_progress/pending merge conflict by recency so a stale peer can't revert a requeue (#3376)
[._.]/ Adam Eivye543e0e2fe9a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 832abb5ecb..35a761204b 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -165,6 +165,7 @@- **[issue-3359] The prompt-integrity snapshot now pins prompt bytes instead of the machine that generated it.** `taskPromptDefaults.test.js` hashes every current and preserved-historical prompt body against a checked-in snapshot, because editing a preserved body silently strands every other install on a prompt it can no longer recognize as an upgradable default. Prompt bodies embed this install's API origin, so hashing normalized it away first — but only the *runtime* origin, while the historical bodies written before that interpolation existed hardcode `http://localhost:5555`. The snapshot therefore only reproduced on a machine whose own origin happened to equal that literal: set a custom host, or merely run the suite in a shell with `PORT` set (as every CoS agent does), and five untouched bodies hashed differently and the suite failed reporting drift that had not happened. Regenerating the snapshot there would have been the damaging fix — it blesses whatever edited a preserved body, which is the one thing this test exists to catch. Hashing now collapses the frozen legacy origin too, which reproduces the committed snapshot byte for byte on every install, and the shared hasher is what both the test and a new `scripts/regen-prompt-integrity-snapshot.js` use, so the regeneration path can no longer normalize differently from the assertion. The guard is also in the CI planner's always-run list now: it covers a cross-install contract nothing else covers, so no impact scope may scope it out.- **[issue-3365] A pinned browser read now closes its own scratch tab, instead of every call site being expected to remember.** `navigateToUrlPinned` opens a fresh Chrome tab per call and tore it down itself on a refusal, but on success handed the caller a tab the caller was supposed to close — a convention that had already been broken twice, once leaving a tab behind for every catalog URL ingested and once for every Stacker News identity check, each fixed by hand-writing another close at the call site. The function already knows which case it is in: a caller that passes `evaluateExpression` did its DOM read on that same session and wants nothing back, while a caller that omits one wants the tab *as* the deliverable. So teardown now defaults to on exactly when an expression was supplied, the three read call sites no longer close anything, and the browser handoff and `POST /api/browser/navigate` still get their tab. `closeAfterRead: false` remains for a future caller that wants to read and keep the tab.- **[issue-3372] The server suite no longer fails two tests just because it was run from a CoS agent's worktree.** `resolveInstallRoot()` refuses a pinned data root that resolves into `data/cos/worktrees/…`, so worktree-version code can never be talked into reading or writing the live install's data (#1947) — and two tests were quietly leaning on the ambient working directory in a way that tripped exactly that guard. The relative-pin test expected `join(process.cwd(), 'some/rel')`, which inside a claim worktree resolves to a worktree path the resolver correctly refuses; the install-state test asserted that the migration ledger is read from `PATHS.installRoot`, which inside a worktree is itself a worktree path the reader deliberately short-circuits, so the call it asserted never happened. Both now pin the value they depend on — a stubbed cwd and a fixed non-worktree install root — instead of inheriting it from wherever the suite happens to be checked out. The refusal behavior is unchanged and now has a test for the relative-pin case too, and the install-state test asserts its pinned root differs from the code checkout, so it is a real check rather than a tautology on a normal install.+- **[issue-3376] A second machine's stale snapshot can no longer undo a requeue and throw away where the retry was supposed to resume.** Federated peers reconcile a task they both hold by lifecycle rank, on the reasoning that a task only ever moves forward — so the higher status is the newer truth. Two paths break that assumption by design: the orphan sweep and the retry-hold release from #3373 both move a task from `in_progress` back to `pending`, and that write is precisely the one that records the branch and worktree a retry should resume from. A peer still holding its pre-requeue view therefore won the merge on rank alone, restoring `in_progress` and discarding the resume pointer with it, so the retry that eventually ran started from an empty tree and redid work that was already committed. The `challenged` status already had an exemption for exactly this shape; `in_progress` versus `pending` now has the same one, decided by which side was edited most recently. A peer that genuinely just spawned still wins over an older `pending`, `completed` still wins outright over both, and because the rule depends only on the pair, both machines pick the same record no matter which one initiates the sweep. The wire format is unchanged — only how a conflict resolves locally — so an older peer converges on the next sweep exactly as it does today.## Three.js Modelsdiff --git a/server/services/cosTaskMerge.js b/server/services/cosTaskMerge.jsindex ff975753f2..e6bf916eda 100644--- a/server/services/cosTaskMerge.js+++ b/server/services/cosTaskMerge.js@@ -29,7 +29,10 @@* higher-ranked status is the newer truth and wins. This makes completion* converge: once either peer marks a task done, the other adopts it instead* of holding it `in_progress` forever (a live claim alone can't carry that- * signal — the owner strips the claim when it completes).+ * signal — the owner strips the claim when it completes). Two pairings are+ * exempt because their transitions run BACKWARD in rank and would otherwise+ * never converge — anything-vs-`challenged` (#2441) and `in_progress`-vs-+ * `pending` (#3376) are decided by newest `updatedAt`; see pickContentBase.** 3. Resolve the CLAIM metadata independently of content via the live lease:* a side holding an unexpired lease is authoritative (the other peer must@@ -87,6 +90,10 @@ import { PRIORITY_VALUES } from '../lib/taskParser.js';// that never actually arise (both-challenged goes to the same-status path). It is// NOT terminal (the dispute resolves back to pending or forward to blocked), so it// keeps a live claim the same way in_progress does.+//+// The `in_progress`/`pending` pair carries the same caveat (#3376): a requeue moves+// a task backward, so `pickContentBase` resolves that pair by newest `updatedAt`+// too, falling back to this rank only when the stamps tie.const STATUS_RANK = Object.freeze({ completed: 5, blocked: 4, challenged: 3, in_progress: 2, pending: 1 });const statusRank = (status) => STATUS_RANK[status] || 0;const isTerminalStatus = (status) => status === 'completed' || status === 'blocked';@@ -186,6 +193,26 @@ function pickContentBase(local, remote) {// (non-challenged) side so an overturn still converges deterministically.return lChallenged ? remote : local;}+ // `in_progress` → `pending` is the OTHER non-monotonic transition (#3376): a+ // requeue moves a task BACKWARD in rank, so a pure rank comparison lets a peer's+ // stale pre-requeue `in_progress` snapshot revert it — discarding the resume+ // pointer (`existingBranch` / `resumeWorktreePath`) that write just resolved, so+ // the eventual retry restarts from scratch. Two live paths requeue this way:+ // the orphan sweep (`handleOrphanedTask`, agentManagement.js) and the retry-hold+ // release (`releaseRetryHold`, agentWorktreeCleanup.js, #3373). So when EXACTLY+ // one side is `in_progress` and the other is `pending`, decide by newest edit —+ // both transitions bump `updatedAt`, so a genuinely newer spawn still wins over+ // an older `pending`. Symmetric (depends only on the pair), so both peers+ // converge. Scoped to this pair only: `completed` (rule 2) is never involved.+ const isRequeuePair = (local.status === 'in_progress' && remote.status === 'pending')+ || (local.status === 'pending' && remote.status === 'in_progress');+ if (isRequeuePair) {+ const lq = updatedAtMs(local);+ const rq = updatedAtMs(remote);+ // Equal/absent stamps (legacy un-stamped peer) fall through to the rank+ // comparison below, preserving today's `in_progress`-wins behavior.+ if (lq !== rq) return rq > lq ? remote : local;+ }const lr = statusRank(local.status);const rr = statusRank(remote.status);if (rr !== lr) return rr > lr ? remote : local;diff --git a/server/services/cosTaskMerge.test.js b/server/services/cosTaskMerge.test.jsindex 44d0413f42..ec37d321bb 100644--- a/server/services/cosTaskMerge.test.js+++ b/server/services/cosTaskMerge.test.js@@ -297,6 +297,63 @@ describe('mergeTaskLists', () => {});});+ describe('in_progress → pending requeue merge (#3376)', () => {+ const stamped = (id, status, updatedAt, extra = {}) =>+ task(id, status, { metadata: { updatedAt, ...extra } });++ it('a newer requeue survives a peer\'s stale in_progress snapshot, keeping its resume pointer', () => {+ // The orphan sweep (handleOrphanedTask) / retry-hold release (releaseRetryHold)+ // move in_progress → pending and stamp the resume pointer they just resolved.+ // A pure status-rank merge would let rank-2 `in_progress` revert rank-1+ // `pending` and discard that metadata.+ const requeued = [stamped('task-r', 'pending', future(1000), {+ existingBranch: 'cos/task-x/agent-y',+ resumeWorktreePath: '/data/cos/worktrees/task-x',+ })];+ const stale = [stamped('task-r', 'in_progress', past(1000))];+ for (const merged of [+ mergeTaskLists(requeued, stale, { now: NOW })[0],+ mergeTaskLists(stale, requeued, { now: NOW })[0],+ ]) {+ expect(merged.status).toBe('pending');+ expect(merged.metadata.existingBranch).toBe('cos/task-x/agent-y');+ expect(merged.metadata.resumeWorktreePath).toBe('/data/cos/worktrees/task-x');+ }+ });++ it('a genuinely newer in_progress (a peer that just spawned) still wins over an older pending', () => {+ const spawned = [stamped('task-r', 'in_progress', future(1000))];+ const older = [stamped('task-r', 'pending', past(1000))];+ expect(mergeTaskLists(older, spawned, { now: NOW })[0].status).toBe('in_progress');+ expect(mergeTaskLists(spawned, older, { now: NOW })[0].status).toBe('in_progress');+ });++ it('completed still wins outright over a newer pending or in_progress', () => {+ const completed = [stamped('task-r', 'completed', past(1000))];+ for (const newer of [+ [stamped('task-r', 'pending', future(1000))],+ [stamped('task-r', 'in_progress', future(1000))],+ ]) {+ expect(mergeTaskLists(completed, newer, { now: NOW })[0].status).toBe('completed');+ expect(mergeTaskLists(newer, completed, { now: NOW })[0].status).toBe('completed');+ }+ });++ it('on equal/absent stamps, keeps today\'s rank behavior (in_progress wins)', () => {+ const inProgress = [task('task-r', 'in_progress')];+ const pending = [task('task-r', 'pending')];+ expect(mergeTaskLists(inProgress, pending, { now: NOW })[0].status).toBe('in_progress');+ expect(mergeTaskLists(pending, inProgress, { now: NOW })[0].status).toBe('in_progress');+ // Equal (not merely absent) stamps take the same fallback.+ const sameStamp = past(500);+ expect(mergeTaskLists(+ [stamped('task-r', 'pending', sameStamp)],+ [stamped('task-r', 'in_progress', sameStamp)],+ { now: NOW },+ )[0].status).toBe('in_progress');+ });+ });+describe('cross-peer investigation fingerprint dedup (#2628)', () => {// An investigation task carries a durable fingerprint marker (#2615). Two// federated peers can each mint one for the SAME failure cause before syncing;