aft icon indicating copy to clipboard operation
aft copied to clipboard

AFT issue: Since 0.64, aft_inspect Rust diagnostics are permanently PARTIAL ('cargo

Open elmagow opened this issue 3 weeks ago • 5 comments

Description

Since 0.64, aft_inspect Rust diagnostics are permanently PARTIAL ('cargo check completed, but Rust inputs cannot be fingerprinted; diagnostics are provisional') for a whole Cargo workspace because ONE test-only macro uses a dynamic include path: include_str!(concat!("../../tests/fixtures/", $fixture)). source_inputs() in lsp/completed_rust_check.rs returns None for any non-literal include, which aborts fingerprint() for the entire workspace (log: 'rust check fingerprint walk ... examined=637 complete=false last=<that file>'). Expected: degrade for that one file (e.g. treat its directory or the file as always-dirty, or re-run the check) instead of making every diagnostic in the workspace provisional forever. Repro: cargo workspace + any .rs file containing include_str!(concat!("a/", "b.txt")), then aft_inspect scope=<any .rs file> sections=diagnostics.

Environment

  • AFT CLI: v0.64.0
  • AFT binary: 0.64.0
  • OS: darwin arm64
  • Node: v26.13.0

Diagnostics

  • Timestamp: 2026-11-11T11:45:26.776Z
  • AFT CLI: v0.64.0
  • AFT binary this CLI found: 0.64.0 at ~/.cache/aft/bin/v0.64.0/aft (the plugin may run a different one)
  • OS: darwin arm64
  • Node: v26.13.0

OpenCode

  • Host installed: true
  • Host version: 2.2.7
  • Plugin registered: true
  • Plugin version: 0.64.0 (installed: ~/.cache/opencode/npm/@cortexkit/[email protected]/1794395718004/node_modules/@cortexkit/aft-opencode/package.json)
  • AFT enabled: true
  • AFT config parse error: none

Config paths

{
  "configDir": "~/.config/opencode",
  "harnessConfig": "~/.config/opencode/opencode.jsonc",
  "harnessConfigFormat": "jsonc",
  "aftConfig": "~/.config/cortexkit/aft.jsonc",
  "aftConfigFormat": "jsonc",
  "tuiConfig": "~/.config/opencode/tui.json",
  "tuiConfigFormat": "json"
}

AFT flags

{
  "$schema": "https://raw.githubusercontent.com/cortexkit/aft/main/assets/aft.schema.json",
  "bash": {
    "rewrite": true,
    "compress": true,
    "background": true
  },
  "lsp": {
    "servers": {
      "rust": {
        "root_markers": [
          "Cargo.lock",
          ".git"
        ],
        "initialization_options": {
          "procMacro": {
            "enable": false
          },
          "cargo": {
            "buildScripts": {
              "enable": true
            }
          },
          "checkOnSave": false
        }
      }
    }
  },
  "semantic": {
    "backend": "ollama",
    "base_url": "http://localhost:11434",
    "model": "qwen3-embedding:0.6b",
    "query_instruction": "auto",
    "query_timeout_ms": 8000
  },
  "disabled_tools": [],
  "indexes": {
    "trigram": true,
    "semantic": true,
    "callgraph": true
  }
}

Plugin cache

{
  "path": "~/.cache/opencode/npm/@cortexkit/[email protected]/1794395718004",
  "manifestPath": "~/.cache/opencode/npm/@cortexkit/[email protected]/1794395718004/node_modules/@cortexkit/aft-opencode/package.json",
  "cached": "0.64.0",
  "version": "0.64.0",
  "versionSource": "installed",
  "configuredEntry": "@cortexkit/[email protected]",
  "exists": true,
  "cliVersion": "0.64.0"
}

Storage

{
  "path": "~/.local/share/cortexkit/aft",
  "exists": true,
  "accessible": true,
  "sizesByKey": {
    "index": 0,
    "semantic": 182204178,
    "backups": 0,
    "url_cache": 37571,
    "onnxruntime": 0,
    "logs": 5195156
  },
  "legacyDuplication": {
    "totalPartitions": 6,
    "totalBytes": 174786032,
    "byHarness": [
      {
        "harness": "opencode",
        "partitions": 6,
        "bytes": 174786032
      }
    ]
  }
}

ONNX Runtime

{
  "required": false,
  "systemPath": "/opt/homebrew/lib",
  "systemVersion": "1.31.1",
  "systemCompatible": true,
  "ignoredSystemPath": null,
  "ignoredSystemReason": null,
  "cachedPath": null,
  "cachedVersion": null,
  "cachedCompatible": null,
  "platform": "darwin-arm64",
  "installHint": "AFT auto-downloads ONNX Runtime on Apple Silicon",
  "autoDownloadable": true,
  "requirement": ">=1.20"
}

Log file

~/.local/share/cortexkit/aft/logs/aft-plugin.log (5000 KB)

Binary cache

{
  "versions": [
    "v0.60.0",
    "v0.62.0",
    "v0.63.4",
    "v0.63.5",
    "v0.64.0"
  ],
  "totalSize": 539530175,
  "path": "~/.cache/aft/bin",
  "Cached binary for this CLI": "v0.64.0"
}

LSP cache

{
  "npm": {
    "path": "~/.cache/aft/lsp-packages",
    "entries": [
      {
        "name": "@biomejs/biome",
        "path": "~/.cache/aft/lsp-packages/%40biomejs%2Fbiome",
        "size": 78514170
      },
      {
        "name": "svelte-language-server",
        "path": "~/.cache/aft/lsp-packages/svelte-language-server",
        "size": 56029601
      },
      {
        "name": "typescript",
        "path": "~/.cache/aft/lsp-packages/typescript",
        "size": 23625999
      },
      {
        "name": "bash-language-server",
        "path": "~/.cache/aft/lsp-packages/bash-language-server",
        "size": 21788234
      },
      {
        "name": "pyright",
        "path": "~/.cache/aft/lsp-packages/pyright",
        "size": 19632190
      },
      {
        "name": "yaml-language-server",
        "path": "~/.cache/aft/lsp-packages/yaml-language-server",
        "size": 14185019
      },
      {
        "name": "typescript-language-server",
        "path": "~/.cache/aft/lsp-packages/typescript-language-server",
        "size": 2422516
      },
      {
        "name": "clangd/clangd",
        "path": "~/.cache/aft/lsp-packages/clangd%2Fclangd",
        "size": 79
      }
    ],
    "totalSize": 216197808
  },
  "github": {
    "path": "~/.cache/aft/lsp-binaries",
    "entries": [
      {
        "name": "clangd",
        "path": "~/.cache/aft/lsp-binaries/clangd",
        "size": 392202163
      }
    ],
    "totalSize": 392202163
  },
  "totalSize": 608399971
}

Root cause (from reading crates/aft/src/lsp/completed_rust_check.rs)

source_inputs() returns None for any include! / include_str! / include_bytes! whose argument is not a single string literal:

// A generated/dynamic include path is uncertain. Do not guess what
// concat!, env!, or a procedural macro will read from disk.
if values.is_empty() || (values.len() != 1 && !matches!(name, "env" | "option_env")) {
    return None;
}

That None propagates through fingerprint() ((current.included, current.env_keys) = source_inputs(&path, &bytes, deadline)?;), so a single dynamic include anywhere in the workspace makes the whole workspace fingerprint fail. Every later aft_inspect diagnostics call returns:

PARTIAL — diagnostics unknown: rust-analyzer @ .: aft_inspect: cargo check completed, but Rust inputs cannot be fingerprinted; diagnostics are provisional; retry aft_inspect.

Retrying never helps, since the source does not change.

In our workspace the only such call is in a #[cfg(test)] helper macro:

macro_rules! fixture {
    ($fixture:literal) => {
        include_str!(concat!("../../tests/fixtures/<dir>/", $fixture))
    };
}

Relevant log lines (paths shortened)

INFO rust check fingerprint walk root=<workspace> examined=637 complete=false last=<workspace>/crates/<crate>/src/<module>/<file-with-dynamic-include>.rs elapsed_ms=375
INFO rust check fingerprint walk root=<workspace> examined=637 complete=false last=<same file> elapsed_ms=368
INFO rust check fingerprint walk root=<workspace> examined=637 complete=false last=<same file> elapsed_ms=400

The walk ends after 0.4 s, well inside the 2 s / 15 s budgets, so this is not a timeout. These lines first appear right after upgrading to 0.64.0; earlier logs have no rust check fingerprint lines.

Minimal repro

  1. cargo new --lib demo && cd demo && mkdir fixtures && echo hi > fixtures/a.txt
  2. Add to src/lib.rs: pub fn f() -> &'static str { include_str!(concat!("../fixtures/", "a.txt")) }
  3. Open the folder in a harness with AFT 0.64.0 and run aft_inspect with scope: "src/lib.rs", sections: "diagnostics".
  4. Per the code above, the result is always PARTIAL ... Rust inputs cannot be fingerprinted. With the literal "../fixtures/a.txt" instead of the concat!, source_inputs() accepts the file. (This repro follows from the code; I have not built this exact demo crate. The real workspace shows the behaviour every time.)

Expected

A non-literal include should only weaken the fingerprint for that file, not disable the completed-check cache for the whole workspace. For example: treat that file (or the directory it is in) as always-dirty, fall back to an mtime/size stamp of the including file plus a re-check, or evaluate concat! of string literals (and $-literal macro arguments) when every part is a literal.

Full logs omitted on purpose: they contain unrelated private project paths and commands. Happy to share specific lines on request.

elmagow avatar Nov 11 '26 11:11 elmagow

Proposed fix (design, for design-approved)

fingerprint() already treats a directory as a sound input: the hashing loop walks it, and declared_build_input_directory_addition_invalidates_completed_check covers adding a file to one. So a dynamic include does not need to abort the walk. It can resolve to the narrowest file or directory that is known to contain everything it could read.

Change in source_inputs()

Replace the return None for non-literal include arguments with a resolver over the include's token tree:

Include argument Input pushed
"a/b.txt" (today) file a/b.txt
concat!("a/", "b.txt"), all parts string literals file a/b.txt (literals concatenated)
concat!("a/fixtures/", $name) or any non-literal part after a literal prefix directory = the literal prefix up to its last / (a/fixtures/)
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/x") same rules, with env!("CARGO_MANIFEST_DIR") resolved to the directory of the nearest Cargo.toml above the file (its key is still recorded in env_keys)
anything else (no literal prefix, a proc macro, a path outside the workspace root) None, as today

Sketch (inside the existing loop, after values is collected):

enum IncludeTarget { File(String), Dir(String) }

fn include_target(values: &[Node], bytes: &[u8]) -> Option<IncludeTarget> {
    match values {
        [lit] => Some(IncludeTarget::File(string_value(*lit, bytes)?)),
        [name, args] if name.utf8_text(bytes).ok()? == "concat" && args.kind() == "token_tree" => {
            let mut cursor = args.walk();
            let mut prefix = String::new();
            for part in args.named_children(&mut cursor) {
                match string_value(part, bytes) {
                    Some(text) => prefix.push_str(&text),
                    None => {
                        // A metavariable, ident or nested macro: everything after is unknown.
                        let dir = &prefix[..prefix.rfind('/')? + 1];
                        return Some(IncludeTarget::Dir(dir.to_string()));
                    }
                }
            }
            Some(IncludeTarget::File(prefix))
        }
        _ => None,
    }
}

string_value is the existing string_literal / raw_string_literal handling, moved into a helper. Both targets are joined to path.parent() and canonicalized exactly as the literal case is now. A Dir target is accepted only when it stays inside the workspace root, so a short prefix such as "../" cannot make the walk hash an unrelated tree. Within the workspace the cost is bounded by the walk's existing deadline. This needs the root passed into source_inputs(), which does not receive it today.

The same shape covers include! and include_bytes!, and the call inside a macro_rules! body. In tree-sitter-rust both forms give a token tree whose named children are identifier("concat") followed by a token_tree; the ! is anonymous.

Why this is sound

Every file the include can read lies under the pushed directory, and any edit, addition or removal there changes the fingerprint, so a completed check is never reused against changed inputs. The only cost is extra invalidations when an unrelated file in that directory changes, which is far cheaper than today, where no check is ever trusted.

Tests (next to included_non_rust_input_edit_invalidates_completed_check)

  1. include_str!(concat!("data/", "a.txt")): fingerprint completes, and editing data/a.txt invalidates.
  2. macro_rules! f { ($n:literal) => { include_str!(concat!("data/", $n)) } }: fingerprint completes; editing, adding or removing a file in data/ invalidates; editing a file outside data/ does not.
  3. concat!(env!("CARGO_MANIFEST_DIR"), "/data/", $n) resolves to <member>/data/.
  4. include_str!(some_macro!()) and a prefix that escapes the root still return None, unchanged.

Happy to open a draft PR with this once the approach is agreed.

elmagow avatar Nov 11 '26 12:11 elmagow

Thanks for the precise report. The diagnosis is right: source_inputs gives up on any include!, include_str! or include_bytes! whose argument is not a single string literal, and that one None makes the whole workspace's fingerprint fail, so every Rust diagnostic stays provisional.

The fix we plan keeps the uncertainty to the file that has it:

  • concat! of string literals, and env!("CARGO_MANIFEST_DIR") inside it, resolve to the exact path.
  • When the path starts with a literal directory, as in your concat!("../../tests/fixtures/<dir>/", $fixture), AFT fingerprints every file under that directory instead of guessing which one the macro reads.
  • Only an include with no literal part left to anchor it still makes the result provisional, and the reply will name that file.

aft-alfonso[bot] avatar Nov 11 '26 12:11 aft-alfonso[bot]

Fixed in v0.65.0, released today: Rust diagnostics no longer stay "provisional" when a macro includes files through a computed path. Thanks for the report. If you still see it after updating, reply here and we'll reopen.

aft-alfonso[bot] avatar Nov 14 '26 10:11 aft-alfonso[bot]

Thanks for the quick fix. On v0.65.0 our workspace is still provisional: the fingerprint walk stops at the same file (examined=642 complete=false last=<that file>). The cause is one step further than the case in the tests.

Our macro takes an ident parameter besides the path one:

macro_rules! fixture_test {
    ($name:ident, $fixture:expr, $expr:expr) => {
        #[test]
        fn $name() {
            let expected = include_str!(concat!("../../tests/fixtures/<dir>/", $fixture));
            // ...
        }
    };
}

fixture_test!(case_a, "a.json", make_a());

parameters() in completed_rust_check/inputs.rs accepts only literal and expr fragments and returns None for anything else. So definition.parameters is None, and every invocation then hits the definition.parameters.is_none() refusal, even though $name never appears inside the include_str! arguments.

Possible fix: record the parameter's fragment kind instead of rejecting other kinds outright. Refuse only when a parameter that is not literal or expr is used inside an include's arguments. Parameters only used elsewhere in the body (ident for a test name, ty, tt, block, ...) cannot change the include path, so they need not make the definition unresolvable. The binding step would then skip those positions in the invocation's arguments by count, as it does for the positions it already maps.

Regression test idea: the existing reporter_fixture_macro_tracks_all_literal_invocations_across_files with the matcher changed to ($name:ident, $fixture:literal) => { const $name: &str = include_str!(concat!("../../tests/fixtures/", $fixture)); }. It should still track exactly a.txt and b.txt.

elmagow avatar Nov 14 '26 16:11 elmagow

Moved to #1453, since this issue is closed.

elmagow avatar Nov 14 '26 16:11 elmagow