← Back to PRs

#19716: fix: inject timestamp into channel message agent context (#16442)

by chi777 open 2026-02-18 03:41 View on GitHub →
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