Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript
9.1 KB
Raw Blame

Key files: Core Cycle (continued)

Subsystem index · Previous entries. Read only the entries relevant to your change. Current behavior and load-bearing invariants; history belongs in Git and CHANGELOG. Synthesis, patterns, consolidation and connector atom gating.

  • src/core/cycle/synthesize-postprocess.ts — Managed synthesis quote repair and provenance stamping publish together through a deterministic maintenance request bound to the source incarnation, transcript hash, child output, and original committed page revision. loadCommittedSynthesisOutputs finds each child's committed output by canonicalizing the retained brain_put_page input (parseWriteRequestId for the request id, journaledPageSlug for the slug) before matching request id, source, incarnation, committed put_page, slug and revision (#6616); slug discovery (collectChildPutPageSlugs) and postprocessing share that set. The immutable committed receipt is the completion checkpoint: later runs skip finalized output rather than repairing user edits. Pending work replays its retained intent under the original revision and existing authority/file guards; missing provenance fails closed. A publish still write_pending after the job's shared maintenance wait is deferred, never written or finalized: withPublishPending turns the phase result into warn with publish_pending and SYNTH_PUBLISH_DEFERRED ("publish deferred (writer busy); finishes next cycle, no action needed"), synthesize.ts leaves dream.synthesize.last_completion_ts unstamped, and the next ordinary cycle resumes the same deterministic request id. Runs the same claim verification as the unmanaged path (groundSource + resolveVerifyPrior + verifyDreamPage from synthesize-verify.ts, scoped by the ref's first_write_at, else the child write epochs passed as sinceByTranscript) and stamps the dream provenance fields only on dream-owned pages (isDreamOwnedPage); the published page reconciles its automatic links like an ordinary put_page (page-prepare.ts treats managed_maintenance_page intents as auto-linked); the unmanaged path retains its fail-open behavior. Covered by test/managed-synthesis-postprocess.test.ts and its PostgreSQL E2E wrapper. The optional grounding pass (System One S8) runs after verifyDreamPage and before publishMaintenancePage, so the published revision never carries a unit S8 quarantined; pinned by test/decide/writepath-phase.serial.test.ts. The postprocess stamps the transcript's seat next to raw_source on dream-owned output. deferPublishOrThrow defers an output or summary publish that is still pending, whose admission gave up on database contention (publicationHold in persistence/accepted-pending.ts), or whose unadmitted request was refused queue_capacity by a positive principal or brain outstanding-request cap (isWriteCapacityWait + outstandingCapacityOf, no write receipt) exactly like the pending case: publish_pending, phase warn, no cooldown stamp, and the next cycle retries the same request id; a contended or capacity-blocked publish writes one stderr line. A zero cap, cumulative quotas, unknown capacity, a capacity refusal carrying a receipt and every other error fail the phase. Pinned by test/managed-synthesis-postprocess.test.ts. #5575 I2: each output publishes with derivation from its transcript (dream-taint.ts transcriptDerivation; meetingTranscriptsDir in opts); a retained request replays the declaration it was admitted with. #6360: when the page moved after the child commit, a drift made only by committed local managed_maintenance_page requests (for example the next cycle's lint created: fix) over a body equal to the child's is adopted: the postprocess runs on the current snapshot under a request id that also binds that base revision (found again on replay among the later requests). Any other later write leaves the page alone as a PostprocessConflict (withPostprocessConflicts: phase warn, details.postprocess_conflicts with the read-only gbrain get fix); it is reported once (config dream.synthesize.postprocess_conflicts, 30-day memory) and does not block the cooldown stamp. #6757: the committed-outputs join (COMMITTED_OUTPUT_REQUESTS_SQL) compares request_id as a uuid within the source, served by persistence_requests_request_id. The phase loads it through loadCommittedOutputsOrDefer; a statement timeout there, or on an output's own getWriteRequest, defers the pass instead of failing it (withPublishPending with details.postprocess_deferred: phase warn, no cooldown stamp, no summary). Deferred and publish-pending outputs are carried by synthesize-postprocess-deferral.ts and finished by a later pass from the carried fields, with no child; finishDeferredPostprocess (run after the phase body by runPhaseSynthesize) finishes them when that pass returned before postprocessing. GBRA-130 A-4: outputs run as ItemRun items (synthesize.postprocess). A postprocess request that ended conflict, failed or cancelled, or whose retained intent no longer matches, is a PostprocessConflict (the request's error_code, else recovery_required; fix gbrain write-request -- <id>) dropped from the pending row; the summary names each slug and code. Other item errors let the rest run and the pass save, then fail the phase; run-scoped errors and item_failures_systemic stop it and record nothing. Pinned by test/pathological/a4-synthesize-postprocess.test.ts. #8110: the earlier postprocess request found among the later requests settles from that row, not a lookup by the current principal, so one made by a local CLI writer registration that gbrain auth local-writer register cli --replace revoked still settles; it is authorized under the current local CLI writer's live grant, and a remote principal's row never qualifies. A child output whose writer registration was revoked or no longer grants the page is a permission_denied PostprocessConflict (fix gbrain auth local-writer list --json).
  • src/core/cycle/synthesize-postprocess-deferral.ts — #6757: config row dream.synthesize.postprocess_pending, keyed by source and bound to its incarnation: each pending output (child request id, journaled and input slug, revision, job key, transcript path, content hash, seat, first write) and the source's consecutive deferred passes with the last read and its elapsed time. isPostprocessReadTimeout unwinds a cancelled cycle first, then accepts only SQLSTATE 57014 with the statement-timeout message (a user cancel is not deferred). recordPostprocessPass drops settled outputs, adds deferred and carried ones and resets the count on a pass that deferred nothing; repeatedPostprocessDeferrals lists sources at three or more for doctor persistence_request_indexes. The replay runs no child job and verifies a replayed output's quotes against the transcript as it is now, even when it grew after synthesis; a quote not found there goes to unverified_claims like any failed quote.
  • src/core/cycle/dream-write-deferral.ts — W3 (#7587): config row dream.write_deferral.pending, keyed <phase>:<source>. A purge or consolidate write accepted but still pending after its publish wait (maintenancePublishWaitMs) is recorded with its request id (deferDreamWrite); the next pass's reconcileDreamWriteDeferrals reads each receipt before anything is submitted: committed clears it, a terminal failure is reported with its real code and not resubmitted that pass, still pending holds the source (nothing new submitted) and counts a replay. At DREAM_WRITE_DEFERRAL_MAX_REPLAYS (3) doctor's dream_write_deferred (src/commands/doctor/checks/dream-write-deferred.ts) warns with the receipt and gbrain write-request -- <id>. dream.write_deferral.enabled=false restores the failing phase. Audit rows go to src/core/heal-audit.ts (config heal.audit, 200 rows, 30 days) in the same transaction. Tests: test/dream-write-deferral-w3.test.ts (PGLite, Postgres, repo and repo-less).
  • src/core/embedding-restamp.ts — W3 (#5527 class): restampCurrentSpaceSignatures runs at the start of the cycle embed phase (never on upgrade, skipped in dry runs) and sets pages.embedding_signature on up to 500 pages per run whose every chunk already holds a current-model vector (currentSpaceChunkPredicate), with no provider call. Each stamp takes lockPageKeys and re-checks the selected revision and signature, the sealed text projection, the active column and every chunk, so a concurrent edit or re-embed makes it match nothing (rejected). Three failed runs in a row escalate to doctor embedding_restamp_stalled (src/commands/doctor/checks/embedding-restamp.ts); embed.restamp.enabled=false turns it off. Tests: test/embedding-restamp-w3.test.ts.
  • src/core/cycle/bookkeeping-gc.ts — the bookkeeping_gc phase, split out of purge with the same functions and retentions (op and brainstorm checkpoints, batch-retry audit files, volunteer events, decision receipts, applied captures, retrieval feedback); it never touches a page, so unattended upkeep runs it.

Patterns, drift and the entries after them: Core Cycle (patterns).