Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: calibration skip without a schema change; goldens for slug_path_mismatch and the grade window; drift test slugs without hyphen runs
garrytane9adc5e062cb
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex ee775127de..0d105c7d18 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1112,7 +1112,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: 'TBD', text: 'With the System One triage slot in shadow mode (or on without a calibration), Dream now asks the decide provider only about transcripts the LLM triage judged in that pass, not about every transcript whose verdict was already cached, so a shadow brain stops paying the provider for its whole backlog on every pass.' },{ since: 'TBD', id: 'repair_provider_refusal_memo', text: 'Fence and content repair now treat a provider error that refuses the request\'s own input (a content-policy block, a prompt block, a context-length overflow) as `llm_refused`: the attempt memo records it and the same bytes are not sent again until the page, the model or the prompt changes. Timeouts, rate limits and server errors stay `llm_unavailable` and are retried on the next run.' },{ since: 'TBD', id: 'concepts_hold_before_spend', text: '`synthesize_concepts` now checks an existing concept page before the model call: a page whose fences it cannot republish losslessly (`concept_preservation_hold`) or whose body is stored in segments (`page_body_segmented`) is listed under `publication_held` with no model spend, every cycle, and a segmented concept no longer stops the phase. A concept\'s failed-attempt count is cleared only after its narrative is published.' },- { since: 'TBD', id: 'calibration_profile_unchanged_skip', text: '`calibration_profile` makes no model call and writes no new profile row when the holder\'s resolved count, Brier score, accuracy, partial rate, model and prompt version all equal the latest stored profile (`skipped: unchanged_scorecard`). Profiles written before this release have no stored prompt version, so the first pass after upgrading regenerates once.' },+ { since: 'TBD', id: 'calibration_profile_unchanged_skip', text: '`calibration_profile` makes no model call and writes no new profile row when the holder\'s resolved count, Brier score, accuracy, partial rate and model all equal the latest stored profile (`skipped: unchanged_scorecard`); a new profile prompt takes effect at the next scorecard change.' },{ since: 'TBD', id: 'grade_takes_window', text: '`grade_takes` now reads unresolved takes oldest-first, leaves takes too recent to grade (or with no date) out of its 50-take window, and puts takes with no verdict for the current prompt and judge ahead of graded ones, so with auto-resolve off older takes beyond the first 50 are graded on later passes. Its `too_recent` count now covers only takes whose date it could not read in SQL.' },];diff --git a/src/core/cycle/calibration-profile.ts b/src/core/cycle/calibration-profile.tsindex 2dc9927883..7c2c69dc68 100644--- a/src/core/cycle/calibration-profile.ts+++ b/src/core/cycle/calibration-profile.ts@@ -289,20 +289,21 @@ class CalibrationProfilePhase extends BaseCyclePhase {};}- // The profile is a function of the scorecard, the model and the prompt: when- // none changed since the latest stored profile, there is nothing to buy.- // REAL columns are compared against the scorecard rounded the same way.+ // The profile is a function of the scorecard and the model: when neither+ // changed since the latest stored profile, there is nothing to buy (a new+ // prompt takes effect at the next scorecard change). REAL columns are+ // compared against the scorecard rounded the same way.const sourceId = scope.sourceId ?? 'default';const [latest] = await engine.executeRaw<{ unchanged: boolean }>(`SELECT COALESCE(total_resolved = $3 AND brier IS NOT DISTINCT FROM $4::real AND accuracy IS NOT DISTINCT FROM $5::real- AND partial_rate IS NOT DISTINCT FROM $6::real AND model_id = $7 AND prompt_version = $8, false) AS unchanged+ AND partial_rate IS NOT DISTINCT FROM $6::real AND model_id = $7, false) AS unchangedFROM calibration_profiles WHERE source_id = $1 AND holder = $2ORDER BY generated_at DESC, id DESC LIMIT 1`,- [sourceId, holder, scorecard.resolved, scorecard.brier, scorecard.accuracy, scorecard.partial_rate, modelId, promptVersion],+ [sourceId, holder, scorecard.resolved, scorecard.brier, scorecard.accuracy, scorecard.partial_rate, modelId],);if (latest?.unchanged) {return {- summary: `calibration_profile: holder=${holder} unchanged since the latest profile (${scorecard.resolved} resolved, same scorecard, model and prompt); no model call`,+ summary: `calibration_profile: holder=${holder} unchanged since the latest profile (${scorecard.resolved} resolved, same scorecard and model); no model call`,details: { ...result, skipped: 'unchanged_scorecard' },status: 'ok',};@@ -404,12 +405,12 @@ class CalibrationProfilePhase extends BaseCyclePhase {total_resolved, brier, accuracy, partial_rate, grade_completion,domain_scorecards, pattern_statements,voice_gate_passed, voice_gate_attempts,- active_bias_tags, model_id, cost_usd, judge_model_agreement, prompt_version+ active_bias_tags, model_id, cost_usd, judge_model_agreement) VALUES ($1, $2, now(), false,$3, $4, $5, $6, $7,$8::text::jsonb, $9::text[],$10, $11,- $12::text[], $13, NULL, NULL, $14)`,+ $12::text[], $13, NULL, NULL)`,[sourceId,holder,@@ -427,7 +428,6 @@ class CalibrationProfilePhase extends BaseCyclePhase {result.voice_gate_attempts,result.active_bias_tags,modelId,- promptVersion,],);result.profile_written = true;diff --git a/src/core/cycle/grade-takes.ts b/src/core/cycle/grade-takes.tsindex b80227005f..443ca746c1 100644--- a/src/core/cycle/grade-takes.ts+++ b/src/core/cycle/grade-takes.ts@@ -50,6 +50,7 @@ import { managedPersistenceEnabled } from '../persistence/ownership.ts';import { parseTakesFence } from '../takes-fence.ts';import { submitPageMutation } from '../persistence/page-mutations.ts';import { maintenanceTransaction } from '../persistence/attribution.ts';+import { utcDate } from './cycle-date.ts';/*** Bump when the judge prompt or the JSON output shape changes. Old verdicts@@ -500,7 +501,7 @@ function listGradeWindow(engine: BrainEngine, opts: { minAgeMonths: number; promconst cutoff = new Date();cutoff.setMonth(cutoff.getMonth() - opts.minAgeMonths);return engine.listTakes({- resolved: false, active: true, sortBy: 'since_date', oldestFirst: true, sinceOnOrBefore: cutoff.toISOString().slice(0, 10),+ resolved: false, active: true, sortBy: 'since_date', oldestFirst: true, sinceOnOrBefore: utcDate(cutoff),ungradedFirst: { promptVersion: opts.promptVersion, judgeModelId: opts.judgeModelId }, limit: opts.limit,});}diff --git a/src/core/schema-migrations/latest.generated.ts b/src/core/schema-migrations/latest.generated.tsindex d776960602..1f7aa9e1ba 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 = 265;+export const LATEST_SCHEMA_VERSION = 264;diff --git a/src/core/schema-migrations/registry.generated.ts b/src/core/schema-migrations/registry.generated.tsindex f4bb49881a..87001c9313 100644--- a/src/core/schema-migrations/registry.generated.ts+++ b/src/core/schema-migrations/registry.generated.ts@@ -265,7 +265,6 @@ import { v261 } from './v261-persistence-request-transient-retries.ts';import { v262 } from './v262-commit-notifier.ts';import { v263 } from './v263-try-jsonb-function.ts';import { v264 } from './v264-set-based-fact-insert-guards.ts';-import { v265 } from './v265-calibration-profile-prompt-version.ts';// Array order is historical (see HISTORICAL_ARRAY_ORDER in the generator); the// runner sorts by version before applying.@@ -529,5 +528,4 @@ export const MIGRATIONS: Migration[] = [v262,v263,v264,- v265,];diff --git a/src/core/schema-migrations/v265-calibration-profile-prompt-version.ts b/src/core/schema-migrations/v265-calibration-profile-prompt-version.tsdeleted file mode 100644index 774ccfe4da..0000000000--- a/src/core/schema-migrations/v265-calibration-profile-prompt-version.ts+++ /dev/null@@ -1,19 +0,0 @@-import type { Migration } from './types.ts';--export const v265: Migration = {- // GBRA-177: the pattern-statement prompt version a calibration profile was- // generated with. calibration_profile skips the paid generate+judge calls- // when the holder's resolved count, Brier, accuracy, partial rate, model and- // this prompt version equal the latest stored profile's. Rows written before- // this column read NULL, which never matches, so the first pass after the- // upgrade regenerates once. Nullable, no backfill, no index- // (bootstrap-coverage: column-only). Fresh installs get it from this- // migration too (not src/schema.sql), so fresh and upgraded brains share- // calibration_profiles column ordinals.- version: 265,- name: 'calibration_profile_prompt_version',- idempotent: true,- sql: `- ALTER TABLE calibration_profiles ADD COLUMN IF NOT EXISTS prompt_version TEXT;- `,-};diff --git a/test/e2e/calibration-profile-write.test.ts b/test/e2e/calibration-profile-write.test.tsindex 2a55b4c032..b1e9ef20c8 100644--- a/test/e2e/calibration-profile-write.test.ts+++ b/test/e2e/calibration-profile-write.test.ts@@ -70,7 +70,7 @@ async function seedResolvedTakes(engine: BrainEngine, slug: string): Promise<voi}}-async function runPhase(engine: BrainEngine, extra: { model?: string; promptVersion?: string } = {}) {+async function runPhase(engine: BrainEngine, extra: { model?: string } = {}) {return runPhaseCalibrationProfile(buildCtx(engine), {holder: HOLDER,patternsGenerator,@@ -82,9 +82,8 @@ async function runPhase(engine: BrainEngine, extra: { model?: string; promptVers/*** GBRA-177: a pass on an unchanged scorecard (resolved count, Brier, accuracy,- * partial rate, model and prompt version all equal the latest stored- * profile's) makes no model call and writes no row; a change to any of them- * regenerates. Runs after the lane's first profile is written.+ * partial rate and model all equal the latest stored profile's) makes no model+ * call and writes no row; a change to any of them regenerates. Runs after the lane's first profile is written.*/async function expectUnchangedSkip(engine: BrainEngine, slug: string): Promise<void> {const rows = async () => Number((await engine.executeRaw<{ n: number }>('SELECT COUNT(*)::int AS n FROM calibration_profiles WHERE holder = $1', [HOLDER]))[0]!.n);@@ -96,14 +95,13 @@ async function expectUnchangedSkip(engine: BrainEngine, slug: string): Promise<vexpect(generatorCalls).toBe(0);expect(await rows()).toBe(before);expect(((await runPhase(engine, { model: 'anthropic:claude-opus-4-7' })).details as Record<string, unknown>).profile_written).toBe(true);- expect(((await runPhase(engine, { model: 'anthropic:claude-opus-4-7', promptVersion: 'v-next' })).details as Record<string, unknown>).profile_written).toBe(true);- expect(((await runPhase(engine, { model: 'anthropic:claude-opus-4-7', promptVersion: 'v-next' })).details as Record<string, unknown>).profile_written).toBe(false);+ expect(((await runPhase(engine, { model: 'anthropic:claude-opus-4-7' })).details as Record<string, unknown>).profile_written).toBe(false);const page = await engine.getPage(slug);await engine.addTakesBatch([{ page_id: page!.id, row_num: 6, claim: 'Seed claim 6', kind: 'bet' as const, holder: HOLDER, weight: 0.6 }]);await engine.resolveTake(page!.id, 6, { quality: 'correct', resolvedBy: 'test' });- expect(((await runPhase(engine, { model: 'anthropic:claude-opus-4-7', promptVersion: 'v-next' })).details as Record<string, unknown>).profile_written).toBe(true);- expect(generatorCalls).toBe(3);- expect(await rows()).toBe(before + 3);+ expect(((await runPhase(engine, { model: 'anthropic:claude-opus-4-7' })).details as Record<string, unknown>).profile_written).toBe(true);+ expect(generatorCalls).toBe(2);+ expect(await rows()).toBe(before + 2);}// ─── PGLite lane (always runs) ──────────────────────────────────────diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-default.json b/test/fixtures/goldens/catalog/pglite-engine-init-default.jsonindex 7d9c81b1fd..90cc50ea7a 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-default.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-default.json@@ -1664,8 +1664,7 @@"16 active_bias_tags ARRAY/_text NOT NULL","17 model_id text/text NOT NULL","18 cost_usd numeric/numeric NULL",- "19 judge_model_agreement real/float4 NULL",- "20 prompt_version text/text NULL"+ "19 judge_model_agreement real/float4 NULL"],"flags": "relkind=r rls=false 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.jsonindex bf7690efc5..dd1469c4b1 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json@@ -1664,8 +1664,7 @@"16 active_bias_tags ARRAY/_text NOT NULL","17 model_id text/text NOT NULL","18 cost_usd numeric/numeric NULL",- "19 judge_model_agreement real/float4 NULL",- "20 prompt_version text/text NULL"+ "19 judge_model_agreement real/float4 NULL"],"flags": "relkind=r rls=false 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.jsonindex 1af28b3022..acd10f1d6d 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json@@ -1660,8 +1660,7 @@"16 active_bias_tags ARRAY/_text NOT NULL","17 model_id text/text NOT NULL","18 cost_usd numeric/numeric NULL",- "19 judge_model_agreement real/float4 NULL",- "20 prompt_version text/text NULL"+ "19 judge_model_agreement real/float4 NULL"],"flags": "relkind=r rls=false force_rls=false"},diff --git a/test/fixtures/goldens/doctor/content-pglite-human.json b/test/fixtures/goldens/doctor/content-pglite-human.jsonindex 0cdc73f832..11214fc4be 100644--- a/test/fixtures/goldens/doctor/content-pglite-human.json+++ b/test/fixtures/goldens/doctor/content-pglite-human.json@@ -213,6 +213,7 @@" [OK] extraction_input_truncated: Every page extraction read all of its input (no head-only, tail-window or size-skip receipts)."," [OK] ghost_pages: No live page is missing its canonical file (5 page(s) inspected)."," [OK] origin_twins: pages_live_origin_key is present: no two live pages can record one file.",+ " [OK] slug_path_mismatch: Every live page's slug is the one its recorded file path derives (0 candidate(s) inspected)."," [OK] rename_identity_downgrades: No rename that lost its page identity is waiting for a disposition."," [OK] purge_parked_pages: No soft-deleted page is parked by the managed purge."," [INFO] missing_recorded_files: Not applicable: no source is a classic checkout on this host (managed sources are checked by ghost_pages).",diff --git a/test/fixtures/goldens/doctor/content-pglite-json.json b/test/fixtures/goldens/doctor/content-pglite-json.jsonindex 9d085e328d..97b0779ad3 100644--- a/test/fixtures/goldens/doctor/content-pglite-json.json+++ b/test/fixtures/goldens/doctor/content-pglite-json.json@@ -3197,6 +3197,29 @@"name": "origin_twins","status": "ok"},+ {+ "category": "brain",+ "details": {+ "count": 0,+ "docs": "docs/guides/repair.md#slug-path-mismatch",+ "file_limit": 200,+ "files": {+ "file_missing": 0,+ "no_checkout": 0,+ "not_read": 0,+ "stamped": 0,+ "unstamped": 0+ },+ "inspected": 0,+ "samples": [],+ "scan_limit": 20000,+ "truncated": false+ },+ "elapsed_ms": "<volatile>",+ "message": "Every live page's slug is the one its recorded file path derives (0 candidate(s) inspected).",+ "name": "slug_path_mismatch",+ "status": "ok"+ },{"category": "brain","details": {diff --git a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json b/test/fixtures/goldens/doctor/hot-checks-pglite-json.jsonindex 2efc00fe88..ee38d7e8af 100644--- a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json+++ b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json@@ -3405,6 +3405,29 @@"name": "origin_twins","status": "ok"},+ {+ "category": "brain",+ "details": {+ "count": 0,+ "docs": "docs/guides/repair.md#slug-path-mismatch",+ "file_limit": 200,+ "files": {+ "file_missing": 0,+ "no_checkout": 0,+ "not_read": 0,+ "stamped": 0,+ "unstamped": 0+ },+ "inspected": 0,+ "samples": [],+ "scan_limit": 20000,+ "truncated": false+ },+ "elapsed_ms": "<volatile>",+ "message": "Every live page's slug is the one its recorded file path derives (0 candidate(s) inspected).",+ "name": "slug_path_mismatch",+ "status": "ok"+ },{"category": "brain","details": {@@ -7945,6 +7968,29 @@"name": "origin_twins","status": "ok"},+ {+ "category": "brain",+ "details": {+ "count": 0,+ "docs": "docs/guides/repair.md#slug-path-mismatch",+ "file_limit": 200,+ "files": {+ "file_missing": 0,+ "no_checkout": 0,+ "not_read": 0,+ "stamped": 0,+ "unstamped": 0+ },+ "inspected": 0,+ "samples": [],+ "scan_limit": 20000,+ "truncated": false+ },+ "elapsed_ms": "<volatile>",+ "message": "Every live page's slug is the one its recorded file path derives (0 candidate(s) inspected).",+ "name": "slug_path_mismatch",+ "status": "ok"+ },{"category": "brain","details": {diff --git a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json b/test/fixtures/goldens/doctor/hot-checks-postgres-json.jsonindex e3477807f1..2f161b3316 100644--- a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json+++ b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json@@ -3408,6 +3408,29 @@"name": "origin_twins","status": "ok"},+ {+ "category": "brain",+ "details": {+ "count": 0,+ "docs": "docs/guides/repair.md#slug-path-mismatch",+ "file_limit": 200,+ "files": {+ "file_missing": 0,+ "no_checkout": 0,+ "not_read": 0,+ "stamped": 0,+ "unstamped": 0+ },+ "inspected": 0,+ "samples": [],+ "scan_limit": 20000,+ "truncated": false+ },+ "elapsed_ms": "<volatile>",+ "message": "Every live page's slug is the one its recorded file path derives (0 candidate(s) inspected).",+ "name": "slug_path_mismatch",+ "status": "ok"+ },{"category": "brain","details": {@@ -7949,6 +7972,29 @@"name": "origin_twins","status": "ok"},+ {+ "category": "brain",+ "details": {+ "count": 0,+ "docs": "docs/guides/repair.md#slug-path-mismatch",+ "file_limit": 200,+ "files": {+ "file_missing": 0,+ "no_checkout": 0,+ "not_read": 0,+ "stamped": 0,+ "unstamped": 0+ },+ "inspected": 0,+ "samples": [],+ "scan_limit": 20000,+ "truncated": false+ },+ "elapsed_ms": "<volatile>",+ "message": "Every live page's slug is the one its recorded file path derives (0 candidate(s) inspected).",+ "name": "slug_path_mismatch",+ "status": "ok"+ },{"category": "brain","details": {diff --git a/test/fixtures/goldens/doctor/json-postgres-fresh.json b/test/fixtures/goldens/doctor/json-postgres-fresh.jsonindex 2b47098523..be281d5300 100644--- a/test/fixtures/goldens/doctor/json-postgres-fresh.json+++ b/test/fixtures/goldens/doctor/json-postgres-fresh.json@@ -2960,6 +2960,29 @@"name": "origin_twins","status": "ok"},+ {+ "category": "brain",+ "details": {+ "count": 0,+ "docs": "docs/guides/repair.md#slug-path-mismatch",+ "file_limit": 200,+ "files": {+ "file_missing": 0,+ "no_checkout": 0,+ "not_read": 0,+ "stamped": 0,+ "unstamped": 0+ },+ "inspected": 0,+ "samples": [],+ "scan_limit": 20000,+ "truncated": false+ },+ "elapsed_ms": "<volatile>",+ "message": "Every live page's slug is the one its recorded file path derives (0 candidate(s) inspected).",+ "name": "slug_path_mismatch",+ "status": "ok"+ },{"category": "brain","details": {diff --git a/test/fixtures/goldens/exports/types.json b/test/fixtures/goldens/exports/types.jsonindex e4af923d66..5cc15846aa 100644--- a/test/fixtures/goldens/exports/types.json+++ b/test/fixtures/goldens/exports/types.json@@ -4047,15 +4047,18 @@"limit?: number | undefined","minTrust?: \"user_confirmed\" | \"operator_curated\" | \"tool_observed\" | \"agent_written\" | \"unknown\" | \"external_untrusted\" | undefined","offset?: number | undefined",+ "oldestFirst?: boolean | undefined","page_id?: number | undefined","page_slug?: string | undefined","requireSafeChunks?: boolean | undefined","resolved?: boolean | undefined",+ "sinceOnOrBefore?: string | undefined","sortBy?: \"weight\" | \"since_date\" | \"created_at\" | undefined","sourceId?: string | undefined","sourceIds?: string[] | undefined","suppressFlagged?: boolean | undefined",- "takesHoldersAllowList?: string[] | undefined"+ "takesHoldersAllowList?: string[] | undefined",+ "ungradedFirst?: { promptVersion: string; judgeModelId: string; } | undefined"],"name": "TakesListOpts"},diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.jsonindex 8ba1fbe26b..8ba43d1064 100644--- a/test/fixtures/goldens/migrations/records.json+++ b/test/fixtures/goldens/migrations/records.json@@ -1,6 +1,6 @@{"golden": {- "count": 260,+ "count": 259,"gaps": [17,18,@@ -72,7 +72,7 @@"tableRows": "906d2413b13d76a06d5910885e47ed5c544be4ff3a2266e83146715721b24270","verifyProjectionStatistics": "0d231b04ecfbc5a4109d6fca9567bf4e8c9e9db6c3fbbb35212e026579ed6f67"},- "latest": 265,+ "latest": 264,"records": [{"handler": {@@ -4201,19 +4201,6 @@"transaction": "absent","verify": "absent","version": 264- },- {- "handler": "absent",- "idempotent": true,- "name": "calibration_profile_prompt_version",- "sql": {- "length": 86,- "sha256": "07db6f6a6c3a66e0024a81c7ae7e7c1b41942e91c7a6202d64ddbee7997b290b"- },- "sqlFor": "absent",- "transaction": "absent",- "verify": "absent",- "version": 265}],"versions": [@@ -4475,8 +4462,7 @@261,262,263,- 264,- 265+ 264]},"normalizer": "migrations-record-v1"diff --git a/test/fixtures/goldens/sql-text/_driver.json b/test/fixtures/goldens/sql-text/_driver.jsonindex 0f731042e9..87bd63a850 100644--- a/test/fixtures/goldens/sql-text/_driver.json+++ b/test/fixtures/goldens/sql-text/_driver.json@@ -5012,7 +5012,7 @@"listTakes": {"default": [{- "paramCount": 20,+ "paramCount": 25,"unsafeOptions": {"cancelFence": false,"prepare": true,@@ -5023,7 +5023,7 @@],"sourceId": [{- "paramCount": 21,+ "paramCount": 26,"unsafeOptions": {"cancelFence": false,"prepare": true,@@ -5034,7 +5034,7 @@],"sourceIds+excludePrivate": [{- "paramCount": 21,+ "paramCount": 26,"unsafeOptions": {"cancelFence": false,"prepare": true,diff --git a/test/fixtures/goldens/sql-text/takes.json b/test/fixtures/goldens/sql-text/takes.jsonindex 29a71b5626..d8b14f45ae 100644--- a/test/fixtures/goldens/sql-text/takes.json+++ b/test/fixtures/goldens/sql-text/takes.json@@ -217,14 +217,19 @@"null","null","null",+ "null",+ "null",+ "string",+ "boolean","string","string",+ "boolean","string","number","number"],- "sql": "SELECT t.*, p.slug AS page_slug FROM takes t JOIN pages p ON p.id = t.page_id WHERE 1=1 AND ($1::int IS NULL OR t.page_id = $2::int) AND ($3::text IS NULL OR p.slug = $4::text) AND ($5::text IS NULL OR t.holder = $6::text) AND ($7::text IS NULL OR t.kind = $8::text) AND ($9::boolean IS NULL OR t.active = $10::boolean) AND ( $11::boolean IS NULL OR ($12::boolean = true AND t.resolved_at IS NOT NULL) OR ($13::boolean = false AND t.resolved_at IS NULL) ) AND ( $14::text[] IS NULL OR t.holder = ANY($15::text[]) ) ORDER BY CASE WHEN $16 = 'weight' THEN t.weight END DESC NULLS LAST, CASE WHEN $17 = 'since_date' THEN t.since_date END DESC NULLS LAST, CASE WHEN $18 = 'created_at' THEN t.created_at END DESC NULLS LAST LIMIT $19 OFFSET $20",- "textSha256": "974ece0b8fa9166ba0b1462f293fc6e19c1952e1fccac100b957afd1d2ceccbb"+ "sql": "SELECT t.*, p.slug AS page_slug FROM takes t JOIN pages p ON p.id = t.page_id WHERE 1=1 AND ($1::int IS NULL OR t.page_id = $2::int) AND ($3::text IS NULL OR p.slug = $4::text) AND ($5::text IS NULL OR t.holder = $6::text) AND ($7::text IS NULL OR t.kind = $8::text) AND ($9::boolean IS NULL OR t.active = $10::boolean) AND ( $11::boolean IS NULL OR ($12::boolean = true AND t.resolved_at IS NOT NULL) OR ($13::boolean = false AND t.resolved_at IS NULL) ) AND ( $14::text[] IS NULL OR t.holder = ANY($15::text[]) ) AND ($16::text IS NULL OR (t.since_date IS NOT NULL AND NOT ( t.since_date ~ '^[0-9]{4}-[0-9]{2}(-[0-9]{2})?$' AND (CASE WHEN length(t.since_date) = 7 THEN t.since_date || '-15' ELSE t.since_date END) > $17::text))) ORDER BY CASE WHEN $18 = 'since_date' AND $19::boolean THEN t.since_date END ASC NULLS LAST, CASE WHEN $20 = 'weight' THEN t.weight END DESC NULLS LAST, CASE WHEN $21 = 'since_date' AND NOT $22::boolean THEN t.since_date END DESC NULLS LAST, CASE WHEN $23 = 'created_at' THEN t.created_at END DESC NULLS LAST LIMIT $24 OFFSET $25",+ "textSha256": "7606ca39ead96bfabe93581194e46d50f8f3ad120f5c0e718d9ca7fddd516e8e"}],"sourceId": [@@ -246,15 +251,20 @@"null","null","null",+ "null",+ "null","string","string",+ "boolean","string","string",+ "boolean",+ "string","number","number"],- "sql": "SELECT t.*, p.slug AS page_slug FROM takes t JOIN pages p ON p.id = t.page_id WHERE 1=1 AND ($1::int IS NULL OR t.page_id = $2::int) AND ($3::text IS NULL OR p.slug = $4::text) AND ($5::text IS NULL OR t.holder = $6::text) AND ($7::text IS NULL OR t.kind = $8::text) AND ($9::boolean IS NULL OR t.active = $10::boolean) AND ( $11::boolean IS NULL OR ($12::boolean = true AND t.resolved_at IS NOT NULL) OR ($13::boolean = false AND t.resolved_at IS NULL) ) AND ( $14::text[] IS NULL OR t.holder = ANY($15::text[]) ) AND p.source_id = $16 ORDER BY CASE WHEN $17 = 'weight' THEN t.weight END DESC NULLS LAST, CASE WHEN $18 = 'since_date' THEN t.since_date END DESC NULLS LAST, CASE WHEN $19 = 'created_at' THEN t.created_at END DESC NULLS LAST LIMIT $20 OFFSET $21",- "textSha256": "adad16434be36a3105641b3e645cc6cfb0cd0d90b1cb9b0dfc5eb861ac5ff0b1"+ "sql": "SELECT t.*, p.slug AS page_slug FROM takes t JOIN pages p ON p.id = t.page_id WHERE 1=1 AND ($1::int IS NULL OR t.page_id = $2::int) AND ($3::text IS NULL OR p.slug = $4::text) AND ($5::text IS NULL OR t.holder = $6::text) AND ($7::text IS NULL OR t.kind = $8::text) AND ($9::boolean IS NULL OR t.active = $10::boolean) AND ( $11::boolean IS NULL OR ($12::boolean = true AND t.resolved_at IS NOT NULL) OR ($13::boolean = false AND t.resolved_at IS NULL) ) AND ( $14::text[] IS NULL OR t.holder = ANY($15::text[]) ) AND ($16::text IS NULL OR (t.since_date IS NOT NULL AND NOT ( t.since_date ~ '^[0-9]{4}-[0-9]{2}(-[0-9]{2})?$' AND (CASE WHEN length(t.since_date) = 7 THEN t.since_date || '-15' ELSE t.since_date END) > $17::text))) AND p.source_id = $18 ORDER BY CASE WHEN $19 = 'since_date' AND $20::boolean THEN t.since_date END ASC NULLS LAST, CASE WHEN $21 = 'weight' THEN t.weight END DESC NULLS LAST, CASE WHEN $22 = 'since_date' AND NOT $23::boolean THEN t.since_date END DESC NULLS LAST, CASE WHEN $24 = 'created_at' THEN t.created_at END DESC NULLS LAST LIMIT $25 OFFSET $26",+ "textSha256": "311b98cfec565a9f8b6ddbc8ede6a66c2e52053531c075f9bfec72cb852a93bb"}],"sourceIds+excludePrivate": [@@ -276,15 +286,20 @@"boolean","null","null",+ "null",+ "null","array<string>","string",+ "boolean",+ "string","string",+ "boolean","string","number","number"],- "sql": "SELECT t.*, p.slug AS page_slug FROM takes t JOIN pages p ON p.id = t.page_id WHERE 1=1 AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(lower(btrim(p.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(p.frontmatter->>'confidentiality')) IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = p.frontmatter->>'source_slug' AND derived_origin.frontmatter->>'visibility' = 'private') WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = derived_input.frontmatter->>'source_slug' AND derived_input_origin.frontmatter->>'visibility' = 'private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(lower(btrim(chronicle_origin.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(chronicle_origin.frontmatter->>'confidentiality')) IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) AND ($1::int IS NULL OR t.page_id = $2::int) AND ($3::text IS NULL OR p.slug = $4::text) AND ($5::text IS NULL OR t.holder = $6::text) AND ($7::text IS NULL OR t.kind = $8::text) AND ($9::boolean IS NULL OR t.active = $10::boolean) AND ( $11::boolean IS NULL OR ($12::boolean = true AND t.resolved_at IS NOT NULL) OR ($13::boolean = false AND t.resolved_at IS NULL) ) AND ( $14::text[] IS NULL OR t.holder = ANY($15::text[]) ) AND p.source_id = ANY($16::text[]) ORDER BY CASE WHEN $17 = 'weight' THEN t.weight END DESC NULLS LAST, CASE WHEN $18 = 'since_date' THEN t.since_date END DESC NULLS LAST, CASE WHEN $19 = 'created_at' THEN t.created_at END DESC NULLS LAST LIMIT $20 OFFSET $21",- "textSha256": "32b0eaf4851cac51606e35ce0fd714d78d779fcec5fe63ed42a4efed9f3a675d"+ "sql": "SELECT t.*, p.slug AS page_slug FROM takes t JOIN pages p ON p.id = t.page_id WHERE 1=1 AND ((COALESCE(p.frontmatter->>'visibility', CASE WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(p.frontmatter ? 'pinned_question', false) AND NOT (p.frontmatter->>'visibility' IS NULL AND (COALESCE(lower(btrim(p.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(p.frontmatter->>'confidentiality')) IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN p.type = 'atom' THEN EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = p.source_id AND derived_origin.slug = p.frontmatter->>'source_slug' AND derived_origin.frontmatter->>'visibility' = 'private') WHEN (p.type IN ('atom', 'question') OR (p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = p.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = derived_input.frontmatter->>'source_slug' AND derived_input_origin.frontmatter->>'visibility' = 'private'))) WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = p.source_id AND chronicle_origin.slug = p.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(lower(btrim(chronicle_origin.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(chronicle_origin.frontmatter->>'confidentiality')) IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = p.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(p.frontmatter->'derived_from') = 'array' THEN p.frontmatter->'derived_from' ELSE jsonb_build_array(p.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) AND ($1::int IS NULL OR t.page_id = $2::int) AND ($3::text IS NULL OR p.slug = $4::text) AND ($5::text IS NULL OR t.holder = $6::text) AND ($7::text IS NULL OR t.kind = $8::text) AND ($9::boolean IS NULL OR t.active = $10::boolean) AND ( $11::boolean IS NULL OR ($12::boolean = true AND t.resolved_at IS NOT NULL) OR ($13::boolean = false AND t.resolved_at IS NULL) ) AND ( $14::text[] IS NULL OR t.holder = ANY($15::text[]) ) AND ($16::text IS NULL OR (t.since_date IS NOT NULL AND NOT ( t.since_date ~ '^[0-9]{4}-[0-9]{2}(-[0-9]{2})?$' AND (CASE WHEN length(t.since_date) = 7 THEN t.since_date || '-15' ELSE t.since_date END) > $17::text))) AND p.source_id = ANY($18::text[]) ORDER BY CASE WHEN $19 = 'since_date' AND $20::boolean THEN t.since_date END ASC NULLS LAST, CASE WHEN $21 = 'weight' THEN t.weight END DESC NULLS LAST, CASE WHEN $22 = 'since_date' AND NOT $23::boolean THEN t.since_date END DESC NULLS LAST, CASE WHEN $24 = 'created_at' THEN t.created_at END DESC NULLS LAST LIMIT $25 OFFSET $26",+ "textSha256": "c449cc1e5f55d98db9301d62239a3ddf7fe7049bd20b0ce231ea15731553cd09"}]},diff --git a/test/physical-root-birth-tolerance-6501.test.ts b/test/physical-root-birth-tolerance-6501.test.tsindex 65ae4eb7b3..1d65c5d107 100644--- a/test/physical-root-birth-tolerance-6501.test.ts+++ b/test/physical-root-birth-tolerance-6501.test.ts@@ -162,7 +162,7 @@ for (const kind of testBackends()) describe(`physical root birth drift (${kind})expect(await put(f, 'notes/before-drift')).toBe('committed');for (const delta of [-50n, 47n, -1000n, 1000n]) {const stamped = drift(f, delta);- expect(await put(f, `notes/drift-${delta}`)).toBe('committed');+ expect(await put(f, `notes/drift-${delta < 0n ? `minus${-delta}` : delta}`)).toBe('committed');expect(readJson(f.marker)).toEqual({ ...stamped, birth: (BigInt(stamped.birth) + delta).toString() });writeJson(f.marker, stamped);}@@ -173,7 +173,7 @@ for (const kind of testBackends()) describe(`physical root birth drift (${kind})const binding = (await getWorktreeBinding(engine, f.source))!;for (const delta of [-1001n, 1001n, -5_000_000_000n]) {const stamped = drift(f, delta);- expect(await put(f, `notes/drift-${delta}`)).toBe('recovery_required/relocated-root-exit');+ expect(await put(f, `notes/drift-${delta < 0n ? `minus${-delta}` : delta}`)).toBe('recovery_required/relocated-root-exit');const refused = await refusal(binding);expect(refused).toMatchObject({ code: 'recovery_required', detail: 'physical_root_directory_changed' });expect(refused!.suggestion).toContain(`gbrain sources writer transfer prepare ${f.source} --self-transfer --confirm-relocated-root`);