Skip to content

perf(sessions): skip settled Codex directory fingerprints - #4815

Open
ScriptedAlchemy wants to merge 9 commits into
masterfrom
fix/4756-skip-settled-codex-directory-fingerprints
Open

ScriptedAlchemy wants to merge 9 commits into
masterfrom
fix/4756-skip-settled-codex-directory-fingerprints

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Refs #4756 — partial historical Codex directory-scan CPU reduction

A Codex discovery pass currently calls codex_directory_witness before enumerating each directory. That helper always runs an additional read_dir, collects every entry name into a Vec, and sorts the names for a fingerprint. For settled historical directories, the idle change probe uses only the native change-time/stat digest and never consumes that fingerprint. Reset/restart catch-up thus repeatedly performs an unnecessary full directory enumeration and sort outside the bounded candidate-walk budget.

Focused source change

  • Retain an entry-name fingerprint only when the native change-time witness is unsettled, where coarse timestamps require comparing names.
  • For settled directories, retain just the native stat witness and skip the redundant enumeration/sort. This removes an O(entries log entries) and O(entries) memory step per settled directory scanned; it does not remove the required bounded traversal of files.
  • If a previously settled directory becomes unsettled, conservatively mark it changed and rebuild its discovery state. Do not assume unchanged coverage without a name witness.

A new Unix behavioral test creates a real dated Codex bucket, establishes a settled witness, verifies the entry-name fingerprint is omitted and unchanged state is accepted, then creates a new rollout and requires change detection. Existing Codex epoch, recent-first, directory-change and restart tests remain applicable.

Evidence and limitations

Source-level review establishes the eliminated duplicate enumeration for settled buckets. No TraceDecay end-to-end CPU or transaction benchmark, and no nonvacuous Bazel Rust pass is claimed: this execution environment has neither a checkout nor Bazel, and hosted draft-PR CI may skip Rust testing. The regression must be run via Bazel and reviewed before merge.

This is a partial mitigation, not Fixes #4756. The durable CodexDiscoveryFrontier still lacks a serialized mid-scan directory position: process-retained ReadDir iterators are lost on restart, so repeated traversal of an unfinished history remains. The 4+ hour re-import, 125–160 ms profile writes, multi-provider continuation, and end-to-end bounded-write targets are unproven. Keep #4756 open. The separate projection-queue repair is in #4793. Both issue-specific PRs are temporarily ready for review so the repository's normally skipped Bazel Linux Rust and Clippy jobs can execute; this does not authorize a merge or claim incident acceptance. The exact-head verification run for this PR is #42505092291. Protected #4776 and Kev/decision-model PRs remain draft, and release #4763 is read-only.

Changes are restricted to the Codex discovery source and its test module. No CI policy, dependency, release, infrastructure, production, credential, or other owner branch changes.

@changeset-bot

changeset-bot Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: bdbc266

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

Copy link
Copy Markdown
Owner Author

Follow-up a1f2a63f — Refs #4756, partial Codex discovery CPU/correctness repair.

Additional cause: During the coarse-clock window, codex_directory_changed computed and sorted the entire directory entry-name fingerprint even when the native directory identity was already different. For a busy Codex bucket, that repeats O(entries log entries) work during idle/historical probes. It could also report unchanged for a native metadata change with the same entry-name set, because the previous unsettled branch compared only names.

Fix: First detect changed native identity in both settled and unsettled windows. Only when the identity is equal and the clock remains unsettled do we compare entry-name fingerprints; an older settled witness without an entry fingerprint remains conservatively invalidated when appropriate. No persistence contracts or worker limits changed.

Regression: A new Unix filesystem test creates a real Codex rollout directory, verifies the coarse-clock path and identical entry fingerprints, then models a previously observed different native identity and requires invalidation. The assertion fails under the prior implementation. The already-added settled-directory and new-rollout checks remain.

Verification: Reviewed the exact commit diff (two files, one parent, non-force exact-head fast-forward). Hosted Bazel CI #42482223482 is queued. There is no nonvacuous Rust/Bazel test result or incident-scale macOS CPU/write measurement yet; draft workflows may skip Rust test jobs. Do not merge or claim full issue acceptance. This PR stays draft and #4756 stays open; durable mid-scan restart continuation remains unresolved. #4793, protected #4776/Kev drafts, release #4763, and other owners' branches were untouched.

Copy link
Copy Markdown
Owner Author

Refs #4756 — exact-head Bazel gate repair, not incident acceptance.

