@vellumai/assistant 0.10.0-dev.202606201539.0cebd50 → 0.10.0-dev.202606201736.e485b5f
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/package.json +1 -1
- package/src/__tests__/agent-loop-compaction-events.test.ts +0 -1
- package/src/__tests__/agent-loop-compaction-strip.test.ts +0 -1
- package/src/__tests__/agent-loop-exit-reason.test.ts +0 -1
- package/src/__tests__/agent-loop-regrowth-guard.test.ts +0 -1
- package/src/__tests__/compaction.benchmark.test.ts +0 -1
- package/src/__tests__/context-window-manager-compact-retry.test.ts +6 -2
- package/src/__tests__/context-window-manager-overflow-rung.test.ts +6 -2
- package/src/__tests__/db-migration-rollback.test.ts +21 -11
- package/src/__tests__/heartbeat-disk-pressure.test.ts +1 -0
- package/src/__tests__/workspace-git-service.test.ts +114 -1
- package/src/__tests__/workspace-heartbeat-service.test.ts +45 -0
- package/src/agent/loop.ts +10 -24
- package/src/daemon/conversation-agent-loop-handlers.ts +3 -0
- package/src/daemon/conversation-agent-loop.ts +0 -1
- package/src/daemon/conversation.ts +1 -2
- package/src/memory/db-init.ts +255 -223
- package/src/plugins/defaults/compaction/window-manager.ts +32 -69
- package/src/runtime/agent-wake.ts +0 -4
- package/src/workspace/git-service.ts +144 -29
- package/src/memory/migrations/010-ext-conv-bindings-channel-chat-unique.ts +0 -66
- package/src/memory/migrations/038-actor-token-records.ts +0 -45
- package/src/memory/migrations/039-actor-refresh-token-records.ts +0 -57
- package/src/memory/migrations/103-complex-migrations.ts +0 -24
- package/src/memory/migrations/113-late-migrations.ts +0 -32
- package/src/memory/migrations/index.ts +0 -302
package/package.json
CHANGED
|
@@ -104,7 +104,6 @@ function fakeCompaction(
|
|
|
104
104
|
): { trust: TrustContext } {
|
|
105
105
|
createContextWindowManager({
|
|
106
106
|
provider: { name: "mock-provider" } as unknown as Provider,
|
|
107
|
-
systemPrompt: "system",
|
|
108
107
|
config: {} as unknown as ContextWindowConfig,
|
|
109
108
|
conversationId,
|
|
110
109
|
});
|
|
@@ -106,7 +106,6 @@ function installCapturingManager(capture: CompactionInputCapture): {
|
|
|
106
106
|
} {
|
|
107
107
|
createContextWindowManager({
|
|
108
108
|
provider: { name: "mock-provider" } as unknown as Provider,
|
|
109
|
-
systemPrompt: "system",
|
|
110
109
|
config: {} as unknown as ContextWindowConfig,
|
|
111
110
|
conversationId: CONVERSATION_ID,
|
|
112
111
|
});
|
|
@@ -142,7 +142,6 @@ function fakeCompaction(
|
|
|
142
142
|
): { trust: TrustContext } {
|
|
143
143
|
createContextWindowManager({
|
|
144
144
|
provider: { name: "mock-provider" } as unknown as Provider,
|
|
145
|
-
systemPrompt: "system",
|
|
146
145
|
config: {} as unknown as ContextWindowConfig,
|
|
147
146
|
conversationId,
|
|
148
147
|
});
|
|
@@ -101,7 +101,6 @@ function installManager(opts?: { proactiveExhausted?: boolean }): {
|
|
|
101
101
|
const exhausted = opts?.proactiveExhausted ?? false;
|
|
102
102
|
createContextWindowManager({
|
|
103
103
|
provider: { name: "mock-provider" } as unknown as Provider,
|
|
104
|
-
systemPrompt: "system",
|
|
105
104
|
config: {} as unknown as ContextWindowConfig,
|
|
106
105
|
conversationId: CONVERSATION_ID,
|
|
107
106
|
});
|
|
@@ -27,6 +27,12 @@ mock.module("../util/logger.js", () => ({
|
|
|
27
27
|
getLogger: () => makeLoggerStub(),
|
|
28
28
|
}));
|
|
29
29
|
|
|
30
|
+
mock.module("../daemon/conversation-registry.js", () => ({
|
|
31
|
+
findConversationOrSubagent: () => ({
|
|
32
|
+
systemPrompt: "you are a test assistant",
|
|
33
|
+
}),
|
|
34
|
+
}));
|
|
35
|
+
|
|
30
36
|
// ── Module-level mock state ───────────────────────────────────────────
|
|
31
37
|
// Per-test mocks key off these — keeps closures simple and avoids the
|
|
32
38
|
// "declared after mockImplementation references it" TDZ trap.
|
|
@@ -177,7 +183,6 @@ function makeConfig(maxAttempts: number = 3) {
|
|
|
177
183
|
function buildManager(maxAttempts: number = 3): ContextWindowManager {
|
|
178
184
|
return new ContextWindowManager({
|
|
179
185
|
provider: makeProvider(),
|
|
180
|
-
systemPrompt: "you are a test assistant",
|
|
181
186
|
config: makeConfig(maxAttempts),
|
|
182
187
|
conversationId: "conv-test",
|
|
183
188
|
});
|
|
@@ -446,7 +451,6 @@ describe("ContextWindowManager.emergencyCompact", () => {
|
|
|
446
451
|
// GIVEN a manager constructed without a conversation id
|
|
447
452
|
const manager = new ContextWindowManager({
|
|
448
453
|
provider: makeProvider(),
|
|
449
|
-
systemPrompt: "you are a test assistant",
|
|
450
454
|
config: makeConfig(),
|
|
451
455
|
});
|
|
452
456
|
|
|
@@ -30,6 +30,12 @@ mock.module("../util/logger.js", () => ({
|
|
|
30
30
|
getLogger: () => makeLoggerStub(),
|
|
31
31
|
}));
|
|
32
32
|
|
|
33
|
+
mock.module("../daemon/conversation-registry.js", () => ({
|
|
34
|
+
findConversationOrSubagent: () => ({
|
|
35
|
+
systemPrompt: "you are a test assistant",
|
|
36
|
+
}),
|
|
37
|
+
}));
|
|
38
|
+
|
|
33
39
|
// ── Module-level mock state ───────────────────────────────────────────
|
|
34
40
|
// The reducer call is captured so tests can assert which state and config the
|
|
35
41
|
// manager fed in; the returned step is seeded per call so tests can drive the
|
|
@@ -145,7 +151,6 @@ function makeConfig(maxAttempts: number = 3) {
|
|
|
145
151
|
function buildManager(maxAttempts: number = 3): ContextWindowManager {
|
|
146
152
|
return new ContextWindowManager({
|
|
147
153
|
provider: makeProvider(),
|
|
148
|
-
systemPrompt: "you are a test assistant",
|
|
149
154
|
config: makeConfig(maxAttempts),
|
|
150
155
|
conversationId: "conv-test",
|
|
151
156
|
});
|
|
@@ -279,7 +284,6 @@ describe("ContextWindowManager.reduceOverflowOneRung", () => {
|
|
|
279
284
|
] as unknown as ToolDefinition[];
|
|
280
285
|
const manager = new ContextWindowManager({
|
|
281
286
|
provider: makeProvider(),
|
|
282
|
-
systemPrompt: "you are a test assistant",
|
|
283
287
|
config: makeConfig(),
|
|
284
288
|
conversationId: "conv-test",
|
|
285
289
|
toolTokenBudget: 50,
|
|
@@ -17,10 +17,22 @@ import { afterEach, describe, expect, test } from "bun:test";
|
|
|
17
17
|
import { drizzle } from "drizzle-orm/bun-sqlite";
|
|
18
18
|
|
|
19
19
|
import { type DrizzleDb, getSqliteFrom } from "../memory/db-connection.js";
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
import {
|
|
21
|
+
downJobDeferrals,
|
|
22
|
+
migrateJobDeferrals,
|
|
23
|
+
} from "../memory/migrations/001-job-deferrals.js";
|
|
24
|
+
import {
|
|
25
|
+
downMemoryEntityRelationDedup,
|
|
26
|
+
migrateMemoryEntityRelationDedup,
|
|
27
|
+
} from "../memory/migrations/004-entity-relation-dedup.js";
|
|
28
|
+
import {
|
|
29
|
+
downMemoryItemsFingerprintScopeUnique,
|
|
30
|
+
migrateMemoryItemsFingerprintScopeUnique,
|
|
31
|
+
} from "../memory/migrations/005-fingerprint-scope-unique.js";
|
|
32
|
+
import {
|
|
33
|
+
downMemoryItemsScopeSaltedFingerprints,
|
|
34
|
+
migrateMemoryItemsScopeSaltedFingerprints,
|
|
35
|
+
} from "../memory/migrations/006-scope-salted-fingerprints.js";
|
|
24
36
|
import { downAssistantIdToSelf } from "../memory/migrations/007-assistant-id-to-self.js";
|
|
25
37
|
import { downRemoveAssistantIdColumns } from "../memory/migrations/008-remove-assistant-id-columns.js";
|
|
26
38
|
import { downLlmUsageEventsDropAssistantId } from "../memory/migrations/009-llm-usage-events-drop-assistant-id.js";
|
|
@@ -55,20 +67,18 @@ import { migrateDropCapabilityCardStateDown } from "../memory/migrations/176-dro
|
|
|
55
67
|
import { migrateBackfillInlineAttachmentsToDiskDown } from "../memory/migrations/180-backfill-inline-attachments-to-disk.js";
|
|
56
68
|
import { migrateRenameThreadStartersCheckpointsDown } from "../memory/migrations/181-rename-thread-starters-checkpoints.js";
|
|
57
69
|
import { migrateBackfillAudioAttachmentMimeTypesDown } from "../memory/migrations/191-backfill-audio-attachment-mime-types.js";
|
|
70
|
+
import { migrateLlmUsageAttribution } from "../memory/migrations/235-llm-usage-attribution.js";
|
|
58
71
|
import {
|
|
59
|
-
migrateJobDeferrals,
|
|
60
|
-
migrateLlmUsageAttribution,
|
|
61
|
-
migrateMemoryEntityRelationDedup,
|
|
62
|
-
migrateMemoryItemsFingerprintScopeUnique,
|
|
63
|
-
migrateMemoryItemsScopeSaltedFingerprints,
|
|
64
72
|
MIGRATION_REGISTRY,
|
|
65
73
|
type MigrationRegistryEntry,
|
|
66
74
|
type MigrationValidationResult,
|
|
75
|
+
} from "../memory/migrations/registry.js";
|
|
76
|
+
import { runMigrationSteps } from "../memory/migrations/run-migrations.js";
|
|
77
|
+
import {
|
|
67
78
|
rollbackMemoryMigration,
|
|
68
79
|
validateMigrationState,
|
|
69
80
|
withCrashRecovery,
|
|
70
|
-
} from "../memory/migrations/
|
|
71
|
-
import { runMigrationSteps } from "../memory/migrations/run-migrations.js";
|
|
81
|
+
} from "../memory/migrations/validate-migration-state.js";
|
|
72
82
|
import * as schema from "../memory/schema.js";
|
|
73
83
|
|
|
74
84
|
// ---------------------------------------------------------------------------
|
|
@@ -69,6 +69,7 @@ describe("WorkspaceGitService", () => {
|
|
|
69
69
|
expect(content).toContain("*.sock");
|
|
70
70
|
expect(content).toContain("*.pid");
|
|
71
71
|
expect(content).toContain("session-token");
|
|
72
|
+
expect(content).toContain("plugins/*/node_modules/");
|
|
72
73
|
});
|
|
73
74
|
|
|
74
75
|
test("sets git identity correctly", async () => {
|
|
@@ -401,6 +402,30 @@ describe("WorkspaceGitService", () => {
|
|
|
401
402
|
expect(status.clean).toBe(false);
|
|
402
403
|
expect(status.staged).toContain("file.txt");
|
|
403
404
|
});
|
|
405
|
+
|
|
406
|
+
test("tolerates porcelain output larger than 1 MB without throwing", async () => {
|
|
407
|
+
const service = new WorkspaceGitService(testDir);
|
|
408
|
+
await service.ensureInitialized();
|
|
409
|
+
|
|
410
|
+
// git status --porcelain prints one line per untracked entry. Enough
|
|
411
|
+
// long-named entries push the output well past Node's 1 MB execFile
|
|
412
|
+
// maxBuffer; the streamed read must handle it without surfacing
|
|
413
|
+
// ERR_CHILD_PROCESS_STDIO_MAXBUFFER. Files live in the (tracked) root
|
|
414
|
+
// so git reports them individually instead of collapsing a dir.
|
|
415
|
+
const fileCount = 6000;
|
|
416
|
+
const pad = "a".repeat(200);
|
|
417
|
+
for (let i = 0; i < fileCount; i++) {
|
|
418
|
+
writeFileSync(
|
|
419
|
+
join(testDir, `f${String(i).padStart(6, "0")}-${pad}`),
|
|
420
|
+
"",
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const status = await service.getStatus();
|
|
425
|
+
|
|
426
|
+
expect(status.clean).toBe(false);
|
|
427
|
+
expect(status.untracked.length).toBe(fileCount);
|
|
428
|
+
});
|
|
404
429
|
});
|
|
405
430
|
|
|
406
431
|
describe("mutex locking", () => {
|
|
@@ -805,7 +830,7 @@ describe("WorkspaceGitService", () => {
|
|
|
805
830
|
cwd: testDir,
|
|
806
831
|
});
|
|
807
832
|
const gitignoreContent =
|
|
808
|
-
"# Runtime state - excluded from git tracking\ndata/db/\ndata/qdrant/\nlogs/\n*.log\n*.sock\n*.pid\n*.sqlite\n*.sqlite-journal\n*.sqlite-wal\n*.sqlite-shm\n*.db\n*.db-journal\n*.db-wal\n*.db-shm\nvellum.pid\nsession-token\n";
|
|
833
|
+
"# Runtime state - excluded from git tracking\ndata/db/\ndata/qdrant/\nplugins/*/node_modules/\nlogs/\n*.log\n*.sock\n*.pid\n*.sqlite\n*.sqlite-journal\n*.sqlite-wal\n*.sqlite-shm\n*.db\n*.db-journal\n*.db-wal\n*.db-shm\nvellum.pid\nsession-token\n";
|
|
809
834
|
writeFileSync(join(testDir, ".gitignore"), gitignoreContent);
|
|
810
835
|
writeFileSync(join(testDir, "file.txt"), "content");
|
|
811
836
|
execFileSync("git", ["add", "-A"], { cwd: testDir });
|
|
@@ -906,6 +931,54 @@ describe("WorkspaceGitService", () => {
|
|
|
906
931
|
expect(status.untracked).toContain("config.json");
|
|
907
932
|
expect(status.untracked).toContain("README.md");
|
|
908
933
|
});
|
|
934
|
+
|
|
935
|
+
test("excludes plugin node_modules from computed status", async () => {
|
|
936
|
+
const service = new WorkspaceGitService(testDir);
|
|
937
|
+
await service.ensureInitialized();
|
|
938
|
+
|
|
939
|
+
// Track the plugin dir first so git reports finer-grained untracked
|
|
940
|
+
// entries — an entirely-untracked dir collapses to a single line and
|
|
941
|
+
// would hide whether node_modules was filtered.
|
|
942
|
+
mkdirSync(join(testDir, "plugins", "image-fallback"), {
|
|
943
|
+
recursive: true,
|
|
944
|
+
});
|
|
945
|
+
writeFileSync(
|
|
946
|
+
join(testDir, "plugins", "image-fallback", "index.js"),
|
|
947
|
+
"x",
|
|
948
|
+
);
|
|
949
|
+
await service.commitChanges("add plugin");
|
|
950
|
+
|
|
951
|
+
// Plugin dependencies (ignored) alongside a real source change.
|
|
952
|
+
mkdirSync(
|
|
953
|
+
join(testDir, "plugins", "image-fallback", "node_modules", "dep"),
|
|
954
|
+
{ recursive: true },
|
|
955
|
+
);
|
|
956
|
+
writeFileSync(
|
|
957
|
+
join(
|
|
958
|
+
testDir,
|
|
959
|
+
"plugins",
|
|
960
|
+
"image-fallback",
|
|
961
|
+
"node_modules",
|
|
962
|
+
"dep",
|
|
963
|
+
"big.js",
|
|
964
|
+
),
|
|
965
|
+
"module.exports = {}",
|
|
966
|
+
);
|
|
967
|
+
writeFileSync(
|
|
968
|
+
join(testDir, "plugins", "image-fallback", "other.js"),
|
|
969
|
+
"y",
|
|
970
|
+
);
|
|
971
|
+
|
|
972
|
+
const status = await service.getStatus();
|
|
973
|
+
|
|
974
|
+
const allEntries = [
|
|
975
|
+
...status.staged,
|
|
976
|
+
...status.modified,
|
|
977
|
+
...status.untracked,
|
|
978
|
+
];
|
|
979
|
+
expect(allEntries.some((f) => f.includes("node_modules"))).toBe(false);
|
|
980
|
+
expect(status.untracked).toContain("plugins/image-fallback/other.js");
|
|
981
|
+
});
|
|
909
982
|
});
|
|
910
983
|
|
|
911
984
|
describe("deadline-aware commitIfDirty", () => {
|
|
@@ -1102,6 +1175,46 @@ describe("WorkspaceGitService", () => {
|
|
|
1102
1175
|
});
|
|
1103
1176
|
});
|
|
1104
1177
|
|
|
1178
|
+
describe("commitIfDirty status read resilience", () => {
|
|
1179
|
+
test("status read failure does not trip the circuit breaker", async () => {
|
|
1180
|
+
const service = new WorkspaceGitService(testDir);
|
|
1181
|
+
await service.ensureInitialized();
|
|
1182
|
+
|
|
1183
|
+
writeFileSync(join(testDir, "test.txt"), "content");
|
|
1184
|
+
|
|
1185
|
+
// Simulate an oversized/failed `git status` read by making the streamed
|
|
1186
|
+
// status call throw the way Node's maxBuffer overflow would.
|
|
1187
|
+
const proto = Object.getPrototypeOf(service);
|
|
1188
|
+
const originalStreaming = proto.execGitStreaming;
|
|
1189
|
+
proto.execGitStreaming = async function () {
|
|
1190
|
+
const err = new Error(
|
|
1191
|
+
"Git command failed: git status --porcelain\n" +
|
|
1192
|
+
"Error: stdout maxBuffer length exceeded",
|
|
1193
|
+
) as Error & { code?: string };
|
|
1194
|
+
err.code = "ERR_CHILD_PROCESS_STDIO_MAXBUFFER";
|
|
1195
|
+
throw err;
|
|
1196
|
+
};
|
|
1197
|
+
|
|
1198
|
+
try {
|
|
1199
|
+
const result = await service.commitIfDirty(() => ({
|
|
1200
|
+
message: "should not commit",
|
|
1201
|
+
}));
|
|
1202
|
+
// Degrades to "no commit this tick" rather than throwing.
|
|
1203
|
+
expect(result.committed).toBe(false);
|
|
1204
|
+
// Breaker stays closed so the next cycle still runs.
|
|
1205
|
+
expect(_getConsecutiveFailures(service)).toBe(0);
|
|
1206
|
+
} finally {
|
|
1207
|
+
proto.execGitStreaming = originalStreaming;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
// Once status recovers, auto-commit proceeds — it was never disabled.
|
|
1211
|
+
const recovered = await service.commitIfDirty(() => ({
|
|
1212
|
+
message: "after status recovery",
|
|
1213
|
+
}));
|
|
1214
|
+
expect(recovered.committed).toBe(true);
|
|
1215
|
+
});
|
|
1216
|
+
});
|
|
1217
|
+
|
|
1105
1218
|
describe("commitIfDirty diff error handling", () => {
|
|
1106
1219
|
test("non-1 exit code from git diff --cached --quiet is treated as an error", async () => {
|
|
1107
1220
|
const service = new WorkspaceGitService(testDir);
|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
CommitMessageResult,
|
|
22
22
|
} from "../workspace/commit-message-provider.js";
|
|
23
23
|
import {
|
|
24
|
+
_getConsecutiveFailures,
|
|
24
25
|
_resetGitServiceRegistry,
|
|
25
26
|
WorkspaceGitService,
|
|
26
27
|
} from "../workspace/git-service.js";
|
|
@@ -89,6 +90,50 @@ describe("WorkspaceHeartbeatService", () => {
|
|
|
89
90
|
expect(result.skipped).toBe(1);
|
|
90
91
|
});
|
|
91
92
|
|
|
93
|
+
test("continues (does not circuit-break) when a status read fails", async () => {
|
|
94
|
+
writeFileSync(join(testDir, "dirty.txt"), "content");
|
|
95
|
+
|
|
96
|
+
// Force the streamed status read to fail the way a maxBuffer overflow
|
|
97
|
+
// over a bloated working tree would.
|
|
98
|
+
const proto = Object.getPrototypeOf(service);
|
|
99
|
+
const originalStreaming = proto.execGitStreaming;
|
|
100
|
+
proto.execGitStreaming = async function () {
|
|
101
|
+
const err = new Error("stdout maxBuffer length exceeded") as Error & {
|
|
102
|
+
code?: string;
|
|
103
|
+
};
|
|
104
|
+
err.code = "ERR_CHILD_PROCESS_STDIO_MAXBUFFER";
|
|
105
|
+
throw err;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
const heartbeat = new WorkspaceHeartbeatService({
|
|
110
|
+
ageThresholdMs: 0,
|
|
111
|
+
fileThreshold: 1,
|
|
112
|
+
getServices: () => services,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const result = await heartbeat.check();
|
|
116
|
+
|
|
117
|
+
// The cycle is skipped, not failed — and the breaker stays closed.
|
|
118
|
+
expect(result.checked).toBe(1);
|
|
119
|
+
expect(result.failed).toBe(0);
|
|
120
|
+
expect(result.committed).toBe(0);
|
|
121
|
+
expect(_getConsecutiveFailures(service)).toBe(0);
|
|
122
|
+
} finally {
|
|
123
|
+
proto.execGitStreaming = originalStreaming;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Once status recovers, the still-dirty workspace auto-commits — the
|
|
127
|
+
// heartbeat was never disabled.
|
|
128
|
+
const recovered = new WorkspaceHeartbeatService({
|
|
129
|
+
ageThresholdMs: 0,
|
|
130
|
+
fileThreshold: 1,
|
|
131
|
+
getServices: () => services,
|
|
132
|
+
});
|
|
133
|
+
const recoveredResult = await recovered.check();
|
|
134
|
+
expect(recoveredResult.committed).toBe(1);
|
|
135
|
+
});
|
|
136
|
+
|
|
92
137
|
test("does not commit when changes are below age and file thresholds", async () => {
|
|
93
138
|
writeFileSync(join(testDir, "file.txt"), "content");
|
|
94
139
|
|
package/src/agent/loop.ts
CHANGED
|
@@ -500,14 +500,6 @@ export interface AgentLoopRunOptions {
|
|
|
500
500
|
onEvent: (event: AgentEvent) => void | Promise<void>;
|
|
501
501
|
signal?: AbortSignal;
|
|
502
502
|
requestId: string;
|
|
503
|
-
/**
|
|
504
|
-
* System prompt for this run, resolved by the caller (Conversation) before
|
|
505
|
-
* invoking the loop. One turn == one agent loop == one system prompt; the
|
|
506
|
-
* prompt is NOT re-resolved mid-loop (that would bust the provider's
|
|
507
|
-
* prefix cache). When omitted, falls back to the constructor's
|
|
508
|
-
* {@link AgentLoopConstructorOptions.systemPrompt}.
|
|
509
|
-
*/
|
|
510
|
-
systemPrompt?: string;
|
|
511
503
|
/**
|
|
512
504
|
* Explicit model override (provider/model string) for every LLM call in
|
|
513
505
|
* this run. When omitted, the model is resolved through the normal
|
|
@@ -912,14 +904,14 @@ export class AgentLoop {
|
|
|
912
904
|
compactInPlace = false,
|
|
913
905
|
isNonInteractive = false,
|
|
914
906
|
modelProfileKey = null,
|
|
915
|
-
systemPrompt: runSystemPrompt,
|
|
916
907
|
model: runModel,
|
|
917
908
|
} = options;
|
|
918
|
-
//
|
|
919
|
-
//
|
|
920
|
-
//
|
|
921
|
-
//
|
|
922
|
-
|
|
909
|
+
// Snapshot the system prompt once per run. The instance field is mutable
|
|
910
|
+
// (the conversation may update it between turns), but a single run must
|
|
911
|
+
// use one consistent prompt — an aborted run left detached after the
|
|
912
|
+
// watchdog rejects must not pick up a later turn's prompt on its next
|
|
913
|
+
// provider call.
|
|
914
|
+
const runSystemPrompt = this.systemPrompt;
|
|
923
915
|
let history = [...messages];
|
|
924
916
|
// Index into `history` where this run's appended output begins. It starts
|
|
925
917
|
// after the input and resets to the new base whenever the loop rewrites the
|
|
@@ -1227,12 +1219,6 @@ export class AgentLoop {
|
|
|
1227
1219
|
? this.resolveTools(history)
|
|
1228
1220
|
: this.tools;
|
|
1229
1221
|
|
|
1230
|
-
// System prompt and model are resolved once per run (by the caller),
|
|
1231
|
-
// not per-LLM-call — re-resolving mid-loop would bust the provider's
|
|
1232
|
-
// prefix cache.
|
|
1233
|
-
const turnSystemPrompt = resolvedSystemPrompt;
|
|
1234
|
-
const turnModel = runModel;
|
|
1235
|
-
|
|
1236
1222
|
// Field precedence (highest wins):
|
|
1237
1223
|
// 1. Per-run explicit (`runModel`)
|
|
1238
1224
|
// 2. Call-site resolved values (filled by
|
|
@@ -1256,8 +1242,8 @@ export class AgentLoop {
|
|
|
1256
1242
|
providerConfig.max_tokens = this.config.maxTokens;
|
|
1257
1243
|
}
|
|
1258
1244
|
|
|
1259
|
-
if (
|
|
1260
|
-
providerConfig.model =
|
|
1245
|
+
if (runModel) {
|
|
1246
|
+
providerConfig.model = runModel;
|
|
1261
1247
|
}
|
|
1262
1248
|
|
|
1263
1249
|
if (!callSite) {
|
|
@@ -1351,7 +1337,7 @@ export class AgentLoop {
|
|
|
1351
1337
|
currentTools.length > 0 ? estimateToolsTokens(currentTools) : 0;
|
|
1352
1338
|
const preSendEstimatedTokens = estimatePromptTokensRaw(
|
|
1353
1339
|
history,
|
|
1354
|
-
|
|
1340
|
+
runSystemPrompt,
|
|
1355
1341
|
{
|
|
1356
1342
|
providerName: getCalibrationProviderKey(this.provider),
|
|
1357
1343
|
toolTokenBudget,
|
|
@@ -1383,7 +1369,7 @@ export class AgentLoop {
|
|
|
1383
1369
|
// type through unchanged.
|
|
1384
1370
|
const providerOptions: SendMessageOptions = {
|
|
1385
1371
|
tools: currentTools.length > 0 ? currentTools : undefined,
|
|
1386
|
-
systemPrompt:
|
|
1372
|
+
systemPrompt: runSystemPrompt,
|
|
1387
1373
|
config: providerConfig,
|
|
1388
1374
|
onEvent: (event) => {
|
|
1389
1375
|
if (event.type === "text_delta") {
|
|
@@ -296,7 +296,7 @@ export class Conversation {
|
|
|
296
296
|
outputTokens: 0,
|
|
297
297
|
estimatedCost: 0,
|
|
298
298
|
};
|
|
299
|
-
/** @internal */
|
|
299
|
+
/** @internal */ systemPrompt: string;
|
|
300
300
|
/** @internal */ contextCompactedMessageCount = 0;
|
|
301
301
|
/** @internal */ contextCompactedAt: number | null = null;
|
|
302
302
|
/** @internal */ contextSummary: string | null = null;
|
|
@@ -713,7 +713,6 @@ export class Conversation {
|
|
|
713
713
|
});
|
|
714
714
|
createContextWindowManager({
|
|
715
715
|
provider,
|
|
716
|
-
systemPrompt: () => this.buildCurrentSystemPrompt(),
|
|
717
716
|
config: initialContextWindowConfig,
|
|
718
717
|
toolTokenBudget: this.agentLoop.getToolTokenBudget(),
|
|
719
718
|
conversationId: this.conversationId,
|