Skip to content

feat(doctor): add disk space health check for state directory#59196

Merged
steipete merged 8 commits into
openclaw:mainfrom
alkor2000:feat/doctor-disk-space-check
May 31, 2026
Merged

feat(doctor): add disk space health check for state directory#59196
steipete merged 8 commits into
openclaw:mainfrom
alkor2000:feat/doctor-disk-space-check

Conversation

@alkor2000

@alkor2000 alkor2000 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Add a new Doctor health contribution that checks free disk space on the partition containing the state directory (~/.openclaw). Warns when available space drops below 500 MB and reports CRITICAL when below 100 MB.

Problem

When the disk hosting the state directory fills up, OpenClaw silently fails to write config files, session transcripts, and logs. Users see symptoms (missing sessions, corrupted config) but have no way to diagnose the root cause through Doctor.

The existing doctor:state-integrity contribution checks directory existence, permissions, cloud sync, and SD/eMMC storage — but not free space.

The upstream fix in v2026.4.5 (surface explicit disk-full message when ENOSPC) confirms this is a recognized problem — this PR adds the proactive diagnostic counterpart.

Real behavior proof

  • Behavior or issue addressed: When the disk hosting the state directory fills up, OpenClaw silently fails to write config, session transcripts, and logs. Doctor had no disk-space check, so users only saw downstream symptoms. This adds a doctor:disk-space health contribution with two-tier warning (500 MB) / critical (100 MB) thresholds.

  • Real environment tested: Linux (Ubuntu 24.04, WSL2), Node.js 24.14.0, OpenClaw built from this PR head. Exercised the patched noteDiskSpace() and the shared tryReadDiskSpace() probe against the real ~/.openclaw partition and at simulated low-space thresholds.

  • Exact steps or command run after this patch: invoked the patched functions via tsx against the real state-dir partition and injected low-space readings:

$ node --import tsx run-disk-check.ts
  • Evidence after fix: Real probe via the shared tryReadDiskSpace() helper (now reused instead of a duplicate statfs implementation), plus actual noteDiskSpace() terminal output at low-space thresholds:
Real probe via shared tryReadDiskSpace
  state dir:    /home/alkor2000/.openclaw
  checked path: /home/alkor2000/.openclaw
  available:    935.1 GB (1004057964544 bytes)
  warnings at real free space: 0  (healthy disk, no warning)

noteDiskSpace at 80 MB (CRITICAL):
  - CRITICAL: only 80 MB free on the partition containing ~/.openclaw.
  - Config writes, session transcripts, and log rotation may fail silently.
  - Free up disk space immediately to avoid data loss.

noteDiskSpace at 400 MB (WARNING):
  - Low disk space: 400 MB free on the partition containing ~/.openclaw.
  - Consider freeing space to prevent future config/session write failures.
  • Observed result after fix: On a healthy disk (935 GB free) no warning is emitted. At 400 MB the WARNING tier fires; at 80 MB the CRITICAL tier fires with data-loss guidance. Disk probing now delegates to the shared src/infra/disk-space.ts helper (addressing the duplicate-implementation review note); the two-tier thresholds and formatting remain specific to this Doctor check. 20 unit tests pass.

  • What was not tested: A literally full partition (real ENOSPC) was not reproduced; low-space readings were injected via the shared probe's return value. Non-Linux platforms rely on the shared helper's platform handling.

Solution

New doctor:disk-space contribution registered before doctor:state-integrity so the root cause (disk full) appears before downstream symptoms (write failures).

New file: src/commands/doctor-disk-space.ts

  • formatBytes() — human-readable byte formatting (B/KB/MB/GB)
  • getAvailableBytes() — statfsSync wrapper using bavail * bsize
  • buildDiskSpaceWarnings() — pure function for threshold logic
  • noteDiskSpace() — Doctor contribution entry point

New file: src/commands/doctor-disk-space.test.ts

  • 25 unit tests covering formatting, thresholds, and edge cases

Modified: src/flows/doctor-health-contributions.ts

  • Register doctor:disk-space contribution

Design decisions

  • bavail not bfree — reflects unprivileged user available space
  • Synchronous statfsSync — Doctor runs serially
  • Dependency injection — consistent with doctor-state-integrity.ts
  • Silent skip on failure — other contributions handle missing dirs
  • Thresholds — 100 MB critical / 500 MB warning

Verification

  • pnpm vitest: 25/25 passed
  • pnpm check: clean

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: M labels Apr 1, 2026
@greptile-apps

