Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
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.loadCommittedSynthesisOutputsfinds each child's committed output by canonicalizing the retainedbrain_put_pageinput (parseWriteRequestIdfor the request id,journaledPageSlugfor 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 stillwrite_pendingafter the job's shared maintenance wait is deferred, never written or finalized:withPublishPendingturns the phase result intowarnwithpublish_pendingandSYNTH_PUBLISH_DEFERRED("publish deferred (writer busy); finishes next cycle, no action needed"),synthesize.tsleavesdream.synthesize.last_completion_tsunstamped, and the next ordinary cycle resumes the same deterministic request id. Runs the same claim verification as the unmanaged path (groundSource+resolveVerifyPrior+verifyDreamPagefromsynthesize-verify.ts, scoped by the ref'sfirst_write_at, else the child write epochs passed assinceByTranscript) 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.tstreatsmanaged_maintenance_pageintents as auto-linked); the unmanaged path retains its fail-open behavior. Covered bytest/managed-synthesis-postprocess.test.tsand its PostgreSQL E2E wrapper. The optionalgroundingpass (System One S8) runs afterverifyDreamPageand beforepublishMaintenancePage, so the published revision never carries a unit S8 quarantined; pinned bytest/decide/writepath-phase.serial.test.ts. The postprocess stamps the transcript'sseatnext toraw_sourceon dream-owned output.deferPublishOrThrowdefers an output or summary publish that is still pending, whose admission gave up on database contention (publicationHoldinpersistence/accepted-pending.ts), or whose unadmitted request was refusedqueue_capacityby 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 bytest/managed-synthesis-postprocess.test.ts. #5575 I2: each output publishes withderivationfrom its transcript (dream-taint.tstranscriptDerivation;meetingTranscriptsDirin 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 localmanaged_maintenance_pagerequests (for example the next cycle's lintcreated: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 aPostprocessConflict(withPostprocessConflicts: phasewarn,details.postprocess_conflictswith the read-onlygbrain getfix); it is reported once (configdream.synthesize.postprocess_conflicts, 30-day memory) and does not block the cooldown stamp. #6757: the committed-outputs join (COMMITTED_OUTPUT_REQUESTS_SQL) comparesrequest_idas a uuid within the source, served bypersistence_requests_request_id. The phase loads it throughloadCommittedOutputsOrDefer; a statement timeout there, or on an output's owngetWriteRequest, defers the pass instead of failing it (withPublishPendingwithdetails.postprocess_deferred: phase warn, no cooldown stamp, no summary). Deferred and publish-pending outputs are carried bysynthesize-postprocess-deferral.tsand finished by a later pass from the carried fields, with no child;finishDeferredPostprocess(run after the phase body byrunPhaseSynthesize) finishes them when that pass returned before postprocessing. GBRA-130 A-4: outputs run asItemRunitems (synthesize.postprocess). A postprocess request that ended conflict, failed or cancelled, or whose retained intent no longer matches, is aPostprocessConflict(the request'serror_code, elserecovery_required; fixgbrain 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 anditem_failures_systemicstop it and record nothing. Pinned bytest/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 thatgbrain auth local-writer register cli --replacerevoked 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 apermission_deniedPostprocessConflict(fixgbrain auth local-writer list --json).src/core/cycle/synthesize-postprocess-deferral.ts— #6757: config rowdream.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.isPostprocessReadTimeoutunwinds a cancelled cycle first, then accepts only SQLSTATE 57014 with the statement-timeout message (a user cancel is not deferred).recordPostprocessPassdrops settled outputs, adds deferred and carried ones and resets the count on a pass that deferred nothing;repeatedPostprocessDeferralslists sources at three or more for doctorpersistence_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 tounverified_claimslike any failed quote.src/core/cycle/dream-write-deferral.ts— W3 (#7587): config rowdream.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'sreconcileDreamWriteDeferralsreads 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. AtDREAM_WRITE_DEFERRAL_MAX_REPLAYS(3) doctor'sdream_write_deferred(src/commands/doctor/checks/dream-write-deferred.ts) warns with the receipt andgbrain write-request -- <id>.dream.write_deferral.enabled=falserestores the failing phase. Audit rows go tosrc/core/heal-audit.ts(configheal.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):restampCurrentSpaceSignaturesruns at the start of the cycle embed phase (never on upgrade, skipped in dry runs) and setspages.embedding_signatureon up to 500 pages per run whose every chunk already holds a current-model vector (currentSpaceChunkPredicate), with no provider call. Each stamp takeslockPageKeysand 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 doctorembedding_restamp_stalled(src/commands/doctor/checks/embedding-restamp.ts);embed.restamp.enabled=falseturns it off. Tests:test/embedding-restamp-w3.test.ts.src/core/cycle/bookkeeping-gc.ts— thebookkeeping_gcphase, split out ofpurgewith 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).