Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge remote-tracking branch 'origin/master' into capy/fix-6543-doctor

garrytan25a7d6bff2be
diff --cc src/commands/doctor/checks/sync-failures.ts
index 3d0f75ee1b,6fcb1059d8..4ee1496a1f
--- a/src/commands/doctor/checks/sync-failures.ts
+++ b/src/commands/doctor/checks/sync-failures.ts
@@@ -4,10 -4,13 +4,14 @@@ import { loadSyncFailures, unacknowledg
import { formatManagedSyncFailure, managedSyncRetryCommand, readManagedSyncFailures } from '../../../core/persistence/sync-failures.ts';
import { resolveHoursEnv } from '../../../core/env-number.ts';
import { makeRemediationStep } from '../../../core/remediation-step.ts';
- import { classifyManagedSyncOrphans } from '../../../core/persistence/managed-sync-orphans.ts';
+ import { classifyManagedSyncOrphans, type ManagedSyncOrphan } from '../../../core/persistence/managed-sync-orphans.ts';
import { readManagedMode } from '../../../core/persistence/ownership.ts';
+import { legacyLedgerNote } from '../../../core/persistence/legacy-sync-failures.ts';
+ /** #6518 [R18 vi]: the fast check cannot verify a mirror row; a warning there is uncertainty, never recovery. */
+ const MIRROR_UNVERIFIED = (count: number) => `${count} mirrored managed sync failure(s) could not be verified without a database connection: `
+ + 'a better fast score means less certainty, not that sync recovered. Run gbrain doctor --only sync_failures with the brain reachable.';
+
export async function checkSyncFailures(engine: BrainEngine | null, opts: { sourceIds?: string[]; remote?: boolean } = {}): Promise<Check | null> {
// #5452: sync refuses an archived source, so its failures cannot be cleared and are not a live health signal.
const archived = new Set(engine ? (await engine.executeRaw<{ id: string }>('SELECT id FROM sources WHERE archived = true')).map(row => row.id) : []);
@@@ -39,14 -69,10 +70,11 @@@
const orphanKeys = new Set(orphans.map(orphan => orphan.cursor_key));
const resumable = managed.filter(row => !orphanKeys.has(row.cursor_key));
const retries = [...new Set(resumable.map(row => managedSyncRetryCommand(row)))];
- const orphanNote = orphans.length ? ` ${orphans.length} of these (${orphans.map(orphan => `${orphan.source_id}:${orphan.cursor_key.slice(0, 12)} ${orphan.reason}`).join(', ')}) cannot be resumed or cleared by any sync: `
- + `preview gbrain repair managed-sync-orphans${new Set(orphans.map(orphan => orphan.source_id)).size === 1 ? ` --source ${orphans[0]!.source_id}` : ''} and apply with the hash it prints (docs/guides/repair.md#managed-sync-orphans).` : '';
const recovery = requiresManagedRetry
- ? `${resumable.length || !orphans.length ? `Fix the cause, then run ${retries.length ? retries.join(' ; ') : 'gbrain sync --no-pull --retry-failed with the same source and options'}. Completed full runs do not resolve a different unfinished cursor.` : ''}${orphanNote}`.trim()
- : "Fix the file(s) and re-run 'gbrain sync', or use 'gbrain sync --skip-failed' to acknowledge legacy file failures.";
+ ? `${resumable.length || !orphans.length ? `Fix the cause, then run ${retries.length ? retries.join(' ; ') : 'gbrain sync --no-pull --retry-failed with the same source and options'}. Completed full runs do not resolve a different unfinished cursor.` : ''}${orphanNote}${unreadNote}`.trim()
+ : `Fix the file(s) and re-run 'gbrain sync', or use 'gbrain sync --skip-failed' to acknowledge legacy file failures.${orphanNote}${unreadNote}`;
- return { name: 'sync_failures', status: severity.status, message: `${summary} ${details.join('; ')} ${recovery}`,
+ const legacyNote = managedBrain ? legacyLedgerNote(unresolvedLegacy) : '';
+ return { name: 'sync_failures', status: severity.status, message: `${summary} ${details.join('; ')} ${recovery}${legacyNote}`,
remediation, remediation_status: remediation ? 'remediable' : 'blocked', ...(orphans.length ? { details: { orphans } } : {}),
- ...(engine ? {} : { message: `${summary} Durable sync state is unavailable without a database connection; the local ledger is only a compatibility mirror.` }) };
+ ...(engine ? {} : { message: `${summary} Durable sync state is unavailable without a database connection; the local ledger is only a compatibility mirror.${mirrorNote}` }) };
}
diff --cc src/core/behavior-change-notice.ts
index 13e9ba1328,dc97e9d7c4..479ff0556f
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@@ -493,17 -493,20 +493,31 @@@ export const BEHAVIOR_CHANGES: Readonly
// Low-hanging-fruit wave (GBRA-81 items 2 and 3).
{ since: '0.60.188.0', text: 'Lean `search` and `query` rows (remote callers) now carry `id`, the `fetch` key, only when the connection can call `fetch` at that moment: a `full` surface, a stdio session `request_tools` widened, or an HTTP client whose surface and scopes include it. On `starter` and `verbs` connections, `fetch` was never callable, so the row\'s `slug` and `source_id` identify the page; `fields: "full"` returns every field, `id` included, and the `mcp.result_rows: full` host setting does so for every remote caller. Lean-row `score` now prints 4 significant digits. The local CLI and gbrain\'s thin client keep full rows, unchanged. `fetch` called without an id now says to re-run `search` once `fetch` is callable, or to pass the row\'s slug.' },
{ since: '0.60.188.0', text: 'On stdio MCP and the CLI, the `degraded_recall` notice now shows on every call a transient degradation affects (`rerank_failed`, `embed_timeout`, a failed keyword or title arm, and every other per-call stage); it used to show once per session, so a rerank failure after an earlier embedding timeout returned fused-order results with no notice. A keyless brain whose only degradation is `embed_unavailable` still shows it once per session. HTTP is unchanged: every affected call. `_meta.retrieval.degraded` still records every call\'s stages.' },
+ // wave 16 (GBRA-79), v0.60.189.0.
+ { since: '0.60.189.0', text: 'A page purge (`gbrain delete <slug> --purge`) now searches the source\'s write journal for the page\'s claims at preparation, in bounded keyset chunks under the preparation budget (`persistence.maintenance_preparation_ms`), and its publication transaction only re-checks the requests admitted or settled since; the receipt reports `journal_sweep` (`scanned`, `ceiling`, `tail`, `pending_rechecked`, `complete`), and `complete: false` means a cap was hit and some requests were not tested. A purge whose remaining in-transaction lookup times out now ends `failed` with `purge_lookup_timeout` (nothing removed, tombstoned or redacted; later writes to the source move again) instead of being requeued as `database_contention` without bound, and a sweep that outruns its budget twice ends `preparation_stalled`; either failure needs a new request_id. A schema migration adds the request-table slug index (`gbrain repair request-indexes` rebuilds it).' },
+ { since: '0.60.189.0', text: 'A soft delete (`delete_page`, `gbrain delete <slug>`) of a page whose canonical file another live page of the source records now keeps the file and publishes database-only (receipt `write_through.skipped: shared_origin`, with a warning): the selected database page is hidden; the file and the surviving page remain, and nothing is erased. It used to refuse `source_changed` (the shared file renders the other page), leaving no supported exit for a duplicate-origin twin. Managed sync\'s discovery census and its origin guards now apply one rule: a live page wins the origin over tombstones, several live pages refuse `page_identity_changed` naming that soft delete, a single tombstone may still be reused and several tombstones still refuse. The receipt names the surviving slug to the trusted local owner or to a remote writer whose grant and visibility cover it, never otherwise. A purge of a shared-origin page refuses and names the soft delete. The kept file is imported into the surviving page by the next sync that imports it (`gbrain sync --source <id> --no-pull --full` does it now); edit the file first if it holds the deleted page\'s text.' },
+ // wave 16 (GBRA-79), v0.60.189.0 (managed sync bookkeeping).
+ { since: '0.60.189.0', text: 'A managed sync checkpoint whose cursor another run of the same source replaced (a `--retry-failed` rediscovery or a newer sync) now refuses `sync_cursor_replaced` (receipt state `conflict`) instead of `revision_conflict`, the run that awaited it records no managed-sync failure for it and goes on with the winning cursor, and `--retry-failed` no longer treats the superseded checkpoint as a page fault; `gbrain doctor` stops reporting such a checkpoint as an unresolved sync failure. A same-run index lag still reports `revision_conflict` and a missing manifest `storage_error`.' },
+ { since: '0.60.189.0', text: 'A write a database trigger gbrain does not know refuses now carries a closed `reason` in its public failure detail (`attribution_unclassified_table`, `trust_unclassified_table`, `graduation_in_progress`, or `unknown`), its stored message reads `Publication failed (P0001 in <raiser>: <reason>). Inspect owner diagnostics.`, and the engine-graduation fence (SQLSTATE 55000) is recognized as `graduation_in_progress` with a retry-later message instead of an owner-exception `storage_error`. The managed sync failure a run records, the failure ledger, `gbrain doctor` and `gbrain sync status --json` (`last_error.write_error_detail`, `last_error.detail`) now name the raiser, table and reason that only the receipt named before; the trigger\'s message text stays on the brain host (`gbrain write-request <id> --json`).' },
+ { since: '0.60.189.0', text: 'Managed sync bookkeeping recorded under a source incarnation the source no longer has (a source re-pointed at a new checkout, or removed and added again) is now retirable: `gbrain repair managed-sync-orphans --source <id>` lists such cursor and failure rows as `incarnation_retired` and local ledger rows whose durable failure row is gone as `mirror_only`, and a successful sync prunes a source\'s stale mirror rows. `gbrain doctor` names them with the repair even when no current failure is visible; `gbrain doctor --fast` (no database) now reports mirrored managed rows as `warn` "could not be verified" instead of `fail` (a better fast score is less certainty, not recovery; the engine-backed check stays authoritative), while old unmanaged file failures keep their severity. `gbrain sync status` reports only a cursor a current sync can select: an old-incarnation cursor is `cursor: null` with `last_error.code: cursor_incarnation_retired` and the repair preview as `next`, instead of a resumable cursor whose `next` selected nothing.' },
+ // wave 16 (GBRA-79)
+ { since: '0.60.189.0', text: 'On a managed brain, automatic fact extraction (sync import, `put_page`, `extract_facts`, the sweep) now skips a candidate whose exact claim was forgotten in that source and visibility and publishes the other facts of the same entity, counting the skips as `withdrawn_skipped` on the entity and completion write receipts and the extraction result; before, one forgotten claim refused the entity\'s whole group with `fact_withdrawn`. Explicitly remembering the forgotten claim still refuses, and a purge tombstone still refuses the whole write. A claim forgotten after the facts were prepared refuses that entity\'s write with `revision_conflict` and a detail naming the withdrawal, publishing nothing. An extraction keyed by its input alone (no request id) recovers from such a refusal, and from a batch an older release refused for a forgotten claim, on its next run: the retained facts are re-admitted as a follow-up batch with no model call, at most three times per batch, and the refused receipts stay as they were. An extraction admitted under a request id replays its receipt; a new request_id extracts again.' },
+ { since: '0.60.189.0', text: 'Atom extraction (`extract_atoms`, `gbrain dream --drain`) no longer marks an item complete when its text was cut at `cycle.extract_atoms.max_input_chars` (default 50,000 characters). The model reads the head once and its atoms are kept, but no completion stamp is written, no atom from an earlier extraction is retired, the phase result and the drain count the item under `input_truncated` with a stderr line naming the knob, and the item is skipped with no model call until the cap is raised or its content changes; raising the cap makes every such item eligible again on the next run. Before, a cut item was certified complete on its full content and a re-extraction could retire the atoms a larger cap had produced from its tail.' },
+ { since: '0.60.189.0', text: 'With the `claude-cli` provider, a model answer Claude Code reports as "API Error: Claude\'s response exceeded the N output token maximum" is now treated as an answer that stopped at the output cap (`finishReason: length`), not as a provider failure, so the output-cap ladders run as designed: open-loop extraction (`loops_extract`) retries once at 8192 output tokens and fact extraction retries once at twice its output budget. Each retry is one more model call on the same input; every other claude-cli error envelope still fails the call.' },
+ { since: '0.60.189.0', text: 'The same-page rewording measurement (`would_dedup_same_page`, 0.60.177.0) now also runs on a managed brain: automatic fact extraction there counts the rewordings on the entity and completion receipts and the `extract_facts` result and prints the same one stderr line per match. Nothing is dropped; a replay of the same request reports the recorded count without a model call.' },
+ // wave 16 (GBRA-79) G5.1 #6495, v0.60.189.0.
+ { since: '0.60.189.0', text: 'On Postgres, the keyword, keyword-count, keyword-page, title and CJK search statements run under one operator bound, `search.keyword_statement_timeout_ms` (default 8000, range 1000-60000; `gbrain config set`, then restart `gbrain serve` or the workers), instead of a fixed 8 s; a value outside the range is refused and never set from a request. `gbrain doctor` gains `keyword_plan`, a read-only canary that warns when the brain\'s commonest keyword term cannot be counted inside the bound (one term is not workload coverage, and a timed-out count is never "no matches"). A longer bound buys time, not a cheaper statement (#6495 stays open).' },
+ // #6543 fix wave PR 2 (GBRA-84). `since` is the release this PR is slotted for.
- { since: '0.60.189.0', text: 'On a managed brain, `gbrain sync` (one source, `--all`, and a sync handed to `gbrain serve`) now implies `--no-pull` and prints one stderr line naming `gbrain sources refresh <id>` for taking upstream commits, instead of refusing with `writer_coordinator_required` until `--no-pull` was typed. Nothing changes on stdout or in `--json`; `--dry-run` and the library/MCP refusal of an explicit pull are unchanged.' },
- { since: '0.60.189.0', text: 'A managed sync drain whose queued head no consumer can claim now stops within one governor tick with `drain_stalled`, `cause: head_blocked`, when the blocker needs an operator (a refresh fence no refresh process holds: `next.fix` is `gbrain sources refresh <id> --resume`; a running request ahead held by a process that reports `restart_required`: restart it), instead of waiting the 5-10 minute no-progress window. `drain.stall` gains `blocked_by` and `consumer`, the stall line prints `consumer=` and `blocked_by=`, and `claimable here` is read for the head itself (`unknown` when the read fails; it used to print a constant `no`). `gbrain sources writer status` names the blocker of each queued head (`blocked_by`, `claimable_here`) and adds `cancel_command` only when this caller may cancel the blocking request.' },
- { since: '0.60.189.0', text: '`gbrain repair <kind> --apply` no longer stops at the first write that is accepted but still pending publication while a consumer on this host is publishing: it keeps the receipt (the saved position stays before it), admits the remaining items without a per-item publication wait (at most half the principal outstanding-request cap unresolved at once) and settles them against one shared wait (the write wait with nothing publishing). A run that still stops lists the receipts in `pending` and the same command resumes; `--wait 0` still waits for nothing. With no live consumer, or one that reports `restart_required`, the run stops at the first pending write as before and names the owner.' },
- { since: '0.60.189.0', text: '`[persistence] phase=` log lines about one write request now carry `request_id`, `operation`, `source`, `slug`, `principal` and `elapsed_ms`, and their 30-second repeat suppression is per request: two requests failing the same phase log two lines.' },
- { since: '0.60.189.0', text: '`gbrain serve` now logs the behavior changes this brain has not been told about once per process at startup, on stderr. It reads the notice state without marking it delivered, so the CLI, stdio and HTTP notices still show once each.' },
- { since: '0.60.189.0', text: 'Importing an image no longer writes `type` or `title` into its frontmatter (the keys `gbrain repair frontmatter-keys` strips since 0.60.177.0). Doctor `stale_frontmatter_keys` names 0.60.177.0 and, on a brain with several sources, its fix is the all-sources `gbrain repair frontmatter-keys`, with the per-source commands listed.' },
- { since: '0.60.189.0', text: '`gbrain embed --stale --images` and doctor `image_assets` find an image whose recorded path differs from the file on disk only in letter case (an exact match still wins), import it under the real-case path, and refuse a case-fold match that is ambiguous or resolves outside the source root instead of importing or counting it. `image_assets` reports case-only, ambiguous and unrooted counts.' },
- { since: '0.60.189.0', text: 'On a managed brain, a successful `gbrain sync --source <id>` settles legacy rows the pre-managed sync left in `sync-failures.jsonl` one at a time (the imported commit holds the file and a live page claims it, or the file is gone and no page claims it); rows on an unknown commit, sentinel rows, held files and files it did not index stay. Doctor `sync_failures` says how many unresolved rows are legacy and which command settles them, and `gbrain sync --retry-failed` names them instead of saying the ledger is empty.' },
- { since: '0.60.189.0', text: 'The Postgres in-flight watchdog now also retires a connection whose statement keeps receiving rows or notices past its budget (`pg_connection_stuck` `reason=age`; `reason=idle` when nothing came back, which used to be the only case), and the budget is per statement: an operation that declares a longer `statement_timeout` on its connection (`SET LOCAL`, `set_config`, a session `SET` on a reserved connection) gets that timeout plus the grace, and a declared 0 has no cap, read from the statements themselves so it holds behind a transaction-mode pooler. The warn line adds `reason=` and `budget_ms=`, and `/health?deep=1` reports `pool_inflight_over_budget` only for a statement past its own budget (a long transaction that declared its timeout no longer reads as over budget).' },
- { since: '0.60.189.0', text: 'Pools count reconnects of connections retired after an incident (stuck, desynced, or closed under running statements): `recovered` and `recovery_failed` in `/health?deep=1` and `getPoolDiagnostics()`, and a failed reconnect logs `pg_connection_recovery_failed`. `gbrain serve` writes its stuck, desync and recovery events to the pool-recovery audit, so `gbrain doctor --only pool_reap_health` now fails on a recovery failure and warns on a stuck or desynced connection in the last hour.' },
++ { since: '0.60.190.0', text: 'On a managed brain, `gbrain sync` (one source, `--all`, and a sync handed to `gbrain serve`) now implies `--no-pull` and prints one stderr line naming `gbrain sources refresh <id>` for taking upstream commits, instead of refusing with `writer_coordinator_required` until `--no-pull` was typed. Nothing changes on stdout or in `--json`; `--dry-run` and the library/MCP refusal of an explicit pull are unchanged.' },
++ { since: '0.60.190.0', text: 'A managed sync drain whose queued head no consumer can claim now stops within one governor tick with `drain_stalled`, `cause: head_blocked`, when the blocker needs an operator (a refresh fence no refresh process holds: `next.fix` is `gbrain sources refresh <id> --resume`; a running request ahead held by a process that reports `restart_required`: restart it), instead of waiting the 5-10 minute no-progress window. `drain.stall` gains `blocked_by` and `consumer`, the stall line prints `consumer=` and `blocked_by=`, and `claimable here` is read for the head itself (`unknown` when the read fails; it used to print a constant `no`). `gbrain sources writer status` names the blocker of each queued head (`blocked_by`, `claimable_here`) and adds `cancel_command` only when this caller may cancel the blocking request.' },
++ { since: '0.60.190.0', text: '`gbrain repair <kind> --apply` no longer stops at the first write that is accepted but still pending publication while a consumer on this host is publishing: it keeps the receipt (the saved position stays before it), admits the remaining items without a per-item publication wait (at most half the principal outstanding-request cap unresolved at once) and settles them against one shared wait (the write wait with nothing publishing). A run that still stops lists the receipts in `pending` and the same command resumes; `--wait 0` still waits for nothing. With no live consumer, or one that reports `restart_required`, the run stops at the first pending write as before and names the owner.' },
++ { since: '0.60.190.0', text: '`[persistence] phase=` log lines about one write request now carry `request_id`, `operation`, `source`, `slug`, `principal` and `elapsed_ms`, and their 30-second repeat suppression is per request: two requests failing the same phase log two lines.' },
++ { since: '0.60.190.0', text: '`gbrain serve` now logs the behavior changes this brain has not been told about once per process at startup, on stderr. It reads the notice state without marking it delivered, so the CLI, stdio and HTTP notices still show once each.' },
++ { since: '0.60.190.0', text: 'Importing an image no longer writes `type` or `title` into its frontmatter (the keys `gbrain repair frontmatter-keys` strips since 0.60.177.0). Doctor `stale_frontmatter_keys` names 0.60.177.0 and, on a brain with several sources, its fix is the all-sources `gbrain repair frontmatter-keys`, with the per-source commands listed.' },
++ { since: '0.60.190.0', text: '`gbrain embed --stale --images` and doctor `image_assets` find an image whose recorded path differs from the file on disk only in letter case (an exact match still wins), import it under the real-case path, and refuse a case-fold match that is ambiguous or resolves outside the source root instead of importing or counting it. `image_assets` reports case-only, ambiguous and unrooted counts.' },
++ { since: '0.60.190.0', text: 'On a managed brain, a successful `gbrain sync --source <id>` settles legacy rows the pre-managed sync left in `sync-failures.jsonl` one at a time (the imported commit holds the file and a live page claims it, or the file is gone and no page claims it); rows on an unknown commit, sentinel rows, held files and files it did not index stay. Doctor `sync_failures` says how many unresolved rows are legacy and which command settles them, and `gbrain sync --retry-failed` names them instead of saying the ledger is empty.' },
++ { since: '0.60.190.0', text: 'The Postgres in-flight watchdog now also retires a connection whose statement keeps receiving rows or notices past its budget (`pg_connection_stuck` `reason=age`; `reason=idle` when nothing came back, which used to be the only case), and the budget is per statement: an operation that declares a longer `statement_timeout` on its connection (`SET LOCAL`, `set_config`, a session `SET` on a reserved connection) gets that timeout plus the grace, and a declared 0 has no cap, read from the statements themselves so it holds behind a transaction-mode pooler. The warn line adds `reason=` and `budget_ms=`, and `/health?deep=1` reports `pool_inflight_over_budget` only for a statement past its own budget (a long transaction that declared its timeout no longer reads as over budget).' },
++ { since: '0.60.190.0', text: 'Pools count reconnects of connections retired after an incident (stuck, desynced, or closed under running statements): `recovered` and `recovery_failed` in `/health?deep=1` and `getPoolDiagnostics()`, and a failed reconnect logs `pg_connection_recovery_failed`. `gbrain serve` writes its stuck, desync and recovery events to the pool-recovery audit, so `gbrain doctor --only pool_reap_health` now fails on a recovery failure and warns on a stuck or desynced connection in the last hour.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */