Skip to content

fix: close the defects a ninth audit found - #10

Merged
dinhdev666 merged 1 commit into
mainfrom
fix/ninth-audit-findings
Nov 24, 2026
Merged

dinhdev666 merged 1 commit into
mainfrom
fix/ninth-audit-findings

Conversation

@dinhdev666

Copy link
Copy Markdown
Owner

What was wrong

A ninth audit pass over the runtime, the fixture and the suites found four real defects and a
set of assertions that could not fail.

Shutdown could spend the whole grace period before the drain began

prober.stop() awaits the batch it has in flight, and a batch is
providers / HEALTH_PROBE_CONCURRENCY probes at HEALTH_PROBE_TIMEOUT_MS each. It was awaited
before the drain window opened: five unreachable endpoints at the tested settings is a 25 s
wait, the drain then started with nothing left to wait for, the hard timer fired at 23 s, and the
process exited 1 without ever closing the database — for a router that was not serving a
single request. maintenance.stop() had the same unbounded await.

Reproduced before the fix (five providers behind a socket that accepts and never answers, SIGTERM
with no client work):

router exited code=1 signal=null after 23.01s
[info] shutting down {"signal":"SIGTERM","grace":"20000ms"}   <- no further line

After: exit 0 in about 2 s, with the drain and shutdown complete both logged.

Every rejection log line redacted the error code

src/errors.js logged { code: thrown.code } and src/server/app.js logged the parser's raw
code. maskDeep() decides on the field name, and code is in the credential alternation
for the OAuth authorization code, so queue_full, model_not_allowed, gateway_shutting_down and
metrics_unauthorized all arrived as [REDACTED] — the one field an operator greps for when a
request fails. Those payloads carry errorCode now, which the logger's allowlist leaves readable
while ?code=… is still masked.

A malformed percent-escape never reached the error handler

find-my-way throws FST_ERR_BAD_URL during lookup, before onRequest, so setErrorHandler never
saw it. Fastify answered with its own body, no X-Request-Id and no log line, while the README
promises the envelope and the id for every response. frameworkErrors is the only seam that runs
there; it answers in the project's envelope, stamps the id and logs the framework code.

/%zz9 -> HTTP/1.1 400 | x-request-id=rt-mwuehjz8084aiq
          {"error":{"message":"the request URL is not valid","type":"invalid_request_error","code":"invalid_request"}}
[warn] a request was rejected before it reached a route {"requestId":"rt-…","errorCode":"FST_ERR_BAD_URL"}

Assertions that could not fail

  • Twenty-two SMOKE_SLOW checks were never registered: one skip per section, and two sections
    emitted their heading inside the branch so their skips were tallied under the previous one. The
    summary claimed "4 skipped". Each check now has its own named skip and its own heading.
  • 'a model outside the last sync is flagged' asserted inUpstream === true, the opposite of its
    name. Invariant 10's other half is now asserted: a catalogue that shrinks keeps the vanished model
    and flags it inUpstream === false.
  • The status-sort assertion passed whether ORDER BY status ran or not (the fixture was
    insertion-ordered ascending). It seeds 404, 200, 502 and asserts the exact sequence both ways.
  • start()/stop() were asserted with a literal true; runs >= 1 was already true before the
    code under test ran.
  • The /status README row passed through a || readme.includes('/status') fallback; a float
    skipped the bounds rule entirely; the event-loop check had no upper bound.
  • maskDeep aside, several checks accepted {}/null bodies (?? 0, .every() on ?? []).

The fixture invented behaviour the provider does not have

GET /v1/models/<unknown> answered 200 with a fabricated entry, STUB_QUOTA_STATUS rewrote
generic failures to 429, and STUB_STALL swallowed /health, /__stats and /__reset, so the
stalled fixture could not be started or observed at all.

Smaller ones

README.md's only /metrics example pointed at port 8080; METRICS_TOKEN and DEBUG were
refused as boot-only by PATCH /api/settings but never listed in bootOnly(), so the Settings tab
had no group that explained the refusal.

Verification

command result
pnpm run check 62 files, imports OK, no console outside the logger, 14 pinned actions
pnpm run typecheck clean
pnpm run test:web 17 passed
pnpm run build built
pnpm run test:unit 6 of 6 files (38 / 258 / 510 / 114 / 166 / 158 checks)
SMOKE_PORT=8399 SMOKE_STUB_PORT=4499 node test/smoke.mjs 430 passed, 27 skipped
SMOKE_SLOW=1 … 457 passed
node test/check-commit-messages.mjs 1 message checked, all follow the convention

Not run: no Docker image build (no Docker on this machine), and the suite was not run against the
real free-opencode-api — the stub is the contract, as designed.

A health-probe batch in flight could eat the whole stop budget. `prober.stop()`
awaits the batch it is running, which is `providers / HEALTH_PROBE_CONCURRENCY`
probes at `HEALTH_PROBE_TIMEOUT_MS` each, and it was awaited *before* the drain
window opened: five unreachable endpoints at the defaults is a 25 s wait, so the
drain started with nothing left, the hard timer fired at 23 s and the process
exited 1 without ever closing the database - for an idle router. The background
jobs now stop inside the window, bounded and concurrent with the drain.

Every rejection log line redacted the OpenAI error code. `maskDeep()` treats a
field named `code` as the OAuth authorization code, so `queue_full`,
`model_not_allowed`, `gateway_shutting_down` and `metrics_unauthorized` all
arrived as `[REDACTED]`; the payloads carry `errorCode`, which the logger's
allowlist leaves readable while `?code=...` stays masked.

A malformed percent-escape never reached the error handler. find-my-way raises
`FST_ERR_BAD_URL` during lookup, before `onRequest`, so Fastify answered with its
own body, no `X-Request-Id` and no log line, while the README promises both for
every response. A `frameworkErrors` renderer answers it in the project's
envelope, stamps the id and logs the framework code.

The test suite could not fail for several of its claims. Twenty-two slow checks
were never registered (one skip per section, and two sections were tallied under
the wrong heading); "a model outside the last sync is flagged" asserted
`inUpstream === true`; the status-sort assertion passed whether `ORDER BY` ran or
not; `start()`/`stop()` were asserted with a literal `true`; the `/status` README
row passed through an `includes()` fallback; a float skipped the bounds rule. A
provider fixture answered 200 with an invented model for any id, rewrote generic
failures with `STUB_QUOTA_STATUS`, and swallowed `/health` under `STUB_STALL`.

Also: the `/metrics` example pointed at port 8080, and `METRICS_TOKEN` and
`DEBUG` were refused as boot-only but never listed as such in Settings.
@dinhdev666
dinhdev666 merged commit 3a7dbdb into main Nov 24, 2026
6 checks passed
@dinhdev666
dinhdev666 deleted the fix/ninth-audit-findings branch November 24, 2026 08:23
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