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 (agy): count unconverted scenes off the record, not the loop
[._.]/ Adam Eivy237b99fc17ff
diff --git a/server/services/fableLoom/weave.js b/server/services/fableLoom/weave.jsindex 4bf55f23ba..1c16363ac2 100644--- a/server/services/fableLoom/weave.js+++ b/server/services/fableLoom/weave.js@@ -371,15 +371,11 @@ export async function reformatLoom(loomId, { format, providerId, model, effort }const sceneCount = pending.reduce((total, e) => total + e.nodes.length, 0);let rewritten = 0;let chunks = 0;- let remaining = 0;for (const { episode, nodes } of pending) {for (let i = 0; i < nodes.length; i += REFORMAT_CHUNK) {const batch = nodes.slice(i, i + REFORMAT_CHUNK);- if (chunks >= REFORMAT_CHUNKS_MAX) {- remaining += batch.length;- continue;- }+ if (chunks >= REFORMAT_CHUNKS_MAX) continue;chunks += 1;const { content, runId } = await runStagedLLM('fableloom-reformat-scenes', {// The TARGET format, not the loom's current one: the pin is written@@ -423,10 +419,18 @@ export async function reformatLoom(loomId, { format, providerId, model, effort }// A loom with nothing to rewrite is a no-op, not a failure — the pin is still// the point. Only a loom that HAD scenes and got none back is a bad response.if (sceneCount && !rewritten) throw aiShapeError('The model returned no rewritten scenes');- // Only a fully-converted loom gets the pin; a run that stopped at the ceiling- // leaves it alone so the record never claims a format half its scenes lack.++ // Counted off the RECORD rather than accumulated in the loop, because scenes+ // go unconverted for two unrelated reasons: the per-request ceiling stopped+ // early, or the model simply didn't return them (it can drop 2 of a 5-scene+ // batch). Tracking only the first would report a partial rewrite as complete+ // and pin the loom to a format some of its scenes are not in.+ const after = await getLoom(loomId);+ const remaining = after.episodes.reduce((total, ep) => total+ + ep.nodes.filter((n) => isStr(n.prose) && n.prose.trim() && n.format !== target).length, 0);+ // Only a fully-converted loom gets the pin.const updated = remaining- ? await getLoom(loomId)+ ? after: await mutateLoom(loomId, (current) => ({ ...current, format: target }));return { loom: updated, format: target, rewritten, remaining, runIds };}diff --git a/server/services/fableLoom/weave.test.js b/server/services/fableLoom/weave.test.jsindex 677b03062d..31e0824fbd 100644--- a/server/services/fableLoom/weave.test.js+++ b/server/services/fableLoom/weave.test.js@@ -416,6 +416,26 @@ describe('reformatLoom', () => {expect(allNodes.every((n) => n.format === 'teleplay')).toBe(true);});+ it('reports scenes the model dropped as remaining, and holds the pin back', async () => {+ const { loomId, gateId, insideId } = await proseSetup();+ // The model returns one of the two scenes it was given. The run is under+ // the chunk ceiling, so nothing but the dropped scene is left over.+ runStagedLLM.mockResolvedValue({ content: { scenes: [{ id: gateId, prose: 'INT. GATE' }] } });++ const result = await reformatLoom(loomId, { format: 'teleplay' });+ expect(result).toMatchObject({ rewritten: 1, remaining: 1 });+ // Claiming teleplay here would point every later weave/branch/play at a+ // contract the untouched scene isn't written in.+ expect(result.loom.format).toBe('prose');+ expect(result.loom.episodes[0].nodes.find((n) => n.id === insideId).format).toBeNull();++ // Finishing the job pins it.+ runStagedLLM.mockResolvedValue({ content: { scenes: [{ id: insideId, prose: 'INT. INSIDE' }] } });+ const done = await reformatLoom(loomId, { format: 'teleplay' });+ expect(done).toMatchObject({ rewritten: 1, remaining: 0 });+ expect(done.loom.format).toBe('teleplay');+ });+it('asks the model for the TARGET format, not the one the loom still holds', async () => {const { loomId } = await proseSetup();runStagedLLM.mockImplementation(async (stage, variables) => ({