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 identity beside vanished-source provenance (#13302)
[._.]/ Adam Eivy74e042074931
diff --cc server/lib/README.mdindex 88a6a083d2,917faa879b..0f47ba0315--- a/server/lib/README.md+++ b/server/lib/README.md@@@ -26,9 -26,8 +26,9 @@@ The barrel `server/lib/index.js` is a m| Module | Purpose ||---|---|| `checkoutRetirementAdmission.js` | Durable common-repository publication/cut admission for explicit initialized-checkout quarantine; pending reservations survive restart and block managed checkout mutations until verified recovery. |- | `branchRetirementArchive.js` | `preserveBranchRetirement` preserves the shared branch reflog verbatim, records its filesystem metadata, and verifies a standalone bundle containing the current tip and every old/new reflog commit before local branch retirement. Its final verifier holds changed refs or reflogs; unsupported storage, missing objects and archive failures retain the branch. |- | `reconcileRetirementEvidence.js` | Matches exact checkout receipts, preserves observation identity across delayed scans, and retains each unresolved checkout incarnation. Legacy observations retain their original generation timestamps. |-| `branchRetirementArchive.js` | `preserveBranchRetirement` privately archives exact shared configuration, the branch reflog and a verified standalone recovery bundle. Retirement retains Git's receiver lease/holder guards, then removes only the unchanged branch configuration under native config/ref locks. Changed evidence, recreated refs, external configuration sources and uncertain deletion retain live settings and leave retirement unresolved. |-| `reconcileRetirementEvidence.js` | Matches exact checkout retirement and recovered-preservation receipts and retains unresolved cleanup obligations. Server-created generation timestamps prevent an old archive receipt from completing a recreated checkout at the same branch, path and head; verified historical preservation does not assert branch deletion. |++| `branchRetirementArchive.js` | `preserveBranchRetirement` privately archives exact shared configuration, the branch reflog and a verified standalone recovery bundle (current tip and every old/new reflog commit) before local branch retirement. Retirement retains Git's receiver lease/holder guards, then removes only the unchanged branch configuration under native config/ref locks. Changed refs, reflogs, evidence, recreated refs, external configuration, unsupported storage, missing objects and uncertain deletion retain the branch and its live settings. |++| `reconcileRetirementEvidence.js` | Matches exact checkout receipts and recovered-preservation receipts, preserves observation identity across delayed scans, and retains each unresolved checkout incarnation. Legacy observations keep their original generation timestamps. A recreated checkout at the same branch, path and head starts after every older receipt; verified historical preservation does not assert branch deletion. |+| `retirementCheckoutObservation.js` | Reads a checkout's filesystem identity and verifies its live branch/head before the schedule writer admits a recreated checkout's obligation. || `backupSharedAdmission.js` | Durable cross-process backup cuts and publication leases, with fail-closed owner recovery. || `runtimeFilePublication.js` | Admitted runtime recording updates with rollback of the prior file pair on failure. || `maintenanceAdmission.js` | Durable machine-local workflow drain, cross-process admission permits, continuation ownership and stale-resume fencing. |diff --cc server/lib/reconcileRetirementEvidence.jsindex 565c1213e8,d720fda0b4..ddb5185594--- a/server/lib/reconcileRetirementEvidence.js+++ b/server/lib/reconcileRetirementEvidence.js@@@ -1,43 -1,47 +1,72 @@@/** Exact checkout obligations survive scans until fresh service preservation evidence. */export const sameRetirementCheckout = (left, right) => left.branch === right.branch && left.path === right.path && left.head === right.head;+export const sameRetirementObservation = (left, right) => sameRetirementCheckout(left, right)+ && (left.checkoutIdentity || null) === (right.checkoutIdentity || null);++ export const isRetirementObligation = row => ['retirement-review-pending', 'retirement-receipt-unverified',+ 'retirement-provenance-unverified'].includes(row?.reason);+-export const hasRetirementReceipt = (outcome, release) => Number.isFinite(Date.parse(release.createdAt))- && (outcome?.retired?.some(row => sameRetirementCheckout(row, release) && row.branchDeleted === true+export const matchingRetirementReceipts = (outcome, release) => [...(outcome?.retired || []), ...Object.values(outcome?.retirementReceiptEvidence || {})].filter(row =>+ sameRetirementCheckout(row, release) && row.branchDeleted === true+ && typeof row.archiveDir === 'string' && row.archiveDir.length > 0+ && Number.isFinite(Date.parse(row.retiredAt)));+- export const hasRetirementReceipt = (outcome, release) => matchingRetirementReceipts(outcome, release).some(row => {- if (release.checkoutIdentity) return row.checkoutIdentity === release.checkoutIdentity;++export const hasRetirementReceipt = (outcome, release) => {+ const observed = Date.parse(release.createdAt || release.observedAt);- return Number.isFinite(observed) && Date.parse(row.retiredAt) >= observed;- });++ const receiptHit = matchingRetirementReceipts(outcome, release).some(row => {++ // Identity distinguishes a recreated checkout from the one a receipt already settled.++ if (release.checkoutIdentity) return row.checkoutIdentity === release.checkoutIdentity;++ return Number.isFinite(observed) && Date.parse(row.retiredAt) >= observed;++ });++ if (receiptHit) return true;++ // Recovered archives are not branch-deleted receipts. They settle the obligation++ // they were verified for, and only that createdAt.++ return outcome?.recoveredPreservations?.some(row => sameRetirementCheckout(row, release)++ && row.obligationCreatedAt === release.createdAt && row.verified === true+ && typeof row.archiveDir === 'string' && row.archiveDir.length > 0- && Date.parse(row.retiredAt) >= Date.parse(release.createdAt)) === true- || outcome?.recoveredPreservations?.some(row => sameRetirementCheckout(row, release)- && row.obligationCreatedAt === release.createdAt && row.verified === true- && typeof row.archiveDir === 'string' && row.archiveDir.length > 0- && /^[a-f0-9]{64}$/.test(row.evidenceDigest || '')- && Date.parse(row.archivedAt) >= Date.parse(release.createdAt)- && Date.parse(row.verifiedAt) >= Date.parse(row.archivedAt)) === true);++ && /^[a-f0-9]{64}$/.test(row.evidenceDigest || '')++ && Number.isFinite(Date.parse(release.createdAt))++ && Date.parse(row.archivedAt) >= Date.parse(release.createdAt)++ && Date.parse(row.verifiedAt) >= Date.parse(row.archivedAt)) === true;++};export function unresolvedRetirements(outcome, additional = []) {const rows = [...(outcome?.retirementObligations || []), ...(outcome?.remaining || []), ...additional];const obligations = [];for (const row of rows) {- if (!['retirement-review-pending', 'retirement-receipt-unverified'].includes(row.reason)- || hasRetirementReceipt(outcome, row) || obligations.some(previous => sameRetirementObservation(previous, row))) continue;- obligations.push({ ...row, reason: 'retirement-receipt-unverified' });+ if (!isRetirementObligation(row) || hasRetirementReceipt(outcome, row)) continue;- const previous = obligations.find(entry => sameRetirementCheckout(entry, row));++ const previous = obligations.find(entry => sameRetirementObservation(entry, row));+ if (previous) {+ if (row.reason === 'retirement-provenance-unverified') previous.reason = row.reason;+ continue;+ }- obligations.push({ ...row, reason: row.reason === 'retirement-provenance-unverified' ? row.reason : 'retirement-receipt-unverified' });++ obligations.push({++ ...row,++ reason: row.reason === 'retirement-provenance-unverified' ? row.reason : 'retirement-receipt-unverified',++ });}return obligations;}-/** Only the serialized schedule writer allocates timestamps. A recreated exact- * path/head starts after every older matching receipt, even within one clock tick.+/** New incarnations are admitted by the serialized writer after a live check.+ * Never replace a producer's observation time with its delayed write time.++ * A recreated exact path/head starts after every older matching receipt.*/export function retainRetirementObligations(outcome, additional, now) {const existing = unresolvedRetirements(outcome);- const pending = unresolvedRetirements({ retirementObligations: existing }, additional);+ const pending = unresolvedRetirements({ ...outcome, retirementObligations: existing }, additional);return pending.map(row => {- const previous = existing.find(entry => sameRetirementCheckout(entry, row));+ const previous = existing.find(entry => sameRetirementObservation(entry, row));if (Number.isFinite(Date.parse(previous?.createdAt))) return { ...row, createdAt: previous.createdAt };- const earlier = [...(outcome?.retired || []), ...(outcome?.recoveredPreservations || [])]- .filter(entry => sameRetirementCheckout(entry, row))- .map(entry => Date.parse(entry.verifiedAt || entry.retiredAt)).filter(Number.isFinite);- return { ...row, createdAt: new Date(Math.max(Date.parse(now), ...earlier.map(time => time + 1))).toISOString() };+ if (Number.isFinite(Date.parse(row.createdAt))) return row;- const earlier = matchingRetirementReceipts(outcome, row).map(entry => Date.parse(entry.retiredAt));++ const earlier = [++ ...matchingRetirementReceipts(outcome, row).map(entry => Date.parse(entry.retiredAt)),++ ...(outcome?.recoveredPreservations || [])++ .filter(entry => sameRetirementCheckout(entry, row))++ .map(entry => Date.parse(entry.verifiedAt || entry.archivedAt)),++ ].filter(Number.isFinite);+ const observed = Number.isFinite(Date.parse(row.observedAt)) ? Date.parse(row.observedAt) : Date.parse(now);+ return { ...row, createdAt: new Date(Math.max(observed, ...earlier.map(time => time + 1))).toISOString() };});}diff --cc server/services/heldCheckoutRecovery.jsindex 401f1e4381,cbff29c23b..0062273c89--- a/server/services/heldCheckoutRecovery.js+++ b/server/services/heldCheckoutRecovery.js@@@ -665,12 -984,11 +1005,12 @@@ export async function retireInventoriedconst app = await getAppById(appId);if (!app?.repoPath) return { ok: false, reason: 'app-not-found' };const outcome = await taskSchedule.getBranchReconcileOutcome(appId);- if (!outcome?.remaining?.some?.(entry => sameRelease(entry, release))) return { ok: false, reason: 'release-not-in-inventory' };+ release = bindInventoriedRelease(outcome, release);+ if (!release) return { ok: false, reason: 'release-not-in-inventory' };const inventoryCurrent = async () => (await taskSchedule.getBranchReconcileOutcome(appId))?.remaining?.some(entry => sameRelease(entry, release)) === true;const result = await retireHeldCheckout({ repoPath: app.repoPath, release, review }, { ...opts, inventoryCurrent, forgeAccount: app.forgeAccount ?? null });- // The row was stale: something else already removed the checkout. That is the- // outcome the operator asked for, so settle the row instead of refusing it.+ // A missing original cannot be archived retroactively. Retain its exact+ // identity for provenance recovery rather than equating absence with success.if (!result.ok && result.reason === 'checkout-not-found') {const gone = await findGoneInventoryRows(app.repoPath, [release]).catch(() => []);if (gone.length) {diff --cc server/services/heldCheckoutRecovery.test.jsindex e0da547a27,67b1abc0a9..4acedae925--- a/server/services/heldCheckoutRecovery.test.js+++ b/server/services/heldCheckoutRecovery.test.js@@@ -319,26 -681,16 +686,39 @@@ describe.skipIf(SKIP_HEAVY_INTEGRATION)const outcome = await getBranchReconcileOutcome('app-1');expect(outcome.status).toBe('incomplete');expect(outcome.remaining).toEqual([{ branch: 'other', reason: 'actionable' }]);- expect(outcome.retired[0]).toMatchObject({ path: release.path, branch: 'feature/held', branchDeleted: true, archiveDir: result.archiveDir });+ expect(outcome.retired[0]).toMatchObject({ path: release.path, branch: 'feature/held', branchDeleted: true, archiveDir: result.archiveDir, checkoutIdentity });+ await recordBranchReconcileOutcome('app-1', { status: 'running', remaining: [delayed] });- expect((await getBranchReconcileOutcome('app-1')).retirementObligations).toEqual([]);++ // The stale retired checkout stays settled. The sibling row left this scan, and its++ // branch is absent, so disappearance stays a provenance obligation.++ const settled = await getBranchReconcileOutcome('app-1');++ expect(settled.retirementObligations).toEqual([++ expect.objectContaining({ branch: 'other', reason: 'retirement-provenance-unverified' }),++ ]);++ expect(settled.retirementObligations.some(row => row.path === delayed.path)).toBe(false);+ await execGit(['worktree', 'add', '-b', release.branch, path, release.head], repo);+ const recreated = { ...delayed, checkoutIdentity: await readRetirementCheckoutIdentity(path), observedAt: new Date().toISOString() };+ expect(recreated.checkoutIdentity).not.toBe(checkoutIdentity);+ expect(await isCurrentRetirementCheckout(delayed)).toBe(false);+ expect(await isCurrentRetirementCheckout({ ...recreated, head: '0'.repeat(40) })).toBe(false);+ // Even while the new tuple is live, the old scan cannot create its obligation.+ await recordBranchReconcileOutcome('app-1', { status: 'running', remaining: [delayed] });- expect((await getBranchReconcileOutcome('app-1')).retirementObligations).toEqual([]);++ expect((await getBranchReconcileOutcome('app-1')).retirementObligations).toEqual([++ expect.objectContaining({ branch: 'other', reason: 'retirement-provenance-unverified' }),++ ]);+ await recordBranchReconcileOutcome('app-1', { status: 'running', remaining: [recreated] });- expect((await getBranchReconcileOutcome('app-1')).retirementObligations)- .toEqual([expect.objectContaining({ checkoutIdentity: recreated.checkoutIdentity, reason: 'retirement-receipt-unverified' })]);++ expect((await getBranchReconcileOutcome('app-1')).retirementObligations).toEqual([++ expect.objectContaining({ branch: 'other', reason: 'retirement-provenance-unverified' }),++ expect.objectContaining({ checkoutIdentity: recreated.checkoutIdentity, reason: 'retirement-receipt-unverified' }),++ ]);});- it('settles a stale inventory row whose checkout was already removed instead of refusing it', async () => {- const { path, release } = await heldCheckout('already-gone');+ it('retains vanished active claim provenance instead of reporting an unarchived checkout retired', async () => {+ const { path, release } = await heldCheckout('already-gone', { branch: 'claim/issue-42' });+ await execGit(['branch', 'other', 'main'], repo);+ const gitDir = (await execGit(['rev-parse', '--absolute-git-dir'], path)).stdout.trim();+ await writeFile(join(gitDir, 'portos-review-status'), 'private synthetic evidence');await recordBranchReconcileOutcome('app-1', {- status: 'incomplete', remaining: [{ ...release, reason: 'worktree-locked' }, { branch: 'other', reason: 'actionable' }],+ status: 'incomplete', remaining: [{ ...release, reason: 'retirement-review-pending' }, { branch: 'other', reason: 'actionable' }],});await execGit(['worktree', 'unlock', path], repo);await execGit(['worktree', 'remove', '--force', path], repo);diff --cc server/services/taskSchedule.jsindex 4dac351786,4c24df4a7c..04c34f57b8--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@@ -775,31 -774,18 +775,37 @@@ export async function recordBranchReconconst record = ensureExecutionRecord(schedule, 'branch-reconcile', appId);const now = new Date().toISOString();const previous = record.branchReconcileOutcome;+ const existing = unresolvedRetirements(previous);+ const admitted = [];+ const rejected = [];+ for (const row of [...(remaining || []), ...additionalObligations]) {+ if (!isObligationRow(row)) continue;+ if (existing.some(entry => sameRetirementObservation(entry, row))) continue;+ const previousIncarnation = existing.some(entry => sameRetirementCheckout(entry, row));+ const receipts = matchingRetirementReceipts(previous, row);+ // Legacy rows without observation identity cannot claim to be recreations.+ if (hasRetirementReceipt(previous, row)+ || ((receipts.length || previousIncarnation) && !Number.isFinite(Date.parse(row.createdAt))+ && (!row.checkoutIdentity || !await isCurrentRetirementCheckout(row).catch(() => false)))) {+ rejected.push(row);+ } else admitted.push(row);+ }- const retirementObligations = retainRetirementObligations(previous, admitted, now);+ // A fresh empty scan must not erase the last observation of vanished source.+ const omitted = remaining === undefined ? [] : (previous?.remaining || [])- .filter(row => !remaining.some(current => sameRetirementCheckout(current, row)));++ .filter(row => !remaining.some(current => sameRetirementCheckout(current, row))++ && !rejected.some(entry => sameRetirementObservation(entry, row)));+ const missing = await missingInventoryRows(appId, omitted);+ const retirementObligations = retainRetirementObligations(previous,- [...(remaining || []), ...additionalObligations, ...missing.map(missingPreservationObligation)], now);- const inventory = remaining === undefined ? previous?.remaining ?? null : remaining;++ [...admitted, ...missing.map(missingPreservationObligation)], now);+ const inventory = (remaining === undefined ? previous?.remaining ?? null : remaining)+ ?.filter(row => !rejected.some(entry => sameRetirementObservation(entry, row))) ?? null;const current = inventory?.map(row => {- const obligation = retirementObligations.find(entry => sameRetirementCheckout(entry, row));- return obligation ? { ...row, createdAt: obligation.createdAt } : row;+ const obligation = retirementObligations.find(entry => sameRetirementObservation(entry, row));+ return obligation ? { ...row, createdAt: obligation.createdAt,+ ...(obligation.checkoutIdentity && { checkoutIdentity: obligation.checkoutIdentity }),+ ...(obligation.observedAt && { observedAt: obligation.observedAt }) } : row;}) ?? null;- const retained = retirementObligations.filter(obligation => !current?.some(row => sameRetirementCheckout(row, obligation)));+ const retained = retirementObligations.filter(obligation => !current?.some(row => sameRetirementObservation(row, obligation)));record.branchReconcileOutcome = {...previous, status, reason, nextAction, updatedAt: now, retirementObligations,remaining: retained.length ? [...(current || []), ...retained] : current,