Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
doctor: capacity view reads last compaction through executeRaw; terminal failures registered as its own entry; early-stop golden gains elapsed_ms (#6696 B)
garrytan47f9348000c5
diff --git a/src/core/persistence/capacity-view.ts b/src/core/persistence/capacity-view.tsindex 8a3920294b..d59ff22c6e 100644--- a/src/core/persistence/capacity-view.ts+++ b/src/core/persistence/capacity-view.ts@@ -64,7 +64,8 @@ export async function readCapacityCounters(engine: BrainEngine): Promise<Counterexport async function readCapacityView(engine: BrainEngine): Promise<CapacityView> {const counters = await readCapacityCounters(engine);const rows = capacityDiagnostics(counters, await readJournalLimits(engine));- return { rows, counters_read: counters.length, forecast: null, last_compaction: parseLastCompaction(await engine.getConfig(LAST_COMPACTION_KEY)) };+ const [compaction] = await engine.executeRaw<{ value: string }>('SELECT value FROM config WHERE key = $1', [LAST_COMPACTION_KEY]);+ return { rows, counters_read: counters.length, forecast: null, last_compaction: parseLastCompaction(compaction?.value ?? null) };}function parseLastCompaction(raw: string | null): LastCompaction | null {diff --git a/test/fixtures/goldens/doctor/early-stop-connection-failure.json b/test/fixtures/goldens/doctor/early-stop-connection-failure.jsonindex ee5fa4c4c0..baf1eb4a4d 100644--- a/test/fixtures/goldens/doctor/early-stop-connection-failure.json+++ b/test/fixtures/goldens/doctor/early-stop-connection-failure.json@@ -1,6 +1,7 @@{"golden": [{+ "elapsed_ms": "<volatile>","message": "1 skills, all reachable","name": "resolver_health","status": "ok"@@ -14,6 +15,7 @@"path": "postgres direct","policy_skill_installed": false},+ "elapsed_ms": "<volatile>","message": "postgres direct; enabled; not observed firing yet — policy skill not installed; run `gbrain integrations install retrieval-reflex --target <host-repo>`","name": "retrieval_reflex_health","status": "ok"@@ -23,26 +25,31 @@"channels": {},"window_days": 7},+ "elapsed_ms": "<volatile>","message": "no push-context activity in 7 days — note: the harness-hook channels require a PGLite serve socket — on this engine the hook lane stays quiet by design (pull-mode retrieval covers it)","name": "volunteer_channels","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "no verb calls recorded yet (sidecar appears on first remember/recall/entity/synthesize/forget)","name": "memory_verbs_usage","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "1/1 skills pass","name": "skill_conformance","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "1 skill(s) compliant or exempt","name": "skill_brain_first","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No skills.lock.json in <home>/skills — integrity check not applicable","name": "skills_manifest_integrity","status": "ok"@@ -117,11 +124,13 @@"webhook-transforms"]},+ "elapsed_ms": "<volatile>","message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},{+ "elapsed_ms": "<volatile>","message": "no installed skills declare preconditions","name": "skill_preconditions","status": "ok"@@ -132,6 +141,7 @@"out_of_band_settable": true,"reason": "disabled"},+ "elapsed_ms": "<volatile>","message": "memorable relay off (default)","name": "memorable_relay_health","status": "ok"@@ -164,11 +174,13 @@"ttl_valid": true,"visibility_note": "world = readable by agents authorized on THIS brain, not the public internet"},+ "elapsed_ms": "<volatile>","message": "ambient writeback off (default): Stop-hook turn capture is off, but the compaction harvest and SessionEnd transcripts still extract (installing the harness hooks opted into them; stop them: gbrain config set memory.auto_writeback off). Enable: gbrain config set memory.auto_writeback salient","name": "memory_writeback","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No chat connectors configured (optional).","name": "connectors","status": "ok"@@ -181,21 +193,25 @@"keys": [],"threshold": 3},+ "elapsed_ms": "<volatile>","message": "No dream key died 3+ times in 24h","name": "dream_paid_loop","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "mode=notify","name": "self_upgrade_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "Bun <bun-version> (minimum 1.4.0)","name": "bun_runtime","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "disabled (opt-in). Enable with: gbrain config set autopilot.nightly_quality_probe.enabled true","name": "nightly_quality_probe_health","status": "ok"@@ -205,11 +221,13 @@"kinds": [],"schema_version": 1},+ "elapsed_ms": "<volatile>","message": "no extractions in last 7 days","name": "extract_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "disabled (opt-in). Enable with: gbrain config set cycle.conversation_facts_backfill.enabled true","name": "conversation_facts_backlog","status": "ok"@@ -220,6 +238,7 @@"known_approximation": "page backlog only; transcript corpus not counted","pack_declares_phase": false},+ "elapsed_ms": "<volatile>","message": "no pages awaiting atom extraction","name": "extract_atoms_backlog","status": "ok"@@ -228,31 +247,37 @@"details": {"health": "unknown"},+ "elapsed_ms": "<volatile>","message": "atom provenance query returned no rows","name": "atom_provenance_drift","status": "warn"},{+ "elapsed_ms": "<volatile>","message": "No conversation-type pages — coverage check not applicable","name": "conversation_format_coverage","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No progressive-batch operations in the last 7 days","name": "progressive_batch_audit_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "disabled (opt-in; default-on only for search.mode=tokenmax). Enable with: `gbrain config set autopilot.conversation_parser_probe.enabled true`","name": "conversation_parser_probe_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "gbrain home is outside any enclosing git worktree.","name": "home_dir_in_worktree","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No abandoned PGLite store under the gbrain home (engine: postgres).","name": "pglite_leftovers","status": "ok"@@ -268,6 +293,7 @@"embedding_model": "voyage:voyage-4","shadows": []},+ "elapsed_ms": "<volatile>","message": "No embedding key is set here (VOYAGE_API_KEY or voyage_api_key). No environment variable overrides a different config-plane provider key. This check sees only the environment `gbrain doctor` runs in; a daemon (gbrain serve, autopilot) has its own, and reports a mismatch in its log with a startup warning or embedding_auth_failed.","name": "embedding_key_source","status": "ok"@@ -277,6 +303,7 @@"decision": null,"provider_env": []},+ "elapsed_ms": "<volatile>","message": "No gbrain setup receipt records a provider-use decision for this install; provider calls follow the configured keys.","name": "provider_consent","readiness_state": "not_applicable",@@ -287,6 +314,7 @@"details": {"reason": "no_harness_detected"},+ "elapsed_ms": "<volatile>","fix": {"actor": "user","consent": [@@ -312,11 +340,13 @@"json_document_missing": 0,"window_days": 7},+ "elapsed_ms": "<volatile>","message": "No agent dead ends in the last 7 days (0 non-success event(s) logged).","name": "agent_contract","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "Prepared statements disabled (PgBouncer-safe)","name": "pgbouncer_prepare","status": "ok"@@ -328,6 +358,7 @@"transient": true,"url_source": "database_url in <home>/.gbrain/config.json"},+ "elapsed_ms": "<volatile>","fix": {"actor": "agent","argv": [diff --git a/test/fixtures/goldens/doctor/early-stop-null-engine-connect-error.json b/test/fixtures/goldens/doctor/early-stop-null-engine-connect-error.jsonindex 82b7329e40..75d3e56207 100644--- a/test/fixtures/goldens/doctor/early-stop-null-engine-connect-error.json+++ b/test/fixtures/goldens/doctor/early-stop-null-engine-connect-error.json@@ -1,6 +1,7 @@{"golden": [{+ "elapsed_ms": "<volatile>","message": "1 skills, all reachable","name": "resolver_health","status": "ok"@@ -14,26 +15,31 @@"path": "postgres direct","policy_skill_installed": false},+ "elapsed_ms": "<volatile>","message": "postgres direct; enabled; not observed firing yet — policy skill not installed; run `gbrain integrations install retrieval-reflex --target <host-repo>`","name": "retrieval_reflex_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "no verb calls recorded yet (sidecar appears on first remember/recall/entity/synthesize/forget)","name": "memory_verbs_usage","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "1/1 skills pass","name": "skill_conformance","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "1 skill(s) compliant or exempt","name": "skill_brain_first","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No skills.lock.json in <home>/skills — integrity check not applicable","name": "skills_manifest_integrity","status": "ok"@@ -108,11 +114,13 @@"webhook-transforms"]},+ "elapsed_ms": "<volatile>","message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},{+ "elapsed_ms": "<volatile>","message": "skill preconditions not checked (no connected brain)","name": "skill_preconditions","status": "ok"@@ -123,6 +131,7 @@"out_of_band_settable": true,"reason": "disabled"},+ "elapsed_ms": "<volatile>","message": "memorable relay off (default)","name": "memorable_relay_health","status": "ok"@@ -135,41 +144,49 @@"transient_ttl": "3d","ttl_valid": true},+ "elapsed_ms": "<volatile>","message": "ambient writeback off (default; file-plane mirror — database unreachable)","name": "memory_writeback","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "mode=notify","name": "self_upgrade_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "Bun <bun-version> (minimum 1.4.0)","name": "bun_runtime","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "disabled (opt-in). Enable with: gbrain config set autopilot.nightly_quality_probe.enabled true","name": "nightly_quality_probe_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No progressive-batch operations in the last 7 days","name": "progressive_batch_audit_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "disabled (opt-in; default-on only for search.mode=tokenmax). Enable with: `gbrain config set autopilot.conversation_parser_probe.enabled true`","name": "conversation_parser_probe_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "gbrain home is outside any enclosing git worktree.","name": "home_dir_in_worktree","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No abandoned PGLite store under the gbrain home (engine: postgres).","name": "pglite_leftovers","status": "ok"@@ -185,6 +202,7 @@"embedding_model": "voyage:voyage-4","shadows": []},+ "elapsed_ms": "<volatile>","message": "No embedding key is set here (VOYAGE_API_KEY or voyage_api_key). No environment variable overrides a different config-plane provider key. This check sees only the environment `gbrain doctor` runs in; a daemon (gbrain serve, autopilot) has its own, and reports a mismatch in its log with a startup warning or embedding_auth_failed.","name": "embedding_key_source","status": "ok"@@ -194,6 +212,7 @@"decision": null,"provider_env": []},+ "elapsed_ms": "<volatile>","message": "No gbrain setup receipt records a provider-use decision for this install; provider calls follow the configured keys.","name": "provider_consent","readiness_state": "not_applicable",@@ -204,6 +223,7 @@"details": {"reason": "no_harness_detected"},+ "elapsed_ms": "<volatile>","fix": {"actor": "user","consent": [@@ -229,6 +249,7 @@"json_document_missing": 0,"window_days": 7},+ "elapsed_ms": "<volatile>","message": "No agent dead ends in the last 7 days (0 non-success event(s) logged).","name": "agent_contract","status": "ok"@@ -240,6 +261,7 @@"transient": true,"url_source": "database_url in <home>/.gbrain/config.json"},+ "elapsed_ms": "<volatile>","fix": {"actor": "agent","argv": [diff --git a/test/fixtures/goldens/doctor/early-stop-null-engine-fast.json b/test/fixtures/goldens/doctor/early-stop-null-engine-fast.jsonindex deb14b42bc..9a42e6ae7c 100644--- a/test/fixtures/goldens/doctor/early-stop-null-engine-fast.json+++ b/test/fixtures/goldens/doctor/early-stop-null-engine-fast.json@@ -1,6 +1,7 @@{"golden": [{+ "elapsed_ms": "<volatile>","message": "1 skills, all reachable","name": "resolver_health","status": "ok"@@ -14,26 +15,31 @@"path": "postgres direct","policy_skill_installed": false},+ "elapsed_ms": "<volatile>","message": "postgres direct; enabled; not observed firing yet — policy skill not installed; run `gbrain integrations install retrieval-reflex --target <host-repo>`","name": "retrieval_reflex_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "no verb calls recorded yet (sidecar appears on first remember/recall/entity/synthesize/forget)","name": "memory_verbs_usage","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "1/1 skills pass","name": "skill_conformance","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "1 skill(s) compliant or exempt","name": "skill_brain_first","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No skills.lock.json in <home>/skills — integrity check not applicable","name": "skills_manifest_integrity","status": "ok"@@ -108,11 +114,13 @@"webhook-transforms"]},+ "elapsed_ms": "<volatile>","message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},{+ "elapsed_ms": "<volatile>","message": "skill preconditions not checked (no connected brain)","name": "skill_preconditions","status": "ok"@@ -123,6 +131,7 @@"out_of_band_settable": true,"reason": "disabled"},+ "elapsed_ms": "<volatile>","message": "memorable relay off (default)","name": "memorable_relay_health","status": "ok"@@ -135,41 +144,49 @@"transient_ttl": "3d","ttl_valid": true},+ "elapsed_ms": "<volatile>","message": "ambient writeback off (default; file-plane mirror — database unreachable)","name": "memory_writeback","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "mode=notify","name": "self_upgrade_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "Bun <bun-version> (minimum 1.4.0)","name": "bun_runtime","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "disabled (opt-in). Enable with: gbrain config set autopilot.nightly_quality_probe.enabled true","name": "nightly_quality_probe_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No progressive-batch operations in the last 7 days","name": "progressive_batch_audit_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "disabled (opt-in; default-on only for search.mode=tokenmax). Enable with: `gbrain config set autopilot.conversation_parser_probe.enabled true`","name": "conversation_parser_probe_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "gbrain home is outside any enclosing git worktree.","name": "home_dir_in_worktree","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No abandoned PGLite store under the gbrain home (engine: postgres).","name": "pglite_leftovers","status": "ok"@@ -185,6 +202,7 @@"embedding_model": "voyage:voyage-4","shadows": []},+ "elapsed_ms": "<volatile>","message": "No embedding key is set here (VOYAGE_API_KEY or voyage_api_key). No environment variable overrides a different config-plane provider key. This check sees only the environment `gbrain doctor` runs in; a daemon (gbrain serve, autopilot) has its own, and reports a mismatch in its log with a startup warning or embedding_auth_failed.","name": "embedding_key_source","status": "ok"@@ -194,6 +212,7 @@"decision": null,"provider_env": []},+ "elapsed_ms": "<volatile>","message": "No gbrain setup receipt records a provider-use decision for this install; provider calls follow the configured keys.","name": "provider_consent","readiness_state": "not_applicable",@@ -204,6 +223,7 @@"details": {"reason": "no_harness_detected"},+ "elapsed_ms": "<volatile>","fix": {"actor": "user","consent": [@@ -229,11 +249,13 @@"json_document_missing": 0,"window_days": 7},+ "elapsed_ms": "<volatile>","message": "No agent dead ends in the last 7 days (0 non-success event(s) logged).","name": "agent_contract","status": "ok"},{+ "elapsed_ms": "<volatile>","fix": {"actor": "agent","argv": [@@ -260,6 +282,7 @@"status": "warn"},{+ "elapsed_ms": "<volatile>","message": "Prepared statements disabled (PgBouncer-safe)","name": "pgbouncer_prepare","status": "ok"diff --git a/test/fixtures/goldens/doctor/early-stop-null-engine-no-config.json b/test/fixtures/goldens/doctor/early-stop-null-engine-no-config.jsonindex ff4b55f633..187d94f25d 100644--- a/test/fixtures/goldens/doctor/early-stop-null-engine-no-config.json+++ b/test/fixtures/goldens/doctor/early-stop-null-engine-no-config.json@@ -1,6 +1,7 @@{"golden": [{+ "elapsed_ms": "<volatile>","message": "1 skills, all reachable","name": "resolver_health","status": "ok"@@ -14,26 +15,31 @@"path": "engine unknown","policy_skill_installed": false},+ "elapsed_ms": "<volatile>","message": "engine unknown; enabled but NO resolve path exists right now: the IPC socket is only bound by a running `gbrain serve` (stdio or --http) — until one is up, hooks/reflex degrade to no_serve on this brain (host capability may still supply pointers; policy skill carries otherwise) — policy skill not installed; run `gbrain integrations install retrieval-reflex --target <host-repo>`","name": "retrieval_reflex_health","status": "warn"},{+ "elapsed_ms": "<volatile>","message": "no verb calls recorded yet (sidecar appears on first remember/recall/entity/synthesize/forget)","name": "memory_verbs_usage","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "1/1 skills pass","name": "skill_conformance","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "1 skill(s) compliant or exempt","name": "skill_brain_first","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No skills.lock.json in <home>/skills — integrity check not applicable","name": "skills_manifest_integrity","status": "ok"@@ -108,11 +114,13 @@"webhook-transforms"]},+ "elapsed_ms": "<volatile>","message": "64 new built-in skill(s) available that this workspace hasn't installed: academic-verify, archive-crawler, article-enrichment, ask-user, blog-ingest, book-mirror, brain-ingest-gate, brain-link-discipline, … +56 more. Add them with `gbrain skillpack sync`.","name": "skill_currency","status": "warn"},{+ "elapsed_ms": "<volatile>","message": "skill preconditions not checked (no connected brain)","name": "skill_preconditions","status": "ok"@@ -123,6 +131,7 @@"out_of_band_settable": true,"reason": "disabled"},+ "elapsed_ms": "<volatile>","message": "memorable relay off (default)","name": "memorable_relay_health","status": "ok"@@ -135,36 +144,43 @@"transient_ttl": "3d","ttl_valid": true},+ "elapsed_ms": "<volatile>","message": "ambient writeback off (default; file-plane mirror — database unreachable)","name": "memory_writeback","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "mode=notify","name": "self_upgrade_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "Bun <bun-version> (minimum 1.4.0)","name": "bun_runtime","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "disabled (opt-in). Enable with: gbrain config set autopilot.nightly_quality_probe.enabled true","name": "nightly_quality_probe_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "No progressive-batch operations in the last 7 days","name": "progressive_batch_audit_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "disabled (opt-in; default-on only for search.mode=tokenmax). Enable with: `gbrain config set autopilot.conversation_parser_probe.enabled true`","name": "conversation_parser_probe_health","status": "ok"},{+ "elapsed_ms": "<volatile>","message": "gbrain home is outside any enclosing git worktree.","name": "home_dir_in_worktree","status": "ok"@@ -180,6 +196,7 @@"embedding_model": "voyage:voyage-4","shadows": []},+ "elapsed_ms": "<volatile>","message": "No embedding key is set here (VOYAGE_API_KEY or voyage_api_key). No environment variable overrides a different config-plane provider key. This check sees only the environment `gbrain doctor` runs in; a daemon (gbrain serve, autopilot) has its own, and reports a mismatch in its log with a startup warning or embedding_auth_failed.","name": "embedding_key_source","status": "ok"@@ -189,6 +206,7 @@"decision": null,"provider_env": []},+ "elapsed_ms": "<volatile>","message": "No gbrain setup receipt records a provider-use decision for this install; provider calls follow the configured keys.","name": "provider_consent","readiness_state": "not_applicable",@@ -199,6 +217,7 @@"details": {"reason": "no_harness_detected"},+ "elapsed_ms": "<volatile>","fix": {"actor": "user","consent": [@@ -224,11 +243,13 @@"json_document_missing": 0,"window_days": 7},+ "elapsed_ms": "<volatile>","message": "No agent dead ends in the last 7 days (0 non-success event(s) logged).","name": "agent_contract","status": "ok"},{+ "elapsed_ms": "<volatile>","fix": {"actor": "agent","argv": [diff --git a/test/terminal-failures-6650.test.ts b/test/terminal-failures-6650.test.tsindex 62f7df09da..a6b981397a 100644--- a/test/terminal-failures-6650.test.ts+++ b/test/terminal-failures-6650.test.ts@@ -322,6 +322,6 @@ for (const kind of testBackends()) describe(`the aggregate, doctor and the drillconst [row] = await engine.executeRaw<{ n: number }>(`SELECT count(*)::int AS n FROM persistence_requests r JOIN persistence_requests c ON ${supersessionSql('r', 'c')} WHERE r.state='failed'`);expect(row!.n).toBe(1);expect(categorizeCheck('persistence_terminal_failures')).toBe('ops');- expect(WAVE_CHECKS.find(spec => spec.id === 'persistence_terminal_failures')).toMatchObject({ resolution: 'operator', registration: 'wave' });+ expect(WAVE_CHECKS.find(spec => spec.id === 'persistence_terminal_failures')).toMatchObject({ resolution: 'operator', registration: 'doctor.ts' });});});