Repository navigation
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Author
|
@jmlago gentle ping on this one when you have time. |
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.
What
Context.MemoryMdkeeps the lastmax_bytesof MEMORY.md withbinary_part(body, byte_size(body) - max_bytes, max_bytes), in bothread_tail/2(thebefore_turn/4context) andtrim/2(which writes the tail back as the new file). Once the file grows past the limit (24 000 bytes by default — a dozen long turns), that byte offset regularly lands inside a multi-byte UTF-8 sequence: accented letters,€, emoji — ordinary Telegram traffic.Consequences:
before_turn/4is not valid UTF-8, so the ingress object'sprefix <> turn.textreachesAgentProtocol.encode_task/2andJason.encode!/1raises inside the agent's task path — the conversation stops answering until the file happens to be cut on a boundary again;trim/2persists the damaged tail, so the file itself is invalid from then on.Replaying 400 turns of mixed Spanish/emoji text through a line-for-line port of the two functions gave an invalid context on 61 turns (15 %).
Change
lib/genswarms/telegram/context/memory_md.ex: onetail/2used by both call sites. It still keeps at mostmax_bytes, but starts the kept text on the first line break inside the window (so it is valid UTF-8 and begins with a whole- role: …turn or a template heading; leading blank lines are dropped), and when the window holds no line break it drops the leading UTF-8 continuation bytes so the text starts on a character boundary.test/client_store_memory_test.exs: 40 turns ofñandú €N 🦤 ok(2-, 3- and 4-byte sequences) with limits cycling 61–70 bytes; after every turn the file and thebefore_turn/4context must be valid UTF-8, within the limit, and start on a whole line.Testing done
mix test(Elixir 1.18.4 / OTP 27): 257 tests, 0 failures.main(turn N: context is not valid UTF-8).max_bytes: 120/50) still passes: the size bounds are unchanged, the tail only gets shorter.mix formaton the touched files.