Repository navigation
fix(telegram): keep delivery mirroring fast in long sessions - #169663
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR separates indexed delivery-key lookup from sequence-bounded assistant-run correlation. Example: Finalize a queued Telegram answer in a session containing 50,000 historical events.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep this PR: it repairs a current-main performance defect while preserving queued-answer correlation, and no actionable patch defect remains. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherTelegram delivery finalization passes delivery identities and a producing run to the shared transcript owner, which reads SQLite correlation facts before recording the delivery mirror. flowchart TD
A[Telegram finalized delivery] --> B[Shared transcript mirror owner]
B --> C[Transcript worker]
C --> D[Indexed delivery identities]
C --> E[Sequence bounded assistant candidates]
D --> F[Correlated delivery receipt]
E --> F
F --> G[Chat history]
Technical reviewBest possible solution: Land the focused indexed-query repair with its documented legacy boundary after satisfying the native CI landing policy. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the session-wide OR lookup, and the PR records comparable measurements through real append APIs; this review did not execute a reproduction. Is this the best way to solve the issue? The repair addresses query selection at the shared owner, reuses existing indexes, and retains idempotency, active-branch selection, and worker ownership without a schema change. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6cf651fb899f. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +17, Tests +43, Docs +6. Total +66 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed October 12, 2026, 3:51 AM ET / 07:51 UTC (Revision 4). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
The SQLite worker-ratchet finding is fixed: the complete baseline-ratchet equivalents pass, with normalized T1 calls staying 605 → 605. Indexed branches now share the original query execution boundary through The remaining
Both failures are in The cancelled type-check logs also exposed an attributable test-only error ( |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
At f9c2185 the test-only TS2532 error is fixed with an explicit expected message. Both cancelled jobs were replayed using their exact CI graph lists plus root stripes 2/4 and 3/4; all passed, as did the affected regression file. The source implementation is unchanged from the proven 917cdbf head. The independent lifecycle-abort evidence remains https://github.com/openclaw/openclaw/actions/runs/38217941201/job/114707435469 (PR #138087). No hosted job was rerun. |
|
Final head: ClawSweeper is ready on this SHA, with no findings. The aggregate gate is red only because
Both fail All four cancelled jobs are covered by successful local replays on this head using their exact CI graph selections: The exact-head 50k lookup measurement, Telegram queued scenario and real-provider gate all pass. No further source changes are pending; the remaining CI decision belongs to the maintainer landing workflow. |
|
Maintainer override: the only red job is build-artifacts, whose lifecycle smoke fails with 'AbortError: agent run aborted' after a successful build. The same test and error fail on an unrelated PR (https://github.com/openclaw/openclaw/actions/runs/38217941201/job/114707435469). This PR changes only the SQLite transcript-mirror lookup, a lifecycle test for it and docs. The 4 cancelled typecheck jobs passed in exact local replays. ClawSweeper is ready on this exact head with no findings. |
|
Landed in f479340. Telegram mirror lookups stay fast on long sessions. |
…w#169663) Since openclaw#169019, the transcript mirror lookup by run id scanned and decoded events across the whole session history, because the JSON-extracted run id inside an OR kept SQLite off its index. Telegram delivery mirroring therefore got slower as a persistent session grew. The lookup now combines the indexed idempotency-key probe and a bounded run lookup with UNION ALL, filters by role in SQL before decoding bodies, and needs no schema change. The count of direct SQLite call sites stays at 605. Measured at 50k events: median 178.00 ms down to 4.39 ms, and run-metadata evaluations from 50,003 to 2,049, with the same row selected. Telegram Test Server proof with 50k historical events: the queued-turn scenario still stores one history row per delivered answer. Fixes openclaw#169643. Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #169643
What Problem This Solves
Fixes slow Telegram delivery mirroring as a persistent session accumulates history, without losing the queued-answer correlation introduced in #169019.
User Impact
Delivery finalization no longer searches every historical event for the producing run. Queued answers still appear once in chat history. There is no schema or migration change.
Why This Change Was Made
The combined idempotency/run predicate prevented the idempotency index from narrowing the query. The lookup now resolves supplied keys independently through that index, then reads only assistant candidates starting at the producing run's indexed input. Runs without an indexed input use a recent 4,096-event tail rather than an unlimited history search; very old legacy deliveries outside that tail cannot acquire a new text correlation. Existing delivery identities remain resolvable regardless of age.
The indexed branches use
UNION ALLin the existing query boundary; the producing-input and tail bounds are scalar subqueries. This preserves the native compatibility reader without adding main-thread SQLite call sites.Reported by @obviyus.
Evidence
Real append APIs seeded 1,000, 10,000 and 50,000 history events. Median lookup latency across seven samples:
The captured query plan changes from a session-wide event scan to the idempotency index plus a sequence-range lookup. Replaying the captured 50k query with counted run-metadata evaluation gives 50,003 evaluations before and 2,049 after, returning the same answer.
The new regression fails on the base because tool-result bodies are returned as run candidates, and passes on the fix. Both focused test files pass: 29 tests, including both queued-answer cases from fix(telegram): avoid duplicate history replies for queued messages #169019; total runner time 61.56 s. Targeted formatting/lint and the build pass.
All fast baseline-ratchet equivalents pass. The database-worker comparison remains 605 → 605 T1 calls; no exemption was added.
Exact head
f9c21859b48b05ab0d43a221bc85bdfd1ba68758, built candidate, Telegram Test Server userbot: the 14a queued scenario in a session with 50,000 pre-seeded historical events produces exactly three history rows for its three delivered answers. All six run-owned user/bot messages were deleted by raw TDLib id and each deletion was read back as absent. The credential lease and runner scratch were released.On the same head, a real OpenAI
gpt-5-miniturn through an isolated built Gateway completed withP169643_LIVE_OK(2.88 s); the task-only credential file was removed afterward. Both previously cancelled type-check jobs passed local replays of their exact graph lists and root stripes.Merge danger: two-way door. Reverting restores the previous lookup; this changes no stored format or persisted content. The blast radius is SQLite channel-final mirror correlation, particularly delayed legacy deliveries without an indexed producing input.