Repository navigation
Conversation
Greptile SummaryThis PR adds a staleness guard to Confidence Score: 5/5Safe to merge — the feature is well-scoped, logic is correct, and tests cover both new paths and existing regression scenarios. The staleness check is logically sound and properly positioned in the recovery loop. No existing behavior is broken: entries enqueued within the same session are well within the 10-minute window, and retried entries bypass the check entirely. The only finding is a trivial style issue (loop-invariant constant resolved inside the loop), which does not affect correctness. No files require special attention.
|
| Filename | Overview |
|---|---|
| src/infra/outbound/delivery-queue-recovery.ts | Adds staleness check for first-attempt entries during startup recovery. Logic is correct and properly ordered. One minor style issue: maxEntryAgeMs is resolved on every loop iteration rather than once before the loop. |
| src/infra/outbound/delivery-queue.recovery.test.ts | Existing assertions updated for the new skippedStale field; two new tests added covering the stale-skip path and the retried-entry bypass. Both tests are correct and exercise the right conditions. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/infra/outbound/delivery-queue-recovery.ts
Line: 215-216
Comment:
**Constant resolved inside the loop on every iteration**
`maxEntryAgeMs` is derived purely from `opts.maxEntryAgeMs` and never changes between iterations, so it doesn't need to be recomputed in each pass of the loop. Hoist it above the loop alongside `deadline` and `summary`.
```suggestion
const maxEntryAgeMs =
opts.maxEntryAgeMs !== undefined ? opts.maxEntryAgeMs : DEFAULT_MAX_ENTRY_AGE_MS;
for (let i = 0; i < pending.length; i++) {
```
Then remove the two lines inside the loop body.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(delivery-queue): skip stale first-at..." | Re-trigger Greptile
| const maxEntryAgeMs = | ||
| opts.maxEntryAgeMs !== undefined ? opts.maxEntryAgeMs : DEFAULT_MAX_ENTRY_AGE_MS; |
There was a problem hiding this comment.
Constant resolved inside the loop on every iteration
maxEntryAgeMs is derived purely from opts.maxEntryAgeMs and never changes between iterations, so it doesn't need to be recomputed in each pass of the loop. Hoist it above the loop alongside deadline and summary.
| const maxEntryAgeMs = | |
| opts.maxEntryAgeMs !== undefined ? opts.maxEntryAgeMs : DEFAULT_MAX_ENTRY_AGE_MS; | |
| const maxEntryAgeMs = | |
| opts.maxEntryAgeMs !== undefined ? opts.maxEntryAgeMs : DEFAULT_MAX_ENTRY_AGE_MS; | |
| for (let i = 0; i < pending.length; i++) { |
Then remove the two lines inside the loop body.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/infra/outbound/delivery-queue-recovery.ts
Line: 215-216
Comment:
**Constant resolved inside the loop on every iteration**
`maxEntryAgeMs` is derived purely from `opts.maxEntryAgeMs` and never changes between iterations, so it doesn't need to be recomputed in each pass of the loop. Hoist it above the loop alongside `deadline` and `summary`.
```suggestion
const maxEntryAgeMs =
opts.maxEntryAgeMs !== undefined ? opts.maxEntryAgeMs : DEFAULT_MAX_ENTRY_AGE_MS;
for (let i = 0; i < pending.length; i++) {
```
Then remove the two lines inside the loop body.
How can I resolve this? If you propose a fix, please make it concise.|
Rebased onto current main, CI is green. Happy to address any feedback when you get a chance. |
…recovery When the gateway restarts, the delivery queue replays any pending entries from previous runs. This is the intended crash-recovery behavior for messages that genuinely failed to send (network error, provider down, etc.). However, messages enqueued during an active session but not yet sent when the gateway stops — due to an intentional restart or graceful shutdown — are also replayed. These entries have retryCount=0 and no lastAttemptAt, making them indistinguishable from crash survivors. The result is stale, out-of-context messages delivered to users long after the conversation that generated them. This change adds a staleness check: first-attempt entries (retryCount === 0, lastAttemptAt undefined) older than maxEntryAgeMs (default: 10 minutes) are moved to failed/ instead of being replayed. Entries with retryCount > 0 are unaffected — they are legitimate retry candidates regardless of age. The check can be disabled by passing maxEntryAgeMs: 0 to recoverPendingDeliveries.
b74caf3 to
f7c8699
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7c8699eb6
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const isFirstAttempt = entry.retryCount === 0 && entry.lastAttemptAt === undefined; | ||
| if (maxEntryAgeMs > 0 && isFirstAttempt && now - entry.enqueuedAt > maxEntryAgeMs) { |
There was a problem hiding this comment.
Keep stale filtering for budget-deferred first attempts
This stale gate only runs when retryCount === 0, but entries skipped by the recovery time budget are marked via failDelivery(...) in deferRemainingEntriesForBudget, which increments retryCount even though no delivery attempt happened. In a large backlog where maxRecoveryMs is hit, old never-attempted entries will be converted to retryCount > 0, bypass this new stale check on the next startup, and can still be replayed out of context. Consider tracking "attempted" separately (or preserving first-attempt status for budget deferrals) so stale protection still applies after budget rollover.
Useful? React with 👍 / 👎.
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close this PR as superseded: the stale replay problem is real, but the remaining TTL/default/expire-action decision is already tracked in the open canonical issue, and this branch is conflicting, proof-missing, and stale against current recovery safeguards. Canonical path: Close this stale branch and keep the TTL/default/expire-action decision in #16555, then use a fresh current-main PR once maintainers choose the compatibility policy. So I’m closing this here and keeping the remaining discussion on #16555. Review detailsBest possible solution: Close this stale branch and keep the TTL/default/expire-action decision in #16555, then use a fresh current-main PR once maintainers choose the compatibility policy. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main persists Is this the best way to solve the issue? No. The PR is a plausible mitigation, but not the best current solution because the canonical issue still owns the TTL/default/expire-action policy and this branch is stale against current recovery safeguards. Security review: Security review cleared: The diff touches delivery queue runtime and tests only and introduces no dependency, workflow, secret, package, or supply-chain changes. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 4644e0c10256. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper applied the proposed close for this PR.
|
Problem
When the gateway restarts, the delivery queue replays pending entries from previous runs. This is the correct behavior for messages that genuinely failed to send (network errors, provider downtime, etc.).
However, messages that were enqueued but not yet sent when the gateway stopped — due to an intentional restart or graceful shutdown — are also replayed. These entries have
retryCount === 0and nolastAttemptAt, making them indistinguishable from crash survivors. The result: stale, out-of-context messages delivered to users long after the conversation that generated them.Example: A user session generates 5 outbound messages. The gateway restarts before they're sent. On startup, recovery replays all 5 — delivering content from the previous session into the current one.
Solution
Add a staleness check in
recoverPendingDeliveries: first-attempt entries (retryCount === 0,lastAttemptAtundefined) older thanmaxEntryAgeMs(default: 10 minutes) are moved tofailed/instead of being replayed.Entries with
retryCount > 0are unaffected — they are legitimate retry candidates regardless of age (a message that failed to send should keep retrying).The check can be disabled by passing
maxEntryAgeMs: 0torecoverPendingDeliveries.Changes
delivery-queue-recovery.ts: addDEFAULT_MAX_ENTRY_AGE_MS,skippedStalefield toRecoverySummary,maxEntryAgeMsopt torecoverPendingDeliveries, staleness check in recovery loopdelivery-queue.recovery.test.ts: update existingtoEqualassertions for new field, add 2 new tests covering stale skip and retried-entry bypassTests
All 13 tests pass (
pnpm exec vitest run src/infra/outbound/delivery-queue.recovery.test.ts).