mirror of
https://github.com/ranxianglei/billion-context.git
synced 2026-11-23 01:58:16 +08:00
fix: re-anchor on the authored checkpoint's conv declaration when full compaction erases all positional proofs (#5719)
A full dsh compaction (#3733 authored checkpoint replacing the whole head) landing in the same turn as a persona-text drift made every positional re-anchor rung structurally unreachable: the recorded tail is gone by definition, the incoming is shorter than the recorded skeleton, and the first post-compaction model step carries zero assistant turns. The live conversation then forked onto <id>|sub:<fp16(new tag)> while the parent record froze (resume-inheritance miss, re-compression from zero). New E5 rung, first in the tagChanged branch: trust the self-declaration embedded in bili's own authored checkpoint — the identity header forged by src/server/dsh-authored-compaction.ts names the exact raw id it belongs to. Gate: first user message only, exact producer format (version-pinned), conv byte-equal to the raw id. External personas quoting checkpoints are unaffected: stamped review/title sidecars never reach the resolver (sideRequestLike gate), and a foreign or late marker fails the gate. Behavior change: this shape went from 'always forks' to 're-anchors on the raw lane when carrying the self-declaration'; every marker-less shape is byte-identical (tests pin each pre-existing rung's reason string). Tests: tests/issue5719-self-checkpoint-reanchor.test.ts (acceptance 1/2/3 + four wire shapes + foreign-quote boundaries); regression suites green locally: dsh-persona-continuity, issue2944-neutral-skeleton, issue3397-persona-restart-stability, side-lane-invariants, issue2601-model-drift-absorption, issue4778-dsh-goal-subfork, issue5686-tagchanged-shorter-tail-reanchor, dsh-persona-fingerprint, issue4438-dsh-review-lane-isolation, issue5095-subagent-lane-token, dsh-authored-compaction.
This commit is contained in:
@@ -5,6 +5,9 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
- **全量压缩与 persona 文本漂移同轮发生时,主会话不再分叉到 `|sub:` 副车道(#5719)**:dsh 全量压缩 checkpoint(#3733 authored checkpoint,把整段历史头替换成一条 user 消息)与系统提示漂移(如 dsh 重启后 GUI 端口重分配写进 system prompt)落在同一轮时,既有的全部位置型 re-anchor 逃生结构性不可达——被记录的尾部按定义已被抹掉、incoming 比记录更短、压缩后首个模型步零 assistant——于是活着的会话确定性地分叉到 `<id>|sub:<fp16(新tag)>`:父车道记录冻结、副车道从零起步(resume-inheritance miss)、事故当天又触发 3 次再压缩 + 1 次 REFUSED turn + 2 次 max-tokens 截断。根因=判定器要求一种全量压缩按定义抹掉的字节级续接证据,而唯一能存活压缩的自足证明——bili 自己铸造的 checkpoint 内嵌的 `conv="<rawId>"` 自声明——从未被读取。现在 tagChanged 分支最前新增 E5 级:**第一条** user 消息携带我方 `\x3cbili-snapshot v1 …\x3e` 身份头且其 conv 与当前 id 逐字相等 → 直接 re-anchor 回主车道(record() 同步更新 tagHash,后续请求即普通 continue)。外部 persona 引用 checkpoint 的情形照旧分叉:要么根本到不了判定层(sideRequestLike 门,#4438),要么标记 conv 不符 / 不在第一条 user 消息。**旧行为→新行为**:该形状从「必然分叉」变为「带自声明时 re-anchor 回主车道」;无标记的形状逐字节不变(回归测试钉住每一既有 rung 的 reason 文案)。tests/issue5719-self-checkpoint-reanchor.test.ts(验收标准 1/2/3 + 四种 wire 形状 + foreign-quote 边界)。
|
||||
|
||||
### Changed
|
||||
- **pi 内联压缩通道默认开启(#5428,取代 #4687 的手动开启规则)**:装了 bili 扩展的裸 `pi`(没设任何环境变量、没写配置)现在直接跑**进程内引擎**,不再自己派生代理进程。新优先级:kill-switch > /bili/ 改写启动 > 显式内联(`BILI_PI_INLINE=1/on/yes/TRUE` 或 `"pi": {"inline": true}`)> 宣告的附着目标(launcher 预置的 `BILLION_CONTEXT_PROXY/ATTACH`,`bili pi` 照旧用自己的 launcher 代理)> **默认内联** > spawn。**人类入口(短旗标,必须放在子命令前)**:`bili -i pi`(≡ `bili pi-inline`,强制内联+预检扩展+清理继承代理变量)与 `bili -s pi`(钉死代理姿态:子进程预置 `BILI_PI_INLINE=0`,压过继承的内联变量;opencode 同理)。不想用内联:`bili -s pi`、`BILI_PI_INLINE=0/false/no/off` 或 `"pi": {"inline": false}`——都恢复旧的 attach/spawn 姿态(有宣告代理就附着,否则自己派生代理)。`bili pi-inline` 一键车道保留(同 `-i pi`);空白 `BILI_PI_INLINE=""` 按未设置折叠。opencode 通道的默认不变(仍手动开启,`-i/-s` 两个旗标对它可用)。
|
||||
- **The full-resend watermark fastpath (#5403/#5418) is now ON by default (GA)** after its §7.4 human review: plugin-lane chat-completions turns whose prefix is byte-stable skip the full history re-parse/re-pin on hit (the #5403 OOM producer), any doubt still falls back to the untouched full-parse path per turn. Opt out per install with `rollout.features.pluginFullResendWatermark: false` (or a percent) or `BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK=0`.
|
||||
|
||||
+57
-1
@@ -161,6 +161,47 @@ function maxAlignedFragRun(kindsA: string[], fragsA: string[], kindsB: string[],
|
||||
* history is the SAME conversation with host-side edits, not a stranger. */
|
||||
const CONTINUATION_MIN_RUN = 8;
|
||||
|
||||
// #5719 E5: the #3733 authored-checkpoint identity header, as FORGED by
|
||||
// src/server/dsh-authored-compaction.ts (BILI_SNAPSHOT_TAG_PREFIX). Pinned
|
||||
// locally instead of imported: this module must stay server-free (the wiring
|
||||
// direction is handle.ts → here), and the version-pin doctrine
|
||||
// (src/server/dsh-compaction-guard.ts header) wants detector constants local.
|
||||
// If the producer's bytes drift the scan degrades to a MISS — the pre-#5719
|
||||
// fork behavior — never to a false claim.
|
||||
const BILI_SNAPSHOT_CONV_RE = /\x3cbili-snapshot v1 [^\x3e]*\bconv="([^"]+)"/;
|
||||
|
||||
/** #5719 E5: does the FIRST user message carry our own authored-checkpoint
|
||||
* identity header declaring exactly `rawId`? A full compaction erases every
|
||||
* continuation proof the tag-changed rungs demand by definition (recorded
|
||||
* tail gone, depth collapsed, zero assistant in the first post-compaction
|
||||
* step) — the self-declaration is the one survivor. Content-blind text
|
||||
* extraction over all four wire shapes (string content; parts/blocks arrays
|
||||
* with .text items — openai/anthropic/responses/google alike). Only the
|
||||
* first user message counts: a LATER quote of a checkpoint (the #4438
|
||||
* class) must never re-anchor someone else's lane. */
|
||||
function selfCheckpointDeclares(history: unknown, rawId: string): boolean {
|
||||
if (!Array.isArray(history)) return false;
|
||||
for (const m of history as unknown[]) {
|
||||
if (m === null || typeof m !== "object") continue;
|
||||
const msg = m as { role?: unknown; content?: unknown; parts?: unknown };
|
||||
if (msg.role !== "user") continue;
|
||||
const c = msg.content !== undefined ? msg.content : msg.parts;
|
||||
let text = "";
|
||||
if (typeof c === "string") {
|
||||
text = c;
|
||||
} else if (Array.isArray(c)) {
|
||||
for (const p of c) {
|
||||
if (p !== null && typeof p === "object" && typeof (p as { text?: unknown }).text === "string") {
|
||||
text += (p as { text: string }).text;
|
||||
}
|
||||
}
|
||||
}
|
||||
const hit = BILI_SNAPSHOT_CONV_RE.exec(text);
|
||||
return hit !== null && hit[1] === rawId;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export type SessionOrderResolution = {
|
||||
key: string;
|
||||
action: "claim" | "continue" | "reanchor" | "derived-aux" | "derived-task" | "derived-persona";
|
||||
@@ -208,7 +249,10 @@ function record(rawId: string, turns: NeutralTurn[], tagHash: string, model?: st
|
||||
* kinds prefix-align AND head fragments match) migrates the raw key
|
||||
* (#2241/#2250); a tag change whose recorded body still sits verbatim at
|
||||
* its own indices inside the incoming (host-side rewrite of its own log —
|
||||
* #4778) migrates too; only a tag change with NO positional continuation
|
||||
* #4778) migrates too; a tag change whose first user message carries our
|
||||
* own authored checkpoint declaring exactly the raw id migrates outright
|
||||
* (#5719 — full compaction erases every positional proof by definition,
|
||||
* the self-declaration is the survivor); only a tag change with NO such
|
||||
* evidence forks onto `<rawId>|sub:<fp16(tag)>` — byte-identical to the
|
||||
* old ladder's fork keys, so persisted fork lanes keep their sessions
|
||||
* across the upgrade.
|
||||
@@ -291,6 +335,18 @@ export function resolveSessionOrder(rawId: string, history: unknown, personaTag?
|
||||
// else is a different persona under the shared id (#150 fresh
|
||||
// task, #1916 auto-review): its own `|sub:<fp16(tag)>` lane,
|
||||
// stable across successive calls of the same persona.
|
||||
if (selfCheckpointDeclares(history, rawId)) {
|
||||
// #5719 E5 (first rung — strongest evidence, cheapest check): the
|
||||
// incoming carries bili's OWN authored checkpoint (#3733) whose
|
||||
// identity header declares this exact raw id. Full compaction
|
||||
// erases every continuation proof the rungs below demand by
|
||||
// definition, so no other evidence is demanded here — the marker
|
||||
// IS the proof. record() moves the recorded tagHash to the new
|
||||
// tag, so the next request is tag-unchanged and simply continues;
|
||||
// the `|sub:` fork never happens and the parent lane unfreezes.
|
||||
record(rawId, turns, tagHash, effectiveModel);
|
||||
return { key: rawId, action: "reanchor", reason: "self-authored checkpoint declares this raw id — continuation across full-compaction rewrite (#5719)" };
|
||||
}
|
||||
const headN = Math.min(kinds.length, recorded.kinds.length);
|
||||
const headAligns = headN > 0 && recorded.kinds.every((k, i) => kinds[i] === k);
|
||||
const headFragsEqual = headN > 0 && incomingFrags.slice(0, headN).every((f, i) => f === recorded.frags[i]);
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
// #5719: a FULL compaction (the #3733 authored checkpoint replacing the whole
|
||||
// head..tail) landing in the SAME TURN as a persona-text drift (dsh restart
|
||||
// reallocating its GUI port into the system prompt — dsh-side root cause
|
||||
// tracked separately) made every positional re-anchor rung structurally
|
||||
// unreachable: the recorded tail is gone by definition, the incoming is
|
||||
// shorter than the recorded skeleton, and the first post-compaction model
|
||||
// step carries zero assistant turns. The resolver then forked the LIVE
|
||||
// conversation onto <id>|sub:<fp16(new tag)> while the parent record froze
|
||||
// (incident: parent lastSeen stuck, sub lane re-compressing from zero the
|
||||
// same day, resume-inheritance miss).
|
||||
//
|
||||
// The fix is the E5 rung: trust the self-declaration embedded in bili's OWN
|
||||
// authored checkpoint — the identity header \x3cbili-snapshot v1
|
||||
// conv="<rawId>" …\x3e forged by src/server/dsh-authored-compaction.ts names
|
||||
// the exact raw id the checkpoint belongs to. It is the one continuation
|
||||
// proof that survives a full compaction, so it outranks every positional
|
||||
// rung. These tests pin the issue's three acceptance criteria plus the
|
||||
// wire-shape matrix and the foreign-quote boundaries (the #4438 class: a
|
||||
// checkpoint QUOTED elsewhere in someone else's blob must never
|
||||
// re-anchor).
|
||||
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "path";
|
||||
import { orderSnapshot, resetSessionOrderForTest, resolveSessionOrder, sessionOrderSkeletonOf } from "../src/session-resolve.ts";
|
||||
|
||||
process.env.NODE_ENV = "test";
|
||||
process.env.BILI_PERSIST = "0";
|
||||
|
||||
// Hermetic state dirs (same discipline as tests/dsh-persona-continuity.test.ts):
|
||||
// without these a rerun hydrates the previous run's persisted skeletons.
|
||||
const testRoot = mkdtempSync(join(tmpdir(), "bili-issue5719-"));
|
||||
test.after(() => rmSync(testRoot, { recursive: true, force: true }));
|
||||
for (const key of ["XDG_STATE_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME", "XDG_CONFIG_HOME"]) process.env[key] = testRoot;
|
||||
|
||||
const ID = "session-64ebc9f9-e957-4f2a-9b02-fe4ff4788225";
|
||||
const OLD_SYS = "You are DeepSeek Harness.\nWeb GUI at http://127.0.0.1:54042\n" + "A".repeat(512);
|
||||
// The incident drift: five digits, same byte length, nowhere else different.
|
||||
const NEW_SYS = OLD_SYS.replace("54042", "62335");
|
||||
const fp16 = (s: string): string => createHash("sha256").update(s, "utf8").digest("hex").slice(0, 16);
|
||||
|
||||
const MARKER = `\x3cbili-snapshot v1 conv="${ID}" seq="147" blocks="b1+b2+b3+b4+b5+b6+b7+b8" \x3e`;
|
||||
const CHECKPOINT = MARKER + "\nSummary of the folded conversation: built the parser, fixed the off-by-one.";
|
||||
const PLAIN_CHECKPOINT = "Summary of the folded conversation: built the parser, fixed the off-by-one.";
|
||||
|
||||
type Msg = Record<string, unknown>;
|
||||
|
||||
/** Deep main-shaped openai history under `sys` (the claim shape). */
|
||||
const deepHistory = (sys: string, cells = 20): Msg[] => {
|
||||
const body: Msg[] = [];
|
||||
for (let i = 0; i < cells; i++) body.push({ role: i % 2 === 0 ? "user" : "assistant", content: `cell-${i}-` + "z".repeat(120) });
|
||||
return [{ role: "system", content: sys }, ...body];
|
||||
};
|
||||
|
||||
/** Fresh post-compaction scaffolding: NO assistant turns, content sharing
|
||||
* nothing with the recorded skeleton (the incident's turn-3 cells). */
|
||||
const tailCells = (cells = 12): Msg[] => {
|
||||
const body: Msg[] = [];
|
||||
for (let i = 0; i < cells; i++) body.push({ role: i % 3 === 0 ? "tool" : "user", content: `post-${i}-` + "q".repeat(80) });
|
||||
return body;
|
||||
};
|
||||
|
||||
/** Incident shape: system re-render + the checkpoint replacing the ENTIRE
|
||||
* recorded tail + fresh scaffolding, zero assistant. */
|
||||
const postCompaction = (sys: string, checkpoint: string): Msg[] =>
|
||||
[{ role: "system", content: sys }, { role: "user", content: checkpoint }, ...tailCells()];
|
||||
|
||||
test("E5: an authored checkpoint declaring the raw id re-anchors across full compaction + tag drift (acceptance 1)", () => {
|
||||
resetSessionOrderForTest();
|
||||
const r0 = resolveSessionOrder(ID, deepHistory(OLD_SYS), OLD_SYS);
|
||||
assert.equal(r0.action, "claim");
|
||||
const before = sessionOrderSkeletonOf(ID);
|
||||
assert.ok(before && before.length >= 20, "deep skeleton recorded");
|
||||
|
||||
const r1 = resolveSessionOrder(ID, postCompaction(NEW_SYS, CHECKPOINT), NEW_SYS);
|
||||
assert.equal(r1.key, ID, "stays on the raw lane");
|
||||
assert.equal(r1.action, "reanchor");
|
||||
assert.match(r1.reason ?? "", /#5719/);
|
||||
|
||||
// Parent unfrozen: the recorded skeleton moved to the post-compaction shape.
|
||||
const after = sessionOrderSkeletonOf(ID);
|
||||
assert.ok(after && after.length < (before?.length ?? 0), "skeleton followed the compacted history");
|
||||
assert.notDeepEqual(after, before);
|
||||
// No |sub: lane was minted for the drifted tag.
|
||||
assert.ok(orderSnapshot().every((e) => !e.id.startsWith(`${ID}|sub:`)), "no sub lane exists");
|
||||
|
||||
// Next request: the tag now matches the recorded one → plain continue.
|
||||
const r2 = resolveSessionOrder(ID, postCompaction(NEW_SYS, CHECKPOINT), NEW_SYS);
|
||||
assert.equal(r2.key, ID);
|
||||
assert.equal(r2.action, "continue");
|
||||
});
|
||||
|
||||
test("control: the SAME shape without the marker still forks (E5 is the only rescuer; the #5686 tail rung cannot reach a fully-erased tail)", () => {
|
||||
resetSessionOrderForTest();
|
||||
assert.equal(resolveSessionOrder(ID, deepHistory(OLD_SYS), OLD_SYS).action, "claim");
|
||||
const before = sessionOrderSkeletonOf(ID);
|
||||
|
||||
const r = resolveSessionOrder(ID, postCompaction(NEW_SYS, PLAIN_CHECKPOINT), NEW_SYS);
|
||||
assert.equal(r.action, "derived-persona");
|
||||
assert.equal(r.key, `${ID}|sub:${fp16(NEW_SYS)}`);
|
||||
// The raw record stayed FROZEN (only the fork lane was written).
|
||||
assert.deepEqual(sessionOrderSkeletonOf(ID), before);
|
||||
});
|
||||
|
||||
test("acceptance 2: a foreign persona quoting a checkpoint never re-anchors the raw id", () => {
|
||||
resetSessionOrderForTest();
|
||||
assert.equal(resolveSessionOrder(ID, deepHistory(OLD_SYS), OLD_SYS).action, "claim");
|
||||
const before = sessionOrderSkeletonOf(ID);
|
||||
const REVIEW_SYS = "You are the final authorization reviewer for exactly one pending tool call.\nAnswer with one word.";
|
||||
const forkKey = `${ID}|sub:${fp16(REVIEW_SYS)}`;
|
||||
|
||||
// (a) the blob quotes a checkpoint declaring ANOTHER id.
|
||||
const foreignQuote = `Transcript:\n${MARKER.replace(`conv="${ID}"`, 'conv="session-other-aaaa-bbbb"')}\nDecide: risky?`;
|
||||
const ra = resolveSessionOrder(ID, [{ role: "system", content: REVIEW_SYS }, { role: "user", content: foreignQuote }], REVIEW_SYS);
|
||||
assert.equal(ra.action, "derived-persona");
|
||||
assert.equal(ra.key, forkKey);
|
||||
|
||||
// (b) the blob quotes OUR marker — but in the SECOND user message. The
|
||||
// scan stops at the first user message by design (an authored
|
||||
// checkpoint always REPLACES the head, so it is the first one).
|
||||
const lateMarker: Msg[] = [
|
||||
{ role: "system", content: REVIEW_SYS },
|
||||
{ role: "user", content: "plain question" },
|
||||
{ role: "user", content: `quoted:\n${CHECKPOINT}` },
|
||||
];
|
||||
const rb = resolveSessionOrder(ID, lateMarker, REVIEW_SYS);
|
||||
assert.equal(rb.action, "derived-persona");
|
||||
assert.equal(rb.key, forkKey);
|
||||
|
||||
// Raw record untouched by both attempts.
|
||||
assert.deepEqual(sessionOrderSkeletonOf(ID), before);
|
||||
});
|
||||
|
||||
test("acceptance 2b: a marker outside a user message does not count (role gate)", () => {
|
||||
resetSessionOrderForTest();
|
||||
assert.equal(resolveSessionOrder(ID, deepHistory(OLD_SYS), OLD_SYS).action, "claim");
|
||||
const r = resolveSessionOrder(
|
||||
ID,
|
||||
[{ role: "system", content: NEW_SYS + "\n" + MARKER }, { role: "user", content: "plain question" }],
|
||||
NEW_SYS,
|
||||
);
|
||||
assert.equal(r.action, "derived-persona");
|
||||
assert.equal(r.key, `${ID}|sub:${fp16(NEW_SYS)}`);
|
||||
});
|
||||
|
||||
test("E5 fires on all four wire shapes (string / openai+anthropic parts / responses item / google parts)", () => {
|
||||
const shapes: Array<[string, (cp: string, sys: string) => Msg[]]> = [
|
||||
["openai-string", (cp, sys) => postCompaction(sys, cp)],
|
||||
[
|
||||
"openai-parts",
|
||||
(cp, sys) => [{ role: "system", content: sys }, { role: "user", content: [{ type: "text", text: cp }] }, ...tailCells()],
|
||||
],
|
||||
[
|
||||
"anthropic-parts",
|
||||
(cp, sys) => [{ role: "system", content: sys }, { role: "user", content: [{ type: "text", text: cp }] }, ...tailCells()],
|
||||
],
|
||||
[
|
||||
"responses-item",
|
||||
(cp, sys) => [
|
||||
{ role: "system", content: sys },
|
||||
{ type: "message", role: "user", content: [{ type: "input_text", text: cp }] },
|
||||
...tailCells(),
|
||||
],
|
||||
],
|
||||
[
|
||||
"google-parts",
|
||||
(cp, sys) => [{ role: "system", content: sys }, { role: "user", parts: [{ text: cp }] }, ...tailCells()],
|
||||
],
|
||||
];
|
||||
for (const [name, build] of shapes) {
|
||||
resetSessionOrderForTest();
|
||||
assert.equal(resolveSessionOrder(ID, deepHistory(OLD_SYS), OLD_SYS).action, "claim", name);
|
||||
const r = resolveSessionOrder(ID, build(CHECKPOINT, NEW_SYS), NEW_SYS);
|
||||
assert.equal(r.key, ID, name);
|
||||
assert.equal(r.action, "reanchor", name);
|
||||
assert.match(r.reason ?? "", /#5719/, name);
|
||||
}
|
||||
});
|
||||
|
||||
test("acceptance 3: without any marker the pre-existing rungs are untouched (reasons byte-stable)", () => {
|
||||
// The pre-existing tagChanged outcomes, each with its historical reason
|
||||
// string, none of them carrying a checkpoint marker. Corpora mirror the
|
||||
// suites that own each rung (tests/issue2601-*, tests/issue4778-*,
|
||||
// tests/issue5686-tagchanged-shorter-tail-reanchor.*).
|
||||
const plain = (n: number, label: string): Msg[] =>
|
||||
Array.from({ length: n }, (_, i) => ({ role: i % 2 === 0 ? "user" : "assistant", content: `${label}-${i + 1}-` + "x".repeat(120) }));
|
||||
|
||||
// E1: continuing history under a new system → anchor migrated (#2241/#2250).
|
||||
resetSessionOrderForTest();
|
||||
assert.equal(resolveSessionOrder("e1", [{ role: "system", content: OLD_SYS }, ...plain(12, "e1")], OLD_SYS).action, "claim");
|
||||
const r1 = resolveSessionOrder("e1", [{ role: "system", content: NEW_SYS }, ...plain(12, "e1"), { role: "user", content: "next-" + "w".repeat(64) }], NEW_SYS);
|
||||
assert.equal(r1.action, "reanchor");
|
||||
assert.match(r1.reason ?? "", /#2241\/#2250/);
|
||||
|
||||
// E2: header-corroborated model switch on fresh deep history.
|
||||
resetSessionOrderForTest();
|
||||
assert.equal(resolveSessionOrder("e2", [{ role: "system", content: OLD_SYS }, ...plain(12, "e2")], OLD_SYS, "model-a").action, "claim");
|
||||
const r2 = resolveSessionOrder("e2", [{ role: "system", content: NEW_SYS }, ...plain(6, "fresh-e2")], NEW_SYS, "model-b");
|
||||
assert.equal(r2.action, "reanchor");
|
||||
assert.match(r2.reason ?? "", /#2601\/#2817/);
|
||||
|
||||
// E4: host cleared mid-history harness cells; conversation cells keep
|
||||
// their indices (#4778).
|
||||
resetSessionOrderForTest();
|
||||
assert.equal(resolveSessionOrder("e4", [{ role: "system", content: OLD_SYS }, ...plain(12, "e4")], OLD_SYS).action, "claim");
|
||||
const e4body = plain(12, "e4").flatMap((m) => [{ role: "system", content: "" }, m]);
|
||||
const r4 = resolveSessionOrder("e4", [{ role: "system", content: NEW_SYS }, ...e4body, { role: "user", content: "goal-" + "g".repeat(120) }], NEW_SYS);
|
||||
assert.equal(r4.action, "reanchor");
|
||||
assert.match(r4.reason ?? "", /#4778/);
|
||||
|
||||
// Fifth rung (#5686): strictly shorter incoming keeping the verbatim tail.
|
||||
resetSessionOrderForTest();
|
||||
const seedC = [{ role: "system", content: OLD_SYS }, ...plain(16, "c5686")];
|
||||
assert.equal(resolveSessionOrder("c5686", seedC, OLD_SYS).action, "claim");
|
||||
const r5686 = resolveSessionOrder("c5686", [{ role: "system", content: NEW_SYS }, { role: "user", content: "checkpoint sentence" }, ...seedC.slice(9)], NEW_SYS);
|
||||
assert.equal(r5686.action, "reanchor");
|
||||
assert.match(r5686.reason ?? "", /#5686/);
|
||||
|
||||
// Fork: nothing aligns → persona lane, historical reason intact.
|
||||
resetSessionOrderForTest();
|
||||
assert.equal(resolveSessionOrder("fork", deepHistory(OLD_SYS), OLD_SYS).action, "claim");
|
||||
const rf = resolveSessionOrder("fork", postCompaction(NEW_SYS, PLAIN_CHECKPOINT), NEW_SYS);
|
||||
assert.equal(rf.action, "derived-persona");
|
||||
assert.match(rf.reason ?? "", /persona lane/);
|
||||
});
|
||||
Reference in New Issue
Block a user