Skip to content
Merged
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag

### Added

### 修复 master 回归(搭乘)

- **#4525 合并把 `sidScope` 改名 `dispatchScope` 漏改一处**:dsh fork-blind-spot 日志(C10b,#4215)仍读旧名 → master tsc 红(`TS2304: Cannot find name 'sidScope'`,dsh-native.ts:1287,CI run 40093629255 failure 同因)。修复=读 `dispatchScope.getStore()` 并按 `{sid,msgIds}` 形状取 `.sid`,语义不变(作用域归因活跃判定)。

### 折叠记账迁正史 seq 区间(#4316 层3 PR2/3)

- **kernel 双轨覆盖**:CompressionBlock 增 `startSeq`/`endSeq`(可选,仅当折叠范围全部带章且区间精确才记录,任一无章/有洞=不记——never guess);prune 的 rebuildMessages 在 id 覆盖判定后加区间判定 `isCoveredBySeq`(带章消息落任意活跃块区间即压制原件,与 id churn 解耦);syncBlocks 块活性判定加第三析取项 `blockSeqPresent`(块有界+任一在场消息带章落区间=块仍活着,防 id 重铸引发 deactivate)。
- **章的传输与重钉**:插件车道 canonical 行带 `ledgerSeq`(store 0 基→显示 1 基)经 `biliLedgerSeqs` 平行数组随 turn body 传输(与 biliMsgIds 同位,校验严格、拒绝降级不上游泄漏);prepare-anthropic 与 msgid pin 同位重钉(章只进内核态,不改 wire 格式);lane 侧 assembly 对本 turn 未落库尾部按 maxSeq+1 递增投影;`recordCanonicalPointers` 每 wrap-up 回写行章。
- **行身份免疫章**:`identityInputOf` 剥除清单加 `ledgerSeq`(服务端晚加的位置章非逻辑内容,不参与行身份哈希——否则每轮带章重入库整段换血)。
- **验收桩**:kernel 侧 4 测(盖章折叠记区间+id churn 后按区间压制/对照无章丢覆盖=snapshot 现状文档化;sync 盖章 churn 视图保块活性;部分盖章不记界;相邻联合区间精确+空洞不记录);lane 侧端到端 1 测(12 消息 lane 折叠→store `start_seq`/`end_seq` 落真值+payload 区间章+出站压制原件+首用户钉存活+摘要乘 #1567 载体回显)。

### 判官渲染基准(#4241)

- **出站判官感知快照渲染车道**:渲染轮(turn 的出站前缀由服务端正史替换——摘要锚+存储行)上,判官的对账基准从「客户端入站原始字节」换成「引擎计算的渲染视图」(prepare 层引用不等判别 `judgeBaseline`,仅视图真正被替换时携带;relay 判官消费点换基准,其余字节等价)。修复:渲染车道每个折叠轮误报 I2 `mid-history-rewrite`(入站原件被覆盖/覆写属引擎定义行为);判官对渲染引擎自身的缺陷(前缀行丢失/插入)照常开火——桩含注错对照。
Expand Down
1 change: 1 addition & 0 deletions LIFECYCLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
| `BILI_ROLLOUT_`(前缀家族;现成员 `BILI_ROLLOUT_SIMHASH_V2`、`BILI_ROLLOUT_FOLD_GUARD`) | src/rollout.ts 灰度机制 | 每功能灰度 kill-switch:env > config `rollout.features.<name>`(true/false/percent 简写,#3062)> 确定性分桶(sha256(salt\nid)%10000)> off | 单个功能灰度完成并稳定后,从 rollout 表移除该功能,其 env 随之失去意义 | 机制常设;单个成员轮换 |
| `BILI_FOLD_RECONCILE` | #1921 | fold 对账模式 off/warn/repair(默认 repair;非法值只告警不致命,src/fold-reconcile.ts:384) | 增量车道 #3248 落地后评估 legacy 对账路径去留 | 在用(默认 repair);与 #3248 联动 |
| `BILI_RECLAIM_FETCH_PATCH` | #1158 | escape hatch:`=0` 保留经典直装 fetch patch 路径 | fetch-chain patch 成为既定行为后退役 | 默认开(`=0` 回退经典路径) |
| `BILI_CODEX_STATE_MODE` | #2222 | codex state-db 策略逃生口(auto/shared/legacy;auto=二进制认 CODEX_SQLITE_HOME 就 shared 否则 legacy;shared 遇旧二进制降级并告警) | codex 状态策略稳定后随 #2222 收尾 | 默认 auto |
| `BILI_CODEX_COMPACT` | #3008 | codex compaction 拦截 kill-switch(intercept/pass);intercept 覆盖显式与内联 auto-compact(SUMMARIZATION_PROMPT 识别) | intercept-by-default 站稳后评估 pass 模式是否还有人需要 | 默认 intercept |
| `BILI_CODEX_STATE_MODE` | #2222/#3321 | codex 状态库策略逃生舱:`auto`(默认,二进制支持 CODEX_SQLITE_HOME 则 shared,否则 legacy)/ `legacy`(始终旧拷贝路径)/ `shared`(请求 shared,二进制太旧时降级 legacy 并告警);非法值告警后按 auto(src/launcher.ts:3674) | shared/auto 策略站稳(#3321 并发车道落地后观察)后评估去留 | 在用(默认 auto) |
| `BILI_SQLITE_AUTO_DOWNLOAD` | #2833 | sqlite 引擎自下载开关(严格 1/0 > 文件 > 默认 true;被拒时仍用缓存副本) | —(转正为常设安全阀则移 §2) | 在用(默认 true) |
Expand Down
4 changes: 2 additions & 2 deletions kernel/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kernel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "acp-kernel",
"version": "0.0.161",
"version": "0.0.162",
"description": "Framework-agnostic context-compression engine (model-driven, 3-tier LSM). Pure core: no host dependency.",
"license": "MIT",
"author": "ranxianglei",
Expand Down
63 changes: 63 additions & 0 deletions kernel/src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,13 @@ function applySingleRange(input: SingleRangeInput): SingleRangeOutcome {
}

const blockId = allocateBlockId(input.state);
// #4316 layer 3: resolve the fold's ledger interval before constructing the
// block. The claim is recorded only when it is EXACT — see
// resolveCoverageInterval.
const interval = resolveCoverageInterval(
filteredIds.map((id) => input.messages.find((entry) => entry.id === id)),
consumedBlockIds.map((id) => blockById(input.state, id)),
);
const block: CompressionBlock = {
blockId,
runId: input.runId,
Expand All @@ -1588,6 +1595,9 @@ function applySingleRange(input: SingleRangeInput): SingleRangeOutcome {
compressCallId: input.spec.compressCallId,
startRef: input.spec.startRef,
endRef: input.spec.endRef,
...(interval
? { startSeq: interval.start, endSeq: interval.end }
: {}),
};
input.state.blocks.push(block);

Expand All @@ -1599,6 +1609,59 @@ function applySingleRange(input: SingleRangeInput): SingleRangeOutcome {
return { tokens: compressedTokens, warnings };
}

/**
* #4316 layer 3: compute a fold's unified-ledger interval claim from its
* direct (folded) messages and consumed blocks. Returns [start, end] ONLY
* when the claim is exact:
* - every direct message carries an integer ledgerSeq stamp;
* - every consumed block carries its own startSeq/endSeq bounds;
* - merging the resulting segments (direct seq points + consumed
* intervals, overlaps/adjacency merged) yields exactly ONE contiguous
* segment — a hole between them means [min, max] would swallow messages
* the fold does not actually cover, so no bounds are recorded and the
* id path stays authoritative for this block. Never guessed.
*/
function resolveCoverageInterval(
directMessages: Array<CoreMessage | undefined>,
consumedBlocks: Array<CompressionBlock | undefined>,
): { start: number; end: number } | undefined {
const segments: Array<{ start: number; end: number }> = [];
for (const message of directMessages) {
if (
!message ||
typeof message.ledgerSeq !== "number" ||
!Number.isInteger(message.ledgerSeq)
) {
return undefined; // unstamped direct traffic — never guess
}
segments.push({ start: message.ledgerSeq, end: message.ledgerSeq });
}
for (const consumed of consumedBlocks) {
if (
!consumed ||
typeof consumed.startSeq !== "number" ||
typeof consumed.endSeq !== "number" ||
consumed.endSeq < consumed.startSeq
) {
return undefined; // unbounded consumed block (or legacy) — never guess
}
segments.push({ start: consumed.startSeq, end: consumed.endSeq });
}
if (segments.length === 0) return undefined;
segments.sort((a, b) => a.start - b.start || a.end - b.end);
let merged = { ...segments[0]! };
for (const segment of segments.slice(1)) {
if (segment.start <= merged.end + 1) {
// Adjacent or overlapping — merge (overlap can only shrink the union,
// keeping the [min,max] claim exact).
if (segment.end > merged.end) merged.end = segment.end;
} else {
return undefined; // hole — a [min,max] claim would over-cover
}
}
return merged;
}

function validateCompressionRange(
input: SingleRangeInput,
directMessageIds: string[],
Expand Down
48 changes: 48 additions & 0 deletions kernel/src/prune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,44 @@ export function isCovered(id: string, coveredBases: Set<string>): boolean {
return coveredBases.has(baseIdOf(id));
}

/**
* #4316 layer 3: seq-interval coverage claims. A block that recorded an exact
* ledger interval (startSeq/endSeq) covers ANY message carrying a ledgerSeq
* stamp inside that interval — id churn (model switch / re-stamp / re-encode
* re-mints every content-hash id) cannot invalidate the positional claim.
* Blocks without bounds contribute nothing; messages without stamps are
* decided by the id path alone. Both paths run in parallel (union): the id
* path stays byte-identical for unstamped traffic.
*/
export function coveredSeqIntervals(
state: CompressionState,
): Array<{ start: number; end: number }> {
const intervals: Array<{ start: number; end: number }> = [];
for (const block of state.blocks) {
if (!block.active) continue;
if (
typeof block.startSeq === "number" &&
typeof block.endSeq === "number" &&
block.endSeq >= block.startSeq
) {
intervals.push({ start: block.startSeq, end: block.endSeq });
}
}
return intervals;
}

/** True when `seq` falls inside any active block's exact interval claim. */
export function isCoveredBySeq(
seq: number | undefined,
intervals: Array<{ start: number; end: number }>,
): boolean {
if (typeof seq !== "number" || !Number.isInteger(seq)) return false;
for (const interval of intervals) {
if (seq >= interval.start && seq <= interval.end) return true;
}
return false;
}

/**
* True when a message is a rendered block summary (the exact shape prune
* emits). The id prefix alone is not sufficient — a host-authored message
Expand Down Expand Up @@ -176,6 +214,8 @@ export function prune(
rebuildMessages(
messages,
coveredBases,
// #4316 layer 3: positional claims, built once per prune pass.
coveredSeqIntervals(state),
firstUserIndex,
anchors,
knownSummaryIds,
Expand Down Expand Up @@ -387,6 +427,9 @@ const wireIndexOf = (m: CoreMessage): number | undefined =>
function rebuildMessages(
messages: CoreMessage[],
coveredBases: Set<string>,
// #4316 layer 3: exact ledger-interval claims of active blocks (positional
// coverage, immune to id churn), threaded from prune().
seqIntervals: Array<{ start: number; end: number }>,
firstUserIndex: number,
anchors: SummaryAnchor[],
knownSummaryIds: Set<string>,
Expand Down Expand Up @@ -466,6 +509,11 @@ function rebuildMessages(
continue;
}
if (isCovered(messages[index]!.id, coveredBases)) continue;
// #4316 layer 3: positional coverage — a stamped message inside any
// active block's exact ledger interval is covered even when its id was
// re-minted (the id check above just missed it by construction). Runs
// after the pin and the id path so unstamped behavior is untouched.
if (isCoveredBySeq(messages[index]!.ledgerSeq, seqIntervals)) continue;
// A stale copy of a block's summary from a previously-pruned view:
// the freshly rendered one above replaces it. Active blocks re-render
// at their anchor; consumed blocks (chain re-fold) are covered by their
Expand Down
36 changes: 35 additions & 1 deletion kernel/src/sync.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
import { baseIdOf, summaryMessageId } from "./prune.js";
import type { CompressionState, CoreMessage } from "./types.js";

/** #4316 layer 3: true when any visible message's ledgerSeq stamp falls
* inside the block's exact interval claim. Unbounded blocks and unstamped
* views answer false — the id path decides those. */
function blockSeqPresent(
block: { startSeq?: number; endSeq?: number },
messages: CoreMessage[],
): boolean {
if (
typeof block.startSeq !== "number" ||
typeof block.endSeq !== "number" ||
block.endSeq < block.startSeq
) {
return false;
}
for (const message of messages) {
const seq = message.ledgerSeq;
if (
typeof seq === "number" &&
Number.isInteger(seq) &&
seq >= block.startSeq &&
seq <= block.endSeq
) {
return true;
}
}
return false;
}

export interface SyncResult {
state: CompressionState;
deactivated: string[];
Expand Down Expand Up @@ -115,9 +143,15 @@ export function syncBlocks(
// (pruned view) is still present — the summary IS the block's visible
// representation. Without this, hosts passing pruned views would lose
// block activity every turn.
// #4316 layer 3: a block with an exact ledger interval is also still
// present when ANY visible message carries a ledgerSeq stamp inside the
// interval — the host restored/re-stamped the originals (fresh ids, same
// positions), and the positional claim survives the id churn that the
// id-membership check above just missed.
const stillPresent =
block.effectiveMessageIds.some((id) => presentBases.has(baseIdOf(id))) ||
presentIds.has(summaryMessageId(block.blockId));
presentIds.has(summaryMessageId(block.blockId)) ||
blockSeqPresent(block, messages);
if (!stillPresent) {
block.active = false;
deactivated.push(block.blockId);
Expand Down
10 changes: 10 additions & 0 deletions kernel/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ export interface CompressionBlock {
compressCallId?: string;
startRef?: string;
endRef?: string;
/** #4316 layer 3: the block's coverage as a unified-ledger seq interval
* [startSeq, endSeq] (inclusive, 1-based display space — same space as
* CoreMessage.ledgerSeq). Recorded ONLY when the fold can prove the claim
* exact: every direct folded message carried a ledgerSeq stamp, every
* consumed block carried its own bounds, and the union of those segments
* is one contiguous span (a hole means min/max would swallow uncovered
* messages, so no bounds are recorded — the id path stays authoritative).
* Undefined = unstamped traffic or provably-loose coverage; never guessed. */
startSeq?: number;
endSeq?: number;
}

/** A compression block's current ref span, pre-resolved for display. */
Expand Down
Loading
Loading