openclaw - 💡(How to fix) Fix Session reset: /new prompt drops sender envelope, blocking personalized greetings [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#63295Fetched 2026-04-09 07:55:38
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0

On a bare /new (or /reset) in a channel like Telegram, the agent's first turn receives the BARE_SESSION_RESET_PROMPT_BASE string without the Sender (untrusted metadata) envelope block. This means the LLM has no way to see who just started the session — even though the channel adapter already populated SenderName / SenderId / SenderUsername in sessionCtx.

Net effect: agents cannot personalize the /new greeting (e.g. "Hey David" vs. "Hey, what's your name?") on the first turn. They are forced into a two-turn workaround where Turn 1 asks the name and Turn 2 uses the envelope that finally arrives with the first real user message.

Root Cause

src/auto-reply/reply/get-reply-run.ts around lines 281–300:

```ts const isBareNewOrReset = rawBodyTrimmed === "/new" || rawBodyTrimmed === "/reset"; const isBareSessionReset = isNewSession && ((baseBodyTrimmedRaw.length === 0 && rawBodyTrimmed.length > 0) || isBareNewOrReset); const baseBodyFinal = isBareSessionReset ? buildBareSessionResetPrompt(cfg) : baseBody; const envelopeOptions = resolveEnvelopeFormatOptions(cfg); const inboundUserContext = buildInboundUserContextPrefix( isNewSession ? { ...sessionCtx, /* history stripped */ } : { ...sessionCtx, ThreadStarterBody: undefined }, envelopeOptions, ); const baseBodyForPrompt = isBareSessionReset ? baseBodyFinal // <-- envelope dropped : [inboundUserContext, baseBodyFinal].filter(Boolean).join("\n\n"); ```

The isBareSessionReset branch deliberately throws away inboundUserContext, which is the exact block that contains the sender metadata. buildInboundUserContextPrefix in src/auto-reply/reply/inbound-meta.ts already builds that block correctly from sessionCtx.SenderName / SenderId / SenderUsername, and the Telegram channel adapter populates those fields for /new in extensions/telegram/src/bot-native-commands.ts around lines 870–900.

So everything upstream works — the metadata just gets stripped off at the last step.

Fix Action

Fix / Workaround

Net effect: agents cannot personalize the /new greeting (e.g. "Hey David" vs. "Hey, what's your name?") on the first turn. They are forced into a two-turn workaround where Turn 1 asks the name and Turn 2 uses the envelope that finally arrives with the first real user message.

Unblocks personalized /new greetings for every agent in every channel that populates sender metadata (Telegram confirmed; Discord/iMessage adapters likely already populate the same fields). Today's workaround is a forced two-turn flow in each agent's IDENTITY.md, which is brittle and wastes a turn.

RAW_BUFFERClick to expand / collapse

Summary

On a bare /new (or /reset) in a channel like Telegram, the agent's first turn receives the BARE_SESSION_RESET_PROMPT_BASE string without the Sender (untrusted metadata) envelope block. This means the LLM has no way to see who just started the session — even though the channel adapter already populated SenderName / SenderId / SenderUsername in sessionCtx.

Net effect: agents cannot personalize the /new greeting (e.g. "Hey David" vs. "Hey, what's your name?") on the first turn. They are forced into a two-turn workaround where Turn 1 asks the name and Turn 2 uses the envelope that finally arrives with the first real user message.

Repro

  1. Configure any Telegram agent (e.g. the Divergent Systems bot) with a persona that should greet known senders by name.
  2. From a Telegram account that is in the agent's contacts.json, send /new.
  3. Observe the run jsonl for that turn: the user message contains only the bare reset prompt — no Sender (untrusted metadata): {...} block.
  4. The LLM therefore greets generically ("What's your name?") even though Telegram already knows the sender's id and display name.

Root cause

src/auto-reply/reply/get-reply-run.ts around lines 281–300:

```ts const isBareNewOrReset = rawBodyTrimmed === "/new" || rawBodyTrimmed === "/reset"; const isBareSessionReset = isNewSession && ((baseBodyTrimmedRaw.length === 0 && rawBodyTrimmed.length > 0) || isBareNewOrReset); const baseBodyFinal = isBareSessionReset ? buildBareSessionResetPrompt(cfg) : baseBody; const envelopeOptions = resolveEnvelopeFormatOptions(cfg); const inboundUserContext = buildInboundUserContextPrefix( isNewSession ? { ...sessionCtx, /* history stripped */ } : { ...sessionCtx, ThreadStarterBody: undefined }, envelopeOptions, ); const baseBodyForPrompt = isBareSessionReset ? baseBodyFinal // <-- envelope dropped : [inboundUserContext, baseBodyFinal].filter(Boolean).join("\n\n"); ```

The isBareSessionReset branch deliberately throws away inboundUserContext, which is the exact block that contains the sender metadata. buildInboundUserContextPrefix in src/auto-reply/reply/inbound-meta.ts already builds that block correctly from sessionCtx.SenderName / SenderId / SenderUsername, and the Telegram channel adapter populates those fields for /new in extensions/telegram/src/bot-native-commands.ts around lines 870–900.

So everything upstream works — the metadata just gets stripped off at the last step.

Proposed fix

Always prepend inboundUserContext, even on bare session reset:

```ts const baseBodyForPrompt = [inboundUserContext, baseBodyFinal].filter(Boolean).join("\n\n"); ```

This is a one-liner for the channel reply path. The agent's system prompt already tells the LLM the envelope is untrusted metadata, so no trust boundary changes.

Secondary call site

src/gateway/server-methods/agent.ts around line 525 also calls buildBareSessionResetPrompt(cfg) in the JSON-RPC agent handler, but there is no rich sessionCtx in scope there. Fixing that path would require looking up session origin from the session entry — probably a follow-up.

Impact

Unblocks personalized /new greetings for every agent in every channel that populates sender metadata (Telegram confirmed; Discord/iMessage adapters likely already populate the same fields). Today's workaround is a forced two-turn flow in each agent's IDENTITY.md, which is brittle and wastes a turn.

Environment

  • openclaw b5c597cc66 (local build), behavior also present in upstream/main 9e4f478f86
  • Channel: Telegram (bot-native commands)
  • Observed via DS bot @DivergentSystemsBot

extent analysis

TL;DR

The issue can be fixed by prepending the inboundUserContext to the baseBodyForPrompt, even on bare session reset, to include the sender metadata.

Guidance

  • The root cause of the issue is the deliberate stripping of inboundUserContext in the isBareSessionReset branch, which contains the sender metadata.
  • To fix the issue, update the baseBodyForPrompt assignment to always prepend inboundUserContext, as proposed in the issue: const baseBodyForPrompt = [inboundUserContext, baseBodyFinal].filter(Boolean).join("\n\n");.
  • Verify the fix by checking the run.jsonl for the first turn after sending /new and ensuring that the user message contains the Sender (untrusted metadata) block with the sender's information.
  • Note that this fix only addresses the channel reply path, and a separate fix may be needed for the JSON-RPC agent handler in src/gateway/server-methods/agent.ts.

Example

const baseBodyForPrompt = [inboundUserContext, baseBodyFinal].filter(Boolean).join("\n\n");

Notes

  • The proposed fix assumes that the buildInboundUserContextPrefix function correctly builds the inboundUserContext block from sessionCtx.SenderName / SenderId / SenderUsername.
  • The fix may need to be adapted for other channels or adapters that populate sender metadata differently.

Recommendation

Apply the proposed workaround by updating the baseBodyForPrompt assignment to always prepend inboundUserContext, as this will allow agents to personalize the /new greeting without requiring a two-turn workaround.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING