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: rank foundation checkpoints by severity
[._.]/ Adam Eivyffd66c1986cf
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 99c1e70740..094068ee65 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -46,6 +46,8 @@## Fixed+- **Foundation structure repair now keeps the safest verified checkpoint, not merely the one with the fewest findings.** The bounded verifier loop ranked candidates by raw blocker count, so a live repair that eliminated every high-severity authorization and climax failure was discarded because its deeper pass surfaced six medium/low follow-ups while an earlier four-finding checkpoint still contained two highs. Checkpoints are now ordered lexicographically by high, medium, low, then total count: one unresolved high can never be hidden by any number of polish findings, while equal-severity sets still prefer the smaller residual. The retained-progress message reports the complete severity profile so a partial repair is auditable.+- **The prompt-drift baseline caught up with the arc-resolve migration, un-reddening `main`.** Migration 254 shipped a new `pipeline-arc-resolve.md` and correctly recorded the prior default as an accepted-old hash, but the independent baseline in `scripts/setup-data-drift.test.js` still named the superseded hash as current — so the drift sweep disagreed with the migrations it mirrors and the suite failed on every commit after it landed. The baseline now carries the shipped hash and lists the previous one among the accepted-old set. The guard itself is unchanged and still fails when a migration ships a hash it doesn't export.- **Body stats on the MeatSpace Overview card no longer show raw float precision.** A unit-converted weight rendered every binary digit it carried (the shape `170.35000000000002 lbs`), blowing out the tile's line and implying precision the measurement never had. Weight, body fat, lean mass, and the body-composition chart's tooltip now share `formatWeight` / `formatPercent` from the client formatters, which round to one decimal, drop trailing zeros, and render a dash for a missing reading instead of a coerced zero.diff --git a/server/services/pipeline/foundationJudge.js b/server/services/pipeline/foundationJudge.jsindex 8f5073e453..876ba169f3 100644--- a/server/services/pipeline/foundationJudge.js+++ b/server/services/pipeline/foundationJudge.js@@ -101,6 +101,37 @@ const JUDGE_OUTPUT_RESERVE_TOKENS = 2_000;const nowIso = () => new Date().toISOString();+const ARC_BLOCKER_SEVERITIES = Object.freeze(['high', 'medium', 'low']);++function arcBlockerProfile(findings) {+ const list = Array.isArray(findings) ? findings : [];+ const profile = Object.fromEntries(ARC_BLOCKER_SEVERITIES.map((severity) => [severity, 0]));+ for (const finding of list) {+ const severity = ARC_BLOCKER_SEVERITIES.includes(finding?.severity) ? finding.severity : 'medium';+ profile[severity] += 1;+ }+ return { ...profile, total: list.length };+}++// Negative means `left` is the safer checkpoint. A smaller high-severity count+// outranks raw total: six polish findings are preferable to four findings that+// still include a broken authorization or climax. Medium, low, then total break+// ties. This is deliberately lexicographic rather than a weighted sum so no+// number of low findings can conceal one unresolved high blocker.+function compareArcBlockers(left, right) {+ const a = arcBlockerProfile(left);+ const b = arcBlockerProfile(right);+ for (const key of [...ARC_BLOCKER_SEVERITIES, 'total']) {+ if (a[key] !== b[key]) return a[key] - b[key];+ }+ return 0;+}++function formatArcBlockerProfile(findings) {+ const profile = arcBlockerProfile(findings);+ return `${profile.total} blocker(s): ${profile.high} high, ${profile.medium} medium, ${profile.low} low`;+}+// Defense-in-depth: refuse path-traversal-shaped ids before interpolating into// the on-disk snapshot path (series ids are `ser-<uuid>`).function assertValidSeriesId(id) {@@ -1855,7 +1886,7 @@ export async function applyFoundationFix(seriesId, dimension, {return { dimension, applied: true, actions: 2, acceptedRunIds: firstAttempt.runIds };}- const initialBlockerCount = blockers.length;+ const initialBlockers = blockers;let retainedRunIds = [...firstAttempt.runIds];let rejectedRunIds = [];let bestVerified = {@@ -1866,14 +1897,14 @@ export async function applyFoundationFix(seriesId, dimension, {// A foundation-directed structure rewrite can satisfy its broad judge// while accidentally violating a narrower canon/location/timing rule.- // Keep correcting while the specialized verifier's blocker count shrinks.+ // Keep correcting while the specialized verifier's severity profile improves.// A single all-or-nothing pass threw away demonstrated 10 → 3 progress and// forced the next run to rebuy all ten fixes. The bounded loop preserves// the original rollback guarantee, but spends up to three focused passes// when each one is moving monotonically toward a clean plan.let actions = 2;for (let pass = 0; pass < MAX_STRUCTURE_CORRECTION_PASSES && blockers.length > 0; pass += 1) {- const before = blockers.length;+ const before = blockers;const correctionAttempt = await trackedResolve(blockers);const correction = correctionAttempt.result;actions += 1;@@ -1891,12 +1922,12 @@ export async function applyFoundationFix(seriesId, dimension, {rejectedRunIds,};}- if (blockers.length > before) {+ if (compareArcBlockers(blockers, before) > 0) {rejectedRunIds = [...rejectedRunIds, ...correctionAttempt.runIds];break;}retainedRunIds = [...retainedRunIds, ...correctionAttempt.runIds];- if (blockers.length <= bestVerified.blockers.length) {+ if (compareArcBlockers(blockers, bestVerified.blockers) <= 0) {bestVerified = {blockers,snapshot: await snapshotArcState(seriesId),@@ -1910,14 +1941,14 @@ export async function applyFoundationFix(seriesId, dimension, {// the best independently verified checkpoint; the foundation judge will// still decide whether it improved structure, and the normal full-arc// gate remains latched dirty so it must close the residual before beats.- if (bestVerified.blockers.length < initialBlockerCount) {+ if (compareArcBlockers(bestVerified.blockers, initialBlockers) < 0) {await restoreArcState(seriesId, bestVerified.snapshot);return {dimension,applied: true,partial: true,actions,- reason: `structure repair retained its best verified improvement (${initialBlockerCount} → ${bestVerified.blockers.length} blocker(s)); the full arc gate must close the residual`,+ reason: `structure repair retained its best verified improvement (${formatArcBlockerProfile(initialBlockers)} → ${formatArcBlockerProfile(bestVerified.blockers)}); the full arc gate must close the residual`,residual: bestVerified.blockers,discarded: blockers,acceptedRunIds: bestVerified.runIds,diff --git a/server/services/pipeline/foundationJudge.test.js b/server/services/pipeline/foundationJudge.test.jsindex 1ed709d656..c7ef6785e0 100644--- a/server/services/pipeline/foundationJudge.test.js+++ b/server/services/pipeline/foundationJudge.test.js@@ -1237,6 +1237,54 @@ describe('applyFoundationFix — dimension → owning-service routing table', ()expect(r.discarded).toHaveLength(5);});+ it('prefers more lower-severity residuals over fewer high-severity blockers', async () => {+ const original = { seriesId: 'ser-1', arc: { logline: 'Original' }, seasons: [], episodes: [] };+ const highCheckpoint = { seriesId: 'ser-1', arc: { logline: 'Two high blockers remain' }, seasons: [], episodes: [] };+ const lowerCheckpoint = { seriesId: 'ser-1', arc: { logline: 'Only medium and low residuals' }, seasons: [], episodes: [] };+ arcPlanner.snapshotArcState+ .mockResolvedValueOnce(original)+ .mockResolvedValueOnce(highCheckpoint)+ .mockResolvedValueOnce(lowerCheckpoint);+ const findings = (severities, prefix) => severities.map((severity, i) => ({+ severity, location: `Issue ${i + 1}`, problem: `${prefix} ${i + 1}`,+ }));+ const highResiduals = findings(['high', 'high', 'medium', 'medium'], 'high checkpoint');+ const lowerResiduals = findings(['medium', 'medium', 'medium', 'medium', 'medium', 'low'], 'lower checkpoint');+ const worseResiduals = findings(['medium', 'medium', 'medium', 'medium', 'medium', 'medium', 'low'], 'worse checkpoint');+ arcPlanner.verifyArc+ .mockResolvedValueOnce({ issues: highResiduals })+ .mockResolvedValueOnce({ issues: lowerResiduals })+ .mockResolvedValueOnce({ issues: worseResiduals });+ arcPlanner.resolveVerifyIssues+ .mockImplementationOnce(async (_id, options) => {+ options.onRunCreated('structure-broad');+ return { applied: true };+ })+ .mockImplementationOnce(async (_id, options) => {+ options.onRunCreated('structure-lower-severity');+ return { applied: true };+ })+ .mockImplementationOnce(async (_id, options) => {+ options.onRunCreated('structure-more-mediums');+ return { applied: true };+ });++ const r = await applyFoundationFix('ser-1', 'structure', {+ finding: { gap: 'The issue plan contradicts the spine.', fix: 'Reconcile it.' },+ onRunCreated: vi.fn(),+ });++ expect(arcPlanner.restoreArcState).toHaveBeenCalledWith('ser-1', lowerCheckpoint);+ expect(r).toMatchObject({+ dimension: 'structure', applied: true, partial: true,+ acceptedRunIds: ['structure-broad', 'structure-lower-severity'],+ rejectedRunIds: ['structure-more-mediums'],+ });+ expect(r.residual).toEqual(lowerResiduals);+ expect(r.discarded).toEqual(worseResiduals);+ expect(r.reason).toContain('0 high, 5 medium, 1 low');+ });+it('rolls a structure repair back when its bounded correction remains unverified', async () => {const snapshot = { seriesId: 'ser-1', arc: { logline: 'Before' }, seasons: [], episodes: [] };arcPlanner.snapshotArcState.mockResolvedValue(snapshot);