Skip to content

test(plugin-hono-server): wait for the response head instead of a fixed sleep in adapter-drain - #35638

Merged
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-35621-adapter-drain-keepalive-wait
Nov 19, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-35621-adapter-drain-keepalive-wait

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #35621

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户无感:只改了一个服务器关停流程的测试文件,产品行为前后不变。
  • 为什么做:合并队列里这条测试在机器繁忙时会误报失败,把无关的改动踢出队列;这次让它等到响应真的到了再检查。
  • 出错会怎样:最坏是这条测试在等待五秒后给出一句清楚的失败说明,不会影响任何用户;可直接撤回。
  • 要你做什么:无。

What changes

packages/plugins/plugin-hono-server/src/adapter-drain.test.ts only (test-only).

  • New helper waitForResponseHead(conn, timeoutMs = 5000) next to rawConnection / splitResponse: resolves once the connection has received a response head (through the blank line after the headers); rejects with a message naming the bytes received if the deadline passes or the connection closes first.
  • "an idle keep-alive connection is released at drain start": the fixed sleep(50) before reading the response is replaced by await waitForResponseHead(idle). The assertion is unchanged.
  • Two other cases whose sleep stood in for "wait for the bytes we assert on" use the same helper:
    • "a response that ended before close() but is still flushing to a slow reader arrives whole": the sleep(100) stays (it also gives the big response time to call end() and fill the socket buffers, which the next two assertions read), and the wait for the idle connection's head is added after it.
    • "an event stream open when the drain begins ...": sleep(100) replaced by the wait before asserting on the head.
  • Sleeps that deliberately hold a request in flight or a connection mid-headers are untouched.

No retry, no longer sleep. No changeset: the package builds from src/index.ts; after pnpm --filter @objectstack/plugin-hono-server build, waitForResponseHead has 0 hits in dist/ while the control inFlightResponses has 4, so nothing published changes (skip-changeset).

Tests

Read first: the helper waitForResponseHead (listener order: rawConnection's collector is registered first, so received() already holds the chunk when the helper checks it), then the idle keep-alive case.

Two-minute check: pnpm --filter @objectstack/plugin-hono-server exec vitest run --maxWorkers=2 src/adapter-drain.test.ts should print Tests 12 passed (12).

File run and typecheck at 7db8fd8
pnpm --filter @objectstack/plugin-hono-server exec vitest run --maxWorkers=2 src/adapter-drain.test.ts && pnpm --filter @objectstack/plugin-hono-server typecheck
 Test Files  1 passed (1)
      Tests  12 passed (12)
check:test-typecheck: OK — @objectstack/plugin-hono-server's test layer compiles under packages/plugins/plugin-hono-server/tsconfig.test.json
os-verify-lock: VERDICT command-exit 0
Loop under CPU pressure: new 50/50 green; old version reproduced 1 in 20

Pressure: 12 parallel busy loops (sh -c 'while :; do :; done', 3x the 4 CPUs of this container), started before the loop and killed by a trap at the end. Each run is a fresh pnpm exec vitest run --maxWorkers=1 src/adapter-drain.test.ts (whole file, 12 cases). The old version is the origin/main file copied in under another name for the run and removed afterwards.

  • New version (this PR): RESULT new: 50 passed, 0 failed of 50 (12 busy loops only; load average about 14.6).
  • Old version: RESULT old: 19 passed, 1 failed of 20. The failure is the reported one: FAIL ... an idle keep-alive connection is released at drain start / AssertionError: expected undefined to be 'keep-alive'. Honest caveat: that loop ran under the same 12 busy loops PLUS this branch's derived gate scripts running at the same time for its first part, and the one failure (run 3) fell inside that window; the new-version loop did not have the gate scripts on top. One earlier old-version run under the 12 busy loops alone passed (a script bug invalidated the rest of that first old loop, so it is not counted).

Acceptance notes

  • None.

Verification

Derived gates (dispatch-gates --commands, 52 families) at 7db8fd8
  • 50 exit 0.
  • pnpm check:dual-build-cjs-loads exit 3, pnpm check:lean-entry-closure exit 3: NOT MEASURED locally (both need the whole workspace's dist/; neither reads this test file's behaviour). CI runs them.
  • dispatch-gates --ran: 52 derived, 50 run, 2 NOT-MEASURED (from a recorded exit 3), 0 UNRUN.
  • node scripts/check-nul-bytes.mjs exit 0.

Ablation: not done; the diff changes test timing, not a behaviour a test pins. The old-version loop above is the before/after reading.


🤖 Generated with Claude Code

https://claude.ai/code/session_01L6bhgTyMahdAdhXSzgy2nt

…ed sleep in adapter-drain

The idle keep-alive case read the socket 50 ms after writing its request;
on a loaded runner the response had not arrived and the connection header
read as undefined. A bounded wait on the socket (5 s deadline, clear failure
message) replaces the sleep there and in two other cases whose sleep stood
in for waiting for bytes they assert on.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6bhgTyMahdAdhXSzgy2nt
@objectstack-fleet objectstack-fleet Bot added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

Nothing in this diff resolved to a documentable surface (no symbol, route or SDK anchor derived from 0 changed package(s)), so this run has no opinion about the docs.

What this run could not see

Coarse fallback — 0 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 5c5b54d3faecbac18a642c70139df295639b985c → packageMentionDocs.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-sales · session_01L6bhgTyMahdAdhXSzgy2nt

Landing · 2026-11-19T20:36Z · area b1-B self-review ACCEPT on head 7db8fd85 (area-lease.md 送审: 38 changed lines, test-only, Clause-②: no, no other contract face). This PR has no L2 face.

Self-review (l1-review-checklist):

  • The diff is the one file the card names, adapter-drain.test.ts. The fixed sleep(50) in "an idle keep-alive connection is released at drain start" is replaced by waitForResponseHead(idle), and the assertion is unchanged. The same wait replaces the byte-waiting sleep in the event-stream case and is added after the slow-reader case's sleep(100), which stays because it also lets the big response call end(). Sleeps that hold a request in flight are untouched.
  • The helper is bounded (5 s). It removes both listeners on every exit and rejects with the received byte count on a timeout or an early close. It reads received() after rawConnection's own collector, which was registered first.
  • There is no retry and no longer sleep, and no test was skipped. skip-changeset holds: the helper has 0 hits in the built dist/.
  • Evidence (os-dev-report 7020909248 on Flaky: plugin-hono-server adapter-drain.test.ts "an idle keep-alive connection is released at drain start" reads the socket after a fixed 50 ms sleep #35621): file run 12/12 and typecheck OK. Under 12 busy loops the new version passed 50/50. The old version reproduced the reported failure once in 20 runs. The PR states the caveat that that old run had extra load.
Probe Reading
check-governed-merges.mjs --pr 35638 NOT governed · 38 changed lines ≤ 3000
check-runs on 7db8fd8522ecb46a80c71c77fc119d5ec99427f7 58 completed: 37 success, 21 skipped, 0 failed · mergeable_state clean · K = 8 since e01b8bed

State: ready + auto-merge now; #35621 closes on merge.

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

Labels

size/s skip-changeset PR has no user-facing published change; bypasses the changeset gate tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky: plugin-hono-server adapter-drain.test.ts "an idle keep-alive connection is released at drain start" reads the socket after a fixed 50 ms sleep

2 participants