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:
1 parent
1d907c08fa
commit
01fd7b9922
9 files changed
+474
-31
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import * as os from "node:os";
|
||||
import { makeSessionState, makeWorkspaceInfo } from "./fakes.js";
|
||||
import { createHarness, TEST_LIMITS, type Harness } from "./harness.js";
|
||||
import { createHarness, makeFakeSysinfoSampler, TEST_LIMITS, type Harness } from "./harness.js";
|
||||
import { DaemonError } from "../../src/daemon/errors.js";
|
||||
import { ERROR_CODES } from "../../src/protocol/errors.js";
|
||||
import { WorkspaceError } from "../../src/workspaces/errors.js";
|
||||
@@ -486,6 +486,34 @@ describe("HTTP API", () => {
|
||||
}));
|
||||
});
|
||||
|
||||
it("relays the per-filesystem disk list on resources", async () => {
|
||||
const custom = await createHarness({
|
||||
sysinfo: makeFakeSysinfoSampler({
|
||||
disks: [
|
||||
{ mountPoint: "/home", fsType: "btrfs", usedBytes: 950, totalBytes: 1000, percent: 95 },
|
||||
{ mountPoint: "/", fsType: "ext4", usedBytes: 500, totalBytes: 1000, percent: 50 },
|
||||
],
|
||||
diskPath: "/home",
|
||||
diskPercent: 95,
|
||||
}),
|
||||
});
|
||||
try {
|
||||
const response = await fetch(`${custom.url}/api/v1/resources`, {
|
||||
headers: { Authorization: `Bearer ${custom.createToken()}` },
|
||||
});
|
||||
expect(response.status).toBe(200);
|
||||
const system = (await response.json()).system;
|
||||
expect(system.disks).toEqual([
|
||||
{ mountPoint: "/home", fsType: "btrfs", usedBytes: 950, totalBytes: 1000, percent: 95 },
|
||||
{ mountPoint: "/", fsType: "ext4", usedBytes: 500, totalBytes: 1000, percent: 50 },
|
||||
]);
|
||||
// The /info scalar stays the worst row, so old clients keep working.
|
||||
expect(system.diskPercent).toBe(95);
|
||||
} finally {
|
||||
await custom.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("resolves bare models without spawning when no instance is ready", async () => {
|
||||
const bare = await createHarness();
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user