Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/server/egress-lane-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ import type { Session } from "../session.js";

type LaneLog = (level: string, msg: string) => void;

/** The rendered history tag the kernel puts ahead of a message body
* (`<acp tokens=… type=…>mNNNNN</acp>` + one newline). Angle brackets are
* hex-escaped per KDD #2 — literal tag sequences in source get mangled by
* content sanitizers upstream of git push (same construction as
* kernel/src/ccr.ts `LEADING_TAG_RE`). */
const LEADING_ACP_TAG_RE = new RegExp("^\\x3cacp\\b[^>]*>m\\d+\\x3c/acp>\\n?");

/** Ruling 7439-5 identity/order channel + divergence sampler.
*
* Part 1 ORDER: every client id that exists in the server view must appear
Expand All @@ -66,7 +73,10 @@ type LaneLog = (level: string, msg: string) => void;
* contentType + text length + (short, ≤32KB) exact text. A mismatch does NOT
* fail the probe — the seam keeps server bytes regardless of what the client
* sent; sampling only LOGS the divergence event (ruling: 记日志 + 警告,
* 内容跟服务端, 出站自然收敛). */
* 内容跟服务端, 出站自然收敛). Server rows hold kernel output, so the
* rendered `<acp …>mNNNNN</acp>` tag ahead of the body is stripped before
* comparing (#8316); the client resends the untagged body, and counting the
* tag as divergence warned on every clean turn. */
export function egressAuthorityProbe(
base: readonly BiliMessage[],
client: readonly BiliMessage[],
Expand All @@ -92,7 +102,7 @@ export function egressAuthorityProbe(
if (bi === undefined) continue;
const b = base[bi];
const ct = typeof c.text === "string" ? c.text : "";
const bt = typeof b.text === "string" ? b.text : "";
const bt = (typeof b.text === "string" ? b.text : "").replace(LEADING_ACP_TAG_RE, "");
if (c.contentType !== b.contentType || ct.length !== bt.length || (ct.length <= 32768 && ct !== bt)) diverged++;
if (diverged >= 4) break;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/egress-authority-ladder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ test("egressAuthorityProbe: identity + order + sampled-byte rows (#3617 both dir
assert.equal(egressAuthorityProbe(base, [M("m9", "fresh")], S, quiet), true, "all-fresh client rows pass");
});

test("egressAuthorityProbe: rendered acp tag on server rows is not divergence (#8316)", () => {
const logs: string[] = [];
const collect = (_level: string, msg: string) => logs.push(msg);
// server rows hold kernel output: the rendered tag rides ahead of the body
const base = [M("m1", "<acp tokens=\"2\" type=\"text\" time=\"2026-12-05T00:00:00Z\">m00001</acp>\nalpha"), M("m2", "<acp tokens=\"1\" type=\"text\" time=\"2026-12-05T00:00:01Z\">m00002</acp>\nbeta")];
// unchanged client resend carries the untagged body only => no divergence warn
assert.equal(egressAuthorityProbe(base, [M("m1", "alpha"), M("m2", "beta")], S, collect), true);
assert.equal(logs.length, 0, "tagged server rows vs untagged identical client rows stay quiet");
// a real body edit under the tag still warns
assert.equal(egressAuthorityProbe(base, [M("m1", "alpha"), M("m2", "tampered beta")], S, collect), true);
assert.equal(logs.length, 1, "real divergence still logs");
});

test("egress-lane-io: authority seam records first, then serves the written view (#7439-4, P1-1 regression)", () => {
const H = open();
const session = { metadata: {} } as unknown as Session;
Expand Down
Loading