Repository navigation
fix(telegram): offset checkpoints fail under stock Bun - #178909
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. |
|
Codex review: needs maintainer review before merge. What this changesBind Telegram ingress Worker messages to the constructing plugin’s async context so offset checkpoints persist under stock Bun. Example: Telegram polling receives update 7001 under stock Bun 1.4.4.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a concrete Telegram checkpoint failure that remains on current main; no actionable patch defects were found, and the existing CI gate is still pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Telegram ingress Worker fetches Bot API updates and forwards messages to the polling session, which uses the owning plugin runtime to spool updates and persist SQLite checkpoints. flowchart LR
A[Telegram Bot API] --> B[Ingress Worker]
B --> C[Bound message callback]
C --> D[Polling session]
D --> E[Plugin runtime]
E --> F[SQLite spool and checkpoint]
F --> B
Technical reviewBest possible solution: Land the existing callback-context repair after the required checks pass. Do we have a high-confidence way to reproduce the issue? The supplied built-Gateway comparison reproduces the failure under stock Bun 1.4.4, and current-main source retains the same unbound callback; this read-only review executed no target code. Is this the best way to solve the issue? Binding the existing callback at construction restores the runtime lookup invariant at the context-loss boundary without adding retries, alternate runtime registries, or storage changes. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fb824384939f. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +5, Tests +119, Docs +1. Total +125 across 4 files. Added test files: 2. View PR surface stats
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 HistoryReviewed October 22, 2026, 8:40 PM ET / October 23, 2026, 00:40 UTC (Revision 3). |
|
Addressed the test-boundary finding in 1d1b458. The ownership regression now uses existing public SDK test APIs and real registry-managed plugin contexts, with no private core imports, helper bridges, new exports, or boundary exceptions. The import guard and all 20 extension-boundary contracts pass. The revised regression fails on the original adapter under stock Bun with The PR body now includes sanitized, reproducible two-process proof using the actual ingress Worker/sidecar, real HTTP to a local synthetic Bot API, the production ingress monitor, and production SQLite stores: the first process persists checkpoint 7001 with one pending update after an injected retryable delivery failure; the replacement reads 7001, replays that update, polls from 7002, then persists and delivers update 7002. Final pending and claimed queues are empty. Live Telegram Test Server validation remains unavailable because I do not have QA broker access. The new proof establishes the local transport, persistence, and process-replacement behavior; it does not claim live Telegram, a running Gateway/model turn, or abrupt-kill recovery. A maintainer with QA credentials can complete that remaining live-service check. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Maintainer override: QA Smoke CI (profile 5/6) is an inherited failure, not caused by this PR. The failing scenario is memory-dreaming-sweep. It times out after 90 s waiting for the managed cron, because embedding can't find a module in the captured package ( |
|
Landed in 9f89542. Thanks @brianmcguire. Telegram polling on Bun now saves its offset. |
fix(telegram): keep the ingress Worker context on stock Bun On stock Bun (an opt-in runtime), the Telegram ingress Worker lost its runtime context, so saving the update offset failed every time with "Telegram runtime not initialized" and polling restarted from the old offset. The Worker now keeps its context on Bun, so the checkpoint is saved and polling resumes after it. Evidence: built Gateway on stock Bun 1.4.4 with a Telegram Bot API boundary. On main the checkpoint stayed null and polling restarted at offset 0 (twice); with this change the checkpoint is 7001, polling restarts at 7002 and status replies are delivered (twice). Node behaves as before. Thanks @brianmcguire. Co-authored-by: Ayaan Zaidi <[email protected]>
fix(telegram): keep the ingress Worker context on stock Bun On stock Bun (an opt-in runtime), the Telegram ingress Worker lost its runtime context, so saving the update offset failed every time with "Telegram runtime not initialized" and polling restarted from the old offset. The Worker now keeps its context on Bun, so the checkpoint is saved and polling resumes after it. Evidence: built Gateway on stock Bun 1.4.4 with a Telegram Bot API boundary. On main the checkpoint stayed null and polling restarted at offset 0 (twice); with this change the checkpoint is 7001, polling restarts at 7002 and status replies are delivered (twice). Node behaves as before. Thanks @brianmcguire. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 9f89542) Adapted for 2026.9.x: 9.x fans Worker messages out to registered listeners, so the bound handler wraps that loop. Main's regression fixture needs the newer plugin background-context API and passes on Node either way, so it is omitted; a Bun 1.4.2 probe confirmed that an unbound Worker message handler loses the construction context and the bound one keeps it.
fix(telegram): keep the ingress Worker context on stock Bun On stock Bun (an opt-in runtime), the Telegram ingress Worker lost its runtime context, so saving the update offset failed every time with "Telegram runtime not initialized" and polling restarted from the old offset. The Worker now keeps its context on Bun, so the checkpoint is saved and polling resumes after it. Evidence: built Gateway on stock Bun 1.4.4 with a Telegram Bot API boundary. On main the checkpoint stayed null and polling restarted at offset 0 (twice); with this change the checkpoint is 7001, polling restarts at 7002 and status replies are delivered (twice). Node behaves as before. Thanks @brianmcguire. Co-authored-by: Ayaan Zaidi <[email protected]> Adapt the factory-scope binding to the existing subscriber-set handle without replacing subscribe/unsubscribe or ACK/stop ownership; validate with two real worker/account owners and deferred offset writes. (cherry picked from commit 9f89542) Co-authored-by: RomneyDa <[email protected]>
Mirror main's Knip entries for files added by beta.5 backports:
- scripts/perf/{node-event-session-source-measure.mjs,
stream-dispatch-scope-measure.ts,system-prompt-report-retention.ts}
as path-invoked script roots (#183931, #183552, #183010);
- the Telegram ingress context Worker fixture loaded by URL (#178909) in
production ignoreFiles.
Also register scripts/test-security-mail-parser.mjs, the standalone
nodemailer sender-parsing regression added by #187301 (release-only).
…eadcode after backports (#187570) * refactor: keep Teams allowlist sentinel private (#185484) The Microsoft Teams fail-closed allowlist sentinel now remains module-private while preserving its exact restrictive projection and lifecycle coverage. (cherry picked from commit 59b1ddd) * test: teach the live-wrapper fake Bun to answer --revision Partial cherry-pick of the test/scripts/test-live.test.ts hunk only. #173807 (backported as e72f868) made the CI Bun --revision probe mandatory; the fake Bun fixture must answer it from the checkout pin. (cherry picked from commit 08dd80a) * test(ci): expect watchdog exit 124 from wedged run-tsgo #184639 (backported as d9a91b5) intentionally changed the run-tsgo watchdog exit from 1 to 124 so CI collectors stop admitting work. Main realigned this case in run-tsgo-worktree.test.ts (9b14a38); on the release branch the same watchdog case lives in run-tsgo.test.ts and was not realigned by the backport. * test(vitest): keep gateway database-worker routes in canonical order The beta.5 adaptation of #178415 (23a2bcd) prepended three integration proofs to gatewayDatabaseWorkerTestFiles. Canonical project ownership compares that list against sorted discovery, so the out-of-order entries failed vitest-cli-ownership. Move them to their sorted positions; routing membership is unchanged. * refactor: keep Slack reconnect policy private (#181690) Keeps Slack reconnect policy details module-private while preserving the exact invalid-auth cutoff, reset, and blocked-status behavior. (cherry picked from commit cd65901) * fix: keep retired Telegram throttler release private Telegram hunk of 09f9ec8 (#183086) only. The release-only test called the private helper directly; its surviving-alias case is already asserted through releaseRemovedTelegramAccountThrottler, so drop the duplicate direct call. (cherry picked from commit 09f9ec8, partial) * refactor: keep Claude partial-message measurement private src/agents/cli-output-stream-limits.ts hunk of 28e2774 (#184686) only; the backport of #184352 left this export without a consumer. (cherry picked from commit 28e2774, partial) * refactor: keep managed plugin cache selector private src/plugins/management-catalog.ts hunk of 2c0c30b (#185269) only; the backport of #184921 left this export without a consumer. (cherry picked from commit 2c0c30b, partial) * refactor(agents): keep requester settle batch callbacks type private The backport of #181260 (2f7589a) moved RequesterSettleWakeParams into the state module, leaving RequesterSettleWakeBatchCallbacks exported only for a test fixture. Main keeps it module-private; type the fixture through RequesterSettleWakeParams instead. * refactor(infra): drop unconsumed streaming UTF-8 decoder The minimal backport of #180861 (8d3183d) added decodeUtf8Chunks as a prerequisite, but its main consumers (streaming state-migration importers) were intentionally not backported, so production Knip flags it. Remove the export and its unit case; decodeUtf8Input is unchanged. * refactor(scripts): keep pinned Bun CI detection private The minimal #172625 backport (e6c3639) deferred the dev-tool, test-runtime and run-format callers that consume isCiEnvironment on main, so the export has no consumer on the release branch. * test(update): drop orphaned recovery version-mismatch fixture The #185692 backport in 39f9bde removed the last consumer of recoveryVersionMismatch from update-cli.plugin-convergence.test.ts. Main removed the same fixture in eae9bc4 (#181717). * test(gateway): type config removal mocks through inline module imports The release adaptation of #152052 (41aa7a6, de41770) typed its partial mocks through type-only namespace imports. Knip treats the secrets runtime namespace as the only consumer of its exports, so the full-tree scan reported prepareSecretsRuntimeSnapshotRestore and SecretResolverWarning as unused. Use main's inline typeof import() form. * refactor(shared): drop unconsumed async-store helper The backport of #179213 (6d9852d, plus f3fb0e9 registering it as a wrapper component) took the runWithAsyncStore helper and its test without the plugin-instance-invocation consumer, leaving src/shared/async-store.ts unused in production. Remove the helper, its test and its wrapper-components entry rather than complete a perf change during beta stabilization. * chore(knip): model backported perf scripts and Telegram worker fixture Mirror main's Knip entries for files added by beta.5 backports: - scripts/perf/{node-event-session-source-measure.mjs, stream-dispatch-scope-measure.ts,system-prompt-report-retention.ts} as path-invoked script roots (#183931, #183552, #183010); - the Telegram ingress context Worker fixture loaded by URL (#178909) in production ignoreFiles. Also register scripts/test-security-mail-parser.mjs, the standalone nodemailer sender-parsing regression added by #187301 (release-only). * refactor(doctor): keep dashboard migration guard at the repair boundary Release adaptation of 50b532d (#183153). The backport of #182345 (51f63cb) exported isUnstampedDashboardRoot only for its unit test. Main made it private and drove the eligibility cases through repairLegacyDashboardChatTypes using a canonical-repair fixture this branch does not carry. Keep every accepted and rejected row case, now asserted through the repair boundary with the branch's session accessor. * test(agents): hold requester preparation for the settle capacity case after #181260 backport Backport 2f7589a (#181260) filters delivered child findings from settle wakes (needsRequesterSettleFindings), so this delivered-row case no longer reads the child transcript where it injected worker capacity and failed with 'expected findTranscriptEvent to be called'. Main realigned the same case in 411b2e6 (#178104): inject capacity at captureRequesterSessionEntryCurrent and assert the delivered result is not repeated in the resumed wake. Apply that realignment; the 'Already delivered child results' wording that main also asserts belongs to #178104's message change, which this branch does not carry. (adapted from commit 411b2e6) --------- Co-authored-by: Shakker <[email protected]>
Closes #178809
What Problem This Solves
Under supported stock Bun, Telegram's native ingress Worker messages can lose the constructing plugin's async context. Real polling then logs
failed to persist update offset ... Telegram runtime not initialized; the durable checkpoint remains unset even though an update was received. A clean Gateway restart consequently begins polling without the saved offset.Solution and User Impact
Bind the existing Worker message callback to its construction context with
AsyncLocalStorage.bind. The lateronMessageassignment stays unchanged, and both immediate and deferred work use the correct plugin owner. No retry, state, schema, configuration, dependency, or plugin-SDK surface changes. The troubleshooting page identifies the error and recommends updating rather than clearing checkpoints.The fix uses the existing callback and native async-context owner, not a parallel registry or wrapper API. Necessary production growth is +8/-3 (net +5); tests/support +119/-0; docs +1/-0. The native Worker test covers independent plugin owners, foreign-scope callback assignment, and immediate/deferred offset writes through public APIs. Its Node run also passes on main; it is a Node ownership control, not the evidence for the Bun defect.
Evidence
Built and installed main (
cb81ec86d1c9d19ce300781ef84dde5209fa569b) and candidate (6b0850f71792c71780e1d111732562a7c6ed6f78) in secretless Linux arm64 Docker with Node 24.22.1. The latest official stock Bun release was 1.4.4, downloaded from its official Linux arm64 asset; its nativenode:sqlitereports SQLite 3.53.4. The installedopenclaw.mjsruns underbun --bun, passing its unchanged runtime/SQLite admission. No engine edits or guard overrides.The shipped setup/config commands create each independent profile, workspace, database, Telegram account, and allowlist. A local Bot API boundary server supplies synthetic
getMe/getUpdatesresponses and an allowed user's ordinary/statusupdate 7001. The actual built Gateway starts the actual ingress Worker; this does not replace the Worker or invoke a private callback. The observer only reads the SQLite checkpoint and records Bot API requests/replies.lastUpdateId: null, and starts the first poll after a clean restart with no offset (recorded as 0).lastUpdateId: 7001, returns the visible/statusresponse through the Bot API boundary, and starts the first poll after restart at 7002. Neither first-run nor restart logs contain the context/persistence error.Captured outputs and checkpoint observations follow below. This is a real built-Gateway/local-channel-boundary proof, not a live Telegram account or live-provider claim. No model turn is needed for the
/statuscommand.Captured built Gateway checkpoint and restart observations
Each arm used a fresh command-created profile. Empty/absent polling offsets are recorded as 0 by the local Bot API observer. Checkpoint rows below are read-only SQLite observations, not seeded state.
base0
base1
base-node-control
cand0
cand1
cand-node-control
Thanks to @brianmcguire for the fix and @qwexs for reporting the runtime failure.
Merge danger: two-way door; reverting removes callback context binding without changing storage or configuration. Existing polling checkpoint writes remain in the existing format. Blast radius is Telegram polling Worker message handling, especially Bun; Node behavior is retained by the control.