Skip to content

fix(serve): close the resident-process staleness and growth holes - #957

Merged
iamtoruk merged 1 commit into
mainfrom
fix/serve-hardening
Aug 10, 2026
Merged

fix(serve): close the resident-process staleness and growth holes#957
iamtoruk merged 1 commit into
mainfrom
fix/serve-hardening

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Devil's-advocate pass over #956, fixing what survived scrutiny:

  1. A memoized or burst-reused parse embeds costUSD priced under the config at parse time; the memo key now includes the model-alias, price-override, and local-model-savings hashes, so any pricing-affecting change is an automatic miss. (Config itself was already re-read per request via the preAction hook; the exposure was only the memo layer, bounded to seconds in practice, but the class is now closed structurally.)
  2. RSS guard at 3GB: the resident child drops its in-memory memos instead of growing without bound on lifetime-scale corpora; next request re-parses once. No child exit, so the client's restart budget is untouched.
  3. codeburn serve on a TTY prints what it is instead of silently blocking on stdin.

Attacks that did NOT survive (verified safe): config mutations reaching the child (preAction re-reads per request), orphaned children on app crash (stdin EOF ends the serve loop), request timeout mid-parse holding the refresh lock (#855 recovery handles the SIGKILL'd holder), option-state leakage (fresh program per request, pinned by test).

Full suite green; alias-hash covered by new tests; one-shot output unaffected (key widening only adds terms that are constant within a single run).

Adversarial review of the serve design surfaced three weaknesses a
one-shot CLI never had, because it never lived long enough:

- Pricing-affecting config (model aliases, price overrides, local-model
  savings) now participates in the parse memo key. Config reloads fresh
  per request (the preAction hook), but a memoized or burst-reused parse
  embedded costs priced under the OLD config; the widened key makes any
  such change an automatic memo miss. New alias-hash helper + tests.
- Memory guard: past 3GB RSS the serve loop drops its in-memory memos
  (session cache + parse entries) and the next request re-parses once.
  The child never exits for this, so the client's death budget is
  untouched.
- codeburn serve typed in an interactive terminal now explains itself on
  stderr instead of hanging silently on stdin.
@iamtoruk
iamtoruk merged commit 8e61b20 into main Aug 10, 2026
5 checks passed
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