@vellumai/assistant 0.11.4-dev.202608191823.2d04996 → 0.11.4-dev.202608192008.2b8f565
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +10 -0
- package/openapi.yaml +73 -0
- package/package.json +1 -1
- package/src/__tests__/container-cpu-sampler.test.ts +153 -0
- package/src/__tests__/resource-pressure-guard.test.ts +428 -0
- package/src/__tests__/resource-pressure-routes.test.ts +113 -0
- package/src/agent/loop-tool-dedup.test.ts +161 -0
- package/src/agent/loop.ts +67 -15
- package/src/api/events/resource-pressure-status-changed.ts +53 -0
- package/src/api/index.ts +14 -0
- package/src/api/responses/resource-pressure-status.ts +25 -0
- package/src/cli/commands/monitoring.ts +1 -0
- package/src/daemon/lifecycle.ts +2 -0
- package/src/daemon/resource-pressure-guard-lifecycle.ts +66 -0
- package/src/daemon/resource-pressure-guard.ts +387 -0
- package/src/daemon/shutdown-handlers.ts +2 -0
- package/src/providers/inference/__tests__/adapter-factory-litellm.test.ts +47 -1
- package/src/providers/inference/__tests__/adapter-factory-openai-compatible.test.ts +64 -1
- package/src/providers/inference/adapter-factory.ts +9 -0
- package/src/providers/openai/__tests__/chat-completions-provider-reasoning.test.ts +75 -5
- package/src/providers/openai/chat-completions-provider.ts +11 -8
- package/src/runtime/routes/__tests__/monitoring-routes.test.ts +1 -0
- package/src/runtime/routes/identity-routes.ts +5 -121
- package/src/runtime/routes/index.ts +2 -0
- package/src/runtime/routes/monitoring-routes.ts +9 -1
- package/src/runtime/routes/resource-pressure-routes.ts +22 -0
- package/src/util/__tests__/cgroup-memory.test.ts +3 -0
- package/src/util/cgroup-memory.ts +3 -0
- package/src/util/container-cpu-sampler.ts +250 -0
package/ARCHITECTURE.md
CHANGED
|
@@ -35,6 +35,16 @@ Safe storage limits protect the workspace volume from running out of disk. The d
|
|
|
35
35
|
|
|
36
36
|
**Prompt and tools:** Cleanup-mode turns carry `diskPressureContext` through runtime assembly and receive the concise `<disk_pressure_warning>` injector in `src/plugins/defaults/memory-retrieval/injectors.ts`. The instruction tells the assistant to warn first, call `skill_load` for `system-storage-cleanup`, and explain that background processes and trusted-contact messages are blocked. Tool setup marks the turn as cleanup mode; `skill_load` remains available so the assistant can load the cleanup skill (or another already-installed skill) for its instructions, but under the lock it performs **no side effects** — it skips catalog auto-install (workspace writes / `bun install`) and strips inline command tokens instead of executing them, so loading a skill cannot write to the workspace or run shell. `skill_execute` and skill-origin tools remain unavailable, and a loaded skill's own tools stay filtered by the cleanup allowlist. The bundled `system-storage-cleanup` skill (`src/config/bundled-skills/system-storage-cleanup/SKILL.md`) carries the detailed cleanup procedure and deletion safety rules, including read-only SQLite diagnosis only; product-owned retention and maintenance work remains tracked separately by ATL-450 and related tickets. `src/tools/tool-approval-handler.ts` rejects non-cleanup-safe tools, and foreground shell inspection remains available while background `bash` and `host_bash` modes are rejected. When a new lock is created, active background terminal tools are cancelled with reason `disk_pressure`.
|
|
37
37
|
|
|
38
|
+
### Resource Pressure Monitoring
|
|
39
|
+
|
|
40
|
+
Resource pressure monitoring reports sustained CPU/memory pressure on platform-hosted assistants so clients can suggest a plan upgrade. Unlike disk pressure it never locks or blocks work; it is observe-and-report only.
|
|
41
|
+
|
|
42
|
+
**Guard state:** `src/daemon/resource-pressure-guard.ts` is gated on `getIsPlatform()`: off-platform there is no plan allocation to measure against, so the guard stays disabled and samples nothing. On platform it samples every 30 seconds. CPU percent comes from the shared rolling container CPU sampler (`src/util/container-cpu-sampler.ts`) measured against the cgroup CPU allocation (null when no CPU cores are reported); memory percent is the working set (cgroup usage minus reclaimable file cache) measured against the container memory limit. Each signal keeps a 20-sample window (10 minutes) with hysteresis: it enters `elevated` only when the window is full and at least 18 samples exceeded the enter threshold (CPU 85%, memory 90%), and clears only after 10 consecutive samples below the clear threshold (CPU 70%, memory 80%). An unavailable sample resets that signal's window; when both samples fail the status becomes `unknown` with the sample error. The overall state is `elevated` while either signal holds.
|
|
43
|
+
|
|
44
|
+
**Runtime API and events:** `src/runtime/routes/resource-pressure-routes.ts` exposes the read-only `GET /v1/resource-pressure/status` (scope `settings.read`, actor principals); there are no acknowledge or override transitions. `resource_pressure_status_changed` events broadcast the same status shape, but only on substantive transitions: the raw percents and `lastCheckedAt` are excluded from the change fingerprint so the 30-second cadence does not spam the SSE hub. The canonical wire contract lives in `src/api/events/resource-pressure-status-changed.ts`.
|
|
45
|
+
|
|
46
|
+
**Lifecycle:** `src/daemon/resource-pressure-guard-lifecycle.ts` starts the guard at daemon boot with the first sample deferred onto a macrotask so it never blocks startup, and stops the guard (cancelling any pending deferred sample) on shutdown. The web chat banner built on this status is documented in the repo-level [`/ARCHITECTURE.md`](../ARCHITECTURE.md) "Resource Pressure Monitoring" section.
|
|
47
|
+
|
|
38
48
|
### Single-Header JWT Auth Model
|
|
39
49
|
|
|
40
50
|
All HTTP API requests use a single `Authorization: Bearer <jwt>` header for authentication. The JWT carries identity, permissions, and policy versioning in a unified token.
|
package/openapi.yaml
CHANGED
|
@@ -21459,6 +21459,10 @@ paths:
|
|
|
21459
21459
|
anyOf:
|
|
21460
21460
|
- type: number
|
|
21461
21461
|
- type: "null"
|
|
21462
|
+
inactiveFileBytes:
|
|
21463
|
+
anyOf:
|
|
21464
|
+
- type: number
|
|
21465
|
+
- type: "null"
|
|
21462
21466
|
kernelBytes:
|
|
21463
21467
|
anyOf:
|
|
21464
21468
|
- type: number
|
|
@@ -21482,6 +21486,7 @@ paths:
|
|
|
21482
21486
|
required:
|
|
21483
21487
|
- anonBytes
|
|
21484
21488
|
- fileBytes
|
|
21489
|
+
- inactiveFileBytes
|
|
21485
21490
|
- kernelBytes
|
|
21486
21491
|
- slabReclaimableBytes
|
|
21487
21492
|
- slabUnreclaimableBytes
|
|
@@ -25345,6 +25350,74 @@ paths:
|
|
|
25345
25350
|
responses:
|
|
25346
25351
|
"200":
|
|
25347
25352
|
description: Successful response
|
|
25353
|
+
/v1/resource-pressure/status:
|
|
25354
|
+
get:
|
|
25355
|
+
operationId: resourcepressure_status_get
|
|
25356
|
+
summary: Get resource pressure status
|
|
25357
|
+
description:
|
|
25358
|
+
Return the current resource pressure status snapshot. Off-platform the guard does not run, so a disabled
|
|
25359
|
+
status is returned.
|
|
25360
|
+
tags:
|
|
25361
|
+
- resource-pressure
|
|
25362
|
+
responses:
|
|
25363
|
+
"200":
|
|
25364
|
+
description: Successful response
|
|
25365
|
+
content:
|
|
25366
|
+
application/json:
|
|
25367
|
+
schema:
|
|
25368
|
+
type: object
|
|
25369
|
+
properties:
|
|
25370
|
+
status:
|
|
25371
|
+
type: object
|
|
25372
|
+
properties:
|
|
25373
|
+
enabled:
|
|
25374
|
+
type: boolean
|
|
25375
|
+
state:
|
|
25376
|
+
type: string
|
|
25377
|
+
enum:
|
|
25378
|
+
- disabled
|
|
25379
|
+
- ok
|
|
25380
|
+
- elevated
|
|
25381
|
+
- unknown
|
|
25382
|
+
cpuPercent:
|
|
25383
|
+
anyOf:
|
|
25384
|
+
- type: number
|
|
25385
|
+
- type: "null"
|
|
25386
|
+
memoryPercent:
|
|
25387
|
+
anyOf:
|
|
25388
|
+
- type: number
|
|
25389
|
+
- type: "null"
|
|
25390
|
+
cpuElevated:
|
|
25391
|
+
type: boolean
|
|
25392
|
+
memoryElevated:
|
|
25393
|
+
type: boolean
|
|
25394
|
+
cpuThresholdPercent:
|
|
25395
|
+
type: number
|
|
25396
|
+
memoryThresholdPercent:
|
|
25397
|
+
type: number
|
|
25398
|
+
lastCheckedAt:
|
|
25399
|
+
anyOf:
|
|
25400
|
+
- type: string
|
|
25401
|
+
- type: "null"
|
|
25402
|
+
error:
|
|
25403
|
+
anyOf:
|
|
25404
|
+
- type: string
|
|
25405
|
+
- type: "null"
|
|
25406
|
+
required:
|
|
25407
|
+
- enabled
|
|
25408
|
+
- state
|
|
25409
|
+
- cpuPercent
|
|
25410
|
+
- memoryPercent
|
|
25411
|
+
- cpuElevated
|
|
25412
|
+
- memoryElevated
|
|
25413
|
+
- cpuThresholdPercent
|
|
25414
|
+
- memoryThresholdPercent
|
|
25415
|
+
- lastCheckedAt
|
|
25416
|
+
- error
|
|
25417
|
+
additionalProperties: false
|
|
25418
|
+
required:
|
|
25419
|
+
- status
|
|
25420
|
+
additionalProperties: false
|
|
25348
25421
|
/v1/retrospective/config:
|
|
25349
25422
|
get:
|
|
25350
25423
|
operationId: retrospective_config_get
|
package/package.json
CHANGED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
__resetContainerCpuSamplerForTests,
|
|
5
|
+
__runContainerCpuSamplerTickForTests,
|
|
6
|
+
computeCpuPercent,
|
|
7
|
+
computeDurationWeightedMeanPercent,
|
|
8
|
+
getAverageContainerCpuPercentOrNull,
|
|
9
|
+
getCachedContainerCpuPercent,
|
|
10
|
+
getCachedContainerCpuPercentOrNull,
|
|
11
|
+
} from "../util/container-cpu-sampler.js";
|
|
12
|
+
|
|
13
|
+
describe("computeCpuPercent", () => {
|
|
14
|
+
test("computes percent of the full allocation from a CPU-time delta", () => {
|
|
15
|
+
// 2.5s of CPU over a 5s window on 1 core is 50% of the allocation.
|
|
16
|
+
expect(computeCpuPercent(2_500_000, 5_000, 1)).toBe(50);
|
|
17
|
+
// The same delta on 2 cores is half the utilization.
|
|
18
|
+
expect(computeCpuPercent(2_500_000, 5_000, 2)).toBe(25);
|
|
19
|
+
// Fully saturating 4 cores for the whole window is 100%.
|
|
20
|
+
expect(computeCpuPercent(20_000_000, 5_000, 4)).toBe(100);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("rounds to 2 decimal places", () => {
|
|
24
|
+
expect(computeCpuPercent(123_456, 5_000, 2)).toBe(1.23);
|
|
25
|
+
expect(computeCpuPercent(123_999, 5_000, 2)).toBe(1.24);
|
|
26
|
+
expect(computeCpuPercent(0, 5_000, 1)).toBe(0);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("yields a non-finite result for zero cores, which callers must guard", () => {
|
|
30
|
+
expect(Number.isFinite(computeCpuPercent(1_000_000, 5_000, 0))).toBe(false);
|
|
31
|
+
expect(Number.isFinite(computeCpuPercent(0, 5_000, 0))).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("getCachedContainerCpuPercent", () => {
|
|
36
|
+
test("returns a finite number", () => {
|
|
37
|
+
expect(Number.isFinite(getCachedContainerCpuPercent())).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("getCachedContainerCpuPercentOrNull", () => {
|
|
42
|
+
test("returns null until the sampler computes its first delta", () => {
|
|
43
|
+
__resetContainerCpuSamplerForTests();
|
|
44
|
+
|
|
45
|
+
expect(getCachedContainerCpuPercentOrNull()).toBeNull();
|
|
46
|
+
// The plain accessor keeps its 0 placeholder for /v1/health.
|
|
47
|
+
expect(getCachedContainerCpuPercent()).toBe(0);
|
|
48
|
+
|
|
49
|
+
// Drive one sampler tick a full interval ahead of the reset baseline so
|
|
50
|
+
// it computes a real delta from process.cpuUsage().
|
|
51
|
+
__runContainerCpuSamplerTickForTests(Date.now() + 5_000);
|
|
52
|
+
|
|
53
|
+
const sampled = getCachedContainerCpuPercentOrNull();
|
|
54
|
+
expect(sampled).not.toBeNull();
|
|
55
|
+
expect(Number.isFinite(sampled!)).toBe(true);
|
|
56
|
+
expect(sampled).toBe(getCachedContainerCpuPercent());
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("computeDurationWeightedMeanPercent", () => {
|
|
61
|
+
test("weights each percent by the wall time its delta spanned", () => {
|
|
62
|
+
// 25s at 80% then 5s at 100% is 83.33% of the half minute, not the 90%
|
|
63
|
+
// an equal-weight mean would report.
|
|
64
|
+
expect(
|
|
65
|
+
computeDurationWeightedMeanPercent(
|
|
66
|
+
[
|
|
67
|
+
{ at: 25_000, percent: 80, elapsedMs: 25_000 },
|
|
68
|
+
{ at: 30_000, percent: 100, elapsedMs: 5_000 },
|
|
69
|
+
],
|
|
70
|
+
0,
|
|
71
|
+
),
|
|
72
|
+
).toBe(83.33);
|
|
73
|
+
// Equal durations degrade to the plain mean.
|
|
74
|
+
expect(
|
|
75
|
+
computeDurationWeightedMeanPercent(
|
|
76
|
+
[
|
|
77
|
+
{ at: 5_000, percent: 40, elapsedMs: 5_000 },
|
|
78
|
+
{ at: 10_000, percent: 60, elapsedMs: 5_000 },
|
|
79
|
+
],
|
|
80
|
+
0,
|
|
81
|
+
),
|
|
82
|
+
).toBe(50);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("clips a delayed tick's contribution to its overlap with the window", () => {
|
|
86
|
+
// A 25s CPU-bound stall at 100% ends 1s into the window; only that 1s
|
|
87
|
+
// may count. With 29s of idle at 10% after it, the window reads 13%,
|
|
88
|
+
// not the 52.8% an unclipped duration weighting would report.
|
|
89
|
+
expect(
|
|
90
|
+
computeDurationWeightedMeanPercent(
|
|
91
|
+
[
|
|
92
|
+
{ at: 1_000, percent: 100, elapsedMs: 25_000 },
|
|
93
|
+
{ at: 30_000, percent: 10, elapsedMs: 29_000 },
|
|
94
|
+
],
|
|
95
|
+
0,
|
|
96
|
+
),
|
|
97
|
+
).toBe(13);
|
|
98
|
+
// A tick entirely before the window contributes nothing.
|
|
99
|
+
expect(
|
|
100
|
+
computeDurationWeightedMeanPercent(
|
|
101
|
+
[
|
|
102
|
+
{ at: -1_000, percent: 100, elapsedMs: 5_000 },
|
|
103
|
+
{ at: 10_000, percent: 20, elapsedMs: 10_000 },
|
|
104
|
+
],
|
|
105
|
+
0,
|
|
106
|
+
),
|
|
107
|
+
).toBe(20);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("returns null without any overlapping samples", () => {
|
|
111
|
+
expect(computeDurationWeightedMeanPercent([], 0)).toBeNull();
|
|
112
|
+
expect(
|
|
113
|
+
computeDurationWeightedMeanPercent(
|
|
114
|
+
[{ at: 5_000, percent: 50, elapsedMs: 0 }],
|
|
115
|
+
0,
|
|
116
|
+
),
|
|
117
|
+
).toBeNull();
|
|
118
|
+
expect(
|
|
119
|
+
computeDurationWeightedMeanPercent(
|
|
120
|
+
[{ at: -1_000, percent: 50, elapsedMs: 5_000 }],
|
|
121
|
+
0,
|
|
122
|
+
),
|
|
123
|
+
).toBeNull();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("getAverageContainerCpuPercentOrNull", () => {
|
|
128
|
+
test("returns null until a tick lands inside the window", () => {
|
|
129
|
+
__resetContainerCpuSamplerForTests();
|
|
130
|
+
|
|
131
|
+
expect(getAverageContainerCpuPercentOrNull(60_000)).toBeNull();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("averages the ticks recorded within the trailing window", () => {
|
|
135
|
+
__resetContainerCpuSamplerForTests();
|
|
136
|
+
|
|
137
|
+
// A single recorded tick makes the average equal the last cached value.
|
|
138
|
+
__runContainerCpuSamplerTickForTests(Date.now() + 5_000);
|
|
139
|
+
const single = getAverageContainerCpuPercentOrNull(60_000);
|
|
140
|
+
expect(single).not.toBeNull();
|
|
141
|
+
expect(single).toBe(getCachedContainerCpuPercentOrNull());
|
|
142
|
+
|
|
143
|
+
// More ticks keep the average finite and within the recorded range; the
|
|
144
|
+
// exact value depends on real process CPU deltas, so only the invariant
|
|
145
|
+
// is asserted.
|
|
146
|
+
__runContainerCpuSamplerTickForTests(Date.now() + 10_000);
|
|
147
|
+
__runContainerCpuSamplerTickForTests(Date.now() + 15_000);
|
|
148
|
+
const averaged = getAverageContainerCpuPercentOrNull(60_000);
|
|
149
|
+
expect(averaged).not.toBeNull();
|
|
150
|
+
expect(Number.isFinite(averaged!)).toBe(true);
|
|
151
|
+
expect(averaged!).toBeGreaterThanOrEqual(0);
|
|
152
|
+
});
|
|
153
|
+
});
|