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 (claude): fail-safe episode match + sibilant-gated -es stemming
[._.]/ Adam Eivya4f47a8b717e
diff --git a/server/lib/editorial/nameSimilarity.js b/server/lib/editorial/nameSimilarity.jsindex 6285ba4739..3ecfbd680c 100644--- a/server/lib/editorial/nameSimilarity.js+++ b/server/lib/editorial/nameSimilarity.js@@ -113,7 +113,12 @@ export const DEFAULT_SIGNAL_OPTS = Object.freeze({function singularStem(letters) {if (typeof letters !== 'string' || letters.length < 4) return letters;if (letters.endsWith('ies')) return `${letters.slice(0, -3)}y`; // cities → city- if (letters.endsWith('es') && letters.length > 4) return letters.slice(0, -2); // boxes → box+ // `-es` only forms a plural after a sibilant (s/x/z, ch/sh): boxes→box,+ // dishes→dish, churches→church. Gating on the sibilant (not just length)+ // stops a singular name that merely ends in "es" from being over-stemmed —+ // "James"→"jam", "Charles"→"charl" — which could then false-collapse onto an+ // unrelated short name and wrongly suppress a real confusability pair.+ if (letters.endsWith('es') && /(s|x|z|ch|sh)es$/.test(letters)) return letters.slice(0, -2);if (letters.endsWith('s') && !letters.endsWith('ss')) return letters.slice(0, -1); // poets → poetreturn letters;}diff --git a/server/lib/editorial/nameSimilarity.test.js b/server/lib/editorial/nameSimilarity.test.jsindex 7a35973a98..e36de0164b 100644--- a/server/lib/editorial/nameSimilarity.test.js+++ b/server/lib/editorial/nameSimilarity.test.js@@ -106,6 +106,12 @@ describe('nameSimilaritySignals', () => {expect(nameSimilaritySignals('a waiter', 'THE WAITERS')).toEqual([]);expect(nameSimilaritySignals('city', 'cities')).toEqual([]);expect(analyzeNamePair('readers', 'reader')).toEqual({ signals: [], distance: Infinity, phoneticMatch: false });+ // `-es` plurals collapse only after a sibilant (box/boxes, church/churches).+ expect(nameSimilaritySignals('box', 'boxes')).toEqual([]);+ expect(nameSimilaritySignals('church', 'churches')).toEqual([]);+ // A SINGULAR name ending in non-sibilant + "es" (James, Charles) must NOT be+ // over-stemmed to "jam"/"charl" and false-collapsed onto a short name.+ expect(nameSimilaritySignals('James', 'Jam')).not.toEqual([]);// But two DIFFERENT words that merely both end in "s" are not a plural pair —// genuine confusability signals still apply.expect(nameSimilaritySignals('Marcus', 'Atlas')).not.toContain('near-identical spelling (edit distance 1)');diff --git a/server/services/pipeline/arcPlanner.test.js b/server/services/pipeline/arcPlanner.test.jsindex c2e86860a3..0c900ae09f 100644--- a/server/services/pipeline/arcPlanner.test.js+++ b/server/services/pipeline/arcPlanner.test.js@@ -935,6 +935,43 @@ describe('arcPlanner — resolveVerifyIssues', () => {const updated = await issuesSvc.getIssue(issue.id);expect(updated.stages.idea.input).toBe('frozen synopsis'); // unchanged});++ it('fails safe (no-match) when a correction names a season the matched-number issue is NOT in', async () => {+ // Guard against a numbering-scheme mismatch: the arc tree numbers episodes+ // series-globally, but if the resolve LLM ever returns a per-season+ // episodeNumber, a season-agnostic fallback would silently rewrite the wrong+ // season's issue. With a resolvable seasonNumber we now REQUIRE the season to+ // match — a mismatch is dropped, not mis-applied to another season's issue.+ const s = await setupSeries();+ await seriesSvc.updateSeries(s.id, { arc: { logline: 'L' } });+ const s1 = await seasonsSvc.createSeason(s.id, { title: 'Vol 1', episodeCountTarget: 1 });+ const s2 = await seasonsSvc.createSeason(s.id, { title: 'Vol 2', episodeCountTarget: 1 });+ const issue = await issuesSvc.createIssue({ seriesId: s.id, seasonId: s1.id, title: 'Ep' });+ await issuesSvc.updateStage(issue.id, 'idea', { input: 'season 1 synopsis', status: 'empty' });+ const fresh = await issuesSvc.getIssue(issue.id);++ // Correction names season 2 but the only issue with this number is in season 1.+ stageRunnerSpy = vi.fn(async () => ({+ content: {+ arc: { logline: 'L2', summary: 'S', themes: [], protagonistArc: '' },+ seasons: [+ { id: s1.id, number: s1.number, title: 'Vol 1', logline: '', synopsis: '', endingHook: '', episodeCountTarget: 1 },+ { id: s2.id, number: s2.number, title: 'Vol 2', logline: '', synopsis: '', endingHook: '', episodeCountTarget: 1 },+ ],+ episodes: [{ seasonNumber: s2.number, episodeNumber: fresh.number, synopsis: 'WRONG-SEASON overwrite' }],+ notes: '',+ },+ runId: 'r', providerId: 'p', model: 'm',+ }));++ const out = await planner.resolveVerifyIssues(s.id, {+ findings: [{ severity: 'high', problem: 'contradiction', suggestion: 'fix' }],+ });++ expect(out.episodesResolved[0].skipped).toBe('no-match');+ const updated = await issuesSvc.getIssue(issue.id);+ expect(updated.stages.idea.input).toBe('season 1 synopsis'); // NOT overwritten+ });});describe('arcPlanner — shapeEpisodeResolutions', () => {diff --git a/server/services/pipeline/arcPlanner/arcCore.js b/server/services/pipeline/arcPlanner/arcCore.jsindex 68505fb020..5c0d03ea18 100644--- a/server/services/pipeline/arcPlanner/arcCore.js+++ b/server/services/pipeline/arcPlanner/arcCore.js@@ -475,10 +475,18 @@ export async function applyEpisodeResolutions(seriesId, series, episodes) {const applied = [];for (const edit of episodes) {const wantSeasonId = edit.seasonNumber != null ? seasonIdByNumber.get(edit.seasonNumber) : null;- // Prefer an issue that matches BOTH season and number; fall back to the- // series-global number alone (issue numbers are unique across the series).- const issue = issues.find((i) => i.number === edit.episodeNumber && (!wantSeasonId || i.seasonId === wantSeasonId))- || issues.find((i) => i.number === edit.episodeNumber);+ // Match an issue by series-global number. When the correction names a season+ // that resolved to a real season id, REQUIRE the issue to be in it — do NOT+ // fall back to a season-agnostic number match. The arc tree numbers episodes+ // series-globally, but if an LLM ever emits a per-season `episodeNumber`, a+ // bare-number fallback would silently rewrite the wrong season's issue (e.g.+ // global issue 5 when the model meant season 2 episode 5) and could clear its+ // beats. Failing safe to `no-match` (logged below) is the correct outcome for+ // a numbering-scheme mismatch. Only when no season is given (or it didn't+ // resolve) do we match on the globally-unique number alone.+ const issue = wantSeasonId+ ? issues.find((i) => i.number === edit.episodeNumber && i.seasonId === wantSeasonId)+ : issues.find((i) => i.number === edit.episodeNumber);if (!issue) {// A correction we can't land is a silent path to non-convergence — log it// so a number-scheme mismatch (per-season vs series-global) is diagnosable.