Skip to content

feat: search_context targets historical sessions read-only via conversation_id - #858

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-16_search-context-cross-session
Sep 17, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-16_search-context-cross-session

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #841

What

search_context accepts the existing per-call conversation_id param (shipped for MCP routing in #760/#761) as a read-only cross-session search target: when the id does not match the caller's own session (verbatim or canonical alias), the call searches that historical session's compressed blocks instead of re-routing to it. Omitted or self-referencing ids keep today's behavior byte-for-byte.

This satisfies the issue's three minimal points:

  1. Explicit historical pfa-* target — search_context({query, conversation_id: "pfa-old"}) searches that session in both proxy mode (wire schema gains the optional param via derived BILI_* constants; kernel constants never mutated) and plugin mode (param description specialized in the manifest).
  2. Non-resident targets load from persistence — resolveForeignSessionState prefers resident memory (peekSession / findSessionByCanonicalId), else a new SessionStore.loadStateForSearch(id) path that reads the envelope and merges state without ever scheduling a save (unlike loadSync, which carries the 代理压缩不上报改写量,宿主上下文会计塌缩至 ~0(omps recordAnchoredHistoryRewrite 零调用);且持久化 lastInputTokens 恢复无钳制,旧版负值升级后复活 #408 clamp side effect).
  3. Strictly read-only — execution stays anchored to the caller session: no re-routing, so the target's mode binding / lastSeen are untouched; the cold-load path performs zero writes (asserted by test: file bytes identical before/after, no pending saves). The MCP shim keeps conversation_id in args only for search_context precisely so the proxy resolves the target itself rather than adopting it as the caller's binding.

Cross-session results are namespaced: output lines carry in session <id> plus a note that block ids are per-session namespaces (decompress acts on the current session only; bulk content stays bili export <id> [--full]). Unknown ids fail loudly with [search_context FAILED: unknown session "<id>"] and create nothing.

Pre-flight (on rebased head, acp-kernel 0.0.74)

  • npm run typecheck clean
  • npm test: 1654 pass / 0 fail / 2 skipped (ACP_TEST_E2E-gated e2e not run — needs a live upstream)
  • npm run build success

New tests: tests/search-context-cross-session.test.ts (schema derivation + kernel non-mutation, self-reference incl. canonical alias, unknown-id failure, resident-memory hit without disk touch, cold-load read-only proof); extended tests/plugin-protocol.test.ts manifest assertions (per-shape conversation_id description, openai shape nested under function.parameters).

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-16_search-context-cross-session (b941b5d)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-858

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr858.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] 🏷 Reviewing PR #858 now — pulling branch 2026-09-16_search-context-cross-session, checking CI status, running local pre-flight (typecheck / test / build), and reviewing the diff. Will report back with findings.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — PR #858 verified, ready to merge.

CI (head d49c681): all 7 checks pass — tests on ubuntu/windows × node 22/24, build-artifact, version-guard, and the zero-token codex e2e.

Local pre-flight on rebased head (branch is a single linear commit directly on current master a752e54 — no stale base):

  • npm run typecheck clean
  • npm test: 1654 pass / 0 fail / 2 skipped (matches your claim)
  • npm run build success

Diff hygiene: 11 files, +340/−26, every line related to the feature. No lockfile churn, no version touch, no unrelated files. New test file + extended plugin-protocol assertions.

Code verification against the three claims:

  1. Kernel constants never mutated ✓ — src/compress-tool.ts derives BILI_ACP_TOOLS_* / BILI_SEARCH_CONTEXT_TOOL* from kernel constants via spread/map (new objects), and all four arrays are covered incl. BILI_ACP_READONLY_TOOLS_RESPONSES. server.ts switched every injection point (injectTool, injectOpenaiTool, injectResponsesTool + readonly variant) to the BILI_ arrays; the plugin manifest reuses the same SEARCH_CONTEXT_CONVERSATION_ID_PARAM via structuredClone. Test asserts the kernel constants themselves stay free of conversation_id and that no other tool entry changed.
  2. Non-resident targets load from persistence without side effects ✓ — resolveForeignSessionState (src/decompress-shared.ts) goes resident-memory first (peekSession/findSessionByCanonicalId, pure Map lookups at src/session.ts:280,319), else SessionStore.loadStateForSearch (src/persist.ts:474). Verified loadEnvelope (persist.ts:443) is a pure read through the same kernel-store path as loadSync, and loadStateForSearch never calls scheduleSave — so no 代理压缩不上报改写量,宿主上下文会计塌缩至 ~0(omps recordAnchoredHistoryRewrite 零调用);且持久化 lastInputTokens 恢复无钳制,旧版负值升级后复活 #408 clamp-rewrite side effect. Kernel search(query, state) is a pure function of state, so running it on foreign state is safe.
  3. Strictly read-only ✓ — execution stays anchored to the caller session at all three dispatch points (src/stream.ts anthropic, src/loop/core.ts openai-chat, src/compress-loop-responses.ts responses); no re-routing, so the target's mode binding/lastSeen are untouched. Cold-load creates nothing (no getSession call). Self-reference detection covers both verbatim id and canonical alias; unknown ids fail loudly with [search_context FAILED: unknown session "<id>"]. Output namespacing (in session <id> + per-session block-id note + bili export pointer) only appears on foreign results — omitted/self ids keep byte-for-byte legacy output (asserted).
  4. MCP shim ✓ — keepForSearch keeps conversation_id in args only for search_context when a default binding exists; routing override becomes undefined so the proxy resolves the target itself. No-binding fallback (per-call routing) is unchanged from feat: per-call conversation_id for MCP tools — let the model supply its session id #760/feat: per-call conversation_id for MCP tools (#760) #761.

Both compression modes covered per §6 (proxy mode: wire schema via BILI_ constants; plugin mode: manifest description + /__bili/plugin/tool → executeProxyTool in loop/core.ts). Wire fidelity intact — only an optional schema param added, no message-shape change.

No blocking findings. Merge is yours to do (agents don't merge).

中文摘要:审查了跨会话只读搜索(search_context conversation_id)的实现与测试——内核常量零改动、冷加载路径零写入(无 #408 clamp 副作用)、自引用/别名/未知 id 边界全覆盖、双压缩模式均验证通过,本地 typecheck/test/build 全绿且 CI 全绿,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

继续

@ranxianglei

Copy link
Copy Markdown
Owner Author

冲突 另外这个是否有回归问题 这个是否有行为改动

…sation_id

Extends the #760/#761 per-call conversation_id plumbing with a second, execution-layer semantic for search_context: when the id does not match the caller's own session (verbatim or canonical alias), the call searches that historical session instead of re-routing to it.

- resolveForeignSessionState: resident memory first (peekSession / findSessionByCanonicalId), else SessionStore.loadStateForSearch — a new strictly read-only persistence path that never schedules saves (unlike loadSync, which has the #408 clamp side effect).
- Cross-session results are scoped and namespaced: output lines carry 'in session <id>' plus a note that block ids are per-session namespaces; decompress stays anchored to the current session, bulk content via 'bili export <id> [--full]'.
- Unknown ids fail loudly ([search_context FAILED: unknown session ...]) without creating state.
- search_context's conversation_id param description is specialized in the plugin manifest (routing text kept for all other tools); wire-mode schemas gain the optional param via BILI_* derived constants so proxy-mode clients can target historical sessions too. Kernel constants are never mutated.
- MCP shim keeps conversation_id in args only for search_context so the proxy resolves the target itself; routing semantics for every other tool are unchanged, and no tool call ever mutates a foreign session.

Closes #841
@ranxianglei
ranxianglei force-pushed the 2026-09-16_search-context-cross-session branch 2 times, most recently from 2eefd9b to b941b5d Compare September 17, 2026 09:34
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

冲突已解决并重新 pre-flight,回归与行为改动逐条回答如下。

冲突

回归(均在 rebased head b941b5d 上实跑)

  • npm run typecheck clean
  • npm test:1675 pass / 0 fail / 2 skipped(ACP_TEST_E2E 门控的 e2e 不计,需 live upstream)
  • npm run build success
  • 跨会话搜索测试(tests/search-context-cross-session.test.ts)+ plugin manifest 断言全部在新 master 之上通过;未发现回归。

行为改动

  1. 默认路径零变化:不传 conversation_id、或传自己 session 的 id(含 canonical alias)→ 输出与旧版 byte-for-byte 一致(有测试断言);其余工具 schema、MCP 路由逻辑不变。
  2. 新增 opt-in 能力:显式传另一个 session 的 id → search_context 对该历史 session 做只读搜索(优先 resident memory,冷加载走 loadStateForSearch 零写入);未知 id 直接报错 [search_context FAILED: unknown session "<id>"],不创建任何东西。proxy mode 下 wire schema 多一个可选参数,plugin mode 下仅 manifest description 文案变化,kernel 常量零修改。
  3. 一处有意行为变更(MCP 客户端):此前给 search_context 传外部 conversation_id 会把调用 re-route 到那个 session(顺带触碰目标 session 的 mode binding / lastSeen);现在保持锚定调用者、对目标做只读搜索。无 default binding 时 per-call routing fallback 与 feat: per-call conversation_id for MCP tools — let the model supply its session id #760/feat: per-call conversation_id for MCP tools (#760) #761 原行为完全一致。
  4. 双压缩模式均已覆盖(§6):proxy 走 BILI_ 派生常量注入,plugin 走 manifest 描述特化。

推送后 CI 会重跑全量检查。合并由你操作(agent 不合并):#858

中文摘要:解决了 master 前进导致的冲突(仅两行 import 取并集,rebase 后 typecheck/test/build 全绿无回归);行为上仅新增"显式指定历史 session 只读搜索"的 opt-in 能力,外加把 MCP search_context 的外部 id 从 re-route(会碰目标 session 状态)改为锚定调用者的只读搜索,默认路径 byte-for-byte 不变,可以合并。

@ranxianglei
ranxianglei merged commit 753c483 into master Sep 17, 2026
8 checks passed
This was referenced Sep 17, 2026
@ranxianglei
ranxianglei deleted the 2026-09-16_search-context-cross-session branch October 15, 2026 05:32
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.

feat: 支持 search_context 显式查询历史 session

1 participant