209 Commits
Author SHA1 Message Date
ranxianglei ffcb085b06 fix(#7574): correct the rollback finding — tool-output texts do not come back, state fields do
Checked against the real previous build: once an older build has saved a
session it rewrote the ccr_entries rows to the bare { hash } stubs it saw
and released the entry rows, so no link from the placeholders to the texts
is left anywhere. The "take the texts back from the ledger" heal added in
717364a5 could never fire and also broke the export's missing-hash
contract; it is removed. What stays and is real: the nine state fields
come back (an older build's own value wins) and the lost content store is
logged with its cause instead of failing silently. A session the older
build only read is intact after re-upgrading.
2026-11-23 19:32:03 +08:00
ranxianglei 0f09d5fed6 docs(#7574): record the review follow-up in the unified storage design doc
New §7 in both languages: what a rollback to an older build loses and what heals, the big-request fix, the outbound op log rules (authority, damaged log, admin routes, compaction), the msgid changes, the migration fix. Three inline sentences point at it.
2026-11-23 19:32:03 +08:00
ranxianglei 4ef435d2b4 chore(#7574): drop four draft files committed at the repo root, refresh stale rollout text
- .pr-body.md, .ci6785-final.txt, .comment-7439.md, .reply-7439.md were
  working notes that slipped into the hand-resolved merge of #6785.
- "KDD #21/#21" -> "KDD #21/#22" in four docs.
- pluginFullResendWatermark is on by default since 2026-11-22 (owner
  ruling); AGENTS.md, design-decisions.md KDD #15, the PR #6785 doc table
  and the web config label still said 5% / experimental.
2026-11-23 17:20:33 +08:00
ranxianglei d85a900525 Merge origin/master (15f06c63) — picks up the #7549 preflight/emergency-digest fixes that turned master's own CI green (branch had merged the pre-fix master 08783eed, inheriting its red #5844/#7013/#7189 test family) 2026-11-23 13:23:49 +08:00
ranxianglei 15f06c63e4 Merge pull request #7549 from ranxianglei/fix/preflight-emergency-digest-default-off
[PR] preflight: stop hard-truncating extreme overflows by default; fold fresh-session first resends in parallel
2026-11-23 13:12:20 +08:00
ranxianglei a4fc29c6f7 Merge origin/master into 2026-11-15_msgid-snapshot-unified
Conflicts resolved:
- src/agent/fork-adopt.ts + src/agent/opencode-v2.ts: union of the two
  fork-branch-point tracks — master's #5509 resolveForkBranchPoint
  (role+text-first, host-declared boundary) stays the base decision;
  this branch's #6262 host-msgid identity track extends it afterwards
  and never beyond a host-capped boundary. Call sites feed BOTH
  msgIds and boundary.
- AGENTS.md + reference/design-decisions.md: master's KDD #20
  (#7537 no estimate-based size refusal, already public on master)
  keeps its number; this branch's three new KDD entries renumber
  #20->#21 (id 存储去重), #21->#22 (pin 增量化), #22->#23 (egress op
  log 正史) — all KDD/des…ions.md references repo-wide
  updated in the same commit.

Verification: tsc clean; fork battery (5509/6262/fork-adopt/
opencode) green; egress battery 129/129; full-suite verdict = CI on
the pushed head.
2026-11-23 11:48:47 +08:00
ranxianglei 46466ae047 chore: clear retired snapBase plane leftovers (7439 audit before merge)
The #5874 v2 snapshot-base plane (storage.snapBase) was retired before merge
(bc51c9445) — egress op log (rollout.features.egressPlane) is its successor.
Sweep the remnants that would otherwise enter master:

- config.ts: the orphaned 17-line snapBase doc comment (the field itself was
  already removed) is replaced by a one-line retirement note.
- release-gate-local.mjs: --snapbase-full wrote the dead storage.snapBase key
  (silent no-op — the plane was unreachable, same bug 52f81bfb fixed in
  scripts/gate); it now writes rollout.features.egressPlane=true.
- scripts/gate config.example.json + README en/zh: the knob docs still said
  'storage.snapBase' and per-protocol cohorts (the plane has neither).
- docs/architecture/storage{,.zh-CN,.ja}.md: the v2 substrate enumeration
  still listed the deleted fold_journal/egress_snapshot tables.
- AGENTS.md KDD #20 + design-decisions.md #20: both describe fold_journal /
  egress_snapshot as live interval-ref tables; they were deleted in bc51c9445
  (only l1_world survives) — a note marks the pre-retirement description as
  history. The entries are new in this PR, so the fix ships with them.
- schema.ts: SNAPBASE_DDL_V12 -> L1WORLD_DDL_V12 (cosmetic; the DDL creates
  the live l1_world table, the name cited the retired plane).
2026-11-23 10:24:18 +08:00
ranxianglei d3eb7ff618 docs/tests: final review nits for PR #7549 (lifecycle bound symbol, test line split)
N3: lifecycle row said ≥19.2x, the code gate is strict > (src/preflight.ts:2049).
N4: env assignment crammed onto the next statement's line in the #1987 test.
2026-11-23 09:25:12 +08:00
ranxianglei 8d7d0f8394 feat(storage): blocks 自包含读写侧(裁定 7439-2 缺口补齐)
配套 PR #6785 分支上的裁定 2(blocks 自包含)只落了 schema 预备
(三列 probe-first ALTER)+ IngestBlock 可选字段的写入管道,但:

1. 读侧完全没切——三个读点仍全部走 content 表 join
   (sqlite getBlockContents/getBlocks、mysql getBlocksOn),
   "blocks 零指针" 未成立;
2. sqlite 新库 base DDL 缺三列 → probe-first ALTER 对全新库 no-op
   → 新库第一次折叠 ingest 直接 `no such column: summary_bytes`;
3. mysql 存量库没有 probe-first ALTER;
4. #5744 稳态等值比较(两端)都不含新列 → 即使写入侧生效,
   summary_bytes 也永不被填;
5. `start_msgid`/`end_msgid` 无任何计算源,恒 NULL。

本 PR 补齐 1-5:

**schema**
- sqlite base DDL(CREATE TABLE blocks)补三列——新库直接带上,
  probe-first ALTER 继续照顾存量库;
- mysql 存量库 probe-first ALTER(information_schema 探测,
  放在版本门之外——已 stamp 到当前版本的共享库走不进版本门,
  与 sqlite ccr 探针惯例一致),CREATE TABLE 侧上一提交已补。

**写侧(sqlite)**
- ingestSession 计算每块的 `summary_bytes`(= summary 文本,
  IngestBlock.summaryBytes 显式覆盖优先)与 `start_msgid`/`end_msgid`:
  覆盖 id(effectiveMessageIds ∪ directMessageIds)在 egress 流水视图
  (`snapEgressPinLiveIds`)中的 min/max 位置对应 msgid——折叠时一次性
  对齐,之后零 join;未被流水记录的会话保持 NULL;流水损坏降级 NULL,
  永不 fail save;
- 稳态 carry-forward:coverage 未变的已盖章行直接沿用存储值
  (等值平凡成立,零 view 读零重写);
- #5744 等值比较加入三列 → 遗留行(NULL)在下次保存时一次性回填。

**写侧(mysql 镜像)**: 同构处理;该车道无 egress 表 →
msgid 坐标恒 NULL(注释标明),summary_bytes 同样回填。

**读侧**: sqlite getBlockContents/getBlocks 与 mysql getBlocksOn
切为内联字节优先(sqlite 用 SQL `COALESCE(summary_bytes, content.bytes)`,
mysql 用 JS 优先)——遗留行回 content 表;content 行损坏不再击穿块读取。

**测试** `tests/egress-blocks-selfcontained.test.ts`(6 用例,双向断言):
新库首折回归、内联优先+内容行损坏隔离、遗留行 fallback、
msgid 坐标(有流水 vs 无流水)、遗留行回填、稳态零重写。

**验证**: tsc 0 错;定向电池 72+6 全绿(5744 ingest diff /
egress record/serve/state/oplog-lifecycle/lazy-projection/
authority-ladder/authority-pinned / block-bounds / envelope-import /
archive reference counts / atomic-archive-rewrite / ingest watermark)。
全量套件以 CI 为准。

**明确不动(FLAG,请 owner 裁定,均在本 PR 范围外)**
- 并行提交 790a72d1 的 `authorityLaneTurn` 四车道全 arm 没有
  `session.metadata["egressAuthority"]` latch → `isEgressOn`
  (persist.ts)对 anthropic/responses/google 永不真 → KDD#22 收益链
  (投影冻结 / pin 读 egress_state / 抽检豁免)在这三条车道不生效;
- 同一函数无 `egressAuthorityProbe` 门(openai 车道的内联缝
  保留了自己的 probe + 双 latch);
- anthropic arm 门只有 egressPlane 灰度,无 pluginMode/title-gen 门。

**裁定 2 边界说明**: `summary_hash NOT NULL REFERENCES content(hash)`
+ "只加列不改列" ⇒ 写入侧 content CAS 照写(不破坏 FK);读侧已切
自包含列。彻底断 CAS = content 表退役步(裁定 1 §3.4 后续迁移)。
`one`/`one_hash` 不在裁定 2 点名范围,未动。

docs: architecture/storage{,.zh-CN}.md egress 段补裁定 2 落地一句。

Closes discussion #7439 裁定 2 缺口(见 #7553 前序评论)。
2026-11-23 09:22:18 +08:00
ranxianglei ae11da8789 Merge branch 'master' into 2026-11-15_msgid-snapshot-unified 2026-11-23 00:07:26 +08:00
ranxianglei a73c63c378 docs: regenerate configuration docs for network.emergencyDigest (docs-sync drift) 2026-11-23 00:01:49 +08:00
nockaeoandClaude Opus 5.5 4836d9dc28 docs: add Korean README
Add README.ko.md, a full Korean translation of README.md, and link it
from the language switcher in every root README and from docs/index.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 00:28:38 +09:00
ranxianglei 9f2d74eadc preflight: fold fresh-session first resends with concurrent in-model summaries (owner decision 2026-11-22, #2383 follow-up)
A session that has never been forwarded (no usage sample ever landed —
lastInputTokens <= 0) resends its whole raw history verbatim, so no
compression blocks can have been lost and folding is pure gain. For those
fresh sessions below the 6M-char bound (~1M real tokens x 4 chars/token x
1.5 headroom), preflight now nominates K=2 disjoint ranges per round, runs
their in-model summarization calls CONCURRENTLY (Promise.all — the pure
call part only), and commits the candidates sequentially afterwards (kernel
state mutates single-threaded, #2678 shape). The serial walk keeps one fold
per round; the half-life of the 15-40s ladder halves, and a range the
parallel pass cannot summarize is deliberately left out of the skipSet so
the walk takes it over with its halving/transient/probe semantics.

Existing sessions are untouched: a large payload there may indicate LOST
folds, and the owner's rule for that case is to diagnose (warn), not to
spend tokens folding — that tier lands as a separate diagnostic. Above the
6M-char bound the request fails fast instead (the default-off digest
regime, prior commit) rather than burning the call budget without
converging.

Nomination, span selection, preview/render gates, acceptance (max cap,
net-shrink monotonicity, rescue truncate) and failure shapes mirror the
walk and the external batch lane byte-for-byte.

Test: fresh anonymous session, 30 x 10k-char messages (~300k chars, under
the doomed-probe byte floor, non-emergency), asserts peak in-flight >= 2
summarization calls, single forward, mid-history folded out of the rebuilt
payload (kernel anchor + recent tail stay resident by design), and the
blocks hold the upstream-written summaries.
2026-11-22 22:54:20 +08:00
ranxianglei dd68e49c74 fix(qoder): disambiguate same-type side tasks by body metadata.task_id
Agent review found that qoderSideTaskConversation keyed the |aux: lane on
business_type only, so two side tasks of the SAME type under one parent mapped
to the same session id — and with trustStampedId GA-on (which retires the
in-lane content-guessed split) they would merge + cross-bleed compression
state. Read the per-task id from body metadata.task_id (validated, zcode
x-query-id pattern) and append it to the lane; fall back to the type-only lane
when absent/malformed. Also trim the claude request-class doc line to match the
implementation (only subagent/main act; the rest fall to the legacy heuristic).
2026-11-22 22:28:35 +08:00
ranxianglei da2586d46c feat(rollout): pluginFullResendWatermark GA — default 5% → 100 (owner ruling)
Owner ruling (2026-11-22, PR #6785 thread): the fastpath grey has run a long
time without issues, so it goes GA. The 2026-11-02 retraction that pinned the
5% guard is superseded; the guard test is re-pinned to 100 with this
justification. Web notice/i18n and the config docs (en/zh/ja via the seed)
drop the 'experimental / 5% grey' wording; the one-time intro notice stays
(opt-out pointer) with its gate unchanged. Opt out: rollout.features
pluginFullResendWatermark=false (or a percent) / env = 0.
2026-11-22 22:03:01 +08:00
ranxianglei 97f32b4cd4 docs: fix the broken table row from the snapBase-retirement edit 2026-11-22 21:38:41 +08:00
ework-agent a67102d1e5 docs: add the round-2 egressPlane paragraph to the config seed (docs-sync drift)
The round-2 (KDD #22) paragraph was hand-edited into the generated
docs/configuration.md + .zh-CN.md (c85e4a304) but never into the seed
yaml, so gen-config-docs generate rewrote it away and docs-sync went red.
Fix at the source: the seed (website/config-reference/rollout.yaml) now
carries the round-2 text in en/zh/ja; the regenerated ja.md gains the
paragraph (it was missing there too). EN/ZH generated output is now
byte-identical to the committed docs.
2026-11-22 21:01:36 +08:00
ranxianglei 68f70ce4f0 docs: mark the retired snapBase config rows in the PR #6785 walkthrough (bc51c9445 removed the keys) 2026-11-22 20:56:19 +08:00
ranxianglei c85e4a3043 docs: sync the PR #6785 surface to the round-2 state (KDD #22)
The review-grade walkthrough (en/zh) still described the pre-round-2
architecture — egress_snapshot tables, messages as the canonical id
truth, no lazy projection, no perf gate. Add the round-2 chapter
(ruling 7439-2/5: op-log canonical numbering, window re-anchor,
sole-canonical + lazy projection, pin-from-flow, envelope freeze,
hard-fail, measured 10w matrix, resident bench) and mark the
superseded sections inline instead of deleting them.

Supporting sync:
- storage.md (en/zh): egress tables + canonical-authority semantics
- msgid-infrastructure.md (en/zh): KDD #22 carve-out on the
  'messages.msg_id is the single id truth' statement
- configuration.md (en/zh): egressPlane knob gains the round-2
  lazy-projection semantics
- index.md (en/zh): pr-6785 doc row
- reference/testing.md: ACP_TEST_EG_BENCH bench lane

No code changes. Docs-only.
2026-11-22 20:39:30 +08:00
ranxianglei 567a54f471 feat(identity): trust stamped session id (GA) + Copilot per-task id + 18-client survey
#7439 / discussion #7524 — the server trusts the client-stamped session id +
purpose and retires the content-guessing |sub: subagent fork ladder.

- rollout: trustStampedId GA (percent 100; force-off BILI_ROLLOUT_TRUST_STAMPED_ID=0)
- session-resolve: gate the 4 content-forecasting |sub: forks (derived-aux/task/
  persona) behind the flag; the #5095 client-declared lane-token tail is kept
- session-id: add x-agent-task-id (GitHub Copilot per-task id) before x-session-id
- docs: client-session-ids.md (18-client survey, source-verified); mark
  identity-channels.md superseded
- tests: trust-stamped-id (new, GA-on); issue2944 pinned to the legacy ladder
2026-11-22 15:58:14 +08:00
ework-agent 0fc364a1f3 Merge remote-tracking branch 'origin/master' into 2026-11-15_msgid-snapshot-unified 2026-11-22 10:57:01 +08:00
ranxianglei 312bf5d916 Merge pull request #7470 from ranxianglei/fix/dsh-ext-intercept-2026-11-21
[PR] fix: intercept DSH top-level dsh_* client extensions so they are not forwarded upstream (#7168 #7439)
2026-11-22 10:45:22 +08:00
ranxianglei 99ff869fdd docs: regenerate config docs for the 429 governor default flip
gen-config-docs generate: throttle429Enabled default true -> false in the
generated tables + website artifacts (seed wording updated for the
#6639/#5853 passthrough posture).
2026-11-21 23:10:09 +08:00
ci-check 83b0d8ac51 docs: register rollout.features.passDshExtensions in the config reference (#7168/#7439)
The intercept PR added the passDshExtensions rollout key (src/rollout.ts)
but every other rollout feature carries a seed entry in
website/config-reference/rollout.yaml plus the generated rows in
docs/configuration.{md,zh-CN.md,ja.md} — this key had none, and the PR body
lacked the config-surface section. Add the seed entry (en/zh/ja) and the
regenerated artifacts; check-coverage stays green (the env name is derived
at runtime via rolloutEnvName, so it lands in the expected-dynamic notice
list like its BILI_ROLLOUT_* siblings).
2026-11-21 22:00:46 +08:00
ranxianglei 5ee76292c1 fix: 429 governor off by default — upstream 429s pass through to the client
#6639 + #5853 decision: the egress 429 governor (#4204) now requires an
explicit opt-in (BILI_THROTTLE_429=1 or network.throttle429Enabled: true).
With no config, upstream 429 responses are forwarded to the client
unchanged — no local hold, no terminal 424 — and bili logs one
[429-passthrough] warn per observed 429 so incidents stay diagnosable.

This fixes the "shared concurrency limit" false positives: free-tier /
shared-pool accounts (opencode.ai, Magpie) whose hosts legitimately rate
each other now keep their own retry loops instead of having the whole
credential frozen for Retry-After minutes (#7295) with no self-clearing
hold (#7301). The governor stays available as an escape hatch for
accounts where host retry storms would pin a shared concurrency limit.

- src/knobs.ts: throttle429Enabled() default flips to OFF (env override
  semantics unchanged)
- src/upstream-throttle.ts: passthrough warn log on both 429 intake
  paths (gate + provisional) when disabled
- docs (en/zh/ja): default true -> false + passthrough wording
- tests: new issue6639-throttle429-default-off pins default-OFF behavior
  and the opt-in re-arm; issue4743 A-E now opt in explicitly (they test
  the ENABLED path and must not rely on the default)
2026-11-21 21:41:39 +08:00
ework-agent 66914d5f9b Merge remote-tracking branch 'origin/master' into 2026-11-15_msgid-snapshot-unified
# Conflicts:
#	src/server/fastpath.ts
#	tests/fastpath.test.ts
#	tests/issue7156-pure-sqlite-refusal.test.ts
2026-11-21 19:44:06 +08:00
ranxianglei 9bf4d48c87 Merge pull request #7457 from ranxianglei/2026-11-21_workbuddy-lane
[PR] feat: WorkBuddy Desktop lane — settings-file routing + auto-compact gate (#7456)
2026-11-21 19:05:59 +08:00
ranxianglei 29ff5807ea feat: rename wb lane to workbuddy + extend codebuddy identity harvest to the workbuddy config root (#7456) 2026-11-21 18:36:27 +08:00
ranxianglei a2610a5223 docs: seed + regenerate config docs for BILI_WB_PROXY/BILI_WB_UPSTREAM (#7456)
docs/configuration.*.md is generated from website/config-reference/*.yaml
(docs-sync lane) — add the two workbuddy env pins to env-only.yaml and
regenerate instead of hand-editing the table. check-coverage now passes.
2026-11-21 17:37:04 +08:00
ranxianglei 37f1ac6c05 feat: WorkBuddy Desktop lane — settings-file routing + auto-compact gate (#7456)
WorkBuddy Desktop embeds a CodeBuddy Code CLI fork for every agent session.
The CLI reads env.CODEBUDDY_BASE_URL from its user settings file BEFORE
process.env (decompiled evidence in #7456), so a managed block in
~/.workbuddy/settings.json routes desktop-spawned AND terminal sessions
through the resident proxy — the app's explicit spawn env allowlist makes
shell exports unreachable.

- bili plugin install wb: wraps env.CODEBUDDY_BASE_URL into the pinned
  origin (BILI_WB_PROXY override; default http://127.0.0.1:8787) and sets
  autoCompactEnabled:false — bili owns compression, manual compaction
  survives. A foreign base URL and an explicit autoCompactEnabled:true are
  reported, never clobbered. The install warns when no live proxy is
  recorded at the pinned origin (origin-matched instance-file liveness).
- bili plugin remove wb / status row / doctor lane: strips exactly the
  bili-owned values; .bili-bak snapshot semantics shared with other lanes.
- Pure wire mode by design: desktop-spawned sessions run --strict-mcp-config
  (user MCP scopes blocked), so a host tool face is impossible for the app's
  own sessions; compression rides the proxy (acp_summary carrier). No
  wire/format changes in either compression mode — the lane is config-write
  only on the existing /bili/ forward.

Docs: clients.md/.zh-CN WorkBuddy sections, architecture lanes pages
(en/zh/ja), configuration env-var tables, lifecycle ledger
(BILI_WB_PROXY/BILI_WB_UPSTREAM).
2026-11-21 17:29:28 +08:00
ework-agent 1f4bd580be docs: seed the sessions/plugin/snapshot config surface + egress-lane-io file map
The PR's snapshot-plane commits added config fields (sessions.*, plugin.snapshotCapBytes, snapshot.shadow) and src/server/egress-lane-io.ts without doc seeds, so three CI gates went red on head 02fc8f4c2:

- config-surface-guard: 11 leaf fields lacked website/config-reference seed entries
- docs-coverage: 11 env vars + 2 top-level keys (sessions, plugin) undocumented (BILI_SESSION_CONTENT_STORE_PIN is env-only)
- architecture-docs: reference/architecture.md missing src/server/egress-lane-io.ts

Added the seeds (process.yaml: sessions block + 9 leaves; server.yaml: plugin.snapshotCapBytes + snapshot.shadow; env-only.yaml: BILI_SESSION_CONTENT_STORE_PIN), the file-map line, and the regenerated docs/configuration.{md,zh-CN.md,ja.md} + website artifacts.

Verified locally: all three gates green, generate idempotent, typecheck clean.

PR #6785 CI fix.
2026-11-21 17:20:04 +08:00
ranxianglei 02fc8f4c2c refactor(egress): one switch, one path — collapse egressOpLog/egressServeLog into egressPlane (#7439 ruling)
The egress plane gets a SINGLE rollout key: egressPlane (default 0).
ON = the complete new path in every lane — sparse-op recording,
serve-from-log (byte-identical swap), and server authority for pinned
plugin lanes (rulings 7439-3/5). OFF = legacy chain, zero rows,
byte-identical to pre-feature. Both predecessor keys never shipped
(default 0, born in rollback state) — no migration.

Owner ruling 2026-11-21: '删掉以前的开关 只留下一个开关'.

Verification: typecheck 0; 13-file storage/egress/fastpath battery
112/112; e2e codex 4-phase pass (rollout off = legacy path).
2026-11-21 16:12:38 +08:00
ranxianglei bc51c94453 refactor(egress): retire the fold-journal / egress-snapshot / scope-rev plane (7439 ruling)
Every v12 table that never entered master is deleted except the ones the
ruling keeps (l1_world, orphan_blocks, state_fields, egress_state,
egress_flow). The #5874 v2 snapshot-base plane (fold_journal +
egress_snapshot + egress_scope_rev) shipped no behavior yet — its D-lane
byte cache was bypassed on the plugin lane and its sole write consumer
was this PR — so it is removed wholesale:

- schema.ts: three DDL consts + all probes (incl. the covered_ids /
  ids_json DROP-column and scope_rev ADD-column migrations); v12 keeps
  l1_world / orphan_blocks / state_fields / egress_state+flow
  (probe-first, unchanged).
- snap.ts: fold-journal + egress-snapshot functions deleted; the L1
  world / R3 latch functions (stage-0 identity + pf pin) are kept.
- store.ts / shadow.ts / persist.ts: egressCut / egressReadView /
  appendFoldJournal / appendEgressSnapshot / bumpEgressScopeRev and all
  seven per-write rev-bump sites gone; delete/archive cascades trimmed.
- snapshot-render.ts: the splice (warm serve) and cut blocks gone — the
  D-lane reverts to live derive, pre-#5874 behavior.
- config surface: storage.snapBase (enabled/cohorts/cutEveryKUserTurns)
  removed from config.ts, knobs.ts, process.yaml + regenerated docs —
  the plane never shipped, so there is no compat story to keep.
- tests: the three plane-only suites retired; 111/111 battery +
  108/108 lane suites green, typecheck clean.

The byte-level prefix-cache gain the plane would have given is superseded
by the self-contained egress op-log, which serves the FULL rendered view
from the flow tables on every lane.
2026-11-21 15:54:55 +08:00
ework-agent d3ab5abb76 merge: resolve conflicts with master (#7381 pf-tail-ids-cap-and-stamp-decouple)
Conflicts resolved:
1. src/server/prepare-openai.ts: union of fastpath imports (PR's
   DeltaReanchorError/PF_TAIL_IDS_HEADER/evaluateDeltaResend/parseTailIdsForPin
   + master's stampOnlyWatermarkTurn).
2. tests/fastpath.test.ts: union of fastpath imports (PR's
   evaluateDeltaResend/PF_DELTA_HEADER + master's stampOnlyWatermarkTurn).
3. src/agent/pf-channel.ts: kept PR's TAIL_MAX_BYTES byte-budget (supersedes
   master's MAX_TAIL_IDS count-cap; the byte check is stricter and
   tailPayloadFor is the single source of truth for both header emit AND
   full-form suppression).
4. src/server/fastpath.ts: kept BOTH evaluateDeltaResend (PR #6785 delta arm)
   AND stampOnlyWatermarkTurn (master #7367 stamp-only turn).
5. src/storage/shadow.ts: kept master's fileJsonWriter parameter (new in
   master, not in PR branch).
6. tests/pf-channel.test.ts: updated #7367 tail-cap test to match PR branch's
   byte-budget behavior (full slice under 8 KB, not capped to 160).
2026-11-21 15:28:57 +08:00
Afloat 17350dea17 fix: preserve responses beyond the fake-completion buffer cap
Stop bounded inspection at the first over-budget chunk and replay its
complete prefix and remaining stream through the existing response pipes.
Do not classify a partial response or alter its fake-completion streak.

Keep retry idle timers and client-abort listeners until the live response
and optional raw dump finish. Error-body truncation remains unchanged.

Validation: 5 baseline behavior failures and 2 passing exact-cap controls;
74 targeted tests pass. Typecheck, build and static gates pass. Codex
preflight finds the CLI/artifact but the live upstream is unavailable;
the real four-phase E2E and full remote CI remain pending.

(cherry picked from commit 2703cbe80f)
2026-11-21 15:13:24 +08:00
ranxianglei 98fa9575f1 Merge pull request #7443 from ranxianglei/fix/7426-ingest-cap-unlimited
[PR] fix: disable the 32 MiB ingest cost band by default for all lanes (#7426)
2026-11-21 15:09:56 +08:00
ranxianglei 1c4bbec76e Merge pull request #7424 from ranxianglei/fix/refuse-legacy-degrade-pure-sqlite
[PR] fix(storage): in pure SQLite mode, confirmed index corruption no longer silently falls back to JSON; now fails loudly on | fix(storage): 纯 SQLite 姿态下索引证实损坏不再静默降级 JSON,改为响亮拒启 (#7156)
2026-11-21 14:59:46 +08:00
ranxianglei d351a4d3a9 fix: disable the 32 MiB ingest cost band by default for all lanes (#7426)
#5794's ingest band proxied 'beyond every model window' by raw decoded bytes,
which is invalid on the re-send lanes (opencode/dsh re-send the whole raw ledger
every turn and bili folds it) — it 413'd a 33.5 MB opencode turn whose folded
context was tiny. Default -> 0 (unlimited, all lanes); the sibling receive (5 GiB)
/ decode (10 GiB) transport guards still bound pathological bodies.
BILI_INGEST_BODY_BYTES re-enables the band. Supersedes #6933.
2026-11-21 14:48:37 +08:00
ework-agent 58abab9cc7 merge: resolve prepare-openai.ts conflict with master (#7346 fix already on PR branch at new location) 2026-11-21 12:10:18 +08:00
ranxianglei 2e7293e767 docs: PR #6785 review-grade walkthrough + remove the outdated docs
- NEW docs/pr-6785-unified-storage-and-flows.{md,zh-CN.md}: the full
  review-grade report — table structure (schema v12, all 8 new tables +
  payload contracts), per-module implementation logic, per-turn data flow
  (steady / fold / degrade / lifecycle), the complete switch ledger
  (rollout keys, config objects, headers), and the 2026-11-21 ideal-model
  incremental bench with honest conclusions.
- REMOVE docs/proposals/snapshot-compression-foundation/ (described the
  RETIRED v1 four-table plane; contradicts the shipped v12 shape) and
  docs/storage-relations.{en,zh}.svg (5 tables missing, stale cards) —
  both were PR-introduced, never on master; the report supersedes them.
  docs/index.{md,zh-CN.md} rows swapped; schema.ts comment re-pointed.
- website/config-reference/rollout.yaml: pluginLaneServerHistory default
  corrected to 100 (GA), egressServeLog description corrected to the seg
  4b reality (self-recording, true swap, whole-turn degrade), new
  pluginMsgIdIncremental entry (was undocumented — the dynamic env name
  evaded the docs-coverage CI); docs regenerated.
- Stale comment corrections: rollout.ts egressServeLog (no longer 'seg 4a
  LOG ONLY' / 'tool rows in v1'), schema.ts v12 note.

Part of #6785.
2026-11-21 12:04:10 +08:00
ci-check 6ecf4fe211 docs: list dsh-mneme in the known-conflict tier of the BILI_CONFLICT_SCAN docs (#7379)
The scan now flags dsh-mneme as a KNOWN conflict (like dsh-live-compact), but
the configuration docs still enumerated the known-conflict tier without it.
Add dsh-mneme to the tier list (both the env-var row and the scan section) and
a one-line mechanism note, in en/zh/ja, so the docs match the code.
2026-11-21 11:53:27 +08:00
ci-check 6f5a562628 docs: register BILI_STORAGE_ALLOW_LEGACY_DEGRADE in config-docs seed + lifecycle ledger (#7156)
The #7156 fix added the BILI_STORAGE_ALLOW_LEGACY_DEGRADE escape-hatch env var to src/ but only hand-edited the generated en/zh config docs. The seed (website/config-reference/env-only.yaml — the source of truth) and docs/lifecycle.md were never updated, so three doc gates went red: docs-coverage (undocumented env var), docs-sync (hand-edited docs drift from regenerated output), lifecycle-ledger-guard (no ledger entry).

Fix: add the seed entry (en/zh/ja) and split the BILI_STORAGE_QUICK_CHECK row by stance in all three languages, then regenerate (only the ja doc picks up the new rows — en/zh already matched the seed), and register the new var in lifecycle §2.4 as a permanent operator escape hatch.
2026-11-21 09:42:02 +08:00
ranxianglei 0d7e0ec18c fix(storage): pure-sqlite stance refuses to start on a proven-corrupt index instead of degrading to legacy JSON (#7156)
In the pure-sqlite stance the SQLite index is the ONLY persistent copy of
the sessions — but a proven corruption (this boot's own quick_check, or the
first post-open write on a large store with a cached verdict) still took the
historical #4626-era contract: loud alarm, start WITHOUT the index, serve
the JSON envelopes. Here those envelopes are a near-empty, non-persistent
view, so the degradation silently loses the durable history — worse than the
corruption itself (2026-11-21 production incident: 3.2GB index.db, panel
showed requests:2/context 0 while the real 1,563 requests / 124k context /
cost sat inside the index).

Now, when the effective stance is pure-sqlite (effective mode full + sqlite
backend + no encryption + jsonWriter off — the 2026-11-13 default flip or an
explicit off), a proven corruption makes bili REFUSE TO START with an
actionable manual fix (back up index.db{,-wal,-shm}, move them aside by
hand, start again). The files stay byte-identical (no move/copy/rebuild, the
#4609/#4626 no-auto-touch policy is untouched). Every stance where the
envelopes remain a real recovery source (explicit dual-write full, shadow,
legacy, network backends, encryption) keeps the historical alarm-and-degrade
contract byte-for-byte.

BILI_STORAGE_ALLOW_LEGACY_DEGRADE=1/true/on is the conscious escape hatch
that restores the degrade path in the pure-sqlite stance; it is never the
default and never implied by any config value.

The stance decision is a pure function (storageStancePureSqlite) using the
exact same knobs/precedence as the persist constructor's jsonWriterOff
switch, so the two can never disagree. The refusal is recorded on the
diagnostics surface (REFUSING TO START (pure-sqlite stance) prefix on the
sidecar open error, visible in /__bili/status and the diagnostics dump) and
applies again on every boot.

Docs: docs/configuration.md + configuration.zh-CN.md (BILI_STORAGE_QUICK_CHECK
row split by stance, new BILI_STORAGE_ALLOW_LEGACY_DEGRADE row), CHANGELOG
[Unreleased] Fixed.

Regression: tests/issue7156-pure-sqlite-refusal.test.ts (new: stance truth
table, corrupt-index refusal in both pure-sqlite env spellings + file tier,
escape hatch, repeat refusal, byte-identity assertions, dual-write stance
keeps degrading), tests/issue4816-integrity-throw-quarantine.test.ts,
tests/acp-status-storage-degraded.test.ts, tests/web-storage-banner.test.ts,
tests/storage-durability.test.ts and the full storage suite green.
2026-11-21 09:19:22 +08:00
ework-agent d401a28ea7 fix: make the compress receipt's 'fold more' recommendation opt-in (default off)
⚠️ MODEL-FACING TEXT CHANGE — the success compress receipt changes what the
model reads: with the new default (compress.postComPressTail off, the
pre-existing behavior is NOT the default), the receipt no longer re-advises
the remaining foldable ranges after every successful fold, and no longer
emits the 'Uncovered history remains' audit note. With it on (explicit opt-in),
the range list is restored and the uncovered note fires at most once per
nudge-injection cycle (fresh injection re-opens it). The verbatim
context-minimum stop signal is unchanged in both modes.

Consumption-chain reasoning (#6855 discipline): the removed text carried the
only forward-pointing refs the model propagated into its NEXT compress call
(startId/endId copied from the 'Current compressible ranges' list). Removing
it removes the propagation anchor entirely — no phantom-value class possible.
Nothing else in the receipt is altered byte-wise; the stop-signal sentence
(#1387) is preserved verbatim, so models that key on it see identical text.
The per-turn growth nudge (KDD #8) is a separate channel and untouched.

Why: per-receipt re-recommendation drove models into endless fold loops
against explicit user stop requests (#7318: 200+ folds in one night on a
0.1.216 build; #6522 '不要连续推荐' and #5872 are the same family — the
receipt footer drives single-message retry folds). Each fold rewrites the
context prefix and re-bills the prompt cache.

config surface (#1437 discipline, owner decision in-thread 2026-11-20):
adds compress.postComPressTail (boolean, default off) to the existing three-
level compress hierarchy (global/provider/model via mergeCompress); boolean
only (non-boolean rejects the whole block like the sibling requireNudge /
requireRecommendation); no new env var (knob goes through the existing
compress file hierarchy, env-discipline #2030). Docs: config-reference seed
entry + regenerated configuration.md en/zh/ja + website.

Plumbing: the flag is stamped per round on session.transient next to the
existing nudge gate (src/unprompted-gate.ts) and read at the tail decision
point in src/stream.ts — off by default when a session has no stamp
(defensive: never recommend on an unknown posture). The #6522 at-most-once
latch rides on an in-memory Session field (uncoveredReceiptNoted), re-opened
only by an actual nudge injection.

Fixes #7318 (design: default off); implements #6526's at-most-once note (that
PR is superseded — its change was unconditional, this one is gated).
Supersedes: https://github.com/ranxianglei/billion-context/pull/6526
2026-11-20 23:07:03 +08:00
ranxianglei a936b3f0ad feat(storage): egress serve-from-log reconstruction + shadow byte-identity comparison (discussions/7398 seg 4a)
The outbound element array can now be REBUILT from the op-log view alone:
view rows carry role + a unified-content-CAS reference (the message's final
core JSON, hashed at record time — no new content bytes anywhere), and
rebuildOutboundFromLog runs the exact legacy chain (systemToUser ->
coreToOpenai -> hardenOpenaiAssistantContent) over the CAS bodies.

- src/storage/egress-serve.ts (new): rebuild + the degrade ladder — missing
  CAS body / casRef-less legacy rows / tool rows / bad JSON -> null, the
  caller keeps the legacy bytes. v1 scope pinned: text + acp_summary rows.
- src/storage/egress-state.ts: role?/casRef? ride the I and U ops, the B
  base and both replay paths (JSON payload fields only — no schema change;
  absent on pre-seg-4 rows, which serve-from-log skips).
- src/storage/egress-record.ts: rows recorded with the CAS seam
  (store.egressPutContent); system row included with its own casRef.
- src/storage/store.ts: egressPutContent/egressGetContent public seam over
  the existing private content CAS (dedup by sha256, refcount).
- src/server/prepare-openai.ts: captures the legacy core elements + the
  recorded source; behind egressServeLog (default 0) it rebuilds from the
  log and logs IDENTICAL|DIVERGENT vs the legacy bytes. NO swap: the
  pipeline always sends the legacy path until the shadow gate proves it.
- rollout: egressServeLog {percent: 0} (env BILI_ROLLOUT_EGRESS_SERVE_LOG,
  requires egressOpLog on); config docs regenerated (348 entries, stable).
- tests/egress-serve.test.ts (new, 6 tests): byte identity vs the legacy
  chain (plain + summary re-voicing + table-replayed + post-compaction)
  and the three degrade directions (#3617).
- Battery: egress-state/record/serve 24/24, perf-suite set 53/53,
  typecheck + build clean.
2026-11-20 19:11:15 +08:00
ranxianglei 5b3b55cb61 feat(storage): egress op-log recording seam — shadow-record the outbound view as sparse ops (discussions/7398 seg 3)
The four upper-layer shapes now land in the op log behind rollout key
egressOpLog (default 0 = zero impact):

  1. new message            -> exactly one +I (tail append)
  2. nudge injection        -> structurally absent: the recording seam sits
                               BEFORE the nudge/scratch append, so the
                               ephemeral rows never reach the tables
  3. compress fold          -> one -D over the folded span + one +I for the
                               summary row; any -D batch triggers compaction
                               (replay into a base row, state table bounded)
  4. content edit           -> exactly one +U (msgid/ref stable, content-only)

recordEgressTurn (new src/storage/egress-record.ts) builds deterministic
view rows (system row first; msgid/ref/tokens/type/contentHash), diffs
against the previous turn's view, appends the sparse ops, and compacts on
folds. Wired in prepare-openai between recordNudgeInject and the single
return: feature-gated, try/catch with per-session disable on any error
(shadow lane — the pipeline never throws from it).

SessionStore.egressOpLogStore() -> UnifiedShadow.egressOpLogSync() exposes
the sqlite UnifiedStore (null on legacy mode / network backends -> the
turn is skipped exactly like every other sqlite-lane fast path).

Tests: tests/egress-record.test.ts 6/6 (build determinism, tail append =
one op, fold = -D + +I + compaction, edit = one +U, identical view = zero
ops, rollout-off default both directions). Battery 71/71.
Full battery + CI green.
2026-11-20 18:56:33 +08:00
ranxianglei bf6d45c0af chore(ci): unexport DeltaVerdict (unused-export gate) + regenerate config docs from rollout.yaml seed
CI on fe54b7b2: unused-exports flagged DeltaVerdict (type used only
inside fastpath.ts — drop the export); docs-sync drifted because the
pluginDeltaResend row was hand-written into the generated
docs/configuration*.md instead of the single source
website/config-reference/rollout.yaml — seed entry added (en/zh/ja)
and all three docs regenerated by tools/gen-config-docs.mjs.
2026-11-20 16:33:56 +08:00
ranxianglei fe54b7b239 feat(fastpath): delta resend arm — the tail-slice form of the watermark lane
Steady plugin-lane turns can now send body.messages = ONLY the new
elements (L = T - stampT) plus x-bili-pf-delta: 1; the anchor (previous
turn's last element) rides x-bili-pf-tail-ids[0] only. evaluateDeltaResend
runs before the full lane and rebuilds the exact same FastpathHit
(stashed prefix cores + rekeyWindowCores(parsed tail)), so every
downstream consumer (stage-0 pin, kernel, ingest, snapshot, ledger window)
is the untouched full-lane path.

Re-anchor ladder: any unsatisfiable claim (bad header value, rollout off,
no/mismatched seed, count/body/tail-ids width mismatch, anchor-chain break
after a known previous list, broken scan, window shape) returns 400
pf_delta_reanchor + x-bili-msgid-mode: full and NO x-bili-pf-seq stamp —
the client resends that turn in full form and converges within one
round-trip. Editing/deleting the previous turn's LAST message breaks the
chain by design (full form next); earlier-history rewrites degrade via the
existing KDD#21 truncated-tail path, never a 400. No anchor byte
re-parse — identity is verified on the ledger/pin (2x2) side.

Rollout: rollout.features.pluginDeltaResend (default 0, OFF). Delta
bodies are unprocessable by servers that do not ship this arm, so the key
stays at 0 until client send-sides exist; env BILI_ROLLOUT_PLUGIN_DELTA_RESEND.
x-bili-pf-delta joins UPSTREAM_HOP_HEADERS.

Tests: tests/fastpath.test.ts delta-oracle test (reconstructed view byte-
equivalent to the legacy full-parse oracle across consecutive slices, then
a full-form turn after a delta hit) + the re-anchor matrix (both
directions, #3617). Full 52-test battery green; typecheck + build clean.

Docs: technical-notes en+zh (delta section), configuration en+zh
(rollout row + env row).
2026-11-20 16:27:54 +08:00
ework-agent ac9c3a00e3 Merge remote-tracking branch 'origin/master' into 2026-11-15_msgid-snapshot-unified 2026-11-20 14:16:20 +08:00
ranxianglei 1e357bf2d6 Merge pull request #7173 from ranxianglei/2026-11-18_issue7156-corruption-fallback
[PR] fix: #7156 storage-corruption fallout — webSummaryRows json_valid guard, .chk close-time gate, first-write corruption classification
2026-11-20 12:04:07 +08:00