Repository navigation
fix: close the defects an eighth audit found - #9
Merged
Merged
Conversation
A shutdown review and a test-quality review of the suite turned up one robustness gap and a set of assertions that could not fail. Shutdown. A stop signal arriving before the router was ready killed the process by signal, because nothing was listening yet; `SIGTERM` on a starting container exited -15 instead of 0. `src/boot-signals.js` is now the first import of `index.js` and answers both signals with a clean exit. A response a route hijacked never reaches `onResponse`, so the drain had no idea it was still streaming: `src/http/hijacked.js` tracks those sockets, the drain counts them, and shutdown destroys what is left only after the window. Every unguarded step - the upstream agents, the session sweeper, `db.close()` - is now bounded, so a stuck one can no longer hold `process.exit` past the ceiling. The budget is one 20 s window plus a 3 s margin, which fits the 25 s stop grace both the image documentation and `docker-compose.yml` publish. Tests. Several assertions could not fail: the keep-alive case searched for a string the router writes itself, the log filter passed on an empty list, the byte counter was only type-checked, `waitForHttp` promised "below 500" and accepted anything, and the 400-not-retried case never contacted a provider. The fixture gained `STUB400`, a distinguishable keep-alive, the switches it documented but did not implement, and a modelled provider concurrency limit whose peak the capacity case now asserts. A new documentation case keeps the fixture's switch table and the dashboard's public-route list honest, and the error-code table in the README is complete. Documentation. The Docker verification command for `config.json` cannot work on a fresh container and now uses a started one; the claim about which tables the documentation lint checks is accurate; AGENTS.md carries the new files, `src/server/schemas.js` and the correct plugin count.
The shutdown case for a streamed export slept half a second and then sent SIGTERM, which is a guess: on a slower runner the signal arrived while the request was still being dispatched, the drain correctly found nothing in flight, and the case failed while the shutdown behaviour it was written for was intact. It now waits for the CSV header on the socket, so the export is provably streaming before the signal, and pauses only then. The fixture grew to 50 000 rows because 5 000 is about half a megabyte and loopback socket buffers can hold that much: the route finished writing into the kernel and ended before the signal arrived, which is the same failure from the other direction. Both slow runs pass locally: 427 of 427, twice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The eighth audit was two reviews: one of shutdown, one of the test suite. Its findings are fixed here.
Shutdown
SIGTERMon a starting container killed the process by signal (-15).src/boot-signals.jsis the first import ofindex.jsand answersSIGINT/SIGTERMwith a logged, clean exit 0. A unit case spawns a child that arms the handler and signals it.reply.hijack()route never reachesonResponse, so shutdown could not tell that an SSE stream or a CSV export was still being written.src/http/hijacked.jstracks those sockets; the drain counts them, and only after the window are they destroyed — truncation stays a last resort.upstream.close(), the session sweeper anddb.close()are now bounded (1 000 / 400 / 900 ms) and log which one did not finish. Close and drain share a single 20 s window; the hard ceiling is 23 s, inside the 25 s stop grace thatdocker/README.mdanddocker-compose.ymlboth publish.The gap that remains, stated rather than papered over: a signal arriving during ESM instantiation, before any statement of ours runs, still dies by signal. That is inherent to static imports and is not claimed as covered.
Tests that could not fail, now can
: keep-alive, which the router writes itself, so it matched with or without a forwarded comment. The fixture now writes: stub keep-aliveand the case also asserts the comment arrived during the silence.[].every(...). It now creates its own row, asserts inclusion of that row and exclusion of it under a different status.injectedByteswas only type-checked; it is now asserted to be0for a stream that carried its own[DONE]and exactlydata: [DONE]\n\nfor one that did not.null; they now require a measured success rate and p50.STUB400marker, and the case asserts the client sees the provider's own message and that the provider was contacted exactly once.waitForHttppromised "below 500" and returned true for anything; it now honours that.refused.status >= 400became an exact 404 with the documented message.max_concurrency, withinFlight/maxInFlight/saturatedcounters, and the capacity case asserts the peak never exceeded one.Documentation drift
docker/README.md: the--entrypoint stat /app/config.jsonverification cannot work on a fresh container (the entrypoint creates that file), so it uses a started one; the claim about which tablestest/unit-docs.mjschecks is now accurate; the shutdown paragraph describes truncation and the 23 s ceiling.AGENTS.md: five first-party plugins, andsrc/server/schemas.js,src/http/hijacked.js,src/boot-signals.json the repository map.web/src/pages/Keys.tsx: the public route list now matchesPUBLIC_PATHS— it was missing/statusand the preflight — and a new documentation case compares the two so it cannot drift again.README.md: the error table lists every code the product emits (invalid_credentials,unauthorized,metrics_unauthorized,internal_error,no_account_configured,metrics_token_unset), enforced by a lint.Verification
pnpm run check— 62 files, imports resolved, 14 action references pinned.pnpm run typecheck— clean.pnpm run test:web— 17 passed.pnpm run test:unit— 1 231 checks across six files (core 498, docs 158).pnpm run build— clean.SMOKE_PORT=8399 SMOKE_STUB_PORT=4499 node test/smoke.mjs— 405 of 405, 4 skipped.SMOKE_SLOW=1 SMOKE_PORT=8403 SMOKE_STUB_PORT=4503 node test/smoke.mjs— 426 of 426.Docker: no image was built for this change; nothing under
docker/changed except its documentation, which was verified against the running container commands already used in CI.