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
harden inherited-foundation guards after local review (#7461)
[._.]/ Adam Eivy1c8f46e9d7a9
diff --git a/client/src/components/eidoverse/EidoverseFoundationsPanel.jsx b/client/src/components/eidoverse/EidoverseFoundationsPanel.jsxindex 752f5c4121..9e9dd8831e 100644--- a/client/src/components/eidoverse/EidoverseFoundationsPanel.jsx+++ b/client/src/components/eidoverse/EidoverseFoundationsPanel.jsx@@ -88,6 +88,19 @@ const draftFromFoundation = (foundation) => ({notes: foundation.disclosure?.notes || '',});+/**+ * A list-rendering key that stays unique even when a local vernacular+ * foundation and an inherited copy share the same human-readable `id` — the+ * ledger stores them under disjoint keys precisely so that can happen (#7461).+ * `openId` (the `?foundation=` URL param) stays plain-id on purpose: it is+ * documented, deliberate scope that a deep link cannot yet disambiguate the+ * two, matching the "run assay"/"promote" actions, which are never offered+ * for an inherited entry in the first place.+ */+const foundationRowKey = (foundation) => (foundation.inheritance+ ? `${foundation.inheritance.originInstanceId}:${foundation.id}`+ : foundation.id);+function LayerBadge({ layer }) {const meta = LAYERS[layer];if (!meta) return <span className="rounded-full border border-port-border px-2 py-0.5 text-xs text-gray-400">{layer || 'unknown layer'}</span>;@@ -303,7 +316,7 @@ export default function EidoverseFoundationsPanel() {{foundations.map((foundation) => {const expanded = foundation.id === openId;return (- <li key={foundation.id} className="rounded-xl border border-port-border bg-port-card p-4">+ <li key={foundationRowKey(foundation)} className="rounded-xl border border-port-border bg-port-card p-4"><div className="flex flex-wrap items-start justify-between gap-3"><div className="min-w-0"><div className="flex flex-wrap items-center gap-2">@@ -319,38 +332,36 @@ export default function EidoverseFoundationsPanel() {{foundation.assay ? (foundation.assay.pass ? ' · assay passed' : ' · assay failed') : ' · assay not run'}</p></div>- {/* A local copy of a peer's foundation is never packaged or promoted- from here — it is already the origin's candidate, and promoting- it would re-share another install's work as this one's own. */}- {!foundation.inheritance && (- <div className="flex flex-wrap gap-2">- <button- type="button"- className={secondaryButton}- disabled={busyId === foundation.id}- onClick={() => runGate(foundation.id, packageEidoverseFoundationCandidate)}- >- {busyId === foundation.id ? 'Running assay…' : 'Run assay'}- </button>- <button- type="button"- className={primaryButton}- disabled={busyId === foundation.id || foundation.layer === 'baseline'}- title={foundation.layer === 'baseline' ? 'Already offered to the shared baseline' : 'Run every gate and publish to the shared baseline'}- onClick={() => runGate(foundation.id, promoteEidoverseFoundation)}- >- Promote- </button>- <button type="button" className={secondaryButton} onClick={() => openFoundation(expanded ? '' : foundation.id)}>- {expanded ? 'Hide' : 'Details'}- </button>- </div>- )}- {foundation.inheritance && (+ <div className="flex flex-wrap gap-2">+ {/* A local copy of a peer's foundation is never packaged or+ promoted from here — it is already the origin's candidate,+ and promoting it would re-share another install's work as+ this one's own (the server refuses it too). */}+ {!foundation.inheritance && (+ <>+ <button+ type="button"+ className={secondaryButton}+ disabled={busyId === foundation.id}+ onClick={() => runGate(foundation.id, packageEidoverseFoundationCandidate)}+ >+ {busyId === foundation.id ? 'Running assay…' : 'Run assay'}+ </button>+ <button+ type="button"+ className={primaryButton}+ disabled={busyId === foundation.id || foundation.layer === 'baseline'}+ title={foundation.layer === 'baseline' ? 'Already offered to the shared baseline' : 'Run every gate and publish to the shared baseline'}+ onClick={() => runGate(foundation.id, promoteEidoverseFoundation)}+ >+ Promote+ </button>+ </>+ )}<button type="button" className={secondaryButton} onClick={() => openFoundation(expanded ? '' : foundation.id)}>{expanded ? 'Hide' : 'Details'}</button>- )}+ </div></div><Verdict verdict={verdicts[foundation.id]} />diff --git a/docs/features/eidoverse.md b/docs/features/eidoverse.mdindex ac73dedb39..600a2eae92 100644--- a/docs/features/eidoverse.md+++ b/docs/features/eidoverse.md@@ -788,11 +788,16 @@ name) and its ordered lineage. `foundationLineage()``assayed` → `packaged` → `promoted`, or `inherited` → `assayed` for a localcopy of a peer's — from fields the record already persists, so it costs noextra storage and a ledger written before this existed still projects-correctly. `GET /api/eidoverse/world/foundations` and `.../foundations/:id`-return it on every entry, and the mind tools' `summarizeFoundation()`-projection carries `provenance`, `inheritance`, and `lineage` too — the same-identity fields a candidate envelope was already authorized to carry, now-surfaced consistently everywhere a foundation is read.+correctly. `GET /api/eidoverse/world/foundations` returns it on every entry,+and the mind tools' `summarizeFoundation()` projection carries `provenance`,+`inheritance`, and `lineage` too — the same identity fields a candidate+envelope was already authorized to carry, now surfaced consistently+everywhere a foundation is read. `GET /api/eidoverse/world/foundations/:id`+only reaches a locally-authored (plain-id) record: an inherited copy lives+under a separate ledger key precisely so it can share a human-readable id+with a local vernacular foundation without colliding, which also means a+single bare id cannot disambiguate the two — the list endpoint is the+provenance query surface for an inherited entry.**`recordEidoverseFoundationInheritance()`** (`eidoverseFoundationLedger.js`)is the accept-side of a peer pull: given an already-verified candidatediff --git a/server/lib/eidoverseFoundations.js b/server/lib/eidoverseFoundations.jsindex 70ecba2392..d8e14ec9e1 100644--- a/server/lib/eidoverseFoundations.js+++ b/server/lib/eidoverseFoundations.js@@ -484,8 +484,9 @@ export function verifyFoundationCandidate(candidate, { requiredDisturbances }) {* disjoint from any id `recordEidoverseFoundation()` can ever author, so* pulling a peer's foundation never touches, shadows, or can collide with a* local vernacular foundation that happens to share the same foundation id.- * `foundationIdSchema` is a plain lowercase slug with no colon, which is what- * makes this namespace collision-proof rather than merely unlikely.+ * Both `foundationIdSchema` (a plain lowercase slug) and `instanceIdSchema`+ * (opaque alphanumeric/dash/underscore) forbid colons, which is what makes+ * this `:`-delimited namespace collision-proof rather than merely unlikely.*/export function inheritedFoundationStorageKey(originInstanceId, foundationId) {return `peer:${originInstanceId}:${foundationId}`;@@ -538,6 +539,16 @@ export function foundationFromInheritedCandidate({ candidate, requiredDisturbancif (envelope.provenance.originInstanceId === localInstanceId) {return inheritanceRefused(['this candidate originated on this install — inheritance applies to another install\'s foundation, not a copy of your own']);}+ // A separate check from the one above: `sourceInstanceId` is the peer this+ // install pulled FROM, which is not always who AUTHORED the candidate (a+ // foundation can be re-shared through more than one hop). "Pulled from+ // myself" is its own nonsensical edge even when the origin is genuinely+ // someone else, and the schema validation below cannot catch it — it only+ // checks that the field is a well-formed opaque id, not that it differs+ // from `localInstanceId`.+ if (sourceInstanceId === localInstanceId) {+ return inheritanceRefused(['this install cannot be the peer it pulled the candidate from']);+ }const draft = {id: envelope.foundationId,diff --git a/server/lib/eidoverseFoundations.test.js b/server/lib/eidoverseFoundations.test.jsindex 0dca11be9e..61497b9b41 100644--- a/server/lib/eidoverseFoundations.test.js+++ b/server/lib/eidoverseFoundations.test.js@@ -226,6 +226,18 @@ describe('inheriting a foundation from a peer (#7461)', () => {expect(result.reasons.join(' ')).toContain('originated on this install');});+ it('refuses a pull whose source is this install itself, even when the origin is genuinely a different install', () => {+ const { candidate } = packageRecord();++ const result = foundationFromInheritedCandidate({+ candidate, requiredDisturbances: DISTURBANCES, sourceInstanceId: LOCAL_INSTANCE_ID, localInstanceId: LOCAL_INSTANCE_ID, now: NOW,+ });++ expect(result.outcome).toBe('refused');+ expect(result.foundation).toBeNull();+ expect(result.reasons.join(' ')).toContain('cannot be the peer it pulled');+ });+it('refuses a candidate altered after packaging, exactly as a peer running verifyFoundationCandidate would', () => {const { candidate } = packageRecord();const tampered = { ...candidate, body: { ...candidate.body, affordance: { inspect: 'quietly grants owner role' } } };diff --git a/server/routes/eidoverseWorldRoutes.js b/server/routes/eidoverseWorldRoutes.jsindex 170e87e9f0..d49fae8369 100644--- a/server/routes/eidoverseWorldRoutes.js+++ b/server/routes/eidoverseWorldRoutes.js@@ -135,7 +135,13 @@ router.post('/foundations/:id/promote', asyncHandler(async (req, res) => {res.json(result);}));-// GET /api/eidoverse/world/foundations/:id — one foundation record.+// GET /api/eidoverse/world/foundations/:id — one foundation record, looked+// up by its plain (locally-authored) id. An inherited local copy of a peer's+// foundation lives under a separate `peer:<originInstanceId>:<foundationId>`+// ledger key (#7461) and is reachable only through the LIST endpoint above —+// deliberately: two records can legitimately share the same human-readable+// `id` (a local vernacular one and an inherited one), and this route has no+// way to disambiguate which one a bare id means.router.get('/foundations/:id', asyncHandler(async (req, res) => {const { id } = validateRequest(eidoverseFoundationIdParamSchema, req.params || {});const foundation = await getEidoverseFoundation(id);diff --git a/server/services/eidoverseFoundationLedger.js b/server/services/eidoverseFoundationLedger.jsindex 995c2a1ea6..e6b5057e7a 100644--- a/server/services/eidoverseFoundationLedger.js+++ b/server/services/eidoverseFoundationLedger.js@@ -175,6 +175,16 @@ const unknownFoundation = (id) => verdict('unknown-foundation', [`no foundationexport async function packageEidoverseFoundationCandidate(id, { now = new Date().toISOString() } = {}) {const existing = await getEidoverseFoundation(id);if (!existing) return unknownFoundation(id);+ // Refused before resolving or replaying ANYTHING: `packageFoundationCandidate`+ // (the pure lib) refuses an inherited record too, but only after running the+ // assay against whatever `contributionId` it names. This is a local copy of a+ // PEER's declared contribution id — replaying it here would be exactly the+ // "run arbitrary code pulled from a peer" this install's own assay harness+ // exists to keep off every OTHER install, even though `findContributionById`+ // only ever resolves this install's own fixed local registry.+ if (existing.inheritance) {+ return verdict('refused', [`inherited from another install (${existing.inheritance.originInstanceId}) — promotion re-shares only foundations this install authored`]);+ }// Outside the ledger lock: replaying a contribution is the slow part, and it// reads nothing from the ledger. The lock below re-reads the record anddiff --git a/server/services/eidoverseFoundationLedger.test.js b/server/services/eidoverseFoundationLedger.test.jsindex 4de07ac7c4..8c7206896a 100644--- a/server/services/eidoverseFoundationLedger.test.js+++ b/server/services/eidoverseFoundationLedger.test.js@@ -8,6 +8,7 @@import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';import { rmSync } from 'node:fs';import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../lib/mockPathsDataRoot.js';+import { inheritedFoundationStorageKey } from '../lib/eidoverseFoundations.js';vi.mock('../lib/fileUtils.js', async (importOriginal) => makePathsProxy(await importOriginal(), {dataRoot: () => lazyTempDataRoot('portos-eidoverse-foundations-'),@@ -221,4 +222,28 @@ describe('inheriting a foundation this install pulled from a peer (#7461)', () =expect(result.foundation).toBeNull();expect((await listEidoverseFoundations()).counts).toMatchObject({ vernacular: 0, baseline: 0, inherited: 0 });});++ it('refuses to package or promote an inherited record without touching the ledger, even though its contributionId is registered locally', async () => {+ const candidate = await peerCandidate();+ rmSync(lazyTempDataRoot('portos-eidoverse-foundations-'), { recursive: true, force: true });+ const inherited = await recordEidoverseFoundationInheritance(candidate, {+ sourceInstanceId: 'instance-peer-relay', localInstanceId: 'instance-this-install', now: '2026-03-04T06:00:00.000Z',+ });+ const storageKey = inheritedFoundationStorageKey(inherited.foundation.provenance.originInstanceId, inherited.foundation.id);+ expect(inherited.outcome).toBe('inherited');++ // The candidate's `contributionId` ('beacon-relay-demo') IS registered+ // locally, so a guard that fired too late (after resolving the+ // contribution) would run the assay and could package it instead of+ // refusing. If the record is untouched afterward, nothing ran.+ const before = await getEidoverseFoundation(storageKey);+ const packaged = await packageEidoverseFoundationCandidate(storageKey, { now: '2026-03-04T07:00:00.000Z' });+ const promoted = await promoteEidoverseFoundation(storageKey, { now: '2026-03-04T07:00:00.000Z' });++ expect(packaged).toMatchObject({ outcome: 'refused' });+ expect(packaged.reasons[0]).toContain('inherited from another install');+ expect(promoted).toMatchObject({ outcome: 'refused', promoted: false });+ const after = await getEidoverseFoundation(storageKey);+ expect(after).toMatchObject({ assay: before.assay, updatedAt: before.updatedAt, layer: 'baseline' });+ });});