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: keep checkout archives within recovery budgets
[._.]/ Adam Eivy69b93117d79d
diff --git a/server/services/heldCheckoutRecovery.js b/server/services/heldCheckoutRecovery.jsindex bc8a5288ae..2d2235b5d6 100644--- a/server/services/heldCheckoutRecovery.js+++ b/server/services/heldCheckoutRecovery.js@@ -37,6 +37,14 @@ import { withClaimOwnershipLock, readClaimOwnershipAgents, retireWithUnlockedArcexport const heldCheckoutArchiveRoot = (cosDir = PATHS.cos) => join(cosDir, 'held-checkout-archives');const evidenceHash = value => createHash('sha256').update(value).digest('hex');+const MAX_ARCHIVE_FILES = 1000;++function checkArchiveBudget(content, administration) {+ if (content.files.length + administration.files.length > MAX_ARCHIVE_FILES) throw new Error('archive-file-budget-exceeded');+ // Creation and recovery share one byte budget across both snapshots.+ const total = [...content.files, ...administration.files].reduce((bytes, file) => bytes + file.bytes, 0);+ checkArchiveSize('combined', 0, total);+}const historicalNextAction = 'Locate a complete archive for this exact historical checkout and retry branch reconciliation; if none exists, recover the original data from backup. Checkout or ref absence is not preservation evidence.';/** Never follow an archive link, including an intermediate directory link. */@@ -75,7 +83,7 @@ async function verifyHeldArchive(repoPath, dir, release) {|| !Array.isArray(saved.administration?.files) || !Array.isArray(saved.administration?.symlinks)|| !saved.administration.files.some(file => file.path === 'gitdir/HEAD')|| !saved.administration.files.some(file => file.path === 'git-indirection')) throw new Error('archive-preservation-incomplete');- if (captured.files.length + saved.administration.files.length > 1000) throw new Error('archive-file-budget-exceeded');+ checkArchiveBudget(captured, saved.administration);const stamps = [];const stamp = async path => {const info = await lstat(path, { bigint: true });@@ -273,8 +281,10 @@ function checkArchiveSize(scope, fileBytes, totalBytes) {} });}-const archiveLimitRefusal = error => error.message === 'retirement-archive-limit-exceeded'- ? { ok: false, reason: error.message, archiveLimit: error.archiveLimit } : null;+const archiveLimitRefusal = error => error.message === 'archive-file-budget-exceeded'+ ? { ok: false, reason: 'retirement-archive-file-limit-exceeded' }+ : 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);@@ -361,7 +371,7 @@ async function reviewCurrentCheckout({ repoPath, release, prUrl, unlocked = falsif (forge?.error) return { ok: false, reason: /^retirement-[a-z-]+$/.test(forge.error.message) ? forge.error.message : 'retirement-forge-unavailable' };const policy = await retirementPolicy(repoPath, release.branch, opts, policyReviewIdentity(release, prUrl, forge));if (policy.reason) return { ok: false, reason: policy.reason };- return Promise.all([snapshotContent(release.path), snapshotAdministration(release.path)])+ return archiveSnapshots(matched.tree, repoPath).then(([content, administration]) => buildCheckoutRetirementReview({ repoPath, release, prUrl,contentFingerprint: content.fingerprint, administrationFingerprint: administration.fingerprint, policy }, { ...opts, readForge: async () => forge })).then(review => ({ ok: true, review }), error => archiveLimitRefusal(error) || ({ ok: false,@@ -527,7 +537,11 @@ async function missingCheckoutAdministration(repoPath, path) {}async function archiveSnapshots(tree, repoPath, missingRoot) {- if (!missingRoot) return Promise.all([snapshotContent(tree.path), snapshotAdministration(tree.path)]);+ if (!missingRoot) {+ const snapshots = await Promise.all([snapshotContent(tree.path), snapshotAdministration(tree.path)]);+ checkArchiveBudget(...snapshots);+ return snapshots;+ }const present = await lstat(tree.path).catch(error => { if (error.code === 'ENOENT') return null; throw error; });if (present) throw new Error('missing-checkout-reappeared');const prefix = ['--git-dir', missingRoot, '--work-tree', tree.path];@@ -535,7 +549,9 @@ async function archiveSnapshots(tree, repoPath, missingRoot) {const indexDiff = await git([...prefix, 'diff', '--cached', '--binary', '--no-textconv', '--no-ext-diff'], repoPath);const content = { indexDiff, worktreeDiff: '', files: [], symlinks: [], gitlinks: [], missingCheckout: true,fingerprint: createHash('sha256').update('missing-checkout\0').update(indexDiff).digest('hex') };- return [content, await snapshotAdministration(tree.path, missingRoot)];+ const administration = await snapshotAdministration(tree.path, missingRoot);+ checkArchiveBudget(content, administration);+ return [content, administration];}/** Preserve ignored content and recovery evidence before a clean merged treediff --git a/server/services/heldCheckoutRecovery.test.js b/server/services/heldCheckoutRecovery.test.jsindex 934b93b7a9..d85b9acaf6 100644--- a/server/services/heldCheckoutRecovery.test.js+++ b/server/services/heldCheckoutRecovery.test.js@@ -932,6 +932,93 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('held checkout recovery (real git)', ()return checkout;}+ it('refuses file-count overflow before preview, reviewed retirement or unattended archive publication', async () => {+ const c = await reviewedCheckout('file-count-overflow', { normalMerge: true });+ const prepared = await c.prepare();+ expect(prepared.ok).toBe(true);+ await writeFile(join(c.path, '.gitignore'), 'ignored.txt\nlinked\nprivate-files/\n');+ const directory = join(c.path, 'private-files');+ await mkdir(directory);+ // Content alone stays below 1000; its private Git administration crosses the shared limit.+ const files = Array.from({ length: 995 }, (_, i) => join(directory, `item-${i}`));+ await Promise.all(files.map(file => writeFile(file, 'preserve every tiny file\n')));+ const hashes = await Promise.all(files.map(sha256File));+ const before = await getBranchReconcileOutcome('app-1');+ const refusal = { ok: false, reason: 'retirement-archive-file-limit-exceeded' };+ expect(await c.prepare()).toEqual(refusal);+ expect(await c.confirm(prepared.review)).toEqual(refusal);+ expect(await retireInventoriedCheckout({ appId: 'app-1', release: c.release }, {+ ...c.opts, settleMergedReviewObligation: true,+ })).toEqual(refusal);+ 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('refuses combined content and administration bytes before preview or teardown while each snapshot fits', async () => {+ const c = await reviewedCheckout('combined-byte-limit', { normalMerge: true });+ const prepared = await c.prepare();+ expect(prepared.ok).toBe(true);+ await writeFile(join(c.path, '.gitignore'), 'ignored.txt\nlinked\nprivate-files/\n');+ const bytes = 22 * 1024 * 1024;+ const files = [];+ for (const root of [c.path, c.admin]) {+ const directory = join(root, 'private-files');+ await mkdir(directory);+ for (let i = 0; i < 6; i++) {+ const file = join(directory, `item-${i}`);+ await writeFile(file, 'retained bytes\n');+ await truncate(file, bytes);+ files.push(file);+ }+ }+ const hashes = await Promise.all(files.map(sha256File));+ const before = await getBranchReconcileOutcome('app-1');+ const refusal = { ok: false, reason: 'retirement-archive-limit-exceeded', archiveLimit: {+ scope: 'combined', kind: 'total', limitBytes: 250 * 1024 * 1024, observedBytes: expect.any(Number),+ } };+ const preview = await c.prepare();+ expect(preview).toEqual(refusal);+ expect(preview.archiveLimit.observedBytes).toBeGreaterThanOrEqual(12 * bytes);+ expect(preview.archiveLimit.observedBytes).toBeLessThan(12 * bytes + 1024 * 1024);+ expect(await c.confirm(prepared.review)).toEqual(refusal);+ expect(await retireInventoriedCheckout({ appId: 'app-1', release: c.release }, {+ ...c.opts, settleMergedReviewObligation: true,+ })).toEqual(refusal);+ 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('admits a near-boundary file-count archive that the missing-checkout verifier can independently recover', async () => {+ const c = await reviewedCheckout('file-count-admitted', { normalMerge: true });+ await writeFile(join(c.path, '.gitignore'), 'ignored.txt\nlinked\nprivate-files/\n');+ const directory = join(c.path, 'private-files');+ await mkdir(directory);+ await Promise.all(Array.from({ length: 980 }, (_, i) => writeFile(join(directory, `item-${i}`), 'retained ignored bytes\n')));+ const createdAt = new Date().toISOString();+ const prepared = await c.prepare();+ expect(prepared.ok).toBe(true);+ const retired = await c.confirm(prepared.review);+ expect(retired).toMatchObject({ ok: true, branchDeleted: true });+ const manifest = JSON.parse(await readFile(join(retired.archiveDir, 'manifest.json'), 'utf8'));+ const capturedCount = manifest.captured.files.length + manifest.administration.files.length;+ expect(capturedCount).toBeGreaterThanOrEqual(990);+ expect(capturedCount).toBeLessThanOrEqual(1000);+ const before = await getBranchReconcileOutcome('app-1');+ const proof = await findMissingCheckoutPreservation({ repoPath: repo, release: { ...c.release, createdAt } }, { cosDir });+ expect(proof, `Standalone archive proof failures: ${JSON.stringify(injected.proofFailures)}`)+ .toMatchObject({ archiveDir: retired.archiveDir, evidenceDigest: expect.stringMatching(/^[a-f0-9]{64}$/) });+ expect(await proof.recheck()).toBe(true);+ expect(await getBranchReconcileOutcome('app-1')).toEqual(before);+ });+it.each([{ scope: 'content', kind: 'file', count: 1, bytes: 25 * 1024 * 1024 + 1 },{ scope: 'content', kind: 'total', count: 11, bytes: 24 * 1024 * 1024 },