Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge Lane 1 (chronicle core) into fix-wave-chronicle (#5876)

garrytan8285daf032e2
diff --cc src/core/schema-migrations/registry.generated.ts
index 13fe187cb2,2d8e8642b3..b53eaae58f
--- a/src/core/schema-migrations/registry.generated.ts
+++ b/src/core/schema-migrations/registry.generated.ts
@@@ -198,7 -198,7 +198,8 @@@ import { v194 } from './v194-f0-worktre
import { v195 } from './v195-f3-access-token-grants.ts';
import { v196 } from './v196-f4-planner-stats.ts';
import { v197 } from './v197-managed-guard-null-source-fallback.ts';
-import { v198 } from './v198-chronicle-page-state.ts';
+import { v198 } from './v198-publication-failure-detail.ts';
++import { v199 } from './v199-chronicle-page-state.ts';
// Array order is historical (see HISTORICAL_ARRAY_ORDER in the generator); the
// runner sorts by version before applying.
@@@ -396,4 -396,4 +397,5 @@@ export const MIGRATIONS: Migration[] =
v196,
v197,
v198,
++ v199,
];
diff --cc src/core/schema-migrations/v199-chronicle-page-state.ts
index 0000000000,680ddb6565..e9142240e3
mode 000000,100644..100644
--- a/src/core/schema-migrations/v199-chronicle-page-state.ts
+++ b/src/core/schema-migrations/v199-chronicle-page-state.ts
@@@ -1,0 -1,58 +1,58 @@@
+ 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.
+ //
+ // #5876: the Life Chronicle ledger. One row per (source, page, content,
+ // extractor version) records the write-time decision and the extraction
+ // outcome; it, not minion idempotency keys (pruned with their jobs), is the
+ // record of what was extracted. chronicle_judge_reservations holds one row
+ // per automatic judge call for the rolling daily limit. The activation stamp
+ // (config chronicle.activated_at) is stamped by the first write decision or chronicle phase run.
-export const v198: Migration = {
- version: 198,
++export const v199: Migration = {
++ version: 199,
+ name: 'chronicle_page_state',
+ idempotent: true,
+ sql: `
+ CREATE TABLE IF NOT EXISTS chronicle_page_state (
+ source_id TEXT NOT NULL REFERENCES sources(id) ON DELETE CASCADE,
+ page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE,
+ content_hash TEXT NOT NULL,
+ extractor_version INTEGER NOT NULL,
+ slug TEXT NOT NULL,
+ state TEXT NOT NULL CHECK (state IN ('pending','skipped','extracted','failed')),
+ reason TEXT,
+ trigger TEXT NOT NULL CHECK (trigger IN ('auto','backfill')),
+ principal_kind TEXT,
+ principal_id TEXT,
+ request_id UUID,
+ no_extract BOOLEAN NOT NULL DEFAULT false,
+ attempts INTEGER NOT NULL DEFAULT 0 CHECK (attempts >= 0),
+ next_attempt_at TIMESTAMPTZ,
+ cost_usd NUMERIC,
+ unpriced BOOLEAN NOT NULL DEFAULT false,
+ event_slugs TEXT[] NOT NULL DEFAULT '{}',
+ event_hashes TEXT[] NOT NULL DEFAULT '{}',
+ decided_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ PRIMARY KEY (source_id, page_id, content_hash, extractor_version)
+ );
+ CREATE INDEX IF NOT EXISTS chronicle_page_state_work_idx
+ ON chronicle_page_state (source_id, state, next_attempt_at);
+ CREATE INDEX IF NOT EXISTS chronicle_page_state_page_idx ON chronicle_page_state (page_id);
+ CREATE TABLE IF NOT EXISTS chronicle_judge_reservations (
+ id BIGSERIAL PRIMARY KEY,
+ reserved_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ source_id TEXT NOT NULL,
+ page_id INTEGER NOT NULL,
+ content_hash TEXT NOT NULL
+ );
+ CREATE INDEX IF NOT EXISTS chronicle_judge_reservations_at_idx ON chronicle_judge_reservations (reserved_at);
+ DO $rls$ BEGIN
+ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname=current_user AND rolbypassrls) THEN
+ ALTER TABLE chronicle_page_state ENABLE ROW LEVEL SECURITY;
+ ALTER TABLE chronicle_judge_reservations ENABLE ROW LEVEL SECURITY;
+ END IF;
+ END $rls$;
+ `,
+ };