Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
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 isinvalid_params),parseBudgetMs(--budget-ms, default 4000 under ops, 10000 under quick, none otherwise) andstartDoctorDeadlinebuild theDoctorDeadlinethe CLI starts before connecting.runDoctorRegistryruns the entries taggedtier: '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 opsit runs only those (eachexecuteRawgets the absolutedeadlineAt, soSET LOCAL statement_timeoutis the time left after the pool wait:postgres-engine/bounded-statement.ts), reports an entry markedopsPglite: 'not_applicable'as anokinfo row on PGLite, and stays complete. Every other tier bounds each entry bydoctor.entry_budget_ms(default 15000). An entry past its budget, an unknown reported after the overall deadline, or a connect the deadline ended becomesbudgetUnknownCheck(warn,details.health: 'unknown',reason: 'budget',exact: false, a rerun-alone fix), never a clear result; every check carrieselapsed_ms, and the report addstier/complete/unknown_sections/elapsed_ms/budget_msonly when--tieror--budget-mswas given (doctorRunSummary).doctorHealth(ctx)memoizesgetHealthfor one run.orphan_ratioestimates from aTABLESAMPLE SYSTEMsample abovedoctor.orphan_ratio.full_scan_max_pages(default 50000) unless--tier deep. Capacity and compaction freshness live inchecks/ops-sections.ts. On every tier each entry runs inside its ownStatementDeadline(src/core/statement-deadline.ts: an AsyncLocalStorage scope plusdeadlineBoundEngine, one stable Proxy per real engine that refuses any engine call past the deadline, carries the deadline to the server on PostgresexecuteRaw, and marks the scope expired on a cancel even when the check catches it;engineCacheKeymaps 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--fastor--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.tslocalProberuns the home-dir entry'snpm root -g,which -a gbrainandcrontab -l, and the bootstrap entry'sgitpush-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.scanDeadlineclips the frontmatter walk and the fence census to the entry deadline less 250 ms, so they report partial results.--onlywith an explicit--budget-msgives the selected entries the whole overall budget;budgetUnknownChecknames the limiting budget (details.limit:entryoroverall) and fixes with--only <check> --budget-ms N(N ten times that budget; actor agent while N fitsAGENT_TOOL_LIMIT_MSless 10 s, else actor user).--budget-ms 0is no overall budget.default-budget.ts: a plain non-interactive CLIdoctor --json(stderr not a TTY; no--budget-ms,--tier,--fix,--remediateor--remediation-plan) caps its check run atdoctor.default_budget_ms(file plane, default 90000, 0 off), started bystartDeferredDeadlinewhen the registry starts (connect and migrations are outside it), with one stderr line; the report then carries the tier fields.capacity-memo.tsdoctorCapacityForecast: one forecast per run (shared bypersistence_capacityandpersistence_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_timeoutsreadsSHOW statement_timeoutoutside 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; benchscripts/bench/doctor-scale.ts. #7276:scoredCheckskeeps over-budget unknowns out of every score (unknown_count);derived_visibilityis its own entry (test/doctor-unknown-score-7276.test.ts).