Repository navigation
fix(telegram): keep reply text visible with pending automation context - #166869
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 changesThis PR keeps Telegram reply text beside its current-message marker when automation or delivery context is added. Example: Reply to “The restore finished.” with “Tldr” while a scheduled digest is pending.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR provides a focused repair for an ordering defect still present on current main. No actionable correctness or security findings remain. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherShared prompt assembly combines inbound conversation metadata, runtime additions, and user text before CLI rendering; structured embedded-runtime fragments and stored user text retain their existing contracts. flowchart LR
A[Telegram quoted reply] --> B[Inbound context]
B --> C[Reply prompt envelope]
D[Pending runtime additions] --> C
C --> E[CLI prompt renderer]
E --> F[Claude CLI]
F --> G[Telegram answer]
Technical reviewBest possible solution: Land the shared ordering repair while retaining separate user text, typed runtime fragments, and existing paragraph rendering. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the failing composition directly: appended context separates the quoted reply header from the space-joined user body; supplied parent/head live observations corroborate it, and no target code was executed during this review. Is this the best way to solve the issue? The repair belongs in the existing shared append owner and envelope assembly, where it fixes all inspected inline callers without introducing another prompt policy or changing embedded fragment semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 53dc08144966. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +9, Tests +85. Total +94 across 4 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, 5:17 PM ET / 21:17 UTC (Revision 4). |
e6f80f6 to
04c41aa
Compare
|
Rebased onto Focused validation on Node 24.19.0: 31 tests passed across |
Live before/after verificationVerified the requested Telegram quoted-reply regression on unchanged PR head The same real sequence ran on both revisions: a leased Telegram Test Server user asked the bot to say “The restore finished.”; a pending synthetic automation event was queued in that conversation without waking another turn; the user replied to the observed bot message with
Both live cases passed their reply-association, prompt-ordering, return-message and cleanup checks. Successful Actions run, harness revision Videos: before first, after second. Each is an inspected 42-second live terminal recording, not a reconstructed Telegram UI. Startup/trailing idle were trimmed; dedicated QA account metadata is visibly redacted. The relevant prompt, user text and bot responses are retained. This is one real sequence per revision, not a statistical claim about all model outputs. The temporary session-only branch, test runtimes, credential scratch and transfer artifacts were removed. No shared workflow or running Team Gateway was changed. pr166869-before.mp4pr166869-after.mp4 |
|
@clawsweeper re-review Live before/after Telegram Test Server + real Claude CLI proof is now attached and linked from the updated PR body: #166869 (comment) . Head remains |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…6869) Keep runtime additions and delivery instructions before inline current-message context so quoted Telegram reply text stays beside its message marker. Preserve existing paragraph joins and structured runtime fragments. Verified with focused regression tests and a live Telegram Test Server → OpenClaw → Claude CLI → Telegram before/after run on the exact parent and reviewed head. Co-authored-by: VACInc <[email protected]>
…logging and tests: 41 conflict files Resolved against base v2026.10.8; each import kept only where the merged file uses it. Ported onto beta.4's reshaped code (the fork change kept, beta.4's mechanism taken): - heartbeat awareness dedupe: beta.4 (openclaw#169622) dropped the pre-send lifecycle recheck (`latest`); the dedupe compares the prepare-time worker read, the post-send re-read is readSessionEntryReadOnlyInWorker with readConsistency "latest". - prompt prelude: openclaw#166869's space-joiner ordering applies to `text`; the fork's version-3 Telegram carrier keeps the paragraph order (no joiner completes it). - directive acks: beta.4 removed the thinking-remap ack; the fork's queue-ack helper stays. - secret redaction: beta.4 (openclaw#169063) removed the registry snapshot scope; the fork's getLongestRegisteredSecretLength loses its scoped branch and its scoped test case. - committed-turn entry read (pending inputs): beta.4 replaced PendingInputScope.incognito with session-actor storage; the read goes through readSessionEntryReadOnlyInWorker. - persisted install records: beta.4 (openclaw#169714) made the reader async; install-persistence and the CLI test mocks use readPersistedInstalledPluginIndexInstallRecordsAsync. - sessions.patch and cron validation mock modules (fork line-cap extractions) take beta.4's readAcpSessionMetaForEntryAsync, cron-session-reader and inference-binding mocks. - test cases beta.4 removed as low-value (openclaw#172040) stay removed; the fork's own cases stay. Native in beta.4, fork side dropped: question-answer custody in prepared-assistant validation (openclaw#169306), the realtime-voice turn exception, the cron host test helper.
…tart-recovery conflicts Takes beta.4 where it carries a fork change natively. Elsewhere it keeps the fork's delta on top of beta.4's code. - Native on beta.4, fork copies dropped: - openclaw#169306 (e353566): session-manager-persistence.ts and session-manager-metadata.worker.ts are byte-identical to beta.4. The fork's session-manager-append-custody.ts pull-forward is deleted; it has no importers left. - openclaw#158161 (177b090): classify.legacy-provider-predicates.test.ts is byte-identical to beta.4, whose corpus carries the same three TGI rows. - runtime-read.ts is beta.4's re-export. The fork's skipInheritance option moves to runtime-read.types.ts, where beta.4 now defines LoadAuthProfileStoreOptions (store.ts and models auth clean pass it). - Fork deltas kept on beta.4's code: - auth-controller.ts: openclaw#93952's withAuthDeadline around beta.4's forceRefresh argument object; the cooldown-probe extraction and its re-export stay (it inlines beta.4's file-local resolveUnavailableAuthReason). - auth-controller.test-support.ts: beta.4's runtime-provider change, which its SIWC tests need, moves into the fork's split-out harness. - failover tests: beta.4's case moves, plus the fork's Anthropic long-context 429 overflow test and its classified-reason 5xx copy test. - assistant-failure.ts: union of imports (recordModelFallbackStop and isPreDispatchToolCallRejectionMessage). - session-store.ts: the fork's per-attempt contextSnapshot ahead of beta.4's buildMainSessionRecoveryAfterAgentRunPatch, so recovery sees its totals. - session-manager-entries.ts: the fork's checkpoint-handle formatter with beta.4's createEntry timestamp. - restart recovery (dispatch, delivery, tests): beta.4's prepareRestartRecoveryDeliveryCurrent and isCurrent structure; the fork's restart-cause wording passes cause to announceRestartRecoveryResumption. - oauth-common-mocks.test-support.ts: beta.4's importOriginal spread, keeping the fork's syncEnvBackedTokenCredentials identity override. - docs/concepts/oauth.md: the fork's dead-grant paragraph in beta.4's wording. - Tests that follow upstream's openclaw#170532 pruning: 3 of the 5 tests in the fork's transcript-file-state.compaction-checkpoint.test.ts are removed, because upstream deleted the same tests; the 2 that remain keep the checkpoint-handle pins. - runtime-context-prompt.ts: the clean merge ran the fork's carrierText through openclaw#166869's joiner-aware append, which puts late context first for a space joiner. The carrier is rendered without a joiner (prompt-prelude.ts), so it gets its own paragraph-order append. The existing joiner test now pins carrierText for both joiners. Not built here (no builds on this host); tsgo and tests run on the M4.
…2 tests) From the qualification fast gate at 81b7e06: - main-session-restart-recovery.test.ts (3): beta.4's case records no restart cause, so the fork's resume prompt claims no restart (7bb739a). The test now pins the fork's no-cause wording instead of upstream's shared note. - main-session-restart-recovery.restart-cause.test.ts (3, fork): beta.4's recovery reads the prepared runtime config. The suite sets and clears the snapshot like main-session-restart-recovery.test.ts does. - main-session-restart-recovery-marking.test.ts (1, fork case): awaits captureRuntimeConfigAsyncReader()() like its beta.4 siblings. - embedded-agent-subscribe.tools.media.test.ts (2, fork): transcript grounding reads through the history worker, which needs the snapshot. - auth-profiles.env-token-sync.test.ts (2, fork): beta.4 admits credential writes only off worker threads, so the file joins vitest.database-worker-core-paths.mjs beside auth-profiles.readonly-sync. - attempt-prompt-context.test.ts (1): the v3 carrier expectations follow openclaw#166869 (a space-joined text gets the system event first, so the header stays last) while the carrier keeps paragraph order. Tests only; no product code changes. Not run here (no tests on this host).
Summary
High Level TLDR
Keep Telegram reply text attached to its current-message marker when scheduled automation events or other runtime context arrive in the same turn. A short reply such as
Tldrmust remain the user's request, rather than looking like the end of an automation notice.What Problem This Solves
Fixes: a Telegram reply can look empty to CLI-backed agents when OpenClaw inserts additional context between the reply header and the user's text.
User Impact
Users can reply to a specific message while unrelated automation context is pending without their words being rendered as part of that context. No configuration or migration is required.
Why This Change Was Made
The shared context-addition owner now preserves the trailing header for contexts that explicitly use an inline space joiner, in both full and resumed prompts. Structured runtime fragments retain their existing order and provenance. Inline delivery directives are placed before inbound context so they cannot interrupt the same header/body boundary. Ordinary paragraph-joined additions retain their existing order.
Related: #151099 addresses the separate embedded-runtime carrier projection and explicitly preserves CLI rendering. This PR fixes the CLI inline rendering when additional context is present.
Root Cause
A live Telegram forum-topic turn, its persisted user message, and the native CLI transcript were inspected. The reply target and user text both arrived, but the submitted prompt had this shape (synthetic text and identifiers):
resolveInboundUserContextPromptJoinerselects a space so the body follows the reply header.buildReplyPromptEnvelopethen adds system events to that context, andbuildCurrentInboundPromptjoins the user body after the new final line. The model consequently treated the current message as empty. The same composition error occurs with message-tool delivery instructions or later runtime additions.Verification
Real behavior proof
The regression exercises the production chain
finalizeInboundContext→buildInboundUserContextPrefix→buildReplyPromptEnvelope→buildCurrentInboundPrompt, the renderer used by CLI preparation. Synthetic fixtures contain no private transcript data.Before the production fix: 4 failed, 36 passed across the two changed test files. Failures cover a scheduled event, a delivery instruction, both together, and a late addition to full/resumed inline context. The ordinary reply and paragraph-joined control cases pass on the baseline.
After the fix, the rendered prompt keeps:
Evidence
Live before/after verification (October 12): Real Telegram Test Server → OpenClaw → Claude CLI → Telegram passed on parent
d401baee6154aec607cc71466c8ed7898b8f0169and this exact head04c41aafc24fa9b34dec3acb58fa2304c08c834c. Before,Tldrwas appended to pending automation text and the bot summarized the unrelated digest. After, the reply marker andTldrremained together and the bot answered “Restore complete.” Inspected before/after videos and source-bound proof. These are real live terminal captures, not Telegram client UI recordings.Exact-head CI: CI run 38134313167 and the required
openclaw/ci-gatepassed for04c41aafc24fa9b34dec3acb58fa2304c08c834c.Supported Node 24.19.0: 124 passed across five files (prompt prelude, runtime-context prompt, inbound metadata, CLI durable-context preparation, and MCP context); 98.92 s total wrapper wall time.
Per-file cost using
pnpm test <file> --maxWorkers=1:prompt-prelude.test.ts10.71 s wall (22 cases);runtime-context-prompt.test.ts1.73 s wall (18 cases). Measured on supported Node 24.19.0. CI seconds pending.node scripts/check-changed.mjs: passed (format, core production types, all 27 core-test type groups, lint, export/cycle checks, and repository guards). Final inline-only refinement also passed a fresh core typecheck, the agents-other/messaging type groups, all 40 tests in the changed suites, and the existing addressed message-tool dispatch test (1 selected case passed).Local correctness and readiness review completed by the authoring agent; no delegated reviewer was launched under the operator's explicit no-delegation instruction.
Formatter microbenchmark on Linux, Node 24.19.0: 10,000 warmup calls, nine alternating samples of 100,000 append/render pairs using the same synthetic context and alternating full/resumed projection. Median baseline 175.8 ms, candidate 180.0 ms. This measures prompt assembly only, not model or Telegram latency.
What was not tested
The October 12 live proof covers one quoted-reply sequence per revision with pending automation context; it is not a statistical model-reliability claim or native Telegram UI capture. Delivery-directive combinations and late full/resumed additions are covered by the focused regression tests rather than separate live roundtrips. The running Team Gateway was not modified or restarted. Initial local worktree checks exposed missing package links and a shared-dependency typecheck guard; local validation used a private frozen-lockfile install with supported Node 24.19.0. No dependency or lockfile change is included.
Repeat the formatter microbenchmark at this PR head
Run with Node 24.19.0 from the checkout. This loads the unchanged production functions from the parent and the candidate, removing TypeScript annotations only.