Skip to content

fix: repair the defects a fourth audit found - #5

Merged
dinhdev666 merged 1 commit into
mainfrom
chore/fourth-audit-improvements
Nov 24, 2026
Merged

dinhdev666 merged 1 commit into
mainfrom
chore/fourth-audit-improvements

Conversation

@dinhdev666

Copy link
Copy Markdown
Owner

What this is

The fourth audit of the router, implemented: every defect, improvement and feature the report
listed, each with a test that fails without the change.

Verification

  • pnpm run check — clean
  • pnpm run typecheck — clean
  • pnpm run test:unit — 1004 checks across six files
  • pnpm run test:smoke — 344 checks
  • SMOKE_SLOW=1 pnpm run test:smoke — 348 checks
  • boot check: GET /health 200, GET /v1/models 200 without a key, a chat completion with and
    without stream: true against test/stub-provider.mjs
  • SIGINT logs [info] shutdown complete {"signal":"SIGINT"} and exits 0
  • pnpm run check:commits main..HEAD — clean

Notes

  • Migration 6 adds request_logs.extra, the transfer detail the gateway already assembled and
    the insert dropped.
  • The one proposal not implemented is the UNION ALL rewrite of the log provider filter: SQLite
    short-circuits the OR per row, so the JSON is only parsed for rows the direct branch missed.
    The reasoning is recorded in the comment at the filter instead.

Every item was reproduced or read in the code before it was changed, and each
one has a test that fails without the fix.

Gateway and engine
- a caller abort is no longer classified as a timeout, and an exhausted attempt
  budget reports 504 instead of 502 (invariant 3's "before the first byte")
- a reset or an edit mid-stream keeps the provider's in-flight count, so a
  second request cannot be admitted into a provider that is still streaming
- queue_wait_ms is assigned from the original wait rather than added per
  attempt, and a waiter that loses a slot race re-queues at the head
- RETRY_AFTER_CAP_MS = 0 means "ignore Retry-After", matching every other zero
- a 2xx with an empty body answers 502 upstream_error, never a 200 with no body
- a quoted .env value keeps its inline `#`, and persist() stops rewriting keys
  the operator never decided about
- credential-shaped names (pass, pat, key, mfa) are masked again, while
  error_code, block_code and key_prefix stay readable

Database and admin API
- a route id is digits only, so /api/logs/0x10 is 404 instead of log 16
- a model id containing `%` is neither double-decoded nor a 500
- the log range is a Map, so ?range=constructor no longer queries the whole
  retention window
- the CSV export streams to the socket instead of buffering 100k rows, and a
  cell starting with a tab, a carriage return, `=`, `+`, `-` or `@` is defused
- the log's transfer detail (bytes, injected bytes, terminator) is stored
  instead of assembled and dropped; migration 6 adds the column

Performance and dashboard
- model hints are cached against the model table's revision, and one instant is
  read per evaluation pass
- the provider list is grouped once, not rescanned per model
- the dashboard renders the retry chain, a clear-filters control, the real
  eligibility label, a failed-detail state, and stops polling after unmount

The key-limiter map is swept by the maintenance job, a per-key 429 carries
x-ratelimit-limit/remaining, and the documented test counts and Docker defaults
match the code.
@dinhdev666
dinhdev666 merged commit 297545d into main Nov 24, 2026
6 checks passed
@dinhdev666
dinhdev666 deleted the chore/fourth-audit-improvements branch November 24, 2026 03:11
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