-
Notifications
You must be signed in to change notification settings - Fork 7.4k
fix: Auto-detect and recover from stale cargo cache (integrated) #9399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Auto-detect and recover from stale cargo cache (integrated) #9399
Conversation
The intent of this change is to eliminate manual intervention when cargo's incremental compilation cache references outdated struct definitions, by integrating stale cache detection directly into the existing build command rather than requiring developers to learn a new script. Current UX Flow (Broken): 1. Developer pulls changes or modifies struct fields 2. Developer runs just build (or cargo build) 3. Build fails with 'no field X on type Y' error 4. Developer must manually diagnose as stale cache 5. Developer must manually run cargo clean -p affected-crate 6. Developer must manually retry build Target UX Flow (Fixed): 1. Developer pulls changes or modifies struct fields 2. Developer runs just build (same command as always) 3. Build detects 'no field...on type' error automatically 4. Build extracts affected crate and cleans it automatically 5. Build retries and succeeds automatically 6. Developer continues without ever knowing there was an issue Implementation: - Integrated into existing 'just build' recipe (no new commands) - Wraps cargo build with error detection and auto-recovery - Extracts crate name from compiler error - Converts snake_case to kebab-case for cargo clean - Falls back to full clean if crate extraction fails - Passes through all build arguments (--release, -p, etc.) Assumptions: - [ ] 'no field...on type' pattern reliably indicates stale cache - [ ] Crate name extraction regex parses error format correctly - [ ] Cleaning affected crate resolves the issue - [ ] Full cargo clean is acceptable fallback - [ ] Developers use 'just build' or can switch to it Location: justfile (build recipe)
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
There was a problem hiding this comment.
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: 728eea6cec
ℹ️ 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".
| AFFECTED_CRATE_KEBAB=$(echo "$AFFECTED_CRATE" | tr '_' '-') | ||
|
|
||
| if [[ -n "$AFFECTED_CRATE_KEBAB" ]]; then | ||
| echo "Detected stale cache, cleaning $AFFECTED_CRATE_KEBAB..." >&2 | ||
| cargo clean -p "$AFFECTED_CRATE_KEBAB" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid cleaning non-package module names from rustc errors
When the compiler reports a missing field on a type in the current crate (e.g., crate::Cli or cli::Cli), the regex above captures the first path segment (crate/cli) and cargo clean -p is invoked with that value. cargo clean --help shows -p/--package expects a package spec, so module names like crate (or cli) are not valid package IDs in this repo (packages are codex-*), which makes cargo clean -p fail and, with set -e, exits before the original compiler error is shown or the build is retried. This makes ordinary compile errors surface as a clean failure instead of the real error. Consider validating the extracted name against workspace package IDs (or skipping -p when it’s crate/self/module) and falling back to cargo clean only when the package lookup succeeds.
Useful? React with 👍 / 👎.
|
@jryanhaber, thanks for the contribution. I left you some questions in the bug report. |
Fixes #9397
Intent
The intent of this PR is to eliminate manual intervention when cargo's incremental compilation cache references outdated struct definitions, by integrating stale cache detection directly into the existing build workflow rather than requiring developers to adopt a new command.
Current UX Flow (Broken)
just build(orcargo build)error[E0609]: no field X on type Ycargo clean -p affected-crateTarget UX Flow (Fixed)
just build(same command as always)Implementation
just buildrecipe (no new commands to learn)codex_tuifromcodex_tui::Cli)cargo cleanif crate extraction fails--release,-p, etc.)Why This Approach
Developers shouldn't need to learn a new command or remember when to use it. The fix is transparent - they use the same
just buildcommand they already know, and stale cache issues are automatically detected and resolved.Testing
Manual reproduction test:
Checklist
just fmt