greptile-apps Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a new doctor:disk-space Doctor health contribution that checks free space on the partition hosting the state directory (~/.openclaw) and surfaces a warning below 500 MB or a CRITICAL alert below 100 MB. The contribution is registered just before doctor:state-integrity so a full-disk root cause appears before downstream write-failure symptoms.

Key changes:

  • src/commands/doctor-disk-space.ts — new file with formatBytes, getAvailableBytes (wrapping statfsSync), buildDiskSpaceWarnings (pure threshold logic), and noteDiskSpace (Doctor entry point). Uses dependency injection for statfsSync consistent with sibling contributions.
  • src/commands/doctor-disk-space.test.ts — 20 unit tests covering edge cases for all exported functions, including BigInt mocking and strict boundary values.
  • src/flows/doctor-health-contributions.ts — minimal registration of the new contribution.

Findings:

  • The inline comment on line 50 of doctor-disk-space.ts mislabels bsize as "fundamental block size"; it is the optimal transfer block size in Node's StatsFs API. The math is correct but the comment is misleading.
  • The cfg: OpenClawConfig first parameter of noteDiskSpace is never read inside the function (the state directory is resolved purely from env vars). The parameter appears kept for API symmetry with other Doctor contributions; a clarifying comment or renaming to _cfg would make the intent explicit.

Confidence Score: 5/5

  • Safe to merge — all findings are P2 style/comment issues with no impact on correctness or runtime behaviour.
  • The implementation is logically correct: bavail * bsize is the right formula for Node's fs.statfsSync API, errors are silently swallowed as documented, thresholds are well-reasoned, and the contribution is registered in the right order. The two P2 findings (misleading comment on bsize, unused cfg parameter) do not affect runtime behaviour or data integrity. Test coverage is thorough with boundary value tests at every relevant threshold.
  • No files require special attention.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/commands/doctor-disk-space.ts
Line: 48-51

Comment:
**Misleading comment: `bsize` is not the "fundamental block size"**

The inline comment says _"Multiply by `bsize` (fundamental block size)"_, but in the libuv/Node.js `StatsFs` API `bsize` is the **optimal transfer block size** (`f_bsize`). The "fundamental block size" term refers to `frsize` (`f_frsize`) from the POSIX `statvfs` struct.

The math itself is correct — in the `statfs`-based API that Node.js exposes, `bavail` blocks are indeed counted in `f_bsize` units — but the comment is the wrong way round and will mislead anyone who checks against POSIX `statvfs` docs.

