Skip to content

chore: tinygrad adoptions closeout — sz caps, CHAT_DEBUG, three-lane parity, alias cleanup - #62

Merged
sv merged 6 commits into
mainfrom
chore/tinygrad-closeout
Aug 24, 2026
Merged

sv merged 6 commits into
mainfrom
chore/tinygrad-closeout

Conversation

@sv

@sv sv commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

What

Four closeout items, one commit each:

  • Alias removal (item 5): every monkeypatch.setattr(app_module, KNOB, ...) that targeted a CHAT_* knob (28 setattr lines, 6 test files) migrates to with config.override(KNOB=...) wrapping the assertions that depended on it; the seven app-side aliases nothing needed any more are deleted and their use sites read config.<name> at call time. app.py 919 -> 916 code-lines.
  • CHAT_DEBUG (item 2): a three-level stderr ladder on the write path — 1 = limiter take/refund verdicts with client identity, 2 = + store flock/compact/reap/CAS-conflict, 3 = + one line per room write (room, seq, chars). Zero cost when off, never message content, +20 core code-lines.
  • Three-lane differential check (item 3): tests/http/test_lane_parity.py — one logical write via store.append, the HTTP GET lane, and the MCP wrapper, asserting field-identical JSONL records (modulo seq/ts, stated why) and byte-identical rendered lines; notes land the strictest form (byte-equal reads, nothing masked). Written as the seed of the §6.5 port gate.
  • sz caps (item 1): per-file caps measured from the end state, enforced by sz.py --check (which now names the cap) and printable with --caps; AGENTS.md carries the numbers and the "new primitive or extra" rule, CONTRIBUTING.md points at sz.py --caps.

sz before -> after (code-lines): app 919 -> 919, config 39 -> 48, didkey 57 -> 57, limit 107 -> 110, store 709 -> 714, total 1831 -> 1848. The caps are exactly those end-state numbers; the baseline stays a ratchet that only moves down.

DEBUG ladder in one line: CHAT_DEBUG=0|1|2|3 — limiter verdicts / +store locks & conflicts / +per-write room-seq-chars, stderr only, invalid -> 0 with one warning.

Why

