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
address review (codex r6): importer respects locks, sidecarless-candidate guards, live retry provenance
[._.]/ Adam Eivy6702646bbaa4
diff --git a/server/services/sprites/importer.js b/server/services/sprites/importer.jsindex e418d22954..b69769a310 100644--- a/server/services/sprites/importer.js+++ b/server/services/sprites/importer.js@@ -232,6 +232,16 @@ async function importCharacter({ sourceRoot, characterId, spec, specPath, selectconst result = { id: characterId, kind: 'character', files: 0, verified: 0, errors: [] };const srcCharDir = join(sourceRoot, 'art-source', 'sprites', characterId);const destDir = spriteDir(characterId);++ // A destination with a LOCKED reference set (#2896) is immutable evidence+ // — a same-id import would copy the source's reference tree straight over+ // the frozen identity root, bypassing every lock check. Refuse the whole+ // character; the user can delete the record or import under another id.+ const destManifest = await readJSONFile(join(destDir, 'reference', `${characterId}-reference-set-v1.json`), null);+ if (destManifest?.mainReference?.locked) {+ result.errors.push('destination has a locked reference set — refusing to overwrite immutable artifacts (delete the record or import under a different id)');+ return result;+ }await ensureDir(destDir);// Character spec — verbatim copy for provenance alongside the record.diff --git a/server/services/sprites/importer.test.js b/server/services/sprites/importer.test.jsindex 836300d447..d2b231a8e7 100644--- a/server/services/sprites/importer.test.js+++ b/server/services/sprites/importer.test.js@@ -9,7 +9,7 @@*/import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest';-import { mkdtempSync, mkdirSync, rmSync, writeFileSync, existsSync } from 'fs';+import { mkdtempSync, mkdirSync, rmSync, writeFileSync, existsSync, readFileSync } from 'fs';import { createHash } from 'crypto';import { tmpdir } from 'os';import { join } from 'path';@@ -264,6 +264,21 @@ describe('importFromSource', () => {expect(existsSync(join(SPRITES_ROOT, 'hero/reference/hero-anchor-south.png'))).toBe(true);});+ it('refuses to overwrite a destination whose reference set is locked (#2896 immutability)', async () => {+ writeTree(SPRITES_ROOT, {+ 'hero/reference/hero-reference-set-v1.json': {+ schemaVersion: 1, mainReference: { path: 'reference/hero-walk-south-v1.png', locked: true },+ },+ });+ const { results } = await importFromSource({ sourceRoot: SOURCE_ROOT, characters: ['hero'], includeProps: false });+ const hero = results.find((r) => r.id === 'hero');+ expect(hero.errors.some((e) => e.includes('locked reference set'))).toBe(true);+ expect(hero.files).toBe(0);+ // The locked manifest survives untouched.+ const manifest = JSON.parse(readFileSync(join(SPRITES_ROOT, 'hero/reference/hero-reference-set-v1.json'), 'utf8'));+ expect(manifest.mainReference.locked).toBe(true);+ });+it('rejects a root that is not a sprite pipeline', async () => {const empty = mkdtempSync(join(tmpdir(), 'sprite-importer-empty-'));await expect(importFromSource({ sourceRoot: empty })).rejects.toMatchObject({ code: 'INVALID_SOURCE_ROOT' });diff --git a/server/services/sprites/reference.js b/server/services/sprites/reference.jsindex 0985032ca5..a0c76c14ab 100644--- a/server/services/sprites/reference.js+++ b/server/services/sprites/reference.js@@ -186,9 +186,12 @@ export async function getReferenceSet(recordId) {extensions: ['.png'],mapEntry: async (name) => {const sidecar = await readJSONFile(join(candidatesDir, `${name.replace(/\.png$/, '')}.generation.json`), null);+ // Sidecarless (crash between copy and sidecar write): infer the target+ // from the filename so the client can't group it under the wrong slot.+ const inferred = /^walk-(.+)-candidate-\d+\.png$/.exec(name)?.[1] || null;return {path: `reference/candidates/${name}`,- target: sidecar?.target || null,+ target: sidecar?.target || (inferred === 'south' ? 'main' : inferred),anchorId: sidecar?.anchorId || null,chromaKey: sidecar?.chromaKey || null,mode: sidecar?.mode || null,@@ -273,6 +276,10 @@ async function startReferenceGenerationImpl(recordId, body, upload = null) {throw new ServerError('Locked main reference file is missing on disk', { status: 500, code: 'MAIN_REFERENCE_MISSING' });}initImageStrength ??= ANCHOR_DEFAULT_STRENGTH;+ // Known limitation shared with every i2i surface (proof-as-base, refine):+ // the WINDOWS local runner (imagine_win.py) has no i2i and drops the+ // init image — anchors there degrade to text-to-image, like all other+ // pipeline i2i renders on that platform. Cloud modes are unaffected.}const { cleanC2PA, denoise } = resolveImageCleaners(undefined, settings, mode);@@ -333,7 +340,10 @@ export async function attachReferenceCandidate(ctx) {direction: ctx.direction,chromaKey: ctx.chromaKey || null,mode: ctx.mode || null,- model: ctx.model || null,+ // Prefer the completed job's live params — Render Queue's Edit & Retry+ // rewrites top-level params but carries the original tag through, so the+ // tag's model can be stale provenance.+ model: ctx.job?.params?.model || ctx.job?.params?.modelId || ctx.model || null,jobId: ctx.jobId || null,...(ctx.designPrompt ? { designPrompt: ctx.designPrompt } : {}),generatedAt: new Date().toISOString(),@@ -373,10 +383,17 @@ async function lockReferenceImpl(recordId, { target, candidate, acceptClipRisk =const refDir = join(spriteDir(recordId), 'reference');const sidecar = await loadCandidateSidecar(candAbs);// A candidate generated for one facing must not land in another slot — a- // misclick would freeze the wrong pose as immutable evidence.+ // misclick would freeze the wrong pose as immutable evidence. The filename+ // prefix is checked as well as the sidecar: a crash between the PNG copy+ // and the sidecar write leaves a sidecarless candidate whose target would+ // otherwise be unverifiable.if (sidecar?.target && sidecar.target !== target) {throw new ServerError(`Candidate was generated for target "${sidecar.target}", not "${target}"`, { status: 400, code: 'CANDIDATE_TARGET_MISMATCH' });}+ const expectedPrefix = `${anchorIdForDirection(target === 'main' ? 'south' : target)}-candidate-`;+ if (!candidate.slice('reference/candidates/'.length).startsWith(expectedPrefix)) {+ throw new ServerError(`Candidate filename does not match target "${target}" (expected ${expectedPrefix}*)`, { status: 400, code: 'CANDIDATE_TARGET_MISMATCH' });+ }// Mask on the key the candidate was GENERATED against (its actual// background), which may differ from the key selected at lock time.const maskKey = sidecar?.chromaKey || record.chromaKey || DEFAULT_CHROMA_KEY;diff --git a/server/services/sprites/reference.test.js b/server/services/sprites/reference.test.jsindex 14e01be632..fb0dc931b9 100644--- a/server/services/sprites/reference.test.js+++ b/server/services/sprites/reference.test.js@@ -208,6 +208,7 @@ describe('attachReferenceCandidate', () => {kind: 'sprite-reference-generation', characterId: id, target: 'main',anchorId: 'walk-south', chromaKey: '#FF00FF', jobId: 'j1', designPrompt: 'a ranger',});+ expect(sidecar.model).toBe('m'); // tag model when the job carries noneexpect(sidecar.candidateSha256).toMatch(/^[0-9a-f]{64}$/);const { candidates } = await getReferenceSet(id);@@ -215,6 +216,22 @@ describe('attachReferenceCandidate', () => {expect(candidates[0].target).toBe('main');});+ it('prefers the completed job\'s live model over the tag (Edit & Retry provenance)', async () => {+ const id = newId();+ await createCharacter(id);+ await mkdir(join(TEST_ROOT, 'images'), { recursive: true });+ await writeCandidatePng(join(TEST_ROOT, 'images', 'render-2.png'));+ await attachReferenceCandidate({+ recordId: id, target: 'main', direction: 'south', anchorId: 'walk-south',+ chromaKey: '#FF00FF', mode: 'codex', model: 'stale-tag-model', jobId: 'j2',+ filename: 'render-2.png', job: { params: { model: 'retried-model' } },+ });+ const sidecar = JSON.parse(await readFile(+ join(TEST_ROOT, 'sprites', id, 'reference', 'candidates', 'walk-south-candidate-01.generation.json'), 'utf8',+ ));+ expect(sidecar.model).toBe('retried-model');+ });+it('returns null when the gallery file is gone', async () => {const id = newId();await createCharacter(id);@@ -358,6 +375,21 @@ describe('lockReference', () => {.rejects.toMatchObject({ code: 'CANDIDATE_TARGET_MISMATCH' });});+ it('refuses a sidecarless candidate whose filename does not match the target', async () => {+ const id = newId();+ await createCharacter(id);+ // Crash between PNG copy and sidecar write: PNG exists, no provenance.+ const candDir = join(TEST_ROOT, 'sprites', id, 'reference', 'candidates');+ await mkdir(candDir, { recursive: true });+ await writeCandidatePng(join(candDir, 'walk-east-candidate-01.png'));+ await expect(lockReference(id, { target: 'main', candidate: 'reference/candidates/walk-east-candidate-01.png' }))+ .rejects.toMatchObject({ code: 'CANDIDATE_TARGET_MISMATCH' });+ // And the reference-set view infers its target from the filename so the+ // client can't group it under main.+ const { candidates } = await getReferenceSet(id);+ expect(candidates[0].target).toBe('east');+ });+it('refuses candidates outside reference/candidates/ and traversal paths', async () => {const id = newId();await createCharacter(id);