Skip to content

[codex] defer startup maintenance cleanup#3761

Open
nightt5879 wants to merge 5 commits into
Hmbown:mainfrom
nightt5879:nightt5879/issue-3757-startup-defer
Open

[codex] defer startup maintenance cleanup#3761
nightt5879 wants to merge 5 commits into
Hmbown:mainfrom
nightt5879:nightt5879/issue-3757-startup-defer

Conversation

@nightt5879

@nightt5879 nightt5879 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3757.

This moves the startup cleanup work that does not mutate snapshot refs off the synchronous interactive path:

  • stale tool-output spillover pruning now runs in a delayed best-effort maintenance thread
  • old saved-session cleanup now runs in that thread and protects the active --resume target
  • --resume latest protection is resolved inside the maintenance thread, avoiding a second pre-frame session scan

Snapshot 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 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

Cloud:

  • CI green on eba988c99d
  • Claude review passed
  • Codex review on eba988c99d: no major issues
  • All Codex review threads resolved

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)
@nightt5879 nightt5879 marked this pull request as ready for review June 29, 2026 02:51
@nightt5879 nightt5879 requested a review from Hmbown as a code owner June 29, 2026 02:51

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread crates/tui/src/main.rs Outdated
Comment thread crates/tui/src/main.rs
Comment thread crates/tui/src/main.rs Outdated
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
@nightt5879

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread crates/tui/src/main.rs
Comment thread crates/tui/src/main.rs Outdated
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
@nightt5879

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread crates/tui/src/main.rs
Comment thread crates/tui/src/main.rs
Comment thread crates/tui/src/tools/truncate.rs Outdated
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
@nightt5879

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread crates/tui/src/tools/truncate.rs Outdated
Comment thread crates/tui/src/main.rs Outdated
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
@nightt5879

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: eba988c99d

ℹ️ 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".

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.

v0.8.67: Launch is slow; profile and remove startup inefficiency

1 participant