Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(dream): a two-word term in scare quotes is prose, not a quotation quote_verify quarantines (#7071)

garrytaneb69e4d1000b
diff --git a/docs/architecture/key-files/core-cycle-patterns.md b/docs/architecture/key-files/core-cycle-patterns.md
index a085e4d6a3..fbd0fc1008 100644
--- a/docs/architecture/key-files/core-cycle-patterns.md
+++ b/docs/architecture/key-files/core-cycle-patterns.md
@@ -9,7 +9,7 @@ Patterns, drift reports and the cycle modules listed after them.
- `src/core/cycle/phases/consolidate.ts` — the consolidate phase: clusters facts per page and promotes the best claim into a take. `cycle.consolidate.enabled` (default on; an explicit falsy value returns `skipped`, #6667) is read inside the phase; `dream --phase consolidate --once` bypasses it. Take identity for the upsert lookup is `(page_id, claim)` restricted to rows this phase authors (`kind='fact' AND holder='self'`) — `since_date` is NOT identity (it derives from MIN(valid_from) of the cluster and moves whenever extract_facts re-inserts, which degraded the lookup into duplicate INSERTs); deliberately NOT filtered on `active` (a superseded take still owns its claim — skipping it would resurrect a retired claim via the INSERT path); `ORDER BY id` keeps the pick deterministic across pre-existing duplicate rows. A resolved take is immutable — its id is reused for consolidation but the row is left untouched. Managed local consolidation passes the cycle source ID, publishes take, contributing facts and validity changes atomically: a fenced member on the entity page is closed in its `## Facts` fence row in the same page publication and its `valid_until` derives from that cell, an unfenced member is closed in the database, and a member fenced on another page stays open (test `test/consolidate-fenced-close-reimport.test.ts`). Retired/resolved matching takes produce a durable skipped receipt; semantic intent excludes vectors/timestamps/cache metadata, while a genuine newer fact/page snapshot changes request identity. Only live world-visible evidence is promoted; private facts remain private. #5575 ENG-3: fact tiers are read per bucket and external_untrusted facts cluster in a separate pass, so an external claim never shares a take with owner facts. Each cluster's take is written at `derive:consolidate` = min(cluster fact tiers, agent_written): unmanaged, the take insert or re-promotion, consolidation marks and valid_until writeback are one `derivedMaintenanceTransaction` (a re-promotion lowers the existing take to min(existing, cluster), even a resolved one); managed, the request carries `declareDerivation`. Edges: take -> every cluster fact. The unmanaged path runs the write gate (`decideTakeWrite`, config read once per run via `loadImportSanityConfig`) on each... (line truncated to 2000 chars)
-- `src/core/cycle/synthesize-verify.ts` — Mechanical claim verification on every page a synthesis child wrote (zero LLM). Exports the shared grounding primitive `normalizeForGrounding` (whitespace/curly-quote/dash/ellipsis/case folding, skipping markdown inline markup (`*`, backticks, `~~`; not `_`), WITH an offset map back to the original string, so every replacement is a verbatim transcript slice; a slice that differs from the quote only by that markup counts exact and is not spliced in) + `normForGrounding` (plain form, also used by `buildTriageMapBlock` and triage-rescue). A source built with `groundSource(path, content, { tolerant: true })` (think, concepts and patterns; never dream synthesis) also reads markdown link syntax and any other square bracket as plain text (`[Name](target)`, `[Name]` and `Name` match; repairs drop link targets and never carry a `"`), folds `"` to `'`, and counts a quote exact when its words match once the writer's edge punctuation and elision, brackets (including a bracketed letter's case, `[T]he`), editorial insertions in a word (`decide[s]`, `want[ed]`) and inner quote style are set aside. Think also grounds against the user's question. `groundSource(path, content)` prepares a transcript: offset map, speaker turns (`parseSpeakerTurns`: bold `**Name** (ts):` anchors and standalone `[user]` / `[assistant]` / `[system]` role lines (the session-corpus renderer's turn boundaries, so a `Name:` label inside one turn never carries into the next) always, plain `Label:` anchors when the label is a role word or opens two or more lines), canonical numbers and dates (`numericFacts`: `$250K` = `$250,000` = `250 thousand`, `2026-03-14` = `March 14th`; the file basename counts), and speaker-mention patterns. In strict mode (dream synthesis) a quote that misses whole is retried on its core (`quoteCore`: edge elision and closing punctuation set aside) at the exact and normalized rungs; an exact core keeps the writer's quote, a normalized core is replaced by the verbatim source slice. `groundQuote` runs the ladder exact → normalized → near (word-trigram anchors, window clipped to the anchor's speaker turn, ≥0.8 token overlap, ambiguity within 0.05 falls through, trimmed to the first/last shared token, refused above 1.3x the... (line truncated to 2000 chars)
+- `src/core/cycle/synthesize-verify.ts` — Mechanical claim verification on every page a synthesis child wrote (zero LLM). Exports the shared grounding primitive `normalizeForGrounding` (whitespace/curly-quote/dash/ellipsis/case folding, skipping markdown inline markup (`*`, backticks, `~~`; not `_`), WITH an offset map back to the original string, so every replacement is a verbatim transcript slice; a slice that differs from the quote only by that markup counts exact and is not spliced in) + `normForGrounding` (plain form, also used by `buildTriageMapBlock` and triage-rescue). A source built with `groundSource(path, content, { tolerant: true })` (think, concepts and patterns; never dream synthesis) also reads markdown link syntax and any other square bracket as plain text (`[Name](target)`, `[Name]` and `Name` match; repairs drop link targets and never carry a `"`), folds `"` to `'`, and counts a quote exact when its words match once the writer's edge punctuation and elision, brackets (including a bracketed letter's case, `[T]he`), editorial insertions in a word (`decide[s]`, `want[ed]`) and inner quote style are set aside. Think also grounds against the user's question. `groundSource(path, content)` prepares a transcript: offset map, speaker turns (`parseSpeakerTurns`: bold `**Name** (ts):` anchors and standalone `[user]` / `[assistant]` / `[system]` role lines (the session-corpus renderer's turn boundaries, so a `Name:` label inside one turn never carries into the next) always, plain `Label:` anchors when the label is a role word or opens two or more lines), canonical numbers and dates (`numericFacts`: `$250K` = `$250,000` = `250 thousand`, `2026-03-14` = `March 14th`; the file basename counts), and speaker-mention patterns. In strict mode (dream synthesis) a quote that misses whole is retried on its core (`quoteCore`: edge elision and closing punctuation set aside) at the exact and normalized rungs; an exact core keeps the writer's quote, a normalized core is replaced by the verbatim source slice. `groundQuote` runs the ladder exact → normalized → near (word-trigram anchors, window clipped to the anchor's speaker turn, ≥0.8 token overlap, ambiguity within 0.05 falls through, trimmed to the first/last shared token, refused above 1.3x the... (line truncated to 2000 chars) A quoted span of two words or fewer that grounds nowhere, with no punctuation inside, no quotation lead-in (a speech verb or a colon) and no speaker named in its unit, is the writer's term in scare quotes and is not verified as a quotation (#7071; `test/synthesize-verify-scare-quotes-7071.test.ts`).
- `src/core/cycle/triage-backoff.ts` — Backoff for unreliable dream-triage verdicts (#6069). `runTriagePass` calls `recordUnreliableTriage` for a truncated, refused or unparseable judge response: it upserts a `dream_verdicts` marker through `putDreamVerdict` (`score` NULL, `content_type` `triage_unreliable`, reasons `unreliable:<kind>` + `attempt:<n>`, the triage model and `TRIAGE_VERSION`) and writes one stderr line with the stop reason, response length and a 12-hex sha256 prefix, never the response text. A row that is a valid verdict for the current model is kept, and a cancelled run writes nothing. `backoffUntil` defers judging while the marker for the same model and version is younger than 24h × 2^(attempt−1), capped at 7 days; `force` (`dream retriage --force`), a model change or a content-hash change re-judges at once. Every score reader (`isTriageCacheValid`, retriage, triage-decide, the rescue gate) treats the NULL score as a miss; the 30-day TTL sweep removes old markers. `TRIAGE_BACKOFF_WHY` / `TRIAGE_BACKOFF_FIX` feed `details.triage.unreliable_backoff`. Pinned by `test/synthesize-triage-backoff.test.ts`. GBRA-130 B-6: `VerdictCacheWrites` isolates each verdict write (`synthesize.triage_verdict_cache`): a refused write is listed in `details.triage.verdict_cache_failures` and its verdict still decides the pass; a 22P02/22P05 refusal backs off as `uncacheable`. Both engines' `putDreamVerdict` apply `wellFormedJson`. Pinned by `test/pathological/b6-triage-verdict-surrogate.test.ts`.
- `src/core/cycle/attribution-checks.ts` — #5425 [UC4]: `dream.attribution_checks` (`ATTRIBUTION_CHECKS_KEY`, registered in `KNOWN_CONFIG_KEYS`; `config set` takes a boolean word through `CYCLE_GUARDED_KEYS` in `cycle/config-guards.ts`), the one default-off switch for the two mechanical attribution checks: the propose_takes holder downgrade (`propose-takes-attribution.ts`) and the synthesis `superseded_in_source` quarantine (`synthesize-verify.ts`). `attributionChecksEnabled(engine)` is `isConfigTruthy` over the stored value and false on any read error. The default flips only on a held-out gbrain-evals receipt, the same bar as the prompt rules `dream.synthesize.attribution_rules` / `dream.propose_takes.attribution_rules`.
diff --git a/src/core/cycle/synthesize-verify.ts b/src/core/cycle/synthesize-verify.ts
index 94d6b23376..f1039fb484 100644
--- a/src/core/cycle/synthesize-verify.ts
+++ b/src/core/cycle/synthesize-verify.ts
@@ -1137,8 +1137,9 @@ export function verifyBody(body: string, sources: GroundedSource[], opts: { prio
const unitProvenance: QuoteProvenance[] = [];
const grounded: Array<{ source: GroundedSource; start: number }> = [];
for (const sp of unitSpans) {
- quotes++;
const g = groundAcross(sp.inner, sources);
+ if (g.result.status === 'none' && g.result.reason === 'not_found' && mentioned.size === 0 && isScareQuote(body, sp)) continue;
+ quotes++;
if (g.result.status === 'none') {
fail(g.result.reason === 'crosses_speakers' ? 'quote_crosses_speakers' : 'quote_not_in_source', clip(sp.inner));
continue;
@@ -1201,6 +1202,20 @@ export function verifyBody(body: string, sources: GroundedSource[], opts: { prio
return { body: out, changed: out !== body, quotes, exact, normalized, near, unbalanced, quarantined, provenance, failures, groundingUnits };
}
+/** A quoted span of at most this many words can be the writer's own term in scare quotes (#7071); a three-word unattributed span is still a quotation to verify. */
+const MAX_SCARE_QUOTE_WORDS = 2;
+/** Text just before an opening mark that introduces a quotation: a speech verb or a colon. */
+const QUOTATION_LEAD_IN = /(?:\b(?:say|says|said|saying|tell|tells|told|ask|asks|asked|write|writes|wrote|reply|replies|replied|add|adds|added|call|calls|called|put it|quote|quotes|quoted)\b[^.!?\n]{0,16}|:)\s*$/i;
+
+/**
+ * #7071: a short quoted span that grounds nowhere, in a unit that names no speaker, with no punctuation inside and no
+ * quotation lead-in, is the writer's term in scare quotes (`not simply "work-life balance"`), not a quotation to verify.
+ */
+function isScareQuote(body: string, span: { start: number; inner: string }): boolean {
+ return span.inner.trim().split(/\s+/).length <= MAX_SCARE_QUOTE_WORDS && !/[.,;:!?]/.test(span.inner)
+ && !QUOTATION_LEAD_IN.test(body.slice(Math.max(0, span.start - 40), span.start));
+}
+
/** Units shorter than this many words (labels, headings, fragments) are not claims S8 judges. */
const MIN_GROUNDING_UNIT_WORDS = 5;
diff --git a/test/synthesize-verify-scare-quotes-7071.test.ts b/test/synthesize-verify-scare-quotes-7071.test.ts
new file mode 100644
index 0000000000..8940b69ea0
--- /dev/null
+++ b/test/synthesize-verify-scare-quotes-7071.test.ts
@@ -0,0 +1,56 @@
+/**
+ * #7071 — dream synthesis quote_verify: a short term the writer put in scare
+ * quotes (`not simply "work-life balance"`) is prose, not a quotation, so the
+ * unit around it is no longer quarantined as quote_not_in_source. A short
+ * quotation attributed to a speaker, or introduced as speech, is still verified.
+ */
+import { describe, expect, test } from 'bun:test';
+import { groundSource, verifyBody } from '../src/core/cycle/synthesize-verify.ts';
+
+const SOURCE = '**alice-example** (10:02): The deal desk is always open at the right price for us.\n\n**bob-example** (10:03): Fine, send terms. We keep the pace sustainable.\n';
+const strict = groundSource('conversations/2026-10-01-acme-example', SOURCE);
+const tolerant = groundSource('conversations/2026-10-01-acme-example', SOURCE, { tolerant: true });
+const reflection = (line: string) => `# Pacing\n\n## Reflection\n\n${line}\n`;
+
+describe('#7071 scare quotes', () => {
+ test('a short term in scare quotes is prose in strict and tolerant grounding', () => {
+ for (const line of [
+ 'The pattern here is not simply "work-life balance" but a deliberate pacing choice the team keeps making.',
+ 'What looks like “strategic patience” is mostly a refusal to discount the offer for acme-example.',
+ ]) {
+ for (const source of [strict, tolerant]) {
+ const v = verifyBody(reflection(line), [source]);
+ expect(v.quarantined).toEqual([]);
+ expect(v.body).toBe(reflection(line));
+ expect(v.quotes).toBe(0);
+ }
+ }
+ });
+
+ test('a short quotation attributed to a speaker is still verified and quarantined when absent', () => {
+ const v = verifyBody(reflection('alice-example described the desk as "strategic patience" in the meeting.'), [strict]);
+ expect(v.quarantined.map(q => q.reason)).toEqual(['quote_not_in_source']);
+ });
+
+ test('a three-word unattributed span is still verified', () => {
+ expect(verifyBody(reflection('You keep a "weekly launch diary" for the desk.'), [strict]).quarantined.map(q => q.reason)).toEqual(['quote_not_in_source']);
+ });
+
+ test('a short span introduced as speech is still verified', () => {
+ for (const line of ['The team said "shipping tomorrow" and moved on.', 'The takeaway was blunt: "never discounting" for now.']) {
+ expect(verifyBody(reflection(line), [strict]).quarantined.map(q => q.reason)).toEqual(['quote_not_in_source']);
+ }
+ });
+
+ test('a longer quotation and a short span with sentence punctuation are still verified', () => {
+ expect(verifyBody(reflection('The desk is "never closed to a good offer from anyone" in practice.'), [strict]).quarantined.map(q => q.reason)).toEqual(['quote_not_in_source']);
+ expect(verifyBody(reflection('The desk motto is "closed, then open" in practice.'), [strict]).quarantined.map(q => q.reason)).toEqual(['quote_not_in_source']);
+ });
+
+ test('a short span that does ground keeps its provenance', () => {
+ const v = verifyBody(reflection('The pace stays "pace sustainable" by design, per bob-example.'), [strict]);
+ expect(v.quarantined).toEqual([]);
+ expect(v.quotes).toBe(1);
+ expect(v.provenance.map(p => p.text)).toEqual(['pace sustainable']);
+ });
+});