The preceding CI run #42482223482 failed //crates/tracedecay-sessions:rustfmt_check_2024 (repository-gates job 128736441064): the new codex/tests.rs import list needed a single rustfmt wrap. Published d936b861 with that exact two-line adjustment only, using the prior a1f2a63f head as an expected-head nonforce fast-forward. Independently inspected the resulting commit patch: no runtime logic, test assertions, or CI policy changed.

New exact-head CI #42486957234 is queued. Draft workflow Rust tests are not a validated pass; no local Bazel checkout/toolchain or affected macOS performance environment is available. This PR remains draft, and #4756 remains open: durable mid-discovery restart continuation and the reported four-hour CPU/write-cost outcomes are still unproven. Protected #4776/Kev drafts, release #4763, and other owners' branches are untouched.

Refs #4756. Keep the native directory change-time in the negative
metadata witness rather than a fresh per-sample Unvouched nonce.
An unsettled equal stat still requires a name fingerprint; the first
settled probe forces revalidation of an unsettled witness.
Add deterministic regression for repeated filesystem probes.
Refs #4756. Exercise the raw-vs-directory identity distinction on a
real filesystem bucket and use a valid JSONL fixture.

Copy link
Copy Markdown
Owner Author

Refs #4756 — published correction to the hot-directory CPU path (partial fix, not incident acceptance).

I found a correctness/performance regression in the preceding #4815 optimization by tracing codex_directory_changed through the canonical ChangeStamp implementation in tracedecay-private-fs/src/coarse_time.rs: ChangeStamp::Unvouched intentionally contains a fresh per-sample token on every stat. The new early current.stat != stored.stat test thus always reported a changed directory while the clock remained unsettled, even if not one entry had changed. That could restart Codex discovery on each poll and amplify the same high-CPU condition #4756 reports.

Published 6346d7ba and test refinement 12a0e824 with exact-head, non-force fast-forwards. Directory change detection only now hashes a stable raw native change time when the stamp is Unvouched, rather than its process-random token. The existing unsettled-entry fingerprint remains mandatory when the stat is unchanged; the transition to a settled stamp still invalidates the earlier unsettled witness. File-content identity and its conservative nonmatching Unvouched semantics are unchanged.

The regression uses a real filesystem Codex bucket: two distinct Unvouched tokens must differ under file-content identity but agree under the directory's metadata-change identity; a settled transition must still invalidate it. Independent commit comparisons verified only the Codex source and its targeted regression changed; no other owner, CI policy, or release change.

Exact-head Bazel CI is queued. Draft-PR CI may skip Rust execution, and the environment has no Bazel checkout, so nonvacuous Rust tests and incident-scale CPU/write-latency outcomes are not yet proven. Keep this PR draft and #4756 open; durable mid-scan restart continuation and the 125–160 ms write costs remain unresolved.

Refs #4756. The rotating idle probe can revisit the same hot buckets
already checked in the same pass. Advance the rotation without a second
stat or unsettled directory fingerprint; preserve urgent hot change
detection and the complete rotation cycle. Add a filesystem regression
that detects a new rollout when rotation starts on the hot prefix.

Copy link
Copy Markdown
Owner Author

Refs #4756 — focused idle-discovery CPU reduction (partial).

Published 841d2af8 as an exact-old-head, non-force fast-forward. In CodexSource::discover_transcript_paths_with_state, every idle tick already checks the newest/hot directory prefix. The subsequent rotating probe could visit the same directories again during that tick, repeating metadata probes and, within the unsettled filesystem-clock window, a directory-entry enumeration/fingerprint. The rotating cursor now advances past those already-checked hot entries without probing twice. It retains the first hot-prefix check, periodic rotation of other entries, and cycle accounting.

The added real-directory regression covers a new rollout appearing in a hot bucket while the rotating cursor starts there; it requires the earlier hot check to invalidate the complete frontier and subsequent bounded passes to discover the rollout. Only the Codex discovery source and test file changed. The commit diff was separately inspected after publication.

Exact-head CI #42501909517 is queued. This is not a claim of a nonvacuous Bazel Rust pass or incident-scale improvement. Draft-PR CI skips Rust jobs, and a local Bazel checkout is unavailable. Durable mid-scan restart continuation, the 4-hour CPU plateau, and 125–160 ms write latency are still unproven; keep this PR draft and issue #4756 open. Related #4793 and #4806, held #4776/Kev PRs, release #4763, and other owner branches remain untouched.

@ScriptedAlchemy
ScriptedAlchemy marked this pull request as ready for review November 8, 2026 17:27

