Fix #147: truncate task prompt by byte length for Telegram's 4096-byte limit#172
Conversation
- Issue grinev#147: truncate task prompt in detail view to avoid Telegram's 4096-char limit on editMessageText (add truncatePromptForDetails) - Issue grinev#170: add filename-based text type detection fallback to handle .svelte and other code files that lack a proper MIME type - Update isTextMimeType to accept an optional filename parameter and check against TEXT_FILE_EXTENSIONS when MIME type is unrecognized Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
@hbx12 thanks for the fixes! A couple of comments before we merge. #170 (.svelte / unknown MIME types) — code looks good, the fallback path works as intended. Could we move it into a separate PR? The two fixes are independent and splitting keeps things easier to review and revert. Only thing missing is tests — the new extension fallback in isTextMimeType isn't covered, would be good to add a couple of cases (e.g. application/octet-stream + .svelte filename → true, and an unknown extension → false). #147 (long prompt truncation) — this one needs a small change. It truncates by character count, but Telegram's limit is 4096 bytes in UTF-8. For non-ASCII text that's a different number: a 3800-char Cyrillic prompt is ~7600 bytes and still crashes (real threshold is ~1800 chars; CJK is even lower). Suggest truncating by byte length (e.g. Buffer.byteLength) with a byte budget that leaves room for the rest of the template, instead of a fixed char limit. Once #147 is reworked and tests are added for both, I'm happy to merge. |
|
@grinev Thanks for the detailed review! Good point about splitting #170 into a separate PR. I’ll move the MIME type fallback into its own PR and add the missing test cases for both the .svelte fallback and the unknown extension case. For #147, you’re absolutely right. I overlooked Telegram’s UTF-8 byte limit and only considered character count. I’ll rework it to truncate based on byte length while leaving enough room for the rest of the template, and I’ll add tests covering non-ASCII input as well. I’ll update both PRs and let you know once they’re ready. Thanks again! |
…am's 4096-byte limit Rework truncation to use Buffer.byteLength() instead of character count. Telegram's editMessageText limit is 4096 bytes (not characters), so non-ASCII prompts (Arabic, Cyrillic, CJK) still crashed with the previous character-based fix. Binary search approach finds the correct character offset efficiently. Also removes the svelte MIME type fallback changes from this PR — they now live in a separate PR (grinev#173). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
@grinev PR is updated! Here's what changed: #147 rework (this PR)
#170 moved to separate PRThe svelte/file extension fallback was moved to #173 with its own tests as requested. |
|
@hbx12 thanks for contribution! |
Changes
🐛 #147 — Task detail view silently fails when prompt exceeds byte limit
editMessageTextexceeds Telegram's 4096-byte limit. The previous fix used character count, which still crashed for non-ASCII text (Arabic/Cyrillic: ~7600 bytes for 3800 chars)truncatePromptForDetails()to useBuffer.byteLength()with binary search, ensuring the prompt stays within byte budget regardless of encodingFiles changed
scheduled-task-callback-handler.ts— byte-length truncation with 3800-byte budget✅ TypeScript — zero errors
⚠️ Note: #170 (svelte file support) moved to separate PR #173
✅ 1054/1054 tests passing (3 new tests for byte truncation)