Skip to content

Incremental turns: pull receipt for hosts without a response seam + opencode v1 wired (#3352) - #3481

Merged
ranxianglei merged 1 commit into
2026-10-16_fix-incr-ack-url-keyingfrom
2026-10-17_opencode-incr-seams
Oct 17, 2026
Merged

ranxianglei merged 1 commit into
2026-10-16_fix-incr-ack-url-keyingfrom
2026-10-17_opencode-incr-seams

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Two gaps in the incremental-turn feature (#3248 phase 2), both opencode-shaped but one of them protocol-level:

  1. Hosts with no response seam could never ride incremental turns. opencode's v2 http.request hook observes requests but never responses — the ack (x-bili-applied-seq) lands on a seam the host cannot see. The seed turn was dispatched, the pending entry accumulated, and every following turn re-seeded: the feature silently never engaged for exactly the host class the issue (Incremental turns give opencode native zero savings in either generation (V1: no divert seam; V2: no response-ack channel) | opencode 原生插件的增量轮次两个版本下都不生效 #3352) reports.
  2. opencode's v1 lane (fetch patch) was not wired at all — the beforeSend slot existed (dsh-native rides it) but nothing converted anthropic bodies there.

How

Pull receipt (protocol): GET /__bili/plugin/turn?conversation=<id> now answers { conversation: { appliedSeq, boundary } } — the canonical's current length plus the wire hash of its last applied wire message (sha256(role \0 JSON.stringify(content)), first 16 hex — byte-identical formula to the client helper's wireHash, pinned by a cross-module test). A host without a response seam reconciles itself: before planning turn N+1 it pulls the receipt and settles its last unacked turn only on a boundary match:

The boundary check is the whole safety story: adopting a receipt whose boundary is not your tail would credit foreign rows (an interleaved wire full-resend, a provider switch — both advance the canonical through rawTail) to your watermark, and sinceSeq (core count) would drift from sent (wire hashes) → duplicate messages served upstream. Blind seq-based adoption is exactly the double-serve trap.

Boundary is warm-cache-only, deliberately. It is computed from the wire bytes the lane itself applied (deltaWire tail — never a core-converted form, whose JSON key order could drift and fake a mismatch into a resync loop). A cold-rebuilt canonical never claims a boundary: stored rows are core-form, wire parity is unprovable, so null forces the client to resync once (which re-arms it from that resync's own wire tail). A system-only turn through a cold-rebuilt canonical keeps boundary: null for the same reason. Cost: one extra resync per conversation per proxy restart — acceptable.

v1 wiring: beforeSend converts anthropic bodies in place (init.body swap, marker + turn id stamped on the same init — atomic per #3370), acks ride the existing response seam per turn id (#3329), and the pull reconcile heals a missed seam (host restart mid-turn). The conversation id comes from the chat.headers stamp (x-bili-plugin-conversation); proxy-mode installs without the stamp have no conversation identity and stay full-resend. Dual-call hosts (setup + server both run) cannot double-convert: a v2-converted incremental payload has no top-level model, so the v1 guard rejects it.

sweepStale moved from the adapter entry to the single-flight scan (both seams): an entry older than the 30s TTL is still the reconcile's only record of what the last turn sent — sweeping it at entry forced an unnecessary resync after every idle gap.

Stacking

Stacked on #3340 (2026-10-16_fix-incr-ack-url-keying) — the turn-id mechanism is a prerequisite. Rebase onto master once #3340 merges; the diff there is small.

Testing

  • tests/opencode-incremental.test.ts: pull-ack (V2, no response seam, watermark advances by boundary), cold/foreign decline → resync self-heal → re-arm, unreachable lane → skip + stash kept; v1 seam convert/stamp/ack/delta + missed-seam pull heal; proxy-mode no-stamp untouched (11/11)
  • tests/incremental-lane.test.ts: receipt shape + client-formula parity cross-module; cold rebuild → boundary: null through a system-only turn; wire delta re-arms (21/21)
  • Families: incremental-client-recovery 4/4, omp-native-incremental 4/4, issue3343-divert-authz 3/3, native-intercept 59/59, opencode-native-v1 28/28, opencode-native 38/39
  • Known pre-existing on clean origin/master (same test, same count, verified in a detached worktree): opencode-v2.test.ts 3 fails (v2 setup: activates from /bili/ baseURL…, env-based activation…, #2443 acp_retrieve…) and opencode-native.test.ts 1 fail (module evaluation marks the process as a native opencode host) — sandbox network class, unrelated to this change
  • PLUGIN.md: pull receipt documented (EN incremental + marker divert host wiring, ZH mirror); tsc clean

Fixes #3352

opencode's v2 http.request hook sees requests but never responses, so an
incremental seed was never acked and every later turn re-seeded — the
feature could never ride for that host. The lane now answers
GET /__bili/plugin/turn?conversation=<id> with { appliedSeq, boundary },
the canonical length plus the wire hash of its last applied wire message
(byte-identical formula to the client helper). Hosts without a response
seam pull the receipt before planning and settle their last unacked turn
ONLY on a boundary match — a cold (null) or foreign boundary is declined
(one decline re-seeds, a streak falls back per #3369). Pulls are always
fresh, never the 30s probe cache.

opencode v1 (fetch patch installed) is wired through beforeSend: bodies
converted in place, marker + turn id stamped atomically (#3370), acks on
the response seam per turn id (#3329); the pull reconcile heals a missed
seam there too. sweepStale moved from the adapter entry to the
single-flight scan — an aged stash is still the reconcile's only record
of the last turn, and sweeping it first forced a resync after every idle
gap.

Stacked on #3340 (turn-id mechanism). Boundary is warm-cache-only by
design; store-rebuilt canonicals never claim one (core-form rows cannot
prove wire parity) — resync re-arms it.
@ranxianglei
ranxianglei merged commit 3736aad into 2026-10-16_fix-incr-ack-url-keying Oct 17, 2026
17 checks passed
ranxianglei pushed a commit that referenced this pull request Oct 17, 2026
…s gate

#3599 review: the re-landed #3481 exported IncrementalReceipt although no module imports it by name (consumers use pullIncrementalReceipt's inferred return type). The CI unused-exports gate classifies it INTERNAL_ONLY and fails the head, which fail-fast-skipped every test lane. Dropping the leading export keeps the type available through the exported signature.
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