@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: 2 flags

Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Copy link
Copy Markdown
Owner Author

Refs #4756 — new full-CI verification blocker (no source change).

The first non-draft exact-head Bazel CI #42505092291 compiled this branch and passed //crates/tracedecay-sessions:unit_test (33.7 s), //crates/tracedecay:session_suite (179.8 s), and Clippy. The Linux-fleet suite still failed at unrelated paths: three automation-runner assertions (backend_unconfigured vs scheduler-state expectations), and runtime acceptance's Git preview/apply journey (code_index_convergence_parked). None of these files are changed by #4815. Their status on master has not yet been independently established, so do not label them baseline failures or suppress them. Windows/Linux remaining jobs were still pending at last check; macOS was skipped.

The Codex unit-test pass establishes targeted behavior on this exact head, not durable mid-scan process-restart continuation or the reported multi-hour CPU/write improvement. Do not merge or close #4756 without further proof; no other owner/CI/release paths were changed.

Copy link
Copy Markdown
Owner Author

Refs #4756 — independently confirmed existing master CI blocker (not a source fix).

I compared the completed exact-master Bazel CI at 91c72aba7750a398dd28e83d64bf0c6d6fef4172 (run #42328697300, Linux-fleet job 128270517186) with this PR's exact-head run #42505092291 (Linux-fleet job 128808340262). Both fail the same three //crates/tracedecay:automation_runner_test cases: retained_scheduler_runner_reacquires_after_due_prefilter, scheduler_prefilter_live_lock_wins_over_not_due_summary, and scheduler_trigger_skips_repeat_and_respects_lock_discipline, with backend_unconfigured in the assertion output. That failure family is demonstrably present on master, not introduced exclusively by this two-file Codex patch. Do not suppress, skip, or weaken these tests.

This PR additionally fails runtime_acceptance_suite::runtime_surface_acceptance::git_preview_and_apply_have_real_cli_mcp_runtime_parity with code_index_convergence_parked; that specific failure was not shown on the cited master run, so I am not classifying it as established baseline. The affected Codex sessions unit suite, session integration suite and Clippy passed on #4815's head, but the full CI is still red, and macOS/incident-scale restart and write-latency verification remain missing.

PR remains an unmerged partial Refs #4756 repair, with issue #4756 open. No unrelated owner, protected draft, CI policy, production, or release changes.

Copy link
Copy Markdown
Owner Author

Refs #4756 — newly verified full-CI timeout blocker; no source change.

I read the current master AGENTS.md, issue #4756 (zero issue comments), current #4815 source/tests/reviews, and exact-head CI. The Linux fleet job for #4815 head 841d2af846cb228e05088fa63e0cb380912b7a75 reports //crates/tracedecay-global-db:unit_test TIMEOUT in 301.0s. This is an additional full-suite gate failure beyond the already documented scheduler assertions and Git runtime-acceptance failure. The same target passed in 267.1s on master's Linux fleet job, close to the 300s cutoff. The Codex-only patch changes neither global-db source nor its test target; that does not prove the timeout is unrelated under shared runner load, nor does one comparison justify relaxing the test deadline.

The earlier Codex unit/session integration/Clippy passes remain valid; this timeout means the full //... Rust run is not green. CI #42505092291 still has an in-progress Windows job at this inspection. Do not weaken, skip, or simply raise test limits. Investigate deterministic cost/load or independently reproduce before attributing cause. I did not publish a fix or rerun expensive known-red suites. Durable mid-scan restart progress, observed incident-scale CPU improvement and bounded live profile write latency remain unproven. Keep #4756 open and #4815 unmerged; leave protected #4776 and Kev PRs draft, release #4763 read-only.

Repair three hosted automation_runner_test failures by supplying the
configured executable identity required by the production prefilter.
Use the same identity for the prefilter and retained runner, preserving
manual-schedule, exact-ledger, live-lock and lock-race assertions.

Add a production-prefilter regression for unconfigured refusal,
deduplication and same-occurrence recovery after binding, with zero
backend calls and no effectful terminal. Do not relax backend admission,
change timeouts, or alter the graph publication changes.

Refs #4532
ScriptedAlchemy added a commit that referenced this pull request Nov 8, 2026
Restore the unrelated scheduler fixture file to the current master blob
on this #4374 branch. The identical scheduler repair remains preserved
in the separately owned #4815 branch; do not duplicate its CI/review
surface here. Preserve all Codex admission and regression changes.

Refs #4374

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