Skip to content

fix(auto-reply): RawBody command parsing + safer usage save#643

Closed
mcinteerj wants to merge 5 commits intoopenclaw:mainfrom
mcinteerj:fix/session-store-race
Closed

fix(auto-reply): RawBody command parsing + safer usage save#643
mcinteerj wants to merge 5 commits intoopenclaw:mainfrom
mcinteerj:fix/session-store-race

Conversation

@mcinteerj
Copy link
Copy Markdown
Contributor

@mcinteerj mcinteerj commented Jan 10, 2026

Fixes two auto-reply reliability issues:\n\n1) WhatsApp group messages: introduce MsgContext.RawBody (clean message text) and prefer it for command/directive/abort/reset parsing. Keep Body/BodyStripped as the best-available prompt text (may include structural context/history).\n\n2) Fallback runs: reload the session store from disk immediately before persisting usage/model info to reduce clobbering concurrent session updates (e.g. /model during a long run).\n\nIncludes tests covering RawBody parsing and abort/reset triggers.

WhatsApp group messages include structural context (history, sender labels)
in the Body field for LLM context. This caused command detection to fail
when the formatted body did not match exact command strings like "/status".

Changes:
- Add RawBody field to MsgContext for clean message text
- WhatsApp gateway sets RawBody to msg.body (original Baileys message)
- Command detection, directive parsing, abort detection, and reset triggers
  now prefer RawBody over Body
- BodyStripped falls back to RawBody before Body

This separates concerns: Body carries formatted LLM context, RawBody carries
clean text for command matching.

Tests:
- session.test.ts: RawBody extraction, reset triggers, fallback
- abort.test.ts: /stop detection, bare word triggers
- reply.raw-body.test.ts: /think, /model, /status directive parsing

Related: openclaw#638 (RFC: Structured MsgContext and Decomposition of CombinedBody)

Note: Discord has a similar combinedBody pattern that may need the same fix.
@steipete
Copy link
Copy Markdown
Contributor

Thanks Jake!

@steipete steipete self-assigned this Jan 10, 2026
@steipete steipete changed the title Reply: fix session store race condition during fallback fix(auto-reply): RawBody command parsing + safer usage save Jan 10, 2026
@steipete
Copy link
Copy Markdown
Contributor

Pushed follow-up fix (3a32cde): keeps combined prompt context in Body/BodyStripped while using RawBody for command/directive parsing (prevents dropping the history wrapper). Also ran biome formatting so CI lint is green.\n\nLocal gate: pnpm lint && pnpm test && pnpm build.

@steipete
Copy link
Copy Markdown
Contributor

More cleanup + concurrency fix pushed:\n\n- 8451b08: Discord now sets MsgContext.RawBody (message.content/placeholder) so commands/directives don’t get confused by the combined history wrapper.\n- 5852ef6: Replace reload-before-save with a real lock+merge helper (updateSessionStoreEntry) and use it for usage/model persistence in agent-runner + followup-runner; adds regression test + docs {{RawBody}}.

@steipete
Copy link
Copy Markdown
Contributor

Landed on main via e3cd431 (squash/manual). Thanks @mcinteerj!\n\nNotes: = provider-raw inbound text used for command/directive parsing; keeps history+wrapper for LLM context. Session store updates now use lock+merge+save to avoid clobbering concurrent writers.

@steipete steipete closed this Jan 10, 2026
@steipete
Copy link
Copy Markdown
Contributor

Landed on main as e3cd431.

Clarify:

  • RawBody = provider-raw inbound text used for command/directive parsing.
  • Body = history + current message wrapper for LLM context.
  • Session store updates now: lock + load + merge + save (avoids clobbering concurrent writers).

Thanks @mcinteerj!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants