Repository navigation
fix(send): cache the sent message right away - #30
Merged
Merged
Conversation
tg send returned the message ID but never wrote the message to messages_cache. Telegram pushes no update for a message to the session that sent it, and the daemon shares that session, so the message only reached the cache by accident: after an unrelated update revealed a gap, or on a later sync job. tg messages search missed it until then. Now send upserts the message from the response. A full updates response goes through the sync worker's parseRawMessage with the chat ID taken from the message peer. updateShortSentMessage has no message object, so the row is rebuilt from the request, with the own user ID as sender and as the Saved Messages chat; the ID comes from the account row, or from getMe once if the row lacks it. Chat IDs are marked peer IDs, the format the daemon uses for messages_cache. The FTS index follows through the existing triggers. A cache failure is logged in verbose mode and the send still reports success. Fixes #19 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The new smoke test sends to Saved Messages with no daemon running and finds the message with tg messages search, cached under the own user ID. It is the "done when" check of #19 against the real API, where Telegram answers a Saved Messages send with a full updates response (out=false, no fromId) rather than updateShortSentMessage. Co-Authored-By: Claude Opus 5.5 <[email protected]>
neoromantic
force-pushed
the
fix/send-cache-19
branch
from
October 21, 2026 12:13
5bc13e1 to
d353801
Compare
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.
Problem
tg sendreturned the message ID but never wrote the message tomessages_cache. Telegram pushes no update for a message to the session that sent it, and the daemon shares that session, so the message reached the cache only by accident (an unrelated update revealing a gap, or a later sync job).tg messages searchmissed it until then.Fix
After a successful send,
tg sendupserts the message intomessages_cachefrom the response (src/commands/send/sent-message-cache.ts):updates/updatesCombined: eachupdateNewMessage/updateNewChannelMessagegoes through the sync worker'sparseRawMessage, with the chat ID from the message'speerId(toPeerIdFromRawPeer).raw_jsonis the raw message.updateShortSentMessage: there is no message object, so the row is rebuilt from the request (text, reply-to) and the response (id, date,out, media), then mapped by the sameparseRawMessage. The sender is the own user ID, andinputPeerSelfmaps to it as well. The ID comes from the account row, or fromgetMeonce if the row lacks it (it is then saved, astg medoes).raw_jsonis the short response.-chatId,-100…), the format the daemon uses formessages_cache.chat_id. The newtoPeerIdFromInputPeerinsrc/utils/telegram-peer-ids.tshandles input peers. The messages/chats format mismatch (Messages and chats are cached with different peer ID formats #18) is untouched.message_search) follows through the existingmessages_cachetriggers, so the message is searchable at once.verbose()and the send still reports success.No daemon code changed: the command only imports the already exported
parseRawMessageandbigIntReplacer. Docs (docs/cli-commands.md,docs/caching.md,docs/testing.md),CHANGELOG.mdandROADMAP.mdare updated.Tests
src/__tests__/send-cache.test.ts(16 tests) runs the real module: both response shapes,inputPeerSelf/ user / basic group / channel peers, link preview media, reply-to, FTS search,fetched_atandraw_json, the own user ID from the account row vs.getMewith save, and a failing cache write or failing user ID lookup that resolves without throwing.bun run check,bun run test(1135 pass) andbun run test:e2e(100 pass) are green locally.tg send --to me(no daemon), then finds the message withtg messages search --query <marker>under the own user ID. It passed against the real API together with the existing Saved Messages test (2 pass), and both messages were deleted afterwards. The live run showed that Telegram answers a Saved Messages send with a fullupdatesresponse (out=false, nofromId), notupdateShortSentMessage, so the short path is covered by unit tests only.Fixes #19
🤖 Generated with Claude Code