Skip to content

[PR] fix: preserve cancellation across native Request reconstruction - #6556

Merged
ranxianglei merged 14 commits into
ranxianglei:masterfrom
Afloat16:2026-11-13_preserve-native-request-cancellation
Nov 14, 2026
Merged

ranxianglei merged 14 commits into
ranxianglei:masterfrom
Afloat16:2026-11-13_preserve-native-request-cancellation

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6555

Problem

Native interception stamps headers and replaces incremental/restored request bodies by constructing a new Request from selected fields. The caller's signal is omitted, so cancelling a generation stops controlling the actual outbound request. This affects spawned transport as well as requests entering the inline engine.

Changes

Preserve the original Request signal when stamping headers, replacing payloads, restoring full bodies and rebuilding a streamed target after the ordinary constructor fails. Explicit init.signal replacements and null overrides keep their existing fetch precedence.

Validation

  • On unchanged master e1f31ad9d5b47500362699a9867819b861c7de96, the 12-case regression suite reports 8 failures and 4 passing controls.
  • After the change, all 128 tests pass across native-request-signal, native-intercept and issue3304-incremental-direct-send. The new suite exercises real loopback HTTP on rewrite/routed/self paths, pre-aborted and later-aborted signals, incremental/restored payloads, streamed-target fallback, and explicit signal/null controls.
  • Root typecheck, complete bundle build, unused-export gate, test-import-graph gate and git diff --check pass.
  • Full hosted CI and real-model E2E are not claimed from these local results.

Related history and scope

The maintainer review of #6504 identifies the header-stamping defect. That PR changes the inline dispatcher's signal lookup; this patch preserves the signal before it reaches any transport. Checked all 71 Afloat16 PRs, open PR metadata and all-state searches for withHeaders, Request signals and cancellation. No existing native-constructor fix was found.

The change preserves body bytes, plugin headers, request routing and compression behavior. It introduces no configuration, persistence or kernel change.

Remote CI follow-up (2026-11-13)

CI run 43456733438 is failed, not green. I inspected every failed test job: Ubuntu Node 22/24 report the two notice-registry.test.ts assertions for the sqlite-default notice; Windows Node 22 additionally reports EBUSY while deleting index.db in persist-zstd.test.ts and persist-metadata-fold-gate.test.ts teardown. None of the changed files owns those paths. On the unchanged base e1f31ad9d5b47500362699a9867819b861c7de96, running the notice suite with the exact CI preload chain reproduces 3 passed / 2 failed (without the legacy-storage preload it is 5 passed / 0 failed).

Existing upstream PR #6561 / issue #6547 covers these same storage-baseline and Windows-handle failures. This PR keeps its focused product change separate; its full CI verdict remains failed until the upstream test fixes land and the head is rechecked. Windows reproduction here is limited to the remote job logs.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Duplicate screening (查重): not a duplicate. PR #6556 is the only open PR touching src/agent/native-intercept.ts. The sibling PRs by the same author cover different files/layers: #6560 / #6565 / #6566 touch src/agent/pi-inline.ts (pi-inline fallback), #6571 / #6502 / #6504 touch src/inline-engine.ts (inline engine). Same theme (cancellation / Request reconstruction) but a distinct file and mechanism — the native fetch-intercept Request constructors. Not a duplicate; no hot-file contention on native-intercept.ts.

I reviewed the diff independently against the code and ran the tests both ways rather than taking the local-pass claim at face value.

