Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(chronicle): skip re-judging unchanged judge input and replace same-window generations (#8972)

garrytan49a59816e3b3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3256cc56a1..96d10d35c6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,22 @@ credits are retained; no result has been reassigned to another provider. Origina
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [Unreleased]
+
+**A long conversation that keeps growing is no longer re-extracted, and re-paid for, on every new message.** Automatic event extraction reads a page's title, date, attendees and the first 12,000 characters of its body. On a conversation longer than that, each new message recorded a new revision, and each revision paid for another extraction call on exactly the same text. The model words each event a little differently every time, event pages are named after that wording, and an extraction of a page longer than 12,000 characters never retired the previous one, so every run added a fresh copy of every event. One page could collect dozens of paid calls and hundreds of duplicate events. Now a revision that changes nothing extraction reads (text, title, date, attendees, privacy) makes no call and writes nothing (it records `judge_input_unchanged`); a window the judge keeps failing on is paid for at most the page's attempt limit across all revisions, then records `judge_input_failed` until the text changes or a backfill asks again; and a re-extraction that re-read all the text the page's live events came from (for example after a title change, or the first time a conversation grows past 12,000 characters) replaces those events instead of adding to them. A page whose opening text was edited still keeps its earlier events, as before. Text past the first 12,000 characters is still not extracted; incremental coverage of the tail is tracked in #9013. Reported by @andreineacsu.
+
+**Doctor counts the duplicates earlier releases left.** The new `chronicle_duplicate_events` check (info) reports how many pages hold live events from earlier extraction runs beside their newest run's, and how many such events. It changes nothing; a preview-first repair that retires them is tracked in #9012.
+
+### Itemized changes
+
+- `src/core/chronicle/execute.ts`: before the daily reservation, a row whose judge input digest equals that of the page's latest decided extracted generation (no ineligible revision or chronicle retirement since) finishes `skipped` / `judge_input_unchanged` with no call; an automatic row whose input already used the attempt limit on earlier revisions without publishing finishes `failed` / `judge_input_failed` (a refused input stays `judge_refused`), with no call; a truncated generation replaces the previous one only when every live chronicle event of the page is recorded by a ledger row whose judged window the new window starts with. Ended-invite projections and held results never count as judged.
+- `src/core/chronicle/extract-events.ts`: `chronicleJudgedInput` (digest of the judge input with the body cut to `JUDGE_BODY_CHARS`, the extractor version and the depth page's visibility and source incarnation; the window and its sha256).
+- Migration `v297` `chronicle_judge_window` (number restamped at the slot): `chronicle_page_state.judge_input_hash`, `judge_window_chars`, `judge_window_hash`; nullable, no backfill. A row recorded before it has no window, so that page's next revision is judged once more and stays additive.
+- `src/core/chronicle/reasons.ts`, `src/core/error-registry.ts`: reason codes `judge_input_unchanged` and `judge_input_failed`.
+- `src/core/chronicle/ledger-stats.ts`, `src/commands/doctor/checks/auto-chronicle.ts`: `readChronicleDuplicateEvents` and the `chronicle_duplicate_events` doctor check.
+- Docs: `docs/guides/life-chronicle.md`, `docs/guides/error-codes.md`.
+- Tests: `test/chronicle-long-conversation-8972.test.ts` with its Postgres arm `test/e2e/chronicle-long-conversation-8972-postgres.test.ts`; schema, migration and doctor goldens regenerated for the new columns and check.
+
## [0.60.623.0] - 2026-11-09
**The brain owner's own agents now read the whole personal brain, and pages stamped `access: private` by default can be cleared in reviewed batches.** On a single-user brain, writer templates stamped `access: private` on ordinary research and ops pages, and every remote caller got `not_found` for them, the owner's own agent included. `gbrain access owner set <member>` now names the owner (config `access.owner_member`, database state, so repo-less brains work the same). Every token, OAuth client or stdio server bound to that member reads `visibility: private` pages, privacy-alias pages, derived and pinned-question pages and private facts through `get_page`, `search`, `query`, `recall` and the other page reads, within its source grant. `readable_by` and folder rules still bind it, a shared-room audience gets no relaxation, and other members, unbound and public callers read exactly as before. `gbrain repair private-labels` previews the existing labels with counts per category, keeps real restrictions, and clears the over-stamped ones in reviewed, recorded, reversible batches. The bulk-ingestion page template no longer writes an `access:` line, and docs/guides/access-designations.md defines every designation.
diff --git a/docs/guides/error-codes.md b/docs/guides/error-codes.md
index 917a8556ba..852a9e90d7 100644
--- a/docs/guides/error-codes.md
+++ b/docs/guides/error-codes.md
@@ -666,7 +666,7 @@ More: [docs/guides/shared-checkout-git.md#checkout_not_a_source](../../docs/guid
|---|---|---|---|---|---|---|
| Automatic event extraction (auto_chronicle) skipped or failed this page; `reason` says why and `fix`, when present, is the next step. | A capability this request needs is not configured or not reachable on this brain. | Read the receipt or doctor `auto_chronicle` check: its `why` explains the reason and its `fix`, when present, is the next step (paid fixes need the user's agreement). | agent | `gbrain doctor --json` | 1 | no |
-Reasons: `auto_chronicle_off`, `auto_chronicle_invalid`, `slug_bound_client`, `operation_bound_client`, `no_extract`, `history`, `not_yet_happened`, `too_short`, `dream_generated`, `page_body_segmented`, `no_write_decision`, `not_chronicle_shaped`, `already_extracted`, `superseded`, `daily_limit`, `judge_llm_unavailable`, `no_pricing`, `budget_exhausted`, `campaign_exhausted`, `judge_chat_error`, `judge_truncated`, `judge_parse_failed`, `malformed_proposal`, `publish_error`, `judge_refused`, `page_missing`, `no_events`, `future_dated`, `date_imprecise`, `no_chat_provider`.
+Reasons: `auto_chronicle_off`, `auto_chronicle_invalid`, `slug_bound_client`, `operation_bound_client`, `no_extract`, `history`, `not_yet_happened`, `too_short`, `dream_generated`, `page_body_segmented`, `no_write_decision`, `not_chronicle_shaped`, `already_extracted`, `judge_input_unchanged`, `judge_input_failed`, `superseded`, `daily_limit`, `judge_llm_unavailable`, `no_pricing`, `budget_exhausted`, `campaign_exhausted`, `judge_chat_error`, `judge_truncated`, `judge_parse_failed`, `malformed_proposal`, `publish_error`, `judge_refused`, `page_missing`, `no_events`, `future_dated`, `date_imprecise`, `no_chat_provider`.
More: [docs/guides/life-chronicle.md#skip-and-failure-codes](../../docs/guides/life-chronicle.md#skip-and-failure-codes)
diff --git a/docs/guides/life-chronicle.md b/docs/guides/life-chronicle.md
index 7f555a951c..c4c60d754a 100644
--- a/docs/guides/life-chronicle.md
+++ b/docs/guides/life-chronicle.md
@@ -156,7 +156,10 @@ purged.
`gbrain doctor` reports the `auto_chronicle` check: whether it is on, 24 h use
of the daily limit and the largest writer's share, 7-day outcomes and spend
(priced dollars, unpriced calls and calls without a cost record are listed
-apart), pending pages and the command that runs them.
+apart), pending pages and the command that runs them. `chronicle_duplicate_events`
+(info) counts pages that still hold events from earlier extraction runs beside
+their newest run's, such as the reworded copies releases before #8972 added on
+long conversations; it changes nothing.
## After upgrading
@@ -258,6 +261,8 @@ brackets are filled in with real values on each surface.
| `no_write_decision` | discovery | This revision has no recorded write decision (written by an older binary or before this release activated), so only a trusted backfill extracts it. | `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50 --yes` (preview: `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50 --dry-run`) | agent | paid |
| `not_chronicle_shaped` | decision | The page is no longer a meeting, conversation or calendar page, so the events extracted from it were retired. | — | — | — |
| `already_extracted` | decision | This exact content was already extracted; its events are current, so no new call is made. | — | — | — |
+| `judge_input_unchanged` | execution | Nothing the extraction reads changed since the page was last extracted (for example only text past a long page's first 12,000 characters changed), so the earlier events are current and no new call is made. | — | — | — |
+| `judge_input_failed` | execution | Earlier revisions of the page already spent every extraction attempt on exactly this text without publishing events (the calls failed, or a newer revision arrived first), so it is not paid for again until the text extraction reads changes. | `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50 --yes` (preview: `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50 --dry-run`) | agent | paid |
| `superseded` | execution | A newer revision replaced this content before extraction ran; the newer revision carries its own decision. | — | — | — |
| `daily_limit` | execution | The automatic daily limit (chronicle.auto_daily_limit = 200 calls per rolling 24 hours) is used up; pending pages wait for a free slot. | `gbrain config set chronicle.auto_daily_limit 400` | agent | paid |
| `judge_llm_unavailable` | execution | No chat provider is configured on the brain host, so extraction cannot run. | — | user | credentials |
@@ -294,4 +299,11 @@ Don't hand-write `life/events/` pages: extraction owns them and retires events
the page no longer supports. Edit the meeting page instead. Only a complete
re-extraction retires events: one that finds no events, drops or caps a
proposal, or reads a page longer than the judge's window keeps the earlier
-events live.
+events live. A page longer than the window counts as complete when the window
+still starts with all the text the live events came from (the conversation
+only grew at the end), so a re-extraction of it replaces them. A revision that
+changes nothing extraction reads (for example only a long conversation's
+newest messages, past the window) makes no call at all and records
+`judge_input_unchanged`, and text the judge keeps failing on is paid for at
+most the attempt limit across revisions (`judge_input_failed`). Text past the
+first 12,000 characters is not extracted yet.
diff --git a/src/commands/doctor/checks/auto-chronicle.ts b/src/commands/doctor/checks/auto-chronicle.ts
index 5d31fed413..75875c4675 100644
--- a/src/commands/doctor/checks/auto-chronicle.ts
+++ b/src/commands/doctor/checks/auto-chronicle.ts
@@ -11,7 +11,7 @@ import {
AUTO_CHRONICLE_KEEP_ARGV, AUTO_CHRONICLE_OPT_OUT_ARGV, CHRONICLE_NUMERIC_KEYS, autoChronicleNeedsAcknowledgement,
autoChronicleSetting, chronicleSettings,
} from '../../../core/chronicle/config.ts';
-import { describeChronicleActivity, readChronicleLedgerStats } from '../../../core/chronicle/ledger-stats.ts';
+import { describeChronicleActivity, readChronicleDuplicateEvents, readChronicleLedgerStats } from '../../../core/chronicle/ledger-stats.ts';
import { CHRONICLE_REASONS, CHRONICLE_RUN_NOW_ARGV, chronicleBackfillArgv } from '../../../core/chronicle/reasons.ts';
import type { Action } from '../../../core/agent-output.ts';
import type { ReadinessState } from '../../../core/readiness.ts';
@@ -118,6 +118,17 @@ async function runAutoChronicle(ctx: DoctorContext): Promise<Check[]> {
checks.push({ name: 'chronicle_config_invalid', status: 'ok', message: 'chronicle.* settings are valid.' });
}
+ const duplicates = await readChronicleDuplicateEvents(engine);
+ if (duplicates.pages > 0) {
+ checks.push(infoCheck('chronicle_duplicate_events',
+ `${duplicates.pages} meeting or conversation page(s) hold ${duplicates.surplus} live event(s) from earlier extraction runs that their newest extraction did not produce. ` +
+ 'Most are reworded copies an earlier release added each time it re-read a long page (#8972); this release no longer adds them. ' +
+ 'Nothing is changed automatically; a preview-first repair is tracked in https://github.com/garrytan/gbrain/issues/9012.',
+ 'ok', undefined, { code: 'chronicle_duplicate_events', severity: 'info', pages: duplicates.pages, surplus_events: duplicates.surplus, docs: AUTO_CHRONICLE_DOCS }));
+ } else {
+ checks.push({ name: 'chronicle_duplicate_events', status: 'ok', message: 'No page holds live events from an earlier extraction run beside its newest one.' });
+ }
+
if (await autoChronicleNeedsAcknowledgement(engine)) {
const ceiling = settings.dailyLimit * settings.jobBudgetUsd;
checks.push(infoCheck('auto_chronicle_default_on',
@@ -139,6 +150,6 @@ async function runAutoChronicle(ctx: DoctorContext): Promise<Check[]> {
export const autoChronicleEntry: DoctorEntry = {
name: 'auto_chronicle',
- emits: ['auto_chronicle', 'chronicle_config_invalid', 'auto_chronicle_default_on'],
+ emits: ['auto_chronicle', 'chronicle_config_invalid', 'chronicle_duplicate_events', 'auto_chronicle_default_on'],
run: runAutoChronicle,
};
diff --git a/src/core/chronicle/contract.ts b/src/core/chronicle/contract.ts
index 948f7f073f..b6ec8e7442 100644
--- a/src/core/chronicle/contract.ts
+++ b/src/core/chronicle/contract.ts
@@ -82,6 +82,13 @@ export interface ChronicleLedgerRow {
/** content_hash of each event page as the extractor wrote it, parallel to event_slugs. An event whose
* live hash is no longer in any row of its depth page was edited by an operator and is never touched. */
event_hashes: string[];
+ /** #8972: digest of the whole judge input this row's run read (extract-events.ts `chronicleJudgedInput`); null when not
+ * judged, or recorded before the column existed. */
+ judge_input_hash?: string | null;
+ /** #8972: length and sha256 of the body window the judge read; a later generation covers this row when its own window
+ * starts with the same text. */
+ judge_window_chars?: number | null;
+ judge_window_hash?: string | null;
decided_at: Date | string;
updated_at: Date | string;
}
diff --git a/src/core/chronicle/execute.ts b/src/core/chronicle/execute.ts
index 3595101496..f1bcef5961 100644
--- a/src/core/chronicle/execute.ts
+++ b/src/core/chronicle/execute.ts
@@ -12,7 +12,10 @@
* reservation, no model call. A failed or superseded run never retires
* the previous generation, and neither does an empty or partial one (#7013:
* no events, a proposal dropped or capped, or a body longer than the judge
- * read); an ineligible revision still retires it. A segmented page is never
+ * read, unless that window re-read the text of every live event, #8972); an
+ * ineligible revision still retires it. A revision whose judge input matches
+ * the input of the page's newest extracted generation makes no call and writes
+ * nothing (#8972: a long page whose tail changed). A segmented page is never
* materialized: the judge reads its compiled truth's first JUDGE_BODY_CHARS
* and its last message time comes from a block-by-block parse
* (segmentedJudgePage).
@@ -32,14 +35,15 @@ import type { ChronicleReasonCode } from './reasons.ts';
import type { ChronicleSettings } from './config.ts';
import { chroniclePageDate, isChronicleEligible } from './eligibility.ts';
import {
- allDroppedReason, buildChronicleEvents, chronicleJudgeContext, isValidProposal, JUDGE_BODY_CHARS, lastMessageAt, replacesPreviousGeneration,
+ allDroppedReason, buildChronicleEvents, chronicleJudgeContext, chronicleJudgedInput, isValidProposal, JUDGE_BODY_CHARS, lastMessageAt, replacesPreviousGeneration,
type ChronicleDropCounts, type ChronicleJudge, type ChronicleJudgeResult,
} from './extract-events.ts';
import { endedInviteProposal, markInviteEvents } from './invite-projection.ts';
import { RETIRE_REASONS, reserveChronicleSlot } from './ledger.ts';
import { CAMPAIGN_PRICING_POLICY, rowMaxAttempts } from './campaign.ts';
-import { pinDepth, publishChronicleGeneration, type ChronicleDepthPin } from './publish.ts';
+import { CHRONICLE_RETIRED_BY, pinDepth, publishChronicleGeneration, type ChronicleDepthPin } from './publish.ts';
import { describeMalformedProposals, diagnoseMalformedProposals, type MalformedProposalDiagnostics } from './proposal-diagnostics.ts';
+import { sha256 } from '../persistence/digest.ts';
export interface ChronicleExecContext {
engine: BrainEngine;
@@ -109,6 +113,7 @@ async function setNextAttempt(engine: BrainEngine, row: ChronicleLedgerRow, at:
async function finish(engine: BrainEngine, row: ChronicleLedgerRow, attempt: number, patch: {
state: ChronicleLedgerRow['state']; reason: string | null; nextAttemptAt: Date | null;
costUsd?: number | null; unpriced?: boolean; events?: Array<{ slug: string; hash: string }>;
+ judged?: ReturnType<typeof chronicleJudgedInput>;
}): Promise<void> {
if (patch.costUsd != null) {
await engine.executeRaw(
@@ -118,10 +123,13 @@ async function finish(engine: BrainEngine, row: ChronicleLedgerRow, attempt: num
}
await engine.executeRaw(
`UPDATE chronicle_page_state SET state=$5, reason=$6, next_attempt_at=$7::timestamptz, unpriced=COALESCE($8::boolean, unpriced),
- event_slugs=COALESCE($9::text[], event_slugs), event_hashes=COALESCE($10::text[], event_hashes), updated_at=now()
+ event_slugs=COALESCE($9::text[], event_slugs), event_hashes=COALESCE($10::text[], event_hashes),
+ judge_input_hash=COALESCE($12, judge_input_hash), judge_window_chars=COALESCE($13::int, judge_window_chars),
+ judge_window_hash=COALESCE($14, judge_window_hash), updated_at=now()
WHERE source_id=$1 AND page_id=$2 AND content_hash=$3 AND extractor_version=$4 AND attempts=$11`,
[...key(row), patch.state, patch.reason, patch.nextAttemptAt ? patch.nextAttemptAt.toISOString() : null, patch.unpriced ?? null,
- patch.events ? patch.events.map((e) => e.slug) : null, patch.events ? patch.events.map((e) => e.hash) : null, attempt]);
+ patch.events ? patch.events.map((e) => e.slug) : null, patch.events ? patch.events.map((e) => e.hash) : null, attempt,
+ patch.judged?.inputHash ?? null, patch.judged?.window.length ?? null, patch.judged?.windowHash ?? null]);
}
function backoff(attempts: number, now: Date, maxAttempts: number): Date | null {
@@ -129,6 +137,58 @@ function backoff(attempts: number, now: Date, maxAttempts: number): Date | null
return new Date(now.getTime() + Math.min(6 * 3_600_000, 5 * 60_000 * 2 ** Math.max(0, attempts - 1)));
}
+/**
+ * #8972: whether the page's newest generation was judged on exactly this input and its events still stand. The newest
+ * generation is the extracted row of the latest decided revision, unless a later revision retired the page's events
+ * (an ineligible revision, RETIRE_REASONS); events of it that a chronicle retirement removed since (a deleted and
+ * restored page) mean the page needs judging again.
+ */
+async function judgedOnSameInput(engine: BrainEngine, row: ChronicleLedgerRow, inputHash: string): Promise<boolean> {
+ const [latest] = await engine.executeRaw<{ state: string; judge_input_hash: string | null; retired: boolean }>(
+ `SELECT c.state, c.judge_input_hash, EXISTS (SELECT 1 FROM pages e WHERE e.source_id=c.source_id AND e.slug = ANY(c.event_slugs)
+ AND e.deleted_at IS NOT NULL AND e.frontmatter->>'retired_by' = $6) AS retired
+ FROM chronicle_page_state c
+ WHERE c.source_id=$1 AND c.page_id=$2 AND c.extractor_version=$3 AND c.content_hash<>$4
+ AND (c.state='extracted' OR (c.state='skipped' AND c.reason = ANY($5::text[])))
+ ORDER BY c.decided_at DESC, c.updated_at DESC LIMIT 1`,
+ [row.source_id, Number(row.page_id), CHRONICLE_EXTRACTOR_VERSION, row.content_hash, [...RETIRE_REASONS], CHRONICLE_RETIRED_BY]);
+ return latest?.state === 'extracted' && latest.judge_input_hash === inputHash && !latest.retired;
+}
+
+/**
+ * #8972: paid attempts earlier revisions of the page already spent on exactly this input without publishing it, so a
+ * judge that keeps failing on an unchanged window (output cap, malformed output, per-page cap) is not paid again for
+ * every new tail message; `refused` when one of them was refused.
+ */
+async function failedAttemptsOnSameInput(engine: BrainEngine, row: ChronicleLedgerRow, inputHash: string): Promise<{ attempts: number; refused: boolean }> {
+ const [prior] = await engine.executeRaw<{ attempts: number | string | null; refused: boolean | null }>(
+ `SELECT sum(attempts) AS attempts, bool_or(state='skipped' AND reason='judge_refused') AS refused FROM chronicle_page_state
+ WHERE source_id=$1 AND page_id=$2 AND extractor_version=$3 AND content_hash<>$4 AND judge_input_hash=$5 AND state<>'extracted'`,
+ [row.source_id, Number(row.page_id), CHRONICLE_EXTRACTOR_VERSION, row.content_hash, inputHash]);
+ return { attempts: Number(prior?.attempts ?? 0), refused: prior?.refused === true };
+}
+
+/**
+ * #8972: whether a judge that read `window` (a body longer than the window) re-read every text the page's live events
+ * came from. Fails closed: every live chronicle event naming the depth page must be one a ledger row of the page
+ * recorded, and every such row must have recorded a judged window that `window` starts with. An event no row accounts
+ * for, or a row recorded before the window was stored (or by an earlier extractor), keeps the generation additive (#7013).
+ */
+async function windowCoversLiveEvents(engine: BrainEngine, row: ChronicleLedgerRow, depthSlug: string, window: string): Promise<boolean> {
+ const live = (await engine.executeRaw<{ slug: string }>(
+ `SELECT slug FROM pages WHERE source_id=$1 AND deleted_at IS NULL AND type='event'
+ AND frontmatter->'event'->>'depth' = $2 AND frontmatter->>'captured_via' LIKE 'life-chronicle:%'`,
+ [row.source_id, depthSlug])).map((r) => r.slug);
+ if (!live.length) return true;
+ const producers = await engine.executeRaw<{ event_slugs: string[]; judge_window_chars: number | null; judge_window_hash: string | null }>(
+ `SELECT event_slugs, judge_window_chars, judge_window_hash FROM chronicle_page_state
+ WHERE source_id=$1 AND page_id=$2 AND event_slugs && $3::text[]`,
+ [row.source_id, Number(row.page_id), live]);
+ const attributed = new Set(producers.flatMap((p) => p.event_slugs));
+ return live.every((slug) => attributed.has(slug)) && producers.every((p) => p.judge_window_chars != null && p.judge_window_hash != null
+ && Number(p.judge_window_chars) <= window.length && sha256(window.slice(0, Number(p.judge_window_chars))) === p.judge_window_hash);
+}
+
/** Copy a child scope's spend onto the ambient tracker so an enclosing budget sees it. */
function propagateSpend(parent: BudgetTracker | null, child: BudgetTracker): void {
if (!parent || parent === child) return;
@@ -211,6 +271,20 @@ export async function executeChronicleRow(ctx: ChronicleExecContext, row: Chroni
const judgeCtx = chronicleJudgeContext(page, lastMessage);
const invite = endedInviteProposal(page, judgeCtx.attendees, now);
+ const judgedInput = chronicleJudgedInput(judgeCtx.input, { visibility: pin.visibility, incarnation: pin.incarnation });
+ // #8972: a revision changed only where the judge does not read (a long page's tail) would pay for the same answer.
+ if (!invite && await judgedOnSameInput(engine, row, judgedInput.inputHash)) {
+ await finish(engine, row, row.attempts, { state: 'skipped', reason: 'judge_input_unchanged', nextAttemptAt: null, judged: judgedInput });
+ return done('skipped', 'judge_input_unchanged');
+ }
+ if (!invite && auto) {
+ const prior = await failedAttemptsOnSameInput(engine, row, judgedInput.inputHash);
+ if (prior.refused || prior.attempts >= rowMaxAttempts(row)) {
+ const reason = prior.refused ? 'judge_refused' : 'judge_input_failed';
+ await finish(engine, row, row.attempts, { state: prior.refused ? 'skipped' : 'failed', reason, nextAttemptAt: null, judged: judgedInput });
+ return done(prior.refused ? 'skipped' : 'failed', reason);
+ }
+ }
if (auto && !invite && !(await reserveChronicleSlot(engine, settings.dailyLimit, { sourceId: row.source_id, pageId: Number(row.page_id), contentHash: row.content_hash }))) {
await setNextAttempt(engine, row, null);
return { kind: 'deferred', reason: 'daily_limit' };
@@ -248,7 +322,7 @@ export async function executeChronicleRow(ctx: ChronicleExecContext, row: Chroni
const failure: JudgeFailure | null = overCap && !thrown ? { state: 'failed', reason: 'budget_exhausted' } : classifyJudge(result, thrown);
if (failure) {
const next = failure.state === 'skipped' || CONFIG_BLOCKED.has(failure.reason) ? null : backoff(attempts, now, maxAttempts);
- await finish(engine, row, attempts, { state: failure.state, reason: failure.reason, nextAttemptAt: next, ...spend });
+ await finish(engine, row, attempts, { state: failure.state, reason: failure.reason, nextAttemptAt: next, judged: invite ? undefined : judgedInput, ...spend });
if (!failure.malformed) return done(failure.state, failure.reason, judged);
console.warn(`[chronicle] ${row.slug}: the judge's events failed validation (malformed_proposal: ${describeMalformedProposals(failure.malformed)}); nothing was written${next ? ' and the row retries with backoff' : ''}.`);
return done(failure.state, failure.reason, { ...judged, malformed: failure.malformed });
@@ -258,11 +332,13 @@ export async function executeChronicleRow(ctx: ChronicleExecContext, row: Chroni
const built = buildChronicleEvents(proposals, judgeCtx,
{ slug: pin.slug, visibility: pin.visibility, contentHash: pin.contentHash }, { tz: ctx.tz, now, maxEvents: settings.maxEventsPerPage });
const { events, dropped } = built;
+ // #8972: a truncated generation that re-read the text of every live event is complete for what the page has produced.
+ const truncated = bodyTruncated && !(replacesPreviousGeneration(built, false) && await windowCoversLiveEvents(engine, row, pin.slug, judgedInput.window));
let generation;
try {
generation = await publishChronicleGeneration(engine, {
sourceId: row.source_id, pin, decisionRequestId: row.request_id, maintenance: ctx.maintenance, signal: ctx.signal,
- events: invite ? markInviteEvents(events) : events, replaces: replacesPreviousGeneration(built, bodyTruncated),
+ events: invite ? markInviteEvents(events) : events, replaces: replacesPreviousGeneration(built, truncated),
});
} catch (error) {
if ((error as Error)?.name === 'AbortError') throw error;
@@ -271,11 +347,13 @@ export async function executeChronicleRow(ctx: ChronicleExecContext, row: Chroni
return done('failed', 'publish_error', { ...judged, dropped });
}
if (generation.superseded) {
- await finish(engine, row, attempts, { state: 'skipped', reason: 'superseded', nextAttemptAt: null, events: generation.written, ...spend });
+ await finish(engine, row, attempts, { state: 'skipped', reason: 'superseded', nextAttemptAt: null, events: generation.written, judged: invite ? undefined : judgedInput, ...spend });
return done('skipped', 'superseded', { ...judged, written: generation.written.length, dropped });
}
const reason = events.length > 0 ? null : proposals.length === 0 ? 'no_events' : allDroppedReason(dropped);
- await finish(engine, row, attempts, { state: 'extracted', reason, nextAttemptAt: null, events: generation.written, ...spend });
+ // An ended invite's projection and a held result (nothing published) never stand for a judged input.
+ await finish(engine, row, attempts, { state: 'extracted', reason, nextAttemptAt: null, events: generation.written,
+ judged: invite || generation.held ? undefined : judgedInput, ...spend });
return done('extracted', reason, { ...judged, written: generation.written.length, retired: generation.retired.length, dropped });
}
diff --git a/src/core/chronicle/extract-events.ts b/src/core/chronicle/extract-events.ts
index 1f37f34404..3c24af5d1d 100644
--- a/src/core/chronicle/extract-events.ts
+++ b/src/core/chronicle/extract-events.ts
@@ -16,6 +16,8 @@ import { parseConversation } from '../conversation-parser/parse.ts';
import { isSegmentedPage } from '../page-body/page-shape.ts';
import { chroniclePageDate } from './eligibility.ts';
import { chronicleSettings } from './config.ts';
+import { CHRONICLE_EXTRACTOR_VERSION } from './contract.ts';
+import { digest, sha256 } from '../persistence/digest.ts';
import { buildChronicleEvent, pinDepth, publishChronicleGeneration, type BuiltChronicleEvent } from './publish.ts';
import { diagnoseMalformedProposals, type MalformedProposalDiagnostics } from './proposal-diagnostics.ts';
@@ -188,6 +190,17 @@ export function replacesPreviousGeneration(built: { events: readonly unknown[];
return built.events.length > 0 && Object.keys(built.dropped).length === 0 && !bodyTruncated;
}
+/**
+ * #8972: what the judge reads of one snapshot. `inputHash` covers every field the judge sees (page fields and the body's
+ * first JUDGE_BODY_CHARS), the extractor version and what the events are stamped with (`stamp`: the depth page's
+ * effective visibility and source incarnation), so an unchanged hash means a re-judge would publish the same events.
+ * `window` is that body window; `windowHash` its sha256.
+ */
+export function chronicleJudgedInput(input: ChronicleJudgeInput, stamp: { visibility: string; incarnation: string }): { inputHash: string; window: string; windowHash: string } {
+ const window = input.body.slice(0, JUDGE_BODY_CHARS);
+ return { inputHash: digest(['chronicle-judge-input-v1', CHRONICLE_EXTRACTOR_VERSION, { ...input, body: window }, stamp]), window, windowHash: sha256(window) };
+}
+
/** The latest message timestamp of a chat-shaped body (multi-day conversations end on their last message). */
export function lastMessageAt(body: string, fallbackDate: string | undefined): Date | null {
const { messages } = parseConversation(body, { fallbackDate, noPolish: true, noFallback: true });
diff --git a/src/core/chronicle/ledger-stats.ts b/src/core/chronicle/ledger-stats.ts
index 9ab8739a52..ba1d265820 100644
--- a/src/core/chronicle/ledger-stats.ts
+++ b/src/core/chronicle/ledger-stats.ts
@@ -76,6 +76,38 @@ export async function readChronicleLedgerStats(engine: BrainEngine): Promise<Chr
}
}
+export interface ChronicleDuplicateEvents { pages: number; surplus: number }
+
+/**
+ * #8972: depth pages holding live events from earlier extraction runs that the page's newest extraction (its latest
+ * decided extracted ledger row, any extractor version) did not produce, and how many such events. Releases before the
+ * fix re-judged long pages on every revision and added a reworded copy of each event per run; a page's partial
+ * generations (#7013) count too. Read-only; only pages with two or more ledger rows that recorded events are read.
+ */
+export async function readChronicleDuplicateEvents(engine: BrainEngine): Promise<ChronicleDuplicateEvents> {
+ try {
+ const [row] = await engine.executeRaw<{ pages: number; surplus: number }>(
+ `WITH multi AS (
+ SELECT source_id, page_id FROM chronicle_page_state WHERE cardinality(event_slugs) > 0 GROUP BY source_id, page_id HAVING count(*) > 1),
+ newest AS (
+ SELECT DISTINCT ON (c.source_id, c.page_id) c.source_id, c.page_id, c.event_slugs
+ FROM chronicle_page_state c JOIN multi m ON m.source_id = c.source_id AND m.page_id = c.page_id
+ WHERE c.state = 'extracted' ORDER BY c.source_id, c.page_id, c.decided_at DESC, c.updated_at DESC),
+ live AS (
+ SELECT DISTINCT c.source_id, c.page_id, e.slug
+ FROM chronicle_page_state c JOIN multi m ON m.source_id = c.source_id AND m.page_id = c.page_id
+ CROSS JOIN LATERAL unnest(c.event_slugs) AS s(slug)
+ JOIN pages e ON e.source_id = c.source_id AND e.slug = s.slug AND e.deleted_at IS NULL AND e.content_hash = ANY(c.event_hashes))
+ SELECT count(DISTINCT l.source_id || ':' || l.page_id)::int AS pages, count(*)::int AS surplus
+ FROM live l LEFT JOIN newest n ON n.source_id = l.source_id AND n.page_id = l.page_id
+ WHERE n.event_slugs IS NULL OR NOT (l.slug = ANY(n.event_slugs))`);
+ return { pages: Number(row?.pages ?? 0), surplus: Number(row?.surplus ?? 0) };
+ } catch (error) {
+ if (isMissingSchemaObject(error, 'table', ['chronicle_page_state'])) return { pages: 0, surplus: 0 };
+ throw error;
+ }
+}
+
/**
* One line for doctor/advisor: 24 h usage against the limit, the largest writer's share, 7-day
* outcomes and spend. `nameWriters: false` (remote advisor callers) keeps the share but not who.
diff --git a/src/core/chronicle/reasons.ts b/src/core/chronicle/reasons.ts
index 0969b0dba2..98d837b386 100644
--- a/src/core/chronicle/reasons.ts
+++ b/src/core/chronicle/reasons.ts
@@ -84,6 +84,11 @@ export const CHRONICLE_REASONS = {
meaning: () => 'The page is no longer a meeting, conversation or calendar page, so the events extracted from it were retired.' },
already_extracted: { stage: 'decision',
meaning: () => 'This exact content was already extracted; its events are current, so no new call is made.' },
+ judge_input_unchanged: { stage: 'execution',
+ meaning: () => 'Nothing the extraction reads changed since the page was last extracted (for example only text past a long page\'s first 12,000 characters changed), so the earlier events are current and no new call is made.' },
+ judge_input_failed: { stage: 'execution',
+ meaning: () => 'Earlier revisions of the page already spent every extraction attempt on exactly this text without publishing events (the calls failed, or a newer revision arrived first), so it is not paid for again until the text extraction reads changes.',
+ fix: backfill('agent', 'After fixing the cause the earlier failure named (doctor auto_chronicle), preview and backfill the page if the user agrees to one more paid chat call.') },
superseded: { stage: 'execution',
meaning: () => 'A newer revision replaced this content before extraction ran; the newer revision carries its own decision.' },
daily_limit: { stage: 'execution',
diff --git a/src/core/doctor-categories.ts b/src/core/doctor-categories.ts
index 7f676f4c6a..97a9d772fc 100644
--- a/src/core/doctor-categories.ts
+++ b/src/core/doctor-categories.ts
@@ -117,6 +117,7 @@ export const BRAIN_CHECK_NAMES: ReadonlySet<string> = new Set([
'auto_chronicle',
'auto_chronicle_default_on',
'chronicle_config_invalid',
+ 'chronicle_duplicate_events',
'facts_drain',
'fact_take_vectors',
'code_chunk_metadata',
diff --git a/src/core/error-registry.ts b/src/core/error-registry.ts
index af6d21fed8..4eae9b0515 100644
--- a/src/core/error-registry.ts
+++ b/src/core/error-registry.ts
@@ -146,7 +146,7 @@ export const CODES = {
host_upgrade_required: { class: 'host_only', retryable: false, exit: 16, summary: "The brain host is older than this client and did not answer the question asked: a get_page reply to an `as_of` read came back without `valid_time.as_of`, so it is the current page, not the edition in force on that date. Nothing historical was printed.", why: 'An older host ignores a read parameter it does not know and answers the plain read. Printing that answer as the edition in force on a date would quote the wrong text, so the client fails closed. The error carries the client version, the host version when known, and the minimum host version.', docs: 'docs/guides/page-history.md#host_upgrade_required', suggestion: 'Upgrade gbrain on the brain host (`gbrain upgrade`), or ask its operator to; then run the same read again.' },
change_reason_rejected: { class: 'caller', summary: "The write's reason was refused before anything was admitted: it is longer than 500 characters, or it looks like it holds a secret.", why: 'A reason is kept in page history and, on a page that reaches Git, in the commit message, which a push makes permanent; it is checked before the write is journaled so no copy of a refused reason is stored anywhere.', reasons: ['reason_too_long', 'reason_contains_secret'], legacy_error: 'invalid_params', docs: 'docs/guides/page-history.md#reasons', suggestion: 'Shorten the reason, or remove the secret from it, and send the write again.' },
changed_since_preview: { class: 'caller', summary: "The file changed after its repair was previewed, so nothing was written.", why: "A repair writes exactly the bytes the operator approved; it binds approval to the previewed file hash and refuses when the file moved on.", suggestion: 'Preview the repair again, review the new proposal, and approve its new hash.' },
- chronicle_skipped: { class: 'unavailable', summary: "Automatic event extraction (auto_chronicle) skipped or failed this page; `reason` says why and `fix`, when present, is the next step.", reasons: ['auto_chronicle_off', 'auto_chronicle_invalid', 'slug_bound_client', 'operation_bound_client', 'no_extract', 'history', 'not_yet_happened', 'too_short', 'dream_generated', 'page_body_segmented', 'no_write_decision', 'not_chronicle_shaped', 'already_extracted', 'superseded', 'daily_limit', 'judge_llm_unavailable', 'no_pricing', 'budget_exhausted', 'campaign_exhausted', 'judge_chat_error', 'judge_truncated', 'judge_parse_failed', 'malformed_proposal', 'publish_error', 'judge_refused', 'page_missing', 'no_events', 'future_dated', 'date_imprecise', 'no_chat_provider'], docs: 'docs/guides/life-chronicle.md#skip-and-failure-codes', suggestion: 'Read the receipt or doctor `auto_chronicle` check: its `why` explains the reason and its `fix`, when present, is the next step (paid fixes need the user\'s agreement).' },
+ chronicle_skipped: { class: 'unavailable', summary: "Automatic event extraction (auto_chronicle) skipped or failed this page; `reason` says why and `fix`, when present, is the next step.", reasons: ['auto_chronicle_off', 'auto_chronicle_invalid', 'slug_bound_client', 'operation_bound_client', 'no_extract', 'history', 'not_yet_happened', 'too_short', 'dream_generated', 'page_body_segmented', 'no_write_decision', 'not_chronicle_shaped', 'already_extracted', 'judge_input_unchanged', 'judge_input_failed', 'superseded', 'daily_limit', 'judge_llm_unavailable', 'no_pricing', 'budget_exhausted', 'campaign_exhausted', 'judge_chat_error', 'judge_truncated', 'judge_parse_failed', 'malformed_proposal', 'publish_error', 'judge_refused', 'page_missing', 'no_events', 'future_dated', 'date_imprecise', 'no_chat_provider'], docs: 'docs/guides/life-chronicle.md#skip-and-failure-codes', suggestion: 'Read the receipt or doctor `auto_chronicle` check: its `why` explains the reason and its `fix`, when present, is the next step (paid fixes need the user\'s agreement).' },
checkout_not_a_source: { class: 'caller', actor: 'user', summary: "gbrain git commit-push resolved a checkout from the working directory that is not one of this brain's source checkouts on this host (for example a wrapper that changed into another repository), so nothing was staged.", why: 'Committing there would write into an unrelated repository, or fail later with a confusing path refusal.', docs: 'docs/guides/shared-checkout-git.md#checkout_not_a_source' },
checkpoint_missing: { class: 'caller', summary: "The approved source plan is missing; do not restart from a different revision." },
checkpoint_validation_timeout: { class: 'retryable', summary: "Validating the managed-sync checkpoint timed out." },
diff --git a/src/core/pglite-schema.generated.ts b/src/core/pglite-schema.generated.ts
index e1d41ac7fe..f291ea9d83 100644
--- a/src/core/pglite-schema.generated.ts
+++ b/src/core/pglite-schema.generated.ts
@@ -1366,6 +1366,9 @@ CREATE TABLE IF NOT EXISTS chronicle_page_state (
pricing_policy TEXT,
campaign_max_usd NUMERIC,
cost_attempts INTEGER[] NOT NULL DEFAULT '{}',
+ judge_input_hash TEXT,
+ judge_window_chars INTEGER CHECK (judge_window_chars >= 0),
+ judge_window_hash TEXT,
PRIMARY KEY (source_id, page_id, content_hash, extractor_version)
);
CREATE INDEX IF NOT EXISTS chronicle_page_state_work_idx
diff --git a/src/core/schema-embedded.generated.ts b/src/core/schema-embedded.generated.ts
index c3b0a2e3ac..eda91a1b7b 100644
--- a/src/core/schema-embedded.generated.ts
+++ b/src/core/schema-embedded.generated.ts
@@ -2106,6 +2106,10 @@ CREATE TABLE IF NOT EXISTS chronicle_page_state (
pricing_policy TEXT,
campaign_max_usd NUMERIC,
cost_attempts INTEGER[] NOT NULL DEFAULT '{}',
+ -- #8972 (migration chronicle_judge_window): what the judge read.
+ judge_input_hash TEXT,
+ judge_window_chars INTEGER CHECK (judge_window_chars >= 0),
+ judge_window_hash TEXT,
PRIMARY KEY (source_id, page_id, content_hash, extractor_version)
);
CREATE INDEX IF NOT EXISTS chronicle_page_state_work_idx
diff --git a/src/core/schema-migrations/latest.generated.ts b/src/core/schema-migrations/latest.generated.ts
index a8fdb37405..23b6b67130 100644
--- a/src/core/schema-migrations/latest.generated.ts
+++ b/src/core/schema-migrations/latest.generated.ts
@@ -4,4 +4,4 @@
// The highest schema migration version (migrate.ts LATEST_VERSION), importable without
// loading the migrations themselves.
-export const LATEST_SCHEMA_VERSION = 296;
+export const LATEST_SCHEMA_VERSION = 297;
diff --git a/src/core/schema-migrations/registry.generated.ts b/src/core/schema-migrations/registry.generated.ts
index 852ba0067c..fbb6da24f2 100644
--- a/src/core/schema-migrations/registry.generated.ts
+++ b/src/core/schema-migrations/registry.generated.ts
@@ -297,6 +297,7 @@ import { v293 } from './v293-qm-attest-sources.ts';
import { v294 } from './v294-refresh-barrier-import-deferral.ts';
import { v295 } from './v295-refresh-retry-hint-history-index.ts';
import { v296 } from './v296-ingest-applied-captures.ts';
+import { v297 } from './v297-chronicle-judge-window.ts';
// Array order is historical (see HISTORICAL_ARRAY_ORDER in the generator); the
// runner sorts by version before applying.
@@ -592,4 +593,5 @@ export const MIGRATIONS: Migration[] = [
v294,
v295,
v296,
+ v297,
];
diff --git a/src/core/schema-migrations/v297-chronicle-judge-window.ts b/src/core/schema-migrations/v297-chronicle-judge-window.ts
new file mode 100644
index 0000000000..20e5f503c2
--- /dev/null
+++ b/src/core/schema-migrations/v297-chronicle-judge-window.ts
@@ -0,0 +1,25 @@
+import type { Migration } from './types.ts';
+
+// Applied by src/core/migrate.ts on the next initSchema(); see docs/ENGINES.md
+// ("Canonical schema sources") for when schema.sql or a TS fragment also changes.
+//
+// #8972: each chronicle ledger row records what its judge read, so a revision
+// whose judge input did not change (a long conversation that grew past the
+// judge's window) makes no paid call, and a re-judged generation that read all
+// the text the live events came from replaces them instead of adding to them.
+// judge_input_hash: the digest of the whole judge input (page fields and the
+// body's first JUDGE_BODY_CHARS). judge_window_chars and judge_window_hash: the
+// length and sha256 of that body window. All nullable, metadata-only, no
+// backfill: a row recorded before this migration has no judged window, so the
+// next revision of its page is judged once more and stays additive. The number
+// is a placeholder restamped at the merge slot.
+export const v297: Migration = {
+ version: 297,
+ name: 'chronicle_judge_window',
+ idempotent: true,
+ sql: `
+ ALTER TABLE chronicle_page_state ADD COLUMN IF NOT EXISTS judge_input_hash TEXT;
+ ALTER TABLE chronicle_page_state ADD COLUMN IF NOT EXISTS judge_window_chars INTEGER CHECK (judge_window_chars >= 0);
+ ALTER TABLE chronicle_page_state ADD COLUMN IF NOT EXISTS judge_window_hash TEXT;
+ `,
+};
diff --git a/src/schema.sql b/src/schema.sql
index b7f4166081..318330dbf4 100644
--- a/src/schema.sql
+++ b/src/schema.sql
@@ -2102,6 +2102,10 @@ CREATE TABLE IF NOT EXISTS chronicle_page_state (
pricing_policy TEXT,
campaign_max_usd NUMERIC,
cost_attempts INTEGER[] NOT NULL DEFAULT '{}',
+ -- #8972 (migration chronicle_judge_window): what the judge read.
+ judge_input_hash TEXT,
+ judge_window_chars INTEGER CHECK (judge_window_chars >= 0),
+ judge_window_hash TEXT,
PRIMARY KEY (source_id, page_id, content_hash, extractor_version)
);
CREATE INDEX IF NOT EXISTS chronicle_page_state_work_idx
diff --git a/test/chronicle-long-conversation-8972.test.ts b/test/chronicle-long-conversation-8972.test.ts
new file mode 100644
index 0000000000..b25ffe280f
--- /dev/null
+++ b/test/chronicle-long-conversation-8972.test.ts
@@ -0,0 +1,211 @@
+/**
+ * #8972: a conversation page longer than the judge's window (JUDGE_BODY_CHARS) on the automatic path.
+ *
+ * Protects: a revision whose judge input is unchanged (the tail grew past the window) makes no paid call and writes no
+ * events; a re-judged generation that read every text the live events came from replaces them instead of piling up;
+ * a generation that did not (an edited head, or rows recorded before the judged window was stored) stays additive (#7013).
+ * Fails when: a growing long conversation is judged again on the same window, or each run adds a reworded copy of its
+ * events.
+ * Seams: an injected judge that rewords `what` on every call, as a real model does.
+ */
+import { afterEach, describe, expect, test } from 'bun:test';
+import type { BrainEngine } from '../src/core/engine.ts';
+import type { OperationContext } from '../src/core/ops/contract.ts';
+import { operationsByName } from '../src/core/operations.ts';
+import { runPhaseChronicle } from '../src/core/cycle/chronicle.ts';
+import { JUDGE_BODY_CHARS, type ChronicleJudge, type ChronicleJudgeInput } from '../src/core/chronicle/extract-events.ts';
+import { resetGateway } from '../src/core/ai/gateway.ts';
+import { readChronicleDuplicateEvents } from '../src/core/chronicle/ledger-stats.ts';
+import { managedBrain, type ManagedBrain } from './helpers/managed-brain.ts';
+import { requirePostgresTestDatabase } from './helpers/test-backends.ts';
+
+const databaseUrl = process.env.GBRAIN_TEST_BACKEND === 'postgres' ? requirePostgresTestDatabase() : undefined;
+const brain = (run: (b: ManagedBrain) => Promise<void>) => managedBrain(run, { databaseUrl });
+
+const today = new Date().toISOString().slice(0, 10);
+const SLUG = 'conversations/launch-thread';
+
+/** Chat lines numbered from `from` until the body reaches `chars`. */
+function messages(from: number, chars: number, speaker = 'alice-example'): string {
+ const lines: string[] = [];
+ let n = from;
+ while (lines.join('\n').length < chars) lines.push(`${speaker}: message ${n++} about the beta launch plan and the next steps for it.`);
+ return lines.join('\n');
+}
+const conversation = (body: string, title = 'Launch thread') => `---\ntype: conversation\ntitle: ${title}\ndate: ${today}\n---\n\n${body}`;
+
+async function put(ctx: OperationContext, content: string): Promise<void> {
+ const current = await ctx.engine.readPageSnapshot(SLUG, { sourceId: 'default' });
+ await operationsByName.put_page.handler(ctx, { slug: SLUG, content, ...(current ? { expected_revision: current.revision } : {}) });
+}
+async function settle(engine: BrainEngine) {
+ await engine.executeRaw("UPDATE chronicle_page_state SET next_attempt_at=now()-interval '1 second', decided_at=now()-interval '1 hour' WHERE state='pending'");
+}
+/** Two events per call; the wording of `what` changes on every call, as a model's does. */
+function rewordingJudge() {
+ const inputs: ChronicleJudgeInput[] = [];
+ const judge: ChronicleJudge = async (input) => {
+ inputs.push(input);
+ const n = inputs.length;
+ return { events: [
+ { when: today, who: ['people/alice-example'], what: `Alice agreed to ship the beta (wording ${n})`, kind: 'decision' },
+ { when: today, who: ['people/bob-example'], what: `Bob committed to the launch checklist (wording ${n})`, kind: 'commitment' },
+ ] };
+ };
+ return Object.assign(judge, { inputs });
+}
+async function run(engine: BrainEngine, judge: ChronicleJudge) {
+ await settle(engine);
+ return runPhaseChronicle(engine, { judge });
+}
+async function liveEvents(engine: BrainEngine): Promise<string[]> {
+ return (await engine.executeRaw<{ what: string }>(
+ "SELECT frontmatter->'event'->>'what' AS what FROM pages WHERE type='event' AND deleted_at IS NULL ORDER BY what")).map((r) => r.what);
+}
+async function retiredEvents(engine: BrainEngine): Promise<number> {
+ return (await engine.executeRaw<{ n: number }>(
+ "SELECT count(*)::int AS n FROM pages WHERE type='event' AND deleted_at IS NOT NULL AND frontmatter->>'retired_by'='life-chronicle'"))[0].n;
+}
+async function ledger(engine: BrainEngine) {
+ return (await engine.executeRaw<{ state: string; reason: string | null }>(
+ 'SELECT state, reason FROM chronicle_page_state ORDER BY decided_at, updated_at')).map((r) => [r.state, r.reason]);
+}
+async function reservations(engine: BrainEngine): Promise<number> {
+ return (await engine.executeRaw<{ n: number }>('SELECT count(*)::int AS n FROM chronicle_judge_reservations'))[0].n;
+}
+
+afterEach(() => { resetGateway(); });
+
+describe('#8972: long conversation pages', () => {
+ test('a tail that grows past the window is not judged again and adds no events', () => brain(async ({ engine, ctx }) => {
+ let body = messages(1, JUDGE_BODY_CHARS + 1_000);
+ await put(ctx, conversation(body));
+ const judge = rewordingJudge();
+ await run(engine, judge);
+ expect(judge.inputs).toHaveLength(1);
+ for (const n of [1, 2, 3]) {
+ body += `\nbob-example: tail message ${n}, well past the judged window.`;
+ await put(ctx, conversation(body));
+ const r = await run(engine, judge);
+ expect(r.details).toMatchObject({ judged: 0, events_written: 0, reasons: { judge_input_unchanged: 1 } });
+ }
+ expect(judge.inputs).toHaveLength(1);
+ expect(await reservations(engine)).toBe(1);
+ expect(await liveEvents(engine)).toEqual(['Alice agreed to ship the beta (wording 1)', 'Bob committed to the launch checklist (wording 1)']);
+ expect(await ledger(engine)).toEqual([['extracted', null], ['skipped', 'judge_input_unchanged'], ['skipped', 'judge_input_unchanged'],
+ ['skipped', 'judge_input_unchanged']]);
+ expect(await readChronicleDuplicateEvents(engine)).toEqual({ pages: 0, surplus: 0 });
+ }), 180_000);
+
+ test('a re-judge of the same window (the title changed) replaces the earlier events', () => brain(async ({ engine, ctx }) => {
+ const body = messages(1, JUDGE_BODY_CHARS + 1_000);
+ await put(ctx, conversation(body));
+ const judge = rewordingJudge();
+ await run(engine, judge);
+ await put(ctx, conversation(`${body}\nbob-example: one more.`, 'Launch thread (renamed)'));
+ const r = await run(engine, judge);
+ expect(judge.inputs).toHaveLength(2);
+ expect(r.details).toMatchObject({ judged: 1, events_written: 2, events_retired: 2 });
+ expect(await liveEvents(engine)).toEqual(['Alice agreed to ship the beta (wording 2)', 'Bob committed to the launch checklist (wording 2)']);
+ expect(await retiredEvents(engine)).toBe(2);
+ }), 180_000);
+
+ test('a short conversation that grows past the window keeps its text in the window: the first truncated run replaces', () => brain(async ({ engine, ctx }) => {
+ const head = messages(1, 5_000);
+ await put(ctx, conversation(head));
+ const judge = rewordingJudge();
+ await run(engine, judge);
+ await put(ctx, conversation(`${head}\n${messages(1_000, JUDGE_BODY_CHARS, 'bob-example')}`));
+ const r = await run(engine, judge);
+ expect(judge.inputs).toHaveLength(2);
+ expect(r.details).toMatchObject({ judged: 1, events_retired: 2 });
+ expect(await liveEvents(engine)).toEqual(['Alice agreed to ship the beta (wording 2)', 'Bob committed to the launch checklist (wording 2)']);
+ }), 180_000);
+
+ test('an edited head moves the window: the new run is judged and stays additive (#7013)', () => brain(async ({ engine, ctx }) => {
+ const body = messages(1, JUDGE_BODY_CHARS + 1_000);
+ await put(ctx, conversation(body));
+ const judge = rewordingJudge();
+ await run(engine, judge);
+ await put(ctx, conversation(`carol-example: an earlier message pasted in at the top.\n${body}`));
+ const r = await run(engine, judge);
+ expect(judge.inputs).toHaveLength(2);
+ expect(r.details).toMatchObject({ judged: 1, events_written: 2, events_retired: 0 });
+ expect(await liveEvents(engine)).toHaveLength(4);
+ }), 180_000);
+
+ test('a row recorded before the upgrade (no judged window) is judged once more, additively, then never again', () => brain(async ({ engine, ctx }) => {
+ let body = messages(1, JUDGE_BODY_CHARS + 1_000);
+ await put(ctx, conversation(body));
+ const judge = rewordingJudge();
+ await run(engine, judge);
+ await engine.executeRaw('UPDATE chronicle_page_state SET judge_input_hash=NULL, judge_window_chars=NULL, judge_window_hash=NULL');
+ for (const n of [1, 2]) {
+ body += `\nbob-example: tail message ${n}.`;
+ await put(ctx, conversation(body));
+ await run(engine, judge);
+ }
+ expect(judge.inputs).toHaveLength(2);
+ expect(await liveEvents(engine)).toHaveLength(4);
+ expect(await retiredEvents(engine)).toBe(0);
+ // Doctor's chronicle_duplicate_events: the pre-upgrade run's two events sit beside the newest run's two.
+ expect(await readChronicleDuplicateEvents(engine)).toEqual({ pages: 1, surplus: 2 });
+ }), 180_000);
+test('a judge that keeps failing on an unchanged window is paid at most the attempt limit across revisions', () => brain(async ({ engine, ctx }) => {
+ let body = messages(1, JUDGE_BODY_CHARS + 1_000);
+ await put(ctx, conversation(body));
+ let calls = 0;
+ const failing: ChronicleJudge = async () => { calls++; return { events: [], failure: 'truncated' }; };
+ await run(engine, failing);
+ for (const n of [1, 2, 3, 4, 5, 6]) {
+ body += `\nbob-example: tail message ${n}.`;
+ await put(ctx, conversation(body));
+ await run(engine, failing);
+ }
+ expect(calls).toBe(5);
+ expect((await ledger(engine)).at(-1)).toEqual(['failed', 'judge_input_failed']);
+ expect(await reservations(engine)).toBe(5);
+ }), 180_000);
+
+ test('events a chronicle retirement removed (a deleted and restored page) are judged again', () => brain(async ({ engine, ctx }) => {
+ const body = messages(1, JUDGE_BODY_CHARS + 1_000);
+ await put(ctx, conversation(body));
+ const judge = rewordingJudge();
+ await run(engine, judge);
+ const revision = async () => (await engine.readPageSnapshot(SLUG, { sourceId: 'default', includeDeleted: true }))!.revision;
+ await operationsByName.delete_page.handler(ctx, { slug: SLUG, expected_revision: await revision() });
+ await run(engine, judge); // the orphan sweep retires the deleted page's events
+ expect(await liveEvents(engine)).toHaveLength(0);
+ await operationsByName.restore_page.handler(ctx, { slug: SLUG, expected_revision: await revision() });
+ await put(ctx, conversation(`${body}\nbob-example: back again.`));
+ await run(engine, judge);
+ expect(judge.inputs).toHaveLength(2);
+ expect(await liveEvents(engine)).toHaveLength(2);
+ }), 180_000);
+
+ test('a privacy change re-judges a page whose text did not change, and its events take the new visibility', () => brain(async ({ engine, ctx }) => {
+ const body = messages(1, 2_000);
+ await put(ctx, conversation(body));
+ const judge = rewordingJudge();
+ await run(engine, judge);
+ await put(ctx, `---\ntype: conversation\ntitle: Launch thread\ndate: ${today}\nvisibility: private\n---\n\n${body}`);
+ await run(engine, judge);
+ expect(judge.inputs).toHaveLength(2);
+ const stamps = await engine.executeRaw<{ visibility: string }>(
+ "SELECT frontmatter->>'visibility' AS visibility FROM pages WHERE type='event' AND deleted_at IS NULL");
+ expect(stamps.map((s) => s.visibility)).toEqual(['private', 'private']);
+ }), 180_000);
+
+ test('a live event no ledger row accounts for keeps a re-judged long page additive', () => brain(async ({ engine, ctx }) => {
+ const body = messages(1, JUDGE_BODY_CHARS + 1_000);
+ await put(ctx, conversation(body));
+ const judge = rewordingJudge();
+ await run(engine, judge);
+ await engine.executeRaw("UPDATE chronicle_page_state SET event_slugs='{}', event_hashes='{}'");
+ await put(ctx, conversation(`${body}\nbob-example: one more.`, 'Launch thread (renamed)'));
+ const r = await run(engine, judge);
+ expect(judge.inputs).toHaveLength(2);
+ expect(r.details).toMatchObject({ judged: 1, events_retired: 0 });
+ expect(await liveEvents(engine)).toHaveLength(4);
+ }), 180_000);
+});
diff --git a/test/e2e/chronicle-long-conversation-8972-postgres.test.ts b/test/e2e/chronicle-long-conversation-8972-postgres.test.ts
new file mode 100644
index 0000000000..ccd8f22274
--- /dev/null
+++ b/test/e2e/chronicle-long-conversation-8972-postgres.test.ts
@@ -0,0 +1,3 @@
+import { registerPostgresTests } from '../helpers/test-backends.ts';
+
+await registerPostgresTests(() => import('../chronicle-long-conversation-8972.test.ts'));
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-default.json b/test/fixtures/goldens/catalog/pglite-engine-init-default.json
index fa40c9aaf8..72f511bf24 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-default.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-default.json
@@ -52,6 +52,7 @@
"chat_usage_log.chat_usage_log_pkey": "p PRIMARY KEY (id)",
"chronicle_judge_reservations.chronicle_judge_reservations_pkey": "p PRIMARY KEY (id)",
"chronicle_page_state.chronicle_page_state_attempts_check": "c CHECK ((attempts >= 0))",
+ "chronicle_page_state.chronicle_page_state_judge_window_chars_check": "c CHECK ((judge_window_chars >= 0))",
"chronicle_page_state.chronicle_page_state_max_attempts_check": "c CHECK ((max_attempts > 0))",
"chronicle_page_state.chronicle_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",
"chronicle_page_state.chronicle_page_state_pkey": "p PRIMARY KEY (source_id, page_id, content_hash, extractor_version)",
@@ -2042,7 +2043,10 @@
"23 max_attempts integer/int4 NULL",
"24 pricing_policy text/text NULL",
"25 campaign_max_usd numeric/numeric NULL",
- "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]"
+ "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",
+ "27 judge_input_hash text/text NULL",
+ "28 judge_window_chars integer/int4 NULL",
+ "29 judge_window_hash text/text NULL"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
index aa2c137aab..cf34d9411b 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
@@ -52,6 +52,7 @@
"chat_usage_log.chat_usage_log_pkey": "p PRIMARY KEY (id)",
"chronicle_judge_reservations.chronicle_judge_reservations_pkey": "p PRIMARY KEY (id)",
"chronicle_page_state.chronicle_page_state_attempts_check": "c CHECK ((attempts >= 0))",
+ "chronicle_page_state.chronicle_page_state_judge_window_chars_check": "c CHECK ((judge_window_chars >= 0))",
"chronicle_page_state.chronicle_page_state_max_attempts_check": "c CHECK ((max_attempts > 0))",
"chronicle_page_state.chronicle_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",
"chronicle_page_state.chronicle_page_state_pkey": "p PRIMARY KEY (source_id, page_id, content_hash, extractor_version)",
@@ -2042,7 +2043,10 @@
"23 max_attempts integer/int4 NULL",
"24 pricing_policy text/text NULL",
"25 campaign_max_usd numeric/numeric NULL",
- "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]"
+ "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",
+ "27 judge_input_hash text/text NULL",
+ "28 judge_window_chars integer/int4 NULL",
+ "29 judge_window_hash text/text NULL"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
index 22ea6da123..3dc4dd9031 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
@@ -52,6 +52,7 @@
"chat_usage_log.chat_usage_log_pkey": "p PRIMARY KEY (id)",
"chronicle_judge_reservations.chronicle_judge_reservations_pkey": "p PRIMARY KEY (id)",
"chronicle_page_state.chronicle_page_state_attempts_check": "c CHECK ((attempts >= 0))",
+ "chronicle_page_state.chronicle_page_state_judge_window_chars_check": "c CHECK ((judge_window_chars >= 0))",
"chronicle_page_state.chronicle_page_state_max_attempts_check": "c CHECK ((max_attempts > 0))",
"chronicle_page_state.chronicle_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",
"chronicle_page_state.chronicle_page_state_pkey": "p PRIMARY KEY (source_id, page_id, content_hash, extractor_version)",
@@ -2038,7 +2039,10 @@
"23 max_attempts integer/int4 NULL",
"24 pricing_policy text/text NULL",
"25 campaign_max_usd numeric/numeric NULL",
- "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]"
+ "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",
+ "27 judge_input_hash text/text NULL",
+ "28 judge_window_chars integer/int4 NULL",
+ "29 judge_window_hash text/text NULL"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/pglite-schema-blob-default.json b/test/fixtures/goldens/catalog/pglite-schema-blob-default.json
index e5c631fe71..f6cb4a00e4 100644
--- a/test/fixtures/goldens/catalog/pglite-schema-blob-default.json
+++ b/test/fixtures/goldens/catalog/pglite-schema-blob-default.json
@@ -17,6 +17,7 @@
"chat_usage_log.chat_usage_log_pkey": "p PRIMARY KEY (id)",
"chronicle_judge_reservations.chronicle_judge_reservations_pkey": "p PRIMARY KEY (id)",
"chronicle_page_state.chronicle_page_state_attempts_check": "c CHECK ((attempts >= 0))",
+ "chronicle_page_state.chronicle_page_state_judge_window_chars_check": "c CHECK ((judge_window_chars >= 0))",
"chronicle_page_state.chronicle_page_state_max_attempts_check": "c CHECK ((max_attempts > 0))",
"chronicle_page_state.chronicle_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",
"chronicle_page_state.chronicle_page_state_pkey": "p PRIMARY KEY (source_id, page_id, content_hash, extractor_version)",
@@ -1396,7 +1397,10 @@
"23 max_attempts integer/int4 NULL",
"24 pricing_policy text/text NULL",
"25 campaign_max_usd numeric/numeric NULL",
- "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]"
+ "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",
+ "27 judge_input_hash text/text NULL",
+ "28 judge_window_chars integer/int4 NULL",
+ "29 judge_window_hash text/text NULL"
],
"flags": "relkind=r rls=false force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.json
index 299b03517a..474210e0c2 100644
--- a/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.json
@@ -17,6 +17,7 @@
"chat_usage_log.chat_usage_log_pkey": "p PRIMARY KEY (id)",
"chronicle_judge_reservations.chronicle_judge_reservations_pkey": "p PRIMARY KEY (id)",
"chronicle_page_state.chronicle_page_state_attempts_check": "c CHECK ((attempts >= 0))",
+ "chronicle_page_state.chronicle_page_state_judge_window_chars_check": "c CHECK ((judge_window_chars >= 0))",
"chronicle_page_state.chronicle_page_state_max_attempts_check": "c CHECK ((max_attempts > 0))",
"chronicle_page_state.chronicle_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",
"chronicle_page_state.chronicle_page_state_pkey": "p PRIMARY KEY (source_id, page_id, content_hash, extractor_version)",
@@ -1396,7 +1397,10 @@
"23 max_attempts integer/int4 NULL",
"24 pricing_policy text/text NULL",
"25 campaign_max_usd numeric/numeric NULL",
- "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]"
+ "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",
+ "27 judge_input_hash text/text NULL",
+ "28 judge_window_chars integer/int4 NULL",
+ "29 judge_window_hash text/text NULL"
],
"flags": "relkind=r rls=false force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.json b/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.json
index 64fe5cb55d..5ac9cc9e43 100644
--- a/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.json
+++ b/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.json
@@ -17,6 +17,7 @@
"chat_usage_log.chat_usage_log_pkey": "p PRIMARY KEY (id)",
"chronicle_judge_reservations.chronicle_judge_reservations_pkey": "p PRIMARY KEY (id)",
"chronicle_page_state.chronicle_page_state_attempts_check": "c CHECK ((attempts >= 0))",
+ "chronicle_page_state.chronicle_page_state_judge_window_chars_check": "c CHECK ((judge_window_chars >= 0))",
"chronicle_page_state.chronicle_page_state_max_attempts_check": "c CHECK ((max_attempts > 0))",
"chronicle_page_state.chronicle_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",
"chronicle_page_state.chronicle_page_state_pkey": "p PRIMARY KEY (source_id, page_id, content_hash, extractor_version)",
@@ -1395,7 +1396,10 @@
"23 max_attempts integer/int4 NULL",
"24 pricing_policy text/text NULL",
"25 campaign_max_usd numeric/numeric NULL",
- "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]"
+ "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",
+ "27 judge_input_hash text/text NULL",
+ "28 judge_window_chars integer/int4 NULL",
+ "29 judge_window_hash text/text NULL"
],
"flags": "relkind=r rls=false force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/postgres-db-initschema.json b/test/fixtures/goldens/catalog/postgres-db-initschema.json
index 83a4153832..973828963f 100644
--- a/test/fixtures/goldens/catalog/postgres-db-initschema.json
+++ b/test/fixtures/goldens/catalog/postgres-db-initschema.json
@@ -17,6 +17,7 @@
"chat_usage_log.chat_usage_log_pkey": "p PRIMARY KEY (id)",
"chronicle_judge_reservations.chronicle_judge_reservations_pkey": "p PRIMARY KEY (id)",
"chronicle_page_state.chronicle_page_state_attempts_check": "c CHECK ((attempts >= 0))",
+ "chronicle_page_state.chronicle_page_state_judge_window_chars_check": "c CHECK ((judge_window_chars >= 0))",
"chronicle_page_state.chronicle_page_state_max_attempts_check": "c CHECK ((max_attempts > 0))",
"chronicle_page_state.chronicle_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",
"chronicle_page_state.chronicle_page_state_pkey": "p PRIMARY KEY (source_id, page_id, content_hash, extractor_version)",
@@ -1412,7 +1413,10 @@
"23 max_attempts integer/int4 NULL",
"24 pricing_policy text/text NULL",
"25 campaign_max_usd numeric/numeric NULL",
- "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]"
+ "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",
+ "27 judge_input_hash text/text NULL",
+ "28 judge_window_chars integer/int4 NULL",
+ "29 judge_window_hash text/text NULL"
],
"flags": "relkind=r rls=false force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-default.json b/test/fixtures/goldens/catalog/postgres-engine-init-default.json
index 8f965096b2..5c96fa9e27 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-default.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-default.json
@@ -52,6 +52,7 @@
"chat_usage_log.chat_usage_log_pkey": "p PRIMARY KEY (id)",
"chronicle_judge_reservations.chronicle_judge_reservations_pkey": "p PRIMARY KEY (id)",
"chronicle_page_state.chronicle_page_state_attempts_check": "c CHECK ((attempts >= 0))",
+ "chronicle_page_state.chronicle_page_state_judge_window_chars_check": "c CHECK ((judge_window_chars >= 0))",
"chronicle_page_state.chronicle_page_state_max_attempts_check": "c CHECK ((max_attempts > 0))",
"chronicle_page_state.chronicle_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",
"chronicle_page_state.chronicle_page_state_pkey": "p PRIMARY KEY (source_id, page_id, content_hash, extractor_version)",
@@ -2043,7 +2044,10 @@
"23 max_attempts integer/int4 NULL",
"24 pricing_policy text/text NULL",
"25 campaign_max_usd numeric/numeric NULL",
- "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]"
+ "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",
+ "27 judge_input_hash text/text NULL",
+ "28 judge_window_chars integer/int4 NULL",
+ "29 judge_window_hash text/text NULL"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
index 1015bc6397..620b35a0f9 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
@@ -52,6 +52,7 @@
"chat_usage_log.chat_usage_log_pkey": "p PRIMARY KEY (id)",
"chronicle_judge_reservations.chronicle_judge_reservations_pkey": "p PRIMARY KEY (id)",
"chronicle_page_state.chronicle_page_state_attempts_check": "c CHECK ((attempts >= 0))",
+ "chronicle_page_state.chronicle_page_state_judge_window_chars_check": "c CHECK ((judge_window_chars >= 0))",
"chronicle_page_state.chronicle_page_state_max_attempts_check": "c CHECK ((max_attempts > 0))",
"chronicle_page_state.chronicle_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",
"chronicle_page_state.chronicle_page_state_pkey": "p PRIMARY KEY (source_id, page_id, content_hash, extractor_version)",
@@ -2043,7 +2044,10 @@
"23 max_attempts integer/int4 NULL",
"24 pricing_policy text/text NULL",
"25 campaign_max_usd numeric/numeric NULL",
- "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]"
+ "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",
+ "27 judge_input_hash text/text NULL",
+ "28 judge_window_chars integer/int4 NULL",
+ "29 judge_window_hash text/text NULL"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
index bfd82d703f..aff00ab438 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
@@ -52,6 +52,7 @@
"chat_usage_log.chat_usage_log_pkey": "p PRIMARY KEY (id)",
"chronicle_judge_reservations.chronicle_judge_reservations_pkey": "p PRIMARY KEY (id)",
"chronicle_page_state.chronicle_page_state_attempts_check": "c CHECK ((attempts >= 0))",
+ "chronicle_page_state.chronicle_page_state_judge_window_chars_check": "c CHECK ((judge_window_chars >= 0))",
"chronicle_page_state.chronicle_page_state_max_attempts_check": "c CHECK ((max_attempts > 0))",
"chronicle_page_state.chronicle_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",
"chronicle_page_state.chronicle_page_state_pkey": "p PRIMARY KEY (source_id, page_id, content_hash, extractor_version)",
@@ -2039,7 +2040,10 @@
"23 max_attempts integer/int4 NULL",
"24 pricing_policy text/text NULL",
"25 campaign_max_usd numeric/numeric NULL",
- "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]"
+ "26 cost_attempts ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",
+ "27 judge_input_hash text/text NULL",
+ "28 judge_window_chars integer/int4 NULL",
+ "29 judge_window_hash text/text NULL"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/doctor/content-pglite-human.json b/test/fixtures/goldens/doctor/content-pglite-human.json
index 4e25de0931..acea3a6e2f 100644
--- a/test/fixtures/goldens/doctor/content-pglite-human.json
+++ b/test/fixtures/goldens/doctor/content-pglite-human.json
@@ -90,7 +90,7 @@
" [OK] rls: Skipped (PGLite — no PostgREST exposure, RLS not applicable)",
" [OK] function_search_path: Every gbrain function that pins a search_path ends it with pg_temp",
" [OK] schema_version: Version <latest> (latest: <latest>)",
- " [OK] schema_columns: 1388 column(s) verified against live schema",
+ " [OK] schema_columns: 1391 column(s) verified against live schema",
" [OK] schema_missing_tables: All 175 table(s) the applied migrations create exist.",
" [OK] rls_event_trigger: Skipped (PGLite — no event trigger support)",
" [INFO] embeddings: Not applicable: embeddings are disabled on this brain (keyword search keeps working).",
@@ -214,6 +214,7 @@
" [OK] edge_validity: relationships: none yet; read policy on; contradiction mode propose (default)",
" [OK] auto_chronicle: auto_chronicle is on (default). Last 24 h: 0 of 200 automatic extraction calls. Last 7 days: 0 extracted, 0 failed, 0 skipped; $0.00 known spend. 0 page(s) pending. No chat provider is configured, so nothing will be extracted until one is.",
" [OK] chronicle_config_invalid: chronicle.* settings are valid.",
+ " [OK] chronicle_duplicate_events: No page holds live events from an earlier extraction run beside its newest one.",
" [INFO] auto_chronicle_default_on: Automatic event extraction is on by default and the user has not confirmed it yet. Each eligible new or changed meeting, conversation or calendar page gets one paid chat call (cap $0.25 per page; at most 200 calls per day, so at most $50.00 per day for a priced model; an unpriced model has no cap), and page text goes to the configured chat provider. Relay this to the user, then run `gbrain config set auto_chronicle true` to keep it or `gbrain config set auto_chronicle false` to opt out.",
" [OK] facts_drain: No facts-absorb jobs are queued (no run recorded yet).",
" [INFO] wakeshift: Reporting back through Wakeshift is off (gbrain wakeshift enable turns it on).",
diff --git a/test/fixtures/goldens/doctor/content-pglite-json.json b/test/fixtures/goldens/doctor/content-pglite-json.json
index 63bb1b5937..8268ed73f7 100644
--- a/test/fixtures/goldens/doctor/content-pglite-json.json
+++ b/test/fixtures/goldens/doctor/content-pglite-json.json
@@ -1148,7 +1148,7 @@
{
"category": "meta",
"elapsed_ms": "<volatile>",
- "message": "1388 column(s) verified against live schema",
+ "message": "1391 column(s) verified against live schema",
"name": "schema_columns",
"status": "ok"
},
@@ -2932,6 +2932,13 @@
"name": "chronicle_config_invalid",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "No page holds live events from an earlier extraction run beside its newest one.",
+ "name": "chronicle_duplicate_events",
+ "status": "ok"
+ },
{
"category": "brain",
"details": {
diff --git a/test/fixtures/goldens/doctor/json-pglite-degraded.json b/test/fixtures/goldens/doctor/json-pglite-degraded.json
index 5dc7b9d4bb..5c261728fa 100644
--- a/test/fixtures/goldens/doctor/json-pglite-degraded.json
+++ b/test/fixtures/goldens/doctor/json-pglite-degraded.json
@@ -1061,7 +1061,7 @@
{
"category": "meta",
"elapsed_ms": "<volatile>",
- "message": "1388 column(s) verified against live schema",
+ "message": "1391 column(s) verified against live schema",
"name": "schema_columns",
"status": "ok"
},
@@ -2614,6 +2614,13 @@
"name": "chronicle_config_invalid",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "No page holds live events from an earlier extraction run beside its newest one.",
+ "name": "chronicle_duplicate_events",
+ "status": "ok"
+ },
{
"category": "brain",
"details": {
diff --git a/test/fixtures/goldens/doctor/json-pglite-fresh.json b/test/fixtures/goldens/doctor/json-pglite-fresh.json
index fe956f3135..74fc6ff617 100644
--- a/test/fixtures/goldens/doctor/json-pglite-fresh.json
+++ b/test/fixtures/goldens/doctor/json-pglite-fresh.json
@@ -1108,7 +1108,7 @@
{
"category": "meta",
"elapsed_ms": "<volatile>",
- "message": "1388 column(s) verified against live schema",
+ "message": "1391 column(s) verified against live schema",
"name": "schema_columns",
"status": "ok"
},
@@ -2670,6 +2670,13 @@
"name": "chronicle_config_invalid",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "No page holds live events from an earlier extraction run beside its newest one.",
+ "name": "chronicle_duplicate_events",
+ "status": "ok"
+ },
{
"category": "brain",
"details": {
diff --git a/test/fixtures/goldens/doctor/json-postgres-fresh.json b/test/fixtures/goldens/doctor/json-postgres-fresh.json
index 4c4b47af54..ee06a886d5 100644
--- a/test/fixtures/goldens/doctor/json-postgres-fresh.json
+++ b/test/fixtures/goldens/doctor/json-postgres-fresh.json
@@ -1104,7 +1104,7 @@
{
"category": "meta",
"elapsed_ms": "<volatile>",
- "message": "1394 column(s) verified against live schema",
+ "message": "1397 column(s) verified against live schema",
"name": "schema_columns",
"status": "ok"
},
@@ -2674,6 +2674,13 @@
"name": "chronicle_config_invalid",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "No page holds live events from an earlier extraction run beside its newest one.",
+ "name": "chronicle_duplicate_events",
+ "status": "ok"
+ },
{
"category": "brain",
"details": {
diff --git a/test/fixtures/goldens/doctor/registry-build-checks.json b/test/fixtures/goldens/doctor/registry-build-checks.json
index 51e19e3824..1afe39ca25 100644
--- a/test/fixtures/goldens/doctor/registry-build-checks.json
+++ b/test/fixtures/goldens/doctor/registry-build-checks.json
@@ -917,6 +917,10 @@
"category": "brain",
"name": "chronicle_config_invalid"
},
+ {
+ "category": "brain",
+ "name": "chronicle_duplicate_events"
+ },
{
"category": "brain",
"name": "auto_chronicle_default_on"
diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.json
index 5f3094c3a8..aca213a35a 100644
--- a/test/fixtures/goldens/migrations/records.json
+++ b/test/fixtures/goldens/migrations/records.json
@@ -1,6 +1,6 @@
{
"golden": {
- "count": 291,
+ "count": 292,
"gaps": [
17,
18,
@@ -97,7 +97,7 @@
"verifyProjectionStatistics": "0d231b04ecfbc5a4109d6fca9567bf4e8c9e9db6c3fbbb35212e026579ed6f67",
"withSchemaLockTimeout": "95605bd3004955e11e936c7a4aa6889319b401098abf9db18ef3e48da2c3fc59"
},
- "latest": 296,
+ "latest": 297,
"records": [
{
"handler": {
@@ -4826,6 +4826,19 @@
"transaction": "absent",
"verify": "absent",
"version": 296
+ },
+ {
+ "handler": "absent",
+ "idempotent": true,
+ "name": "chronicle_judge_window",
+ "sql": {
+ "length": 296,
+ "sha256": "6ab654bed8f18f1577c5a083474073b0f2ce116a7227cf0966f332fc8963c4c9"
+ },
+ "sqlFor": "absent",
+ "transaction": "absent",
+ "verify": "absent",
+ "version": 297
}
],
"versions": [
@@ -5119,7 +5132,8 @@
293,
294,
295,
- 296
+ 296,
+ 297
]
},
"normalizer": "migrations-record-v1"