Skip to content

Conversation

@jryanhaber
Copy link

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)

  1. Developer pulls changes or modifies struct fields
  2. Developer runs just build (or cargo build)
  3. Build fails with error[E0609]: no field X on type Y
  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 to learn)
  • Wraps cargo build with error detection and auto-recovery
  • Extracts crate name from compiler error (e.g., codex_tui from codex_tui::Cli)
  • Converts snake_case to kebab-case for cargo clean compatibility
  • Falls back to full cargo clean if crate extraction fails
  • Passes through all build arguments (--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 build command they already know, and stale cache issues are automatically detected and resolved.

Testing

Manual reproduction test:

cd codex-rs

# 1. Add temporary field to tui/src/cli.rs
#    pub test_field: bool,

# 2. Build successfully
just build --bin codex

# 3. Remove the field, clean cli only, add field back
cargo clean -p codex-cli

# 4. Build with just (auto-recovers)
just build --bin codex
# Detects error, cleans codex-tui, succeeds transparently

Checklist

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)
@github-actions
Copy link
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


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.

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

Comment on lines +21 to +25
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"
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@etraut-openai
Copy link
Collaborator

@jryanhaber, thanks for the contribution. I left you some questions in the bug report.

@etraut-openai etraut-openai added the needs-response Additional information is requested label Jan 17, 2026
@etraut-openai etraut-openai removed the needs-response Additional information is requested label Jan 18, 2026
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.

Stale incremental cache causes 'no field' compilation errors

2 participants