fix(tasklist): prevent editMessageText crash when prompt exceeds Telegram 4 096-byte limit#148
Open
aborovsky wants to merge 6 commits into
Open
fix(tasklist): prevent editMessageText crash when prompt exceeds Telegram 4 096-byte limit#148aborovsky wants to merge 6 commits into
aborovsky wants to merge 6 commits into
Conversation
Owner
|
@aborovsky could you please do rebase |
10e6290 to
c4d2cf4
Compare
…rvival + byte-length assertions
Owner
|
@aborovsky A safer solution would be to calculate the prompt budget dynamically in formatTaskDetails():
This would avoid relying on a fixed number like 3800 or 3500, and would make the fix reliable across locales and longer task metadata. |
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.
Description of changes
truncateToByteLength(text, maxBytes)utility that measures string size in UTF-8 bytes (viaTextEncoder) and binary-searches for the longest safe prefix, with a surrogate-pair boundary guard to prevent malformed Unicode output.formatTaskDetails()now passestruncateToByteLength(task.prompt, 3800)instead of the rawtask.promptto thet("tasklist.details", …)i18n template before callingctx.editMessageText().truncateText()(character-count based) is unchanged and still used byformatTaskButtonLabel.Why 3 800 bytes?
4 096 (Telegram hard limit) − 230 (template chrome: title, labels, schedule, cron, timezone, timestamps, run count) − 66 (safety margin) = 3 800.A comment in the code documents this derivation and notes that non-English locales may need recalculating.
Rebase note: After the upstream structure refactor (PR #149),
formatTaskDetails()moved fromsrc/bot/commands/tasklist.tstosrc/bot/callbacks/scheduled-task-callback-handler.ts. ThetruncateToByteLength()function is placed alongside it in that file.Closes issue (optional)
How it was tested
Three new unit tests added to
tests/bot/commands/tasklist.test.ts:truncates oversized ASCII prompt …Buffer.byteLength(text, "utf8") ≤ 4 096truncates oversized multi-byte prompt …does not truncate prompt that fits within the byte limit…appendedAll 1002 tests pass (vitest 3.2.6).
Checklist
fix(tasklist): prevent editMessageText crash when prompt exceeds Telegram 4 096-byte limitmainnpm run lint,npm run build, andnpm test— changes are isolated to one function addition + one call-site change; no new imports or config changes