```suggestion
    // `bavail` is the number of free blocks available to unprivileged users.
    // Multiply by `bsize` (optimal transfer / filesystem block size in Node's
    // StatsFs, equal to `f_bsize` from the underlying statfs syscall) to get
    // available bytes.
    return Number(stats.bavail) * Number(stats.bsize);
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/commands/doctor-disk-space.ts
Line: 92-98

Comment:
**Unused `cfg` parameter**

`cfg: OpenClawConfig` is declared as the first parameter but is never read inside the function body. The state directory is resolved entirely from `env` (via `resolveStateDir`), which is also the pattern used by `resolveStateDir` itself — there is no config-level state-dir override.

If the parameter is kept for API symmetry with other Doctor contributions, a short comment clarifying that intent would prevent future readers from wondering whether it was accidentally forgotten. Alternatively, it can be dropped and the call-site in `doctor-health-contributions.ts` updated accordingly.

```suggestion
export function noteDiskSpace(
  _cfg: OpenClawConfig, // reserved for API consistency with other Doctor contributions
  deps?: {
    env?: NodeJS.ProcessEnv;
    statfsSync?: (p: string) => fs.StatsFs;
  },
): void {
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "feat(doctor): add disk space health chec..." | Re-trigger Greptile

Comment thread src/commands/doctor-disk-space.ts Outdated
Comment thread src/commands/doctor-disk-space.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0f0ea00c7a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/commands/doctor-disk-space.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 971d9e8ad1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/commands/doctor-disk-space.ts Outdated
@alkor2000
alkor2000 force-pushed the feat/doctor-disk-space-check branch from 971d9e8 to 41257c5 Compare April 1, 2026 18:39

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a07e4cb913

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/commands/doctor-disk-space.test.ts Outdated
@alkor2000
alkor2000 force-pushed the feat/doctor-disk-space-check branch from bb9aeac to 29459a3 Compare April 30, 2026 18:54
@clawsweeper

clawsweeper Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed May 31, 2026, 2:34 PM ET / 18:34 UTC.

Summary
The PR adds a Doctor disk-space health contribution for the OpenClaw state directory, registers it before state integrity, records it in the health conversion plan, and adds focused tests.

PR surface: Source +125, Tests +169. Total +294 across 4 files.

Reproducibility: not applicable. as a bug reproduction: this is a feature PR adding a new Doctor diagnostic. The PR body and latest check-runs provide after-fix terminal proof for healthy and injected low-space readings, and source inspection confirms current main lacks this contribution.

Review metrics: none identified.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Next step before merge

  • [P2] No repair lane is needed because there is no concrete patch defect; the remaining action is ordinary maintainer merge judgment.

Security
Cleared: The diff adds Doctor runtime code and tests only; it does not change dependencies, workflows, package scripts, secret handling, permissions, or other supply-chain surfaces.

Review details

Best possible solution:

Land the PR after normal maintainer approval, keeping disk probing in src/infra/disk-space.ts and the Doctor-only thresholds/output in src/commands/doctor-disk-space.ts.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a bug reproduction: this is a feature PR adding a new Doctor diagnostic. The PR body and latest check-runs provide after-fix terminal proof for healthy and injected low-space readings, and source inspection confirms current main lacks this contribution.

Is this the best way to solve the issue?

Yes. The current PR shape is the narrow maintainable solution because it reuses the existing shared disk-space helper, keeps Doctor-specific thresholds local, registers the contribution before state integrity, and adds conversion-plan plus unit coverage.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 7e0d275f7add.

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal output from a real state-directory disk probe plus after-fix warning and critical output from the patched Doctor function, and the latest head has a passing Real behavior proof check.

Label justifications:

  • P2: This is a normal-priority Doctor diagnostic improvement with limited runtime blast radius and no blocking defect found.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes terminal output from a real state-directory disk probe plus after-fix warning and critical output from the patched Doctor function, and the latest head has a passing Real behavior proof check.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal output from a real state-directory disk probe plus after-fix warning and critical output from the patched Doctor function, and the latest head has a passing Real behavior proof check.
Evidence reviewed

PR surface:

Source +125, Tests +169. Total +294 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 125 0 +125
Tests 1 169 0 +169
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 294 0 +294

What I checked:

Likely related people:

  • steipete: Recent history for src/infra/disk-space.ts shows steipete authored the low-disk helper and subsequent diagnostic export cleanup, and local blame on the current shallow checkout points the helper lines at a recent Peter Steinberger commit. (role: shared helper and recent area contributor; confidence: high; commits: b979f2964c96, ebece95058f0; files: src/infra/disk-space.ts)
  • vincentkoc: Recent history for src/flows/doctor-health-contributions.ts and src/flows/doctor-health-conversion-plan.ts includes provider-catalog Doctor diagnostics and conversion-plan test coverage that share this PR's registration surface. (role: recent Doctor health contributor; confidence: high; commits: cc290050b439, 37fdfa0e0bcf; files: src/flows/doctor-health-contributions.ts, src/flows/doctor-health-conversion-plan.ts)
  • giodl73-repo: The read-only health conversion work introduced and maintained the conversion-plan structure this PR updates for the new Doctor contribution. (role: Doctor conversion-plan contributor; confidence: medium; commits: 94abfa76e21f, 2d3fa4832f41; files: src/flows/doctor-health-contributions.ts, src/flows/doctor-health-conversion-plan.ts)
  • alkor2000: Beyond authoring this PR, alkor2000 appears in recent merged Doctor health history for auth-profile repair work touching the same Doctor contribution area. (role: recent adjacent Doctor contributor; confidence: medium; commits: 603aa8a2ed18; files: src/flows/doctor-health-contributions.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@alkor2000
alkor2000 force-pushed the feat/doctor-disk-space-check branch from 29459a3 to a723194 Compare May 3, 2026 17:00
@alkor2000
alkor2000 force-pushed the feat/doctor-disk-space-check branch from a723194 to 3382444 Compare May 14, 2026 02:17
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 14, 2026
@alkor2000

Copy link
Copy Markdown
Contributor Author

Real-world evidence: disk-full failures surface as opaque symptoms in GitHub Issues — config corruption (#issue examples), missing sessions, silent write failures. Users cannot diagnose the root cause through Doctor because no check exists. The upstream fix in v2026.4.5 ("surface explicit disk-full message when ENOSPC") confirms this is a recognized problem — this PR adds the proactive diagnostic counterpart.

@alkor2000

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels May 19, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🥚 common Mossy Branchling

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 🥚 common.
Trait: sparkles near resolved comments.
Image traits: location status garden; accessory release bell; palette sunrise gold and clean white; mood mischievous; pose waving from a small platform; shell soft velvet shell; lighting subtle sparkle highlights; background small review tokens.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Mossy Branchling in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@alkor2000
alkor2000 force-pushed the feat/doctor-disk-space-check branch from 3382444 to 15b908c Compare May 21, 2026 09:34
@alkor2000

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the review feedback:

  • P1 (duplicate disk-space implementation): deleted the local statfs/ancestor probing and now delegate to the shared src/infra/disk-space.ts tryReadDiskSpace() helper, keeping one implementation shared with install/update diagnostics. The two-tier warning/critical thresholds and Doctor formatting remain specific to this check. Net -99 lines.
  • Real behavior proof: PR body now includes actual tryReadDiskSpace() output on the real ~/.openclaw partition plus live noteDiskSpace() terminal output at WARNING and CRITICAL thresholds.
  • Rebased onto current main; 20 unit tests pass.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 21, 2026
@clawsweeper

clawsweeper Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels May 21, 2026
@clawsweeper clawsweeper Bot added status: 🔁 re-review loop A fresh ClawSweeper review was explicitly requested after the latest review. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels May 21, 2026
@clawsweeper

clawsweeper Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 🔁 re-review loop A fresh ClawSweeper review was explicitly requested after the latest review. labels May 21, 2026
@RomneyDa

Copy link
Copy Markdown
Member

Heads up: this PR needs to be updated against current main before the new required Dependency Guard check can pass.

@alkor2000
alkor2000 force-pushed the feat/doctor-disk-space-check branch from 110b1fe to b3d760c Compare May 31, 2026 18:11
@alkor2000

Copy link
Copy Markdown
Contributor Author

Thanks @RomneyDa — rebased onto current main so the Dependency Guard check can run. One adjustment was needed: upstream extracted the terminal note module to packages/terminal-core/src/note.js, so I updated the import path in the disk-space contribution and its tests (the 4 noteDiskSpace tests were failing on the old src/terminal/note.js path). All 20 unit tests and the health-contributions consistency test pass; the doctor:disk-space registration and conversion-plan entry are intact.

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 31, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels May 31, 2026
alkor2000 added 8 commits June 1, 2026 02:24
Add a new Doctor health contribution that checks free disk space on the
partition containing the state directory. Warns when available space drops
below 500 MB and reports CRITICAL when below 100 MB.

This catches a common operational failure mode where OpenClaw silently
fails to write config, sessions, or logs because the disk is full.

- New file: src/commands/doctor-disk-space.ts
  - formatBytes(): human-readable byte formatting
  - getAvailableBytes(): statfsSync wrapper with error handling
  - buildDiskSpaceWarnings(): pure function for threshold logic
  - noteDiskSpace(): Doctor contribution entry point
- New file: src/commands/doctor-disk-space.test.ts (20 tests)
- Modified: src/flows/doctor-health-contributions.ts
  - Register doctor:disk-space before state-integrity so disk-full
    root cause appears before downstream symptoms
- Fix misleading bsize comment: 'fundamental block size' -> 'optimal
  transfer / filesystem block size' (Greptile P2)
- Rename cfg to _cfg with comment for API consistency intent (Greptile P2)
- Use Math.floor instead of toFixed(0) for MB/KB formatting to avoid
  rounding 99.6 MB up to '100 MB' in warning text (Codex P2)
When the state directory does not exist yet (first run, manual cleanup),
statfsSync fails and the disk space check silently exits. This suppresses
the root-cause warning in low-disk situations.

Walk up from the state directory path to find the nearest existing
ancestor and probe that instead. This ensures disk pressure is reported
even before the state directory is created.

- Add findExistingAncestor() with safety bound (max 64 levels)
- Update getAvailableBytes() to use ancestor fallback
- Add 4 new tests for findExistingAncestor + ancestor probe path
  (24 tests total)

Addresses Codex P2 review feedback.
Replace hardcoded POSIX paths ('/tmp', '/') with os.tmpdir() and
path.parse().root so tests pass on Windows where path.resolve
produces drive-rooted paths (e.g. C:\tmp).

Addresses Codex P1 review feedback.
Address ClawSweeper P1: delete the duplicate statfs/ancestor probing in
doctor-disk-space.ts and delegate to src/infra/disk-space.ts
(tryReadDiskSpace), keeping a single disk-space implementation shared with
install/update diagnostics. The two-tier warning/critical thresholds and
Doctor-facing byte formatting remain specific to this health check.
Update tests to inject readDiskSpace and drop the now-removed helpers.
noteDiskSpace is synchronous (returns void); awaiting it tripped the
no-await-sync lint rule. Drop the await on the call (the dynamic import
remains awaited). Also addresses the earlier review note to call the
synchronous disk-space note directly.
The doctor-health-conversion-plan consistency test requires every
registered health contribution to have a matching conversion rule.
Add the doctor:disk-space rule (terminal-side-effect: emits note()
warnings, no repair) so the planned and registered contribution id
lists stay in sync.
…action

Upstream extracted the terminal note module from src/terminal/note.js to
packages/terminal-core/src/note.js; update the disk-space contribution
and its tests to the new path.
@alkor2000
alkor2000 force-pushed the feat/doctor-disk-space-check branch from b3d760c to 06b63e4 Compare May 31, 2026 18:29
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 31, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 31, 2026
@steipete steipete self-assigned this May 31, 2026

@steipete steipete left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Land-ready review for PR #59196.

What landed in this PR:

  • Adds doctor:disk-space, warning below 500 MB free and reporting critical below 100 MB on the partition containing the active OpenClaw state directory.
  • Reuses src/infra/disk-space.ts for disk probing and nearest-existing-ancestor handling; Doctor owns only thresholds and terminal output.
  • Registers the contribution before state integrity and records it in the Doctor health conversion plan.

Proof checked:

  • pnpm test src/commands/doctor-disk-space.test.ts src/flows/doctor-health-conversion-plan.test.ts passed locally: 2 Vitest shards, 23 tests.
  • git diff --check origin/main...HEAD passed locally on the PR head.
  • git merge-tree --write-tree origin/main refs/remotes/pr/59196 passed after refreshing main to 5df0ed3b9f5.
  • GitHub reports mergeStateStatus: CLEAN, mergeable: MERGEABLE for head 06b63e405c91320466050a45eea2b56558298e15.
  • CI run 26720861380 is green for the relevant required checks; latest Real behavior proof run 26720996848 is green.

Known gaps:

  • I did not run a full local suite; the change is scoped to Doctor command wiring, the disk-space contribution, and its focused tests.

@steipete
steipete merged commit 9d97e68 into openclaw:main May 31, 2026
163 of 164 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 1, 2026
Add a Doctor health contribution that checks free space on the partition containing the active OpenClaw state directory. Doctor now warns below 500 MB and reports critical below 100 MB so disk pressure is visible before config writes, session transcripts, or log rotation start failing.

The contribution reuses the shared `src/infra/disk-space.ts` probe, runs before state integrity, and is registered in the Doctor health conversion plan with focused coverage for thresholds, formatting, and note behavior.

PR: openclaw#59196
Proof: `pnpm test src/commands/doctor-disk-space.test.ts src/flows/doctor-health-conversion-plan.test.ts`; `git diff --check origin/main...HEAD`; `git merge-tree --write-tree origin/main refs/remotes/pr/59196`; GitHub CI run `26720861380`; Real behavior proof run `26720996848`.

Co-authored-by: alkor2000 <[email protected]>
SYU8384 pushed a commit to SYU8384/openclaw that referenced this pull request Jun 3, 2026
Add a Doctor health contribution that checks free space on the partition containing the active OpenClaw state directory. Doctor now warns below 500 MB and reports critical below 100 MB so disk pressure is visible before config writes, session transcripts, or log rotation start failing.

The contribution reuses the shared `src/infra/disk-space.ts` probe, runs before state integrity, and is registered in the Doctor health conversion plan with focused coverage for thresholds, formatting, and note behavior.

PR: openclaw#59196
Proof: `pnpm test src/commands/doctor-disk-space.test.ts src/flows/doctor-health-conversion-plan.test.ts`; `git diff --check origin/main...HEAD`; `git merge-tree --write-tree origin/main refs/remotes/pr/59196`; GitHub CI run `26720861380`; Real behavior proof run `26720996848`.

Co-authored-by: alkor2000 <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Add a Doctor health contribution that checks free space on the partition containing the active OpenClaw state directory. Doctor now warns below 500 MB and reports critical below 100 MB so disk pressure is visible before config writes, session transcripts, or log rotation start failing.

The contribution reuses the shared `src/infra/disk-space.ts` probe, runs before state integrity, and is registered in the Doctor health conversion plan with focused coverage for thresholds, formatting, and note behavior.

PR: openclaw#59196
Proof: `pnpm test src/commands/doctor-disk-space.test.ts src/flows/doctor-health-conversion-plan.test.ts`; `git diff --check origin/main...HEAD`; `git merge-tree --write-tree origin/main refs/remotes/pr/59196`; GitHub CI run `26720861380`; Real behavior proof run `26720996848`.

Co-authored-by: alkor2000 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants