fix: seven bugs found in deep code review - #168
Closed
dylanneve1 wants to merge 1 commit into
Closed
dylanneve1 wants to merge 1 commit into
dylanneve1 wants to merge 1 commit into
Conversation
1. history.ts β wrong log component label ("sessions" instead of "history")
in the corrupt-data fallback path; a copy-paste error from sessions.ts.
2. handlers.ts β handleStickerMessage was missing the isUserRateLimited check
that every other message handler has, allowing unlimited sticker-triggered
AI queries from a single user.
3. dream.ts β executeDream wrote last_run = now at the start of a run rather
than preserving the previous completed-run timestamp. A crash mid-dream
would suppress the next scheduled dream for up to 12 h from the crash start
even if the last successful dream was much earlier. Mirrors the correct
pattern in heartbeat.ts (previousLastRun + separate last_started field).
4. dream.ts β runDreamAgent had no AbortController wired to the query() call,
so on timeout the SDK subprocess received no cancellation signal. The
post-timeout await agentPromise.catch(() => {}) was also unbounded β if the
SDK ignored the timeout it would hang forever, holding the dreaming mutex
and preventing all future dream runs. Fixed by: adding AbortController,
calling abort() on timeout, and replacing the unbounded await with a
30-second raceWithTimeout grace period (same pattern as heartbeat.ts).
5. callbacks.ts β the catch-all callback_query handler forwarded unrecognised
callbacks directly to handleCallbackQuery (AI backend) without calling
isAccessAllowed first, allowing any user who knows a callback_data string
to bypass access control and trigger AI queries.
6. gateway.ts β AbortError was constructed with a TalonError object rather
than a string message, causing p-retry to serialise it as "[object Object]"
and lose the original error detail. Also tightened the chatId null guard
from falsy (!chatId) to strict null check (chatId == null) to avoid
incorrectly rejecting a numeric chatId of 0.
7. cron-store.ts β validateCronExpression cast cron.nextRun() directly to Date
without checking for null; croner returns null when an expression has no
future occurrences, causing a TypeError thrown at the user on a valid but
exhausted schedule. Now returns a proper validation error instead.
https://claude.ai/code/session_01D4EX7RLNwAdyh2iZi9qYmZ
Owner
Author
|
Superseded by #246. I reviewed the old changes and ported the valid/current fixes onto current main in the consolidated PR, while leaving out stale removed-backend changes and broad churn that no longer applies. |
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.
Summary
Deep review of the full
src/tree, finding and fixing seven bugs ranging from a user-triggerable null dereference crash to an access-control bypass and an unbounded async hang that would permanently deadlock the dream subsystem.Bug fixes
src/storage/history.ts"sessions"in the corrupt-data fallback β copy-paste fromsessions.tssrc/frontend/telegram/handlers.tshandleStickerMessagewas missing theisUserRateLimitedcheck present on every other message handler, allowing unlimited AI-triggering sticker spam from one usersrc/core/dream.tsexecuteDreamwrotelast_run = Date.now()at run start instead of preserving the previous completed timestamp. A crash mid-dream would suppress the next scheduled dream for up to 12 h, even if the last successful dream was much earlier. Mirrors the correctpreviousLastRun+last_startedpattern inheartbeat.tssrc/core/dream.tsAbortControllerpassed toquery(), so on timeout the SDK subprocess received no cancellation signal. The post-timeoutawait agentPromise.catch(() => {})was also unbounded β if the SDK ignored the timeout it would hang forever, holding thedreamingmutex and preventing all future dream runs (including forced/dreamcommands). Fixed by wiring anAbortController, callingabort()on timeout, and replacing the unbounded await with aDREAM_ABORT_GRACE_MS(30 s)raceWithTimeout, matching theheartbeat.tspatternsrc/frontend/telegram/callbacks.tscallback_query:datahandler forwarded unrecognised callbacks directly tohandleCallbackQuery(AI backend) without callingisAccessAllowedfirst β any user who knows acallback_datastring could bypass access control and trigger AI queriessrc/core/gateway.tsAbortErrorconstructed with aTalonErrorobject instead of a string, causing p-retry to record"[object Object]"as the error message. Also tightened the chatId guard from!chatId(falsy, incorrectly rejects0) tochatId == nullsrc/storage/cron-store.tsvalidateCronExpressioncastcron.nextRun()directly toDatewithout checking fornull. croner returnsnullwhen an expression has no future occurrences (e.g. a one-shot schedule in the past), causing an unhandledTypeErroron a user-supplied input. Now returns a proper validation errorTest plan
last_runindream_state.jsonis unchanged after a failed/crashed dream run; onlylast_startedadvances/dreamforced run aborts cleanly after timeout; subsequent/dreamcalls succeed (mutex released)withRetryexhausted-retry log shows the original error message, not[object Object][history]shows the correct component label on corrupt-data recoveryhttps://claude.ai/code/session_01D4EX7RLNwAdyh2iZi9qYmZ
Generated by Claude Code