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

reject manuscript-fix edits that echo the prompt's JSON example placeholders

[._.]/ Adam Eivy861fde0e5ab5
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index f14da34c29..44875f302c 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -29,6 +29,8 @@
- **A watched TUI run no longer false-times-out after finishing its work** — companion fix to *Live TUI runs are now viewable AND drivable in the Shell page* (above). One-shot AI runs that drive a terminal UI (Claude Code, Codex, etc.) write their completed answer to a response file and then return to an interactive prompt **without exiting**. The runner only auto-completed such a run via output-idle — which is paused while you watch it in the Shell page (so it isn't snapped shut mid-read). With the process never exiting and idle paused, a watched run had no terminus but the 10-minute hard timeout — at which point it was marked **failed**, its already-written result was **discarded**, and a useless fallback retry ran in its place. The runner now watches for the response file as the model's authoritative "done" signal and completes the run the moment it's written — even while you're watching — since once the file exists the task is genuinely finished. A second safety net salvages the file on hard timeout: if the result was written but completion stalled for any other reason, the run finishes as **success** with that result instead of throwing it away and falling back. So a long editorial pass you keep open in the Shell tab now lands its findings when the model finishes, instead of silently dying at 10 minutes. (`server/lib/tuiPromptRunner.js`)
+- **Manuscript "Generate fix" no longer surfaces the prompt's own example as the edit** — a fix run could come back with the JSON example's placeholder text as the suggestion (BEFORE: *"a verbatim excerpt copied EXACTLY from that issue's manuscript above — the span you are replacing"*, AFTER: *"that same span rewritten to close the gap"*) when a model echoed the output-contract example instead of filling it in. That bogus edit could never be located in the manuscript, so Accept would have failed with "Anchor text is no longer present." Two changes close it: the fix's JSON example now uses obviously-schematic `<…>` field descriptions plus an explicit "do not copy the bracketed values" rule (so the model is far less likely to echo it), and `normalizeFix` now drops any edit whose `find`/`replace` still matches the example placeholder text (old prose-style *or* new bracketed) — so an echo collapses to the existing "did not return a usable fix — try again" retry instead of presenting an unappliable diff. The prompt change ships as migration 084 (existing installs auto-upgrade their copy; customized prompts are left intact and warned). (`server/services/pipeline/manuscriptFix.js`, `data.reference/prompts/stages/pipeline-manuscript-fix.md`, `scripts/migrations/084-manuscript-fix-example-placeholders.js`)
+
- **Catalog user-type sync now converges instead of re-applying every cycle** — federated catalog *user-defined types* used an at-or-newer (`>=`) last-write-wins comparison, so a peer re-sending a type you already held at the same timestamp was re-adopted, re-written, and re-counted as a change on every sync cycle. The logs showed a constant non-zero count (e.g. `Synced with <peer>: 3 catalog changes`) once a minute forever, and the slice was rewritten needlessly each pass. The merge now uses strict-newer (`>`), matching the SQL LWW guard every other catalog kind already uses (`EXCLUDED.updated_at > …updated_at`): an equal-clock echo is a skip, so the merge is idempotent and the cycle settles to zero changes. (`server/services/catalogSync.js`)
- **[issue-1080] Notes synced from other machines become searchable promptly** — a Brain note, daily-log entry, person, project, or idea created or edited on one of your machines is now re-indexed into semantic memory on the others as soon as it syncs, instead of waiting for a full manual re-sync. Edits and deletes that arrive from a peer also refresh or retire the matching memory entry, so search no longer surfaces stale copies of records that changed elsewhere. A new **Refresh embeddings** button on the Brain graph re-indexes everything in one pass to heal anything that drifted before this fix.
diff --git a/data.reference/prompts/stages/pipeline-manuscript-fix.md b/data.reference/prompts/stages/pipeline-manuscript-fix.md
index 64d26d4992..8519589f98 100644
--- a/data.reference/prompts/stages/pipeline-manuscript-fix.md
+++ b/data.reference/prompts/stages/pipeline-manuscript-fix.md
@@ -82,14 +82,16 @@ Return ONLY valid JSON matching this shape — no prose, no markdown fence, no c
"edits": [
{
"issueNumber": 1,
- "find": "a verbatim excerpt copied EXACTLY from that issue's manuscript above — the span you are replacing",
- "replace": "that same span rewritten to close the gap",
- "note": "optional short note explaining this edit"
+ "find": "<paste the verbatim manuscript span you are replacing>",
+ "replace": "<that same span, rewritten to close the gap>",
+ "note": "<optional short note explaining this edit>"
}
]
}
```
+The `<…>` values above are field DESCRIPTIONS, not content. Do **not** copy them into your answer — every `find` must be real text lifted character-for-character from the manuscript above, and every `replace` must be your actual rewrite. Returning the bracketed placeholder text (or its wording) is a failed response.
+
- `edits` may contain one edit or several edits. Use several only when the finding genuinely requires more than one insertion/revision.
- `issueNumber` MUST identify the issue section containing that edit's `find`.
- `find` MUST be copied **character-for-character** from the matching issue's manuscript text above (including punctuation, line breaks, and formatting markers). The system locates your edit by an exact substring match on `find`, so any paraphrase will fail. Keep it as **small as possible** while still being uniquely locatable — a sentence, page/panel block, or short paragraph, not a whole page. **Exception (full-page replacement):** when "How to read the suggested fix" above says this is a full-page replacement, `find` IS the entire malformed page block the anchor points at — the whole page is what you are replacing.
diff --git a/scripts/migrations/060-manuscript-multi-edit-fix-prompt.js b/scripts/migrations/060-manuscript-multi-edit-fix-prompt.js
index fa9b71a673..235ba5adf9 100644
--- a/scripts/migrations/060-manuscript-multi-edit-fix-prompt.js
+++ b/scripts/migrations/060-manuscript-multi-edit-fix-prompt.js
@@ -11,20 +11,21 @@
import { makePromptReplaceMigration } from './_lib.js';
-// Pre-change shipped hash (single-edit fix prompt), plus this migration's own
-// multi-edit output ('c88a56…') as accepted-old — migration 066
-// (replacementStrategy) further updated this file, so a copy still at the 060
-// body is auto-upgradable to the current shape.
+// Pre-change shipped hash (single-edit fix prompt), plus the intermediate
+// shipped bodies as accepted-old — 060's own multi-edit output ('c88a56…') and
+// 066's replacementStrategy output ('88199bf…'). Later migrations further
+// updated this file, so a copy still at any of these bodies is auto-upgradable
+// to the current shape.
export const ACCEPTED_OLD_MD5 = {
- 'pipeline-manuscript-fix.md': ['196625952f4a36f3cb962c729f60f0ee', 'c88a56304eb5e290ae0de9dadd20b310'],
+ 'pipeline-manuscript-fix.md': ['196625952f4a36f3cb962c729f60f0ee', 'c88a56304eb5e290ae0de9dadd20b310', '88199bf7b5b50155bd2e1624bd920ebd'],
};
-// Current shipped hash — migration 066 further updated this file (added the
-// replacementStrategy reading instructions), so this hash reflects the post-066
-// body. The idempotent-rerun and drift-catch tests require it to match the live
+// Current shipped hash — migration 084 (schematic example placeholders) is the
+// latest to touch this file, so this hash reflects the post-084 body. The
+// idempotent-rerun and drift-catch tests require it to match the live
// data.reference body, not 060's own output.
export const NEW_SHIPPED_MD5 = {
- 'pipeline-manuscript-fix.md': '88199bf7b5b50155bd2e1624bd920ebd',
+ 'pipeline-manuscript-fix.md': 'e2baaf0f2f53c8aa1e934a428c0ca583',
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/066-manuscript-finding-replacement-strategy-prompts.js b/scripts/migrations/066-manuscript-finding-replacement-strategy-prompts.js
index 8840f29bdb..95103a03f8 100644
--- a/scripts/migrations/066-manuscript-finding-replacement-strategy-prompts.js
+++ b/scripts/migrations/066-manuscript-finding-replacement-strategy-prompts.js
@@ -32,17 +32,21 @@ export const ACCEPTED_OLD_MD5 = {
// accepted-old because migration 083 (with-edits replace field) is the current
// shape, so a copy still at the post-066 body is auto-upgradable.
'pipeline-manuscript-completeness.md': ['1ee5ac936fbf1d365e0eaea99bcf1e77', 'cec8faeb75dfff74e41b8221145c2e92'],
- 'pipeline-manuscript-fix.md': ['c88a56304eb5e290ae0de9dadd20b310'],
+ // 'c88a56…' is 060's multi-edit output; '88199bf…' is this migration's own
+ // (post-066) fix body, kept as accepted-old because migration 084 (schematic
+ // example placeholders) is the current shape, so a copy still at the post-066
+ // body is auto-upgradable.
+ 'pipeline-manuscript-fix.md': ['c88a56304eb5e290ae0de9dadd20b310', '88199bf7b5b50155bd2e1624bd920ebd'],
};
// Post-change shipped hashes. Mirror these into every earlier migration that
// tracks the same file (056/057 for completeness, 060 for fix) so their
// drift-catch tests stay green. The completeness hash reflects the post-083 body
-// (migration 083 added the with-edits `replace` field); the fix hash is still
-// 066's own output (no later migration touches it).
+// (migration 083 added the with-edits `replace` field); the fix hash reflects
+// the post-084 body (migration 084 made the JSON example schematic).
export const NEW_SHIPPED_MD5 = {
'pipeline-manuscript-completeness.md': 'fd26f928c33803c12878a1bfb8561ece',
- 'pipeline-manuscript-fix.md': '88199bf7b5b50155bd2e1624bd920ebd',
+ 'pipeline-manuscript-fix.md': 'e2baaf0f2f53c8aa1e934a428c0ca583',
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/084-manuscript-fix-example-placeholders.js b/scripts/migrations/084-manuscript-fix-example-placeholders.js
new file mode 100644
index 0000000000..e6f63faab2
--- /dev/null
+++ b/scripts/migrations/084-manuscript-fix-example-placeholders.js
@@ -0,0 +1,62 @@
+/**
+ * Make the manuscript-fix prompt's JSON example obviously schematic so weaker
+ * models stop echoing it back as their answer.
+ *
+ * Symptom: a "Generate fix" run returned the example's VALUES verbatim —
+ * `find: "a verbatim excerpt copied EXACTLY from that issue's manuscript above
+ * — the span you are replacing"`, `replace: "that same span rewritten to close
+ * the gap"` — instead of a real manuscript span + rewrite. The old example read
+ * like filled-in content, so the model copied it.
+ *
+ * This migration replaces those prose-style placeholder values with bracketed
+ * `<…>` field descriptions and adds an explicit "the bracketed values are
+ * descriptions, do not copy them" rule. A runtime guard in
+ * server/services/pipeline/manuscriptFix.js (normalizeFix → isEchoedPlaceholder)
+ * also drops an edit whose find/replace still matches either the old or new
+ * placeholder text, so an echo collapses to the existing "did not return a
+ * usable fix — try again" retry instead of surfacing an un-appliable fuzzy edit.
+ *
+ * `scripts/setup-data.js` only copies *missing* prompts, so existing installs
+ * keep their old template until this migration rewrites it. Customization-safe:
+ * only installs whose copy still hashes to a known prior shipped version are
+ * auto-updated; customized prompts are left intact and warned about.
+ *
+ * Strategy: hash-driven prompt-replace via `./_lib.js`. Idempotent.
+ */
+
+import { makePromptReplaceMigration } from './_lib.js';
+
+// Pre-change shipped hash: the post-066 (replacementStrategy) fix body.
+export const ACCEPTED_OLD_MD5 = {
+ 'pipeline-manuscript-fix.md': ['88199bf7b5b50155bd2e1624bd920ebd'],
+};
+
+// Post-change shipped hash (bracketed example + don't-echo rule). Mirror this
+// into every earlier migration that tracks the same file (060/066) so their
+// drift-catch tests stay green.
+export const NEW_SHIPPED_MD5 = {
+ 'pipeline-manuscript-fix.md': 'e2baaf0f2f53c8aa1e934a428c0ca583',
+};
+
+const { applyMigration, up } = makePromptReplaceMigration({
+ accepted: ACCEPTED_OLD_MD5,
+ current: NEW_SHIPPED_MD5,
+ label: 'manuscript-fix example placeholders',
+ customizedHint: (filename) =>
+ ` To harden the example manually, diff:\n` +
+ ` data.reference/prompts/stages/${filename}\n` +
+ ` against your current:\n` +
+ ` data/prompts/stages/${filename}\n` +
+ ` and replace the JSON example's prose placeholder values with bracketed\n` +
+ ` <…> field descriptions plus a "do not copy the bracketed values" rule.`,
+ skipFooter: (count) =>
+ `⚠️ ${count} manuscript-fix prompt(s) could not be auto-updated because\n` +
+ ` they were customized. Fixes still work, but a weaker model may echo the\n` +
+ ` JSON example back as its answer until you harden the example (the\n` +
+ ` runtime guard still drops such echoes — they surface as "did not return\n` +
+ ` a usable fix — try again").\n` +
+ ` See data.reference/prompts/stages/pipeline-manuscript-fix.md.`,
+});
+
+export { applyMigration };
+export default { up };
diff --git a/scripts/migrations/084-manuscript-fix-example-placeholders.test.js b/scripts/migrations/084-manuscript-fix-example-placeholders.test.js
new file mode 100644
index 0000000000..458580a3dc
--- /dev/null
+++ b/scripts/migrations/084-manuscript-fix-example-placeholders.test.js
@@ -0,0 +1,14 @@
+import { describe } from 'vitest';
+
+import { runPromptMigrationTests } from './_testHelpers.js';
+import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './084-manuscript-fix-example-placeholders.js';
+
+describe('migration 084 — manuscript-fix example placeholders', () => {
+ runPromptMigrationTests({
+ migration,
+ applyMigration,
+ ACCEPTED_OLD_MD5,
+ NEW_SHIPPED_MD5,
+ prefix: 'migration-084-',
+ });
+});
diff --git a/scripts/setup-data-drift.test.js b/scripts/setup-data-drift.test.js
index 4c905205c5..982102b2a0 100644
--- a/scripts/setup-data-drift.test.js
+++ b/scripts/setup-data-drift.test.js
@@ -39,7 +39,7 @@ const EXPECTED_STAGE_OLD = {
'story-builder-idea-expand.md': ['778c86e2caa120856c36e4d5a4da3355', 'a23939626a226f7420cebfb45d47950c'],
'pipeline-editorial-analysis.md': ['14d9879697c66d51830cc798040d5369'],
'pipeline-manuscript-completeness.md': ['4f2b95778aed85f5fc461d71eb461b79', 'e6858c74ab2cead752d388e3f428406c', '1ee5ac936fbf1d365e0eaea99bcf1e77', 'cec8faeb75dfff74e41b8221145c2e92'],
- 'pipeline-manuscript-fix.md': ['196625952f4a36f3cb962c729f60f0ee', 'c88a56304eb5e290ae0de9dadd20b310'],
+ 'pipeline-manuscript-fix.md': ['196625952f4a36f3cb962c729f60f0ee', 'c88a56304eb5e290ae0de9dadd20b310', '88199bf7b5b50155bd2e1624bd920ebd'],
'cos-agent-briefing.md': ['181b26838e526427173e4dccfc884d01', '3e1ca7f7b14b799f89a193c568003624', '699d053875472df455258724a0162bd5', '9bcd3a0167dd4aed7cfff7f404494dfb', 'af73fd50d6f29d561772474c12346e53', 'd761133753da290a0c02eca1c87709e4'],
'pipeline-tv-script.md': ['3f6fecc25573ed054b47db392250034a'],
};
@@ -60,7 +60,7 @@ const EXPECTED_STAGE_NEW = {
'story-builder-idea-expand.md': 'c12d76fefaaded2838023065bfc94bb0',
'pipeline-editorial-analysis.md': 'daeb02bd54b0c099b21af659c6298cfe',
'pipeline-manuscript-completeness.md': 'fd26f928c33803c12878a1bfb8561ece',
- 'pipeline-manuscript-fix.md': '88199bf7b5b50155bd2e1624bd920ebd',
+ 'pipeline-manuscript-fix.md': 'e2baaf0f2f53c8aa1e934a428c0ca583',
'pipeline-tv-script.md': '376f779f4687b598f1c92ca4e770fd5a',
};
const EXPECTED_PARTIAL_OLD = {
diff --git a/server/services/pipeline/manuscriptFix.js b/server/services/pipeline/manuscriptFix.js
index 6cf2984b5a..72e4a92eab 100644
--- a/server/services/pipeline/manuscriptFix.js
+++ b/server/services/pipeline/manuscriptFix.js
@@ -74,6 +74,31 @@ function normalizeModelEdits(content) {
return [];
}
+// The placeholder strings used as VALUES in the prompt's JSON example
+// (pipeline-manuscript-fix.md, "Output contract"). Weaker models sometimes echo
+// the example back verbatim instead of filling it in. Those strings are never a
+// real manuscript span, so they'd surface as an un-appliable `fuzzy` edit whose
+// Accept throws "Anchor text is no longer present". Detect and drop them here so
+// the fix collapses to null → the caller's "did not return a usable fix" retry.
+//
+// Only the `find`/`replace` example values are listed (the only fields the guard
+// checks) — not the `note` placeholder. Both the current bracketed wording AND
+// the prior prose-style wording are included: an install whose prompt copy hasn't
+// migrated to the bracketed shape yet still echoes the old text, so the guard must
+// catch both. Keep these byte-identical to whichever example shipped in
+// pipeline-manuscript-fix.md (a drift test in manuscriptFix.test.js pins the
+// current ones to the live prompt so a future example edit can't silently rot it).
+export const PROMPT_EXAMPLE_PLACEHOLDERS = new Set([
+ // Current (bracketed) example.
+ '<paste the verbatim manuscript span you are replacing>',
+ '<that same span, rewritten to close the gap>',
+ // Prior prose-style example (pre-bracket installs).
+ "a verbatim excerpt copied EXACTLY from that issue's manuscript above — the span you are replacing",
+ 'that same span rewritten to close the gap',
+]);
+
+const isEchoedPlaceholder = (s) => typeof s === 'string' && PROMPT_EXAMPLE_PLACEHOLDERS.has(s.trim());
+
function resolveEditSection(raw, targets) {
const issueNumber = Number.isInteger(raw?.issueNumber) ? raw.issueNumber : null;
if (issueNumber != null) {
@@ -132,12 +157,15 @@ export function fixFromEdits(edits) {
return fix;
}
-function normalizeFix(content, targets) {
+export function normalizeFix(content, targets) {
const edits = normalizeModelEdits(content)
.map((raw) => {
const find = typeof raw?.find === 'string' ? raw.find : '';
const replace = typeof raw?.replace === 'string' ? raw.replace : '';
if (!find || !replace) return null;
+ // Drop an edit the model copied straight out of the prompt's JSON example
+ // instead of synthesizing — it would only ever be an un-appliable fuzzy edit.
+ if (isEchoedPlaceholder(find) || isEchoedPlaceholder(replace)) return null;
return shapeAnchoredEdit(resolveEditSection(raw, targets), { find, replace, note: raw.note });
})
.filter(Boolean);
diff --git a/server/services/pipeline/manuscriptFix.test.js b/server/services/pipeline/manuscriptFix.test.js
index c8c5559c9a..5a7f4b50cf 100644
--- a/server/services/pipeline/manuscriptFix.test.js
+++ b/server/services/pipeline/manuscriptFix.test.js
@@ -1,5 +1,8 @@
import { describe, it, expect } from 'vitest';
-import { locateFindSpan } from './manuscriptFix.js';
+import { readFileSync } from 'fs';
+import { join, dirname } from 'path';
+import { fileURLToPath } from 'url';
+import { locateFindSpan, normalizeFix, PROMPT_EXAMPLE_PLACEHOLDERS } from './manuscriptFix.js';
describe('locateFindSpan', () => {
it('locates an exact substring', () => {
@@ -49,3 +52,70 @@ describe('locateFindSpan', () => {
expect(locateFindSpan(text, '$5 (approx)')).toEqual({ start: 8, end: 8 + '$5 (approx)'.length });
});
});
+
+describe('normalizeFix — echoed-placeholder guard', () => {
+ // One target section whose content is real manuscript text.
+ const targets = [{ issueId: 'issue-1', stageId: 'pipeline-script', number: 1, title: '', content: 'PAGE 1\nPANEL 1\nJack climbs.' }];
+
+ const realEdit = { issueNumber: 1, find: 'Jack climbs.', replace: 'Jack climbs, breathless.' };
+
+ it('produces a usable fix for a real find/replace', () => {
+ const fix = normalizeFix({ edits: [realEdit] }, targets);
+ expect(fix).not.toBeNull();
+ expect(fix.find).toBe('Jack climbs.');
+ expect(fix.replace).toBe('Jack climbs, breathless.');
+ expect(fix.fuzzy).toBeUndefined();
+ });
+
+ it('drops an edit that echoes the current bracketed placeholders → null fix', () => {
+ const fix = normalizeFix({
+ edits: [{
+ issueNumber: 1,
+ find: '<paste the verbatim manuscript span you are replacing>',
+ replace: '<that same span, rewritten to close the gap>',
+ note: '<optional short note explaining this edit>',
+ }],
+ }, targets);
+ expect(fix).toBeNull();
+ });
+
+ it('drops an edit that echoes the prior prose-style placeholders (un-migrated install)', () => {
+ const fix = normalizeFix({
+ edits: [{
+ issueNumber: 1,
+ find: "a verbatim excerpt copied EXACTLY from that issue's manuscript above — the span you are replacing",
+ replace: 'that same span rewritten to close the gap',
+ }],
+ }, targets);
+ expect(fix).toBeNull();
+ });
+
+ it('keeps the real edits when a response mixes a real edit with an echoed one', () => {
+ const fix = normalizeFix({
+ edits: [
+ { issueNumber: 1, find: '<that same span, rewritten to close the gap>', replace: '<that same span, rewritten to close the gap>' },
+ realEdit,
+ ],
+ }, targets);
+ expect(fix).not.toBeNull();
+ expect(fix.edits).toHaveLength(1);
+ expect(fix.edits[0].find).toBe('Jack climbs.');
+ });
+
+ it('pins the bracketed placeholders to the live prompt example (drift catch)', () => {
+ // The guard hardcodes the prompt's example values; if the prompt example's
+ // find/replace wording changes without updating PROMPT_EXAMPLE_PLACEHOLDERS,
+ // a fresh echo would slip through. Assert the current bracketed strings still
+ // appear verbatim in the shipped prompt so that coupling can't silently rot.
+ const promptPath = join(
+ dirname(fileURLToPath(import.meta.url)),
+ '../../../data.reference/prompts/stages/pipeline-manuscript-fix.md',
+ );
+ const prompt = readFileSync(promptPath, 'utf-8');
+ const bracketed = [...PROMPT_EXAMPLE_PLACEHOLDERS].filter((s) => s.startsWith('<'));
+ expect(bracketed.length).toBeGreaterThan(0);
+ for (const placeholder of bracketed) {
+ expect(prompt).toContain(placeholder);
+ }
+ });
+});