@vellumai/assistant 0.10.10-dev.202607201927.4faac34 → 0.10.10-dev.202607202034.986455b
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/openapi.yaml +4 -3
- package/package.json +1 -1
- package/src/config/memory-tier.test.ts +44 -0
- package/src/config/memory-tier.ts +31 -0
- package/src/monitoring/worker.ts +8 -0
- package/src/runtime/routes/ps-routes.ts +4 -1
- package/src/telemetry/memory-tier-reporter.test.ts +130 -0
- package/src/telemetry/memory-tier-reporter.ts +103 -0
package/openapi.yaml
CHANGED
|
@@ -33664,9 +33664,10 @@ components:
|
|
|
33664
33664
|
- unreachable
|
|
33665
33665
|
origin:
|
|
33666
33666
|
type: string
|
|
33667
|
-
|
|
33668
|
-
|
|
33669
|
-
|
|
33667
|
+
pattern: ^(workspace|plugin:.+)$
|
|
33668
|
+
description:
|
|
33669
|
+
"Process origin: 'workspace' for the daemon and its subsystems, or 'plugin:<name>' for a process spawned
|
|
33670
|
+
from a plugin (e.g. 'plugin:default-memory', 'plugin:cognee')."
|
|
33670
33671
|
children:
|
|
33671
33672
|
type: array
|
|
33672
33673
|
items:
|
package/package.json
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { memoryTier } from "./memory-tier.js";
|
|
4
|
+
import type { AssistantConfig } from "./schema.js";
|
|
5
|
+
|
|
6
|
+
describe("memoryTier", () => {
|
|
7
|
+
test("off when memory is explicitly disabled", () => {
|
|
8
|
+
const config = { memory: { enabled: false } } as AssistantConfig;
|
|
9
|
+
expect(memoryTier(config)).toBe("off");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("off wins even when v3 is live (OFF over v3 precedence)", () => {
|
|
13
|
+
const config = {
|
|
14
|
+
memory: { enabled: false, v3: { live: true } },
|
|
15
|
+
} as AssistantConfig;
|
|
16
|
+
expect(memoryTier(config)).toBe("off");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("v3 when memory-v3 is live", () => {
|
|
20
|
+
const config = { memory: { v3: { live: true } } } as AssistantConfig;
|
|
21
|
+
expect(memoryTier(config)).toBe("v3");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("v2 when v2 is enabled and v3 is not live", () => {
|
|
25
|
+
const config = {
|
|
26
|
+
memory: { v2: { enabled: true }, v3: { live: false } },
|
|
27
|
+
} as AssistantConfig;
|
|
28
|
+
expect(memoryTier(config)).toBe("v2");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("v3 wins over v2 when both are truthy (v3 over v2 precedence)", () => {
|
|
32
|
+
const config = {
|
|
33
|
+
memory: { v2: { enabled: true }, v3: { live: true } },
|
|
34
|
+
} as AssistantConfig;
|
|
35
|
+
expect(memoryTier(config)).toBe("v3");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("v1 when memory is on but neither v2 nor v3 is selected", () => {
|
|
39
|
+
const config = {
|
|
40
|
+
memory: { enabled: true, v2: { enabled: false }, v3: { live: false } },
|
|
41
|
+
} as AssistantConfig;
|
|
42
|
+
expect(memoryTier(config)).toBe("v1");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isMemoryV3Live } from "./memory-v3-gate.js";
|
|
2
|
+
import type { AssistantConfig } from "./schema.js";
|
|
3
|
+
|
|
4
|
+
export type MemoryTier = "off" | "v1" | "v2" | "v3";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Derive the coarse memory tier for an assistant, as a single bucket for
|
|
8
|
+
* telemetry. Precedence mirrors the runtime memory-source semantics:
|
|
9
|
+
*
|
|
10
|
+
* - `"off"` wins over everything: an explicit `memory.enabled === false`
|
|
11
|
+
* disables the whole memory system regardless of v2/v3 settings.
|
|
12
|
+
* - `"v3"` wins over `"v2"`: when memory-v3 is live it suppresses v2 injection
|
|
13
|
+
* (see {@link isMemoryV3Live}).
|
|
14
|
+
* - `"v2"` when v2 is explicitly enabled and v3 is not live.
|
|
15
|
+
* - `"v1"` otherwise (memory on, neither v2 nor v3 selected).
|
|
16
|
+
*
|
|
17
|
+
* Optional chaining is defensive — a partial config (e.g. a mocked config in
|
|
18
|
+
* tests) resolves to the correct bucket rather than throwing.
|
|
19
|
+
*/
|
|
20
|
+
export function memoryTier(config: AssistantConfig): MemoryTier {
|
|
21
|
+
if (config.memory?.enabled === false) {
|
|
22
|
+
return "off";
|
|
23
|
+
}
|
|
24
|
+
if (isMemoryV3Live(config)) {
|
|
25
|
+
return "v3";
|
|
26
|
+
}
|
|
27
|
+
if (config.memory?.v2?.enabled === true) {
|
|
28
|
+
return "v2";
|
|
29
|
+
}
|
|
30
|
+
return "v1";
|
|
31
|
+
}
|
package/src/monitoring/worker.ts
CHANGED
|
@@ -22,6 +22,10 @@ import {
|
|
|
22
22
|
startConfigSnapshotReporter,
|
|
23
23
|
stopConfigSnapshotReporter,
|
|
24
24
|
} from "../telemetry/config-setting-snapshot.js";
|
|
25
|
+
import {
|
|
26
|
+
startMemoryTierReporter,
|
|
27
|
+
stopMemoryTierReporter,
|
|
28
|
+
} from "../telemetry/memory-tier-reporter.js";
|
|
25
29
|
import {
|
|
26
30
|
startMonitorUsageTelemetryReporter,
|
|
27
31
|
stopUsageTelemetryReporter,
|
|
@@ -94,6 +98,9 @@ async function main(): Promise<void> {
|
|
|
94
98
|
// process flushes.
|
|
95
99
|
startConfigSnapshotReporter();
|
|
96
100
|
|
|
101
|
+
// Emit the coarse memory tier as a periodic per-assistant watchdog heartbeat.
|
|
102
|
+
startMemoryTierReporter();
|
|
103
|
+
|
|
97
104
|
let shuttingDown = false;
|
|
98
105
|
let disposePidGuard: (() => void) | null = null;
|
|
99
106
|
const shutdown = async (signal: string) => {
|
|
@@ -104,6 +111,7 @@ async function main(): Promise<void> {
|
|
|
104
111
|
log.info({ signal }, "Resource monitor process shutting down");
|
|
105
112
|
recovery.stop();
|
|
106
113
|
stopConfigSnapshotReporter();
|
|
114
|
+
stopMemoryTierReporter();
|
|
107
115
|
sourceWatch.stop();
|
|
108
116
|
sampler.stop();
|
|
109
117
|
// Bounded final telemetry flush, mirroring the daemon's shutdown. This
|
|
@@ -41,7 +41,10 @@ interface ProcessEntry {
|
|
|
41
41
|
|
|
42
42
|
const processOriginSchema = z
|
|
43
43
|
.string()
|
|
44
|
-
.regex(/^(workspace|plugin:.+)$/)
|
|
44
|
+
.regex(/^(workspace|plugin:.+)$/)
|
|
45
|
+
.describe(
|
|
46
|
+
"Process origin: 'workspace' for the daemon and its subsystems, or 'plugin:<name>' for a process spawned from a plugin (e.g. 'plugin:default-memory', 'plugin:cognee').",
|
|
47
|
+
) as z.ZodType<ProcessOrigin>;
|
|
45
48
|
|
|
46
49
|
const processEntrySchema: z.ZodType<ProcessEntry> = z
|
|
47
50
|
.lazy(() =>
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { memoryTier } from "../config/memory-tier.js";
|
|
4
|
+
import type { AssistantConfig } from "../config/schema.js";
|
|
5
|
+
import type { ConsentState } from "../platform/consent-cache.js";
|
|
6
|
+
import type { WatchdogEventRecord } from "./watchdog-events-store.js";
|
|
7
|
+
|
|
8
|
+
// Mutable stubs flipped per test. bun's `mock.module` patches retroactively
|
|
9
|
+
// (live bindings), so the reporter's imports resolve to these regardless of
|
|
10
|
+
// import order (mirrors `outbox-test-harness.ts`). Kept off the outbox/DB path
|
|
11
|
+
// on purpose: mocking `recordWatchdogEvent` lets these assert emission without
|
|
12
|
+
// standing up the telemetry DB.
|
|
13
|
+
let consent: ConsentState = true;
|
|
14
|
+
let currentConfig: AssistantConfig = {} as AssistantConfig;
|
|
15
|
+
let recorded: WatchdogEventRecord[] = [];
|
|
16
|
+
|
|
17
|
+
mock.module("../platform/consent-cache.js", () => ({
|
|
18
|
+
getRawShareAnalytics: () => consent,
|
|
19
|
+
}));
|
|
20
|
+
mock.module("../config/loader.js", () => ({
|
|
21
|
+
getConfigReadOnly: () => currentConfig,
|
|
22
|
+
}));
|
|
23
|
+
mock.module("./watchdog-events-store.js", () => ({
|
|
24
|
+
recordWatchdogEvent: (record: WatchdogEventRecord) => {
|
|
25
|
+
recorded.push(record);
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
recordMemoryTierOnce,
|
|
31
|
+
startMemoryTierReporter,
|
|
32
|
+
stopMemoryTierReporter,
|
|
33
|
+
} from "./memory-tier-reporter.js";
|
|
34
|
+
|
|
35
|
+
function makeConfig(
|
|
36
|
+
enabled: boolean,
|
|
37
|
+
v2Enabled: boolean,
|
|
38
|
+
v3Live = false,
|
|
39
|
+
): AssistantConfig {
|
|
40
|
+
return {
|
|
41
|
+
memory: {
|
|
42
|
+
enabled,
|
|
43
|
+
v2: { enabled: v2Enabled },
|
|
44
|
+
v3: { live: v3Live },
|
|
45
|
+
},
|
|
46
|
+
} as AssistantConfig;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe("memory-tier-reporter", () => {
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
consent = true;
|
|
52
|
+
currentConfig = {} as AssistantConfig;
|
|
53
|
+
recorded = [];
|
|
54
|
+
// Clear any interval/boot-retry timer a prior test's start left behind.
|
|
55
|
+
stopMemoryTierReporter();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
stopMemoryTierReporter();
|
|
60
|
+
delete process.env.VELLUM_DEV;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("emits a memory_tier watchdog carrying the current tier", () => {
|
|
64
|
+
const config = makeConfig(true, true); // memory on, v2 enabled → "v2"
|
|
65
|
+
currentConfig = config;
|
|
66
|
+
|
|
67
|
+
recordMemoryTierOnce();
|
|
68
|
+
|
|
69
|
+
expect(recorded).toHaveLength(1);
|
|
70
|
+
expect(recorded[0]).toEqual({
|
|
71
|
+
checkName: "memory_tier",
|
|
72
|
+
detail: { tier: memoryTier(config) },
|
|
73
|
+
});
|
|
74
|
+
expect(recorded[0]?.detail?.tier).toBe("v2");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("reflects a different tier for a different config (v3 live)", () => {
|
|
78
|
+
currentConfig = makeConfig(true, true, true); // v3 live wins over v2
|
|
79
|
+
recordMemoryTierOnce();
|
|
80
|
+
|
|
81
|
+
expect(recorded[0]?.detail).toEqual({ tier: "v3" });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("emits every invocation — no memo", () => {
|
|
85
|
+
currentConfig = makeConfig(true, false); // "v1"
|
|
86
|
+
recordMemoryTierOnce();
|
|
87
|
+
recordMemoryTierOnce();
|
|
88
|
+
recordMemoryTierOnce();
|
|
89
|
+
|
|
90
|
+
expect(recorded).toHaveLength(3);
|
|
91
|
+
for (const event of recorded) {
|
|
92
|
+
expect(event).toEqual({
|
|
93
|
+
checkName: "memory_tier",
|
|
94
|
+
detail: { tier: "v1" },
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("unknown consent emits nothing", () => {
|
|
100
|
+
consent = "unknown";
|
|
101
|
+
currentConfig = makeConfig(true, true);
|
|
102
|
+
|
|
103
|
+
recordMemoryTierOnce();
|
|
104
|
+
|
|
105
|
+
expect(recorded).toHaveLength(0);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("a confirmed opt-out still calls through (recordWatchdogEvent no-ops)", () => {
|
|
109
|
+
// The reporter only skips the UNKNOWN state; the `false` opt-out is
|
|
110
|
+
// honored one layer down in `recordWatchdogEvent`. Here that layer is the
|
|
111
|
+
// stub, so the call is observed — the drop is the real store's concern.
|
|
112
|
+
consent = false;
|
|
113
|
+
currentConfig = makeConfig(true, true);
|
|
114
|
+
|
|
115
|
+
recordMemoryTierOnce();
|
|
116
|
+
|
|
117
|
+
expect(recorded).toHaveLength(1);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("startMemoryTierReporter is a no-op under VELLUM_DEV=1", () => {
|
|
121
|
+
process.env.VELLUM_DEV = "1";
|
|
122
|
+
consent = true; // consent known → a non-dev start would emit immediately
|
|
123
|
+
currentConfig = makeConfig(true, true);
|
|
124
|
+
|
|
125
|
+
startMemoryTierReporter();
|
|
126
|
+
|
|
127
|
+
// No boot emit and no interval scheduled.
|
|
128
|
+
expect(recorded).toHaveLength(0);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { getConfigReadOnly } from "../config/loader.js";
|
|
2
|
+
import { memoryTier } from "../config/memory-tier.js";
|
|
3
|
+
import { getRawShareAnalytics } from "../platform/consent-cache.js";
|
|
4
|
+
import { getLogger } from "../util/logger.js";
|
|
5
|
+
import { recordWatchdogEvent } from "./watchdog-events-store.js";
|
|
6
|
+
|
|
7
|
+
const log = getLogger("memory-tier-reporter");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* How often each assistant re-asserts its coarse memory tier as a
|
|
11
|
+
* `memory_tier` watchdog event. Unlike the config-setting snapshot this emits
|
|
12
|
+
* UNCONDITIONALLY every cycle (no memo): the platform-side query wants a
|
|
13
|
+
* periodic per-assistant heartbeat of the current tier, so a gap in the series
|
|
14
|
+
* is meaningful (assistant offline) rather than "value unchanged". Six-hourly
|
|
15
|
+
* keeps the volume trivial while giving a same-day read on the fleet's tier
|
|
16
|
+
* mix, and every boot re-asserts the tier regardless.
|
|
17
|
+
*/
|
|
18
|
+
const MEMORY_TIER_INTERVAL_MS = 6 * 60 * 60 * 1000;
|
|
19
|
+
|
|
20
|
+
/** Watchdog `check_name` carrying the coarse memory tier in `detail.tier`. */
|
|
21
|
+
const MEMORY_TIER_CHECK_NAME = "memory_tier";
|
|
22
|
+
|
|
23
|
+
// The boot-time emit races the first consent refresh (fire-and-forget in the
|
|
24
|
+
// monitor's startup), so consent is usually still "unknown" on the first call
|
|
25
|
+
// and the emit is skipped. Retry on a short timer until consent resolves
|
|
26
|
+
// rather than waiting a full six-hour interval for the per-boot assertion.
|
|
27
|
+
const BOOT_RETRY_INTERVAL_MS = 60_000;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Emit one `memory_tier` watchdog event for this assistant's current tier.
|
|
31
|
+
*
|
|
32
|
+
* Consent-gated like the config-setting snapshot but with NO memo: every
|
|
33
|
+
* invocation emits, so the platform sees a periodic heartbeat of the current
|
|
34
|
+
* tier rather than only edges. An UNKNOWN consent state skips entirely
|
|
35
|
+
* (consent resolves asynchronously after boot; the boot-retry loop re-invokes
|
|
36
|
+
* once it lands) — deferring loses nothing since the tier is re-derivable
|
|
37
|
+
* state. A confirmed opt-out is honored inside `recordWatchdogEvent`, which
|
|
38
|
+
* no-ops on a `false` share_analytics, so the call still goes through and the
|
|
39
|
+
* record layer drops it. Never throws: a storage failure is logged and
|
|
40
|
+
* retried on the next cycle.
|
|
41
|
+
*/
|
|
42
|
+
export function recordMemoryTierOnce(): void {
|
|
43
|
+
if (getRawShareAnalytics() === "unknown") {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
// `getConfigReadOnly()` re-reads config.json on change (capturing live
|
|
48
|
+
// edits) and never writes to disk — safe for the monitor process.
|
|
49
|
+
const tier = memoryTier(getConfigReadOnly());
|
|
50
|
+
recordWatchdogEvent({
|
|
51
|
+
checkName: MEMORY_TIER_CHECK_NAME,
|
|
52
|
+
detail: { tier },
|
|
53
|
+
});
|
|
54
|
+
} catch (err) {
|
|
55
|
+
log.warn({ err }, "memory_tier watchdog emit failed (non-fatal)");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let tierTimer: ReturnType<typeof setInterval> | null = null;
|
|
60
|
+
let bootRetryTimer: ReturnType<typeof setTimeout> | null = null;
|
|
61
|
+
|
|
62
|
+
function recordBootTierOnceConsentKnown(): void {
|
|
63
|
+
if (getRawShareAnalytics() === "unknown") {
|
|
64
|
+
bootRetryTimer = setTimeout(
|
|
65
|
+
recordBootTierOnceConsentKnown,
|
|
66
|
+
BOOT_RETRY_INTERVAL_MS,
|
|
67
|
+
);
|
|
68
|
+
bootRetryTimer.unref?.();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
bootRetryTimer = null;
|
|
72
|
+
recordMemoryTierOnce();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Start the memory-tier reporter in the resource monitor process: emit the
|
|
77
|
+
* current tier once at boot (once consent resolves), then every six hours,
|
|
78
|
+
* UNCONDITIONALLY. No-op in dev mode (VELLUM_DEV=1) and idempotent if already
|
|
79
|
+
* started. Runs alongside {@link import("./config-setting-snapshot.js").startConfigSnapshotReporter}
|
|
80
|
+
* in the monitor worker.
|
|
81
|
+
*/
|
|
82
|
+
export function startMemoryTierReporter(): void {
|
|
83
|
+
if (process.env.VELLUM_DEV === "1") {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (tierTimer) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
recordBootTierOnceConsentKnown();
|
|
90
|
+
tierTimer = setInterval(recordMemoryTierOnce, MEMORY_TIER_INTERVAL_MS);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Stop the memory-tier reporter loop. Idempotent. */
|
|
94
|
+
export function stopMemoryTierReporter(): void {
|
|
95
|
+
if (tierTimer) {
|
|
96
|
+
clearInterval(tierTimer);
|
|
97
|
+
tierTimer = null;
|
|
98
|
+
}
|
|
99
|
+
if (bootRetryTimer) {
|
|
100
|
+
clearTimeout(bootRetryTimer);
|
|
101
|
+
bootRetryTimer = null;
|
|
102
|
+
}
|
|
103
|
+
}
|