Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript
5.0 KB
Raw Blame

Key files: Doctor tiers and budgets

Subsystem index · Doctor commands · continued. Read only the entries relevant to your change. Current behavior and load-bearing invariants; history belongs in Git and CHANGELOG.

  • src/commands/doctor/budget.ts + checks/ops-sections.ts + checks/orphan-estimate.ts — doctor tiers and budgets (#6696 B1). parseDoctorTier (--tier ops|quick|standard|deep, a bad value is invalid_params), parseBudgetMs (--budget-ms, default 4000 under ops, 10000 under quick, none otherwise) and startDoctorDeadline build the DoctorDeadline the CLI starts before connecting. runDoctorRegistry runs the entries tagged tier: 'ops' (persistence capacity, terminal failures, managed sync movement, persistence compaction, serve build drift, schema-pack consistency, embedding state) right after the connection lane; under --tier ops it runs only those (each executeRaw gets the absolute deadlineAt, so SET LOCAL statement_timeout is the time left after the pool wait: postgres-engine/bounded-statement.ts), reports an entry marked opsPglite: 'not_applicable' as an ok info row on PGLite, and stays complete. Every other tier bounds each entry by doctor.entry_budget_ms (default 15000). An entry past its budget, an unknown reported after the overall deadline, or a connect the deadline ended becomes budgetUnknownCheck (warn, details.health: 'unknown', reason: 'budget', exact: false, a rerun-alone fix), never a clear result; every check carries elapsed_ms, and the report adds tier/complete/unknown_sections/elapsed_ms/budget_ms only when --tier or --budget-ms was given (doctorRunSummary). doctorHealth(ctx) memoizes getHealth for one run. orphan_ratio estimates from a TABLESAMPLE SYSTEM sample above doctor.orphan_ratio.full_scan_max_pages (default 50000) unless --tier deep. Capacity and compaction freshness live in checks/ops-sections.ts. On every tier each entry runs inside its own StatementDeadline (src/core/statement-deadline.ts: an AsyncLocalStorage scope plus deadlineBoundEngine, one stable Proxy per real engine that refuses any engine call past the deadline, carries the deadline to the server on Postgres executeRaw, and marks the scope expired on a cancel even when the check catches it; engineCacheKey maps the wrapper to the real engine for engine-keyed caches; PGLite gets only the pre-statement refusal). The budget-config read is one bounded statement (2 s). CHEAP_INCIDENT_CHECKS (by check name: persistence capacity, managed sync movement, text_projection_readiness, partial_embedding, links_extraction_lag) run right after the ops sections, before any full scan. #8979: with an engine and without --fast or --only, the entries before the connection lane stop at half the time left when the check run starts, so the ops sections and the cheap incident checks keep the other half. local-probe.ts localProbe runs the home-dir entry's npm root -g, which -a gbrain and crontab -l, and the bootstrap entry's git push-health probes (#8990), asynchronously and kills each, with its process group, at its own bound (5 s, 10 s for git) or the entry deadline, whichever comes first, so a hung probe never holds the run past --budget-ms; output past 1 MiB reads as absent. scanDeadline clips the frontmatter walk and the fence census to the entry deadline less 250 ms, so they report partial results. --only with an explicit --budget-ms gives the selected entries the whole overall budget; budgetUnknownCheck names the limiting budget (details.limit: entry or overall) and fixes with --only <check> --budget-ms N (N ten times that budget; actor agent while N fits AGENT_TOOL_LIMIT_MS less 10 s, else actor user). --budget-ms 0 is no overall budget. default-budget.ts: a plain non-interactive CLI doctor --json (stderr not a TTY; no --budget-ms, --tier, --fix, --remediate or --remediation-plan) caps its check run at doctor.default_budget_ms (file plane, default 90000, 0 off), started by startDeferredDeadline when the registry starts (connect and migrations are outside it), with one stderr line; the report then carries the tier fields. capacity-memo.ts doctorCapacityForecast: one forecast per run (shared by persistence_capacity and persistence_request_growth) read under the run's overall deadline and dropped from the memo on a deadline failure, which makes the waiting check unknown instead of a counter-only verdict. persistence_session_timeouts reads SHOW statement_timeout outside the entry deadline. Tests: test/doctor-tier-6696.test.ts, test/doctor-day-zero.test.ts (--tier ops), test/e2e/doctor-ops-tier-postgres.test.ts, test/doctor-entry-deadline-6803.test.ts (+ test/e2e/doctor-entry-deadline-postgres.test.ts), test/doctor-default-budget-6803.test.ts; bench scripts/bench/doctor-scale.ts. #7276: scoredChecks keeps over-budget unknowns out of every score (unknown_count); derived_visibility is its own entry (test/doctor-unknown-score-7276.test.ts).