Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Integrate #6024/#6032 under the wave's guards: merge-queue scope for the crash robot, unit-postgres lane for attribution-backfill-history, serial manifest row, typed f4d report, doc paths; drop 0.60.56.0 CHANGELOG claims that shipped in 0.60.53.0

garrytanfaccf3b2c5b3
diff --git a/.github/workflows/persistence-validation.yml b/.github/workflows/persistence-validation.yml
index 3de721e0fb..a3ca726744 100644
--- a/.github/workflows/persistence-validation.yml
+++ b/.github/workflows/persistence-validation.yml
@@ -205,6 +205,7 @@ jobs:
: "${DATABASE_URL:?unit-lane PostgreSQL arms require the explicit test database}"
case "$SHARD" in
1) files=(
+ test/attribution-backfill-history.test.ts
test/colon-slug-windows-5032.test.ts
test/decide/conflict-proposals-managed.test.ts
test/declared-lineage-visibility.test.ts
@@ -357,7 +358,7 @@ jobs:
bun: ['1.4.0', '1.4.2']
# Pull requests run the primary Bun version; pushes, schedules and
# manual runs keep every supported version.
- exclude: ${{ fromJSON(github.event_name == 'pull_request' && '[{"bun":"1.4.0"}]' || '[]') }}
+ exclude: ${{ fromJSON((github.event_name == 'pull_request' || github.event_name == 'merge_group') && '[{"bun":"1.4.0"}]' || '[]') }}
services:
postgres:
image: pgvector/pgvector:pg16
@@ -394,7 +395,7 @@ jobs:
PGPASSWORD: gbrain_test
DATABASE_URL: postgres://[email protected]:5432/gbrain_test
GBRAIN_PGBOUNCER_URL: postgres://[email protected]:55433/gbrain_test
- ROBOT_SECONDS: ${{ github.event_name == 'pull_request' && '150' || '600' }}
+ ROBOT_SECONDS: ${{ (github.event_name == 'pull_request' || github.event_name == 'merge_group') && '150' || '600' }}
run: >-
bun --no-env-file scripts/persistence/validate.ts --engine=${{ matrix.engine }}
--schedules=0 --operations=0 --no-crashes --robot-seconds="$ROBOT_SECONDS"
diff --git a/docs/architecture/key-files/core-persistence.md b/docs/architecture/key-files/core-persistence.md
index ccfee7034f..919b198a2f 100644
--- a/docs/architecture/key-files/core-persistence.md
+++ b/docs/architecture/key-files/core-persistence.md
@@ -56,7 +56,7 @@ Connector ingestion, item holds and checkpoint validation continue in [Core Pers
- `src/core/persistence/{source-lifecycle,managed-sources,topology-schema,topology-locks,topology-receipts,topology-clone,topology-clone-model,topology-filesystem,topology-recovery}.ts` — migration 157 coordinates source add/claim/archive/restore/remove/purge/rebind/reclone. Native root locks precede topology/source/grant/counter/request guards; a shared root advances every membership and permanently conflicts accepted old-topology requests. Withdrawal mirrors and running publication must settle first. Administrative UUIDs share the page journal's principal-scoped conflict domain and permanent capacity counters. Directory replacement reserves the configured recovery budget before provider/staging work, records a verified manifest and physical identity, and recovers only known bytes; clone failure retains the original checkout and a replayable failure receipt. Rebinding accepts a fresh candidate with exactly matching canonical content, including deletions. Stored worktree manifests and clone recovery records keep `digest`, `file_count`, `canonical_stamp` and `self_transfer` but no per-file map (#5790), so their size is independent of the worktree; `compactStoredManifest` drops a legacy map on rewrite, and transfer prepare/accept hash under the native lock before their transaction. Large-repo tests: `test/persistence-large-manifest.test.ts` (12k files, both engines via `test/e2e/persistence-large-manifest-postgres.test.ts`) and `test/e2e/persistence-large-manifest-50k.test.ts`. Old root refusal records remain. Metadata deletion retains local storage. Restart recovery rotates a bounded root scan so one conflict cannot starve other roots. Tests: `test/persistence-source-lifecycle.test.ts` on PGLite and guarded isolated Postgres.
-- `src/core/persistence/{worktree-refresh,worktree-refresh-schema}.ts` — `gbrain sources refresh` (F0), the one sanctioned managed Git writer. `persistence_worktree_refreshes` holds one row per refresh with a partial unique index (one active refresh per worktree; its 23505 maps to `refresh_in_progress`). `refreshWorktree` prechecks with no database state (managed, owner host, upstream, no active refresh, no recovery, no unexhausted managed-sync cursor, hardened `git fetch` bounded by `sources.refresh_fetch_timeout_ms`, ancestry, dirty paths intersected with the incoming diff), then: `draining` (inserted under `withTopologyLocks` + `lockTopologyRows`; admission in `journal.ts` refuses `worktree_refreshing` for every request with that `worktree_id`, and `assertManagedSyncAllowed` refuses a managed sync before discovery), poll until no queued/running/recovering request, no queued/running `git`/`withdrawal-mirror` effect and no recovery record remain (else `refresh_drain_timeout`, aborted), `fenced` (both native locks held, rechecked in one transaction; `refreshFenceClear` stops request and effect claims), HEAD verified, dirt rechecked, `git merge --ff-only`, HEAD verified again, then one transaction `merged` + upstream observation + `syncing`; native locks are released and the managed `--no-pull` sync runs per member (only `managed_sync_*` `submit_job` admissions pass during `syncing`); `completed` when every member's `last_commit` is the target, or with `outcome.sync_blocked` when a member sync blocks. A per-worktree `refresh-<worktree>.lock` held for the whole run proves liveness: `resumeWorktreeRefreshes` (called from `recoverSourceTopologies`, so on owner start) touches only interrupted `draining`/`fenced`/`merged` rows whose lock is free and applies the section 1.5 table (draining or fenced at the old HEAD abort; HEAD at the verified target moves to `syncing`; anything else is `recovery_required`, which admission refuses with `refresh_recovery_required`). Admission also completes a `syncing` row whose members all reached the target. `--resume` converges and runs the member syncs; `--abandon` lifts a fence only with HEAD back at the start commit. `gbrain sources writer status` lists active refreshes as `worktree_refreshes` (state, heads, the next command), which the refusal hints point at. Doctor `worktree_refresh_stuck` lists rows active over 15 minutes. CLI body: `src/commands/sources-refresh.ts`; while a resident PGLite owner (`gbrain serve`, stdio MCP) holds the database, `src/commands/sources-refresh-delegate.ts` runs the refresh inside it through the `writer_refresh` administration operation (trusted CLI registration only) and prints the same result or refusal. The consumer's idle probe applies `refreshFenceClear` to effects like the claims, so a fenced worktree's queued effects do not wake it. Tests: `test/persistence-worktree-refresh.test.ts`, `test/persistence-worktree-refresh-restart.test.ts` (child-process crash after merge), Postgres via `test/e2e/worktree-refresh-postgres.test.ts`, owner delegation in `test/persistence-sync-stdio-owner.serial.test.ts`.
+- `src/core/persistence/{worktree-refresh,worktree-refresh-schema}.ts` — `gbrain sources refresh` (F0), the one sanctioned managed Git writer. `persistence_worktree_refreshes` holds one row per refresh with a partial unique index (one active refresh per worktree; its 23505 maps to `refresh_in_progress`). `refreshWorktree` prechecks with no database state (managed, owner host, upstream, no active refresh, no recovery, no unexhausted managed-sync cursor, hardened `git fetch` bounded by `sources.refresh_fetch_timeout_ms`, ancestry, dirty paths intersected with the incoming diff), then: `draining` (inserted under `withTopologyLocks` + `lockTopologyRows`; admission in `journal.ts` refuses `worktree_refreshing` for every request with that `worktree_id`, and `assertManagedSyncAllowed` refuses a managed sync before discovery), poll until no queued/running/recovering request, no queued/running `git`/`withdrawal-mirror` effect and no recovery record remain (else `refresh_drain_timeout`, aborted), `fenced` (both native locks held, rechecked in one transaction; `refreshFenceClear` stops request and effect claims), HEAD verified, dirt rechecked, `git merge --ff-only`, HEAD verified again, then one transaction `merged` + upstream observation + `syncing`; native locks are released and the managed `--no-pull` sync runs per member (only `managed_sync_*` `submit_job` admissions pass during `syncing`); `completed` when every member's `last_commit` is the target, or with `outcome.sync_blocked` when a member sync blocks. A per-worktree `refresh-<worktree>.lock` held for the whole run proves liveness: `resumeWorktreeRefreshes` (called from `recoverSourceTopologies`, so on owner start) touches only interrupted `draining`/`fenced`/`merged` rows whose lock is free and applies the section 1.5 table (draining or fenced at the old HEAD abort; HEAD at the verified target moves to `syncing`; anything else is `recovery_required`, which admission refuses with `refresh_recovery_required`). Admission also completes a `syncing` row whose members all reached the target. `--resume` converges and runs the member syncs; `--abandon` lifts a fence only with HEAD back at the start commit. `gbrain sources writer status` lists active refreshes as `worktree_refreshes` (state, heads, the next command), which the refusal hints point at. Doctor `worktree_refresh_stuck` lists rows active over 15 minutes. CLI body: `src/commands/sources-refresh.ts`; while a resident PGLite owner (`gbrain serve`, stdio MCP) holds the database, `src/commands/sources-refresh-delegate.ts` runs the refresh inside it through the `writer_refresh` administration operation (trusted CLI registration only) and prints the same result or refusal. The consumer's idle probe applies `refreshFenceClear` to effects like the claims, so a fenced worktree's queued effects do not wake it. Tests: `test/persistence-worktree-refresh.test.ts`, `test/persistence-worktree-refresh-restart.test.ts` (child-process crash after merge), Postgres via `test/e2e/worktree-refresh-postgres.test.ts`, owner delegation in `test/persistence-sync-stdio-owner.test.ts`.
- `src/core/persistence/{types,params,preconditions,verb-errors}.ts` — public mutation receipt states, error reasons and revision/idempotency parameter contracts. Receipt serialization explicitly selects public fields; queued content and execution credentials stay internal. `frozenVerbWriteError` uses MEMORY_VERBS v1's existing error enum with additive `write_request`/`write_error`; `committedVerbOutcome` refuses pending or failed receipts. `OperationError` and the thin MCP client preserve this metadata, including when a timeout races an already-received receipt. The registry-safe parameter/schema leaf never imports operation values. Pinned by `test/persistence-write-contracts.test.ts`, `test/mcp-client-hardening.test.ts` and a real HTTP envelope in `test/mcp-client.test.ts`.
- `src/core/persistence/{database-write,manual-links}.ts` — `coordinatedDatabaseWrite` is the managed path for rows with no canonical file; `coordinatedManualLinkWrite` (`add_link` / `remove_link`) and `ontology_propose` (one entity page key) use it. On a managed brain it checks the caller's durable write authority for the authority page (`submissionAuthority`, then `authorizeWrite` FOR SHARE inside the transaction), revalidates the source incarnation and commits inside `withCoordinatedWrite` holding the given page keys (both link endpoints). Unmanaged brains keep the engine calls. Manual edges (`link_source` `manual` or a custom tag) survive re-derivation and republication because automatic reconciliation only replaces derived provenances. Tests: `test/managed-writers-w3.test.ts`, `test/managed-ontology-propose.test.ts`.
diff --git a/scripts/scale/gates.ts b/scripts/scale/gates.ts
index 6fa1cabeec..22068a0286 100644
--- a/scripts/scale/gates.ts
+++ b/scripts/scale/gates.ts
@@ -84,6 +84,8 @@ export interface ScaleReport {
planner: { hot_table_stat_rows: Record<string, number>; hot_table_rows: Record<string, number>; probed_after: string };
ops: OpResult[];
data: DataCheck[];
+ /** F4d operational-ceiling measurements by check (scripts/scale/f4d.ts). */
+ f4d?: Record<string, Record<string, unknown>>;
phases_ms: Record<string, number>;
budgets_ms?: Record<string, number>;
}
diff --git a/scripts/scale/run.ts b/scripts/scale/run.ts
index 09cf23e5bc..d834b6c5c5 100644
--- a/scripts/scale/run.ts
+++ b/scripts/scale/run.ts
@@ -574,7 +574,7 @@ try {
console.log(`[scale] ${r.known_answer === 'pass' ? 'PASS' : 'FAIL'} ${r.op}: p50 ${r.p50_ms} ms${r.plan?.worst_loops ? `, worst nested-loop inner loops ${r.plan.worst_loops.inner_loops}` : ''}${r.detail ? ` (${r.detail})` : ''}`);
}
for (const d of report.data) console.log(`[scale] ${d.status === 'pass' ? 'PASS' : 'FAIL'} ${d.check}${d.detail ? ` (${d.detail})` : ''}`);
- for (const [name, measured] of Object.entries(report.f4d)) console.log(`[scale] F4D ${name}: ${JSON.stringify(measured)}`);
+ for (const [name, measured] of Object.entries(report.f4d ?? {})) console.log(`[scale] F4D ${name}: ${JSON.stringify(measured)}`);
console.log(`[scale] phases (ms): ${Object.entries(report.phases_ms).map(([k, v]) => `${k}=${v}`).join(' ')}`);
for (const line of verdictLines(report, verdict, policy)) console.log(line);
console.log(`[scale] report: ${out}${explain ? ` (EXPLAIN for failures: ${out.replace(/\.json$/, '')}.explain.txt)` : ''}; reproduce with: ${full.reproduce}`);
diff --git a/scripts/serial-files.tsv b/scripts/serial-files.tsv
index 61e29dacdd..c17fb67aa1 100644
--- a/scripts/serial-files.tsv
+++ b/scripts/serial-files.tsv
@@ -115,6 +115,7 @@ test/doctor-mode-matrix.serial.test.ts R1 R1: mutates process.env (HOME, GBRAIN_
test/doctor-remediation-plan-observational.serial.test.ts global-state global-state: R3: constructs PGLiteEngine outside beforeAll
test/doctor-remote.serial.test.ts global-state global-state: binds local servers/ports
test/doctor-report-remote.serial.test.ts R1 R1: mutates process.env (GBRAIN_HOME)
+test/doctor-revision-backfill-journey.serial.test.ts global-state global-state: withEnv holds GBRAIN_HOME across awaited doctor and CLI journey runs
test/dream-drain-failure-summary.serial.test.ts R2 R2: mock.module(../src/core/cycle/extract-atoms-drain.ts) replaces modules for every file in the process
test/dream-owner-id-threading.serial.test.ts R2 R2: mock.module(../src/core/cycle.ts) replaces modules for every file in the process
test/dream-postgres.serial.test.ts global-state global-state: spyOn process.exit, console.error
diff --git a/test/scripts/ci-pr-scope.test.ts b/test/scripts/ci-pr-scope.test.ts
index ed172419ea..d54a32a0a0 100644
--- a/test/scripts/ci-pr-scope.test.ts
+++ b/test/scripts/ci-pr-scope.test.ts
@@ -194,7 +194,7 @@ esac
expect(/GBRAIN_E2E_BUN_IMAGE:-oven\/bun:([^}]+)\}/.exec(read('tests/docker/bootstrap-e2e.sh'))?.[1]).toBe(primary);
const matrices = [load('test.yml').jobs['security-regressions'], ...Object.values(load('persistence-validation.yml').jobs)]
.map(job => job.strategy?.matrix.bun).filter(Boolean);
- expect(matrices).toHaveLength(6);
+ expect(matrices).toHaveLength(7);
for (const bun of matrices) expect(bun).toEqual([MINIMUM_BUN_VERSION, primary]);
for (const job of ['native', 'musl', 'windows-backup-console', 'windows-backup-dotnet']) {
expect(native[job].strategy!.matrix.bun).toEqual([MINIMUM_BUN_VERSION, primary]);
diff --git a/test/scripts/data-safety-native-workflow.test.ts b/test/scripts/data-safety-native-workflow.test.ts
index c7b3aa213f..cb66abfa8b 100644
--- a/test/scripts/data-safety-native-workflow.test.ts
+++ b/test/scripts/data-safety-native-workflow.test.ts
@@ -238,7 +238,7 @@ describe('data-safety native CI coverage', () => {
const job = persistence.jobs['crash-robot'];
expect(job.services.pgbouncer?.env?.POOL_MODE).toBe('transaction');
const step = job.steps.find(entry => entry.run?.includes('scripts/persistence/validate.ts'));
- expect(step?.env?.ROBOT_SECONDS).toBe("${{ github.event_name == 'pull_request' && '150' || '600' }}");
+ expect(step?.env?.ROBOT_SECONDS).toBe("${{ (github.event_name == 'pull_request' || github.event_name == 'merge_group') && '150' || '600' }}");
expect(step?.env?.GBRAIN_PGBOUNCER_URL).toContain(':55433/');
const result = Bun.spawnSync(['bash', '-e', '-o', 'pipefail', '-c', `
bun() { printf '%s\\n' "$@"; }