Skip to content

[PR] fix(web): release unread changelog + blog-refresh error response bodies - #7390

Closed
ranxianglei wants to merge 3 commits into
masterfrom
2026-11-20_changelog-error-body-release
Closed

ranxianglei wants to merge 3 commits into
masterfrom
2026-11-20_changelog-error-body-release

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Summary

Fixes #7383 — changelog checks leave HTTP-error response bodies open.

src/web/changelog.ts::runCheck rejects non-2xx statuses before consuming the body, then its finally stops the idle watchdog assuming the body was fully consumed. No code cancels the unread response, so the stopped watchdog can no longer reclaim a connection whose error body never ends. Repeated failed refreshes retain unnecessary response resources until the peer or runtime closes them.

The fix releases an unused body (fire-and-forget cancel()) before stopping the watchdog, matching the existing pattern in src/server/codex-catalog-cache.ts::discard. The cancel is fire-and-forget (not awaited) so cleanup never delays the fail-soft result, and its rejection is swallowed so it cannot replace the original offline result.

Scope (one PR, same root mechanism)

This PR covers the full fetch-util #552 defect class in the web surface — same root mechanism (release an unread body before stopping the idle watchdog), managed as a sub-defect checklist:

  1. src/web/changelog.ts (the reported issue): runCheck now cancels an unread non-2xx body before stopIdleTimer.
  2. src/web/blog-refresh.ts (drive-by, identical mechanism): five fetch helpers (getJsonList, fetchPlainText, fetchApiText, fetchPlainImage, fetchApiImage) each reject or early-return a non-2xx/404/oversize response without consuming the body, then stop the watchdog in finally. A local releaseAndStop helper now cancels an unused body before stopping the watchdog at all five sites.

Relationship to the reporter's PR #7384

This PR builds on the fix proposed in the issue (Afloat16's branch 2026-11-20_release-changelog-error-bodies, commit 8e3a8faa1ae). That commit is included in this PR's history, so the reporter's authorship is preserved. This PR adds:

  • The rationale comment the original fix omitted (why the cancel must precede stopIdleTimer — a stopped watchdog can no longer reclaim the still-open connection).
  • The blog-refresh.ts extension (the same defect class the original fix did not cover).

PR #7384 (the reporter's original fix) is a strict subset of this PR. To avoid a merge conflict, #7384 should be closed once this PR merges (owner's call).

Validation

  • 42/42 targeted tests pass (14 changelog + 28 blog-refresh), including the reporter's 5 regression tests (429/503 cancel, real-socket close, success-no-cancel, failed-cancellation, tee-sibling-open) plus a new blog-refresh 429 test.
  • npm run typecheck clean, npm run build clean, npm run check:unused-exports clean, npm run check:test-import-graph ok.
  • Full-suite verdict comes from remote CI on the pushed head.

Config surface

Not applicable — no config fields, env vars, or CLI flags added or changed.

Afloat16 and others added 3 commits November 20, 2026 16:46
… watchdog stops

The body-release fix cancels an unread non-2xx response before stopping the
idle watchdog. Restore the rationale comment so the next reader sees why the
cancel must happen before stopIdleTimer (fetch-util #552): a stopped watchdog
can no longer reclaim a still-open connection, and the cancel is fire-and-
forget so cleanup never delays the fail-soft result.
Same fetch-util #552 defect as the changelog fix: blog-refresh's five fetch
helpers (getJsonList, fetchPlainText, fetchApiText, fetchPlainImage,
fetchApiImage) reject or early-return a non-2xx/404/oversize response without
consuming the body, then stop the idle watchdog in finally. The stopped
watchdog can no longer reclaim the still-open connection. Add a local
releaseAndStop helper that cancels an unused body (fire-and-forget) before
stopping the watchdog, and use it at all five sites. Regression test pins a
429 listing response whose unread body must be cancelled.
@ranxianglei ranxianglei added bug Something isn't working p2 scope/ui labels Nov 20, 2026
@ranxianglei ranxianglei changed the title fix(web): release unread changelog + blog-refresh error response bodies [PR] fix(web): release unread changelog + blog-refresh error response bodies Nov 20, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Reviewed PR #7390 (fix(web): release unread changelog + blog-refresh error response bodies).

What I verified (independently, not from the PR description):

  • Read the full diff (2 source + 2 test files) and traced the root cause against fetchWithTimeout (src/fetch-util.ts) and the reference discard pattern (src/server/codex-catalog-cache.ts:232).
  • Confirmed the PR covers all 6 web-surface fetch sites (1 in changelog.ts, 5 in blog-refresh.ts) — src/web/ has no other fetchWithTimeout callers, so the "full web-surface defect class" scope claim is accurate.
  • Ran the 42 targeted tests on the PR head: all pass.
  • Reverted the two source files to master and re-ran: the 6 new regression tests fail (teeth confirmed) while the 1 negative test (success → no cancel) still passes, exactly as designed.
  • Checked the non-web call sites with the same helper (admin.ts HEAD probe — no body; reasoning-guard.ts — actively streams the body to the client) — neither has this defect, so scoping to the web surface is correct, not a partial patch.

Code review:

  • The fix is minimal and correct: cancel the unread non-2xx body (fire-and-forget, rejection swallowed) before stopping the idle watchdog. Matches the existing discard pattern; the bodyUsed guard is a small, safe refinement over discard's unconditional cancel (avoids a redundant no-op cancel on already-consumed bodies).
  • releaseAndStop is well-named, documented, single-responsibility; no as any / @ts-ignore / console.error; no new dependencies.
  • Tests are real, not tautologies: positive (429/503 cancel), negative (success no-cancel), real-socket close (the strongest — proves the transport is actually released, not just a callback count), failed-cancellation (a throwing cancel() cannot replace the offline result), and tee-branch (cleanup doesn't wait on a sibling consumer).
  • External contribution handled correctly: Afloat16's original commit 8e3a8faa1ae is preserved in the PR history with its authorship; this PR only adds the rationale comment + the blog-refresh.ts extension. This is a superset, not a replace.

CI (live): 4 checks green (static-gates, kernel-guard, lane-guard, +1), 15 skipped (diff doesn't touch those lanes), 11 test shards still in_progress, 0 failed so far. Full-suite verdict pending.

Notes:


结构化八问

  1. 是什么问题:changelog / blog-refresh 的 web 抓取收到非 2xx 错误响应时,先抛错/早退、没有消费响应体,finally 里就停了 idle watchdog;被拒的响应体从未被 cancel,停掉的 watchdog 再也回收不了那条「错误体永不结束」的连接,反复失败刷新会滞留无用的响应资源。
  2. 什么原因导致的:fetchWithTimeout 的 billion-context: 400 Bad Request when codex sends role: "developer" messages — request a request-body compat transform hook #552 契约要求调用方在 body 消费完(或出错)后停 watchdog;但错误路径在消费 body 之前就抛错,finally 却按「已消费完」的假设停了 watchdog,中间缺了「释放未读 body」这一步。
  3. 影响范围与严重程度:仅 web 面(changelog + blog-refresh 共 6 个抓取点);触发条件是上游返回非 2xx 且错误体不结束(429/503 限流、慢速滴漏体)。对用户可见功能无影响(fail-soft 的 offline 结果和最后一条 good release 本来就正确);严重度 = 连接/响应体资源滞留到对端或 runtime 关闭,p2 级资源/体验瑕疵,非可用性缺陷。
  4. 怎么修复的:停 watchdog 之前,若 body 未消费(!bodyUsed)就 fire-and-forget cancel()(rejection 吞掉——不延迟 fail-soft 结果、不替换原始 offline 结果)。blog-refresh 抽 releaseAndStop 局部 helper 统一 5 个站点;changelog 单点内联。与既有 codex-catalog-cache.ts::discard 模式一致。
  5. 是否有回归问题:无。成功路径 body 已消费(bodyUsed 为真)→ 不 cancel,行为不变;错误路径新增的只是「释放未读 body」的清理,fail-soft 语义(返回缓存视图 + error:"offline")未动;无阈值/时序/输出格式漂移;无 fail-fast 变吞错(吞的是 cancel 自身的 rejection,不是原始错误)。
  6. 是否破坏缓存:不涉及。changelog 内存缓存(state.releases / lastCheckAt / throttle)与 blog-refresh feed 缓存逻辑均未改动。
  7. 是否改了设计方向:不涉及。仅在调用点补齐 billion-context: 400 Bad Request when codex sends role: "developer" messages — request a request-body compat transform hook #552 契约缺失的「释放未读 body」一步,未改 fetch-util 或任何架构/数据流。
  8. 是否引入了新的配置:不涉及。无新 env / config / 默认值。

判定:可合(pending CI 全量绿)。 修法正确且最小、有真实回归测试兜底、外部贡献者署名保留、无回归。等 11 个 test shard 跑完确认全绿即可合;#7384 的关闭由 owner 定夺。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Closing as superseded — re-checked against current master and both halves are already in.

So this PR adds no functional change to master — only a 4-line rationale comment and a 429 body-cancel regression test that overlaps existing coverage. Rather than land a redundant change, closing. If you'd like those two bits kept, reopen (or I can cherry-pick just the comment + test).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p2 scope/ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changelog checks leave HTTP-error response bodies open

2 participants