Skip to content

[PR] fix: blog panel P3 polish (content-length precheck, refresh gate, 1h cache TTL, offline wording) - #4972

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-27_blog-p3-polish
Oct 27, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-27_blog-p3-polish

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

"## What\n\nFour small defects from the #4908 deep review's blog-route P3 batch (#4957 audit trail), fixed in one pass. All user-visible severity is P3 (polish), no behavior change on the happy path.\n\n## Changes\n\n### 1. Content-length precheck before body read — src/web/blog-refresh.ts\ngetText / getImage now check a declared content-length header against their size budgets (512KB text / 2MB image) BEFORE reading the body:\n\n- text direction: oversize declaration → round fails soft (feed.error = offline), body never downloaded;\n- image direction: oversize declaration → image silently dropped from the article (same churn as a 404), body never downloaded;\n- the header is a hint: post-read checks stay the authority when the header is absent or lies small.\n\n### 2. Rejection-immune settle gate for fire-and-forget rounds — src/web/blog-refresh.ts\nkickBlogRefresh / runBlogRefreshRound (TTL + coalesce launchers) now wrap the round promise in settleRoundImmune — a rejection inside a background round clears inflight/roundAt and is swallowed, instead of leaking an unhandledRejection that kills the host process (Node default behavior).\n\n### 3. Blog cache goes stale after ~1h — src/web/client.ts\nThe panel's blog cache kept its ONE fetch for the whole tab lifetime while bl.sub promises "约 1 小时一次" turnover. The cache now carries a timestamp (blogCacheStale, inlined into the IIFE); a stale hit still paints instantly, re-pulls silently in the background, and re-renders only if the blog view is still on screen (busy-flag prevents refresh loops).\n\n### 4. Neutral offline wording — src/web/i18n.ts\nbl.offline no longer claims "GitHub 暂时不可达" (the server cannot know that — the pull may have failed for size/shape reasons). Now: "上次拉取未完成,显示的是缓存内容" / "Last refresh did not finish — showing cached content" (en+zh).\n\n## Tests\n\ntests/web-blog-refresh.test.ts +4 (21 total, all green):\n\n- body-spy proves the precheck trips before arrayBuffer() for both text and image directions; lying-small header still fails soft via the post-read authority;\n- process-level unhandledRejection listener proves the settle gate swallows a rejecting base and settles exactly once;\n- TTL boundary: fresh at 1h−1ms, stale at exactly 1h;\n- wording pins (en+zh).\n\nPre-fix reproduction: with src/web reverted, the suite fails (does not provide an export named 'blogCacheStale' + body-spy assertions).\n\n## Verification\n\n- node --import tsx --test tests/web-blog-refresh.test.ts → 21/21\n- tests/web-blog-route.test.ts + tests/web-i18n.test.ts + tests/web-routing.test.ts → 36/36\n- npm run typecheck clean\n\n## config surface / scope\n\nNone — no config keys, no persistence, no wire protocol; single-module scoped (web panel + blog refresh).\n\nReview thread: https://github.com/ranxianglei/billion-context/pull/4908\nRefs #4957\n"

…sh gate, 1h cache TTL, neutral offline wording

Four small defects from the #4906/#4908 deep review (P3 batch):

- web/blog-refresh.ts: getText/getImage now precheck a declared
  content-length header against their size budgets BEFORE reading the
  body, so a hostile/lying header cannot force a 512KB text or 2MB
  image download (the post-read checks stay as the authority when the
  header is absent or lies small).
- web/blog-refresh.ts: the fire-and-forget launchers (kickBlogRefresh,
  runBlogRefreshRound) wrap their round promise in a rejection-immune
  settle gate (settleRoundImmune) — an unexpected rejection inside a
  background TTL/coalesce round can no longer leak an
  unhandledRejection and kill the host process.
- web/client.ts: the blog view cache now carries a timestamp and goes
  stale after ~1h (matching the bl.sub promise of hourly turnover);
  a stale hit still paints instantly and re-pulls silently in the
  background, re-rendering only if the blog view is still on screen.
- web/i18n.ts: bl.offline no longer claims 'GitHub unreachable' — the
  server cannot know that; it now says the last refresh did not
  finish and cached content is shown (en+zh).

Tests: tests/web-blog-refresh.test.ts pins all four (body-spy proves
the precheck trips before arrayBuffer(); process-level unhandledRejection
listener proves the gate swallows a rejecting base; TTL boundary at
exactly 1h; wording pins en+zh).

Refs #4957 (blog route audit trail); review thread:
#4908
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-27_blog-p3-polish (9d474be)

Latest build — install this exact version

npm install -g billion-context@0.0.6486-pr.4972.7dd5dc6

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
9d474be billion-context@0.0.6486-pr.4972.7dd5dc6 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr4972.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: blog panel P3 polish (content-length precheck, refresh gate, 1h cache TTL, offline wording) [PR] fix: blog panel P3 polish (content-length precheck, refresh gate, 1h cache TTL, offline wording) Oct 27, 2026
@ranxianglei
ranxianglei merged commit b33052a into master Oct 27, 2026
46 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.883-master.b33052a (rolling master tag).

npm install -g billion-context@0.0.883-master.b33052a  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

ranxianglei pushed a commit that referenced this pull request Oct 27, 2026
Follow-up merge after master advanced past c499b14 mid-resolution (#4969/#4970/#4972/#4971 blog+billing, #4544 event-loop-yield, #4678 mysql-v8-dedup, #4782 dsh-goal-subfork). Conflicts:
- src/server/prepare-responses.ts: import hunk unioned again - kept this branch's fold-reconcile import line (superset of master's: adds noteBiliToolSurface/outboundBiliSurface); master's yieldToEventLoop lines from #4528 landed in all four prepare files untouched.
- tests/golden/storage-render/{anthropic,chat,google,responses}.json: regenerated from the merged tree via scripts/update-storage-render-goldens.ts; output byte-identical to the previous round's regeneration (master's new commits did not change these golden conversations' outbound wire or persisted state) and differing from master only by this branch's image-rescale armed-state latch digests.
Verification: no conflict markers remain; targeted suites green (golden-storage-render + fold-reconcile + issue3400-image-rescale = 109/109); typecheck clean. Full-suite verdict deferred to CI on the pushed head.
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