Skip to content

fix: apply the audited improvements across gateway and dashboard - #14

Merged
dinhdev666 merged 1 commit into
mainfrom
fix/improvement-proposals
Nov 24, 2026
Merged

dinhdev666 merged 1 commit into
mainfrom
fix/improvement-proposals

Conversation

@dinhdev666

Copy link
Copy Markdown
Owner

Implements all 42 proposals from the audit recorded in IMPROVEMENT_PROPOSALS.md (the file deletes itself with this change, per its own completion rule).

Defects

id what a client or operator saw
C1 a non-streaming answer whose body stopped early was logged as a success; it now fails over
H1 the total attempt budget stopped at the headers, so a body read was bounded only by the idle timeout
H2 ADMIN_PASSWORD set but empty created an account with the public default; it now means "no account"
H3 a mistyped numeric variable was written into the generated config.json as null, which is fatal at every boot
H3b the entrypoint accepted only === "true", so LOG_BODIES=YES was recorded as false
H4-H6 dashboard: probe result attributed to the wrong provider, sessions table with no loading/empty/error states, password errors all shown as "wrong password"
M1 refusals logged a field named code, which the masker redacts, so upstreamSummary was [REDACTED]
M2 failures_total counted per attempt and could exceed requests_total
M3 login and logout read unlimited bodies
M4 a throw after reply.hijack() escaped with the provider slot held and the connection still owned
M5 a truncated body could be answered twice; and on a keep-alive connection the ownership flag was never released at all, because onResponse read reply.raw.socket after Node had nulled it
M7 the recent-requests ring only pruned from count(), which a cooling provider never reaches
M8 the retention pass blocked the event loop for its whole batch
M10-M16 dashboard: silent validation, clipboard without a fallback, missing pending states, no real <form>, weekday schedule edge

Improvements and features

x-ocr-attempts on completion replies, the provider's x-ratelimit-* forwarded to clients (F1), Retry-After derived from the earliest live cooldown (F2), an ETag and 304 on GET /v1/models (F3), PRAGMA optimize plus a quick_check at boot (F5), the schema version in /api/system (F6), 202 from the danger zone (I4), a bounded drain that does not splice per waiter (M9), bounds on every integer setting (L7), and a revision-keyed enabled-model cache (I2).

Deliberate deviations

  • I8 kept opencode-api:latest: the image has no published tag or digest to pin to, and inventing one would break docker compose up. A comment says so.
  • L4 resolved as documentation: AGENTS.md invariant 2 now names both additions (the appended [DONE] and the injected keep-alive comment) instead of claiming one exception.
  • M6 is a boot-time warn, not a fatal config error: METRICS_ENABLED is boot-only, so refusing to start would remove the scrape endpoint from an operator who already runs one. Brute force is bounded by the new per-address rate limit on /metrics.

Verification

  • pnpm run check - 62 files, 20 pinned action refs
  • pnpm run typecheck - clean
  • pnpm test:unit - 6 of 6 files, 1226 checks
  • pnpm run test:web - 31 tests
  • SMOKE_STUB_PORT=4500 pnpm test - 444 of 444, 27 slow cases skipped
  • sh -n docker/docker-entrypoint.sh - clean
  • Docker image not built - no Docker here.

Forty-two proposals from the audit in IMPROVEMENT_PROPOSALS.md, all of
them implemented. The defects first, because they are the ones a client
or an operator could observe:

- A non-streaming answer whose body stopped early was recorded as a
  success. readBodyStrict() now reports an incomplete body and the
  attempt fails over instead (C1).
- The total attempt budget stopped at the response headers, so a body
  read was bounded only by the idle timeout. send() holds the total
  timer for the body too (H1).
- An empty ADMIN_PASSWORD in the environment created an account with
  the public default password. It now means what invariant 16 says it
  means - no account - and the generated config carries the empty
  string that ensureFirstAdmin() reads that way (H2).
- A mistyped numeric environment variable was written into the
  generated config.json as null, and a bad *file* value is fatal: the
  container exited on every restart, blaming the operator's own file.
  Unparseable values are omitted so the schema default applies (H3).
- The entrypoint tested booleans with === "true", so LOG_BODIES=YES was
  recorded as false in the file that outlives the variable (H3b).
- A throw between reply.hijack() and the end of the stream escaped with
  the provider slot held and the connection still owned: max_concurrency
  1 reads "busy" forever (M4).
- failures_total counted per attempt, so it could exceed requests_total
  (M2).
- The recent-requests ring only pruned from count(), and a provider in
  cooldown or at capacity is never counted (M7).
- A truncated body could be answered twice, and on a keep-alive
  connection the "a route owns this" flag was never released at all,
  because onResponse read reply.raw.socket after Node had nulled it.
  The flag is now a depth over the socket captured at onRequest, and a
  request whose message never finished arriving keeps its share (M5).

The improvements: revision-keyed enabled-id cache on the hot path (I2),
the connect/body timeout names its own budget (I1), a bounded drain
that does not splice per waiter (M9), a release on an unheld slot warns
instead of going negative (L1), Retry-After derived from the earliest
live cooldown (F2), the provider's rate-limit headers forwarded to the
client (F1), x-ocr-attempts so a client can tell failover from a single
attempt (F4), PRAGMA optimize and a quick_check at boot (F5), the
schema version in /api/system (F6), and an async retention pass that
yields between batches (M8).

Dashboard: the probe result is attributed to the provider it belongs
to (H4), the sessions table has loading/empty/error states (H5), a
password change separates "wrong current password" from "new password
rejected" (H6), a blocked form says why (M10), clipboard has a fallback
(M11), pending states everywhere (M12), real <form> elements (M16), and
a batch of accessibility and dead-code fixes (L11-L24).

Also: bounds on every integer setting so a typo is a config error
rather than a 400 at runtime (L7), a warn when METRICS_ENABLED is on
with a short token (M6), /metrics rate-limited and answering 404 while
disabled (I3), a 202 from the danger zone (I4), an ETag on GET
/v1/models (F3), and the dead CSRF_COOKIE constant removed (I5).
@dinhdev666
dinhdev666 merged commit 023d5a8 into main Nov 24, 2026
6 checks passed
@dinhdev666
dinhdev666 deleted the fix/improvement-proposals branch November 24, 2026 10:54
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