Skip to content

Stale incremental cache causes 'no field' compilation errors #9397

@jryanhaber

Description

@jryanhaber

Issue Description

The intent of this report is to document a build failure pattern where cargo's incremental compilation cache references outdated struct definitions after fields are added or modified in workspace crates, causing compilation to fail with 'no field...on type' errors despite the field existing in source.

Current UX Flow (Broken)

  1. Developer pulls changes that modify struct fields (e.g., Cli in codex-tui)
  2. Developer runs cargo build --bin codex
  3. Build fails with error: error[E0609]: no field 'spec' on type 'codex_tui::Cli'
  4. Developer must manually diagnose this as stale cache issue
  5. Developer must manually run cargo clean -p codex-tui
  6. Developer must manually retry build
  7. Build succeeds

Root Cause

When struct definitions change in one crate but cargo's incremental compilation cache for dependent crates is not invalidated, the dependent crates reference the old struct definition from cache. This is most common when:

  • Pulling changes from git
  • Adding/removing struct fields
  • Modifying struct field visibility
  • Working across multiple workspace crates with dependencies

Reproduction

cd codex-rs

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

# 2. Build with new field
cargo build --bin codex

# 3. Remove the field from source

# 4. Clean only codex-cli (not codex-tui)
cargo clean -p codex-cli

# 5. Add field back to source

# 6. Try to build
cargo build --bin codex
# Error: no field `test_field` on type `codex_tui::Cli`

# 7. Manual fix required
cargo clean -p codex-tui
cargo build --bin codex
# Now succeeds

Impact

  • Frequency: Occasional, but blocks all development when it occurs
  • Severity: Medium - has workaround but requires manual diagnosis
  • Affected: All contributors, especially after pulling struct changes
  • Time Cost: 2-5 minutes per occurrence to diagnose and fix

Proposed Solution

A wrapper script that detects the 'no field...on type' error pattern, extracts the affected crate name from compiler output, automatically runs cargo clean -p <crate>, and retries the build.

This would change the UX flow to:

  1. Developer pulls changes
  2. Developer runs build script
  3. Script detects error, cleans cache, retries automatically
  4. Build succeeds without manual intervention

Environment

  • Platform: All (macOS, Linux, Windows)
  • Rust: stable toolchain
  • Workspace: codex-rs monorepo
  • Cargo: Using incremental compilation (default)

Workaround

When encountering 'no field...on type' errors:

cargo clean -p <affected-crate>
cargo build --bin codex

Or for full clean:

cargo clean
cargo build --bin codex

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions