Skip to content

perf(sessions): bound flat Codex directory entry traversal - #4857

Open
ScriptedAlchemy wants to merge 4 commits into
masterfrom
fix/4756-codex-directory-entry-budget-20261110
Open

ScriptedAlchemy wants to merge 4 commits into
masterfrom
fix/4756-codex-directory-entry-budget-20261110

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Refs #4756 — partial Codex directory-work bound (not Fixes)

Root cause and focused correction

The initial CodexScanPhase::Directories phase charged queued and discovered subdirectories against its per-turn budget, but did not charge ordinary directory entries read from ReadDir. A flat ~/.codex/archived_sessions directory containing many .zst or other non-directory names could therefore be fully enumerated by one scheduler call, before the separately bounded file-candidate phase. The reported corpus includes 1,385 Codex .zst entries; those entries are not accepted as JSONL transcripts by this reader, so their enumeration should not monopolize a tick.

The source now counts every entry consumed from the structural ReadDir iterator against its own max_files × (MAX_SCAN_DEPTH+2) work window. When the limit is reached, the existing process-owned iterator remains intact for the next call. Child-directory structural work and the candidate-file phase retain their independent existing limits. There is no new format, scheduler, durable storage, or SQL writer behavior.

Nonvacuous behavioral regression

A real filesystem fixture creates 64 ignored .zst entries and one admitted .jsonl in a flat archived Codex directory, then runs max_files=1 discovery. The first call must yield inside the directory phase with its live iterator retained, rather than consuming the archive and entering the file phase in one call; the previous implementation fails this assertion. Repeated bounded calls must converge on exactly the eligible JSONL file and earn the complete frontier, with an empty subsequent idle pass. No other test or assertion was removed.

Verification and boundaries

Kev/decision-model PRs and mixed #4776 remain DRAFT / never merge or auto-merge; release #4763 read-only. No production deployment, infrastructure, tags, credentials, Kody/Copilot/delegation, weakened CI, other owner edits or schedule changes.


Devin Review

Refs #4756

A flat archived directory with many .zst/non-JSONL entries previously
consumed its entire ReadDir iterator in one structural scan turn, outside
the directory-work budget. Charge directory entries independently of child
directory traversal while retaining the iterator across turns.

Add a real archived-directory regression requiring the first scan to yield
in the directory phase, then converge on exactly the eligible JSONL path.

Partial performance repair only; durable restart continuation and affected
host CPU/write-latency acceptance remain outstanding.
@changeset-bot

changeset-bot Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3912dd4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Refs #4756

Keep unsettled directory name witnesses scoped to traversable child
buckets and JSONL candidate paths. Compressed rollouts and other ignored
file churn must not independently invalidate the candidate witness.

Cover ignored additions and renames, candidate admission, and child
bucket discovery with a real-filesystem regression.

Copy link
Copy Markdown
Owner Author

Refs #4756 — follow-up Codex discovery witness repair (partial)

Published 0390a59ed by exact expected-old-head 835291a and non-force fast-forward on this existing issue-specific PR. The commit touches only codex.rs and its existing Rust discovery tests.

Cause and change: Even after limiting structural ReadDir entries per scheduler turn, the unsettled-directory name fingerprint still collected and sorted every entry, including ignored compressed .jsonl.zst rollouts. A coarse timestamp that did not change would then treat churn in those ignored names as candidate-corpus mutation, forcing an unnecessary historical validation sweep. The fingerprint now retains only traversable child directories and names with the exact .jsonl extension accepted by the file-candidate phase. A .jsonl symlink remains tracked, and a new child directory remains tracked. Native stat/change-time invalidation remains authoritative.

Nonvacuous filesystem regression: 128 ignored .jsonl.zst additions and an ignored rename preserve the candidate fingerprint; adding and removing an eligible .jsonl changes/restores it; adding a child directory changes it. The old implementation fails the first assertion. No test or CI gate was weakened.

Detached exact diff is one commit ahead, two files, +46/-1; independently checked the diff and branch head. Exact-head Bazel CI run 42769750119 was queued at inspection; there is no local checkout or Bazel executable, so no Rust test pass or incident-scale performance measurement is claimed. No Cargo used.

This is not Fixes #4756. The process-held ReadDir position still does not survive daemon restart; multi-hour CPU/writer-latency acceptance remains unproven. Keep #4756 open and this PR unmerged pending those proofs. #4793, mixed draft #4776, Kev/decision-model drafts, release #4763, other branches, and task schedules were untouched.

Refs #4756

Apply the two exact formatting hunks emitted by Bazel CI; preserve every behavioral test assertion.

Copy link
Copy Markdown
Owner Author

Refs #4756 — CI repair published as b71eb2b on this issue-specific PR.

The exact preceding-head Bazel run #42769750119 failed //crates/tracedecay-sessions:rustfmt_check_2024. Its log emitted exactly two formatting hunks in codex/tests.rs (the 128-archive and 64-archive fixture writes). Applied those hunks without changing source behavior or test assertions. GitHub compare independently confirms one commit, one file, exact parent 0390a59e, and the branch update used expected_sha=0390a59e, force=false.

New exact-head hosted Bazel run #42775257282 is queued. No Rust test pass, durable mid-directory restart-continuation proof, or incident-scale CPU/SQLite write-latency acceptance is claimed. This remains Refs #4756; keep the issue open and PR unmerged. The unrelated projection-queue lane #4793 currently has Linux global-db timeout/MCP failures on its preceding head and was not modified; protected #4776/Kev drafts, release #4763, CI policies and peer branches remain untouched.

Copy link
Copy Markdown
Owner Author

Refs #4756 — eliminate eager full-archive name enumeration (partial)

Published 3912dd4255e3 to this issue-specific branch via an exact-head, nonforce fast-forward from b71eb2bfee4e1aee8f7c22f0f74cc97cc76248ab.

Root cause: the recently bounded structural ReadDir walk still called codex_directory_witness first. An unsettled directory synchronously enumerated every entry and sorted all eligible names to build its idle-change witness before the entry budget was enforced. A flat archive therefore still had an unbounded preliminary traversal.

Source fix: obtain the native directory identity only; retain an incremental, constant-memory, order-independent candidate-name digest on the same ReadDir iterator that is already sliced by the structural work budget. Publish the completed name witness to the retained directory authority only after the iterator reaches EOF. The standalone idle-check fingerprint uses the same digest algorithm. Ignored .zst entries remain excluded from candidate identity; eligible .jsonl files and subdirectories remain included.

New real-filesystem regression: create 128 ignored .jsonl.zst archive entries plus one eligible JSONL file under an unsettled directory; assert that the first bounded pass retains an unfinished iterator without an eager name fingerprint, that later passes cover the exact JSONL file, and that the final retained name witness equals an independent full enumeration. No assertions or CI gates were weakened.

Review: independent GitHub compare verifies one commit with only codex.rs and codex/tests.rs changed (112/38 and 75/0 insertions/deletions respectively), and a direct parent of the reviewed branch head. Exact-head Bazel CI is queued; no Rust test pass or incident-scale performance result is claimed. No Cargo used.

This specifically removes the eager unbounded name-scan before bounded initial discovery; idle unsettled-directory rechecks, durable mid-directory restart continuation, and measured 4-hour CPU / SQLite write latency acceptance are not yet proved. Keep #4756 open, retain Refs #4756, and do not merge on this evidence alone. #4793, protected Kev/decision-model and mixed #4776 drafts, release #4763, other branches and schedules were untouched.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant