Skip to content

fix: restore missing Telegram replies in conversation context - #179399

Merged
steipete merged 3 commits into
openclaw:mainfrom
sobolevbel:codex/fix-166482-completed-turn-context
Oct 23, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
sobolevbel:codex/fix-166482-completed-turn-context

Conversation

@sobolevbel

@sobolevbel sobolevbel commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Related: #166482

What Problem This Solves

Fixes missing completed Telegram replies in restored conversation context, which can make an already answered request look pending on a later turn.

User Impact

Delivered final answers remain beside their questions when the next turn restores conversation context, preventing this source of repeated answers to old requests.

Why This Change Was Made

The shared recent-text reader discarded confirmed final message-tool replies as delivery bookkeeping. Session-generated chat windows now opt into those replies using the existing terminal-delivery metadata. Native channel windows continue to own their delivery history; progress updates and uncorrelated legacy mirrors remain excluded.

The cache keeps its existing memory-pressure subscription strongly referenced, preserving its behavior on Bun. No SQL schema or storage format changes.

Evidence

The SQLite → channel-turn → rendered-context regression was reproduced against unchanged production: both prior questions remained while both delivered final answers disappeared, for successful and aborted tool-result cases. The candidate tests retain native-window deduplication and verify that reading context does not rewrite stored history.

The focused regression and sibling checks cover the SQLite history reader, channel context restoration, memory-pressure eviction, native-window deduplication, and prompt-prefix stability. Targeted core lint and formatting checks pass. The independent diff review found no actionable P0–P2 findings. Broad local checks pass production and test-graph typechecking, but the unused-export scans report unrelated unchanged exports; exact-head PR CI is tracked below.

Against the merge base: production +9 lines, tests +184 lines, documentation +6 lines. The small production increase adds the explicit opt-in and retains the cache subscription; the simplification pass found no useful adjacent deletion without obscuring those responsibilities.

After merging current main, all 87 tests across seven files pass through the repository runner, including its final source-integrity verification (four Vitest shards, 1300.42 seconds). The two SQLite boundary cases fail on the unchanged base and pass with this fix. Exact-head CI is green on daea9ae482446ee8775364fdd91dbbcf105a76c3 (run 39895471108).

A prior live Telegram run on f4c4222c17b9 recorded the delivered answer exactly once in the next accepted model input; details below preserve that evidence and its head. A fresh live channel round trip was not run in this pass because QA broker credentials are unavailable on the test host. This fix addresses one demonstrated cause of repeated recaps, so the broader issue remains related rather than closed.

Thanks to @sobolevbel for the fix and original proof.

Previously recorded live Telegram + Codex proof on f4c4222

Executed on 2026-10-21 using an isolated Gateway built from f4c4222c17b9e848042df04eb018eefed480a4d6, separate OpenClaw state/workspace/port, disabled cron/heartbeat, and the operator's Telegram bot. A human sent both messages from the real Telegram client. The agent used Codex app-server with an existing ChatGPT subscription. No personal conversation history was copied into the test state.

Sanitized launch shape:

OPENCLAW_STATE_DIR="$PROOF_STATE" pnpm openclaw gateway run --port "$PROOF_PORT"

The two messages were sent in order, waiting for the first answer:

OC179399_TASK_A2. Join the tokens FIXED and 166482 with a colon. Use the message tool with action=send and final=true to send exactly the resulting text to this conversation. Do not send a second visible answer.

OC179399_TASK_B2. A new, unrelated question: what is 2 + 2? Reply with exactly 4.

Observed Telegram replies: FIXED:166482, then only 4. The human confirmed both and supplied a screenshot of the two exchanges. Both turns ran in the same Gateway process, with no restart between them.

The read-only transcript extraction checked the successful Telegram receipt and final delivery mirror, then read B2's message.__openclaw.upstreamUserText. The Codex integration records this from the text inputs of the accepted native turn/start request (request boundary, transcript annotation). The full answer was absent from A2's input, so its later presence cannot be explained by replaying the first question.

