Repository navigation
Implement deep-review findings: fixes, cleanups, dedup, refactors - #50
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the full code-review report for the codebase (bugs, dead-code removal, deduplication, two structural refactors, perf, and robustness).
npm run typecheckandnpm run simboth pass; the change was rebased onto latestmainand the ~460 coach lines added in #48 were folded into the newlines/submodules (verified: all 460 present, none duplicated).Bugs & correctness
.replacein the tracker and wrap the clock-timer callbacks in try/catch, so a malformed GSI frame can't reachuncaughtExceptionand kill the process.COACH_LLM_MAX_TOKENSbounded16..4096, LLM timeouts given a floor;intEnvgains fail-loudmin/max.findMatchEntry's map filter is now case-insensitive (was a silent recap blackhole on a cased mismatch).chooseRibTargetis pure;recentRibbedcommitted viapendingRib), and the recap'srecordSpokenmoved to theonPlayedpath — dropped lines no longer poison the rotation/phrasing memory.bench-llmmedian index fixed for anyRUNS.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); sharedttfbFetch(src/tts/http.ts);NO_BACKPRESSURE_HWMcentralized intts/constants; enginereserveCooldownhelper; single-sourceDISCORD_ID_RE; roster authority predicate reusesisTeammate;prettyMap→mapDisplayName(also fixes spoken "Dust2" → "Dust 2").Refactors (pure reorg, no behavior change)
coach/lines.tsinto a re-export barrel + domain submodules undersrc/coach/lines/(importers unchanged)./coachadminsurface intosrc/discord/admin-commands.ts(renderStatusexported for reuse).Perf
Roster reads the cached
feed.ctxinstead of recomputing the fullcontext()snapshot per payload at three multi-feed sites.Security & robustness
GSI runtime shape-guard on hot fields + empty-token-on-
0.0.0.0startup warning;DEEPGRAM_TTS_BITRATEbounded;enumEnvforLEETIFY_SQUAD_RECAP;/coach songslash guard; trackerMath.max(...)→reduce(RangeError-safe); prewarm abort re-check;replay-logper-line try/catch;deploy.tsssh-error check.Intentionally NOT done (per the review's own guidance)
The
roster.ts/tracker.tsgod-object deep extraction (regression risk > payoff) and four disputed items (cachereadFileSync→in-memory,lastGlobalAtclear-at-matchStart, constant-time token compare, body-size double-writeHead) were left untouched by design.Reviewer notes
main. The two large refactors are pure moves — worth a skim even though the gate is green.🤖 Generated with Claude Code