Skip to content

fix(#2751): clarify search_context receipts — truncation, evidence window, narrowing hint - #2787

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-11_search-context-receipt
Oct 13, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-11_search-context-receipt

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2751

Summary

Long multi-term search_context queries could return only generic-term blocks while the unique-entity block ranked below the default limit, and the receipt gave the model no way to distinguish "cut at limit" from "absent from history" — leading it to conclude a researched project was never discussed and re-investigate old dirs/artifacts. This makes the search receipt honest about its own scope and truncation, and surfaces the actual match evidence instead of hiding it past char 200.

Host-side only (executeSearchContext in src/decompress-shared.ts). No kernel/scorer change, no new config surface, no cross-session expansion, no auto-reactivation of inactive blocks.

Changes

S1 — truncation + scope disclosure.

  • When candidates exceed limit: append [truncated: showing {n} of {c} candidates by relevance — pass limit:{c} to see the rest]. Previously the tail was silently dropped and Found {n} read like a total.
  • No-match now reads [No blocks matched "{q}" among {activeCount} active block(s){scope}. Scope = active compressed topics/summaries only — NOT visible messages, inactive/distilled blocks, or other sessions; absence here ≠ never-discussed.] instead of the bare [No blocks matched "{q}"] which implied history-absence.
  • Empty state ([No compressed blocks exist yet…]) unchanged.

S2 — evidence window instead of fixed head-preview.

S3 — narrowing hint.

  • Only when the query has ≥3 terms AND some distinctive term is absent from every returned block yet present in ≥1 lower-ranked candidate: [tip: none of the top {n} results contain "{term}" but {k} lower-ranked candidate(s) do — try searching "{term}" alone to surface its block directly].

Behavior changes (old → new)

Case Old New
Over-limit result Found 5 block(s)… (tail silently dropped) same header + [truncated: showing 5 of 8 … pass limit:8…]
No match, blocks exist [No blocks matched "q"] [No blocks matched "q" among N active block(s)… Scope = … absence here ≠ never-discussed.]
Match past char 200 first 200 chars shown, match invisible bounded window around the match, 【term】 marked
Long query, entity below cut nothing hints truncation one-line tip to narrow to the distinctive term

The Found {n} block(s) for "{q}"{scope}: header line is byte-stable (existing tests' /Found \d+ block\(s\)/ anchors still hold); new information is additive footer lines. buildVisibilityMarker classification untouched (no failure keyword introduced), so 🔍 vs ❌ rendering is unchanged.

Config surface

None added. Reuses the existing limit argument for pagination. (Per Config Surface Discipline.)

Tests

  • New regression suite tests/search-context-2751.test.ts (5 cases): over-limit truncation disclosure; exactly-at-limit (no false truncation); distinctive term surfaced past char 200 with 【】 mark; crowd-out (unique block ranked below the cut → truncated + hint + target absent); CJK long-连写 match surfaced with no unpaired surrogate introduced.
  • Updated the two existing suites that pinned the old no-match/preview wording (tests/search-context.test.ts, tests/search-context-cross-session.test.ts).
  • Verified green on the rebased head (origin/master @ 4387bcfb0): tsc --noEmit clean; targeted suites (search-context, -2751, -cross-session, issue1333-derived-inheritance, search-plan-aware, loop-core) 63/63 pass. Full suite delegated to CI.

Notes

…indow, narrowing hint

Long multi-term queries could return only generic-term blocks while the
unique-entity block was ranked below the limit, and the receipt gave no way
to tell 'cut at limit' from 'absent from history' — so the model misread a
truncated result as 'not in history' and re-investigated.

- S1: disclose candidate count + truncation ('showing N of M candidates — pass
  limit:M'); scope the no-match message to active topics/summaries and stop
  phrasing it as history-absence.
- S2: replace the fixed 200-char head preview with a bounded window centered
  on the pool-rarest matched term (marked 【term】), so a unique match past
  char 200 is surfaced instead of hidden. Budget stays 200 chars.
- S3: when a long query's distinctive term is absent from every returned block
  yet present in lower-ranked candidates, add a one-line hint to narrow to it.

Host-side only (executeSearchContext); no kernel/scorer change, no new config.
Surrogate-safe slicing (#816 family). Regression suite: tests/search-context-2751.test.ts.
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_search-context-receipt (9aa62f3)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3071-pr.2787.2447393

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2787.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到。这是针对 #2751 的已实现修复 PR,我按 PR Review 规范执行审查(不重做):拉取分支核对代码 → 回归/行为清点 → CI 状态 → 结构化八问结论。稍后回复完整审查结果。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成:发现 1 处漏改测试导致 CI 红,已直接代修并推回分支,重跑全绿 → 可合。

过程摘要:按 [PR] 协议未重做,拉分支核对代码 + 本地定向验证(6 个相关套件 63/63、tsc 干净)+ 审 CI。首轮 CI(run 38138922068)四个 test-matrix job 全红,失败仅一条:tests/plugin-protocol.test.ts:452 的断言仍钉旧格式 /plugin-side compress.../,而 S2 标记后实际回执行是 【plugin】-side compress of the two early turns...——本地复现确认(该套件 15/16)。这是 S2【term】标记的连带影响,你本地只跑了 6 个定向套件没覆盖到它。已在你的 PR 分支补 additive commit 9aa62f315(只改这一条断言为带标记形式,顺带让插件 tool API 路径也钉住了新格式),本地 16/16 绿,CI 重跑(run 38141403170)4/4 test matrix 全绿 + 全部 guard job 绿,mergeable=true。


① 原 issue(#2751)方向审核:回执三缺陷(静默截断、匹配词位置不可见、多词查询无收窄指引)均真实成立,属回执渲染层信息丢失。S1/S2/S3 全部打在产生缺陷的位置(executeSearchContext 渲染层),scorer/可见性逻辑零改动——是疏不是堵,方向正确。无需动 kernel。

② 回归审查(触碰路径的既有行为清单,逐项):

既有行为 结论
头部 Found {n} block(s) for "{q}"{scope}: 逐字节稳定 ✅ 保持(测试钉住)
buildVisibilityMarker(src/loop/core.ts:46)失败关键词 FAILED/not found/is required ✅ 新 footer 字符串不含任一 → 🔍/❌ 渲染不变(marker 只显示首行,首行未变)
#1333 消费方 startsWith('[No blocks matched "')(src/decompress-shared.ts:871) ✅ 前缀保留,仍命中
空态字符串(无任何 block) ✅ 不变
no-match 措辞的测试钉子 ✅ 全仓仅 tests/search-context*.test.ts 两处,均已更新
短摘要(<200 char)预览 ⚠️ 有意变更(见下方披露 2),测试已钉
scorer/kernel/跨会话 scope 语义 ✅ 零改动

③ 代码审查:evidenceSnippet 以池内频率最稀的词为锚、窗口 200(前探 80)、safeMidSlice 代理对边界调整正确(CJK 用例覆盖);查询词不在摘要正文时回退到与旧行为逐字节相同的 head-clamp——老场景零漂移。narrowingHint 三重门控(terms≥3 ∧ 词缺席全部返回块 ∧ 至少一个低排名候选含该词),误报率低。markFirstMatch 用 indexOf+切片而非正则替换,无转义面。

④ 测试有效性:新增 5 例断言全有牙——精确措辞匹配、exactly-at-limit 不出现假截断提示、200 字符外的特征词被窗口捕获且带标、crowd-out 场景同时断言 truncated+tip+目标缺席、CJK 无孤立代理。非恒真,bug 回归时抓得住。

⑤ diff 整洁度:干净,4 文件 +188/-7,每行与本 PR 目的相关,无跑题/空白噪音。

行为变更披露(旧值→新值+原因,均有测试钉住):

  1. 超限回执:旧=静默截断到 limit;新=尾部追加 [truncated: showing {n} of {c} candidates by relevance — pass limit:{c} to see the rest]。原因:模型无法区分「只有这么多」和「被截了」。
  2. 预览行:旧=摘要固定头 200 char;新=查询词在正文中时→围绕最稀匹配词的 200-char 窗口且词被 【term】 标记(对短摘要同样加标记,如 【auth】 token exchange...);词不在正文→与旧输出逐字节一致。原因:头截断会把真正命中的证据切掉。
  3. no-match 回执:旧=[No blocks matched "{q}".];新=追加 scope 说明(scope = active compressed topics/summaries only…)。原因:[Gap][search_context] 长查询结果被通用词挤占,回执未明确候选截断与检索范围,容易被误读为历史不存在 #2751 报告的「以为搜过全部」歧义。
  4. 新增可选 tip 行:仅 ≥3 词查询且满足门控时出现,其余场景输出与旧版一致。

结构化八问:

  1. 是什么问题:search_context 回执在结果超限时静默截断、预览可能不含实际命中词、多词查询 crowd-out 后模型不知道往哪收窄。
  2. 什么原因导致的:根因在回执渲染层——固定 head-clamp + 无截断披露 + 泛化 no-match 文案;搜索/scoring 本身没问题。
  3. 影响范围与严重程度:所有使用 search_context 的会话;体验级缺陷(模型决策质量受损),不影响压缩正确性/数据完整性。
  4. 怎么修复的:渲染层三件套(S1 截断披露+限域 no-match;S2 证据窗口+标记;S3 收窄提示),不碰 scorer。
  5. 是否有回归问题:上表逐项过,无破坏;唯一问题是漏改的 plugin-protocol.test.ts:452(CI 红),已代修,重跑全绿。
  6. 是否破坏缓存:不涉及(不动缓存/重试/增量游标/去重键)。
  7. 是否改了设计方向:不涉及(纯渲染层增强)。
  8. 是否引入了新的配置:不涉及。

备注:PR 正文提到的既有 lock↔pkg 版本漂移(package-lock.json kernel 0.0.110/pi-subagents 0.1.3 vs 各自 package.json 0.0.111/0.1.4)与本 PR 无关,CI 容忍,建议另行对齐,不在此处理。

判定:可合(CI 全绿、mergeable、无回归、行为变更已披露)。合并由人执行:#2787

@ranxianglei
ranxianglei merged commit 5906b73 into master Oct 13, 2026
14 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.348-master.5906b73 (rolling master tag).

npm install -g billion-context@0.0.348-master.5906b73  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

@ranxianglei
ranxianglei deleted the 2026-10-11_search-context-receipt branch October 15, 2026 05:33
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.

[Gap][search_context] 长查询结果被通用词挤占,回执未明确候选截断与检索范围,容易被误读为历史不存在

1 participant