Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge remote-tracking branch 'origin/gbra133-pr1-misc' into gbra133-pr1
garrytanb46594c5e693
diff --cc docs/guides/write-refusals.mdindex 96b306004e,ad28a01ee4..375f2ff7a3--- a/docs/guides/write-refusals.md+++ b/docs/guides/write-refusals.md@@@ -206,27 -206,14 +206,28 @@@ with each file and fix the ones that ne| <a id="legacy_slug_conflict"></a><a id="legacy_slug_conflict-explicit_id_conflict"></a>`legacy_slug_conflict` (`explicit_id_conflict`) | The file has no page at its slug, and several live pages an older gbrain imported before the current slug fold (a space, an emoji, an accent or a trailing dash in the slug; no recorded file) fold to that slug (#6727). Exactly one such page is taken over by the file: the next sync imports into it (same page id, links, timeline and aliases) and records the file as its origin, instead of creating a second page. With several, sync cannot tell which page is the file's, so it holds the file and the rest of the source syncs. It holds the file the same way when the one match has a slug sync cannot write as it stands (capital letters, from a gbrain that predates lowercase slugs; the importer lowercases), rather than creating a second page beside it. With reason `explicit_id_conflict` (#6729), the one match carries an explicit frontmatter `id` that differs from the file's, so it is a different document and is not taken over. With `sync.holds=fail` the run stops with `page_identity_changed`. Twins an older sync already created are not merged by this. | Ask the user which page is the file's (`gbrain sync status --source <source> --json` names every candidate slug). Remove each other one with `gbrain delete --source <source> -- '<slug>'` (soft delete, recoverable for 72 h), or rename the file if none of them is its page; with one match under a slug with capitals, which no command can address yet, keep the file held or rename it to a name that folds to another slug (it then imports as a new page beside the old one, which keeps its links). For `explicit_id_conflict`: give the file the page's `id` if it is the same document; otherwise rename the file or delete the old page. Then `gbrain sync --source <source> --no-pull`. The hold re-screens on every sync. || <a id="origin_conflict"></a><a id="origin_conflict-no_canonical_claimant"></a><a id="origin_conflict-content_differs"></a><a id="origin_conflict-file_unreadable"></a><a id="origin_conflict-explicit_id_conflict"></a><a id="origin_conflict-visibility_differs"></a><a id="origin_conflict-trust_tier_differs"></a><a id="origin_conflict-twin_has_withdrawals"></a><a id="origin_conflict-twin_slug_path_occupied"></a><a id="origin_conflict-twin_evidence_conflicts"></a>`origin_conflict` (`no_canonical_claimant`, `content_differs`, `file_unreadable`, `explicit_id_conflict`, `visibility_differs`, `trust_tier_differs`, `twin_has_withdrawals`, `twin_slug_path_occupied`, `twin_evidence_conflicts`) | Several live pages of the source record this file as their origin (duplicate-origin twins, #6948). Sync used to stop the whole source with `page_identity_changed`; now only this file is held and the rest of the source syncs. With no reason the pages are verified duplicates: the page the path names (`meta.canonical_slug`), one inline body, a readable file, no conflicting frontmatter ids, one visibility and trust tier, no slug-keyed fact withdrawals or purges, no file at a twin's own slug path and no link, relationship date, timeline entry or raw payload the merge would lose. Right after that managed sync, the heal merges each other page into the canonical one (links, relationship dates, timeline, raw data, user tags, aliases and facts move; its slug becomes an alias; it is soft-deleted without touching the file, restorable for 72 h) and the next sync imports the file. A reason means a person decides: `no_canonical_claimant` (no page, or not exactly one, is the page the path names), `content_differs` (the bodies differ, or one cannot be read), `file_unreadable`, `explicit_id_conflict` (different frontmatter `id`s), `visibility_differs`, `trust_tier_differs` (a merge never raises or lowers a tier), `twin_has_withdrawals`, `twin_slug_path_occupied`, `twin_evidence_conflicts`. With `sync.holds=fail` the run stops with `page_identity_changed`. | `gbrain repair origin-twins --source <source>` (read-only) lists every group with its pages, revisions and verdict. Verified groups: let the next sync heal them, or apply the preview now. A decision: read each page (`gbrain get --source <source> -- '<slug>'`), then either `gbrain repair origin-twins --source <source> --slug '<kept-slug>'` (the others forget the file and stay live; nothing is deleted) or soft-delete the others with `gbrain delete`. Then `gbrain sync --source <source> --no-pull`. The heal's kill switch is `gbrain config set sync.origin_twins.auto_resolve false`. The hold re-screens on every sync. Guide: [origin twins](repair.md#origin-twins). || <a id="rename_held"></a><a id="rename_held-rename_source_changed"></a>`rename_held` (`rename_source_changed`) | A renamed file's hold cleared, but the page it was renamed from changed after the rename was recorded, so the page did not move. | `gbrain repair frontmatter --source <source> --include-ambiguous` proposes re-binding the rename to the old page's current revision; apply after the user agrees. Or restore the old file name. |+| <a id="rename_identity_unreadable"></a>`rename_identity_unreadable` | Classic sync (GBRA-133 S-51): a file added in the same sync that removed or renamed another has a title or frontmatter `id` the database refused to compare (SQLSTATE 22021 or 22P05), so sync could not tell whether it is that page renamed. The new file is held and the old page keeps its id, links, facts and timeline; the rest of the source keeps syncing. A NUL byte or an unpaired surrogate in a title or id never reaches the database: sync treats such a value as absent and the pair takes the ordinary unconfirmed-rename path. | Remove the characters the database cannot store from the file title and `id`, commit, then `gbrain sync --source <source> --no-pull`. The pair is decided again when the file changes or on `gbrain sources retry-held <source>`. |+| <a id="rename_reconcile_failed"></a>`rename_reconcile_failed` | Classic sync (GBRA-133 S-67): a rename fell back to importing the new file, and removing the page of the old name then failed with an unexpected error (the hold records its class and code, never its message). The old page was kept and may duplicate the new one; the rest of the source keeps syncing. A transient database error and the reconcile's own "staleness unprovable" verdict still record the `<rename:…>` marker, which a later run converges. | Ask the user before `gbrain sync --source <source> --full --no-pull`: the full walk removes pages whose file is gone after checking each one (it re-reads the whole source). Or remove the old page with `gbrain delete --source <source> -- <slug>` (recoverable for 72 h). || <a id="concurrent_write"></a>`concurrent_write` | Managed sync was importing a newer Git version of the file while a database-only write (write-through off, a sandboxed or derived write) committed a different version of the same page, so the two diverge (#6194). The proof is the page's revision itself: it was written by a committed non-sync request for that page. Neither version was overwritten: the page keeps the database version, the file is held and the rest of the source syncs. Since #6340 a page that moved with no such request to name is held the same way (the hold records `page_revision` and `expected_revision` instead of a competing request), and so is a page that changed, was deleted or was re-bound in the database between the manifest freeze and the entry's turn; a page that still holds exactly what the file would import is re-bound to its new revision and passed. | `gbrain sources status <source>` names the page and the competing request. Preview with `gbrain sources reconcile <source> <slug> --preview`, decide with the user which content wins, apply the resolved preview, then `gbrain sources retry-held <source>` and `gbrain sync --source <source> --no-pull` re-screen the file. A new commit of the file re-screens it too. || <a id="file_drift"></a>`file_drift` | Managed sync would have imported a file over a database version of its page that sync never saw (#6712). Every import records its provenance (the bytes left on disk, the page revision it wrote, the parser); a page that moved since that record (a database-only write, write-through off) while its file did not change, or, in a tree walk (first sync, `--full`, an unreachable checkpoint), a page whose file and revision both moved or that has no usable record (an upgraded brain: none, a pre-PR 0 record, a partial one), is imported only when the import changes nothing, a sync request wrote its current revision, or its writer's write-through wrote that revision to the file. Otherwise the file is held, the page keeps the database version and the rest of the source syncs. The hold names `sides` (`database`, `both`, `unknown`) and the database request that wrote the page when there was one. Pages under `storage.keep_db` prefixes are never held: the entry is skipped and the keep_db worker reconciles the page from the database. Holds of this code never escalate; with `sync.holds=fail` the run stops with `file_drift` instead of holding. | `gbrain sources status <source>` names the page. Preview `gbrain repair file-drift --source <source> --slug <slug> --prefer database` (keep the database copy, rewrite the file) or `--prefer file` (import the file), decide with the user, apply it with the plan hash, then `gbrain sync --source <source> --no-pull`. A changed file or page revision re-screens the hold by itself. |- | <a id="parser_regression"></a>`parser_regression` | With `GBRAIN_SYNC_PARSER_REGRESSION=hold`, a file whose exact bytes imported under an earlier gbrain is now refused. This is a gbrain bug. | Report it with the gbrain version, the file and the code; upgrade or pin the last good version. After a fixed gbrain is installed, `gbrain sources retry-held <source>` and then `gbrain sync --source <source> --no-pull` re-screen it. |+ | <a id="frontmatter_alias_limit"></a>`frontmatter_alias_limit` | A file whose exact bytes an older gbrain imported and validated nests YAML aliases in its frontmatter that expand past the size limit (#7018). This release refuses them on purpose, so only that file is held (its page keeps the last imported version) and the rest of the source syncs; it is never a parser regression. | Reduce the alias nesting in the frontmatter (or write the values out), or remove the file, then commit and `gbrain sync --source <source> --no-pull`. The hold re-screens when the file changes. Before this release such a file stopped the source as `sync_parser_regression`; the workaround there was `GBRAIN_SYNC_PARSER_REGRESSION=hold` for the process that syncs. |+ | <a id="parser_regression"></a>`parser_regression` | With `GBRAIN_SYNC_PARSER_REGRESSION=hold`, a file whose exact bytes imported under an earlier gbrain is now refused. This is a gbrain bug. | Report it with the gbrain version, the file and the code; upgrade, or keep `GBRAIN_SYNC_PARSER_REGRESSION=hold` set for the process that syncs, and never pin a release older than 0.60.305.0. After a fixed gbrain is installed, `gbrain sources retry-held <source>` and then `gbrain sync --source <source> --no-pull` re-screen it. || <a id="write_interrupted-hold"></a>`write_interrupted` | The database ended this file's statements (a statement timeout or cancel) at every attempt, so the sync held the file and kept going. The file is fine: no repair applies, and it is not imported until it is retried. Full reference: [`write_interrupted`](#write_interrupted). | `gbrain sources writer status --source <source> --json` (read-only) names the load on the write owner; reduce it, then `gbrain sources retry-held <source>` and the same sync with its options. || <a id="preparation_stalled-hold"></a>`preparation_stalled` | The write for this file could not finish *preparing* within its attempt limit, so the sync held the file and kept going. The file is fine: no repair applies, and it is not imported until it is retried. Full reference: [`preparation_stalled`](#preparation_stalled). | `gbrain sources writer status --source <source> --json` (read-only), fix what it names, then `gbrain sources retry-held <source>` and the same sync with its options. Runbook: [catch-up stuck / held N files](troubleshooting.md#catch-up-stuck). || <a id="worktree_dirty"></a>`worktree_dirty` | The working tree holds uncommitted bytes for this file that match neither the pinned commit nor the current page (an agent mid-edit on a live checkout), and importing the pinned version would discard them (#6340). Before this release the refusal (`source_changed` / `pinned_git_worktree_conflict`) stopped the whole run; now the file is held, the local edit is untouched and the rest of the source syncs. The hold keeps the pinned blob (`meta.blob_oid`) and a hash of the working bytes, counts `meta.attempts` each time the same file is held again, and a page held three times is reported `needs_human` by `gbrain sync status`. Bytes that are **committed at HEAD** past the pinned target are not a conflict at all: sync imports them as HEAD has them and the later pin..HEAD diff re-imports the same bytes as a no-op. Since 0.60.179.0 (#6513) the same hold covers a pinned import whose canonical correction (a fixable fence, reflowed frontmatter) would rewrite a file that holds newer uncommitted bytes: that refusal used to block the cursor with no exit, because `--retry-failed` replays the same pin against the same bytes, `sources refresh` refuses `sync_in_progress` on the unfinished cursor and `--acknowledge-managed` refuses `cursor_unfinished`. Working-tree bytes that already *are* the correction (gbrain's own writeback, published before the request that carried it settled) are not a conflict either: the page imports and the file is left as it is. | Commit the edit (or restore the file), then `gbrain sync unblock --source <source> --apply` re-screens every held file that is now committed and prints the sync to run (`gbrain sources retry-held <source>` does the same for all holds). A later commit that changes the file re-screens it on its own. Never discard or normalize the local bytes. Runbook: [sync unblock](sync-unblock-runbook.md). |+| <a id="file_unreadable"></a>`file_unreadable` | Classic or managed sync held one file because it is not a readable regular file inside the source root. Sync never reads or follows it, the rest of the source imports, and the bookmark advances. Classic sync re-screens it on every run, so an out-of-band fix needs no commit. | Follow the reason row below. Each hold's `fix` names the exact step; `gbrain sources status <source> --json` lists the holds. |+| <a id="file_unreadable-symlink_in_repo"></a>`file_unreadable` (`symlink_in_repo`) | The path is a symlink to another file in the repository. Sync reads only regular files and never follows a symlink. | Replace the symlink with the regular file it stands for (or delete it), or leave it out with `sync.exclude` (`gbrain config get sync.exclude`, then `gbrain config set sync.exclude '<current list>,<path>'`). The next sync re-screens it. |+| <a id="file_unreadable-symlink_outside_root"></a>`file_unreadable` (`symlink_outside_root`) | The path is a symlink to a path outside the repository (it can point anywhere on the host), so sync never reads it. Before GBRA-133 classic sync blocked the source for three runs, then auto-skipped it. | Copy the content you want into a regular file at that path (or delete the link), or leave it out with `sync.exclude`. The next sync re-screens it. |+| <a id="file_unreadable-symlink_dangling"></a>`file_unreadable` (`symlink_dangling`) | The path is a symlink whose target does not exist. Classic sync used to drop it silently. | Replace it with the regular file, or delete it and commit. The next sync re-screens it. |+| <a id="file_unreadable-symlink_loop"></a>`file_unreadable` (`symlink_loop`) | The path is a symlink that resolves back to itself. Classic sync used to drop it silently. | Replace it with the regular file, or delete it and commit. The next sync re-screens it. |+| <a id="file_unreadable-permission_denied"></a>`file_unreadable` (`permission_denied`) | gbrain cannot open the file (EACCES or EPERM), for example a file another user owns with mode 000. Before GBRA-133 classic sync blocked the source for three runs, then auto-skipped it. With `sync.holds=fail` it still fails the run as `PERMISSION_DENIED`. | Make it readable to the account gbrain runs as (`chmod u+r -- <checkout>/<path>`, or fix its owner or a parent directory's permissions). The next sync imports it with no commit needed. |+| <a id="file_unreadable-not_regular_file"></a>`file_unreadable` (`not_regular_file`) | The path is a FIFO, socket or device in the working tree, which sync never opens. | Replace it with the regular file, or leave it out with `sync.exclude`. |+| <a id="absent_from_worktree"></a>`absent_from_worktree` | Classic sync held a file the commit names that is missing from the working tree. Before GBRA-133 it was treated as "deleted after the pin" and dropped silently. The rest of the source imports and the bookmark advances; the hold re-screens on every run and clears when the file is back on disk (it imports) or leaves the commit. | Follow the reason row below. The fix is `ask_user`: restoring the file and committing its deletion are both valid. |+| <a id="absent_from_worktree-skip_worktree"></a>`absent_from_worktree` (`skip_worktree`) | A sparse checkout (or a skip-worktree bit set by hand) keeps the committed file off disk. | Ask the user: widen the sparse checkout (`git -C <checkout> sparse-checkout add <dir>`; for a hand-set bit, `git -C <checkout> update-index --no-skip-worktree -- <path>` and `git -C <checkout> restore -- <path>`) and the next sync imports it; or leave it out with `sync.exclude`. Keeping it held is also safe. |+| <a id="absent_from_worktree-deleted_locally"></a>`absent_from_worktree` (`deleted_locally`) | The committed file was deleted from the checkout and the deletion is not committed. | Ask the user: restore it (`git -C <checkout> restore -- <path>`) and the next sync imports it; or commit the deletion (`gbrain git commit-push --path <checkout> -m 'Delete <path>' -- <path>`) and the next sync clears the hold. |+| <a id="unsupported_path"></a><a id="unsupported_path-not_utf8"></a><a id="unsupported_path-control_character"></a>`unsupported_path` (`not_utf8`, `control_character`) | Classic sync: the file's name is not valid UTF-8 (`not_utf8`, a Latin-1 name from an old archive) or contains a control character (`control_character`: a tab, a newline or another byte below 0x20). Git stores a name as bytes and a page path is text, so the file cannot be imported under its own name. Sync reads the diff as bytes (`git diff --raw -z`), never as a lossy decoding: before this the file was checkpointed as "deleted after the pin" with no message (`not_utf8`) or skipped as a malformed name naming no path (`control_character`). The hold key is `/gbrain-bytes/` plus the path with every byte outside a printable UTF-8 character, and every `%`, written `%XX` (`notes/caf%E9.md`); it decodes to the exact bytes and never equals a Git path. The message shows the name C-escaped (`notes/caf\351.md`) with an item id (the first 16 hex digits of the bytes' sha256). The rest of the source syncs and the checkpoint advances. | Rename the file to a valid UTF-8 name without control characters and commit. The fix's `user_message` gives a rename command that spells the old name with printf escapes (`printf 'notes/caf\351.md\000' \| xargs -0 -I{} git mv -- {} 'notes/caf_.md'`, run from the source's checkout), so no raw bytes go on a command line; then `gbrain sync --source <source> --no-pull` imports the file and clears the hold. The hold re-screens on every sync: it stays while a file has that name and clears once the name leaves the tree (renamed, deleted or excluded). |+| <a id="gitlink_not_followed"></a>`gitlink_not_followed` (notice, not a hold) | Classic sync: the range added a gitlink (a submodule or an embedded repository, mode 160000). It records another repository's commit, not files, so its contents are not indexed. Reported once, in the run that passes it: the result's `gitlinks_not_followed` lists the paths and one stderr line names them. Nothing is held and the checkpoint advances. | Nothing to fix. To index the linked repository, check it out and add the checkout as its own source (`gbrain sources add <name> --path <checkout>`). |- | <a id="sync_parser_regression"></a>`sync_parser_regression` | Sync stopped without advancing because it would hold a file whose exact bytes imported before (default `GBRAIN_SYNC_PARSER_REGRESSION=stop`). This is a gbrain bug, not a content problem. | Report it with the gbrain version, the file and the code; upgrade or pin the last good version, then `gbrain sync --source <source> --no-pull`. To keep syncing meanwhile, `gbrain config set sync.parser_regression hold` (ask the user). |+ | <a id="sync_parser_regression"></a>`sync_parser_regression` | Sync stopped without advancing because it would hold a file whose exact bytes imported before (default `GBRAIN_SYNC_PARSER_REGRESSION=stop`). This is a gbrain bug, not a content problem. | Report it with the gbrain version, the file and the code; upgrade, or set `GBRAIN_SYNC_PARSER_REGRESSION=hold` for the process that syncs, and never pin a release older than 0.60.305.0; then `gbrain sync --source <source> --no-pull`. To keep syncing meanwhile, `gbrain config set sync.parser_regression hold` (ask the user). || <a id="takes_holder_invalid"></a>takes holder (`invalid_params`) | `takes_add`, or `takes_supersede` with an explicit `holder`, was given a holder the takes fence cannot carry: empty, whitespace, or not `world`, `brain`, `people/<slug>` or `companies/<slug>` (a legacy bare slug is accepted). The value is trimmed first, so `" world "` is stored as `world`. Nothing was written: before this release such a holder was published into the fence and every later takes write on that page was refused `target_fence_malformed`. A supersede without an override keeps the row's stored holder. A page whose stored holder is already malformed still refuses every takes write (`invalid_fence`); `gbrain repair fences` is the way out. | Resend with a holder in that grammar (`holder: me` on the brain host resolves the owner's holder). For a page already carrying a malformed holder, preview `gbrain repair fences --slug <slug>` and apply it, or edit the `who` cell by hand. Format: [holders](fence-format.md#holders). || <a id="changed_since_preview"></a>`changed_since_preview` | A hash-bound repair apply (`gbrain repair frontmatter --apply --expect <hash>`, `gbrain repair fences --apply --expect <hash>`, `gbrain repair content --apply --expect <h1>[,<h2>]`) found a file, its proposed change or its page different from what the preview showed, so that item was not written; the rest of the approved set still applied. | Preview again with the same selection and apply the new hash (for the content lane, one hash per kind in lane order). For frontmatter, show the user the new diff first; a fence repair needs no extra consent ([fence reason](#fence-changed_since_preview)). |diff --cc src/core/persistence/public-category.tsindex df2ff5a11b,07b68f4e0f..2b81d502b9--- a/src/core/persistence/public-category.ts+++ b/src/core/persistence/public-category.ts@@@ -36,10 -36,8 +36,10 @@@ export const PUBLIC_BY_CODE: Readonly<Rworktree_dirty: 'drift', file_drift: 'drift', source_changed: 'drift', pinned_git_worktree_conflict: 'drift',concurrent_write: 'conflict', revision_conflict: 'conflict', page_identity_changed: 'conflict', legacy_slug_conflict: 'conflict', origin_conflict: 'conflict', origin_conflict_decision: 'conflict',invalid_fence: 'content_refused', invalid_frontmatter: 'content_refused', frontmatter_slug_conflict: 'content_refused', rename_held: 'content_refused',+ rename_identity_unreadable: 'content_refused', rename_reconcile_failed: 'conflict',file_too_large: 'content_refused', content_rejected: 'content_refused', managed_image_sync_unsupported: 'content_refused',- purged_content: 'content_refused', write_gate_rejected: 'content_refused',+ purged_content: 'content_refused', write_gate_rejected: 'content_refused', frontmatter_alias_limit: 'content_refused',+ file_unreadable: 'content_refused', absent_from_worktree: 'file_missing',file_database_drift: 'drift', raw_file_changed: 'drift', pending_import: 'transient',source_binding_changed: 'config', unsafe_file_target: 'config',canonical_file_missing: 'file_missing',diff --cc src/core/persistence/sync-holds.tsindex e815234c1e,5c50e819e2..4697832753--- a/src/core/persistence/sync-holds.ts+++ b/src/core/persistence/sync-holds.ts@@@ -74,8 -71,8 +74,10 @@@ type Exec = Pick<BrainEngine, 'executeRexport type GitHoldCode = ContentRefusal['code'] | 'rename_held' | 'parser_regression' | 'managed_image_sync_unsupported' | 'concurrent_write' | 'preparation_stalled' | 'worktree_dirty' | 'file_drift'| 'legacy_slug_conflict' | 'write_interrupted' | 'origin_conflict'+ /** GBRA-133 PR 1 (classic sync): src/core/classic-rename-holds.ts, src/core/classic-file-holds.ts and src/core/sync-byte-paths.ts. */- | 'rename_identity_unreadable' | 'rename_reconcile_failed' | 'file_unreadable' | 'absent_from_worktree' | 'unsupported_path';++ | 'rename_identity_unreadable' | 'rename_reconcile_failed' | 'file_unreadable' | 'absent_from_worktree' | 'unsupported_path'+ /** #6712 PR 4b (S-47): bytes an older gbrain imported and validated whose frontmatter aliases expand past #7018's bound; held alone, never a parser regression. */+ | 'frontmatter_alias_limit';/*** Flip lane C: the holds of a write that ran out of attempts, its preparation never settling (`preparation_stalled`)* or its statements ended by the database every time (`write_interrupted`). The file is not the problem: they route to