Garry's Opinionated OpenClaw/Hermes Agent Brain
Page identity and writer administration
Back to the index. Read this contract alongside the page-operation entries when changing source identity, snapshot selection, or deliberate ownership administration.
Binding owner epochs and topology generations are cast to exact decimal strings
before resident IPC serialization, preserving values above JavaScript's safe
integer range. Reviewed admin-state fingerprints include legacy-lock identity.
Self-transfer preparation records physical before-state and intended repair in
a durable manifest; acceptance checks root, epoch, manifest and coordination
path under the native lock from the database binding. A private token-bound
temporary stamp is byte-verified before rename; changed tokens and malformed
records refuse without deleting uncertain state. Regression coverage:
test/persistence-admin-recovery.test.ts, test/persistence-onboarding.test.ts,
test/persistence-container-preflight.test.ts.
src/core/deep-research-id.ts— canonicalgbrain-page:v1:handles encode a An id may carry a read anchor as a third payload element ({c: chunk_id}for a search hit past the first chunk,{w: cursor}for a fetch continuation);decodeDeepResearchIdreturns the same page key with or without it anddecodeDeepResearchAnchorreturns the anchor. JSON pair of source ID and slug in unpadded base64url. The decoder rejects malformed or noncanonical encodings rather than treating them as legacy slugs. IDs are logical addresses, not credentials, revisions or encrypted metadata. Citation URLs escape each path segment. See the wire protocol.src/core/persistence/admin-intent.ts— whole-brain topology fingerprints bind a deliberate writer action to inspected state. Administration requires an exact action name and a fresh fingerprint; the mutation transaction rechecks it under metadata locks. Generic confirmation and terminal presence are not substitutes. This protects routine repair from accidental topology changes, not against a malicious trusted local administrator. Read the operator procedure before changing its preconditions.src/core/persistence/onboarding.ts+legacy-locks.ts+physical-root-recovery.ts— read-only source onboarding states; exact same-host dead-lock cleanup under explicit activation opt-in; and state-bound same-owner root repair using a durable manifest and token-verified temporary stamp. #5914:inspectPhysicalRootRecovery(root, identity, { relocated })(--confirm-relocated-root) waives only the inode/birth comparison, requires the outside-root reservation and every other field to agree, returns the reservation with the live directory identity and marks the recoveryrelocated: true;repairPhysicalRootthen rewrites the reservation throughphysical-root-record.tsreplacePhysicalRootReservation(compare-and-swap: already-equal is a no-op, anything else refuses with detailstale_record) before adopting the stamp.physical-root-record.tsalso holdsassertPhysicalRootReservation(native-lock callers that publish nothing: reservation worktree id plus stamp token, no inode),readRecordedPhysicalRootReservation,inspectRelocatedPhysicalRootandrelocatePhysicalRoot(P1.3c: a recorded path that now resolves through a symlink keeps its worktree; the reservation moves under the newsha256(root)name and the stamp names the new root). #8625:describeMovedPhysicalRoot(root)reads only files: a stamp whose recorded root is gone, with the reservation of that root beside it (the checkout moved) or besideroot(a renamed parent carried it; the moved pair is cut by common path suffix), token, brain and worktree agreeing, andsameDirectoryfrom device, inode and birth; never ownership authority and never the token.physicalRootMovedErroris the path-free refusal (PHYSICAL_ROOT_MOVED_MESSAGE, detailphysical_root_moved);physicalRootMovedRefusalis the local CLI one naming the recorded path, worktree, sources and anask_userfix chain (symlink,set-pathfor the first source,rm, thenset-pathfor the rest; ormvback andadd/writer claim; or, for a copy whose source was removed,writer deactivate --dry-run).physical-root.tsmovedPhysicalRootadds the database side (this brain, worktree owned by the host, host binding at the recorded root, members) andreservePhysicalRootthrows the path-free refusal on its copied-marker branch, which remote page writes reach through the automatic claim;movedPhysicalRootRefusalbuilds the full one, whichsource-lifecycle.tsraises for a rebind whose missing recorded checkout is stamped at the new path and in place of the claim's path-free refusal (caught aroundwithTopologyLocks, except for the automatic first-write claim), andwriter claimraises the same way. The dry runs predict both:inspectTopologyPhysicalRoottakes the operation, and add, claim andwriter claim --dry-runruntopology-locks.tsinspectClaimedPhysicalRoot(the copied-marker probe of a root no local binding encloses, atclaimedWorktreeRoot); a rebind dry run of a missing recorded checkout refuses as the real run does. Tests:test/physical-root-moved-8625.test.ts.physical-root.tsrestampPhysicalRoothandles a filesystem device id that changed while the owner token, brain, worktree, root, inode and a non-zero birth time still match (macOS can renumberst_devacross reboots): under the caller's outside-root native lock, one transaction verifies owner host, brain and host binding and rewrites the recorded self-transfer copies and retained topology staging identities (each only while it still names the old device); after commit the stamp and the reservation's initial device are rewritten and the event is logged, so an interruption between the two leaves a device-only change the next locked acquisition finishes. Ownership markers inside a retained topology clone stage are not re-stamped; an interrupted clone recovery that spans a device renumbering still needs source recovery.assertPhysicalRootstays read-only; zero birth time or any other difference keeps the refusal.--self-transferprepare/accept requires separate fresh reviewed state, preserves original reservation owner evidence and refuses uncertain records. Tests:test/persistence-onboarding.test.ts,test/persistence-admin-recovery.test.ts,test/persistence-container-preflight.test.ts.src/core/persistence/coordination-lock.ts— the one resolver of a worktree's native coordination lock path, used byclaimWorktree,reservePhysicalRoot(managed claim and clone),runManagedSourceCloneandacceptWriterTransfer.resolveCoordinationLock(root, worktreeId, { reservation, binding }, hostId)returns{ path, rule }: the recorded reservation path (always wins over env), then a transfer's recorded binding path when absolute, canonical and outside the root, thencoordinationLockDirectory:persistenceHome()/lockswhen outside the canonical root (persistence_home), else$GBRAIN_COORDINATION_HOME/locks/<sha256(root\0host)[:32]>(coordination_home, absolute and no.., elseinvalid_params) or~/.gbrain/persistence/locks/<namespace>(home_default); a result still inside the root refusesstorage_errorbefore any reservation is written.GBRAIN_COORDINATION_HOMEis on the cwd.envquarantine list.repairWedgedReservation(engine, root, hostId)(called beforeclaimWorktree's transaction and at the top ofreservePhysicalRoot) returns at once for a missing or healthy reservation; for one whose recorded lock is inside the root (physical-root-record.tsreadWedgedPhysicalRootReservation) it takes the env-independent guardreservationRepairGuardPath(beside the reservation, 2 s wait, elsewriter_lock_unavailable), re-checks, requires the brain id, the claiming host id and nopersistence_worktreesrow, andrepairReservationCoordinationPathrewrites onlycoordinationPath(digest re-read before the atomic rename,stale_recordotherwise).onboarding.tsreports each source'scoordination_lock(path,rule,old_path_wedge, or thedirectoryan unclaimed root would use; never mints a host id) and uses it for the storage preflight'scoordination_directory. Tests:test/coordination-lock.serial.test.ts.coordinationHomeIgnored(root, recorded)reports a setGBRAIN_COORDINATION_HOMEthat applies to the root (rule 4) but names another directory than the recorded lock (configured_directory,recorded_path,move_step); writer status adds it ascoordination_lock.coordination_home_ignored.src/commands/doctor/checks/coordination-lock.ts— doctorcoordination_lock_location(read-only): warns, per source checkout or host binding of this host, whencoordinationHomeIgnoredreports the recorded lock wins overGBRAIN_COORDINATION_HOME, naming the recorded path and the move step. Test:test/coordination-lock.serial.test.ts.
stampDeepResearchIds uses each result's own source, including query fallback
and image paths. fetch independently applies the current source grant and
visibility policy. Legacy slugs resolve only when one readable live page
matches; snapshot content, identity and ambiguity count come from one SQL
statement. An encoded ID never falls back to another source. Source aliases
remain source-bound.
writer_status reads an existing host identity without creating one. Claim,
activate and transfer are explicit local administration paths; ordinary page
errors, startup and doctor --fix lead with inspection, not ownership changes.
The CLI uses the shared BigInt replacer when rendering PostgreSQL epochs.
Behavioral coverage lives in test/helpers/deep-research-contract.ts, its
PGLite/Postgres callers, test/e2e/deep-research-http.test.ts (live OAuth
rescoping/revocation), test/deep-research-cli.test.ts,
test/persistence-admin-intent.test.ts, and
test/e2e/persistence-admin-intent.test.ts (actual routine and deliberate CLI
sequences). These tests establish the exercised boundaries, not a universal
authorization guarantee.
Installation and metadata migrations
The upgrade and migration command entries also carry the memory-only opt-out:
GBRAIN_NO_AUTOPILOT_INSTALL=1 / --no-autopilot-install is propagated through
package installation, post-upgrade and migration orchestration. It skips service
installation and unit rewrites, not unrelated migration work. Paid reindexing
has its own GBRAIN_NO_REEMBED=1 control.
src/commands/migrations/v0_13_1.ts writes nothing (#7814). It used to stamp
validate: false into every page's frontmatter, which an upgrade ran on any
brain whose ledger never recorded v0.13.1 and which moved every content_hash.
The orchestrator now records completion only, and a queued
managed_grandfather request from an older binary ends conflict without
writing (src/core/persistence/grandfather.ts).
test/upgrade-preserves-pages-7814.slow.test.ts (PGLite) and
test/e2e/upgrade-preserves-pages-7814-postgres.test.ts upgrade a
v0.59.2.0-shaped brain, repo-less and repo, and assert no page changes.
Write request ids
src/core/persistence/preconditions.ts—parseWriteRequestId, the one place a write op'srequest_idis normalized (F6, Cat 40 Hard): a UUID passes through lowercased, any other id of 1-128 printable ASCII characters maps to its RFC 4122 UUIDv5 underCLIENT_REQUEST_ID_NAMESPACE(no operation name, so receipt lookups find a write by the client's string);clientRequestIdOfis the string admissions store inpersistence_requests.client_request_id(v238, outside the intent digest, kept by compaction) and receipts echo asclient_request_id. Administration writer/deactivation ids keep strict UUID checks.remember(items)derives child ids from the root string as sent (childRequestId). Tests:test/persistence-client-request-id.test.ts,test/e2e/persistence-client-request-id-postgres.test.ts.
Suffixed slugs
src/core/persistence/suffixed-slug.ts—.md/.mdx-suffixed slugs (#4807).preparePageAdmissionrefuses a new put_page/put_pages slug ending in.md/.mdxbefore any journal row (invalid_params, why, suggestion naming the bare slug, read-onlyget_pagefix and verify); a live page with that exact (source_id, slug) still updates and the put_page response carriesslug_advisory(put under the bare slug, then delete_page).suffixedSlugDryRunserves put_page dry runs;suffixedFrontmatterSlugHoldholds a file import whose frontmatterslug:identity ends in.mdasfrontmatter_slug_conflict. The same admission refuses a NEW slug with a Windows reserved device segment or a segment over 240 bytes (slug_not_portable, suggestion fromportable-slug.ts); a live page with that slug still updates and gets aslug_advisorynaming the move.:stays valid slug grammar. #7305: put_page and capture (theoperationargument; capture checks only this rule) refuse a NEW slug thatsync.tshyphenFoldedSlugchanges (a hyphen run or a segment-final hyphen, which slugifySegment folds) with detailslug_hyphen_runand the folded slug as suggestion and read-only fix; a live exact page keeps updating with aslug_advisory;suffixedSlugDryRunserves both dry runs.validateSlugand path-derived import slugs are unchanged. Tests:test/ingestion/put-page-write-through.test.ts,test/pathological/b5-export-unsafe-slugs.test.ts,test/pathological/b12-slug-segment-bytes.test.ts,test/hyphen-run-slugs-7305.test.ts.src/commands/doctor/checks/slug-path-mismatch.ts— #7305 doctorslug_path_mismatch(BRAIN, afterorigin_twins): live file-backed pages of unarchived sources (scoped bydoctorSourceIds) whose slugresolveSlugForPath(source_path)does not reproduce, such as a hyphen run the path rule folds. One read of candidate rows (slug regex prefilter, id order,SLUG_PATH_SCAN_LIMIT20,000), then at mostSLUG_PATH_FILE_LIMIT(200) recorded files read on this host (bound worktree, elselocal_path, elsesync.repo_pathfor default) to tell a file stamped with the page'sslug:line from an unstamped one. Unstamped files warn with counts, up to 5 samples (nosource_pathfor a remote caller) and anagentFixnaming the read-onlygbrain repair frontmatter --source <id> --jsonpreview; a hit bound with nothing unstamped is the #7145 bounded unknown; stamped, missing or not-checked-out files are ok. Read-only. Test:test/doctor-slug-path-mismatch-7305.test.ts(PGLite + Postgres viatest/e2e/doctor-slug-path-mismatch-7305-postgres.test.ts).src/core/portable-slug.ts— the one slug portability rule (GBRA-130 B-5/B-12):FILE_NAME_MAX_BYTES(240, a name's byte budget; a leaf also reserves.json),RESERVED_DEVICE_NAME(con, prn, aux, nul, com1-9, lpt1-9, alone or before an extension),truncateUtf8,portableSegment(a reserved name gets-<suffix>, an over-budget segment is cut at a code point boundary) andslugPortabilityProblem(reason, first segment, suggested slug). Used bypersistence/suffixed-slug.tsadmission;enrichment-service.tsslugifyEntityuses its parts, so a reserved entity name mintspeople/con-personorcompanies/com1-companyand an over-budget one ends in a hash of the full name.enrichEntityreuses a page at a slug another entity also maps to (Aux Companyatcompanies/aux-company) only when its title names the entity, preferring the matching legacy page (or, for a long name, the untagged cut slug an older gbrain minted, when its title maps to the same full slug), else uses the hash-tagged slug or skips withentity_slug_taken(F8,test/pathological/b5-enrich-entity-identity.test.ts).