Skip to content

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

address review (codex): don't re-impose the stale peer's lease on an adopted requeue (#3376)

[._.]/ Adam Eivyebeae15c8d36
diff --git a/server/services/cosTaskMerge.js b/server/services/cosTaskMerge.js
index e6bf916eda..7c5133f448 100644
--- a/server/services/cosTaskMerge.js
+++ b/server/services/cosTaskMerge.js
@@ -269,8 +269,22 @@ function mergeOne(local, remote, now) {
const base = pickContentBase(local, remote);
// (rule 3) claim metadata resolved separately so a live claim propagates even
- // when content came from the other side.
- const claim = resolveClaim(local, remote, now);
+ // when content came from the other side — EXCEPT when the winner is a requeue
+ // (#3376). `cosTaskStore.updateTask` releases the claim in the very write that
+ // moves a task out of `in_progress` (#1563), precisely so a stale lease can't
+ // block the retry for a full lease window. So when a newer `pending` beats the
+ // counterpart's stale `in_progress` snapshot, that snapshot's lease is a
+ // pre-release leftover: re-applying it would re-impose the lease the requeue
+ // just dropped and undo half of what adopting the requeue bought us. Only this
+ // exact pairing is excluded — a claim held by the WINNING `pending` side is
+ // still honored, because dispatch takes the lease BEFORE flipping the status to
+ // `in_progress` (agentLifecycle.js), so `pending` + live claim is a legitimate
+ // in-flight shape a peer must keep seeing. Both peers reach the same `base` and
+ // counterpart, so this stays symmetric.
+ const counterpart = base === local ? remote : local;
+ const claim = (base.status === 'pending' && counterpart.status === 'in_progress')
+ ? (isLeaseLive(base.metadata, now) ? claimTriple(base) : null)
+ : resolveClaim(local, remote, now);
// Strip any claim keys from the base's metadata, then re-apply the resolved
// live claim — unless the merged status is terminal, where a claim must never
diff --git a/server/services/cosTaskMerge.test.js b/server/services/cosTaskMerge.test.js
index ec37d321bb..c930084d71 100644
--- a/server/services/cosTaskMerge.test.js
+++ b/server/services/cosTaskMerge.test.js
@@ -339,6 +339,42 @@ describe('mergeTaskLists', () => {
}
});
+ it('does NOT re-impose the stale in_progress side\'s lease on the adopted requeue', () => {
+ // The requeue write releases the claim (#1563) so the retry is freely
+ // claimable; rule 3 would otherwise re-attach the peer's pre-release lease
+ // and block that retry for a full lease window.
+ const requeued = [stamped('task-r', 'pending', future(1000))];
+ const stale = [task('task-r', 'in_progress', {
+ metadata: { updatedAt: past(1000), ...liveClaim('peer-A') },
+ })];
+ for (const merged of [
+ mergeTaskLists(requeued, stale, { now: NOW })[0],
+ mergeTaskLists(stale, requeued, { now: NOW })[0],
+ ]) {
+ expect(merged.status).toBe('pending');
+ expect(merged.metadata.claimedBy).toBeUndefined();
+ expect(merged.metadata.leaseExpiresAt).toBeUndefined();
+ }
+ });
+
+ it('keeps a live claim the winning pending side holds (dispatch claims before it flips to in_progress)', () => {
+ // agentLifecycle takes the lease first and only then writes in_progress, so
+ // `pending` + live claim is a real in-flight shape the peer must keep seeing.
+ const claimed = [task('task-r', 'pending', {
+ metadata: { updatedAt: future(1000), ...liveClaim('peer-B') },
+ })];
+ const stale = [task('task-r', 'in_progress', {
+ metadata: { updatedAt: past(1000), ...liveClaim('peer-A') },
+ })];
+ for (const merged of [
+ mergeTaskLists(claimed, stale, { now: NOW })[0],
+ mergeTaskLists(stale, claimed, { now: NOW })[0],
+ ]) {
+ expect(merged.status).toBe('pending');
+ expect(merged.metadata.claimedBy).toBe('peer-B');
+ }
+ });
+
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')];