#19716: fix: inject timestamp into channel message agent context (#16442)
size: XS
## Summary
- Channel messages (Telegram, Discord, Signal, iMessage, LINE, Slack) lack timestamps in the agent prompt, breaking time-sensitive features (reminders, "what time is it?", scheduling)
- The envelope timestamp exists in `Body` but `BodyForAgent` is set to raw text, and the prompt reads `BodyForAgent` first — so `Body` is never reached
- This adds timestamp injection in `buildInboundUserContextPrefix()` using `ctx.Timestamp`, matching the `[DOW YYYY-MM-DD HH:MM TZ]` format used by `injectTimestamp()` for TUI/web messages
## Why this approach
All 6 channel handlers set `ctx.Timestamp` from their platform-specific message timestamps, but none of them surface it in the agent prompt. Rather than fixing `BodyForAgent` in each channel handler (6 files), this injects the timestamp centrally in `buildInboundUserContextPrefix()` (2 files).
No double-stamping risk: channel messages set `ctx.Timestamp` but don't go through `injectTimestamp()`; TUI/web messages go through `injectTimestamp()` but never set `ctx.Timestamp`.
## What changes
| File | Change |
|------|--------|
| `src/auto-reply/reply/inbound-meta.ts` | `buildInboundUserContextPrefix()` accepts optional `opts.userTimezone`, prepends `[DOW YYYY-MM-DD HH:MM TZ]` when `ctx.Timestamp` is set |
| `src/auto-reply/reply/get-reply-run.ts` | Passes `cfg.agents.defaults.userTimezone` to the function |
## Test plan
- [x] Built from source, deployed to personal OpenClaw instance (v2026.2.15)
- [x] Verified via Telegram DM — agent correctly sees message timestamp
- [x] No runtime errors after deployment
- [x] Confirmed no double-stamping with TUI/web path
Closes #16442
🤖 Generated with [Claude Code](https://claude.com/claude-code) — AI-assisted, fully tested on a live instance
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Injects a `[DOW YYYY-MM-DD HH:MM TZ]` timestamp prefix into the agent prompt for channel messages (Telegram, Discord, Signal, iMessage, LINE, Slack) by reading `ctx.Timestamp` in `buildInboundUserContextPrefix()`. This fixes #16442 where channel messages lacked time awareness because `BodyForAgent` bypassed the envelope `Body` that contained the timestamp.
- `inbound-meta.ts`: `buildInboundUserContextPrefix()` now accepts an optional `opts.userTimezone` parameter and prepends a formatted timestamp when `ctx.Timestamp` is a positive number. The format matches the existing `injectTimestamp()` output used for TUI/web messages.
- `get-reply-run.ts`: Passes `cfg.agents?.defaults?.userTimezone` as the timezone option.
- No double-stamping risk: channel messages set `ctx.Timestamp` but don't go through `injectTimestamp()`; TUI/web messages go through `injectTimestamp()` but never set `ctx.Timestamp`.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it adds a well-scoped timestamp injection with no risk to existing code paths.
- The change is minimal (26 lines across 2 files), uses existing well-tested utilities (`formatZonedTimestamp`, `resolveUserTimezone`), has proper guards against edge cases, and the code paths are clearly separated to prevent double-stamping. The only reason for not scoring 5 is the absence of unit tests for the new timestamp injection logic.
- No files require special attention.
<sub>Last reviewed commit: 24c8476</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#17017: feat(auto-reply): make agent time-aware with message timestamps
by liuy · 2026-02-15
84.3%
#16403: feat: add readable timestamp to inbound_meta.v1 payload
by mcinteerj · 2026-02-14
81.1%
#15148: auto-reply: add message_time and compact inbound metadata JSON
by detecti1 · 2026-02-13
80.5%
#21271: fix(commands): pass channel/capabilities/shell/os to runtime in com...
by evansantos · 2026-02-19
76.5%
#4878: fix: string/type handling and API fixes (#4537, #4380, #4373, #4547...
by lailoo · 2026-01-30
76.0%
#23184: fix(auto-reply): prevent reminder guard note from leaking into chan...
by lailoo · 2026-02-22
74.6%
#8271: feat(signal): Add full quoted message context support
by ProofOfReach · 2026-02-03
73.9%
#20294: fix(message): thread mediaLocalRoots through channel plugin dispatch
by odrobnik · 2026-02-18
73.9%
#10836: feat(session_status): include ISO-8601 and Unix timestamps for sche...
by jeanlucthumm · 2026-02-07
73.9%
#12358: fix: Sessions format timestamps in sessions_history using userTimezone
by xialonglee · 2026-02-09
73.8%