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: preserve complete bounded recovery review output
[._.]/ Adam Eivy0a0e4a19547e
diff --git a/scripts/recover-initialized-checkout.js b/scripts/recover-initialized-checkout.jsindex 6907ec2268..50278bbbee 100644--- a/scripts/recover-initialized-checkout.js+++ b/scripts/recover-initialized-checkout.js@@ -22,7 +22,10 @@ import { isDirectlyInvoked } from './lib/directInvocation.js';const CODE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');const MAX_REQUEST_BYTES = 16 * 1024;-const MAX_RESPONSE_BYTES = 1024 * 1024;+// Two patches and a path inventory each have a 4 MiB Git output budget.+// JSON escaping can expand these sixfold (72 MiB); reserve another 24 MiB for+// native/forge evidence and the envelope. Refuse larger records, never truncate.+const MAX_RESPONSE_BYTES = 96 * 1024 * 1024;const HASH = /^[a-f0-9]{64}$/;const ID = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;const ACTIONS = {diff --git a/scripts/recover-initialized-checkout.test.js b/scripts/recover-initialized-checkout.test.jsindex 06192032e9..de9ed9d6ca 100644--- a/scripts/recover-initialized-checkout.test.js+++ b/scripts/recover-initialized-checkout.test.js@@ -66,6 +66,48 @@ describe('initialized checkout recovery CLI', () => {await expect(stat(f.output)).rejects.toMatchObject({ code: 'ENOENT' });});+ it('records complete large escaped quarantine evidence privately', async () => {+ const f = await fixture('review-quarantine');+ // Each patch remains within the upstream 4 MiB byte budget, but JSON+ // escaping plus Unicode makes the complete response much larger than 1 MiB.+ const patch = '\0\n"\\界'.repeat(512 * 1024);+ expect(Buffer.byteLength(patch)).toBeLessThanOrEqual(4 * 1024 * 1024);+ const response = { ok: true, review: { digest: 'c'.repeat(64),+ comparison: { localPatch: patch, difference: patch, paths: ['src/界.js'] } } };+ const stdout = vi.fn();+ expect(await runRecovery(f.args, { load: async () => ({ reviewQuarantineResumption: async () => response }), stdout })).toBe(0);+ const raw = await readFile(f.output, 'utf8');+ expect(Buffer.byteLength(raw)).toBeGreaterThan(1024 * 1024);+ const records = raw.trim().split('\n').map(JSON.parse);+ expect(records).toHaveLength(2);+ expect(records[1].response).toEqual(response);+ if (process.platform !== 'win32') expect((await stat(f.output)).mode & 0o777).toBe(0o600);+ expect(stdout.mock.calls).toHaveLength(1);+ expect(Buffer.byteLength(stdout.mock.calls[0][0])).toBeLessThan(1024);+ expect(JSON.parse(stdout.mock.calls[0][0])).toMatchObject({ ok: true, reviewDigest: response.review.digest });+ expect(stdout.mock.calls[0][0]).not.toContain('comparison');+ });++ it('retains an inspect-before-retry outcome when serialized evidence exceeds the fixed response budget', async () => {+ const f = await fixture('review-quarantine');+ const stdout = vi.fn();+ // 16 MiB of control bytes expands to 96 MiB before the JSON envelope.+ // Exercise the actual byte cap without creating an oversized output file.+ const load = async () => ({ reviewQuarantineResumption: async () => ({+ ok: true, review: { digest: 'c'.repeat(64), evidence: '\0'.repeat(16 * 1024 * 1024) },+ }) });+ expect(await runRecovery(f.args, { load, stdout })).toBe(1);+ const raw = await readFile(f.output, 'utf8');+ expect(Buffer.byteLength(raw)).toBeLessThan(2048);+ const records = raw.trim().split('\n').map(JSON.parse);+ expect(records).toHaveLength(2);+ expect(records[0].outcome).toBe('pending-or-uncertain');+ expect(records[1]).toMatchObject({ outcome: 'inspect-before-any-retry', reason: 'recovery-response-exceeds-budget' });+ expect(records[1]).not.toHaveProperty('response');+ expect(JSON.parse(stdout.mock.calls[0][0])).toEqual({ ok: false, reason: 'recovery-response-exceeds-budget' });+ if (process.platform !== 'win32') expect((await stat(f.output)).mode & 0o777).toBe(0o600);+ });+it.each(['missing-review', 'nonboolean-supersession', 'caller-proof'])('refuses quarantine %s before loading the service', async change => {const f = await fixture('resume-quarantine');const body = { ...f.body };diff --git a/server/services/initializedCheckoutRecovery.js b/server/services/initializedCheckoutRecovery.jsindex 0c44ef81c3..501374c290 100644--- a/server/services/initializedCheckoutRecovery.js+++ b/server/services/initializedCheckoutRecovery.js@@ -577,7 +577,9 @@ export function _createInitializedCheckoutRecovery(deps = {}) {|| !['original', 'quarantine'].includes(proof.initialPlacements?.administration)) fail('quarantine-resumption-placement-not-ready');const current = await quarantineSafety(bound, proof.initialPlacements.administration === 'quarantine');if (JSON.stringify(current) !== JSON.stringify(before)) fail('retirement-evidence-changed');- const evidence = { ...current, safetyEvidence: current, version: 1, mode: 'resume-initialized-quarantine', transactionId: state.id,+ // Retain the complete comparison once. This separate hash also binds the+ // exact safety projection re-read between moves without duplicating patches.+ const evidence = { ...current, safetyEvidenceDigest: hash(current), version: 1, mode: 'resume-initialized-quarantine', transactionId: state.id,repoPath: ctx.repoPath, release: state.release, journalDigest: hash(state), phase: state.phase, reservation,quarantineResumption: proof.quarantineResumption, initialPlacements: proof.initialPlacements,changeCounts: proof.changeCounts, changedPaths: proof.changedPaths };@@ -594,7 +596,7 @@ export function _createInitializedCheckoutRecovery(deps = {}) {const proof = quarantineProofInput({ ...bound, state });const assertSafety = async administrationQuarantined => {const fresh = await quarantineSafety({ ...bound, state }, administrationQuarantined);- if (JSON.stringify(fresh) !== JSON.stringify(current.safetyEvidence)) fail('retirement-evidence-changed');+ if (hash(fresh) !== current.safetyEvidenceDigest) fail('retirement-evidence-changed');executor.assertHeld();};await assertSafety(current.initialPlacements.administration === 'quarantine');diff --git a/server/services/initializedCheckoutRecovery.test.js b/server/services/initializedCheckoutRecovery.test.jsindex bc9cd154a8..1a8c9b3e1f 100644--- a/server/services/initializedCheckoutRecovery.test.js+++ b/server/services/initializedCheckoutRecovery.test.js@@ -388,6 +388,62 @@ describe('initialized checkout transaction', () => {const status = await fixture.service.status(input);return { ...input, journalDigest: status.journalDigest };};+ it('retains large quarantine comparisons once and rejects changed patch bytes after approval', async () => {+ const input = await interruptedMetadata();+ let patch = 'private patch "\n界'.repeat(80_000);+ const comparison = fixture.deps.comparison;+ fixture.deps.comparison = async (...args) => {+ const evidence = await comparison(...args);+ return { ...evidence, comparison: { ...evidence.comparison, localPatch: patch } };+ };+ const service = _createInitializedCheckoutRecovery(fixture.deps);+ const prepared = await service.reviewQuarantineResumption(input);+ expect(prepared.ok).toBe(true);+ expect(prepared.review.comparison.localPatch).toBe(patch);+ expect(prepared.review).not.toHaveProperty('safetyEvidence');+ const safety = await fixture.deps.comparison(null, release, prUrl, fixture.snapshot, null, fixture.facts);+ expect(prepared.review.safetyEvidenceDigest).toBe(createHash('sha256').update(JSON.stringify(safety)).digest('hex'));+ expect(JSON.stringify(prepared).split(JSON.stringify(patch).slice(1, -1))).toHaveLength(2);+ const unsigned = { ...prepared.review }; delete unsigned.digest;+ expect(createHash('sha256').update(JSON.stringify(unsigned)).digest('hex')).toBe(prepared.review.digest);+ // Drift after the fresh approval recheck must also be caught by the+ // between-moves safety read, before administration leaves its original path.+ const native = fixture.deps.native.getMockImplementation();+ fixture.deps.native.mockImplementation(async request => {+ const result = await native(request);+ if (request.command === 'verify-quarantine-resumption') patch += 'changed';+ return result;+ });+ expect(await service.resumeQuarantine({ ...input, review: { digest: prepared.review.digest } }))+ .toMatchObject({ ok: false, reason: 'retirement-evidence-changed' });+ expect(fixture.placement).toEqual({ working: 'quarantined', administration: 'original' });+ expect(fixture.cut).not.toBeNull();+ expect(fixture.deps.native.mock.calls.some(([row]) => row.command === 'resume-quarantine')).toBe(false);+ });+ it('keeps previously journalled full safety evidence verifiable for a fresh branch review', async () => {+ const input = await resumedQuarantine();+ const directory = join(root, input.transactionId);+ const names = (await readdir(directory)).filter(name => /^\d{6}\.json$/.test(name)).sort();+ const previous = JSON.parse(await readFile(join(directory, names.at(-1)), 'utf8'));+ // Model an immutable journal produced by the preceding release, including+ // its duplicated safety evidence. The new code must not rewrite this row.+ const accepted = { ...previous.quarantineResumptionReview };+ const safetyEvidence = await fixture.deps.comparison(null, release, prUrl, fixture.snapshot, null, fixture.facts);+ delete accepted.digest;+ delete accepted.safetyEvidenceDigest;+ accepted.safetyEvidence = safetyEvidence;+ const legacy = { ...previous, sequence: previous.sequence + 1,+ previous: createHash('sha256').update(JSON.stringify(previous)).digest('hex'),+ quarantineResumptionReview: { digest: createHash('sha256').update(JSON.stringify(accepted)).digest('hex'), ...accepted } };+ const saved = JSON.stringify(legacy);+ const name = join(directory, `${String(legacy.sequence).padStart(6, '0')}.json`);+ await writeFile(name, saved, { mode: 0o600, flag: 'wx' });+ const response = await _createInitializedCheckoutRecovery(fixture.deps).reviewBranch({+ ...input, journalDigest: createHash('sha256').update(saved).digest('hex'),+ });+ expect(response).toMatchObject({ ok: true, review: { quarantineResumptionReview: legacy.quarantineResumptionReview } });+ expect(await readFile(name, 'utf8')).toBe(saved);+ });it('resumes only administration quarantine under a fresh purpose-bound review, then requires a separate branch approval', async () => {const input = await interruptedMetadata();const moves = fixture.deps.native.mock.calls.filter(([row]) => row.command === 'move').length;