Redacted terminal output from that extraction:

{
  "head": "f4c4222c17b9e848042df04eb018eefed480a4d6",
  "transport": "real Telegram Bot API; human Telegram client",
  "runtime": "Codex app-server; existing ChatGPT subscription",
  "sameGatewayProcessAcrossA2B2": true,
  "A2": {
    "inputContainsFullAnswer": false,
    "messageToolCalls": 1,
    "action": "send",
    "final": true,
    "successfulTelegramReceipt": true,
    "receiptHasMessageId": true,
    "finalSourceReplyMirrors": 1,
    "sourceTurnIdPresent": true,
    "toolCallIdMatchesMirror": true,
    "visibleReply": "FIXED:166482"
  },
  "B2": {
    "unrelatedQuestion": "what is 2 + 2?",
    "acceptedCodexTurnInputCaptured": true,
    "restoredSessionLineMatchesMirrorId": true,
    "restoredAssistantAnswerOccurrences": 1,
    "fullAnswerOccurrencesInAcceptedUserInput": 1,
    "acceptedUserInputSha256": "109bb238acd37e09b7c4dbc501d64e86b729a8a8fccd7644bc2a47dc49fd2147",
    "visibleReply": "4",
    "humanConfirmedNoRepeatedOldAnswer": true
  }
}

Accepted B2 input excerpt, with the original mirror ID and timestamp replaced by aliases:

#session:<MIRROR_A2> <timestamp> OpenClaw: FIXED:166482

The extractor verified that this line refers to the actual A2 delivery-mirror event ID, and counted FIXED:166482 once across the entire accepted B2 user input. The exactly-once claim concerns this current input and its restored Conversation context, rather than historical tool-call arguments in the native thread.

Proof boundaries: this is a patched-head live run; the before-fix failure is covered by the committed SQLite → channel-turn → context red/green regression. Restart recovery is not claimed: an earlier optional restart attempt failed before model inference and was excluded. The passing A2 → B2 pair used the ordinary consecutive-turn flow.

Cleanup completed: the original installed Gateway and its configuration were restored and verified healthy, the isolated Gateway and local collector exited, and temporary credential copies and their test backup were removed. Public output omits credentials, IPs, phone numbers, private endpoints, native IDs, and model identifiers.

@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: telegram Channel integration: telegram size: S labels Oct 21, 2026
@sobolevbel
sobolevbel marked this pull request as ready for review October 21, 2026 10:54
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR restores confirmed final message-tool replies in session-generated conversation context and retains the history cache’s memory-pressure subscription.

Example: Telegram delivers FIXED:166482 through message(action=send, final=true), then the user asks what 2 + 2 equals.

  • Before: Restored context contains the earlier request but omits its delivered answer.
  • After: The recorded live run includes FIXED:166482 exactly once in the next accepted model input and replies with 4.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong shipped-path evidence supports a focused, correct repair; the overall tier reflects partial coverage of the broader linked issue.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Recorded live Telegram → isolated Gateway → Codex evidence on f4c4222 correlates a successful final send with its mirror and exactly one restored answer in the next accepted input; visible replies are FIXED:166482 and 4. The subsequent main merge preserves this behavior, with reported current-head regression coverage. Restart recovery is outside the proof’s claim.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: A later Telegram turn can see an earlier question without its delivered final answer and treat completed work as pending.
Reason: The bounded repair addresses a demonstrated failure using existing owners; Related remains appropriate for the broader recap issue.

Merge readiness

✅ Ready for maintainer review

This PR repairs a demonstrated context-loss path still present on main; no actionable introduced defect was found, and exact-head CI remains pending.

Priority: P2
Reviewed head: daea9ae482446ee8775364fdd91dbbcf105a76c3

Before merge

None.

Findings

None.

Agent review details

How this fits together

The shared channel-turn preparation reads recent canonical transcript text and renders bounded conversation context for the next agent request.

