-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Bug: Deferred large files can starve indefinitely under newest-first scan priority #3203
Copy link
Copy link
Closed
Labels
P2Normal priority bug or improvement with limited blast radius.Normal priority bug or improvement with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.This issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.no-staleExempts this issue from stale automation.Exempts this issue from stale automation.
Description
Activity
Metadata
Metadata
Assignees
Labels
P2Normal priority bug or improvement with limited blast radius.Normal priority bug or improvement with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.This issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.no-staleExempts this issue from stale automation.Exempts this issue from stale automation.
Summary
Deferred oversized Codex session files can permanently stall at their first-pass progress when the user's daily session volume consistently consumes the full per-refresh byte budget. The bounded scan mechanism introduced in #2452 correctly defers large files and persists resumable progress, but the newest-first priority order combined with high daily throughput creates a starvation condition where deferred files never receive additional budget.
Environment
~/.codex/sessions/and~/.codex/archived_sessions/Observed behavior
Three files have
scan_complete = 0and have not advanced beyond their first-pass progress:rollout-2026-08-19T19-05-32-*.jsonlrollout-2026-07-14T20-16-33-*.jsonlrollout-2026-08-26T12-45-09-*.jsonlThe 1.1 GB file is stuck at exactly
268,435,456bytes = 2^28 =maxFileBytes(256 MiB), confirming the first pass consumed the per-file budget and stopped. Subsequent refreshes have not advanced it despiteupdated_at_msshowing recent attempts.The 28 MB file at 0.5 MB parsed for 42 days is especially notable — it is well under
maxFileBytesand should complete in a single pass, but the global budget is exhausted by higher-priority (newer) files before it is reached.Root cause analysis
The starvation occurs due to the interaction of three design choices in
CostUsageScanner:maxFileBytes = 268,435,456): each file reads at most 256 MiB per refresh.maxBytesPerRefresh = 536,870,912): all file I/O is capped at 512 MiB per refresh.preferNewestCodexSessionsFirst): files sorted by mtime descending.With ~133 new session files/day (~1 GB), the global 512 MiB budget is consumed by fresh/recently-modified files on every refresh. Deferred files from older dates are queued but never reached:
Suggested fix directions
Reserve a deferred-file budget slice. Split
maxBytesPerRefreshinto e.g. 384 MiB for new/changed files + 128 MiB reserved for deferred-in-progress files. Deferred files with persisted progress > 0 should be served from the reserved slice regardless of priority order. This guarantees forward progress on at least one deferred file per refresh.Age-based priority boost. Track how many refreshes a deferred file has been skipped. After N skips (e.g. 10), promote it above newest-first ordering for one pass. This prevents indefinite starvation while preserving the general newest-first preference.
Small-file fast path. Files under
maxFileBytes(like the 28 MB file stuck at 1.8%) should bypass the deferred queue entirely and be processed in a single pass, since they cannot exceed the per-file budget. The current code appears to defer them when the global budget is exhausted, even though completing them would cost minimal budget.Direction 1 is the most straightforward and guarantees bounded completion time for any corpus size.
Diagnostic data
File characteristics of the 1.1 GB file:
Related issues
Regression test sketch