Skip to content

fix: preserve reply context in embedded prompts - #76659

Merged
steipete merged 4 commits into
openclaw:mainfrom
cheechnd:fix/telegram-reply-context-current-turn
May 3, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
cheechnd:fix/telegram-reply-context-current-turn

Conversation

@cheechnd

@cheechnd cheechnd commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • thread explicit current-turn reply context from auto-reply prompt construction through queued/followup embedded runs
  • append only structured reply context to the submitted model prompt while keeping generic runtime context hidden
  • add coverage for reply-context formatting, prompt submission, and handoff into followup runs

Fixes #76419.

Tests

  • pnpm build
  • pnpm vitest run src/auto-reply/reply/get-reply-run.media-only.test.ts --testNamePattern "threads reply context"
  • pnpm vitest run src/agents/pi-embedded-runner/run/runtime-context-prompt.test.ts --testNamePattern "formats explicit reply context|omits empty explicit reply context"

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels May 3, 2026
@clawsweeper

clawsweeper Bot commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The branch threads explicit reply context from auto-reply preparation through embedded run execution, appends a sanitized current-turn reply suffix to model prompts, adds regression coverage and a changelog entry, and includes small test/support cleanup.

Reproducibility: yes. at source level. Current main renders ReplyToBody into the effective prompt, then resolveRuntimeContextPromptParts strips it into runtime context and submits only the clean transcript prompt; I did not perform a live Telegram run.

Next step before merge
No repair job is needed; this PR already contains the focused implementation and I found no actionable code defect for an automated worker.

Security
Cleared: The diff changes prompt assembly and tests without adding dependencies, workflow permissions, secret handling, install hooks, or publish paths.

Review details

Best possible solution:

Land this PR after maintainer review and completed CI, preserving reply context as explicit current-turn prompt data while keeping internal runtime context hidden and image loading scoped to the visible prompt.

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

Yes, at source level. Current main renders ReplyToBody into the effective prompt, then resolveRuntimeContextPromptParts strips it into runtime context and submits only the clean transcript prompt; I did not perform a live Telegram run.

Is this the best way to solve the issue?

Yes. The PR uses a narrow typed current-turn context seam instead of reintroducing arbitrary runtime context into the submitted user prompt, and the follow-up keeps prompt-local image detection on the clean prompt.

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the runtime-context split commit identified by the regression report and added follow-up commits on this branch addressing review feedback. (role: introduced behavior / recent maintainer; confidence: high; commits: e918e5f75cb0, 4d5a50647116, 2317666f7074; files: src/agents/pi-embedded-runner/run/attempt.ts, src/agents/pi-embedded-runner/run/runtime-context-prompt.ts, extensions/codex/src/app-server/approval-bridge.ts)
  • rubencu: The linked issue's prior review cites recent Telegram native quote preservation work on the same Telegram reply-context session path. (role: adjacent Telegram reply-context contributor; confidence: medium; commits: f9146cabfca7; files: extensions/telegram/src/bot-message-context.session.ts)
  • vincentkoc: The linked issue's prior review cites recent inbound metadata/sanitization work on the path that renders ReplyToBody into prompt context. (role: adjacent inbound metadata maintainer; confidence: medium; commits: 6437aa8532f6, 53fde90dc2bb; files: src/auto-reply/reply/inbound-meta.ts)
  • Dash: Current main history shows a same-area embedded-runner touch shortly after the PR base, relevant for merge/review routing around prompt submission behavior. (role: recent adjacent runner maintainer; confidence: low; commits: d35c79edd63b; files: src/agents/pi-embedded-runner/run/attempt.ts)

Remaining risk / open question:

  • I did not run local tests or a live Telegram provider turn because this review had to keep the checkout read-only.
  • Two GitHub check runs were still in progress at the last API read, so merge should wait for final CI status.
  • The branch includes two unrelated test-only expectation adjustments outside the reply-context surface; they look harmless but are still maintainer scope judgment.

Codex review notes: model gpt-5.5, reasoning high; reviewed against d35c79edd63b.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 173a67bf04

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -2737,7 +2742,7 @@ export async function runEmbeddedAttempt(
// Detect and load images referenced in the visible prompt for vision-capable models.
// Images are prompt-local only (pi-like behavior).
const imageResult = await detectAndLoadPromptImages({
prompt: promptSubmission.prompt,
prompt: promptForModel,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Exclude reply-context suffix from image reference scanning

Using promptForModel here makes the image detector parse the appended "Replied message" JSON block as if it were user instructions. Because detectImageReferences matches paths inside quoted strings (e.g. "./foo.png") and [media attached: ...] tokens, a quoted/replied message can trigger local file or media-uri loading and silently attach images to the model call. This only happens on vision-capable models, but in those runs it can leak workspace/local media and change model inputs unexpectedly; scan only the actual user prompt body when resolving image refs.

Useful? React with 👍 / 👎.

@cheechnd
cheechnd force-pushed the fix/telegram-reply-context-current-turn branch from 173a67b to 05520f8 Compare May 3, 2026 12:33
@steipete
steipete force-pushed the fix/telegram-reply-context-current-turn branch from 05520f8 to 0659d77 Compare May 3, 2026 13:41
@steipete
steipete force-pushed the fix/telegram-reply-context-current-turn branch from 0659d77 to 2317666 Compare May 3, 2026 13:53
@steipete
steipete merged commit 39c5bbf into openclaw:main May 3, 2026
109 of 110 checks passed
@steipete

steipete commented May 3, 2026

Copy link
Copy Markdown
Contributor

Landed via rebase onto main.

  • Source head: b315db8
  • Landed commits: abed423, 54c0f98, 95f5b26, 39c5bbf
  • Gate: focused local tests, Testbox vitest.full-core-support-boundary, Testbox pnpm check:changed, GitHub CI green on final head

Thanks @cheechnd!

@cheechnd
cheechnd deleted the fix/telegram-reply-context-current-turn branch May 3, 2026 19:46
lxe pushed a commit to lxe/openclaw that referenced this pull request May 6, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: codex size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram reply context lost after runtime-context prompt split

2 participants