The split (PRs #52-#61) left each knob bound in three places — config, app's alias, limit's parameter plumbing — and tests were the thing holding the aliases alive. With every knob-shaped test on config.override(), the aliases are plain dead weight; deleting them is the last step of the move, not a new one. CHAT_DEBUG and the sz caps are the two adoptions the split was for: an operator-facing debug ladder that costs nothing off, and a numeric form of the line-tradeoff rule so "belongs in core" is checked, not argued. The lane-parity fixture exists because the three write lanes (store, HTTP, MCP) were only ever tested separately — if they disagreed about what a record is, no single-lane test could see it — and because §6.5 needs exactly this differential as a port gate.

Checks

  • uv run coverage run -m pytest tests -q && uv run coverage report — 316 passed (313 at start + 3 parity tests)
  • uv run ruff check . && uv run ruff format --check . and uv run ty check
  • Docs that would now be wrong are updated: AGENTS.md gains the cap line, CONTRIBUTING.md points at sz.py --caps; no served document changes (manual/agent.json publish per-deployment numbers only, and docs/manifest tests stayed green)
  • New surface on a world-writable service: none — stderr only. CHAT_DEBUG writes nothing to stdout, nothing into any room, adds no HTTP surface, and logs lengths/seqs/room names, never message content.

sv added 5 commits August 24, 2026 17:53
…rrides

Every monkeypatch.setattr(app_module, KNOB, ...) that targeted a CHAT_* knob
moves to config.override(KNOB=...) wrapping the assertions that depended on it:
28 setattr lines across 6 test files, bodies otherwise untouched. Test bodies
that read a knob back (app_module.RATE_READ in test_docs, app_module.MAX_WAIT
and the fresh-interpreter app.RATE_WRITE probe in test_limits,
app_module.CLIENT_IP_HEADER, store.EPHEMERAL_TTL_SECONDS) keep their reads, so
the aliases they resolve through stay.

With no monkeypatch site left needing them, seven aliases in app.py are dead
and deleted — ROOT, CORS_ORIGINS, STATS_TOKEN, STATS_CACHE_SECONDS,
ROOMS_CACHE_SECONDS, SECURITY_CONTACT, PUBLIC_URL — and their use sites read
config.<name> at call time, which config.override re-binds directly. The four
that tests still assert against (RATE_READ, RATE_WRITE, RATE_ROOMS_PER_DAY,
CLIENT_IP_HEADER, plus MAX_WAIT beside its ceiling) remain aliased and are
mirrored by override(). The limit re-exports and the __getattr__ forwarding
survive: tests still reach _buckets, _waiters_total, refill_rate, FREE_PATHS,
MAX_BUCKETS and MAX_WAITERS_TOTAL through app, and those are not config knobs.

Left as monkeypatch (genuinely app/limit-local, not config): _room_exists,
_stats_view, store.append/note_set/room_stats (function seams), MAX_BUCKETS,
MAX_WAITERS_TOTAL, WAIT_POLL, MAX_ROOMS_CACHE.

sz: app.py 919 -> 916 code-lines; core total 1831 -> 1828 (both under the
pre-existing baseline). 313 tests green before and after; count unchanged.
Operator-facing only, zero cost when off. config gains DEBUG (floor 0, cap 3,
invalid floors to 0 with one stderr warning instead of refusing to boot — a
debug switch a tired operator can typo into an outage defeats itself) and
_dbg(level, event, **fields): one 'event key=value ...' line to STDERR when
DEBUG >= level, one comparison and nothing built when suppressed. It reads
config.DEBUG at call time, so config.override(DEBUG=2) reaches it like any knob.

Ladder: 1 = limiter take/refund verdicts with client identity (limit.py);
2 = + store flock/compact/reap/CAS-conflict, one line at each existing site,
no restructuring (store.py); 3 = + one line per room write with room, seq and
length in every write route — say, say-signed and POST (app.py). The GET lanes
log the room rather than the path because the path *is* the message content;
lengths, seqs and room names only, never content, never stdout, never any
room, no new HTTP surface.

+20 core code-lines (config 39->48, limit 107->110, store 709->714,
app 916->919; core total 1828->1848). Caps land in sz-baseline.json with the
measurement commit that follows. 313 tests green; count unchanged.
One logical write performed three ways against one tree: store.append
directly, the HTTP GET say lane, and the MCP wrapper (which builds the same
GET; the fixture reuses tests/test_mcp.py's urlopen-into-TestClient wiring and
also yields the TestClient so every lane writes the same root — parity only
means anything then).

Rooms: three appends, one room file, records field-identical modulo exactly
the fields that must differ — seq (room-local, assigned under the lock in
arrival order: 1, 2, 3 IS the parity) and ts (microsecond clock); nick does
not differ because the wrapper's nick argument becomes the same path segment.
Rendered parity: two fresh rooms, replies byte-identical after masking only
the room name and the [seq ts] prefix. Notes fall out naturally and land the
strictest check: one value through note_set, /kv/set and write_note produces
three byte-identical files, and a note read over HTTP equals the wrapper's
reply text byte-for-byte — no timestamps, so nothing to mask.

Written as the seed of the §6.5 port gate: assertions are phrased against the
protocol, not this implementation, so lanes (b)/(c) can be pointed at a port.

313 -> 316 tests; no core changes.
sz-baseline.json before -> after (code-lines):
  app.py    919 -> 919   (alias removal -3, DEBUG level-3 +3)
  config.py  39 ->  48   (the DEBUG knob and _dbg)
  didkey.py  57 ->  57
  limit.py  107 -> 110   (DEBUG level-1 verdicts)
  store.py  709 -> 714   (DEBUG level-2 flock/compact/reap/CAS)
  total    1831 -> 1848

The caps ARE those numbers: the baseline stays a ratchet that only moves down,
the caps are the policy ceiling it ratchets under. sz.py --check now names the
cap in every growth message and fails on any value past its cap even when the
baseline was raised to match — the guard against --update-baseline absorbing
growth the caps exist to force a decision about. New --caps prints the table
(code, cap, headroom) and fails on a breach. --update-baseline carries caps
forward untouched.

AGENTS.md gains the numeric line under the layering rule (app 919, config 48,
didkey 57, limit 110, store 714 — total 1848; growth past a cap needs a new
primitive or belongs in extra) and CONTRIBUTING.md's line-tradeoff bullet
points at sz.py --caps rather than duplicating the numbers.

Gates: ruff/format/ty clean, 316 passed, sz.py --check green.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe141a66b4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sz.py Resolved
Review catch on #62: a label missing from caps — the natural state right
after adding a file to CORE_FILES — silently fell out of the per-file
policy. The 'label in caps' guard skipped it in the breach check, --caps
printed '-', and --check passed as long as the aggregate still had
headroom from earlier reductions, so the new file's growth was enforced
by nothing but the looser total.

The enforcing modes now validate coverage first and fail naming what is
missing: every core label and core_total must have a cap before --check
or --caps will run. With coverage guaranteed, the breach check indexes
caps directly and the '?-fallback' format args are gone. Plain 'uv run
sz.py' still measures without loading the baseline, and --update-baseline
still carries caps forward untouched — so adding a core file now means
deliberately deciding its cap, which is the point of having caps.

Verified: missing file cap and missing core_total both fail --check and
--caps naming the gap; the past-cap negative still fails; clean tree green
in all modes; ruff/format/ty clean; 316 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