Repository navigation
refactor(telegram): merge dispatch controllers into one turn module - #122091
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
438e656 to
cc76476
Compare
Telegram E2E proof (exact head cc7647618afdd06552b1cf9a01e662bcf83e0762)Live drive via the QA userbot lane (TDLib user observer, completions-fixture mock provider, ephemeral gateway from this head; DM;
No Recorded gap, per the review's next-step: the suppressed exec-approval path (H2) has no live mock fixture, so it is pinned by the front-door regression in Artifacts (events NDJSON with raw TDLib updates, summary, scoped gateway log) retained locally. |
Unify draft, progress, delivery, and reply ownership around one dispatch turn record. Remove construction back-edges and fix generation, queued-final, and collapse-summary hazards.
cc76476 to
d2307b4
Compare
The command-menu locale ledger reads state.openKeyedStore during hydration; the fixture's partial runtime stub lacked it, so the degrade warning broke both claim-watchdog cancellation tests on main. Provision it like the dispatch harness does. Surfaced by #122091's follow-up work; suite runs locally only (see #122029 decision). Co-Authored-By: Claude Fable 5 <[email protected]>
…penclaw#122091) The four Telegram dispatch controllers were partitions of one closure: ~75 factory parameter slots, 7 post-construction back-edge setters, a shared mutable state bag, and load-bearing construction order. One turn record now carries the once-resolved config and all state; the four files remain as implementation with a hand-written leaf type contract (four state-slice types). Rides along: dead generation fence deleted (constant-0 from birth), queuedFinal ||= fix with regression (suppressed exec-approval turns no longer trigger a spurious fallback), collapse resolver/mutator split. Dispatch tests and harness byte-identical to main; live E2E lifecycle proof on the PR. Co-authored-by: Ayaan Zaidi <[email protected]>
The command-menu locale ledger reads state.openKeyedStore during hydration; the fixture's partial runtime stub lacked it, so the degrade warning broke both claim-watchdog cancellation tests on main. Provision it like the dispatch harness does. Surfaced by openclaw#122091's follow-up work; suite runs locally only (see openclaw#122029 decision). Co-Authored-By: Claude Fable 5 <[email protected]>
What Problem This Solves
The four Telegram dispatch "controllers" (
bot-message-dispatch-{draft,progress,delivery,reply}) were partitions of one closure pretending to be modules: ~75 parameter slots across five factory signatures, ~12 config fields copied into multiple constructors, a shared mutableTelegramDispatchTurnState, and seven post-construction back-edge setters whose only reason to exist was the module boundary. Construction order was load-bearing (draft's no-op defaults silently absorbed misordering) with nothing asserting it.dispatchTelegramMessagewas already the only production entry point; the internal shape just didn't match that fact.Why This Change Was Made
One
turnrecord now carries the once-resolved config and all turn state; the four files remain as implementation of that single module (plain functions over the turn record), with the factories, option bags, and every setter deleted. Three latent hazards found during the mapping are fixed in the same change:dispatchGenerationwas introduced as a constant0(verified via history), so the buffered-final generation guard could never reject; the whole fence is deleted.runTelegramDispatchTurnunconditionally overwrotestate.queuedFinal, clobbering the reply-side write for suppressed exec-approval prompts; now||=, with a regression test proven to fail on the pre-fix code (one unwanted fallback delivery).resolveCollapseSummaryLinemutatedsummaryDeliveredas a side effect of a resolver; split into a pure resolver plus explicit marks at both consumption sites.User Impact
None intended: behavior-neutral restructure. The acceptance gate makes that checkable — all 17
bot-message-dispatch*test files and the 745-line test harness are byte-identical to main and pass unchanged (247/247). H2 is the one deliberate behavior fix (suppressed exec-approval turns no longer trigger a spurious "no response" fallback).Evidence
bot.test.ts: 18 files, 387 tests green on the exact head; dispatch tests/harness zero-diff vs main.bot.test.ts's three reply-controller tests rewritten through thedispatchTelegramMessagefront door (the deleted factory was their only consumer).||=to assignment fails exactly the new regression.pnpm tsgo:extensions,pnpm check:test-types, oxlint (all touched files incl. tests),git diff --check: clean.TelegramDraftStateSlice16 members, progress 11, delivery 8, reply 4) inbot-message-dispatch.types.ts, now a leaf module with zero imports from implementations (repo madge leaf-contract rule). This replacesReturnType<typeof create*>derived types — the exact interface-is-whatever-the-implementation-returns anti-pattern this refactor exists to kill. What got deleted is interface, not lines: 4 factories, ~75 parameter slots, 7 back-edge setters, the shared mutable state bag, and the dead generation fence.bot-message-dispatch-progress.tskeeps main's centralized text-delivery behavior with the turn-record structure re-applied.