fix(daemon): sample disk usage on the filesystems pi2d uses

The status tile read `—` on a fresh machine: the sampler ran `statfs` on the
daemon's state dir, which is created lazily on the first instance log, so the
call failed with ENOENT and `diskUsedBytes`/`diskTotalBytes`/`diskPercent` all
came back null — `/info` then dropped `disk` altogether and the failure was
indistinguishable from a full disk.

`probeMount()` now walks up to the nearest existing ancestor and then to the
filesystem boundary (`st_dev` change), so a sample describes a volume, not a
directory. Candidates are pi2d's own write targets — `/` (the home volume on
macOS, where `/` is the sealed read-only system volume), the pi session store
and the visible workspace roots — never a mount-table dump: an unrelated or
hung network mount must not stall the sampler. Rows are deduped by `st_dev`,
sorted most-constrained first, capped at four, and reported as `system.disks[]`
with the legacy scalars aliasing the worst row. A sample that yields nothing
now carries `diskError` instead of silent nulls.

The status tile shows the worst filesystem and, when several are in play, one
quiet row per mount instead of a single percentage that hides the full volume.
This commit is contained in:
yuez committed 2026-10-30 16:17:43 +08:00
1 parent 1d907c08fa
commit 01fd7b9922
9 files changed
+474 -31

No files matched your search

+10 -3
View File
@@ -93,7 +93,7 @@ Plugin obligations:
| Endpoint | Notes |
|---|---|
| `GET /api/v1/info` | `{v, daemonId, machineId, platform, hostname, os, version, uptimeMs, pid, port, capabilities, limits}`; additive `cpu`, `mem`, `disk` (integer percent, each omitted when unknown), `cpuCores`, `loadAvg` |
| `GET /api/v1/info` | `{v, daemonId, machineId, platform, hostname, os, version, uptimeMs, pid, port, capabilities, limits}`; additive `cpu`, `mem`, `disk` (integer percent of the **most constrained** filesystem, each omitted when unknown), `cpuCores`, `loadAvg` |
| `GET /api/v1/health` | `{ok, items:[{name, ok, detail}]}` |
| `GET /api/v1/workspaces` | `WorkspaceInfo[]` (registry + disk index + instance state) |
| `GET /api/v1/workspaces/:id/sessions` | relayed `workspace.query{kind:"sessions"}` (row fields below) |
@@ -127,8 +127,15 @@ figures sampled by the daemon itself:
| `cpuCores` | logical core count |
| `loadAvg` | 3-tuple `[1m, 5m, 15m]`, or `null` where the OS has no load average |
| `memUsedBytes`, `memTotalBytes`, `memPercent` | **host** memory; `memPercent` is an integer. `totalRssBytes` stays the soft-limit input — it is instance RSS, not a host figure |
| `diskPath` | the filesystem the sample describes: the daemon's state dir |
| `diskUsedBytes`, `diskTotalBytes`, `diskPercent` | `diskPercent` integer, nullable; the byte counts are `null` when the stat fails |
| `diskPath` | mount point of the most constrained filesystem (`disks[0]`), e.g. `/` or `/home`; the legacy scalar fields below alias that row |
| `disks` | `DiskUsage[]`, at most 4, **most constrained first**. One row per distinct filesystem (`st_dev`) among the daemon's own write targets: `/` (the home volume on macOS), the pi session store and the visible (non-`secondary`) workspace roots. Not a mount-table dump — an unrelated or hung network mount is never touched |
| `disks[].mountPoint`, `disks[].fsType?`, `disks[].totalBytes`, `disks[].usedBytes`, `disks[].percent` | `mountPoint` is the filesystem boundary (never the sampled path), `fsType` a best-effort label (`ext4`, `btrfs`, …) omitted when unknown, `percent` an integer 0–100 |
| `diskUsedBytes`, `diskTotalBytes`, `diskPercent` | the worst row, for clients that predate `disks`; `null` when nothing could be sampled |
| `diskError` | present **only** when `disks` is empty — `"<path>: <code>"`, so a failed sample is distinguishable from a full disk instead of silently rendering `—` |
A candidate path that does not exist yet (the state dir is created lazily) no longer
blanks the sample: the probe walks up to the nearest existing ancestor and then to the
filesystem boundary, so `diskPercent` describes the volume, not a directory.
`GET /api/v1/models` no longer requires `workspaceId`. With one, the read is
relayed as before and may spawn that workspace's instance — the chat picker's