[OMEGA-318] Keep the Telegram authorization ledger usable after a damaged write - #334
Merged
Merged
Conversation
…aged write - Append a leading newline when the previous record was left unterminated, so the next record is not swallowed by the damaged line. A revoked group used to come back after a restart because /unbind landed inside an invalid line. - Read the ledger with errors="replace" on the startup and group-lookup paths, so undecodable bytes are skipped like malformed JSON instead of stopping the agent with exit 2 before any channel starts. - Cover both cases with tests.
This was referenced Sep 2, 2026
blackhammer116
approved these changes
Sep 3, 2026
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.
Follow-up to #327, found while retesting OMEGA-318. Two defects in the group authorization ledger, both reachable when a write is interrupted.
A revoked group comes back after a restart
A record cut short by an interrupted append has no trailing newline, so the next record is written onto the same line:
The revocation is now part of an invalid line and is skipped on the next start, so a group the owner removed is authorized again. Reproduced on a live bot:
/unbindconfirmed, the group stayed silent for 60 seconds, and after a restart it answered._append_json_linewrites a leading newline when the file does not end in one, so an earlier damaged record can no longer swallow later writes.Damage outside UTF-8 stops the agent from starting
errors="replace"was missing on the read paths, so undecodable bytes raisedUnicodeError, whichload_channel_auth_stateturned intoRuntimeErrorreaching main: container exit 2, no adapter, no polling, no owner DM. Such a line is now skipped the same way malformed JSON already is, keeping the failure inside the feature that owns the file.Applied to the startup path and to the group lookup used by
/bindand/unbind.get_channel_saved_user_idis deliberately unchanged, since an existing test fixes its wrapped-error behaviour.Tests
Two tests, both red without the change. Full suite: 42 passed.