Skip to content

fix: mechanical subset of #1064 (awaitDrain leak, codex toml block-end, session-pool reload cap, drop-only echo) - #1113

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-22_mechanical-1064
Sep 22, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-22_mechanical-1064

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Part of #1064, split from #1072 per review (#1072 (comment)).

Why split

#1072 bundles three classes of change: pure mechanical repairs, bug fixes with observable behavior shifts (retry-path abort lifetime, image-billing estimate → earlier compress triggers), and policy/hardening decisions (#13 tail-window trust threshold, #12 beta-window cap). Per the one-issue-one-scope discipline the mechanical subset is extracted here so it can merge independently; the behavioral and policy changes stay in #1072 for their own review.

What's in (4 fixes, each with a regression test that reproduces the original defect)

  1. awaitDrain listener leak (src/server/stream-io.ts): the old code registered once("drain") + once("close") + once("error") and resolved on the first fire, leaking the other two on every backpressure wait (MaxListenersExceededWarning on long streams). One shared settle removes all three. forward() now calls it instead of the inline Promise.race.
  2. codex config.toml block-end (src/plugin-install.ts): the [mcp_servers.bili] block ended at indexOf("\n["), which misses an INDENTED next-table header — the block ran to EOF and a refresh deleted everything after it (data-loss class). End detection now matches codexRemove: next table-header line, optional indent.
  3. session-pool reload cap (src/session.ts): a memory-miss disk reload inserted a new resident entry without the MAX_SESSIONS guard (the guard below only runs for new sessions) — evict-then-revisit grew the pool past the cap unboundedly. Reload now evicts first.
  4. echoReplaced drop-only (src/server.ts prepareResponses): an echoed legacy compaction item without a sentinel blob is DROPPED, nothing inserted — but the old replaced > 0 || dropped > 0 set echoReplaced anyway, suppressing the forge-time summary re-injection and silently losing the summaries. Only a real replacement (summary actually injected) suppresses re-injection now.

What stays in #1072

After this merges, #1072 should rebase and drop the duplicated hunks.

Pre-flight

…l block-end, session-pool reload cap, drop-only echo re-injection

Split from #1072 per review (issuecomment-5771332368): these four fixes are
pure mechanical repairs with no policy/behavior trade-offs, extracted so they
can merge independently of the behavioral changes that stay in #1072:

- awaitDrain one-shot shared settle (server/stream-io.ts) — removes all 3
  listeners per backpressure wait instead of leaking two; forward() call site
  now uses it
- codex config.toml block-end (plugin-install.ts) — block ends at the next
  table header (optional indent, matching codexRemove); a refresh no longer
  deletes everything after an indented table
- session pool reload cap (session.ts) — memory-miss reload evicts at
  MAX_SESSIONS before insert; evict-then-revisit can no longer grow the pool
- echoReplaced drop-only (server.ts prepareResponses) — only a real
  replacement suppresses forge-time summary re-injection; a blob-less legacy
  drop re-injects via the developer message

Gates: typecheck, full suite (0 fail), build.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-22_mechanical-1064 (aba2bff)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1113

Each push to this PR publishes a new version under the pr-1113 npm tag.

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei merged commit 14d06f1 into master Sep 22, 2026
8 checks passed
ranxianglei pushed a commit that referenced this pull request Sep 22, 2026


#1113 (merged as aba2bff) carries the four mechanical fixes — awaitDrain
listener leak, codex config.toml block-end, session-pool reload cap,
drop-only echo re-injection — byte-identical to what this branch had,
including their regression tests. Dropped those duplicated hunks here.

Retained (observable behavior/policy, for standalone review):
- stopIdleTimer lifetime split (fetch-util.ts; degenerate-retry/reasoning-guard
  callers keep client-abort coverage while dropping the idle watchdog)
- imageBillingFor threaded into all three localInputEstimate sites
- withConversationIdNote in the compress-loop system rebuild
- MAX_ANTHROPIC_BETA_WINDOW 10M clamp (#12)
- prefix-affinity w === TAIL_WINDOW trust threshold (#13 interim mitigation;
  design-level follow-up tracked in #1115)

References #1064, #1113, #1115.
@ranxianglei
ranxianglei deleted the 2026-09-22_mechanical-1064 branch October 15, 2026 05:32
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