feat(telegram): add capture ingress queue with atomic ledger persistence (Slice 1.1R-B) - #80671
Closed
danielbeckinho wants to merge 3 commits into
Closed
Conversation
…ice 1.1R-B) capture_ingress.py: CaptureIngressQueue (asyncio.Queue subclass) - Intercepts PTB Updates before dispatch via super().put() for pass-through - Idempotent pre-ack ledger insert with atomic companion payload - Terminal capture-only dispatch deny (commands → inert text) - Agent routes: persist-then-delegate pattern - build_event_id(profile, account_id, update_id) matches ingress-ledger schema - canonicalize_payload() for deterministic sorted-key UTF-8 JSON 20 tests: event_id, canonicalization, atomic insert, idempotency, conflict-rejection, text/command/media/location capture, pass-through, agent delegation, drop route, route matching, sentinel pass-through
…asks 10-11) TelegramAdapter takes an optional keyword-only `profile`, exposed read-only via `.profile`; unset falls back to the process-active profile. gateway/run.py stamps it in `_configure_profile_adapter` (the existing per-profile hook — adapters are built by the plugin registry factory, not constructed in run.py). Capture ingress keys ledger event_ids on this value, so it must not drift. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…Slice 1.1R-B Task 12) - capture_ingress: add CAPTURE_SCHEMA + open_capture_db() so the ledger DDL lives with the module that owns the tables (it previously existed only inline in the test file). - capture_ingress: normalize telegram.Update objects via to_dict() before inspection, delegating the original object. PTB enqueues Update instances, not dicts, so without this the queue passed every real update straight through and captured nothing. - adapter: _build_capture_queue() reads platforms.telegram.extra.capture_routes and installs the queue via builder.update_queue() at both build sites. Returns None when no routes are configured — a queue with an empty route map is a pure passthrough, so we skip it and skip creating the DB file. - adapter: extract the duplicated handler registration into _register_handlers(). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Slice 1.1R-B — Capture-first intake
Installs a capture-aware
asyncio.Queueat PTBApplicationBuilder(...).update_queue(...)that intercepts message-like Telegram updates before PTB dispatch, guaranteeing durable pre-acknowledgment recording for capture-only routes.What changed
capture_ingress.py(new) —CaptureIngressQueue(asyncio.Queue)interceptsput(), routes by(chat_id, thread_id), atomically persists ledger row + companion payload, terminal deny on capture_only routesadapter.py— immutableprofilefield set at construction,_build_capture_queue()readscapture_routesconfig and wires queue viabuilder.update_queue(), extracted_register_handlers()helpergateway/run.py— profile stamped on adapter constructioncapture_ingest.py(live file, not in repo) —CAPTURE_OK:0output on zero-capture runsTest evidence
Architecture
Non-goals (not in this PR)
drop_pending_updatescold-start behaviorAuthorization
Hermes control-plane Slice 1.1R-B, PRs #19 (plan) and #20 (authorization record, merged 2026-08-06T20:55Z). Scoped TDD implementation authorized; merge remains owner-gated.
Closes: control-plane envelope 1.1R-B