Skip to content

refactor(surface): retire host section whitelist; uniform kernel tri-state over SECTIONS-derived keys - #430

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-13_kernel-sanitize-delegation
Sep 26, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-13_kernel-sanitize-delegation

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Retires pi's own slot-legality whitelist in sanitizePromptSections (the structural debt #429 calls out):

Both call sites (src/prompt-pack.ts, src/surface.ts) keep calling sanitizePromptSections; signature unchanged.

Why not literally route through kernel sanitizePackSurface

Verified against both 0.0.66 and 0.0.68 bundles: the kernel deliberately treats surface.adapters as opaque — its own packs docs say "Hosts sanitize their own sub-objects; the kernel only checks it is a plain object." And its section key space (acpTags, tools, summariesInContext, textProtocol, textTools, functionTools) does not include pi's ten extra sections (whenToCompress, multiTierIntro, throttleRetry, philosophy, howToCompress, tier2, tier3, …). Feeding adapters.pi.promptSections through sanitizePackSurface would drop lean pack's entire payload — #423 in reverse. So delegation at that layer is impossible by design; this PR achieves the same goal the other way: per-value validity mirrors the kernel contract exactly (no duplicated type rules), the host owns only its key space, and the kernel's own sanitizePackSurface already ran inside every PackSource before pi sees a Pack — no double sanitization of pack-level fields anywhere.

Tests (acceptance: pin pass-through semantics, not host whitelist)

  • tests/surface-config.test.ts: the old "rule slots take string or null" test becomes a uniform-contract test — every SECTION_KEYS entry accepts string and null identically, junk types and unknown keys dropped for all.
  • tests/prompt-pack.test.ts: new test pins pass-through — a pack carrying valid tri-state values on every pi key survives piAdapterSurface byte-identical.
  • No assertion anywhere encodes a per-key type rule anymore.

Verification

  • Pinned acp-kernel 0.0.66: typecheck clean, 804 tests / 0 fail (3 conditional skips).
  • Local overlay of real 0.0.68 dist (AGENTS.md pre-validation flow): typecheck + build clean; the only 3 failures are the exact hunks release v0.1.69 #428's release commit re-aligns (lean wording: settled history removed, summariesInContext null→string, header without (condensed)). Those fail on master against 0.0.68 with or without this change — they belong to release v0.1.69 #428, not here.
  • The new pass-through tests pass on both kernel versions — including 0.0.68's string-typed summariesInContext, a slot shape the old whitelist never anticipated.

Coordination

No version/pin changes (release territory — #428 owns the 0.0.68 bump). Test hunks are disjoint from #428's; merge order independent (clean rebase either way). After this lands, future prompt-contract changes like #265/#266 need only a pin bump on the pi side.

Fixes #429

@github-actions

github-actions Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Extension Artifact

Branch: 2026-09-13_kernel-sanitize-delegation (fd0d78f)

Option A — Install from npm PR tag (recommended)

pi install npm:billion-context-pi@pr-430

Each push to this PR publishes a new version under the pr-430 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pi-pr430.tgz
pi install ./package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review: PR #430 — claims independently re-verified, one gap fixed directly on the branch, ready to merge.

Diff cleanliness ✅ — 5 files, 29+/13−. Every line serves the refactor or its docs/tests; no unrelated hunks, no whitespace churn.

Verification (re-ran everything locally instead of taking it on faith):

  1. Key-set equivalence — SECTIONS (src/system-prompt.ts:20) enumerates exactly the 13 keys of old PROMPT_SECTION_KEYS ∪ RULE_SLOT_KEYS, matching the PiPromptSections interface field-for-field. Grepped the rest of src/: no surviving copy of this key list (the throttleRetry hits in config/index/user-config are config options, not section keys).
  2. Kernel-contract mirror — read the pinned 0.0.66 bundle: triStateSection accepts string/null per key and drops everything else; applySectionOverrides does null→skip / string→replace / anything-else→default. The new predicate (SECTION_KEYS.has(k) && (typeof v === "string" || v === null)) is the kernel's per-value contract verbatim. Also confirmed the "why not literally delegate" argument from the bundle itself: sanitizePackSurface passes surface.adapters through opaque (plain-object check only), and its section key space (acpTags,tools,summariesInContext,textProtocol,textTools,functionTools) lacks pi's ten extra sections — feeding lean pack through it would drop the whole payload, i.e. sanitizePromptSections drops rule-slot STRING overrides — kernel master leanPack carries a condensed howToCompress text that will be silently discarded #423 in reverse. Delegation impossible by design; per-value mirroring is the right shape.
  3. Dual-kernel test runs:
    • Pinned 0.0.66: typecheck clean, 804 tests / 0 fail (6 conditional skips).
    • Real published 0.0.68 dist overlaid into node_modules: typecheck clean; exactly 3 failures — the lean-wording assertions in tests/prompt-pack.test.ts that release v0.1.69 #428's release commit re-aligns. Re-ran the same overlay on origin/master without this PR's changes: the identical 3 fail → pre-existing against 0.0.68, belong to release v0.1.69 #428, not here. The new pass-through test is green on both versions, including 0.0.68's string-typed summariesInContext (a slot shape the old whitelist never anticipated).
  4. Coordination with release v0.1.69 #428 — release v0.1.69 #428 touches only package.json / package-lock.json / tests/prompt-pack.test.ts (hunks around lines 47–101); this PR's test insertion lands ~line 206. Disjoint, clean rebase either order. No version/pin changes here, consistent with the release-territory split.

Fixed directly on the branch (new commit b876682, pushed to 2026-09-13_kernel-sanitize-delegation):

  • Missing CHANGELOG.md entry — every content PR records itself under ## Unreleased; added the full entry for this refactor in house style.

Minor note (not fixed, out of scope): the topmost existing Unreleased entry (#426, line 4) is missing its leading - bullet dash — pre-existing on master, cosmetic only; left untouched to keep this diff scoped.

Verdict: behavior-preserving relative to master (post-#427 all 13 keys already accepted string|null; what changes is single-sourcing the key derivation, which removes the drift class that produced #423). Mergeable.

修了什么问题 / 为什么修 / 是否可以合并:PR 代码本身零修改(重构与测试全部独立复验通过),仅在 PR 分支补了一个缺失的 CHANGELOG.md 条目(commit b876682,已推送);双内核版本验证确认 3 个失败断言属 #428 发版对齐范围、与本 PR 无关,可以合并。

ework-agent added 2 commits September 26, 2026 08:51
…state over SECTIONS-derived keys (#429)

RULE_SLOT_KEYS/PROMPT_SECTION_KEYS duplicated the kernel's section contract,
so kernel 0.0.68's null→string slot flip silently dropped lean's condensed
rules (#423, symptomatic fix #427). The key set now derives from SECTIONS
(pi's own builder list — host policy) and every key takes the same kernel
tri-state validity (string replaces, null removes, junk dropped): no per-slot
type opinions left for the kernel to outgrow.
@ranxianglei
ranxianglei force-pushed the 2026-09-13_kernel-sanitize-delegation branch from 7f71b49 to fd0d78f Compare September 26, 2026 00:51
@ranxianglei
ranxianglei merged commit 198149c into master Sep 26, 2026
9 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

promptSections 自家 sanitize 白名单退役,委托内核 sanitizePackSurface(以内核为准)

1 participant