Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge remote-tracking branch 'origin/master' into capy/6712-pr2
garrytanef5a9fd66fb1
diff --cc src/commands/doctor/checks/sync-failures.tsindex 9dd2c96558,d1d679a769..3e0245169c--- a/src/commands/doctor/checks/sync-failures.ts+++ b/src/commands/doctor/checks/sync-failures.ts@@@ -7,7 -7,7 +7,8 @@@ import { makeRemediationStep } from '..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';+import { classifyRecordedFault } from '../../../core/persistence/terminal-classify.ts';+ import { agentFix } from '../check-fix.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: `@@@ -75,12 -78,7 +79,12 @@@ export async function checkSyncFailures? `${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}`;const legacyNote = managedBrain ? legacyLedgerNote(unresolvedLegacy) : '';+ // #6712 PR 2 (L5): each managed failure with the classifier's category and the public category beside it.+ const failures = managed.map(row => {+ const v = classifyRecordedFault({ source_id: row.source_id, code: row.code, request_id: row.request_id, error_detail: row.write_error_detail ?? null, message: row.message });+ return { source_id: row.source_id, path: row.path, code: row.code, category: v.category, public_category: v.public_category, class: v.class, needs_human: v.needs_human };+ });return { name: 'sync_failures', status: severity.status, message: `${summary} ${details.join('; ')} ${recovery}${legacyNote}`,- remediation, remediation_status: remediation ? 'remediable' : 'blocked', ...(orphans.length || failures.length ? { details: { ...(orphans.length ? { orphans } : {}), ...(failures.length ? { failures } : {}) } } : {}),- remediation, remediation_status: remediation ? 'remediable' : 'blocked', ...(orphans.length ? { details: { orphans } } : {}), ...orphanFix,++ remediation, remediation_status: remediation ? 'remediable' : 'blocked', ...(orphans.length || failures.length ? { details: { ...(orphans.length ? { orphans } : {}), ...(failures.length ? { failures } : {}) } } : {}), ...orphanFix,...(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.tsindex a66cb087da,2e44ede208..a8e1f3c3df--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@@ -700,18 -700,8 +700,20 @@@ export const BEHAVIOR_CHANGES: Readonly{ since: '0.60.262.0', text: 'A managed Google or GitHub connector item whose content matches a page purge tombstone is now skipped, and the rest of the sync continues (#6831). Before, the pages guard\'s `purged_content` refusal of that one item ended the whole sync job, and every later sync of the source died the same way. Skipped items are listed in `gbrain sources status` ("skipped as purged content"), and `gbrain pages unpurge <slug>` lets one back in. Every other failed connector write still ends the run.' },{ since: '0.60.262.0', text: 'A connector source whose syncs keep ending on an error now says so (#6831): `gbrain sources status` names the error, the item and a read-only next step, and reads STOPPED after 3 failed runs in a row; `gbrain sync status --json` adds `connector_last_error` with that read-only fix; doctor `sync_freshness` warns about a STOPPED source even when its last good sync was recent (fails past the fail age). `last_error`, `state` and `next` are unchanged for connector sources.' },{ since: '0.60.262.0', text: 'A `claude-cli` usage-policy refusal ("API Error: <model> can\'t help with this ... https://www.anthropic.com/legal/aup", and the older "violate our Usage Policy" and "safeguards flagged this" wordings) is now a provider content block (`claude_cli_usage_policy`, #6816): `extract_atoms` tombstones the item after its consecutive-failure limit instead of re-sending it every run, and with `chat_fallback_on_refusal: false` the prompt is not sent on to the next model in `chat_fallback_chain`. Other `claude-cli` errors are unchanged.' },+ // #6834 hotfix. `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.+ { since: '0.60.263.0', text: 'A managed sync whose checkpoint was refused `revision_conflict` on `__managed_sync_checkpoint__` because the source\'s `last_commit` moved under it (#6834) no longer blocks forever: when the source already records the run\'s target, the next plain `gbrain sync` finishes the run; when it records any other commit, `gbrain repair managed-sync-orphans --source <id>` lists the cursor as `checkpoint_moved` (preview, then `--apply --expect <hash>`) and the next sync discovers from that commit. Doctor `sync_failures` and `sync_freshness` name that repair as their fix, the receipt reason is `sync_checkpoint_moved` (fact batches: `facts_batch_incomplete`) instead of "read the current page", the terminal-failure action reads `gbrain sync status` instead of `gbrain get` on the bookkeeping slug, and a later committed checkpoint supersedes the refused receipt.' },+ // #6712 PR 2 lane L3 (flags and config keys): `since` is a placeholder until the merge-slot stamp.- { since: '0.60.263.0', text: 'Five `sync.*` config keys are no longer read (#6712): `sync.bulk_max_txn_ms`, `sync.hold_cap`, `sync.hold_escalate_count`, `sync.hold_escalate_pct` and `sync.parser_regression`. Set `GBRAIN_SYNC_BULK_MAX_TXN_MS`, `GBRAIN_SYNC_HOLD_CAP`, `GBRAIN_SYNC_HOLD_ESCALATE_COUNT`, `GBRAIN_SYNC_HOLD_ESCALATE_PCT` or `GBRAIN_SYNC_PARSER_REGRESSION` in the environment of the process that syncs instead; a value stored on the brain is kept but not applied, so a tuned brain runs with the defaults (15000, 500, 50, 5, stop) until the variable is set. `gbrain doctor --only sync_config_keys` lists stored values that stopped applying, `gbrain config get <key>` prints the value in effect and where it comes from, and `gbrain config set` of a retired key warns, names the variable and writes nothing (exit 0).' },- { since: '0.60.263.0', text: '`sync.job_drain`, `sync.foreground_priority`, `sync.federated_v2`, `sync.waive_batch` and `sync.bulk` are rollback keys (#6712): `false` still restores the earlier behavior a notice named, and they stay honored until at least 2027-01-14 (`CONFIG_ROLLBACK_WINDOWS` in `src/core/wire-skew.ts`), but `config set` now writes them with a note that they are not tunables and help text no longer recommends them. `sync.foreground_priority` is accepted without `--force` (it was refused as an unknown key). A serve or PGLite owner that receives a retired field from an older sync client (`explicitProcessing` today) prints one `[gbrain notice]` naming it and its window, and the PGLite owner lane accepts `--lanes N` and `--no-lanes` (ignored there) instead of refusing them.' },++ { since: '0.60.264.0', text: 'Five `sync.*` config keys are no longer read (#6712): `sync.bulk_max_txn_ms`, `sync.hold_cap`, `sync.hold_escalate_count`, `sync.hold_escalate_pct` and `sync.parser_regression`. Set `GBRAIN_SYNC_BULK_MAX_TXN_MS`, `GBRAIN_SYNC_HOLD_CAP`, `GBRAIN_SYNC_HOLD_ESCALATE_COUNT`, `GBRAIN_SYNC_HOLD_ESCALATE_PCT` or `GBRAIN_SYNC_PARSER_REGRESSION` in the environment of the process that syncs instead; a value stored on the brain is kept but not applied, so a tuned brain runs with the defaults (15000, 500, 50, 5, stop) until the variable is set. `gbrain doctor --only sync_config_keys` lists stored values that stopped applying, `gbrain config get <key>` prints the value in effect and where it comes from, and `gbrain config set` of a retired key warns, names the variable and writes nothing (exit 0).' },++ { since: '0.60.264.0', text: '`sync.job_drain`, `sync.foreground_priority`, `sync.federated_v2`, `sync.waive_batch` and `sync.bulk` are rollback keys (#6712): `false` still restores the earlier behavior a notice named, and they stay honored until at least 2027-01-14 (`CONFIG_ROLLBACK_WINDOWS` in `src/core/wire-skew.ts`), but `config set` now writes them with a note that they are not tunables and help text no longer recommends them. `sync.foreground_priority` is accepted without `--force` (it was refused as an unknown key). A serve or PGLite owner that receives a retired field from an older sync client (`explicitProcessing` today) prints one `[gbrain notice]` naming it and its window, and the PGLite owner lane accepts `--lanes N` and `--no-lanes` (ignored there) instead of refusing them.' },+ // #6712 PR 2 lane L5 (truthful receipts, fast status). `since` is a placeholder until the merge-slot stamp.- { since: '0.60.263.0', text: 'A managed `gbrain sync` returns `synced` when its checkpoint commits: the tail after it (planner statistics, link extraction for the imported pages) now runs after the drain lease is released, bounded at 5 minutes, and a second sync can take the lease while it runs. A tail that fails, is cut short or gets no time keeps the run `synced` and adds a `[gbrain notice sync_tail_degraded]` with its fix (`gbrain extract --stale --source <id>`); a tail a crash skipped runs on the next sync of the source.' },- { since: '0.60.263.0', text: 'The `drain_stalled` cause `no_admission` is retired: a sync pass that admits nothing with no unfinished request stops `drain_stalled` / `no_progress` with the same step and statement, a delegated run no longer falls back to its own consumer for it, and the transaction-pooler warning line is gone. Scripts matching `no_admission` should match `no_progress`.' },- { since: '0.60.263.0', text: 'A plain `gbrain sync status` skips the terminal-failure summary, the checkpoint blocker list and the cursor list (their fields stay, empty or `unknown`, with `terminal_failures_read` / `checkpoint_blockers_read` / `cursors_read` set to `not_read` and a `--detail` fix); `gbrain sync status --detail` reads them. New fields: `state`, `reason`, `oldest_blocker`, `recovery`, and `public_category` on holds, `last_error`, receipts and doctor `sync_failures`.' },++ { since: '0.60.264.0', text: 'A managed `gbrain sync` returns `synced` when its checkpoint commits: the tail after it (planner statistics, link extraction for the imported pages) now runs after the drain lease is released, bounded at 5 minutes, and a second sync can take the lease while it runs. A tail that fails, is cut short or gets no time keeps the run `synced` and adds a `[gbrain notice sync_tail_degraded]` with its fix (`gbrain extract --stale --source <id>`); a tail a crash skipped runs on the next sync of the source.' },++ { since: '0.60.264.0', text: 'The `drain_stalled` cause `no_admission` is retired: a sync pass that admits nothing with no unfinished request stops `drain_stalled` / `no_progress` with the same step and statement, a delegated run no longer falls back to its own consumer for it, and the transaction-pooler warning line is gone. Scripts matching `no_admission` should match `no_progress`.' },++ { since: '0.60.264.0', text: 'A plain `gbrain sync status` skips the terminal-failure summary, the checkpoint blocker list and the cursor list (their fields stay, empty or `unknown`, with `terminal_failures_read` / `checkpoint_blockers_read` / `cursors_read` set to `not_read` and a `--detail` fix); `gbrain sync status --detail` reads them. New fields: `state`, `reason`, `oldest_blocker`, `recovery`, and `public_category` on holds, `last_error`, receipts and doctor `sync_failures`.' },+ // #6712 PR 2 lane L4 (exits, escalation, soak counters): placeholder since; the fresh-install cases in behavior-change-notice.test.ts pass once VERSION is stamped.- { since: '0.60.263.0', text: 'A held file now asks for a person (`needs_human`) only after its safe action failed three times and at least 24 hours have passed since it was first held (#6712). Three re-holds within an hour stay the agent\'s to retry. A `worktree_dirty` file whose uncommitted bytes changed in the last day, and an image held while multimodal embedding is off, never escalate this way. A failed `sync unblock --apply` (still dirty) or a repair that holds the file again counts as an attempt.' },- { since: '0.60.263.0', text: 'A managed-sync file that `write_gate.external_mode=reject` refuses is now held as `write_gate_rejected` when sync freezes it, instead of failing its receipt and stopping the rest of the source. A held file that leaves the source (excluded with `sync.exclude`, or an image while multimodal embedding is off) is released by the next sync even when nothing new was committed. Every sync re-screens a `write_gate_rejected`, `content_rejected` or `purged_content` hold, so switching the setting, an owner allow rule or `gbrain pages unpurge` clears it.' },- { since: '0.60.263.0', text: 'A `source_changed` write receipt\'s fix now follows its recorded reason: two-sided drift previews `gbrain repair file-drift --source <id> --slug <slug> --prefer database` (a group of them `--all-drifted --since <instant>`), a missing canonical file previews `gbrain repair ghost-pages`, an admission race is retried, and a changed binding or unsafe target names `gbrain sources writer status`. `gbrain repair file-drift` takes `--since <ISO-8601 | age>` to narrow `--all-drifted`.' },- { since: '0.60.263.0', text: 'Doctor `managed_sync_not_moving` now fails (it used to list the source as parked) when a managed source\'s queue holds admitted requests with no consumer and nothing has moved for longer than `persistence.preparation_ceiling_ms`; its fix is the resume sync, which consumes the queue (#6552). A managed sync now prints a line when live pages of the source have no canonical file, naming the read-only `gbrain repair ghost-pages` preview; it never deletes them.' },++ { since: '0.60.264.0', text: 'A held file now asks for a person (`needs_human`) only after its safe action failed three times and at least 24 hours have passed since it was first held (#6712). Three re-holds within an hour stay the agent\'s to retry. A `worktree_dirty` file whose uncommitted bytes changed in the last day, and an image held while multimodal embedding is off, never escalate this way. A failed `sync unblock --apply` (still dirty) or a repair that holds the file again counts as an attempt.' },++ { since: '0.60.264.0', text: 'A managed-sync file that `write_gate.external_mode=reject` refuses is now held as `write_gate_rejected` when sync freezes it, instead of failing its receipt and stopping the rest of the source. A held file that leaves the source (excluded with `sync.exclude`, or an image while multimodal embedding is off) is released by the next sync even when nothing new was committed. Every sync re-screens a `write_gate_rejected`, `content_rejected` or `purged_content` hold, so switching the setting, an owner allow rule or `gbrain pages unpurge` clears it.' },++ { since: '0.60.264.0', text: 'A `source_changed` write receipt\'s fix now follows its recorded reason: two-sided drift previews `gbrain repair file-drift --source <id> --slug <slug> --prefer database` (a group of them `--all-drifted --since <instant>`), a missing canonical file previews `gbrain repair ghost-pages`, an admission race is retried, and a changed binding or unsafe target names `gbrain sources writer status`. `gbrain repair file-drift` takes `--since <ISO-8601 | age>` to narrow `--all-drifted`.' },++ { since: '0.60.264.0', text: 'Doctor `managed_sync_not_moving` now fails (it used to list the source as parked) when a managed source\'s queue holds admitted requests with no consumer and nothing has moved for longer than `persistence.preparation_ceiling_ms`; its fix is the resume sync, which consumes the queue (#6552). A managed sync now prints a line when live pages of the source have no canonical file, naming the read-only `gbrain repair ghost-pages` preview; it never deletes them.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --cc src/core/persistence/terminal-classify.tsindex 15b9cb173f,5ee3864488..a6c7d2f3e7--- a/src/core/persistence/terminal-classify.ts+++ b/src/core/persistence/terminal-classify.ts@@@ -257,13 -245,24 +257,28 @@@ function route(input: TerminalInput): Pwhy: 'Previews the live pages whose canonical file is missing and writes nothing; apply only after the user agrees, or restore the file and sync.',verify: { argv: failuresArgv(source) }, docs: 'docs/guides/write-refusals.md#canonical_file_missing' } };}- if (known === 'source_binding_changed' || known === 'unsafe_file_target') return diagnosis(input, code, known, `The write was refused source_changed (${known}).`);+ if (known === 'source_binding_changed' || known === 'unsafe_file_target') {+ const v = row(known);+ return { category: 'diagnosis_required', code, origin: known, ...v,+ action: inspect(source, `The write was refused source_changed (${known}). Writer status shows the source binding and its checkout, read-only.`, v.human_reason) };+ }return fromTable('sync_fault', code, origin ?? known, syncRetry(source, `The file changed under the write (${known}); a sync imports the current bytes.`), known === 'pinned_git_worktree_conflict' ? known : 'source_changed');}+ // #6834: a checkpoint or fact-batch completion receipt names a bookkeeping slug, never a page; reading it finds nothing.+ // A compacted receipt keeps no intent kind; its operation and slug still identify the bookkeeping request.+ const bookkeeping = (kind: string, operation: string, slug: string) => input.slug === slug && (input.intent_kind ? input.intent_kind === kind : input.operation === operation);+ if (code === 'revision_conflict' && bookkeeping('managed_sync_checkpoint', 'submit_job', '__managed_sync_checkpoint__')) {+ return { category: 'caller_conflict', code, origin, class: 'systemic', safe_actions: ['retry'], needs_human: false, escalate: escalateOf(code),+ action: { argv: ['gbrain', 'sync', 'status', '--source', source, '--json'], consent: [], actor: 'agent', requires_exclusive: false,+ why: 'A sync checkpoint was refused (__managed_sync_checkpoint__ is bookkeeping, not a page). Sync status names the step that finishes or retires its run, read-only; a later checkpoint of the source supersedes this receipt.',+ verify: { argv: failuresArgv(source) }, docs: 'docs/guides/repair.md#managed-sync-orphans' } };+ }+ if (code === 'revision_conflict' && bookkeeping('managed_facts_complete', 'extract_facts', '__managed_facts_complete__')) {+ return { category: 'caller_conflict', code, origin, class: 'systemic', safe_actions: ['none'], needs_human: false, escalate: 'never: the batch\'s committed facts stay',+ action: { argv: terminalInspectArgv(input.request_id ?? '<request_id>'), consent: [], actor: 'agent', requires_exclusive: false,+ why: 'A fact-extraction batch was not recorded complete because some of its per-entity requests did not commit (__managed_facts_complete__ is bookkeeping, not a page). The receipt is read-only history; run the extraction again only if facts are still missing.',+ verify: { argv: failuresArgv(source) } } };+ }if (code === 'revision_conflict' || code === 'page_identity_changed') {return { category: 'caller_conflict', code, origin, class: 'page', safe_actions: ['retry'], needs_human: false, escalate: escalateOf(code),action: { argv: ['gbrain', 'get', '--source', source, '--', input.slug], consent: [], actor: 'agent', requires_exclusive: false,diff --cc src/core/persistence/terminal-failures.tsindex aaa0d6adb8,96426df129..aff17521c0--- a/src/core/persistence/terminal-failures.ts+++ b/src/core/persistence/terminal-failures.ts@@@ -296,12 -293,11 +296,12 @@@ export async function readTerminalFailulet cursor = q.before ?? null, scanned = 0, exhausted = false;const want = q.groupBy ? MAX_SCAN : limit + 1;while (out.length < want && scanned < MAX_SCAN && !exhausted) {- const batch = await bounded<KeyColumns & { request_id: string; sequence: string; slug: string; error_detail: Record<string, unknown> | null; ended_at: string; later_state: string | null; same_intent: boolean | null }>(engine,+ const batch = await bounded<KeyColumns & { request_id: string; sequence: string; slug: string; error_detail: Record<string, unknown> | null; ended_at: string; admitted_at: string; later_state: string | null; same_intent: boolean | null }>(engine,- `SELECT r.request_id::text AS request_id, r.sequence::text AS sequence, r.source_id, r.slug, r.operation, r.state, r.error_code, r.error_detail,+ `SELECT r.request_id::text AS request_id, r.sequence::text AS sequence, r.source_id, r.slug, r.operation, r.intent->>'kind' AS intent_kind, r.state, r.error_code, r.error_detail,r.error_detail->>'origin' AS origin, r.error_detail->>'reason' AS reason, r.error_detail->>'cause' AS cause,r.recovery IS NOT NULL AS has_recovery, r.blocked_reason, r.compacted, ${terminalKnockOnSql('r')} AS knock_on, ${ROUTED_MESSAGE('r')} AS routed_message, ${BUILD('r')} AS build,- to_char(${ENDED('r')} AT TIME ZONE 'UTC','YYYY-MM-DD"T"HH24:MI:SS"Z"') AS ended_at, later.state AS later_state, later.same_intent+ to_char(${ENDED('r')} AT TIME ZONE 'UTC','YYYY-MM-DD"T"HH24:MI:SS"Z"') AS ended_at, to_char(r.created_at AT TIME ZONE 'UTC','YYYY-MM-DD"T"HH24:MI:SS"Z"') AS admitted_at,+ later.state AS later_state, later.same_intentFROM persistence_requests rLEFT JOIN LATERAL (SELECT c.state, c.digest=r.digest AS same_intent FROM persistence_requests c WHERE ${supersessionSql('r', 'c')}ORDER BY ${supersessionOrderSql('r', 'c')} LIMIT 1) later ON r.recovery IS NULL