← Back to PRs

#16403: feat: add readable timestamp to inbound_meta.v1 payload

by mcinteerj open 2026-02-14 18:36 View on GitHub →
docs size: M experienced-contributor
#### Summary Agents lose track of real-world time during long chat sessions. The system prompt `## Current Date & Time` is stale after session start, and `timestamp_ms` in chat history is raw epoch milliseconds that agents cannot meaningfully read. This caused incidents like an agent telling a user to go to bed at 7am because it thought it was still nighttime. Adds a `t` field to the `inbound_meta.v1` JSON payload with a tiered format to give agents continuous time awareness without wasting tokens: - **First message or gap ≥ 2hrs**: full date+time — `"t": "Sat 15 Feb 7:13am NZDT"` - **Gap ≥ 90s**: time only — `"t": "7:13am"` - **Gap < 90s**: omit `t` field (save tokens during rapid-fire) - **Max gap 15min**: force time-only inclusion even during extended rapid-fire lobster-biscuit #### Use Cases 1. Agent knows current time on every message without using tools 2. Agent can track time passing during long conversations 3. Token-efficient: skips during rapid-fire, omits timezone on time-only format #### Behavior Changes - `inbound_meta.v1` JSON payload now includes a `t` field (when enabled, which is the default) - New session entry fields: `lastInboundTimeSentAt`, `lastInboundTimeDateSentAt` for tracking - 4 new config fields under `agents.defaults`: - `envelopeInboundTime`: `"on"` | `"off"` (default: `"on"`) - `envelopeInboundTimeSkipMs`: min gap before time-only (default: 90000 = 90s) - `envelopeInboundTimeMaxGapMs`: max gap before forced inclusion (default: 900000 = 15min) - `envelopeInboundTimeDateMs`: gap before full date format (default: 7200000 = 2hrs) #### Existing Functionality Check - [x] I searched the codebase for existing functionality. - Searched for existing time injection in inbound-meta.ts — none exists - Reviewed envelope.ts timestamp/elapsed patterns — followed same config naming conventions - Checked buildTimeSection in system-prompt.ts — deliberately not touched per design #### Alternatives Considered - Heartbeat every 15min injecting time — wasteful, extra LLM calls - Always including timestamp on every message — unnecessary tokens during rapid-fire <90s - Fixing buildTimeSection to include current time — stale after session start - Using session_status tool — agents forget to use it #### Tests 20 tests in `inbound-meta-time.test.ts`: - Time formatting (am/pm, no leading zero, no space) - Full date formatting with timezone abbreviation - All tier transitions (first message, full date, time-only, omit) - Boundary conditions (exactly at skipMs, exactly at dateMs) - Custom config values - Feature disabled - Missing agentDefaults (defaults) All pass. `pnpm lint`, `pnpm build`, `pnpm test` all pass. **Sign-Off** - Models used: claude-opus-4-6 - Submitter effort: agent-built, agent-reviewed - Agent notes: The inbound_meta JSON format should be evaluated by maintainers for token efficiency generally — JSON with keys like `schema`, `channel`, `provider` etc. is verbose. A more compact format could save significant tokens per message. <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR adds a human-readable timestamp (`t` field) to the `inbound_meta.v1` JSON payload to provide agents with continuous time awareness during chat sessions. The implementation uses a tiered format based on message gaps: full date+time for first message or 2hr+ gaps, time-only for 90s+ gaps, and omitted during rapid-fire (< 90s) to save tokens. **Key changes:** - Added `formatInboundTime` and `formatInboundDateTime` helper functions using `Intl.DateTimeFormat` for timezone-aware formatting - Implemented `resolveInboundTime` with tiered logic supporting configurable thresholds - Modified `buildInboundMetaSystemPrompt` to return both prompt string and time result for session tracking reuse - Added session tracking fields (`lastInboundTimeSentAt`, `lastInboundTimeDateSentAt`) to prevent redundant timestamp generation - Added 4 new config fields with Zod validation - Comprehensive test coverage (20 tests) for formatting and all tiering scenarios - Updated documentation with configuration examples **Previous review feedback addressed:** - Fixed unreachable code by reordering maxGap/skipMs checks (maxGap now checked first) - Eliminated duplicate `resolveInboundTime` calls by returning `timeResult` from `buildInboundMetaSystemPrompt` for session tracking reuse The implementation is well-tested, follows existing patterns, and correctly handles edge cases including timezone variations, boundary conditions, and custom configurations. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - All previous review feedback has been addressed correctly, implementation follows existing codebase patterns, comprehensive test coverage validates all edge cases and tiering logic, Zod schema properly validates new config fields, documentation is complete, and the feature is opt-in by default (can be disabled) - No files require special attention <sub>Last reviewed commit: 56d6478</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs