[codex] defer startup maintenance cleanup#3761
Conversation
Move non-essential interactive startup cleanup for workspace snapshots, tool-output spillover files, and old sessions onto a delayed background maintenance thread so the TUI can reach its first frame without waiting on directory scans or snapshot git pruning. The cleanup behavior remains best-effort and keeps the existing logging; the background pass now records its elapsed time at the startup tracing target for follow-up profiling. Fixes Hmbown#3757. Verification: - cargo fmt - cargo test -p codewhale-tui --bin codewhale-tui --locked prune_older_than - cargo test -p codewhale-tui --bin codewhale-tui --locked startup - cargo build -p codewhale-tui --bin codewhale-tui --locked - cargo test -p codewhale-tui --bin codewhale-tui --locked (one unrelated timeout flake: core::engine::tests::edit_last_turn_preserves_current_mode; passed when rerun in isolation)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f735d945e6
ℹ️ 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".
Address Codex review feedback on PR Hmbown#3761 by keeping deferred startup maintenance from racing first-turn state. Serialize side-git snapshot creation and pruning with a repo-local advisory lock, serialize spillover writes with boot pruning while refreshing reused SHA-addressed files, and preserve a resumed session during background session cleanup. Verification: - cargo fmt --all -- --check - cargo clippy --workspace --all-features --locked -- -D warnings -A clippy::uninlined_format_args -A clippy::too_many_arguments -A clippy::unnecessary_map_or -A clippy::collapsible_if -A clippy::assertions_on_constants - cargo test --workspace --locked - cargo build --release -p codewhale-cli -p codewhale-tui --locked
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: faa70b1457
ℹ️ 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".
Address the second Codex review pass on PR Hmbown#3761. Put all side-git snapshot mutation entrypoints behind the same repo-local advisory lock, including keep-last pruning and unreachable-object pruning. Also preserve resumed sessions by the same prefix semantics accepted by resume loading, with explicit handling for --resume latest. Verification: - cargo fmt --all -- --check - cargo clippy --workspace --all-features --locked -- -D warnings -A clippy::uninlined_format_args -A clippy::too_many_arguments -A clippy::unnecessary_map_or -A clippy::collapsible_if -A clippy::assertions_on_constants - cargo test -p codewhale-tui --bin codewhale-tui --locked cleanup_old_sessions_except_preserves_protected_old_session - cargo test -p codewhale-tui --bin codewhale-tui --locked prune_keep_last_n - cargo test -p codewhale-tui --bin codewhale-tui --locked startup - cargo test --workspace --locked - cargo build --release -p codewhale-cli -p codewhale-tui --locked
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e830f062d6
ℹ️ 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".
Resolve Codex review feedback on the startup cleanup deferral. Move latest-session protection resolution into the maintenance thread so startup does not scan sessions twice. Use a launch-time cutoff for deferred snapshot pruning, with a conservative same-second boundary for git commit timestamps. Treat existing SHA spillover files as cache hits even when refreshing their mtime fails. Validation: - cargo fmt - cargo fmt --all -- --check - git diff --check - cargo test -p codewhale-tui --bin codewhale-tui --locked prune_with_launch_cutoff_keeps_cutoff_second_snapshots - cargo test -p codewhale-tui --bin codewhale-tui --locked prune_with_existing_repo_zero_age_clears_all - cargo test -p codewhale-tui --bin codewhale-tui --locked write_sha_spillover_reuses_existing_file_when_refresh_fails - cargo test -p codewhale-tui --bin codewhale-tui --locked startup - cargo test -p codewhale-tui --bin codewhale-tui --locked prune_keep_last_n - cargo clippy --workspace --all-features --locked -- -D warnings -A clippy::uninlined_format_args -A clippy::too_many_arguments -A clippy::unnecessary_map_or -A clippy::collapsible_if -A clippy::assertions_on_constants - cargo test --workspace --all-features --locked - cargo build --release -p codewhale-cli -p codewhale-tui --locked
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 90fa8a1f3f
ℹ️ 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".
Resolve Codex review feedback on deferred startup maintenance. Keep snapshot pruning on the pre-TUI path because it rewrites side-repo refs and can run GC after snapshot list/restore commands become available. Keep the deferred thread for spillover and session cleanup, and keep latest resume resolution inside that thread. Also make snapshot list/restore/read checks share the side-repo lock, and make SHA spillover cache hits rewrite the content if the file disappears after the optimistic existence check. Validation: - cargo fmt - cargo fmt --all -- --check - git diff --check - cargo test -p codewhale-tui --bin codewhale-tui --locked startup - cargo test -p codewhale-tui --bin codewhale-tui --locked prune_with_existing_repo_zero_age_clears_all - cargo test -p codewhale-tui --bin codewhale-tui --locked restore_reverts_workspace_files - cargo test -p codewhale-tui --bin codewhale-tui --locked list_respects_limit - cargo test -p codewhale-tui --bin codewhale-tui --locked snapshot_and_restore_do_not_move_user_git_head - cargo test -p codewhale-tui --bin codewhale-tui --locked write_sha_spillover_reuses_existing_file_when_refresh_fails - cargo test -p codewhale-tui --bin codewhale-tui --locked write_sha_spillover_refreshes_reused_file_mtime - cargo clippy --workspace --all-features --locked -- -D warnings -A clippy::uninlined_format_args -A clippy::too_many_arguments -A clippy::unnecessary_map_or -A clippy::collapsible_if -A clippy::assertions_on_constants - cargo test --workspace --all-features --locked - cargo build --release -p codewhale-cli -p codewhale-tui --locked
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
Fixes #3757.
This moves the startup cleanup work that does not mutate snapshot refs off the synchronous interactive path:
--resumetarget--resume latestprotection is resolved inside the maintenance thread, avoiding a second pre-frame session scanSnapshot pruning stays before the TUI exposes snapshot list/restore commands because it rewrites side-repo refs and can run GC. The side-repo snapshot operations now share the repo lock across snapshot, prune, list, restore, and workspace comparison paths.
SHA-addressed spillover reuse now refreshes mtimes best-effort, treats read-only existing files as cache hits, and recreates the file if it disappears after the optimistic existence check but before the spillover lock is held.
Validation
Local:
cargo fmtcargo fmt --all -- --checkgit diff --checkcargo test -p codewhale-tui --bin codewhale-tui --locked startupcargo test -p codewhale-tui --bin codewhale-tui --locked prune_with_existing_repo_zero_age_clears_allcargo test -p codewhale-tui --bin codewhale-tui --locked restore_reverts_workspace_filescargo test -p codewhale-tui --bin codewhale-tui --locked list_respects_limitcargo test -p codewhale-tui --bin codewhale-tui --locked snapshot_and_restore_do_not_move_user_git_headcargo test -p codewhale-tui --bin codewhale-tui --locked write_sha_spillover_reuses_existing_file_when_refresh_failscargo test -p codewhale-tui --bin codewhale-tui --locked write_sha_spillover_refreshes_reused_file_mtimecargo clippy --workspace --all-features --locked -- -D warnings -A clippy::uninlined_format_args -A clippy::too_many_arguments -A clippy::unnecessary_map_or -A clippy::collapsible_if -A clippy::assertions_on_constantscargo test --workspace --all-features --lockedcargo build --release -p codewhale-cli -p codewhale-tui --lockedCloud:
eba988c99deba988c99d: no major issues