Repository navigation
feat: per-call conversation_id for MCP tools (#760) - #761
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-761Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr761.tgz
npm install -g packageThis comment is automatically updated on each push. |
[bot] 🏷 PR #761 review — merge-ready, two items outstanding (owner decision + CI e2e dispatch) I checked out Independent validation (re-ran everything, not just trusting the description):
Audit findings (both compression modes considered, per AGENTS.md §6):
Minor observations (non-blocking, noting for the record):
Open question for the owner (flagged in the PR description, restating): the acceptance text says flip to pure plugin mode suppresses ephemeral tools and the nudge; this PR follows existing Verdict: diff is clean, logic is sound in both modes, tests are deterministic and well-targeted (the conv-other interleaving and the mock-proxy adoption-guard assertions are exactly the right proofs). Merge once (a) the nudge question is settled and (b) the manual ci-e2e dispatch is green. 审查了 PR #761(MCP 工具按调用传 conversation_id):独立复跑了全部验证(typecheck、1465 项测试、build、e2e 预检均通过),逐行审计确认 identity 懒注册不会误绑他人新会话、kernel 常量未被污染、前缀缓存字节稳定、孤儿收养触发子串原样保留;无需在分支上补修任何问题,待 owner 确认 nudge 保留决策并手动跑一次 ci-e2e 后即可合并。 |
Every session now exposes a stable pfa-* canonical id that MCP tools route by, independent of what the client calls itself. Anonymous sessions already ARE pfa-* (canonical == session.id); legacy client-named sessions derive a deterministic pfa-* from their session id, materialized onto persisted metadata.canonicalId. - wire notes inject the canonical id (all three prepare paths), so the model echoes back one uniform id space - tool/compact/status endpoints gain a canonical reverse-lookup path (map -> verbatim -> canonical); old ids keep working, unknown ids still 404 and create nothing - evidence-based plugin-mode flip: a successful MCP tool execution binds that session to plugin mode (guarded: never overrides an existing agent binding) Extends PR #761 (per-call conversation_id). Fixes #760.
…outing Per review of #760: per-call ensureRegistered() was dead weight. The sticky plugin-mode flip already comes from successful-tool evidence inside handlePluginTool, and a registration keyed by the canonical pfa-* id would never be consumed by a raw-client-id request anyway (consumePluginRegisterFor(raw-id) misses it) while still evicting identity-register LRU slots (cap 64). - src/mcp.ts: remove the per-call register call and the now-unused ensureRegistered(); keep initialize/register (single-session hosts enter plugin mode before their first model request) and rely on evidence for shared-host flips. - tests: the shared-shim e2e now passes the canonical pfa-* id (what the model copies from the injected note) instead of the raw client id, so it exercises the canonical reverse-lookup path end-to-end; the mock-proxy unit asserts NO registration is issued for per-call ids; comments/assertion messages updated from 'identity-mode lazy registration' to 'successful-tool evidence'. Extends PR #761. Fixes #760.
|
更新了很多重新review最新代码 是否有回归问题 |
[bot] 🏷 Re-review of updated head ( Reviewed the two new commits ( Verdict on the redesign: it's strictly simpler than v1 and eliminates the failure surface I flagged last round.
Independent validation on the new head:
One small fix pushed directly to the branch ( Outstanding before merge (unchanged from last round):
Merge-ready once those two land. 重新审查了更新后的 PR(新增 canonical pfa-* 统一 id 空间 + 证据式 plugin-mode 翻转,移除了按调用懒注册):逐机制核对无回归——懒注册移除恰好消除了上轮指出的 64 槽 LRU 边界问题,翻转有守卫不会覆盖原生 agent 绑定,canonical id 确定性派生且旧 raw id 向后兼容、伪造 id 仍 404 不建会话;独立复跑 typecheck/1497 项测试/build/e2e 预检全部通过,顺手在分支上修了一处 mcp.ts 头部过期注释(9009973),待 owner 确认 nudge 决策并手动跑一次 ci-e2e 即可合并。 |
|
owner 确认 nudge 决策 指的是什么决策? |
[bot] 🏷 指的是这个问题: Issue #760 的验收文字写的是——会话翻转到纯 plugin mode 后,proxy「不再注入 ephemeral 压缩工具与 nudge」(即 ephemeral compress 工具和 nudge 两者都不再注入)。 但本 PR 的实现只停掉了 ephemeral 工具,nudge 仍然注入(两种模式都注入,
如果你认为 A 没问题,这条就算关闭,PR 只剩手动跑一次 |
|
所以现在考虑看看有回归问题吗? |
[bot] 🏷 结论:没有发现回归问题。这轮我专门针对本 PR 唯一的新行为——会话中途从 wire mode 翻转到 plugin mode(现有流程都是绑定时就定好模式,没有中途翻转过)——做了一组针对性检查:
加上第二轮已核过的(canonical id 空间、raw id 向后兼容、伪造 id 404 不建会话、#656 收养触发子串保留、adoption guard 未动)和独立复跑的验证(typecheck ✅ / 1497 pass 0 fail / build ✅ / e2e preflight ✅),我的判断维持:可以合并,只剩手动 dispatch 一次 |
|
解决冲突 |
# Conflicts: # src/server.ts
[bot] 🏷 冲突已解决并推送到 PR 分支( 冲突本身只有一处: 合并带入的 master 内容已逐一核对与本 PR 无交互:
合并后树独立复跑全绿:typecheck ✅ · npm test:1593 pass / 0 fail / 2 skipped(含本 PR 的 8 项)· build ✅ · PR 现在与 master(v0.1.112)零冲突。剩余事项不变:手动 dispatch 一次 解决了 PR 与 master(v0.1.112)的合并冲突(server.ts 中 injectSystem 调用行一处,保留 PR 的 canonical id 参数,函数定义自动合并已验证含双方改动),核对了 master 带入的 plugin.ts 计费改动与 server.ts 重构均与本 PR 无交互,合并后树复跑 typecheck/1593 项测试/build/e2e 预检全部通过并已推送(b6e3782),PR 现与 master 零冲突。 |
…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
…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
What
Hosts that share ONE MCP shim process across several concurrent conversations (kimi web et al.) have no env/meta session channel — all three existing identity paths need client cooperation. This adds a fourth channel that needs none: the model supplies its own conversation id on every tool call, and the proxy routes by a unified canonical session id so wire requests and MCP tool calls share one identity space.
Changes
src/session.ts— unified canonical id. Every session exposes a stablepfa-*canonical id: anonymous sessions already AREpfa-*(canonical == session.id); legacy client-named sessions derive one deterministically from their session id (pfa-${sha256("legacy:"+sessionId)}, 16 hex chars), materialized onto persistedmetadata.canonicalId. ExportsensureCanonicalId(materialize+persist, idempotent) andfindSessionByCanonicalId(read-only reverse lookup over the resident pool — always consistent with the live set, no separate index to desync on evict/load).src/server.ts— the injected note prints the session's canonical id (all three prepare paths), so the model echoes back one uniform id space regardless of how its session was named. Byte-stable per session → prefix-cache safe.src/plugin.ts— manifest advertises an optionalconversation_idparam in all three tool formats (kernel constants cloned, never mutated; wire-mode injection serves them directly and is untouched).handlePluginTool/handlePluginCompact/handlePluginStatusresolve the target throughresolveConversation: map → verbatim session id → canonical reverse lookup. First calls route before any binding recorded the mapping; unknown ids still 404 (no model request has arrived) and create nothing. Evidence-based plugin-mode flip: a successful MCP tool execution binds that session to plugin mode (metadata.pluginAgent = "mcp", guarded — never overrides an existing agent binding). Nudge stays injected (owner decision); only ephemeral wire tools are suppressed post-flip.src/mcp.ts— shim routes per-call ids:tools/callreadsconversation_id, overrides the default binding for that one call only, strips the arg, forwards on the body field. Per-call lazy registration removed (post-review): the sticky flip comes from successful-tool evidence, and a registration keyed by the canonical id would never be consumed by a raw-client-id request anyway while evicting identity-register LRU slots (cap 64).initialize/register is kept for known single-session hosts to enter plugin mode before their first model request. Per-call failures never trigger orphan adoption. No-id error hints at the per-call parameter.Key decisions
pfa-*). Legacy sessions get a deterministic alias so old ids keep working AND the canonical reverse lookup works; nothing existing breaks.Tests
tests/issue760-percall-conversation.test.ts(8 tests):pfa-*id routes a legacy-named session (canonical reverse-lookup path) while the raw id still works; unknown id 404 without creating a session;Pre-flight
npm run typecheck✅npm test: 1467 pass / 0 fail / 2 skipped (gated e2e)npm run build✅E2E_CHECK=1preflight ✅; full run NOT completable here — the local sglang upstream (:8199) is down in this environment (ECONNREFUSED, zero completions; environmental, unrelated to the diff). Please run.github/workflows/ci-e2e.ymldispatch before merge sinceserver.tsprompt injection changed.Fixes #760