Skip to content

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

refactor: keep meatspace row identity internals private (#12432)

[._.]/ Adam Eivyaaeea03165f6
diff --git a/scripts/migrations/429-eye-exam-legacy-row-ids.test.js b/scripts/migrations/429-eye-exam-legacy-row-ids.test.js
index 34abfae41b..a2358d25c6 100644
--- a/scripts/migrations/429-eye-exam-legacy-row-ids.test.js
+++ b/scripts/migrations/429-eye-exam-legacy-row-ids.test.js
@@ -3,7 +3,10 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, beforeEach, expect, it } from 'vitest';
import migration from './429-eye-exam-legacy-row-ids.js';
-import { legacyRowId } from '../../server/lib/meatspaceRowIdentity.js';
+import { rowIdentityKeys } from '../../server/lib/meatspaceRowIdentity.js';
+
+// The content key every machine derives for a row without createdAt.
+const legacyRowId = (row) => rowIdentityKeys(row).at(-1);
let rootDir;
beforeEach(async () => { rootDir = await mkdtemp(join(tmpdir(), 'portos-eye-legacy-ids-')); });
diff --git a/server/lib/README.md b/server/lib/README.md
index 4549f1cf9c..a266e08895 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -250,7 +250,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `modelInventory.js` | Identity AND durable shape of a downloaded-model inventory row. `modelInventoryId(backend, key)` mints the `hf:` / `lora:` / `ollama:` / `lmstudio:` id and `parseModelInventoryId` splits it back on the FIRST colon (an Ollama tag like `qwen3:8b` carries one of its own). `hfInventoryRow` / `loraInventoryRow` / `localModelInventoryRow` build the row a backend contributes, and `presentInventoryRow` re-derives the live fields (residency, inventory-verified) that a STORED row can never answer. Shared by the scan that mints rows from disk (`services/systemResources.js`) and the manifest that records them at the install chokepoints (`services/modelManifest.js`) — a drifted copy of a row's risk, manage path or delete action is a delete button pointed at the wrong place. Pure and dependency-free, so the install services reach the builders without pulling the scan's module graph. |
| `videoFailure.js` | `normalizeVideoFailure` classifies and scrubs local video causes; `createVideoDiagnosticTail` retains bounded stdout/stderr diagnostics without grouping bare exit codes. |
| `maintenanceSequence.js` | The maintenance ladder shared by both runners: `MAINTENANCE_TASK_ORDER` / `MAINTENANCE_ORDER_GUIDANCE`, the interleaved `MAINTENANCE_SEQUENCE_TYPES` (a perpetual `claim-issue` drain between every pair of audits), `maintenanceStepParams` (audits file issues, documentation does the work), and `buildMaintenanceSteps` (fix mode runs audits directly with one final drain; issue filing can omit claim jobs) which emits quota-burn-shaped run-once steps so `quotaBurnInvoke.js` can run a step from the Schedule tab's manual run or a Quota Burn family plan alike. Pure. |
-| `meatspaceRowIdentity.js` | Cross-machine identity for MeatSpace health rows (#12432): `legacyRowId` derives a `legacy-<sha256>` key from a row's content, `rowIdentityKeys` lists the keys a row answers to (its id and `aliasIds`, plus the content key when it has no `createdAt`), `mergeRowCopies` collapses every group of rows sharing a key (transitively) to one row under its smallest id for the `row-union` snapshot merge, `preferRowCopy` is the total per-row `updatedAt` LWW order, `normalizeLegacyRows` stamps and dedupes legacy eye exams (also migration 429), and `ROW_TOMBSTONES_KEY` names the per-file deletion markers. Pure. |
+| `meatspaceRowIdentity.js` | Cross-machine identity for MeatSpace health rows (#12432): `rowIdentityKeys` lists the keys a row answers to (its id and `aliasIds`, plus a `legacy-<sha256>` content key when it has no `createdAt`), `mergeRowCopies` collapses every group of rows sharing a key (transitively) to one row by per-row `updatedAt` LWW under its smallest minted id for the `row-union` snapshot merge, `rowAnswersTo` / `retainContentKey` keep edits and deletes addressed by retired keys working, `normalizeLegacyRows` stamps and dedupes legacy eye exams (also migration 429), and `ROW_TOMBSTONES_KEY` names the per-file deletion markers. Pure. |
| `meetingUrl.js` | Selects the one cacheable join URL (`selectMeetingUrl`) out of a raw Google Calendar event — first http(s) `video` entry point, else `hangoutLink` — and owns the shared `MEETING_URL_MAX` bound. Three-state: `undefined` = the producer never described conferencing, `null` = described with none usable. |
| `minimaxH3Memory.js` | The declared weight-placement table for the three MiniMax H3 entries (#5420) — H3 is the one video model family whose components fit nowhere unassisted, so "does this box have enough" is a render gate, not a UI fact. `MINIMAX_H3_MEMORY_PROFILES` maps entry id → `{ shippedRepo, shippedRevision, profiles }`, each profile carrying an honest `minMemoryGb` host floor and (CUDA only) a `minVramGb` device floor, ordered best-first. Every capacity number is HOISTED from what already existed — the CUDA tiers are `resolve_offload_profile()`'s own thresholds in `scripts/generate_minimax_h3_cuda.py`, the host floors are the entries' `memoryGb` — the sole new number being `MINIMAX_H3_HOST_RESERVE_GB`, a policy reserve held back for the OS. `applyMiniMaxH3MemoryProfiles(list)` is the load-time backfill (twin of migration 317) and guards BOTH `repo` and `revision`, like the speed-profile decorator. `selectMiniMaxH3MemoryProfile({ model, totalMemoryGb })` picks the best profile the HOST can hold (VRAM is the runner's call — the server has no synchronous device view); `miniMaxH3MemoryDeclineReason()` RETURNS the fail-closed reason so the render path can 400 it and a status surface can show it, and returns `null` on an UNMEASURED host — "not measured" is a deferral to the runner, never the same as zero. `validateMiniMaxH3MemoryProfileTable` / `sanitizeMiniMaxH3MemoryProfiles` warn + strip a hand-edited table (NaN floor, duplicate/reserved id, mis-ordered tiers) at load. |
| `videoContinuity.js` | How chunk N+1 of a chained video render is conditioned on chunk N. `resolveContextFrames(requested)` normalizes the tail-window size (absent → `DEFAULT_CONTEXT_FRAMES` = 22 ≈ 1s @ 24fps; an explicit `0` is preserved as "last frame only", NOT collapsed into the default) and clamps to `MIN_CONTEXT_FRAMES`..`MAX_CONTEXT_FRAMES`. `resolveContinuityStrategy({model, contextFrames})` picks `'window'` (LTX-2 `extend_from_video` conditioned on the prior chunk's last N frames — motion, not just a pose) or `'frame'` (extract the last frame, run i2v), degrading to `'frame'` on any runtime outside `CONTEXT_WINDOW_RUNTIMES` rather than rejecting. `extendLatentFrames` / `extendedPixelFrames` convert across the VAE's `LATENT_FRAME_STRIDE` (8 pixel frames per latent), `contextPrefixFrames({totalFrames, extendLatents})` measures how much of an extend render is echoed context to trim back off before stitching (0 = leave it alone), `tailWindowStartFrame` gives the cut index for the window itself, and `planExtendSplice({sourceFrames, outputFrames, extendLatents})` decides where a plain native Extend joins the ORIGINAL source to the render's new frames (`null` = layout doesn't verify, keep the model output). Pure — importable from `prepareParams.js` without dragging in `local.js`. Mirrored for the picker in `client/src/lib/videoGenParams.js`, pinned by `videoContinuity.parity.test.js`. |
diff --git a/server/lib/meatspaceRowIdentity.js b/server/lib/meatspaceRowIdentity.js
index 962a531a2a..18afbba2b6 100644
--- a/server/lib/meatspaceRowIdentity.js
+++ b/server/lib/meatspaceRowIdentity.js
@@ -21,7 +21,7 @@ import { createHash } from 'crypto';
import { canonicalStringify, isPlainObject } from './objects.js';
import { parseTsMs } from './lwwTimestamp.js';
-export const LEGACY_ROW_ID_PREFIX = 'legacy-';
+const LEGACY_ROW_ID_PREFIX = 'legacy-';
// Per-row deletion markers (`{ id, deletedAt }`) kept at the top level of a
// row-union file, unioned in both directions by the snapshot merge.
@@ -30,7 +30,7 @@ export const ROW_TOMBSTONES_KEY = 'rowTombstones';
const hasStringId = (row) => typeof row?.id === 'string' && row.id !== '';
/** Deterministic id for a legacy row: a hash of its content without identity or clock fields. */
-export function legacyRowId(row) {
+function legacyRowId(row) {
const { id: _id, aliasIds: _aliasIds, createdAt: _createdAt, updatedAt: _updatedAt, ...content } = row;
const digest = createHash('sha256').update(canonicalStringify(content)).digest('hex');
return `${LEGACY_ROW_ID_PREFIX}${digest.slice(0, 24)}`;
@@ -80,7 +80,7 @@ export const rowLiveStamp = (row) => {
* larger canonical text. The order is total, so every machine converges on the
* same copy whichever side is local.
*/
-export function preferRowCopy(a, b) {
+function preferRowCopy(a, b) {
const am = parseTsMs(rowLiveStamp(a)) ?? -Infinity;
const bm = parseTsMs(rowLiveStamp(b)) ?? -Infinity;
if (am !== bm) return am > bm ? a : b;
diff --git a/server/services/dataSync.meatspace.test.js b/server/services/dataSync.meatspace.test.js
index d1b7b383c8..5ee3a5caae 100644
--- a/server/services/dataSync.meatspace.test.js
+++ b/server/services/dataSync.meatspace.test.js
@@ -25,7 +25,9 @@ vi.mock('../lib/fileUtils.js', async () => {
const dataSync = await import('./dataSync.js');
const health = await import('./meatspaceHealth.js');
-const { legacyRowId } = await import('../lib/meatspaceRowIdentity.js');
+const { rowIdentityKeys } = await import('../lib/meatspaceRowIdentity.js');
+// The content key every machine derives for a row without createdAt.
+const legacyRowId = (row) => rowIdentityKeys(row).at(-1);
const { queueConfigWrite, queueHealthWrite } = await import('./meatspaceWriteQueues.js');
const MEATSPACE_DIR = join(tempRoot, 'meatspace');