The fix is correct and complete. I verified the signal-linking semantics empirically on Node 22:

  • The two object-form reconstructions — replaceRequestTarget happy path (src/agent/native-intercept.ts:1439) and makeTarget (:1644), both new Request(url, existingRequest) — link the signal (aborting the source aborts the clone with the identical reason). Correctly left untouched.
  • The four field-form reconstructions mint a fresh, never-aborted signal when signal is omitted — I reproduced this (aborted source → clone stays un-aborted). All four are now patched: withHeaders (:433), replaceRequestTarget streamed-body fallback (:1455), replaceRequestPayload (:1473), withRestoredBody try (:1491) + catch (:1498).
  • I enumerated every new Request( in the file (6 real sites + 1 comment) — no field-based reconstruction was missed.

init.signal precedence is preserved. In withRestoredBody, an explicit init.signal — including a null override — still wins over the base request's signal (verified: original aborted, effective request stays un-aborted). The catch path's init?.signal !== undefined ? init.signal : input.signal matches fetch semantics.

The tests have teeth. Ran the new suite both directions:

  • Unpatched base (e1f31ad9d5): 8 fail / 4 pass — exactly the PR's claimed baseline. The 4 passing controls are the two object-form target cases and the two init.signal override cases (already correct pre-fix).
  • Fix: 12/12 pass.
    The 3 lane cases drive a real loopback HTTP server (rewrite / routed / self), abort only after the server has received the request, and assert the caller's abort rejects the actual request with the caller's reason. Ports use listen(0).

Base & hygiene. The PR sits on the current master (e1f31ad9d5 = origin/master); native-intercept.ts is byte-identical to master, so no rebase and no hot-file contention. Diff is clean: 2 files, +128/−6, every line on-purpose. No config, persistence, kernel, or wire-message-shape change — the signal is a transport control channel; request bytes are untouched.

CI status (verified live). The PR head's 4 failing test shards (ubuntu 22/24 shard 3, windows 22 shard 3/5) are the inherited master failures from #6547 (notice-registry inherits the legacy storage pin; persist-* suites hold index.db past rmrf on Windows). The open #6561 touches exactly those 3 failing test files, so it is the fix. The new native-request-signal.test.ts is not among the failures (passes 12/12 locally). The red is not this PR's fault; it is blocked on #6561 landing.


结构化八问

  1. 是什么问题:native fetch 拦截器在盖插件头、替换增量/恢复 body、重定向 target(含流式 body 兜底)时,用 url/method/headers/body 逐字段重建 Request,漏拷调用方的 AbortSignal,导致重建后的 Request 挂了一个全新的、永不 abort 的 signal——调用方取消生成后,实际出站请求仍会跑完。
  2. 什么原因导致的:四处「逐字段重建」的 new Request(url, {method, headers, body, …}) 没带 signal,产出未链接的新 signal(实测:源 abort 后克隆不 abort);而两处「对象重建」new Request(url, existingRequest) 本身会链接 signal(实测 abort 带同一 reason 传导),故不受影响。根因是逐字段重建丢失了取消信道,不是 signal 机制本身有缺陷。
  3. 影响范围与严重程度:覆盖 native 三条路由(rewrite / 已路由 /bili/ / 直连 self)上所有走盖头、增量 payload、恢复 body、流式 target 兜底的路径,同时影响 spawn transport 与进 inline engine 的请求。严重度:取消后请求不被取消、继续消耗上游算力/成本且取消被静默忽略——可用但有明显问题,定 p2 合理(非缓存泄露类,不升 p1)。
  4. 怎么修复的:在四处逐字段重建处补 signal: <原>.signal 把原 signal 带过去;withRestoredBody 的 catch 分支按 init?.signal !== undefined ? init.signal : input.signal 保留 fetch 的 init.signal 覆盖优先级(含 null)。两处对象重建不动(已自动链接)。
  5. 是否有回归问题:无。唯一行为变化就是「signal 现在被保留」——正是修复目标;实测基线上 4 个对照(对象重建 target ×2、init.signal 覆盖 ×2)在修复前后都通过,证明这些路径行为未变。body 字节、插件头、路由、压缩行为都不变;init.signal 覆盖(含 null)实测仍按 fetch 语义生效。
  6. 是否破坏缓存:不涉及。signal 是传输层控制信道,不属于被缓存的消息内容;不影响缓存/重试/增量游标/去重键。
  7. 是否改了设计方向:不涉及。是 native-intercept 模块内的传输层修复,无架构/边界/数据流转向。
  8. 是否引入了新的配置:不涉及。无新 env/config/默认值。

判定:修复正确、完整、测试有牙(基线 8 红 / 修复后 12 绿,双向实测)、diff 干净、基于当前 master、无热文件冲突。代码层面满足 auto-merge 门禁各项,唯一未满足的是 CI 绿——而 CI 红是继承性失败(#6547,由在途 #6561 修复,非本 PR 引入)。代码可合;合并动作按规则由人工执行。CI 转绿路径:等 #6561 合入后重跑即可(或确认 ci-fixes 已含该修复后 merge 进本分支)。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 进度汇报:评审已完成,无阻塞。

刚才那段时间不是卡死,是在做本地定向验证(npm install 装 tsx + 构建 in-repo kernel + 双向跑新测试套件),属正常的长耗时操作。完整评审(含结构化八问)已发在本线程上方。

结论一句话:代码可合——修复正确、完整、测试有牙(基线 8 红 / 修复后 12 绿,双向实测)、diff 干净、基于当前 master、无热文件冲突。唯一未满足的 auto-merge 门禁是 CI 绿,而 CI 红是继承性失败(#6547,由在途 #6561 修复,非本 PR 引入)。合并动作按规则由人工执行;CI 转绿路径 = 等 #6561 合入后重跑。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 最终状态(live 复核线程后确认,评审已完成):

  • 完整评审已在本线程上方(4793 字那条:独立验证 + 结构化八问 + 判定)。
  • 新进展:CI 工程师(ci-engineer-r1)已接管这 4 个继承性 CI 失败(ubuntu 22/24 shard3、windows 22 shard3/5,即 [bug][tests] #6480 makes two legacy-envelope suites red on every shard: notice-registry inherits the legacy pin, persist suites hold index.db past rmrf #6547 的 notice-registry 继承 legacy pin + persist-* 套件在 Windows 上 rmrf 后仍持有 index.db)。转绿由 CI 工程师负责——非本 PR 引入,也非我的职责。
  • 判定不变:代码可合。修复正确、完整、测试有牙(基线 8 红 / 修复后 12 绿,双向实测)、diff 干净、基于当前 master、无热文件冲突。唯一未满足的 auto-merge 门禁是 CI 绿,现由 CI 工程师处理中。
  • 边界:我未改源 issue/PR 的标签或标题(规则禁止),未 push 到外部 PR 分支,未开新 issue(无待决策项)。

合并动作按规则由人工执行;CI 转绿后本 PR 即满足全部门禁。

The suite baseline preload (preload-storage-baseline.mjs) pins
BILI_STORAGE_UNIFIED="legacy" for the broad corpus. After ranxianglei#6480 flipped the
storage default to pure-sqlite, the notice-registry suite's visibleNotices
assertions expect the pure-sqlite default notice, which is gated on
unifiedSelectionIsSqlite (unified "sqlite" or absent) — the preload's
"legacy" made the notice silent, so the suite was born-red on master. Pin
the selection explicitly (ranxianglei#4011 lesson: a test that depends on the production
default passes locally but fails in CI).
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

CI diagnosis: the PR is innocent — all 4 red shards are inherited from master, not caused by this PR's diff.

I re-verified the live check state (still red on head e3b2a8122c) and pulled the failing-shard logs. The PR touches only src/agent/native-intercept.ts (adds signal: to the native Request reconstruction) + a new tests/native-request-signal.test.ts. None of the failing tests are in that diff, and the PR's own new suite passes in CI.

Root cause (confirmed by local A/B repro):

  1. notice-registry born-red (ubuntu 22/24 shard 3 + windows 22 shard 5): tests/notice-registry.test.ts 2 visibleNotices cases expect the storage-sqlite-default notice, gated on unifiedSelectionIsSqlite (src/knobs.ts:1038). The suite baseline preload (tests/preload-storage-baseline.mjs:19) pins BILI_STORAGE_UNIFIED="legacy", so the notice is hidden in CI but visible locally (no preload) — the exact [PR] fix: make full-mode storage tests deterministic (#4004) #4011 lesson the preload comment warns about. Introduced by [PR] storage: pure-SQLite default — JSON envelopes stop being written unless dual-write is requested (#6479) #6480 (pure-SQLite default, 5a80e2b8ea, 2026-11-13). Reproduced locally: with the official preload → 2 red; without → 5/5 green.
  2. Windows EBUSY file-lock flake (windows 22 shard 3): persist-metadata-fold-gate (Scheduled full test failed: ee0dcc7c | 定时全量测试失败: ee0dcc7c #5506) + persist-zstd fail with EBUSY: resource busy or locked, unlink …index.db (rimraf teardown vs. SQLite handle). Environmental flake (windows-22-1 lane randomly red: during test cleanup, unlink index.db hit an EBUSY external lock, couldn't survive tmp-rm | windows-22-1 车道随机红:测试清理期 unlink index.db 遇 EBUSY 外部锁,熬不过 tmp-rm 的 9.6 秒重试梯子(#2799/#2908 族复发) #4347 family); re-run clears it.

The fix is already converged in ci-fixes — sentinel commit c6369fb6a1 ("fix(tests): pin pure-sqlite selection in notice-registry suite", pins BILI_STORAGE_UNIFIED="sqlite" in the test, verified 5/5 both regimes).

Blocker — I cannot push to this PR's branch. The head lives in the external fork Afloat16/billion-context; git push returns permission denied (the sentinel hit the same wall, #4599 floor 1323). I merged ci-fixes locally (merge ef5f137cc2) but could not push it.

Action needed from the PR author (one command set, then CI re-runs green):

git fetch origin ci-fixes
git merge origin/ci-fixes
git push

The notice-registry failures clear from the ci-fixes pin; the Windows EBUSY flake clears on re-run.


八问(中文):

  1. 是什么问题:PR 的 CI 红不是 PR 代码问题,是继承自 master 的 born-red(notice-registry 套件断言 pure-sqlite 默认公告可见,但套件基线 preload 把存储模式钉成 legacy,公告静默,断言失败)+ Windows EBUSY 文件锁 flake。
  2. 什么原因导致的:[PR] storage: pure-SQLite default — JSON envelopes stop being written unless dual-write is requested (#6479) #6480(pure-SQLite default)翻转存储默认后,notice-registry 套件没钉 BILI_STORAGE_UNIFIED,依赖了套件基线 preload 的 legacy 钉值([PR] fix: make full-mode storage tests deterministic (#4004) #4011 教训:依赖生产默认值的测试本地过、CI 挂);Windows EBUSY 是文件锁 flake(windows-22-1 lane randomly red: during test cleanup, unlink index.db hit an EBUSY external lock, couldn't survive tmp-rm | windows-22-1 车道随机红:测试清理期 unlink index.db 遇 EBUSY 外部锁,熬不过 tmp-rm 的 9.6 秒重试梯子(#2799/#2908 族复发) #4347 家族)。
  3. 影响范围与严重程度:所有基于 master 的 PR 的 CI 都红(继承红);功能无影响(只是测试断言与生产默认值漂移)。
  4. 怎么修复的:修复已在 ci-fixes(c6369fb6a1,哨兵收敛):在 notice-registry 套件里显式钉 BILI_STORAGE_UNIFIED="sqlite"。本 PR 分支在外部 fork,本 agent 无推送权限(permission denied),需 PR 作者手动 merge origin/ci-fixes。
  5. 是否有回归问题:无。修复只改测试钉值,不改生产代码;Windows flake 是既有 flake,重跑即绿。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及(只是测试钉值,不是新配置)。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI fix run summary (attempt 1/3)

Diagnosis: All 4 red shards are inherited from master, not caused by this PR's diff.

Fix: Already converged in ci-fixes — sentinel commit c6369fb6a1 (pins BILI_STORAGE_UNIFIED="sqlite" in the test, verified 5/5 both regimes).

Blocker: I merged ci-fixes locally (merge ef5f137cc2) but git push to the external fork Afloat16/billion-context returns permission denied (same wall the sentinel hit, #4599 floor 1323). I cannot push to the PR branch.

Action needed from PR author:

git fetch origin ci-fixes
git merge origin/ci-fixes
git push

Verified: Root cause confirmed by local A/B repro (with preload → 2 red; without → 5/5 green). Fix verified by sentinel (5/5 both regimes).
Remains: PR author must manually merge ci-fixes (external-fork push refused for this agent).
Risk: None — the fix is in ci-fixes and verified; the PR's own diff is innocent.

ework-agent and others added 11 commits November 14, 2026 10:20
…test

The dsh plugin lane (ci-e2e-dsh.yml) runs node --import tsx --test
WITHOUT the preload-storage-baseline.mjs preload, so BILI_STORAGE_UNIFIED
is unset and the storage mode defaults to 'full'. Under the pure-sqlite
default flip (5a80e2b, ranxianglei#6480), 'full' mode turns the JSON envelope
writer OFF — so the .content-store.json sidecar is never written, and
the test's readdirSync(namespace) hits ENOENT.

Pin BILI_STORAGE_JSON_WRITER=on in the test so the content-store
sidecar is written regardless of the storage mode. This keeps the
corrupted-store detection path exercised in both full and legacy modes.

Closes: dsh plugin lane red on master (run 43532980164, job 132255459726)
The pure-sqlite default flip (5a80e2b, ranxianglei#6480) turns the JSON envelope
writer OFF, so the .json session file this lane asserts on is never
written and 'proxy must persist the session' / 'no persisted session
carried compressed blocks' fail after the 20s wait. Pin the writer ON in
the spawned client's env (the bootstrapped proxy inherits it) so the
envelope this test was written for is still produced.

Closes: native opencode lane red on master (run 43547593803, job 132302438610)
Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) as the opencode lane:
the JSON envelope writer is OFF, so 'proxy must persist the session
within 20000ms' fails — the on-disk .json session file is never written.
Pin the writer ON in the spawned dsh client's env (the bootstrapped
proxy inherits it).

Closes: native dsh lane red on master (run 43547497015, job 132302138843)
…e2e lane

Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) as the opencode/dsh
lanes: the JSON envelope writer is OFF, so 'session persisted' fails —
the on-disk .json session file is never written. Pin the writer ON in
the spawned pi client's env (the bootstrapped proxy inherits it).

Closes: pi codex-responses WS lane red on master (run 43547626291, job 132302540960)
…lane

4th lane of the pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the
JSON envelope writer is OFF, so 'proxy must persist the session' and
'at least one persisted session must carry compressed blocks' fail — the
on-disk .json session file is never written. Pin the writer ON in the
spawned pi client's env (the bootstrapped proxy inherits it).

Closes: pi package-native lane red on ci-fixes (run 43558179054, job 132336647955)
Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON writer
is OFF, so the per-session CCR content-store sidecar (.content-store.json)
that 'child persists its own companion and survives a proxy restart'
asserts on is never written (0 !== 1). The earlier b1bc17b pin only
covered tests/plugin-fork.test.ts, not this file. Pin the writer ON at
module load (before any SessionStore is constructed).

Closes: dsh plugin lane red on ci-fixes (run 43558179102, job 132336519539)
…lane

Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope
writer is OFF, so 'proxy must persist the session' fails — the on-disk
.json session file is never written. Pin the writer ON in the spawned
opencode client's env (the bootstrapped proxy inherits it).
Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope
writer is OFF, so the on-disk .json session envelope this lane asserts on
(exactly ONE persisted session under the raw key) is never written. Pin
the writer ON in the spawned dsh client's env.
Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope
writer is OFF, so the on-disk .json session file this lane asserts on
(state survival across the OLD→NEW update) is never written. Pin the
writer ON in the spawned proxy's env (both update phases share envBase).
Afloat16 added a commit to Afloat16/billion-context that referenced this pull request Nov 14, 2026
@Afloat16

Copy link
Copy Markdown
Contributor Author

Current head e49d4b73fc1cbdfa362ffcf916696dfc3ec2c5f9 now contains upstream master 1ff89e878522f3e4d4147067973e2dc26e648923 and the requested ci-fixes snapshot 1ca40871581c5009fdb69eea944f448d002098e7. The two feature files are byte-for-byte unchanged from e3b2a8122c40d7d44a2725530f3977fc6833f939.

I verified this exact head on Linux / Node 24.22.1: 27 tests passed, 0 failed, 0 skipped — 12 native cancellation cases, 8 adjacent inline cases, 5 notice-registry cases, and the 2 upstream in-place-update regressions. The repository's storage/test-environment/zone preloads were used; its existing registry-fetch test seam kept the optional catalog refresh offline, while the loopback HTTP fixtures ran normally. Exact-head manifest and test log.

The fresh upstream CI run is still pending. This local result does not establish a Windows or full-matrix pass; the Windows handle-teardown work in #6561 remains open.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Verified the new head e49d4b73fc — ci-fixes is in, feature files unchanged.

I fetched the new head from the fork and confirmed:

  • ✅ ci-fixes (c6369fb6a1) is an ancestor of the new head
  • ✅ master (e1f31ad9d5) is an ancestor of the new head
  • ✅ src/agent/native-intercept.ts and tests/native-request-signal.test.ts are byte-for-byte unchanged from e3b2a8122c

The mirror cache is still showing the old head (e3b2a8122c) — the fresh CI run for e49d4b73fc is still pending (the poller refreshes ~60s). I'll confirm once the new run lands and the cache updates. No action needed from me in the meantime.

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ai: vllm-qwen/qwen3.8-27b)

APPROVE — independently re-verified (direct Node probes + both-direction test runs), not taken from the thread.

Head note: the fork branch has advanced past the head this task pinned — e49d4b73f → now 3d226753 ("Merge upstream master and converge CI test fixes"). The two feature files (src/agent/native-intercept.ts, tests/native-request-signal.test.ts) are byte-identical across that range, so the verification below holds for both heads. The new commits are all master-origin (release v0.1.214, #6671, #2195, CI test pins) — a standard master/ci-fixes refresh, not new PR work. (A 9-space indent slip in e2e-native-pi.test.ts from an earlier ci-fixes pin is already corrected at the new head.)

Correctness. The four field-form Request reconstructions now carry signal: withHeaders (src/agent/native-intercept.ts:433), replaceRequestTarget streamed-body fallback (:1455), replaceRequestPayload (:1473), withRestoredBody try (:1492) + catch (:1498). I probed Node directly: the two object-form sites (:1439, :1645) already link the signal (abort propagates with the same reason), so they were correctly left untouched. I enumerated all six new Request( sites — no field-based reconstruction was missed.

init.signal precedence preserved. withRestoredBody's catch path init?.signal !== undefined ? init.signal : input.signal keeps fetch's override, including a null override (probed: original aborted → effective stays un-aborted; a replacement signal aborts with its own reason; undefined inherits the base).

Tests have teeth. tests/native-request-signal.test.ts (12 cases: 3 real-loopback lanes rewrite/routed/self — abort only after the server receives the request, assert the caller's reason rejects the actual request; 6 replacement cases pre-/later-aborted; 2 init.signal override controls; 1 streamed-body fallback). On the unfixed base: 8 fail / 4 pass (the 4 controls are the two object-form target cases + the two override cases, already correct pre-fix). With the fix: 12/12. Related suites (native-intercept, issue3304-incremental-direct-send) green (116).

Diff/scope. Feature files = the core commit. The storage-test env pins in the diff are the sanctioned ci-fixes merge (same SHAs as origin/ci-fixes) clearing the inherited master red (#6547) — not author noise. No config / persistence / wire-message-shape / kernel change; the signal is a transport control channel, request bytes untouched.


结构化八问

  1. 是什么问题:native 拦截器在盖插件头、换增量 body、恢复全量 body、重定向 target(含流式兜底)时逐字段重建 Request,漏拷调用方 AbortSignal——取消生成后实际出站请求仍跑完。
  2. 什么原因导致的:四处「逐字段重建」new Request(url,{method,headers,body,…}) 省略 signal,产出全新永不 abort 的 signal(实测源 abort 后克隆不 abort);两处「对象重建」new Request(url,req) 本身链接 signal(实测同 reason 传导)故不受影响。根因=逐字段重建丢取消信道,不是 signal 机制本身有缺陷。
  3. 影响范围与严重程度:native 三条路由(rewrite/已路由/self)上盖头、增量 payload、恢复 body、流式 target 兜底全部路径 + spawn transport + 进 inline engine 的请求。严重度:取消被静默忽略、请求继续耗上游算力/成本——可用但有明显问题,p2 合理(非缓存泄露类,不升 p1)。
  4. 怎么修复的:四处逐字段重建补 signal:<原>.signal;withRestoredBody catch 按 init?.signal !== undefined ? init.signal : input.signal 保留 fetch 的 init.signal 覆盖优先级(含 null);两处对象重建不动(已自动链接)。
  5. 是否有回归问题:无。唯一行为变化=signal 现在被保留(正是修复目标);基线 4 个对照(对象重建 target ×2、init.signal 覆盖 ×2)修复前后都过,证明这些路径行为未变;body 字节/插件头/路由/压缩行为不变;init.signal 覆盖(含 null)实测仍按 fetch 语义。
  6. 是否破坏缓存:不涉及。signal 是传输层控制信道,不进被缓存的消息内容;不影响缓存/重试/增量游标/去重键。
  7. 是否改了设计方向:不涉及。native-intercept 模块内传输层修复,无架构/边界/数据流转向。
  8. 是否引入了新的配置:不涉及。无新 env/config/默认值。

判定:修复正确、完整、测试有牙(基线 8 红 / 修复后 12 绿,双向实测)、功能文件=核心 commit、存储测试钉值来自 ci-fixes 合并(非作者噪声)、无热文件冲突、无 kernel/配置/线格式变更。代码可合;合并动作按规则由人工执行。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b) ✅ Review done — posted APPROVE on PR #6556 (independently re-verified: fix correct+complete across all 4 field-form Request reconstructions, init.signal precedence incl. null preserved, new suite 8-fail-unfixed / 12-pass-fixed, related suites green). Note: fork head advanced e49d4b73f→3d226753 (master-origin refresh; feature files byte-identical). Merge is human-only per policy.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #6556 reviewed — APPROVED (GitHub review id 5903340462)

Fix verified correct & complete. The change preserves the caller's AbortSignal across native Request reconstruction in src/agent/native-intercept.ts. All four field-form new Request(url, {method, headers, body, …}) sites now forward signal: <src>.signal; the two object-form sites (new Request(target, req)) already inherit the signal via duck-typing and were correctly left untouched. Without this, cancelling a generation stopped controlling the actual outbound request.

Verification (independent, not copied from prior thread):

  • tests/native-request-signal.test.ts both directions on Node 22: unfixed master → 8 fail / 4 pass (the 4 controls = 2 object-form + 2 init.signal override cases that were already correct); with fix → 12/12 pass.
  • Related suites (native-intercept + issue3304-incremental-direct-send): 116 pass.
  • Node probes: signal=null→fresh, undefined→inherit, real→override; object-form abort propagates with the same reason.
  • Enumerated all 6 new Request( sites — none missed.

Scope: The 8 storage-test env pins are the sanctioned ci-fixes merge (same SHAs as origin/ci-fixes), not author noise — the correct way to clear inherited master red (#6547). No kernel / config / persistence / wire-shape change.

Head note: Fork branch advanced e49d4b73fc→3d226753 (master-origin refresh; feature files byte-identical across the range). GitHub API still shows the stale head e49d4b73fc.

Merge is human-only per policy.


八问审核清单(中文)

  1. 是什么问题:native 拦截在重建 Request(盖头/换 payload/恢复 body/重建 streamed target)时只挑了 method/headers/body 等字段,漏掉了 signal——导致用户取消生成时,实际发出的出站请求不再受控制。
  2. 什么原因导致:四处 field-form 的 new Request(url, {…}) 重建没有透传 signal;对象形式 new Request(target, req) 靠 duck-typing 自动继承,所以只有 field-form 四处受影响。
  3. 影响范围与严重程度:所有走 native 拦截且用户中途取消生成的会话(spawned transport + inline engine);取消不生效 = 体验缺陷(p2),不涉及数据丢失/安全。
  4. 怎么修复的:四处 field-form 重建补上 signal: <src>.signal;withRestoredBody 的 catch 分支用 init?.signal !== undefined ? init.signal : input.signal 保留显式覆盖优先级(含 null)。
  5. 是否有回归问题:无。对象形式两处未动(本就正确);init.signal 显式覆盖(含 null)优先级保留,未改变既有语义。
  6. 是否破坏缓存:不涉及(纯 signal 透传,不影响缓存/重试/游标)。
  7. 是否改了设计方向:不涉及(单模块小修,无架构变化)。
  8. 是否引入了新的配置:不涉及。

判定:APPROVE,可合(合并按策略由人工执行)。

@ranxianglei
ranxianglei merged commit 169f5d2 into ranxianglei:master Nov 14, 2026
50 checks passed
@ranxianglei

Copy link
Copy Markdown
Owner

Superseded by #6677 (merged as 3858b6956, 2026-11-14).

Landed into master via the real merge commit 169f5d21aa2 (Merge Afloat16/2026-11-13_preserve-native-request-cancellation (PR #6556)), so your original commits are preserved verbatim in master history — only hashes of the batch wrapper changed, your authorship and commit messages are intact.

The fix for #6555 is now in master. Closing this PR as superseded — thanks for the careful, well-tested fix.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Acknowledged — PR #6556 closed as superseded by #6677 (merged as 3858b6956); the #6555 fix is now in master via merge commit 169f5d21aa2 with the original commits preserved verbatim. My APPROVE review (id 5903340462) stands on record for the fix as reviewed. Nothing further needed from the review lane.

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.

native Request rebuilding drops caller cancellation during header and body replacement

2 participants