Skip to content

[OMEGA-318] Keep the Telegram authorization ledger usable after a damaged write - #334

Merged
TossSky merged 1 commit into
singnet:mainfrom
sassless:omega-318-ledger-fix
Sep 3, 2026
Merged

[OMEGA-318] Keep the Telegram authorization ledger usable after a damaged write#334
TossSky merged 1 commit into
singnet:mainfrom
sassless:omega-318-ledger-fix

Conversation

@TossSky

@TossSky TossSky commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

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:

{"time":"2026-09-02T14:07:01Z",...,"group_id":"-5146542772","authorized_by":"8905552654"}
{"time":"2026-09-02T10:00:00Z","channel_ident{"time":"2026-09-02T19:12:48Z",...,"revoked":true}

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: /unbind confirmed, the group stayed silent for 60 seconds, and after a restart it answered.

_append_json_line writes 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 raised UnicodeError, which load_channel_auth_state turned into RuntimeError reaching 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 /bind and /unbind. get_channel_saved_user_id is deliberately unchanged, since an existing test fixes its wrapped-error behaviour.

Tests

Two tests, both red without the change. Full suite: 42 passed.

…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.
@TossSky
TossSky merged commit d9f4f14 into singnet:main Sep 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants