fix(cron): refresh stale Current time timestamp on repeated heartbeat runs#45188
fix(cron): refresh stale Current time timestamp on repeated heartbeat runs#45188jackjin1997 wants to merge 2 commits into
Conversation
Greptile SummaryThis PR fixes a stale-timestamp bug in Changes:
One edge case to be aware of: the regex replaces the first Confidence Score: 5/5
Last reviewed commit: ebaee01 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ebaee014d0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const existingTimeRe = /^Current time:.*$/m; | ||
| if (existingTimeRe.test(base)) { | ||
| return base.replace(existingTimeRe, timeLine); |
There was a problem hiding this comment.
Limit replacement to the injected runtime timestamp line
appendCronStyleCurrentTimeLine now replaces the first line that starts with Current time: regardless of where it came from, so any user-authored heartbeat prompt line with that prefix (for example a template or instruction in agents.defaults.heartbeat.prompt, which is passed through by resolveHeartbeatPrompt in src/infra/heartbeat-runner.ts and src/web/auto-reply/heartbeat-runner.ts) gets overwritten on every run. This silently mutates prompt content that is not the stale runtime line the change intended to refresh, and can remove important user instructions; the replacement should be scoped to the known injected timestamp pattern (or append unconditionally) instead of matching any Current time: line.
Useful? React with 👍 / 👎.
ebaee01 to
67dc6e4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 67dc6e4224
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const existingTimeRe = /^Current time:.*$/m; | ||
| if (existingTimeRe.test(base)) { | ||
| return base.replace(existingTimeRe, timeLine); |
There was a problem hiding this comment.
Restrict replacement to generated timestamp lines
The new ^Current time:.*$ match in appendCronStyleCurrentTimeLine replaces the first line with that prefix regardless of where it came from. In heartbeat flows (src/infra/heartbeat-runner.ts and src/web/auto-reply/heartbeat-runner.ts), user-authored prompt text is passed through before this helper runs, so a legitimate instruction line starting with Current time: can be overwritten; if that line appears before the previously injected runtime line, the stale injected timestamp is left untouched. This means repeated runs can still carry stale time context while also mutating user prompt content.
Useful? React with 👍 / 👎.
|
Thanks for the thorough review and the edge-case callout. The concern is valid: if In practice this is unlikely for the callers here ( The two strategies compared:
For the heartbeat/cron use case, avoiding duplicate lines (which the model would see as contradictory) is the higher priority. If it turns out that AGENTS.md-derived content flows into |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 88f17754b7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const existingTimeRe = /^Current time:.*$/m; | ||
| if (existingTimeRe.test(base)) { | ||
| return base.replace(existingTimeRe, timeLine); |
There was a problem hiding this comment.
Restrict timestamp replacement to runtime-generated lines
appendCronStyleCurrentTimeLine now replaces the first line matching Current time: anywhere in the prompt, but in heartbeat paths (src/infra/heartbeat-runner.ts and src/web/auto-reply/heartbeat-runner.ts) this helper is fed user-authored prompt text as well. If a user-defined instruction line starts with that prefix before the previously injected runtime line, this change overwrites the user instruction and leaves the stale generated timestamp later in the prompt unchanged, so repeated runs can still operate with old time context.
Useful? React with 👍 / 👎.
88f1775 to
e45ef80
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e45ef80dea
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const existingTimeRe = /^Current time:.*$/m; | ||
| if (existingTimeRe.test(base)) { | ||
| return base.replace(existingTimeRe, timeLine); |
There was a problem hiding this comment.
Replace only runtime-injected timestamp lines
The new ^Current time:.*$ replacement is broad enough to rewrite user-authored prompt text, not just stale runtime metadata. In heartbeat flows, resolveHeartbeatPrompt(...) passes user-configured prompt content into appendCronStyleCurrentTimeLine (src/infra/heartbeat-runner.ts and src/web/auto-reply/heartbeat-runner.ts), so any instruction line that starts with Current time: gets silently overwritten; if that line appears before an older injected timestamp, the stale timestamp is left unchanged later in the prompt. This mutates user instructions and can still leave outdated time context in repeated runs.
Useful? React with 👍 / 👎.
e45ef80 to
e5a4cd2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5a4cd250e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const existingTimeRe = /^Current time:.*$/m; | ||
| if (existingTimeRe.test(base)) { | ||
| return base.replace(existingTimeRe, timeLine); |
There was a problem hiding this comment.
Restrict timestamp replacement to runtime-injected lines
The new ^Current time:.*$ replacement in appendCronStyleCurrentTimeLine rewrites the first matching line regardless of source, but heartbeat runs pass user-configured prompt text through resolveHeartbeatPrompt in src/infra/heartbeat-runner.ts; if a user instruction line starts with Current time: before the previously injected runtime line, this code overwrites user content and leaves the stale generated timestamp unchanged later in the prompt, so repeated runs can still operate on outdated time context.
Useful? React with 👍 / 👎.
e5a4cd2 to
afe4874
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: afe4874149
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const existingTimeRe = /^Current time:.*$/m; | ||
| if (existingTimeRe.test(base)) { | ||
| return base.replace(existingTimeRe, timeLine); |
There was a problem hiding this comment.
Restrict timestamp replacement to generated runtime lines
appendCronStyleCurrentTimeLine now replaces the first line matching ^Current time: regardless of source, but heartbeat uses user-configured prompt text (resolveHeartbeatPrompt in src/infra/heartbeat-runner.ts:603) and then passes it into this helper (src/infra/heartbeat-runner.ts:727). If a user instruction starts with Current time: (or appears before a previously injected runtime line), this overwrites user-authored content and can leave the stale generated timestamp later in the prompt unchanged, so repeated runs can still carry outdated time context. Fresh evidence: this user-prompt passthrough path is still present in the current tree at those callsites.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7df6d31a0e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const existingTimeRe = /^Current time:.*$/m; | ||
| if (existingTimeRe.test(base)) { | ||
| return base.replace(existingTimeRe, timeLine); |
There was a problem hiding this comment.
Scope timestamp replacement to runtime-injected lines
existingTimeRe matches any line that begins with Current time:, so heartbeat runs can overwrite user-authored prompt content instead of only refreshing the stale runtime metadata line. Fresh evidence: resolveHeartbeatRunPrompt passes user-configured text from resolveHeartbeatPrompt(...) into appendCronStyleCurrentTimeLine(...) (src/infra/heartbeat-runner.ts:603 and src/infra/heartbeat-runner.ts:727), so if a custom prompt includes its own Current time: line before the previously injected line, user instructions are mutated and the stale injected timestamp remains later in the prompt.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d2bbe5e407
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const existingTimeRe = /^Current time:.*$/m; | ||
| if (existingTimeRe.test(base)) { | ||
| return base.replace(existingTimeRe, timeLine); |
There was a problem hiding this comment.
Replace only runtime-injected Current time lines
The new ^Current time:.*$ match rewrites the first line with that prefix regardless of source, so heartbeat runs can overwrite user-authored prompt content instead of refreshing the stale runtime metadata line. Fresh evidence: current heartbeat flows still pass user-configured prompt text into this helper (resolveHeartbeatPrompt(...) in src/infra/heartbeat-runner.ts and extensions/whatsapp/src/auto-reply/heartbeat-runner.ts), so if a custom prompt contains Current time: before an older injected line, user instructions are mutated while the stale generated timestamp remains later in the prompt.
Useful? React with 👍 / 👎.
|
Regarding the repeated bot feedback about timestamp regex scope: The That said, if maintainers prefer a tighter pattern, we could match the full ISO timestamp format: |
f5bde6b to
d155db0
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d155db051b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const existingTimeRe = /^Current time:.*$/m; | ||
| if (existingTimeRe.test(base)) { | ||
| return base.replace(existingTimeRe, timeLine); |
There was a problem hiding this comment.
Restrict replacement to runtime-injected timestamp lines
appendCronStyleCurrentTimeLine now replaces the first line matching ^Current time: regardless of source, but heartbeat paths pass user-authored prompt text into this helper (resolveHeartbeatPrompt(...) in src/infra/heartbeat-runner.ts and extensions/whatsapp/src/auto-reply/heartbeat-runner.ts). If a custom prompt contains its own Current time: instruction before a previously injected runtime line, this code overwrites user content and leaves the stale generated timestamp later in the prompt unchanged, so repeated runs can still execute with outdated time context.
Useful? React with 👍 / 👎.
… runs Replace existing Current time line in-place via regex instead of skipping injection when the prefix is already present. Prevents stale timestamps from persisting across repeated heartbeat/cron runs.
Narrow the regex from `^Current time:.*$` to match the full runtime-generated format ending with `YYYY-MM-DD HH:MM UTC`, preventing accidental overwrites of user-authored lines that start with "Current time:". Add test for the boundary case.
d155db0 to
fb40ddf
Compare
|
Tightened the timestamp regex per the review feedback — now matches the full runtime format ( |
|
Closing — no linked issue and low community engagement. Will revisit if the stale timestamp pattern becomes a reported problem. |
Problem
appendCronStyleCurrentTimeLineinsrc/agents/current-time.tsskips injecting a fresh timestamp if the prompt already containsCurrent time:. In practice, when a heartbeat/cron prompt is built from workspace content or carries over context from a previous run, theCurrent time:line goes stale and is never refreshed — the agent reasons about a time that may be hours old.The same guard exists in
src/auto-reply/reply/post-compaction-context.ts, where a comment already explains it is wrong: "Always append the real runtime timestamp — AGENTS.md content may itself contain 'Current time:' as user-authored text, so we must not gate on that substring."Fix
Replace the early-return guard with an in-place replacement: if a
Current time:line is found, overwrite it with the current timestamp; otherwise append as before.Tests
Added
src/agents/current-time.test.tswith four cases:All 4 tests pass.
pnpm checkclean.