Repository navigation
refactor(telegram): receive webhooks on Gateway routes - #158732
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: blocked before merge. Reviewed September 26, 2026, 10:01 AM ET / 14:01 UTC (Revision 8). ClawSweeper reviewWhat this changesThe branch moves Telegram webhook reception onto Gateway HTTP routes, retains forwarding on the old port, migrates explicit listener settings through Doctor, and updates tests and documentation. Merge readiness⛔ Blocked before merge - 5 items remain Keep this PR open. The merged Gateway listener foundation does not move Telegram reception, and current main still uses Telegram’s private server. This branch is a distinct, coherent part of the open HTTP ingress work. Priority: P2 Review scores
Verification
How this fits togetherTelegram’s webhook plugin receives Bot API callbacks through an HTTP listener. It checks the webhook secret, commits accepted updates to durable ingress, and lets downstream agent processing handle them. flowchart LR
A[Telegram callback] --> C[Gateway HTTP route]
B[Legacy port] --> C
C --> D[Path and secret check]
D --> E[Durable ingress queue]
E --> F[Agent processing]
G[Old listener settings] --> H[Doctor migration]
H --> B
Before merge
Agent review detailsSecurityNone. PR surfaceSource +206, Tests +759, Docs +72, Generated 0. Total +1037 across 36 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Use one Gateway route owner with Telegram-local secret checks and durable admission, while preserving old listener settings through Doctor and retaining the documented opt-out. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this is a transport migration. Current-main source clearly shows the separate Telegram HTTP server that the PR replaces. Is this the best way to solve the issue? Yes, the existing Gateway route and compatibility-listener owner is the appropriate boundary, with Telegram retaining secret verification and durable admission. Its upgrade and live-service behavior still need the required proof. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b4bcfe29678a. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
1d84013 to
d222786
Compare
cb0dea5 to
e0c536d
Compare
Security-sensitive guard clearedCurrent revision: This PR no longer changes files in the maintainer security-review tier. Separate CODEOWNERS requirements still apply to security policy and enforcement files. |
e0c536d to
5a5b3f0
Compare
3b4b23f to
c9dcccb
Compare
c06fbf2 to
e0adfae
Compare
|
Merged via squash.
|
158 upstream commits, none in extensions/feishu. Two conflicts, both generated: docs/.generated/config-baseline.sha256 and src/config/bundled-channel-config-metadata.generated.ts. Upstream's Telegram webhook change (openclaw#158732) moved the channel schema while this branch moves it for Feishu. Both files came from upstream and were regenerated. config-baseline.counts.json auto-merged without a conflict but was wrong: each side took the channel count from 3740 to 3742 for its own entries, so git kept 3742. The real count with both sides is 3744, and the regenerated file says so. build:docker ran in a separate detached checkout of this commit outside the nested node_modules install. Regenerating there changed the three files above and nothing else, giving core 2463, channel 3744, plugin 4349 as predicted, a channel hash neither side had, and upstream's core and plugin lines. The three generated-file checks pass there. The lockfile moved, so dependencies were reinstalled. Feishu: 105 files and 2168 tests in the extension project, 16 files and 348 tests in the database-workers project. The forwarder test and the routing guards pass, 2011 tests, fewer than before because upstream removed tests from test-projects.test.ts (openclaw#158663). tsgo:core, tsgo:extensions, tsgo:extensions:test, tsgo:test:root, and the line-cap, max-lines and assertion-safety ratchets against upstream/main pass, and oxlint and oxfmt pass on the changed code files.
* refactor(telegram): serve webhooks through Gateway routes * fix(telegram): preserve legacy webhook health and auth limits * fix(telegram): share webhook targets across module copies * chore(telegram): regenerate webhook config documentation * fix(telegram): retain deprecated webhook config input types * test(telegram): match webhook fixture types to runtime contracts * fix(telegram): satisfy webhook transport lint contracts
Related: #157553
What Problem This Solves
Telegram webhook mode owns a separate HTTP server, duplicating listener lifecycle and preventing callbacks from using the Gateway's registered HTTP routes.
User Impact
Telegram callbacks can use the Gateway port. Existing webhook installs keep their old effective endpoint, including the implicit
127.0.0.1:8787default and exact legacy/healthzresponse. After pointing the external callback or reverse proxy at the Gateway route and verifying delivery, operators can setlegacyWebhook: falseto close the old port. Polling is unchanged.Why This Change Was Made
The Telegram handler registers with the Gateway route owner and shares its handoff and request lifetime. The Gateway compatibility listener forwards old-port traffic into that same handler. Telegram retains its secret verification before reading bodies, failed-auth-only limiter, raw callback-path semantics, legacy proxy attribution, durable acknowledgement, and admitted-request shutdown behavior. Named runtime storage shares registered targets across duplicate module copies without crossing SDK instance boundaries.
This deletes Telegram's private server, bind/listen helper, listener shutdown, and server-shaped test fixtures. Tests use a shared registered-route fixture. The plugin keeps its externally configured
webhookUrland callssetWebhookwith that URL; retaining the effective listener makes existing proxy mappings continue to work. Canonical-route conflicts give actionable guidance before opting out.The plugin-owned Doctor transform moves explicit
webhookPort/webhookHostvalues intolegacyWebhook. The shared Doctor writer still owns backups and persistence, and startup uses the existing approved-transform path. Current canonical settings, including false, win. Implicit defaults are runtime-derived; Doctor only explains the Gateway route and opt-out. No eligibility guess, receipt migration, implicit-default removal date, storage schema change, or ingress-spool change is included. The small shared port-migration helper is used by this slice and subsequent channel slices.Evidence
Blacksmith Testbox lease
tbx_01m3e42gap1xnz7hdtze8smgg1, run 36221849561: frozen install, canonical channel/schema/docs generation, and 415 focused cases across 10 files passed. The duplicate-module regression failed on the old code with 401 instead of 200, then passed on the candidate. Tested source treeecfc25e83803db5669c7c7e405c009c469b438c9matches generated-output commit7d82b03dec692b4eb3d57667f9176c362afd7933. The later rebase onto the listener-owner head preserves all four patches; main's ingress-identity reset remains intact.Measured
pnpm test <file> --maxWorkers=1wall costs: webhook 29.446 s (111 cases), routing 15.945 s (16), Doctor 14.897 s (41), accounts 16.618 s (18), schema 1.687 s (29), shared migration 1.309 s (6), channel Doctor 14.980 s (16). Supporting schema/metadata/Doctor-flow suites passed 178 cases; the unchanged full Doctor-flow suite costs 45.579 s including its shared fixture and startup.pnpm plugin-sdk:surface:checkandpnpm plugin-sdk:check-exportspassed. Public surface remains 4,580 exports / 2,688 callables; five local-only helpers are added. Exact base/head API diff passed in 270.759 s, with the intended Telegram config and Doctor contract changes and no removed exports. The Node request/response handler contract is unchanged.pnpm buildpassed in 437.339 s;pnpm check:docspassed in 50.137 s. Telegram's isolated import profiler completed successfully at 166.1 MiB maximum RSS. That profile is screening evidence: build-info still names the pre-generation commit, although the effective source tree is identical to the generated-output commit. It is not represented as native-qualified profile evidence.Deslop and independent Codex reviews are clean after preserving the shipped health, proxy/auth-limit and duplicate-module contracts. Final real-Gateway proof runs after the complete stack merges: all four channels, signed/invalid callbacks, defaults/opt-out, explicit Doctor backups, health-checked proxies, compressed Teams callbacks, restart/shutdown, and the published updater cell. This PR's focused proof is isolated channel-boundary evidence, not live Telegram Test Server evidence.
Candidate integration rehearsal on prepared stack
05d0af090da333cef44930986106b8b7c4cea944(not merged main): Blacksmith Testbox leasetbx_01m3eaktnkepydcc70cvg93mhe, run 36227573437,node /tmp/http-ingress-candidate-rehearsal-05-harness/run.mjs --diagnose-restart, 86.277 s, passed. The harness invokespnpm openclaw gateway run --allow-unconfiguredwith isolated home/state and synthetic vendor fixtures. All four channels accepted valid callbacks and rejected bad signatures with 401 on Gateway and legacy ports, on both starts. Telegram/Feishu/Nextcloud returned durable-admission headers; Teams reached its real message handler with each unique synthetic message. Health-checked Telegram/Nextcloud proxies and gzip/deflate/br Teams callbacks passed. Bad Teams audience, issuer and service-URL claims were rejected. Doctor classified all four listener notes as informational and left implicit keys absent. Both shutdowns were graceful (576/776 ms); the independent census found no remaining owned sockets/processes. Fifteen evidence files are captured and hash-verified. This rehearsal does not replace the required full merged-main opt-out/explicit-migration and published-updater cells.Observed listener census used one Gateway PID for
127.0.0.1:3000,*:3978,127.0.0.1:8787,0.0.0.0:8788, and Gateway127.0.0.1:24891/[::1]:24891. No other Gateway-owned listening port appeared. The Gateway port served all four registered paths.The Telegram Test Server userbot prerequisites are unavailable on this lease:
uvis absent, all existing Convex launchers (including offline npx) report UNAVAILABLE, and the broker environment pair is absent. No credential was leased, and no authentication or installation was attempted. The above is isolated signed-webhook evidence, not live Test Server delivery.Size
Production +455 / -249 / net +206. Tests and helpers +1125 / -366 / net +759. Docs +82 / -10 / net +72. Generated production +5 / -5 / net 0. Growth preserves the shipped callback contract and shared-account handoff while removing the private listener; it is within the coordinator-approved design.
HTTP Ingress Stack
e693324ad36f.11a11ef164d7.84d71bf32329.5b5712e68db8.8864423309d3.5fd7c3d95e03.c5b1eee71843.This PR now targets main after the owner merged. Current head
e0adfaed2439822bf599b4ce9ba537aa234b72f5integrates main002288fc669c50b21e6852ecb9509ca12097b6c6and the verified SDK/type/lint corrections; native prepare/auto-merge runs against main. Each channel is rebased after its predecessor merges. At most two slices are open, and native auto-merge waits for the enforced GitHub gate. Final merged-main proof will be recorded on the last slice.Final dead-code audit: removed private-listener symbols have no remaining references across src, extensions, packages, test, ui and apps. The retained legacy limiter and proxy adapter have active callers and preserve the shipped wire contract; no additional deletion was warranted.
Prior stacked candidate
e0c536d0eb81e374abbccdd6c4eed34204e19f97is rebased onto ownerd222786cbc9f8f7507c864b7dc001c63d8ec6048; all four Telegram commits are patch-identical to reviewedcb0dea59251. Blacksmith Testbox leasetbx_01m3em1agscwth7apgm3gxdkbt, run 36235802177, verified the exact head/tree and 45 input hashes after each phase. Frozen install passed in 2.861 s.pnpm test <file> --maxWorkers=1passed 236 cases across seven files: webhook 110 / 31.711 s; routing 16 / 16.909 s; Doctor 41 / 14.602 s; accounts 18 / 16.837 s; config schema 29 / 1.711 s; SDK legacy migration 6 / 1.353 s; shared channel Doctor 16 / 14.980 s. Prior full suite, SDK/build/docs and completed Codex review remain attributed to their original heads; relevant production inputs are byte-identical to reviewed cb0.SDK source compatibility correction: the v2026.9.6 optional
TelegramAccountConfig.webhookPortand.webhookHostproperties remain as deprecated TypeScript inputs, tracked bychannel-webhook-listener-config-inputsuntil the next Plugin SDK major. Runtime schemas and readers remain canonical; Doctor still removes stored old keys. The existing Doctor fixtures now usesatisfies OpenClawConfig. On retained Blacksmith Testbox leasetbx_01m3em1agscwth7apgm3gxdkbt, the old candidate rejects those actual literals with TS2561/TS2353; restored types compile clean in 29.726 s. Doctor passed 41 cases in 20.494 s; registry passed 12 cases in 2.302 s; focused docs checks passed. Fresh incremental Codex review is scoped-clean P0–P2. Committed correction:3b4b23f54f5a6149bfe8942470a2d1a15f6557ae. Its SDK surface/export checks passed, and canonical base/head API diff passed in 258.763 s with no removed export or entrypoint; both old optional fields remain. Two incidental reachable declaration renderings come from source-identical session modules.Final head integration: main's #158860 retires encoded ingress directories. This slice preserves its production
{stateDir, accountId}API and adapts only HTTP test fixtures to supply both values before per-test overrides. The duplicate-module test retains its explicit public URL. No journal owner implementation is edited. Retired scope references were checked across all shards.On exact
e0adfaed2439822bf599b4ce9ba537aa234b72f5, Blacksmith Testbox leasetbx_01m3evphydkwkf37rb027e791d, run 36242669167: frozen install passed (2.199 s);pnpm test extensions/telegram/src/webhook.test.ts --maxWorkers=1passed 110 cases (35.467 s); routing passed 16 cases (17.699 s);pnpm tsgo:extensions:testpassed (85.443 s); canonical extension lint passed all 17 changed Telegram files (205.554 s, including package-boundary preparation). Head/tree and 52 source hashes remained exact after each phase. Fresh full-branch Codex re-review is scoped-clean P0–P2. Unchanged Doctor/SDK/docs proof retains its original revision attribution. Exact-head CI run36245711479is attached.Owned CI failures were corrected at their source: run
36239178348found a widened boolean table value and two overly narrow logger mocks; run36242095200found a mutating reverse call and shadowed Promise callbacks. Literal typing, runtime-compatible log argument narrowing,toReversed()on the fresh hop array, and distinct callback names fix them without weakening assertions or changing transport behavior. The matching type and lint lanes now pass remotely. Each correction passed Codex review.Final merged-main proof passed on
a6b5ed882cb5e7a10e9346d0e1152878a55653a4: all four channels on Gateway and legacy routes, signature rejection, persistent opt-out, Doctor backups/migrations, health-checked proxies, compressed Teams callbacks and clean shutdown. The actual published 2026.9.6 updater also passed after the separate worker-output repair. Exact commands, Testbox lease IDs, socket matrices, limits and observed results are recorded in the Nextcloud Talk and worker-output PRs linked above.