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(sharing): fall back to image metadata sidecar when media-job archive aged out

[._.]/ Adam Eivyfe737263d3e9
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 667c71f5ff..532e13d19e 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -15,6 +15,8 @@
- **Pipeline arc resolve — preserve child issues when the LLM rewrites the seasons array.** Auto-resolve (`POST /api/pipeline/series/:id/arc/resolve`) replaces `series.seasons[]` with whatever the LLM returns. The prompt instructs the LLM to "preserve volume `id` for every existing volume you keep", but when it ignored that and minted fresh UUIDs (or returned seasons without ids), every child issue still pointed at the now-defunct seasonId and vanished from the Arc canvas — the UI groups issues by `seasonId` and never iterated the orphan buckets. `resolveVerifyIssues()` now tags each merged season with its provenance, derives the set of dropped old seasons, and builds an old→new remap (normalized title → unique `number` → positional fallback when counts line up). Affected child issues are migrated to the matched new seasonId (or `null` = ungrouped, which is visible) in the same write, mirroring `deleteSeason`'s bulk-reassign idiom: `updateIssue(…, { skipRenumber: true })` per call + one `recomputeIssueNumbersForSeries` after, wrapped in `withReexportSuppressed('series', seriesId, …)` so a 96-issue series doesn't fan out N socket emits + N debounced re-exports. As a backstop, `ArcCanvas.jsx` now buckets any issue whose `seasonId` isn't in the current `seasons[]` under the existing "Unassigned issues" group instead of a key nothing renders — so non-resolve-path orphans (stale data, future bugs) stay visible too.
+- **Sharing exporter — fall back to per-image metadata sidecar when the media-job archive has aged out.** The `mediaJobQueue` archive trims completed jobs after 24h, so subscription re-exports of any universe with older images were spamming `⚠️ sharing.exporter: imageJobId <id> not found in live queue or archive` for every aged-out job, and the recipient's bundle lost the per-job metadata record (prompt, model, dimensions) used for full-fidelity re-renders. `exportMediaJobAndAsset` now falls back to reading `data/images/<jobId>.metadata.json` (written at gen time by both the codex and local image-gen paths, lifetime tied to the asset file) and synthesizes a job record from it when the in-memory queue/archive miss. The warning now only fires when both lookups miss — meaning the image file or its sidecar is actually gone — and the message text now includes `or sidecar` to reflect the new lookup path.
+
- **Universe Builder — coalesce per-image share re-exports during a batch render.** When a subscribed universe was rendering a large batch (e.g. 160 prompts), every completed image fired a per-item `emitRecordUpdated('universe', …)` → debounced re-export, walking every historical `imageJobId` in the linked collection and warning for any that aged out of the 24h in-memory media-job archive. The render route now registers each run's job count with `universeBuilderCollectionHook`, which wraps every per-item `addItem` in `withReexportSuppressed` while the run is active and emits a single `emitRecordUpdated` once the last terminal event (completed / failed / canceled) lands. A 160-image batch now schedules one debounced re-export at the end instead of ~one per completion, and the "imageJobId not found in live queue or archive" warnings collapse to a single sweep. Server restart mid-run drops the in-memory tracker entry — the hook falls back to the legacy per-image emits for the rest of that run.
- **Media annotations now sync across PortOS instances via shared Drive buckets, with per-author attribution.** Previously, a note or star added on one machine was invisible to peers sharing the same Drive bucket — `data/media-annotations.json` lived purely client-local. Storage is now per-author: each instance owns its own `instanceId` sub-entry under each `<kind>:<ref>` key (`{ authors: { [instanceId]: { authorName, starred, note, updatedAt } } }`), so my notes never clobber yours and vice versa. A new manifest kind (`media-annotations`) carries each instance's annotation snapshot into every auto-merge bucket via a stable filename (`annotations-<instanceId>.json`), debounced 2s after the last local edit. The export is per-bucket scoped to assets actually present in that bucket, so a private annotation can't leak into an unrelated share. On import, peer records merge per-author by `updatedAt` LWW and re-broadcast `media:annotation:updated` so open clients refresh without a reload. Stars are also per-author — "my favorites" remains my view, not a tug-of-war. The lightbox now shows my note in the editable textarea and "Notes from others" as labeled read-only blocks below (with the peer's display name + their star). Migration `012-attribute-existing-annotations.js` rewraps existing notes under the local instance's id on first run.
diff --git a/server/services/sharing/exporter.js b/server/services/sharing/exporter.js
index da178fe5de..e286e2c7c7 100644
--- a/server/services/sharing/exporter.js
+++ b/server/services/sharing/exporter.js
@@ -86,17 +86,44 @@ async function copyAssetIfPresent(filename, kind, bucketPath) {
return { kind, ref: base };
}
+/**
+ * Build a synthetic job record from a `.metadata.json` sidecar when the
+ * in-memory queue/archive no longer holds the job (>24h TTL). The sidecar
+ * lives alongside the image file so its lifetime is tied to the asset.
+ */
+async function jobFromSidecar(jobId) {
+ const sc = await readJSONFile(join(PATHS.images, `${jobId}.metadata.json`));
+ if (!sc) return null;
+ return {
+ id: sc.id || jobId,
+ kind: 'image',
+ owner: null,
+ status: 'completed',
+ completedAt: sc.createdAt || null,
+ params: {
+ prompt: sc.prompt,
+ negativePrompt: sc.negativePrompt,
+ width: sc.width,
+ height: sc.height,
+ mode: sc.mode,
+ model: sc.model,
+ },
+ result: { filename: sc.filename },
+ };
+}
+
/**
* For each `imageJobId`, fetch the live media-job (or look it up in the persisted
* archive) and write a sanitized copy into the bucket records/media/ so the
- * recipient can re-render with identical prompt/seed/params. Returns the asset
- * refs (image filenames) discovered.
+ * recipient can re-render with identical prompt/seed/params. Falls back to the
+ * per-image `.metadata.json` sidecar for jobs older than the 24h archive TTL.
+ * Returns the asset refs (image filenames) discovered.
*/
async function exportMediaJobAndAsset(jobId, bucketPath, mediaRecordsDir) {
if (!jobId || !isStr(jobId)) return [];
- const job = getJob(jobId);
+ const job = getJob(jobId) || await jobFromSidecar(jobId);
if (!job) {
- console.log(`⚠️ sharing.exporter: imageJobId ${jobId} not found in live queue or archive`);
+ console.log(`⚠️ sharing.exporter: imageJobId ${jobId} not found in live queue, archive, or sidecar`);
return [];
}
// Trim transient/runtime fields — keep enough to re-render with full fidelity.