Skip to content

Implement deep-review findings: fixes, cleanups, dedup, refactors - #50

Merged
PureXYZ merged 2 commits into
mainfrom
claude/jolly-hodgkin-c9ae1a
Jun 15, 2026
Merged

PureXYZ merged 2 commits into
mainfrom
claude/jolly-hodgkin-c9ae1a

Conversation

@PureXYZ

@PureXYZ PureXYZ commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Implements the full code-review report for the codebase (bugs, dead-code removal, deduplication, two structural refactors, perf, and robustness). npm run typecheck and npm run sim both pass; the change was rebased onto latest main and the ~460 coach lines added in #48 were folded into the new lines/ submodules (verified: all 460 present, none duplicated).

Bugs & correctness

  • Crash hardening: guard untrusted weapon-name .replace in the tracker and wrap the clock-timer callbacks in try/catch, so a malformed GSI frame can't reach uncaughtException and kill the process.
  • Config validation: COACH_LLM_MAX_TOKENS bounded 16..4096, LLM timeouts given a floor; intEnv gains fail-loud min/max.
  • Leetify recap: findMatchEntry's map filter is now case-insensitive (was a silent recap blackhole on a cased mismatch).
  • Anti-repeat memory: rib-target rotation now advances when a line actually airs (chooseRibTarget is pure; recentRibbed committed via pendingRib), and the recap's recordSpoken moved to the onPlayed path — dropped lines no longer poison the rotation/phrasing memory.
  • bench-llm median index fixed for any RUNS.

Dead code removed

isInMatch, RoundRecord.equipStart, RoundRecord.bombPlanted + recordBombPlanted, SessionStore.deleteLast, config.timings.freezetimeSeconds, SavedVoiceChannel.guildId — all grep-verified unused.

Deduplication

Shared NDJSON sink + tsStamp (src/ndjson-sink.ts); shared ttfbFetch (src/tts/http.ts); NO_BACKPRESSURE_HWM centralized in tts/constants; engine reserveCooldown helper; single-source DISCORD_ID_RE; roster authority predicate reuses isTeammate; prettyMap → mapDisplayName (also fixes spoken "Dust2" → "Dust 2").

Refactors (pure reorg, no behavior change)

  • Split the 1.6k-line coach/lines.ts into a re-export barrel + domain submodules under src/coach/lines/ (importers unchanged).
  • Extracted the owner-only /coachadmin surface into src/discord/admin-commands.ts (renderStatus exported for reuse).

Perf

Roster reads the cached feed.ctx instead of recomputing the full context() snapshot per payload at three multi-feed sites.

Security & robustness

GSI runtime shape-guard on hot fields + empty-token-on-0.0.0.0 startup warning; DEEPGRAM_TTS_BITRATE bounded; enumEnv for LEETIFY_SQUAD_RECAP; /coach song slash guard; tracker Math.max(...) → reduce (RangeError-safe); prewarm abort re-check; replay-log per-line try/catch; deploy.ts ssh-error check.

Intentionally NOT done (per the review's own guidance)

The roster.ts/tracker.ts god-object deep extraction (regression risk > payoff) and four disputed items (cache readFileSync→in-memory, lastGlobalAt clear-at-matchStart, constant-time token compare, body-size double-writeHead) were left untouched by design.

Reviewer notes

  • Single commit on top of latest main. The two large refactors are pure moves — worth a skim even though the gate is green.
  • The 460 lines from Add ~460 new coach lines to the most frequently-fired pools #48 were redistributed into the submodule pools (bomb 116, kills 178, economy 92, rounds 54, squad 20); every original string is present exactly once.

🤖 Generated with Claude Code

PureXYZ and others added 2 commits June 14, 2026 19:11
Implements the full code-review report for the CS2 Coach codebase.
typecheck + sim both green.

Bugs/correctness:
- Guard untrusted weapon-name .replace in tracker; wrap clock-timer
  callbacks in try/catch so a malformed GSI frame can't crash the process.
- Bound COACH_LLM_MAX_TOKENS (16..4096) and LLM timeouts; intEnv gains
  min/max with fail-loud validation.
- Leetify findMatchEntry map filter made case-insensitive (was a silent
  recap blackhole on a cased mismatch).
- Rib-target rotation now advances at airing time (chooseRibTarget pure,
  recentRibbed committed via pendingRib) instead of generation time.
- Leetify recap recordSpoken moved to the spoken (onPlayed) path.
- bench-llm median index fixed for any RUNS.

Dead code removed: isInMatch, RoundRecord.equipStart, RoundRecord.bombPlanted
+ recordBombPlanted, SessionStore.deleteLast, config freezetimeSeconds,
SavedVoiceChannel.guildId.

Dedup: shared NDJSON sink + tsStamp (ndjson-sink.ts); shared ttfbFetch
(tts/http.ts); NO_BACKPRESSURE_HWM centralized; engine reserveCooldown
helper; single-source DISCORD_ID_RE; roster authority predicate -> isTeammate;
prettyMap -> mapDisplayName.

Refactors: split lines.ts into a re-export barrel + src/coach/lines/*
submodules; extract /coachadmin into src/discord/admin-commands.ts.

Perf: roster reads cached feed.ctx instead of recomputing context().

Security/robustness: GSI runtime shape-guard + empty-token startup warning;
DEEPGRAM_TTS_BITRATE bounded; enumEnv for LEETIFY_SQUAD_RECAP; /coach song
guard; tracker Math.max -> reduce; prewarm abort re-check; replay-log
per-line try/catch; deploy.ts ssh-error check.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The high-recall review of this PR surfaced regressions introduced by the
implementation commit. Fixes, all verified (typecheck + sim green, plus a
throwaway harness exercising the two crash paths):

- gsi/server.ts (HIGH): the new shape-guard dereferenced `payload.map`
  before any null check, so an unauthenticated POST body of literal `null`
  (or a bare scalar/array) threw in the un-try/catch'd req."end" handler and
  crashed the process. Drop any non-object body before touching it.
- config.ts: enumEnv threw at boot for a set-but-empty value (LEETIFY_SQUAD_RECAP=),
  where the prior code coerced "" to the fallback — now treats ""/undefined alike.
- coach/llm.ts + engine.ts: the rib-rotation used a single shared pendingRib
  field cleared at the start of every line(), so an intervening line() between a
  rib line's enqueue and its airing wiped the staged rib (rotation never advanced)
  and the canned LLM-failure fallback wrongly advanced it. The rib now travels with
  line()'s return value and is committed by the engine only when that line's own LLM
  text airs — race-free and per-line. Also folds the duplicated candidate filter into
  one ribCandidates() helper.
- ndjson-sink.ts: close() no longer sets `disabled`, restoring DecisionLog's
  reopen-after-close so a post-match write racing a SIGTERM isn't dropped; log
  messages take a human `what` label (no more "gsi-log write failed"); dropped the
  unused `file` getter.
- config.ts: one-sided intEnv/floatEnv bounds now read "at least N" instead of
  "between N and undefined".
- scripts/replay-log.ts: malformed-line error now reports the physical line number
  (was the post-filter index, off by any blank lines).
- scripts/simulate.ts: mock LLM line() updated to the new {text, rib} return shape.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@PureXYZ
PureXYZ merged commit 4fcf122 into main Jun 15, 2026
1 check passed
@PureXYZ
PureXYZ deleted the claude/jolly-hodgkin-c9ae1a branch June 15, 2026 00:02
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