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

fix: distinguish checkout archive capacity refusals (#13349)

Adam Eivye813d070e340
diff --git a/server/routes/cosScheduleRoutes.js b/server/routes/cosScheduleRoutes.js
index 030c7beb66..b823400a15 100644
--- a/server/routes/cosScheduleRoutes.js
+++ b/server/routes/cosScheduleRoutes.js
@@ -295,7 +295,7 @@ router.post('/schedule/branch-reconcile/checkouts/review', asyncHandler(async (r
const { prepareInventoriedCheckoutRetirement } = await import('../services/heldCheckoutRecovery.js');
const result = await prepareInventoriedCheckoutRetirement({ appId, release, prUrl });
if (!result.ok) throw new ServerError(`Checkout review refused: ${result.reason}`, {
- status: 409, code: 'CHECKOUT_REVIEW_REFUSED', context: { reason: result.reason },
+ status: 409, code: 'CHECKOUT_REVIEW_REFUSED', context: { reason: result.reason, ...(result.archiveLimit && { archiveLimit: result.archiveLimit }) },
});
res.json(result);
}));
@@ -308,7 +308,7 @@ router.post('/schedule/branch-reconcile/checkouts/retire', asyncHandler(async (r
const result = await retireInventoriedCheckout({ appId, release, review });
if (!result.ok) {
throw new ServerError(`Checkout kept: ${result.reason}${result.detail ? ` (${result.detail})` : ''}`, {
- status: result.reason === 'app-not-found' ? 404 : 409, code: 'CHECKOUT_RETIREMENT_REFUSED', context: { reason: result.reason },
+ status: result.reason === 'app-not-found' ? 404 : 409, code: 'CHECKOUT_RETIREMENT_REFUSED', context: { reason: result.reason, ...(result.archiveLimit && { archiveLimit: result.archiveLimit }) },
});
}
res.json(result);
diff --git a/server/routes/cosScheduleRoutes.test.js b/server/routes/cosScheduleRoutes.test.js
index fd925bad02..bafcb7e522 100644
--- a/server/routes/cosScheduleRoutes.test.js
+++ b/server/routes/cosScheduleRoutes.test.js
@@ -64,6 +64,25 @@ describe('CoS Schedule Routes', () => {
expect(recovery.retireInventoriedCheckout).not.toHaveBeenCalled();
});
+ it.each([
+ ['review', 'CHECKOUT_REVIEW_REFUSED'], ['retire', 'CHECKOUT_RETIREMENT_REFUSED'],
+ ])('returns numeric archive capacity evidence on refused %s without claiming a review or receipt', async (operation, code) => {
+ const tuple = { path: '/synthetic/checkout', head: 'a'.repeat(40), branch: 'claim/42', locked: false, lockReason: null };
+ const archiveLimit = { scope: 'content', kind: 'total', limitBytes: 250 * 1024 * 1024, observedBytes: 264 * 1024 * 1024 };
+ recovery.prepareInventoriedCheckoutRetirement.mockResolvedValue({ ok: false, reason: 'retirement-archive-limit-exceeded', archiveLimit });
+ recovery.retireInventoriedCheckout.mockResolvedValue({ ok: false, reason: 'retirement-archive-limit-exceeded', archiveLimit });
+ const prUrl = 'https://github.com/example/repo/pull/42';
+ const evidence = operation === 'review' ? { prUrl } : { review: { prUrl, digest: 'b'.repeat(64), acceptSuperseded: false } };
+ const response = await request(app).post(`/api/cos/schedule/branch-reconcile/checkouts/${operation}`)
+ .send({ appId: 'app-1', ...tuple, ...evidence });
+ expect(response.status).toBe(409);
+ expect(response.body).toMatchObject({ code, context: { reason: 'retirement-archive-limit-exceeded', archiveLimit } });
+ expect(response.body).not.toHaveProperty('review');
+ expect(response.body).not.toHaveProperty('archiveDir');
+ expect(JSON.stringify(response.body)).not.toContain(tuple.path);
+ if (operation === 'review') expect(recovery.retireInventoriedCheckout).not.toHaveBeenCalled();
+ });
+
it('requires exact review and journal proofs for explicit initialized checkout operations', async () => {
const base = '/api/cos/schedule/branch-reconcile/initialized-checkouts';
const tuple = { path: '/synthetic/checkout', head: 'a'.repeat(40), branch: 'claim/42', locked: false, lockReason: null };
diff --git a/server/services/branchReconcile.js b/server/services/branchReconcile.js
index 89b8fbfa4e..99da808a6e 100644
--- a/server/services/branchReconcile.js
+++ b/server/services/branchReconcile.js
@@ -1100,6 +1100,7 @@ export function describeIdleReconcilePark(skipped = [], heldLive = [], { wip = [
...(entry.locked !== undefined && { locked: entry.locked, lockReason: entry.lockReason ?? null }),
...(entry.detached && { detached: true }),
...(entry.managed !== undefined && { managed: entry.managed }),
+ ...(entry.archiveLimit && { archiveLimit: entry.archiveLimit }),
reason: entry.cause,
})),
notLaterThan: lifts.length ? new Date(Math.min(...lifts)).toISOString() : null
diff --git a/server/services/branchReconcile.test.js b/server/services/branchReconcile.test.js
index 196bcca0a7..a317158bd5 100644
--- a/server/services/branchReconcile.test.js
+++ b/server/services/branchReconcile.test.js
@@ -2976,6 +2976,13 @@ describe('describeIdleReconcilePark', () => {
expect(out).toEqual({ reason: 'branches-blocked', heldBackMerged: [], counts: { heldBranches: 3, heldDetached: 0 }, skipCauses: { 'cleanup-disabled': 1, 'not-merged-on-recheck': 1, 'branch-delete-failed': 1 }, remaining: [{ branch: 'a', reason: 'cleanup-disabled' }, { branch: 'b', reason: 'not-merged-on-recheck' }, { branch: 'c', reason: 'branch-delete-failed' }], notLaterThan: null });
});
+ it('includes bounded archive capacity evidence in the remaining checkout status', () => {
+ const archiveLimit = { scope: 'content', kind: 'total', limitBytes: 250 * 1024 * 1024, observedBytes: 264 * 1024 * 1024 };
+ const out = describeIdleReconcilePark([{ branch: 'feature/example', reason: 'retirement-archive-limit-exceeded', archiveLimit }]);
+ expect(out.skipCauses).toEqual({ 'retirement-archive-limit-exceeded': 1 });
+ expect(out.remaining).toEqual([{ branch: 'feature/example', reason: 'retirement-archive-limit-exceeded', archiveLimit }]);
+ });
+
it('ignores an unreadable retryAt rather than parking on NaN', () => {
const out = describeIdleReconcilePark([
{ branch: 'a', reason: 'worktree-human-claim', retryAt: 'not-a-date' },
diff --git a/server/services/branchReconcileRetirement.js b/server/services/branchReconcileRetirement.js
index e5770bca8f..ee91ebdbe6 100644
--- a/server/services/branchReconcileRetirement.js
+++ b/server/services/branchReconcileRetirement.js
@@ -35,7 +35,7 @@ export async function prepareReconcileRetirements(app, result, deps = {}) {
{ beforeMutation: assertAutomaticRetirementAllowed, settleMergedReviewObligation: true })
.catch(error => ({ ok: false, reason: ['daemon-stopped', 'automatic-retirement-disabled'].includes(error.message) ? error.message : 'retirement-receipt-unverified' }));
if (outcome.ok && outcome.archiveDir && outcome.branchDeleted === true) retired.push(release);
- else held.push({ ...release, reason: outcome.reason || outcome.branchRetainedReason || 'retirement-receipt-unverified' });
+ else held.push({ ...release, reason: outcome.reason || outcome.branchRetainedReason || 'retirement-receipt-unverified', ...(outcome.archiveLimit && { archiveLimit: outcome.archiveLimit }) });
continue;
}
let failureReason = 'retirement-pr-lookup-unavailable';
@@ -43,7 +43,7 @@ export async function prepareReconcileRetirements(app, result, deps = {}) {
const prUrl = await readPr(app, branch.branch, release.head);
failureReason = 'retirement-review-unavailable';
const prepared = await prepare({ appId: app.id, release, prUrl });
- if (!prepared.ok) { held.push({ ...release, reason: prepared.reason }); continue; }
+ if (!prepared.ok) { held.push({ ...release, reason: prepared.reason, ...(prepared.archiveLimit && { archiveLimit: prepared.archiveLimit }) }); continue; }
// The preview's policy gate requires completed successful legacy review
// owners. An empty policy set after a concurrent change is not that proof.
if (!prepared.review?.policy?.policies?.length) { held.push({ ...release, reason: 'retirement-policy-changed' }); continue; }
@@ -63,7 +63,7 @@ export async function prepareReconcileRetirements(app, result, deps = {}) {
const result = await retire({ appId: app.id, release,
review: { prUrl, digest: prepared.review.digest, acceptSuperseded: false } }, { beforeMutation: assertAutomaticRetirementAllowed });
if (result.ok && result.archiveDir && result.branchDeleted === true) retired.push(release);
- else held.push({ ...release, reason: result.reason || 'retirement-receipt-unverified' });
+ else held.push({ ...release, reason: result.reason || 'retirement-receipt-unverified', ...(result.archiveLimit && { archiveLimit: result.archiveLimit }) });
continue;
}
candidates.push({ ...branch, state: 'REVIEW_RETIREMENT', retirement: { release, prUrl, digest: prepared.review.digest,
diff --git a/server/services/branchReconcileRetirement.test.js b/server/services/branchReconcileRetirement.test.js
index c9434e27e7..7f418f824e 100644
--- a/server/services/branchReconcileRetirement.test.js
+++ b/server/services/branchReconcileRetirement.test.js
@@ -148,6 +148,24 @@ describe('historical completed-checkout review obligations', () => {
expect(await prepareReconcileRetirements(app, scan(), deps)).toMatchObject({ candidates: [], held: [{ branch: branch.branch, reason }] });
});
+ it.each(['preview', 'merged-retirement', 'reviewed-retirement'])('keeps archive capacity diagnostics in held status after %s', async phase => {
+ const deps = setup();
+ const refusal = { ok: false, reason: 'retirement-archive-limit-exceeded', archiveLimit: {
+ scope: 'content', kind: 'total', limitBytes: 250 * 1024 * 1024, observedBytes: 264 * 1024 * 1024,
+ } };
+ if (phase === 'preview') deps.prepare.mockResolvedValue(refusal);
+ if (phase === 'reviewed-retirement') {
+ const prepared = await deps.prepare();
+ prepared.review.comparison = { disposition: 'integrated', localPatch: '', difference: '' };
+ deps.prepare.mockResolvedValue(prepared);
+ }
+ deps.retire = vi.fn(async () => refusal);
+ expect(await prepareReconcileRetirements(app, scan({ isMerged: phase === 'merged-retirement' }), deps)).toEqual({ candidates: [], retired: [], held: [{ branch: tree.branch, path: tree.path, head, locked: false, lockReason: null,
+ reason: refusal.reason, archiveLimit: refusal.archiveLimit,
+ }] });
+ if (phase === 'preview') expect(deps.retire).not.toHaveBeenCalled();
+ });
+
it('does not invent approval after forge failure or vanished historical policy', async () => {
const deps = setup(); deps.readPr.mockRejectedValueOnce(new Error('unreadable'));
expect((await prepareReconcileRetirements(app, scan(), deps)).held[0].reason).toBe('retirement-pr-lookup-unavailable');
diff --git a/server/services/heldCheckoutRecovery.js b/server/services/heldCheckoutRecovery.js
index cbff29c23b..bc8a5288ae 100644
--- a/server/services/heldCheckoutRecovery.js
+++ b/server/services/heldCheckoutRecovery.js
@@ -264,6 +264,18 @@ const MAX_FILE_BYTES = 25 * 1024 * 1024;
const MAX_TOTAL_BYTES = 250 * 1024 * 1024;
const GIT_OUTPUT_BYTES = 64 * 1024 * 1024;
+function checkArchiveSize(scope, fileBytes, totalBytes) {
+ if (fileBytes <= MAX_FILE_BYTES && totalBytes <= MAX_TOTAL_BYTES) return;
+ const kind = fileBytes > MAX_FILE_BYTES ? 'file' : 'total';
+ throw Object.assign(new Error('retirement-archive-limit-exceeded'), { archiveLimit: {
+ scope, kind, limitBytes: kind === 'file' ? MAX_FILE_BYTES : MAX_TOTAL_BYTES,
+ observedBytes: Math.min(kind === 'file' ? fileBytes : totalBytes, Number.MAX_SAFE_INTEGER),
+ } });
+}
+
+const archiveLimitRefusal = error => error.message === 'retirement-archive-limit-exceeded'
+ ? { ok: false, reason: error.message, archiveLimit: error.archiveLimit } : null;
+
const shortBranch = (ref) => (ref ? String(ref).replace(/^refs\/heads\//, '') : null);
const zLines = (stdout) => (stdout || '').split('\0').filter(Boolean);
const git = (args, cwd) => execGit(args, cwd, { maxBuffer: GIT_OUTPUT_BYTES }).then(r => r.stdout || '');
@@ -283,7 +295,9 @@ async function snapshotAdministration(path, missingRoot = null) {
for (const name of (await readdir(source)).sort()) await visit(join(source, name), rel ? `${rel}/${name}` : name);
return;
}
- if (!info.isFile() || info.size > MAX_FILE_BYTES || (bytes += info.size) > MAX_TOTAL_BYTES) throw new Error('administration cannot be archived');
+ if (!info.isFile()) throw new Error('administration cannot be archived');
+ bytes += info.size;
+ checkArchiveSize('administration', info.size, bytes);
files.push({ path: rel, source, bytes: info.size, sha256: await sha256File(source) });
};
await visit(root, 'gitdir');
@@ -350,7 +364,7 @@ async function reviewCurrentCheckout({ repoPath, release, prUrl, unlocked = fals
return Promise.all([snapshotContent(release.path), snapshotAdministration(release.path)])
.then(([content, administration]) => buildCheckoutRetirementReview({ repoPath, release, prUrl,
contentFingerprint: content.fingerprint, administrationFingerprint: administration.fingerprint, policy }, { ...opts, readForge: async () => forge }))
- .then(review => ({ ok: true, review }), error => ({ ok: false,
+ .then(review => ({ ok: true, review }), error => archiveLimitRefusal(error) || ({ ok: false,
reason: /^retirement-[a-z-]+$/.test(error.message) ? error.message : 'retirement-local-evidence-unavailable' }));
}
@@ -425,7 +439,7 @@ async function snapshotContent(path) {
let total = 0;
const addFile = async (rel, info, extra = {}) => {
total += info.size;
- if (info.size > MAX_FILE_BYTES || total > MAX_TOTAL_BYTES) throw new Error(`${rel} exceeds the archive size limit`);
+ checkArchiveSize('content', info.size, total);
files.push({ path: rel, bytes: info.size, sha256: await sha256File(join(path, rel)), ...extra });
};
const format = objectFormat.trim() || 'sha1';
@@ -822,7 +836,7 @@ async function retireHeldCheckout({ repoPath, release, review }, opts = {}) {
// Every ownership check queues behind the claim-ownership lock with a short
// budget, so the archive runs between two critical sections (#12682).
- const refuse = reason => ({ result: { ok: false, reason } });
+ const refuse = (reason, archiveLimit) => ({ result: { ok: false, reason, ...(archiveLimit && { archiveLimit }) } });
return retireWithUnlockedArchive({
busy: () => ({ ok: false, reason: 'checkout-retirement-reserved' }),
admit: async () => {
@@ -836,7 +850,7 @@ async function retireHeldCheckout({ repoPath, release, review }, opts = {}) {
: await isAncestor(repoPath, tree.head, defaultBranch);
if (!merged && !review) return refuse('not-merged-on-recheck');
const reviewed = review ? await reviewCurrentCheckout({ repoPath, release, prUrl: review.prUrl }, opts) : null;
- if (reviewed && (!reviewed.ok || reviewed.review.digest !== review.digest)) return refuse(reviewed.reason || 'retirement-review-changed');
+ if (reviewed && (!reviewed.ok || reviewed.review.digest !== review.digest)) return refuse(reviewed.reason || 'retirement-review-changed', reviewed.archiveLimit);
if (reviewed?.review.comparison.disposition === 'review-supersession' && review.acceptSuperseded !== true) return refuse('retirement-supersession-not-accepted');
const owner = await ownerReason({ repoPath, tree, branch, readAgents, reviewed: Boolean(review), mergedObligationSettled });
if (owner) return refuse(owner);
@@ -846,6 +860,8 @@ async function retireHeldCheckout({ repoPath, release, review }, opts = {}) {
const archive = await archiveCheckout({ repoPath, tree, branch, defaultBranch, release, cosDir, review: reviewed?.review })
.catch(error => ({ error }));
if (!archive.error) return { archive };
+ const capacityRefusal = archiveLimitRefusal(archive.error);
+ if (capacityRefusal) return { result: capacityRefusal };
console.error(`❌ held-checkout recovery: archive failed for ${tree.path}, checkout kept: ${archive.error.message}`);
return { result: { ok: false, reason: 'archive-failed', detail: archive.error.message } };
},
diff --git a/server/services/heldCheckoutRecovery.test.js b/server/services/heldCheckoutRecovery.test.js
index 67b1abc0a9..934b93b7a9 100644
--- a/server/services/heldCheckoutRecovery.test.js
+++ b/server/services/heldCheckoutRecovery.test.js
@@ -69,6 +69,7 @@ vi.mock('./taskScheduleStore.js', async (importOriginal) => ({
vi.mock('./apps.js', () => ({ getAppById: async (id) => (injected.app?.id === id ? injected.app : null) }));
const { retireInventoriedCheckout, prepareInventoriedCheckoutRetirement, retirePendingMergeCheckout, heldCheckoutArchiveRoot, preserveMergedCheckout, recoverMissingCheckoutPreservations, findMissingCheckoutPreservation } = await import('./heldCheckoutRecovery.js');
+const { sha256File } = await import('../lib/fileUtils.js');
const { recordBranchReconcileOutcome, getBranchReconcileOutcome, recordHeldCheckoutRetirement, parkPerpetual } = await import('./taskSchedule.js');
const { withClaimOwnershipLock, checkReconcileOwnership } = await import('./cosClaimOwnership.js');
@@ -931,6 +932,71 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('held checkout recovery (real git)', ()
return checkout;
}
+ it.each([
+ { scope: 'content', kind: 'file', count: 1, bytes: 25 * 1024 * 1024 + 1 },
+ { scope: 'content', kind: 'total', count: 11, bytes: 24 * 1024 * 1024 },
+ { scope: 'administration', kind: 'file', count: 1, bytes: 25 * 1024 * 1024 + 1 },
+ { scope: 'administration', kind: 'total', count: 11, bytes: 24 * 1024 * 1024 },
+ ])('reports $scope $kind capacity at the public preview boundary without changing checkout bytes', async ({ scope, kind, count, bytes }) => {
+ const c = await reviewedCheckout('archive-capacity');
+ const root = join(scope === 'content' ? c.path : c.admin, 'private-build-output');
+ await mkdir(root);
+ if (scope === 'content') await writeFile(join(c.path, '.gitignore'), 'ignored.txt\nlinked\nprivate-build-output/\n');
+ const files = Array.from({ length: count }, (_, i) => join(root, `private-${i}.bin`));
+ for (const file of files) {
+ await writeFile(file, 'synthetic preserved bytes');
+ await truncate(file, bytes);
+ }
+ const hashes = await Promise.all(files.map(sha256File));
+ const before = await getBranchReconcileOutcome('app-1');
+ const result = await c.prepare();
+ expect(result).toEqual({ ok: false, reason: 'retirement-archive-limit-exceeded', archiveLimit: {
+ scope, kind, limitBytes: (kind === 'file' ? 25 : 250) * 1024 * 1024, observedBytes: expect.any(Number),
+ } });
+ expect(Number.isSafeInteger(result.archiveLimit.observedBytes)).toBe(true);
+ expect(result.archiveLimit.observedBytes).toBeGreaterThan(result.archiveLimit.limitBytes);
+ expect(result.archiveLimit.observedBytes).toBeLessThanOrEqual(count * bytes + 1024 * 1024);
+ expect(JSON.stringify(result)).not.toContain('private-');
+ expect(JSON.stringify(result)).not.toContain(c.path);
+ expect(JSON.stringify(result)).not.toContain(c.admin);
+ expect(await Promise.all(files.map(sha256File))).toEqual(hashes);
+ expect(await registered(c.path)).toBe(true);
+ expect(await lockText(c.path)).toBe(c.release.lockReason);
+ expect((await execGit(['rev-parse', c.release.branch], repo)).stdout.trim()).toBe(c.release.head);
+ expect(await archives()).toEqual([]);
+ expect(await getBranchReconcileOutcome('app-1')).toEqual(before);
+ });
+
+ it('keeps non-capacity local evidence failures distinct from archive capacity', async () => {
+ const c = await reviewedCheckout('unreadable-snapshot');
+ await execGit(['update-index', '--skip-worktree', 'initial.txt'], c.path);
+ expect(await c.prepare()).toEqual({ ok: false, reason: 'retirement-local-evidence-unavailable' });
+ expect(await registered(c.path)).toBe(true);
+ expect(await archives()).toEqual([]);
+ });
+
+ it.each(['reviewed', 'merged'])('retains archive capacity evidence when %s retirement refuses before archival', async mode => {
+ const c = await reviewedCheckout('retire-capacity', { normalMerge: true });
+ const prepared = await c.prepare();
+ expect(prepared.ok).toBe(true);
+ const file = join(c.path, 'ignored.txt');
+ const bytes = 25 * 1024 * 1024 + 1;
+ await truncate(file, bytes);
+ const hash = await sha256File(file);
+ const before = await getBranchReconcileOutcome('app-1');
+ const result = mode === 'reviewed' ? await c.confirm(prepared.review)
+ : await retireInventoriedCheckout({ appId: 'app-1', release: c.release }, { ...c.opts, settleMergedReviewObligation: true });
+ expect(result).toEqual({ ok: false, reason: 'retirement-archive-limit-exceeded', archiveLimit: {
+ scope: 'content', kind: 'file', limitBytes: bytes - 1, observedBytes: bytes,
+ } });
+ expect(await sha256File(file)).toBe(hash);
+ expect(await registered(c.path)).toBe(true);
+ expect(await lockText(c.path)).toBe(c.release.lockReason);
+ expect((await execGit(['rev-parse', c.release.branch], repo)).stdout.trim()).toBe(c.release.head);
+ expect(await archives()).toEqual([]);
+ expect(await getBranchReconcileOutcome('app-1')).toEqual(before);
+ });
+
it('retires a merged receipt checkout without an inventory grant, preserving ignored bytes and original commits', async () => {
const c = await receiptCheckout('receipt', { gitlink: true });
const result = await c.retireReceipt();