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

match arc-resolve findings by meaning so a re-worded regression still gets reverted

[._.]/ Adam Eivyed7b47518699
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 43b5b3be1f..87f1995dfe 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -205,6 +205,8 @@
- **A foundation repair no longer sends the entire episode list, and no longer takes the whole autopilot run down with it when it fails.** The foundation-quality gate's repair prompt carried the full synopsis-level plan — every volume *and* every episode synopsis — with no size limit, so it grew with the series forever. On a long-running series that section reached 28KB of a 35KB prompt, and the primary AI provider burned its entire ten-minute timeout on it without producing a single word; the fallback provider then repeated the same request and burned ten more. Twenty minutes spent, nothing written, and the whole autonomous run ended in an error that discarded every step it had already completed. The repair prompt is now bounded the same way the judge prompt beside it always was: the plan spine (arc, volumes, authored character arcs) is always sent in full, and the episode list fills the remaining budget by whole lines, oldest first, saying how many were left out — so the model reads a coherent outline instead of one cut mid-sentence. And a repair whose AI call fails outright now **pauses** the run rather than erroring it: the failure is a provider timeout or a dead CLI, not a verdict on your story, so the run keeps every step it finished, tells you which provider failed, and resumes from where it stopped. Autopilot also stopped quietly losing the reason it paused — "nothing to fix", "budget reached" and this new "provider failed" were all being emitted and then dropped before they reached the screen, leaving a bare "Paused" with no explanation; each now carries its own badge.
+- **An arc auto-resolve round that makes the story worse now gets reverted even when the verifier re-words itself.** Autopilot already refuses to keep a repair round that hands back more blocking findings than it was given while leaving its assignment standing — but it decided "still standing" by comparing the verifier's prose to the previous round's, near-verbatim. Verification is an AI pass: it re-phrases the same defect every time it files it, and re-labels where the defect lives when a round renumbers volumes. So the guard read each restatement as a brand-new finding, concluded the round had done its job, and kept the damage — which is how a run could still go from one blocking finding to three to five and then pause on a plan the repair pass had degraded. Two findings are now matched on what they are *about* (the place they name, or the substance they restate) rather than on wording, so a paraphrased repeat is recognized, the round's edits are put back, and the run pauses on the findings you actually had — one verify and one repair round earlier, before either is billed.
+
## Internal
- **[issue-3713] Confirmed that deleting an iCloud-offloaded note is safe, and pinned the decision not to guard it.** [issue-3706] proved that *overwriting* an offloaded file stalls in the kernel exactly like reading one, which left `obsidian.deleteNote`'s `unlink` as the last unguarded write-shaped call on the vault adapter. The POSIX argument ("unlink only drops a directory entry, so there is nothing to download") was not safe to lean on — `link` is pure metadata too and it *does* materialize, and [issue-3706]'s whole lesson was that the intuitive answer about `O_TRUNC` was wrong. Measured instead, on freshly-evicted iCloud fixtures with each syscall timed in a killable child process: `unlink` returned in 0.1 ms across three runs (two at 512 KB, one at 5 MB), against 884 ms to `read` a separate, equally-sized 5 MB dataless file. So no guard — and not merely because it is unnecessary: the [issue-3706] remedy is to download the file and wait, which here would mean fetching every byte of a note purely to throw it away. A test now pins the *absence* of the screen so a later "add it for symmetry" change has to argue with it. The syscall table in `server/lib/icloudFile.js` gained the `unlink` row.
diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.js
index 9f36fbdba9..cf6ec39c3b 100644
--- a/server/services/pipeline/seriesAutopilot.test.js
+++ b/server/services/pipeline/seriesAutopilot.test.js
@@ -1395,7 +1395,7 @@ describe('trackConvergence (pure divergence/oscillation guard — #1571)', () =>
});
describe('isResolveRegression (pure resolve-round damage check)', () => {
- const { isResolveRegression, findingFingerprint } = autopilot;
+ const { isResolveRegression, sameFinding, findingTextOverlap } = autopilot;
const f = (problem, location = 'V1', severity = 'high') => ({ severity, location, problem });
it('flags a round that grew the blocking set while leaving what it targeted standing', () => {
@@ -1428,14 +1428,42 @@ describe('isResolveRegression (pure resolve-round damage check)', () => {
expect(isResolveRegression(null, [f('a')])).toBe(false);
});
- it('fingerprints through the verifier re-wording its prose', () => {
- // Same finding, re-punctuated and re-cased between two verify calls — a raw
- // string match would read the second as brand new and miss the regression.
- expect(findingFingerprint({ severity: 'high', location: 'V1', problem: 'Both volumes stage the first eclipse.' }))
- .toBe(findingFingerprint({ severity: 'HIGH', location: 'v1', problem: 'both volumes stage the first eclipse' }));
- // Different location is a different finding.
- expect(findingFingerprint({ severity: 'high', location: 'V1', problem: 'x' }))
- .not.toBe(findingFingerprint({ severity: 'high', location: 'V2', problem: 'x' }));
+ it('still flags the regression when the verifier PARAPHRASES the finding it left standing', () => {
+ // The failure mode that let the observed 1 → 3 → 5 divergence through: the
+ // second verify call restates the same defect in its own words and at a
+ // re-labelled location. A prose fingerprint reads that as a brand-new
+ // finding, concludes the round closed what it targeted, and commits the
+ // damage. Identity has to survive the re-wording.
+ expect(isResolveRegression(
+ [f('volume 1 and volume 2 both stage the first eclipse', 'Volume 1 → Volume 2')],
+ [
+ f('the eclipse is presented as a first-time event in two separate volumes', 'Volume 2 opening'),
+ f('mentor subplot never pays off', 'V3'),
+ f('finale hook is unresolved', 'V4'),
+ ],
+ )).toBe(true);
+ });
+
+ it('matches a re-punctuated, re-cased, re-pluralized restatement', () => {
+ expect(sameFinding(
+ { severity: 'high', location: 'V1', problem: 'Both volumes stage the first eclipse.' },
+ { severity: 'medium', location: 'v1', problem: 'both volume stages the first eclipse' },
+ )).toBe(true);
+ });
+
+ it('does not fuse two findings that merely share the structural vocabulary', () => {
+ // "volume"/"episode"/"arc" appear in nearly every finding — they must not be
+ // what makes two of them look like one, or the guard reverts good rounds.
+ expect(findingTextOverlap('volume 3 drops the mentor subplot', 'volume 3 has no ticking clock'))
+ .toBeLessThan(0.4);
+ expect(sameFinding(f('the mentor subplot is dropped', 'V3'), f('the finale hook is unresolved', 'V4')))
+ .toBe(false);
+ // A location label can't swallow a longer one that starts the same way —
+ // containment matches whole words, not prefixes.
+ expect(sameFinding(f('x', 'V1'), f('y', 'V10'))).toBe(false);
+ expect(sameFinding(f('x', 'volume 3'), f('y', 'volume 30'))).toBe(false);
+ // The same place at two altitudes IS one location.
+ expect(sameFinding(f('x', 'volume 3'), f('y', 'volume 3 — act two'))).toBe(true);
});
});
@@ -1914,6 +1942,55 @@ describe('autopilot conductor', () => {
expect(series.autopilot?.residualFindings).toHaveLength(1);
});
+ it('reverts the same 1 → 3 → 5 divergence when each verify call re-words the finding', async () => {
+ // Same incident as the test above, but replayed the way the verifier
+ // actually behaves: round 2 restates the standing defect in fresh prose at a
+ // re-labelled location, and round 3 does it again. Matching those on an
+ // exact prose fingerprint read them as brand-new findings, so the guard
+ // concluded the round had closed what it targeted, committed the damage, and
+ // let the loop run on to a 5-finding divergence pause (the observed
+ // `verify:round` 1/3/5 with two non-empty `resolve:round` frames between
+ // them). It has to be reverted at round 2 here too.
+ const restatements = [
+ { severity: 'high', problem: 'volume 1 and volume 2 both stage the first eclipse', location: 'V1' },
+ { severity: 'high', problem: 'the first eclipse is staged twice — once in each of the opening volumes', location: 'Volume 1 → Volume 2' },
+ { severity: 'medium', problem: 'two separate volumes each present the eclipse as its first occurrence', location: 'Volume 2 opening' },
+ ];
+ const extra = (i) => ({ severity: 'high', problem: `collateral break ${i}`, location: `V${i + 3}` });
+ const round = (n, idx) => ({
+ issues: [restatements[idx], ...Array.from({ length: n - 1 }, (_, i) => extra(i))],
+ });
+ // beforeEach's clearAllMocks does NOT drain a queued `mockImplementationOnce`,
+ // and the test above deliberately leaves its third round unconsumed — reset
+ // (which restores the vi.fn default) so this run starts on round 1.
+ arcSpies.verifyArc.mockReset();
+ arcSpies.verifyArc
+ .mockImplementationOnce(async () => round(1, 0))
+ .mockImplementationOnce(async () => round(3, 1))
+ .mockImplementationOnce(async () => round(5, 2));
+ // The round reports real work (the observed `resolve:round episodesEdited=1`)
+ // — it edited episodes and STILL came back worse, which is the whole point.
+ arcSpies.resolveVerifyIssues.mockImplementationOnce(async () => ({
+ applied: true,
+ episodesResolved: [{ issueId: 'i1', number: 1 }],
+ }));
+ const { seriesId } = await seedComplete();
+ await autopilot.startSeriesAutopilot(seriesId, { maxArcVerifyRounds: 6 });
+ await waitFor(runFinished(seriesId));
+
+ // Round 3 (the 5-finding verify) and its resolve are never billed.
+ expect(arcSpies.verifyArc).toHaveBeenCalledTimes(2);
+ expect(arcSpies.resolveVerifyIssues).toHaveBeenCalledTimes(1);
+ expect(arcSpies.restoreArcState).toHaveBeenCalledWith(
+ seriesId,
+ await arcSpies.snapshotArcState.mock.results[0].value,
+ );
+ const last = autopilot.__testing.runs.get(seriesId)?.lastPayload;
+ expect(last?.pauseKind).toBe('regression');
+ // Paused on the ONE finding the user actually had, not the 3 it manufactured.
+ expect(last?.residualFindings).toEqual([restatements[0]]);
+ });
+
it('keeps a round that closed what it targeted, even when new findings surface', async () => {
// Guard against the over-strict rollback: this round DID clear the finding
// it was handed, and the two that follow were latent underneath. Reverting
diff --git a/server/services/pipeline/seriesAutopilot/convergence.js b/server/services/pipeline/seriesAutopilot/convergence.js
index 54a6b94334..9248e21af1 100644
--- a/server/services/pipeline/seriesAutopilot/convergence.js
+++ b/server/services/pipeline/seriesAutopilot/convergence.js
@@ -72,7 +72,7 @@ export function divergencePauseReason(gate, blockingCount, rounds) {
// damage it caused itself.
// ---------------------------------------------------------------------------
-// Normalizer behind `findingFingerprint`, hoisted so the regexes aren't rebuilt
+// Normalizer behind the finding matcher, hoisted so the regexes aren't rebuilt
// per finding per round.
const normFindingText = (v) => String(v ?? '')
.toLowerCase()
@@ -80,16 +80,90 @@ const normFindingText = (v) => String(v ?? '')
.replace(/\s+/g, ' ')
.trim();
-// Deliberately COARSE identity for a verify finding: the verifier re-words its
-// prose between calls, so a raw-string match would read every round's findings
-// as brand new. Severity + location carry the stable identity; a short prefix of
-// the normalized problem separates two findings filed at the same location.
-// Coarse is the safe direction here — collapsing two similar findings into one
-// print only makes the regression check MORE forgiving (it is a "did anything I
-// targeted survive?" set test, not a diff).
-export function findingFingerprint(finding) {
- return `${normFindingText(finding?.severity)}|${normFindingText(finding?.location)}`
- + `|${normFindingText(finding?.problem).slice(0, 60)}`;
+// Singularize one token so "volumes"/"volume" and "stages"/"stage" don't read
+// as two different words — the single most common way the verifier re-words
+// itself between calls.
+const stemToken = (tok) => (tok.endsWith('s') ? tok.slice(0, -1) : tok);
+
+// Words that carry no identity for a verify finding: ordinary connective tissue
+// plus the structural nouns ("volume", "episode", "arc", …) that appear in
+// nearly every finding this gate sees. Dropped before scoring so the overlap
+// below reflects what a finding is ABOUT, not the vocabulary the whole corpus
+// shares — two unrelated findings that both say "volume" must not read as one.
+// Stemmed through `stemToken` on the way in (so entries stay naturally spelled
+// here and still match the stemmed tokens they have to filter), which also
+// covers each one's plural.
+const FINDING_STOPWORDS = new Set((
+ 'a an and are as at be been both but by can could did do does each ever every for from had has have in'
+ + ' into is it more most never no not of on one only or other same should some still than that the'
+ + ' their then there these this those to two was were when which while with would'
+ + ' arc book chapter episode issue season series story volume'
+).split(' ').map(stemToken));
+
+// Content tokens of one finding field. Tokens shorter than 3 chars are noise
+// (numbers, "v1", articles the normalizer already split off).
+function contentTokens(value) {
+ const out = new Set();
+ for (const raw of normFindingText(value).split(' ')) {
+ const tok = stemToken(raw);
+ if (tok.length < 3 || FINDING_STOPWORDS.has(tok)) continue;
+ out.add(tok);
+ }
+ return out;
+}
+
+/**
+ * Containment overlap of two findings' prose: shared content tokens over the
+ * SMALLER token set, so a terse restatement of a long finding still scores high
+ * (Jaccard would punish it for the length difference). 0 when either side has
+ * no content tokens. Pure.
+ */
+export function findingTextOverlap(a, b) {
+ const left = contentTokens(a);
+ const right = contentTokens(b);
+ if (left.size === 0 || right.size === 0) return 0;
+ let shared = 0;
+ for (const tok of left) if (right.has(tok)) shared += 1;
+ return shared / Math.min(left.size, right.size);
+}
+
+// How much of the smaller finding's prose must be shared before two findings
+// from different verify calls are treated as the same one.
+export const FINDING_MATCH_MIN_OVERLAP = 0.4;
+
+/**
+ * True when two findings — filed by two SEPARATE verifier calls — are the same
+ * underlying problem. Pure.
+ *
+ * Identity is deliberately COARSE, because the verifier re-words itself freely
+ * between calls: it re-punctuates, re-cases, paraphrases the problem, and
+ * re-labels the location when a resolve round renumbers volumes. An exact
+ * fingerprint of that prose reads every round's findings as brand new, which is
+ * how the regression guard below silently missed the 1 → 3 → 5 divergence it
+ * was written for. Two findings match when they name the same place OR restate
+ * the same problem.
+ *
+ * Coarse is the safe direction: collapsing two similar findings into one only
+ * makes the guard MORE willing to call a growing round damage, and a rollback
+ * costs the user a reverted LLM round, not their draft (the pre-resolve state
+ * is what gets restored).
+ *
+ * Severity is NOT part of the identity — every finding here is already in the
+ * gate's blocking set, and the verifier moves a finding between `high` and
+ * `medium` freely, which would otherwise hide it from the guard.
+ */
+export function sameFinding(a, b) {
+ const locA = normFindingText(a?.location);
+ const locB = normFindingText(b?.location);
+ if (locA && locB) {
+ if (locA === locB) return true;
+ // Containment covers "volume 3" vs "volume 3 act two" (the same place at two
+ // altitudes). Matched on WHOLE WORDS — space-padded on both sides — so "v1"
+ // can't swallow "v10" and "volume 3" can't swallow "volume 30".
+ const [short, long] = locA.length <= locB.length ? [locA, locB] : [locB, locA];
+ if (` ${long} `.includes(` ${short} `)) return true;
+ }
+ return findingTextOverlap(a?.problem, b?.problem) >= FINDING_MATCH_MIN_OVERLAP;
}
/**
@@ -102,13 +176,17 @@ export function findingFingerprint(finding) {
* underneath is progress, even when the raw count went up, so it is allowed to
* stand (the divergence guard still catches it if the loop stalls from there).
* A round that closed nothing and added more is damage.
+ *
+ * A round that held the count is NOT this guard's business either — it bought
+ * nothing, but it also broke nothing, and the divergence guard's patience is
+ * what absorbs a verifier that re-files the same set with slightly different
+ * prose. Only a GROWING blocking set gets reverted here.
*/
export function isResolveRegression(before, after) {
const targeted = Array.isArray(before) ? before : [];
const current = Array.isArray(after) ? after : [];
if (current.length <= targeted.length) return false;
- const currentPrints = new Set(current.map(findingFingerprint));
- return targeted.some((f) => currentPrints.has(findingFingerprint(f)));
+ return targeted.some((t) => current.some((c) => sameFinding(t, c)));
}
// Pause reason for a gate whose auto-resolve round was reverted — distinct from