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

fix sprite detail 500 and broken walk-loop thumbnails for imported characters

[._.]/ Adam Eivy89e576e09bd2
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 1c3f53ddcd..efc2ad079d 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -85,3 +85,4 @@
- **[issue-2847] Confirm and harden the CyberCity intel tab bar** — the hand-rolled `role="tablist"` in `CityIntelPane` stays hand-rolled (its cyan/`font-pixel` HUD skin and severity-tinted count chips would need a one-off variant in the shared `ui/TabPills`, which no other call site would use) and now carries a comment saying so, so future audits skip it. The ARIA it duplicates is corrected in the process: the collapse toggle moves out of the tablist (it was an invalid non-tab child), each tab gains `id`/`aria-controls` paired to a real `role="tabpanel"`, roving `tabIndex` plus Left/Right/Home/End keyboard navigation, and `aria-expanded` on the collapse toggle; `aria-selected` now tracks the selected tab rather than dropping to false while the pane is collapsed. The three buttons are driven from the already-exported `CITY_INTEL_TABS` instead of triplicated markup.
- **[issue-2839] Extract the boot sequence from `server/index.js` into a bootstrap service** — the ~600 lines of inline startup orchestration (data migrations, collection-schema verification, AI Toolkit construction + runner registration, ~40 fire-and-forget service inits/schedulers, the ordered instance/sync/media-queue/DB chain that ends in `httpServer.listen()`, and the graceful-shutdown state machine) move to `server/services/bootstrap.js` as `bootstrapServices()` / `runBootSequence()` / `registerShutdownHandlers()`. `index.js` drops from 1259 to ~460 lines and is now HTTP/Socket.IO construction, route registration, and three calls into the bootstrap service. Boot ordering, the DB fail-fast gate, and shutdown behavior are unchanged; no new LLM calls at boot.
- **Pick the sprite import source from the managed-apps list instead of typing a path** — the Sprites import panel replaced its free-text "Source root path" input with the shared `AppContextPicker`, loading `GET /api/apps` on open and filtering to non-archived apps that declare a `repoPath`; the selected app's `repoPath` becomes the importer's `sourceRoot`. Sprite pipelines always live in a repo PortOS already manages, so the typed path was a transcription hazard with no upside, and the picker sets up the eventual sync-from-app flow. `AppContextPicker` gains an `emptyRepoText` prop — its hardcoded "using default PortOS context" empty state would be wrong here, since sprite import has no PortOS fallback; the default is unchanged for existing callers.
+- **Fix two cross-schema breaks in the sprite detail endpoint that were hiding imported walk data** — `GET /api/sprites/:id` 500'd for every imported character because `getWalkState()`'s run-sort called `.localeCompare()` on `createdAt`, which the ElsewhereAcres source pipeline stamps as a Python epoch-seconds number rather than PortOS's own ISO string; the comparator now normalizes both shapes to milliseconds. Separately, each run's `stripPreview` field is now normalized through the existing `toRecordRelativeAssetPath()` helper (`server/services/sprites/paths.js`, mirroring the same rebase-on-read convention `reference.js` already uses for anchor paths): the source pipeline names the field `stripPreview.path` and anchors it at its own repo root, so PortOS's `stripPreview.stripPath`-reading client 404'd on every animated walk-loop thumbnail even once the 500 was fixed. Neither fix rewrites the imported files on disk — normalization happens in memory at read time, so the importer's hash-verified provenance is untouched. New regression coverage in `walk.test.js`. Filed #2924 to cover the one remaining gap: `pioneer`'s `east` direction was approved from an imagegen-redraw pipeline the grok-video-only walk viewer doesn't model, so it shows "approved" but no animated thumbnail.
diff --git a/server/services/sprites/paths.js b/server/services/sprites/paths.js
index aaebfa55ac..5cac0834ab 100644
--- a/server/services/sprites/paths.js
+++ b/server/services/sprites/paths.js
@@ -31,6 +31,31 @@ export function spriteDir(recordId) {
export const RUNTIME_POINTER_REL = 'runtime/current.json';
export const RUNTIME_PUBLICATIONS_REL = 'runtime/publications.json';
+/**
+ * Normalize an asset-path field read out of an imported manifest to the
+ * record-relative form `spriteAssetUrl`/`resolveSpriteAssetPath` expect. The
+ * source pipeline embeds paths anchored at ITS repo root
+ * (`art-source/sprites/<recordId>/...`) inside every manifest, and the
+ * importer copies those manifests byte-for-byte — their hashes are pinned
+ * and verified against the source, so importer.js never rewrites the copied
+ * JSON content. Readers that treat an embedded path as record-relative (the
+ * convention every PortOS-generated manifest already follows) must strip
+ * that source-repo prefix at read time instead. Returns null for a path
+ * that isn't inside this record (repo-anchored provenance, e.g. a pipeline
+ * script path) or for missing/empty/traversal-shaped input. A path with no
+ * repo-anchor segment is assumed already record-relative and passed through
+ * unchanged — this is what makes the helper a no-op for PortOS's own runs.
+ */
+export function toRecordRelativeAssetPath(recordId, rawPath) {
+ if (typeof rawPath !== 'string' || !rawPath) return null;
+ const marker = `art-source/sprites/${recordId}/`;
+ const idx = rawPath.indexOf(marker);
+ const rel = idx >= 0 ? rawPath.slice(idx + marker.length) : rawPath;
+ if (idx < 0 && /^(art-pipeline|art-source|game)\//.test(rel)) return null;
+ if (!rel || rel.split(/[\\/]/).some((seg) => seg === '..' || seg === '')) return null;
+ return rel;
+}
+
/**
* Resolve a relative asset path inside a record's directory, refusing any
* path that escapes it (`..`, absolute paths).
diff --git a/server/services/sprites/walk.js b/server/services/sprites/walk.js
index 5c7d76543c..e9782bf070 100644
--- a/server/services/sprites/walk.js
+++ b/server/services/sprites/walk.js
@@ -29,7 +29,7 @@ import { enqueueJob } from '../mediaJobQueue/index.js';
import { IMAGE_GEN_MODE } from '../imageGen/modes.js';
import { getSettings } from '../settings.js';
import { updateRecord } from './records.js';
-import { spriteDir, resolveSpriteAssetPath } from './paths.js';
+import { spriteDir, resolveSpriteAssetPath, toRecordRelativeAssetPath } from './paths.js';
import { requireCharacter, loadManifest } from './reference.js';
import { SPRITE_DIRECTIONS, anchorIdForDirection, buildWalkVideoPrompt } from './prompts.js';
import {
@@ -86,6 +86,30 @@ async function requireUnfinalized(recordId) {
}
}
+// PortOS stamps createdAt as an ISO string (Date.parse handles it); imported
+// source-pipeline run records (issue #2895 importer) stamp it as a Python
+// time.time() epoch-seconds float instead — .localeCompare on that throws
+// and 500s the whole detail endpoint. Normalize both to comparable ms.
+function runCreatedAtMs(createdAt) {
+ if (typeof createdAt === 'number') return createdAt * 1000;
+ const ms = Date.parse(createdAt);
+ return Number.isNaN(ms) ? 0 : ms;
+}
+
+// PortOS's own postprocess stamps `stripPreview.stripPath` record-relative
+// (walkPostprocess.js). The imported source pipeline stamps the same field
+// as `stripPreview.path`, anchored at ITS repo root — the importer copies
+// manifests byte-for-byte (hashes are pinned and verified against the
+// source, so importer.js never rewrites them), so the mismatch is fixed up
+// here, in memory, at read time instead. Never written back to disk.
+function normalizeStripPreview(recordId, run) {
+ if (!run?.stripPreview) return run;
+ const raw = run.stripPreview.stripPath ?? run.stripPreview.path;
+ const stripPath = toRecordRelativeAssetPath(recordId, raw);
+ if (!stripPath) return run;
+ return { ...run, stripPreview: { ...run.stripPreview, stripPath } };
+}
+
/**
* Walk-workflow view for the detail endpoint: every animation run (newest
* first), the per-direction selection, and the finalized set when present.
@@ -105,7 +129,8 @@ export async function getWalkState(recordId) {
.map((e) => loadRunRecord(recordId, e.name)),
).then((loaded) => loaded
.filter(Boolean)
- .sort((a, b) => (b.createdAt || '').localeCompare(a.createdAt || ''))),
+ .map((run) => normalizeStripPreview(recordId, run))
+ .sort((a, b) => runCreatedAtMs(b.createdAt) - runCreatedAtMs(a.createdAt))),
loadSelection(recordId),
loadWalkSet(recordId),
]);
diff --git a/server/services/sprites/walk.test.js b/server/services/sprites/walk.test.js
index 8a2b247560..a5f9600957 100644
--- a/server/services/sprites/walk.test.js
+++ b/server/services/sprites/walk.test.js
@@ -373,4 +373,47 @@ describe('getWalkState', () => {
expect(runs).toHaveLength(2);
expect(runs[0].id).toBe(second.runId);
});
+
+ // Imported run records (issue #2895 importer, ElsewhereAcres source
+ // pipeline) stamp createdAt as a Python time.time() epoch-seconds float
+ // and stripPreview as { path: <source-repo-relative> } instead of
+ // PortOS's own { stripPath: <record-relative> } — sorting the former
+ // with .localeCompare threw and 500'd the whole detail endpoint, and
+ // rendering the latter through spriteAssetUrl() 404'd. Both must be
+ // tolerated without mutating the file on disk (its hash is pinned and
+ // verified against the source manifest at import time).
+ it('sorts an imported numeric-createdAt run behind a native run and normalizes its stripPreview', async () => {
+ const id = await characterWithLockedAnchors(newId(), ['east']);
+ const legacyRunId = 'walk-east-legacy01';
+ const legacyStripRel = `grok/${legacyRunId}/generated/${id}-walk-east-strip.png`;
+ const legacyDir = join(TEST_ROOT, 'sprites', id, 'grok', legacyRunId, 'generated');
+ await mkdir(legacyDir, { recursive: true });
+ await writeFile(join(legacyDir, `${id}-walk-east-strip.png`), 'legacy-strip');
+ const legacyPath = join(TEST_ROOT, 'sprites', id, 'grok', legacyRunId, 'animation-run.json');
+ await writeFile(legacyPath, JSON.stringify({
+ schemaVersion: 1,
+ kind: 'grok-game-animation-frames-run',
+ status: 'candidate',
+ id: legacyRunId,
+ characterId: id,
+ direction: 'east',
+ createdAt: 1700000000.123456, // source pipeline epoch-seconds float, well in the past
+ stripPreview: {
+ path: `art-source/sprites/${id}/${legacyStripRel}`,
+ frameCount: 8, fps: 12, cellWidth: 384, cellHeight: 384, row: 0, startColumn: 0,
+ },
+ }));
+ const legacyBytesBefore = await readFile(legacyPath);
+
+ const { runId: nativeRunId } = await startWalkGeneration(id, { direction: 'east' });
+ const { runs } = await getWalkState(id);
+
+ expect(runs).toHaveLength(2);
+ expect(runs[0].id).toBe(nativeRunId); // native ISO createdAt sorts first
+ const legacy = runs.find((r) => r.id === legacyRunId);
+ expect(legacy.stripPreview.stripPath).toBe(legacyStripRel);
+ // Normalization happens in memory only — the imported file (and its
+ // hash-pinned provenance) is never rewritten on disk.
+ expect(await readFile(legacyPath)).toEqual(legacyBytesBefore);
+ });
});