Repository navigation
Incremental turns: pull receipt for hosts without a response seam + opencode v1 wired (#3352) - #3481
Merged
ranxianglei merged 1 commit intoOct 17, 2026
Conversation
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
merged commit Oct 17, 2026
3736aad
into
2026-10-16_fix-incr-ack-url-keying
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.
This was referenced Oct 17, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two gaps in the incremental-turn feature (#3248 phase 2), both opencode-shaped but one of them protocol-level:
http.requesthook 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.beforeSendslot 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'swireHash, 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:noteIncrementalAckwith the stash's own wire list)nullboundary (cold rebuild) or a foreign tail → declined: one decline re-seeds via resync next turn, only a streak falls back (Incremental lane: one transient failure (5xx/409) permanently demotes the conversation to full resend; built-in recovery hook is dead code | 增量通道:一次瞬时故障(5xx/409)就把会话永久打回全量重发,内置的恢复钩子是死代码 #3369 circuit — this is not a new failure mode)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, andsinceSeq(core count) would drift fromsent(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 (
deltaWiretail — 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, sonullforces 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 keepsboundary: nullfor the same reason. Cost: one extra resync per conversation per proxy restart — acceptable.v1 wiring:
beforeSendconverts anthropic bodies in place (init.bodyswap, 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 thechat.headersstamp (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-levelmodel, so the v1 guard rejects it.sweepStalemoved 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: nullthrough a system-only turn; wire delta re-arms (21/21)origin/master(same test, same count, verified in a detached worktree):opencode-v2.test.ts3 fails (v2 setup: activates from /bili/ baseURL…,env-based activation…,#2443 acp_retrieve…) andopencode-native.test.ts1 fail (module evaluation marks the process as a native opencode host) — sandbox network class, unrelated to this changeFixes #3352