fix(consult): drop traces, budget checkpoints, silent summary inherit
BUG-729: dropped history rounds leave an omission marker in the model-visible summary slot. BUG-730: checkpoint threshold is 0.4 of historyBudgetChars (128k still 16,000). BUG-731: session_full new chat copies owned context_summary on the server; clients send only continued_from_session_id.
This commit is contained in:
@@ -3,13 +3,14 @@ import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
CONSULTATION_HISTORY_TAIL_MAX_CHARS,
|
||||
consultationHistoryCheckpointChars,
|
||||
} from "../src/lib/consultation-session-history.ts";
|
||||
import {
|
||||
buildSummaryPrompt,
|
||||
checkpointSessionContextSummary,
|
||||
generateSessionContextSummary,
|
||||
messagesForSummaryInput,
|
||||
resolveInheritedContextSummary,
|
||||
sanitizeSessionContextSummary,
|
||||
shouldCheckpoint,
|
||||
writeSessionContextSummary,
|
||||
@@ -24,10 +25,14 @@ function overBudgetConversation() {
|
||||
];
|
||||
}
|
||||
|
||||
test("checkpoint triggers only when the tail exceeds 16_000 characters", () => {
|
||||
assert.equal(CONSULTATION_HISTORY_TAIL_MAX_CHARS, 16_000);
|
||||
test("checkpoint triggers only when the tail exceeds the derived threshold", () => {
|
||||
// Former value: hard-coded CONSULTATION_HISTORY_TAIL_MAX_CHARS = 16_000.
|
||||
// 128k still checkpoints at 16_000 (0.4 × 40_000 budget).
|
||||
assert.equal(consultationHistoryCheckpointChars(128_000), 16_000);
|
||||
assert.equal(shouldCheckpoint([{ role: "user", text: "x".repeat(15_999) }], null), false);
|
||||
assert.equal(shouldCheckpoint([{ role: "user", text: "x".repeat(16_001) }], null), true);
|
||||
assert.equal(shouldCheckpoint([{ role: "user", text: "x".repeat(2_400) }], null, { contextWindow: 64_000 }), false);
|
||||
assert.equal(shouldCheckpoint([{ role: "user", text: "x".repeat(2_401) }], null, { contextWindow: 64_000 }), true);
|
||||
});
|
||||
|
||||
test("checkpoint prompt omits the last question-answer pair", () => {
|
||||
@@ -108,6 +113,41 @@ test("writeSessionContextSummary abandons when updatedAt does not match", async
|
||||
assert.equal(result, "abandoned");
|
||||
});
|
||||
|
||||
test("inherited context summary copies owned text and skips foreign or empty sources", async () => {
|
||||
const source = {
|
||||
version: 1 as const,
|
||||
text: "已问过的问题\n事业时机",
|
||||
throughRequestId: "a1",
|
||||
throughMessageIndex: 3,
|
||||
messageCount: 4,
|
||||
updatedAt: "2026-09-15T00:00:00.000Z",
|
||||
};
|
||||
const copied = await resolveInheritedContextSummary({
|
||||
continuedFromSessionId: "11111111-1111-4111-8111-111111111111",
|
||||
loadOwnedSummary: async () => source,
|
||||
});
|
||||
assert.deepEqual(copied, source);
|
||||
|
||||
const foreign = await resolveInheritedContextSummary({
|
||||
continuedFromSessionId: "22222222-2222-4222-8222-222222222222",
|
||||
loadOwnedSummary: async () => null,
|
||||
});
|
||||
assert.equal(foreign, null);
|
||||
|
||||
const empty = await resolveInheritedContextSummary({
|
||||
continuedFromSessionId: "11111111-1111-4111-8111-111111111111",
|
||||
loadOwnedSummary: async () => ({ version: 1, text: " " }),
|
||||
});
|
||||
assert.equal(empty, null);
|
||||
|
||||
const skipped = await resolveInheritedContextSummary({
|
||||
loadOwnedSummary: async () => {
|
||||
throw new Error("should not load");
|
||||
},
|
||||
});
|
||||
assert.equal(skipped, null);
|
||||
});
|
||||
|
||||
test("checkpoint writes a new summary when the tail is over budget", async () => {
|
||||
const result = await checkpointSessionContextSummary({
|
||||
messages: overBudgetConversation(),
|
||||
|
||||
Reference in New Issue
Block a user