flowchart LR
  A[Delivered message-tool reply] --> B[Canonical session transcript]
  B --> C[Recent conversation reader]
  C --> D[Shared channel preparation]
  E[Native channel window] --> D
  D --> F[Rendered agent input]
Loading

Technical review

Best possible solution:

Land the selective restoration through the existing transcript owner once required CI passes, while retaining the broader recap report for other causes.

Do we have a high-confidence way to reproduce the issue?

Current main’s filter demonstrably excludes final source-reply mirrors; supplied SQLite red/green results establish the failing channel-context path, without reviewer execution.

Is this the best way to solve the issue?

The focused opt-in reuses the existing terminal-delivery classifier and snapshot reader while preserving native-window ownership, bounds, and stored transcript bytes.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 19395491ca6a.

Provenance checked

  • Selective transcript context restoration changes intended behavior with a stated reason (ed37774: Restore marked Cron delivery context only when no live chat window survives, keeping ordinary bookkeeping filtered.)
  • Snapshot-owned recent-text filtering keeps the original intent (681c9c8: Select and filter recent conversation text inside one transcript snapshot to prevent concurrent pagination omissions and repetition.)
  • Recent history cache lifecycle keeps the original intent (97a111c: Clear derived history caches under memory pressure while preserving bounded reuse and transcript content; earlier close callbacks release connection-owned cached pages.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 5e651d5 adds src/channels/inbound-event/session-transcript-context.runtime.ts:115 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5e651d5ac76c; files: src/channels/inbound-event/session-transcript-context.runtime.ts)
  • AyitLabs: Raw commit ed37774 adds src/channels/inbound-event/session-transcript-context.runtime.ts:128 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: ed37774f856d; files: src/channels/inbound-event/session-transcript-context.runtime.ts)

PR surface

Source +9, Tests +184, Docs +6. Total +199 across 7 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 26 17 +9
Tests 3 185 1 +184
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 217 18 +199

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Missing delivered answers in restored context can cause repeated responses during otherwise working Telegram conversations.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-21T11:14:05.701Z sha 1234d77edff4c5053ecbf68ad51b9289f0733b4e :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-21T19:37:16.512Z sha f4c4222 :: needs maintainer review before merge. :: none

Reviewed October 22, 2026, 11:38 PM ET / October 23, 2026, 03:38 UTC (Revision 3).

@sobolevbel
sobolevbel force-pushed the codex/fix-166482-completed-turn-context branch from 09149f3 to f4c4222 Compare October 21, 2026 11:30

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added the requested real behavior proof to the PR body for exact head f4c4222c17b9: human-driven Telegram → isolated Gateway → real Codex subscription. A final message send is confirmed by its successful Telegram receipt and correlated delivery mirror; the accepted Codex input for the next unrelated Telegram turn contains that answer exactly once. Visible replies were FIXED:166482, then only 4. The passing pair ran in the same Gateway process. Redacted terminal output and the request-boundary source links are in Evidence; the original Gateway has been restored and temporary credentials removed.

@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 21, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@steipete
steipete merged commit ca3f743 into openclaw:main Oct 23, 2026
151 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
…aw#179399)

* fix: restore missing Telegram replies in conversation context

* fix: retain history cache pressure channel and SQLite test owners
amittell added a commit to amittell/openclaw that referenced this pull request Oct 24, 2026
Keep replay byte bounds with upstream delivered-message context. Preserve
media grounding probes with the current classifier declarations.

This merge includes upstream history-cache pressure-channel retention from
openclaw#179399.
RomneyDa added a commit that referenced this pull request Oct 28, 2026
* fix: restore missing Telegram replies in conversation context

* fix: retain history cache pressure channel and SQLite test owners

Use a private equivalent terminal-source-reply predicate because the donor shared export is absent on this candidate. Keep the current bounded connection-owned history cache unchanged rather than replay donor-only pressure-channel architecture. Retain native-window and SQLite transcript assertions.

(cherry picked from commit ca3f743)
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram clawtributors PR from a clawtributor docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants