Repository navigation
fix(responses): keep persona-scoped sessions stable across instruction drift - #1104
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1104Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1104.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 收到。这是带 |
[bot] 🏷 Review complete — I pulled the branch ( Code review
Verification (all run by me on the head commit)
The full One non-blocking observation: after upgrading, opencode sessions previously keyed under Per §7.4 this touches identity/session-binding logic, so it stays human-merge. 可以合并。 修了 opencode 会话中 AGENTS.md 变更导致 |
|
Verdict: MERGE (human review — correctly NOT auto-merge eligible: touches identity/session-binding + plugin-protocol surface). Independently verified:
Findings (none blocking):
Negative controls all pass: |
…n drift opencode's system-context reconcile rewrites the Responses instructions field whenever AGENTS.md changes mid-session. The compression session key mixed instructions into subagentNamespace's fingerprint, so each edit forked an orphan |sub:<fp> session and reset all compression state (#1102). Skip the instructions fingerprint only when the winning conversation signal is a verified persona-scoped identifier: - opencode native: x-session-affinity ses_... / x-opencode-session - plugin declaration: x-bili-plugin-conversation + x-bili-plugin-instructions-mutable: 1 (stamped by the opencode plugins; unverified hosts stay fingerprinted) All other signals (codex body/header ids, claude shared-id subagents, grok, generic, pck) keep the fingerprint - the #150 persona-separation guarantee is untouched. Fixes #1102
71fdf76 to
9695a4e
Compare
Acted on the review. New PR head: Done
Not applied as written — needs your call (finding #3, prettier) I checked what
My recommendation: skip prettier for this PR (there is no gate to satisfy). If you want prettier as a project standard, the clean path is committing a Findings #1 / #4 — left untouched
PR is at 已按 review 处理:rebase 到最新 master( |
…-sharing hosts dsh stamps ONE x-bili-plugin-conversation id on every model request of a session, INCLUDING the auto-review classifyRisk() calls (fixed REVIEW_POLICY system + a freshly-flattened user blob, fired before every tool call under the Auto permission tier). Those review requests walked the full pipeline under the MAIN conversation id: they overwrote the usage baseline (#1916), evicted remembered snapshots (#1307's guard was a partial stopgap), and fed orphan-GC — while the review blob is synthesized fresh every time, so compressing it has zero reuse value. Key dsh traffic by id + system hash (kernel subagentNamespace anchor semantics): the FIRST system seen under the id keeps the raw key (the main turn claims it — dsh composes its main system once per session and puts the volatile time-context in a USER message, so main turns never fork mid-conversation), a different system forks onto <id>|sub:<fp> (the review persona), and an empty system is non-anchoring (verbatim key, system-less auxiliary calls keep riding the main session). - src/session-id.ts: dshPersonaFingerprintApplies (evidence-permitlist, the #1104/#1107 discipline — do NOT enable wholesale, #1106) + openaiSystemTextForPersona. - src/server.ts: fork applied on the openai and anthropic lanes; personaForked sessions record under their suffixed id (recordPluginSession) so the single-valued conversations map keeps the raw key owned by the main session (#970 discipline). - AGENTS.md: Key Design Decisions #9 — the rule for future hosts that reuse one session id across personas. - tests: fork/stability/allowlist/anthropic-lane coverage (peekSession — getSession is get-or-create and would mint the sessions we assert about). Refs #1916 #1307 #1314
What / why
opencode's system-context reconcile rewrites the Responses
instructionsfield whenever AGENTS.md changes mid-session. The compression session key mixedinstructionsintosubagentNamespace's fingerprint, so each edit forked an orphan|sub:<fp>session and reset all compression state (#1102). This is the independent design for a bug that exists on master today; it is NOT a salvage of PR #1092's anchor-dependent hunk (that hunk only skips the fingerprint understableSystemAnchor, which absorbs drift as notes — extracting it alone would merge genuinely different personas that share one conversation id, exactly what the fingerprint exists to prevent).Skip the instructions fingerprint only when the winning conversation signal is a verified persona-scoped identifier (one id minted per persona, so an id can never be reused across personas):
x-session-affinitywith ases_…value, orx-opencode-session. opencode stamps its session id on every model request and mints a fresh child session id for every task-tool subagent (sessions.create({ parentID })), so a fixed id carrying different instructions mid-conversation means "same persona, updated system context", not a new persona.x-bili-plugin-conversation+x-bili-plugin-instructions-mutable: 1. A cooperative plugin declares its host's ids are persona-scoped. Only the opencode plugins stamp it today; unverified hosts (dsh, hermes, …) stay on the fingerprinted path.Everything else deliberately keeps the fingerprint: Codex body/header/metadata session ids (#150),
x-claude-code-session-id(Claude subagents SHARE the main agent's session id, #970), grok/mcode/genericx-session-id, prompt-cache-key. The #150 persona-separation guarantee is untouched.Changes
src/session-id.ts: extractconversationHeaderSource()(reports WHICH header won, needed because trust depends on the signal's origin, not just its value) +instructionsFingerprintExempt()with the trust set above and a full rationale comment.src/server.ts: Responses identity branch keys exempt signals verbatim (like the trustedcodexTurnbranch) instead of throughsubagentNamespace.src/plugin.ts: newPLUGIN_INSTRUCTIONS_MUTABLE_HEADERconstant + manifest entry.src/agent/opencode-native.ts,src/agent/opencode-v2.ts: stamp the declaration header.PLUGIN.md: document the flag (manifest example + request-header list).tests/responses-instructions-drift.test.ts: unit tests for the trust set + two end-to-end regressions (native opencode headers, plugin-declared) asserting no orphan fork + compressed state carried across the drift.Migration: upgrading re-keys live opencode sessions from
<id>|sub:<fp>to the bare conversation id — one final compression-state reset per in-flight conversation (no data loss; clients re-send full history on the next request).Pre-flight
npm run typecheckcleannpm test: 2171 tests, 2169 pass, 0 fail, 2 skipped (theACP_TEST_E2E-gated codex e2e)npm run buildcleansrc/server.tsmakes both e2e tests fail (the orphan fork reproduces), proving the tests actually exercise the fix.tests/e2e/e2e-codex.test.tsE2E_CHECK=1zero-token preflight passes; the fullACP_TEST_E2E=1run needs the local sglang upstream athttp://127.0.0.1:8199/v1(not reachable in this environment), so it was not executed here. The change does not touch the codex identity path (codex keeps the fingerprint), so codex e2e behavior is unaffected.Fixes #1102