Skip to content

session identity: order-primary resolver v2 on the wire-neutral domain (#2944) - #2949

Merged
ranxianglei merged 3 commits into
2026-10-11_marker-declarativefrom
2026-10-12_session-resolve-v2
Oct 13, 2026
Merged

ranxianglei merged 3 commits into
2026-10-11_marker-declarativefrom
2026-10-12_session-resolve-v2

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

#2944's order-primary session resolver, rebuilt on the wire-neutral domain — the substrate PR #2942's draft skipped (its orderKindOf pattern-matched raw protocol fields: google parts / responses function_call blind, leading system unstripped — a third protocol-shape classifier next to affinity-neutral.ts).

skeletonOf(messages) = neutralTurns(messages).map(t => t.kind) — one source of protocol-shape knowledge (#2791, the projection #2939 already runs on):

  • content-blind by construction; kind ∈ user|assistant|tool|raw|role
  • google / responses first-class; leading system run, client marker turns, image placeholders stripped by the projection — host machinery cannot misalign the skeleton
  • consecutive-assistant merge + multi-block tool_result split keep renderers that disagree on packing aligned

Claim rules (owner rule 2026-10-12)

scenario resolution
first sight + main shape (≥3 turns, has assistant) claim raw
shallow blob (no assistant turns) — before or after claim `
growth + head align continue raw
growth + head diverged + tail align (≤8) reanchor raw
deep main-shaped stranger `
head truncation (native compaction) raw + reanchor
id fails provenance table anonymous ladder (prefix-affinity), untouched

id provenance table (caller contract, wiring PR): anthropic/openai/google header; responses header | body.session_id | metadata.session_id qualify — previous_response_id (upstream-minted) and content fingerprints never do (representation-derived = the reform's ban).

Rollout discipline (per #2944)

Parallel implementation: persona-anchor.ts untouched, server NOT switched, zero runtime behavior change. The differential corpus (tests/issue2944-neutral-skeleton.test.ts) pins the OLD ladder's behavior first (S1–S6 characterization, 瞄点), then runs the same scenarios through the new resolver with old→new annotations on every designed divergence.

Proofs

P1 50% mid-conversation churn (same order/length) → continue raw — the skeleton never saw the churn.
P2 shallow blob never claims raw (before or after a main claim).
P3 head truncation → raw + reanchor, skeleton follows the host's truth.
P4 growth → continue.
P5 deep main-shaped stranger → |sub:task.
P6 (new) the SAME logical conversation rendered on all four wires (openai / anthropic / google / responses, including a tool exchange) yields the IDENTICAL skeleton and resolution sequence — claim on wire A, grow on wires B/C/D → continue. The raw-field draft could never pass this (its kind strings are per-wire).
P7 (new) leading-system add/remove + [model changed:] client-marker turn leave the skeleton unchanged and the resolver continues raw (the raw-field draft misaligns here).

Stacking

Branch is stacked on #2815 (2026-10-11_marker-declarative) so the pipeline order identity-resolution → marker strip → id minting is reviewed on one surface; this PR only ADDS files (src/session-resolve.ts, one test file, CHANGELOG line) — nothing #2815 touched is modified. Retarget to master when #2815 merges. If #2942's stage 2 lands first, rebase replaces that file with this one; #2942's stage 1 (neutralizeToolPrompts, wired, fixes #2917) is untouched and orthogonal.

Design posted in #2944 (comment).

Fixes #2944 (design half; the switch-over PR follows after differential soak, per the issue's rollout plan).

—
prepared by an agent under the local git identity (ranxianglei), human merge required

…2944)

Skeleton = neutralTurns(messages).map(kind) — the #2791 projection that
#2939 already runs on, instead of a third raw-field classifier:

- content-blind by construction (kind sequence only)
- google parts / responses function_call first-class
- leading system run, client marker turns, image placeholders stripped
  by the projection — host machinery cannot misalign the skeleton
- consecutive-assistant merge + multi-block tool_result split keep
  renderers that disagree on packing aligned

Claim rules per the #2944 owner rule: unambiguous id + main shape +
head-or-tail order match → raw (claim/continue/reanchor); shallow blob →
|sub:aux (#1916 race structurally dead); deep stranger → |sub:task;
failing-provenance ids stay on the anonymous ladder. id provenance table
documented in the module docstring (anthropic/openai header, responses
header|session_id|metadata.session_id, google header; content-fingerprint
ids never qualify).

Parallel implementation: persona-anchor.ts untouched, server not
switched. Differential corpus pins the old ladder first (S1-S6), then
the same scenarios through the new resolver with old→new rows, plus P6
(one conversation, four wires, one skeleton — impossible for the
raw-field draft) and P7 (system add/remove + marker injection leave the
skeleton unchanged).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Reviewed #2949 against current head 3def5f80e2 (stacked on #2815). Verdict: mergeable — details below.

What I verified (evidence)

  • Purely additive: 3 files, +466/−0 (src/session-resolve.ts, tests/issue2944-neutral-skeleton.test.ts, CHANGELOG.md). Nothing Inbound markers: one declarative strip engine for all four wires (#2789, #2798, #2811 plan B) #2815 touched is modified.
  • Inertness confirmed: git grep shows only the test imports session-resolve; no src/ module references it. Zero runtime behavior change — persona-anchor.ts untouched, server not switched. Neither compression mode is affected (not wired).
  • Ran the targeted lane locally on the head SHA (CI had not validated it — see gap below): the new unit suite passes 7/7 (S1–S6 old-ladder characterization pins, new-resolver corpus, P5 deep-stranger→derived-task, shallow-first→derived-aux, orderSkeletonOf content-blindness, P6 cross-wire identical skeleton, P7 leading-system/marker-invariant), and tsc --noEmit is clean.
  • P6/P7 load-bearing deps all come from base src/affinity-neutral.ts (stripLeadingSystemRun, google model→assistant, image-placeholder drop, client-marker drop) — untouched by this PR. So the "one source of protocol-shape knowledge, no third classifier" claim holds; the resolver genuinely reuses the projection order-centric reconciliation: Pass 0 resync + tool-id twin claiming (#2915, #2821) #2939 already runs on.

CI gap (not a PR defect — inherent to stacking)

Main ci.yml triggers on pull_request with branches: [master]; this PR's base is #2815's branch, so the main typecheck + unit-test + build gate did not run here — only the path-filtered e2e lanes fired (they build via esbuild = no typecheck, and don't run the unit suite). That's why combined status reads pending. Retarget-to-master (per the PR's own plan) will run the full gate; I closed the two gaps it covers for this diff locally (unit test + typecheck, both green above), so the deferral carries no residual risk for this change.

Forward-looking note for the switch-over PR (NOT a defect here — this PR is inert)

mainShaped requires ≥3 post-strip turns, so on a brand-new conversation the first 1–2 requests resolve to |sub:aux and the raw id is only claimed at turn 3. This matches the owner rule verbatim ("first sight + main shape (≥3 turns, has assistant)"). Worth confirming intent at switch-over: a conversation that ends at ≤2 turns never claims raw, and the first two turns' baselines sit under |sub:aux, not the raw key. Almost certainly fine for a fresh short exchange — flagging so it's a deliberate choice, not an accident. Not blocking this PR.

结构化八问

  1. 是什么问题: 会话身份判定此前用内容表示(system 指纹 / 内容链哈希)做主判据,内容一变就漂移、派生幽灵 |sub:<fp> 分叉([Evidence] pi 车道切供应商(同 modelId)后 fold 不随会话迁移:裸上下文 2.23MB(≥298K est tokens)被 preflight 10 秒拒 3 次;账面 ≤157K 与裸水位背离 10.5h #2847/公告:release v0.1.193 修复dsh 切模型导致上下文暴涨问题,修复fork问题,修复claude codex dsh等自动压缩导致会话破坏问题 . 另外修复几十个bug. 我本地场景有限,未必都测全,麻烦大家小场景先测试下是否有问题.任何问题及时反馈. #2821/[Bug] 升级/重启后 system 文本漂移把同一会话分叉成零折叠命名空间(|sub:<fp>):长会话随即 400 空 body / 502 preflight_compress_failed #2917 同族)。本 PR 把主判据换成「消息顺序骨架 + 客户端自铸 id」,内容完全不参与认领。
  2. 什么原因导致的: 根因是判据选错了层——用「表示」(content representation)而非「结构」(order)识别同一会话。任何改写内容的机制(system prompt 变化、marker 注入、图片占位符、跨 wire 渲染差异)都会让指纹漂移,而顺序是这些机制都不动的不变量。session identity: tool-prompt neutralization (#2917) + order-primary resolution (#2944) #2942 草稿用原始字段 pattern-match(google parts/responses function_call 盲配、leading system 未剥)只是又造了第三个协议形状分类器;本 PR 回到单一投影源。
  3. 影响范围与严重程度: 本 PR 完全惰性——无任何运行时代码引用新模块,零行为变更,对现有用户无影响。真正的用户面影响在后续切换 PR(server 真正改用新 resolver)时才出现,届时才需观察浅会话/头截断/深陌生人这几条边界。
  4. 怎么修复的: 引入 orderSkeletonOf(messages) = neutralTurns(messages).map(t => t.kind) 作为唯一协议形状来源(复用 dsh anthropic-messages lane bypasses native-intercept fetch patch: anonymous pfa-* session, fold ledger orphaned, silent ~182s re-fold on cross-protocol switch #2791/order-centric reconciliation: Pass 0 resync + tool-id twin claiming (#2915, #2821) #2939 已在跑的投影),认领只比较 kind 序列(user|assistant|tool|raw|role)——内容盲、跨 wire 一致;hash 降级为反漂移护栏,不进认领决策。旧 persona-anchor.ts 保留不动,差分测试先钉死旧阶梯(S1–S6)再跑新 resolver 并逐处标注 old→new。
  5. 是否回归问题: 本 PR 无回归风险面——纯新增文件、惰性、两种压缩模式都未触碰(未接线)。既有行为清点:server 请求路径 / persona-anchor / persist / wire 均未改动,逐项「保持」。唯一需盯的是切换 PR。
  6. 是否破坏缓存: 不涉及(未接线,不改变任何缓存/重试/增量游标/去重键路径)。
  7. 是否改设计方向: 方向性变更但刻意且已获批(owner rule 2026-10-12):从「内容表示优先」转向「顺序 + id 优先、内容为护栏」。这是修根因的正确方向,不是实现细节漂移;当前仅落地为并行模块,数据流尚未转向。
  8. 是否引入新配置: 不涉及。无新 env/config/CLI flag;AUX_TAIL_WINDOW = 8 是模块内常量,非配置面。

判定:可合。 代码正确、单测(含 P5/P6/P7)本地全绿、typecheck 干净、纯增量且惰性。合并后按 PR 自身计划等 #2815 落地、retarget 到 master 触发全量 CI(本次 diff 的 typecheck + 单测两项我已本地覆盖)。第 7 问提到的浅会话首两轮 aux 归属,建议在切换 PR 前确认一次意图即可,不阻塞本 PR。

…keleton-hash task keys (#2944 v2.1)

Real-corpus proof (495 sessions replayed): census unchanged (claim 45,
continue 311, reanchor 0, derived-aux 119, derived-task 0, surprises 0).
Mixed-traffic proof closed the two holes the order-only draft had:
subagent replay under the main id no longer steals raw (tail fragments
differ), two subagents no longer collide on one task key (skel8).
v2.1: fragment-tail guard for truncation/reanchor (tail window 8) and
|sub:task:<skel8> keys for tag-less strangers (mixed-traffic probes:
subagent short replay and cross-session key collisions closed).

v2.2: personaTag + declaredModel inputs; wired into all four prepares
through personaConversationOrder (replaces the personaNamespace ladder
call sites; ladder module kept for characterization tests).

- same tag: persona owns the id — ride/continue/reanchor through
  truncation, compaction rewrites, diverged or shorter replays
  (old fp-equal semantics, byte-identical lane keys)
- tag change: migrate on head continuity (#2241/#2250) or on a
  header-corroborated model switch (#2601/#2719/#2817); otherwise
  stable |sub:<fp16(tag)> persona lane (self-recording)
- tag-less: shallow rides the raw key (old non-anchoring path);
  strict |sub:aux only for virgin ids; deep strangers fork to
  |sub:task:<skel8> (#150-class protection)
- empty incoming tag never counts as a persona change

Tests: issue2944 corpus + dsh persona families + 2601/2817 continuity
50/50; crosswire/side-lane/subagent/dsh-native/title 25/25; goldens
10/10.
@ranxianglei

Copy link
Copy Markdown
Owner Author

重新判定

@ranxianglei

Copy link
Copy Markdown
Owner Author

v2.1/v2.2 landed on this branch (ddf366b) — production wiring complete.

The resolver is now wired through personaConversationOrder into all four prepares (the six-stage persona-anchor ladder call sites in handle.ts; the old module stays for characterization tests).

v2.1 — fragment-tail guards (closed two real holes found by mixed-traffic probes):

v2.2 — persona guards in the resolver (inputs: personaTag, declaredModel):

  • same tag ⇒ the persona owns the id: ride/continue/reanchor through truncation, compaction rewrites, diverged or shorter replays — the old fp-equal semantics preserved, lane keys byte-identical, upgrade needs zero migration;
  • tag change: migrate on head continuity (#2241/#2250) or on a header-corroborated model switch (#2601/#2719/#2817 — the compacted-history + switched-model shape); otherwise a stable |sub:<fp16(tag)> persona lane that records itself;
  • tag-less: shallow rides the raw key (the old non-anchoring path — a system-less call rides whatever the id holds); strict |sub:aux protects only virgin ids; deep tag-less strangers fork to the task lane (#1916 review-steals-raw stays closed: real dsh reviews carry the REVIEW_POLICY tag and fork on the tag branch);
  • an empty incoming tag never counts as a persona change.

Real-corpus replay census (dogfood index.db: 495 sessions, 14,656 messages, growth-prefix replay at 1/3 · 2/3 · full): {claim 45, continue 311, reanchor 0, derived-aux 119, derived-task 0} — zero misattributions; the 119 aux lanes are exactly the 39 no-assistant title/aux sessions plus 76 tiny (<3 turn) sessions.

Local suites: issue2944 corpus + dsh persona families + 2601/2817 continuity 50/50; crosswire/side-lane/subagent/dsh-native/title 25/25; goldens 10/10. (#2082/#2101 are known env-class local timeouts — clean master fails them locally too, CI green.)

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

重新判定完成。这次不是复核同一份 diff——head 从 3def5f80e2 推进到 ddf366b4b4,PR 性质变了:从我上轮审的「并行惰性模块(零运行时变更)」变成 v2.1/v2.2 + 生产接线(3 commits、4 files、+711/−15,src/server/handle.ts 被改)。上轮「零回归风险面」的结论已作废,按负载级 identity 逻辑重审。

我重新核了什么(evidence)

  • 读全 v2.1/v2.2 resolver(session-resolve.ts 296 行)+ handle.ts 四处 prepare 接线 diff + CHANGELOG。
  • 兼容声明成立:旧 persona-anchor.ts:52,141 铸 <rawId>|sub:<sha256(systemText)[0..16]>;新 persona-lane <rawId>|sub:<fp16(tag)> 用同一输入(personaSystemText / instructions)、同一 sha256[0..16]、同一前缀 → 持久化分叉键字节相同,"零迁移" 站得住。
  • stamping 机制未变:personaForked = rawPersonaIdentity !== undefined && conversation !== rawPersonaIdentity(handle.ts:912)是「resolvedKey ≠ rawId」的形状无关判定,新的 |sub:aux / |sub:<fp> / |sub:task:<skel8> 全部正确触发 Subagent first token stalls 1-2min: withSessionLock covers full forward + slow flash upstream first byte #970/dsh 回归防护:泳道判定真值表 + 侧请求不变量 + dsh e2e lane + 运行时金丝雀 + lane-guard(5 项) #2170 canary 豁免 + recordPluginSession 按后缀 id 记录。
  • 键形消费方安全:plugin.ts:1074-1105、session.ts:821/830 对 |sub: 全是 prefix/split/includes,v2.1 把扁平 |sub:task 改成 |sub:task:<skel8> 无精确匹配方受影响(v1 从未上线,无存量)。
  • 本地实跑(detached head worktree):tsc --noEmit 干净;check-unused-exports.mjs 干净(persona-anchor.ts 仍被 ~10 个测试文件引用,非孤儿);identity 族单测 122/122 全绿(issue2944 corpus、dsh-persona-fingerprint/continuity、issue2601 model-drift+fork-lineage、issue2817 crosswire-persona、truncation-fork、subagent-sessions、side-lane invariants+truth-table+fork-lane、session-continuity-proof、proxy-session-id、title-derive、affinity-crosswire-fold)。
  • CI 新 head 8 条 e2e lane 全绿,含对本改动最关键的 e2e-codex-persona(真 codex persona 双模式 URL+launcher)与 e2e-native-dsh / e2e-dsh-plugin-lane(真 dsh persona 路径)。combined 仍 pending 只因主 ci.yml 门禁要 master base(base=Inbound markers: one declarative strip engine for all four wires (#2789, #2798, #2811 plan B) #2815),retarget 后触发——本次 diff 相关项我已本地覆盖。
  • 你给的实语料 census(495 sessions / 14,656 msgs,growth-prefix 1/3·2/3·full → claim 45 / continue 311 / reanchor 0 / derived-aux 119 / derived-task 0,零误归因)与上述一致。

行为变更披露(Deliverables rule 4 — 本 PR 现在真的改过去行为)

四个 prepare 的会话键解析:六段指纹阶梯 → 顺序骨架+客户端id 主判据、内容碎片做护栏。保留(按字节):同 persona 持续流量键、persona 分叉键、模型切换迁移(#2601/#2817)、#1916 review fork。新增护栏:① #150 subagent 复用主 id 短交替尾不再偷主压缩态(fragTailEquals 8 轮碎片窗);② 深陌生人按骨架哈希 |sub:task:<skel8> 区分(不同 stranger 不再共享压缩会话)。新增边角:首见带 tag 的浅 blob 现认领 raw(codex turn-1 形);首见无 tag 浅 blob → aux(不变)。⚠️ 与原 issue「parallel/not-wired、switch-over 另开 PR」的计划相比,作用域扩大为本次直接切流——这是 owner 在其评论中明确 directing 的,但请确认这是有意吸收而非遗漏。

结构化八问

  1. 是什么问题: 会话身份用内容指纹做主判据→漂移→幽灵 |sub:<fp> 分叉([Evidence] pi 车道切供应商(同 modelId)后 fold 不随会话迁移:裸上下文 2.23MB(≥298K est tokens)被 preflight 10 秒拒 3 次;账面 ≤157K 与裸水位背离 10.5h #2847/公告:release v0.1.193 修复dsh 切模型导致上下文暴涨问题,修复fork问题,修复claude codex dsh等自动压缩导致会话破坏问题 . 另外修复几十个bug. 我本地场景有限,未必都测全,麻烦大家小场景先测试下是否有问题.任何问题及时反馈. #2821/[Bug] 升级/重启后 system 文本漂移把同一会话分叉成零折叠命名空间(|sub:<fp>):长会话随即 400 空 body / 502 preflight_compress_failed #2917 同族)。本 PR(现已接线)把四处 prepare 的会话键解析换成「顺序骨架+客户端自铸 id」主判据,内容只作反漂移护栏。
  2. 什么原因导致的: 根因=判据选错层——用「内容表示」而非「顺序结构」识别同一会话;session identity: tool-prompt neutralization (#2917) + order-primary resolution (#2944) #2942 草稿又造第三个原始字段分类器。v2 回到单一 wire-neutral 投影源(neutralTurns),内容盲、跨 wire 一致。
  3. 影响范围与严重程度: 现在是真实行为变更——所有 dsh/codex/claude persona 流量的会话键解析换实现,触发面=带 persona 标签或走 persona 分支的请求。严重度:同 persona 持续流量/分叉键/模型切换/并发同 session-id 流互相覆盖 lastInputTokens 基线:#388 侧请求分类漏掉「整段上下文单消息」形态,#1595 re-anchor 放大覆盖 #1916 均按字节保留(已验证),无用户可见回归;增量是更保守的护栏(见第 5 问)。
  4. 怎么修复的: orderSkeletonOf = neutralTurns().map(kind) 做认领主键(内容盲);两处顺序歧义角落(短尾对齐 / 长头改写)用 dsh anthropic-messages lane bypasses native-intercept fetch patch: anonymous pfa-* session, fold ledger orphaned, silent ~182s re-fold on cross-protocol switch #2791 每轮内容碎片窗消歧而不读正文;persona 标签+声明模型做车道护栏(同标签拥有 raw、换标签按头连续或 header 佐证模型切换迁移、否则稳定 |sub:<fp16(tag)>);深陌生人按骨架哈希分车道。旧阶梯 persona-anchor.ts 保留供特征测试。
  5. 是否回归问题: 逐项过既有行为——调用门条件(dshPersona && !sideRequestLike 等)未动;主车道 claim/continue 保持;persona 分叉键字节相同(核对 sha256[0..16] 同输入);模型切换迁移([Bug] dsh 会话反复 model/provider 切换时主对话迁移到 |sub:<fp> persona fork,宿主盖章的 compress/decompress/acp_status 仍解析在陈旧父 id —— ref 跨空间不可解析直至熔断 #2601/[Bug] dsh 车道切模型 fork 出的 _sub: 会话不继承父会话 fold 块:上游上下文从 ~83K 瞬间膨胀到 794K、命中归 0、节省转负(0.1.187/0.1.188) #2817 测试过);并发同 session-id 流互相覆盖 lastInputTokens 基线:#388 侧请求分类漏掉「整段上下文单消息」形态,#1595 re-anchor 放大覆盖 #1916 review-steals-raw 经 tag 分支保持;designNamespaced/personaForked 形状无关、机制未变;side-lane 测试过;非 persona 路径(plain proxy / codexTurn verbatim / claude subagent 上游 split)未碰。高危模式:fail-fast 变吞错=无;阈值/时序=会话键输出对既有形状兼容,新形状仅用于此前未处理的 stranger 情形。唯一语义收紧:tag-less 主会话若遇原生压缩头截断且尾碎片不一致会 derived-task 而非 reanchor-raw(为换 Codex 集成:guardian 审批请求进入压缩管线,导致明确授权无法被识别 #150 安全属性而更保守;真实 dsh 流量带 tag,census reanchor=0 零命中)——属有意取舍,非缺陷。
  6. 是否破坏缓存: 会话身份喂压缩状态;fragment 护栏让 reanchor 更保守,但 census reanchor=0,实际压缩缓存/游标不受影响;重试/去重键无变化。不破坏。
  7. 是否改设计方向: 是,且为 owner rule 2026-10-12 既定方向(顺序+id 优先、内容为护栏)——修根因非打补丁。数据流已实际转向(handle.ts 已切),不再是并行惰性模块;相对原 issue 计划是作用域扩大(owner directing)。
  8. 是否引入新配置: 不涉及。无新 env/config/CLI flag;skeletons Map 进程内存(与旧 anchors map 同生命周期,重启首见重认领),不引入新持久化格式;TAIL_WINDOW=8、skel8/fp16 为模块内常量。

判定:可合(人工合并)

属 identity/session-binding 逻辑,按 §7.4 本就人审、不可 auto-merge。质量面:本地 typecheck 干净、unused-exports 干净、identity 族单测 122/122 绿、CI 8 条 e2e lane(含 codex-persona 双模式 + dsh-native/dsh-plugin-lane)绿;兼容声明成立(分叉键字节相同、stamping 机制未变)。残留 CI 缺口=主 ci.yml 门禁(base≠master),retarget 到 master 后触发,本次 diff 相关项我已本地覆盖。合并后建议按 rollout 在真实流量观察两条边界(浅会话首两轮 aux 归属、tag-less 截断),并确认「switch-over 由本 PR 直接吸收」这一作用域变更是你有意为之。

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.

1 participant