WhyVec is becoming a causal debugger for compiler decisions.
Compilers describe the final program they received. WhyVec executes controlled counterfactuals to answer two questions they generally do not answer directly:
Which tested change is sufficient to produce this compiler failure?
Which tested compiler assumption is sufficient to change this optimization decision under the recorded toolchain, target, flags, and pipeline?
The LLVM alias/trip-count analyzer remains the first deep optimization pack. It now runs inside an adapter-aware experiment architecture alongside build-causality queries. Executable fixtures cover Clang 21 and rustc 1.96.1 with LLVM 22; every result records whether its optimizer pipeline is exact, independently confirmed, or only a surrogate.
The full re-foundation and defect register live in docs/REFOUNDATION_AUDIT.md.
The local install places the Rust CLI and both pinned-LLVM helpers together:
cargo install --path crates/whyvec-cli --root .local
python3 scripts/build_helpers.py --output .local/bin
.local/bin/whyvec doctorConfigure any CMake project with CMAKE_EXPORT_COMPILE_COMMANDS=ON, then use one
normal command; no function name, LLVM parameter index, or helper path is
required:
whyvec analyze path/to/source.c:LINEThe complete executable demonstration is:
./scripts/demoIt installs/uses the WhyVec Codex plugin, hands over a fresh agent packet, and
runs the model-authored candidate through differential, mutation, sanitizer,
structured-record, and benchmark gates. ./scripts/demo --ci reruns the same
compiler and validation workflow using the exact retained candidate from the
actual installed-skill session. The pinned judge image is built and executed by
containers/judge/build.sh.
The executable build query supports Cargo/rustc, direct Clang and GCC translation units, and TypeScript projects:
cargo run -p whyvec-cli -- explain-build \
--base HEAD \
--diagnostic E0308 \
--at src/lib.rs \
-- cargo checkWhyVec verifies that the base passes, reconstructs the working-tree change in isolated detached worktrees, identifies sufficient changed-file sets for the selected rustc diagnostic, refines successful text files into independently tested Rust syntax-item groups backed by exact Git hunks, and then removes each sufficient set from the full patch to measure which diagnostics disappear with it. See Build causality for the evidence model and refusal surface.
Every completed query retains content-digested intervention snapshots and raw compiler streams. Re-execute and compare the normalized semantic result with:
whyvec replay-build .whyvec/analyses/<analysis-id>/report.jsonTypeScript uses the pinned compiler API adapter:
cd tools/typescript-adapter && npm ci
whyvec explain-build --diagnostic TS2345 --at src/consumer.ts \
-- whyvec-typescript tsconfig.jsonGCC and Clang receive native structured-diagnostic flags inside the same
Bubblewrap isolation boundary, for example -- g++ -fsyntax-only src/main.cpp.
The normal C product path consumes the real compilation database and performs function, pointer-parameter, and helper discovery automatically:
whyvec analyze demo/src/kernel.c:4
whyvec doctorThe expert path accepts an explicit Clang source/IR mapping and evaluates typed LLVM parameter assumptions:
whyvec explain-opt src/kernel.c:5 \
--function add_vectors_ \
--parameter output:0 --parameter input:1 --parameter count:2 \
--transformer /path/to/whyvec-llvm-transform \
--identity-tool /path/to/whyvec-llvm-loop-identityThe complete build installs or builds the pinned-LLVM helpers; explicit helper
paths remain expert overrides. It records equivalent_confirmed fidelity and never converts a
successful LLVM assumption into source authorization.
If a source location maps to more than one LLVM loop, the query retains
identity.ambiguous with the helper evidence and stops before pipeline replay
or variants. It does not select a nearby loop heuristically.
Completed optimization queries can be re-executed from their retained inputs:
whyvec replay-opt .whyvec/analyses/<analysis-id>/report.jsonReplay verifies every declared artifact, the report's normalized semantic digest, the source digest, and all four tool fingerprints before rerunning the same bounded search. It refuses changed evidence, inputs, tools, or outcomes.
GCC has a separate observation surface because its records and cost model are not LLVM assumptions:
whyvec observe-gcc-opt src/kernel.c:5 --function add_vectors_ \
--llvm-report .whyvec/analyses/<llvm-analysis>/report.json
whyvec replay-gcc-opt .whyvec/analyses/<gcc-analysis>/report.jsonThe optional comparison reports only whether the two recorded compiler classifications agree or diverge for the same canonical source subject.
For a positive C bound-alias report, derive the source access obligation separately:
whyvec derive-obligation .whyvec/analyses/<optimization-analysis>/report.json
whyvec replay-obligation .whyvec/analyses/<obligation-analysis>/report.jsonThe derivation names the pointer-loaded bound object, every supported indexed write region, the induction domain, overflow checks, and the unchanged fallback requirement. It remains a candidate obligation until repository evidence or a runtime guard enforces it.
The executable guarded-repair fixture and its retained validation evidence are documented in Guarded repair validation.
The installable Codex skill consumes the compact packet and creates an auditable repository decision before a source edit:
python3 integrations/codex/whyvec/skills/whyvec-optimize/scripts/plan_action.py \
--packet .whyvec/agent-packets/<analysis-id>.json \
--validation-report <validation-report.json> \
--candidate-source <candidate.c> \
--output <new-action-trace.json>The packet locates WhyVec and its linked reports without five manual paths. The
planner verifies replay and artifact integrity and compares restrict, a
guarded path, an API change, and refusal. Its tracked-text discovery is only a
preliminary inventory; Codex must still establish repository contracts and
uncertain caller edges.
The report claims differential agreement only on covered executions and keeps
the original pointer-loaded loop as the overlap and arithmetic-uncertainty
fallback.
An actual fresh Codex CLI 0.144.3 / gpt-5.6-sol run, sanitized observable
session, complete patch, evidence ledger, and linked action trace are retained
under evidence/codex-live/2026-07-21. The
independently sourced SuperLU case is retained under
evidence/real-world/superlu-a9314310;
WhyVec observed its real compiler miss and made a principled refusal after the
declared search found no tested sufficient assumption.
WhyVec separates three kinds of reasoning that must never be conflated:
- Compiler observation — what the pinned compiler did in the baseline build.
- Counterfactual evidence — what changed when one declared assumption was altered in an otherwise identical shadow compilation.
- Repository decision — whether callers and tests justify
restrict, require runtime versioning, or make the optimization unsafe to apply.
The compiler engine is deterministic. GPT-5.6 and Codex operate on its evidence; they do not invent the compiler result.
source location
│
▼
baseline compilation ──► missed vectorization record
│
▼
bounded assumption search ──► successful counterfactual
│
▼
semantic obligation ──► repository and caller analysis
│
├── enforceable ──► patch + regression tests + benchmark
└── unsupported ──► explicit refusal with evidence
$ whyvec explain-opt src/kernel.c:5 --function add_vectors_ \
--parameter output:0 --parameter input:1 --parameter count:2 \
--transformer /path/to/whyvec-llvm-transform \
--identity-tool /path/to/whyvec-llvm-loop-identity
OPTIMIZATION CAUSALITY
baseline: missed
pipeline fidelity: equivalent_confirmed
loop fingerprint: <recorded fingerprint>
smallest sufficient set found: parameter.count.noalias
Under the recorded toolchain and equivalent-confirmed pipeline, parameter.count.noalias was a tested sufficient assumption for the matched loop to vectorize.
report: .whyvec/analyses/<analysis-id>/report.jsonRun derive-obligation on that report before considering a source action. The
result is a candidate obligation or typed decline; repository analysis remains
required and the counterfactual alone never authorizes restrict.
- Never mutate the user's source during an experiment.
- Never describe a counterfactual observation as proof that a caller contract is true.
- Never narrow LLVM parameter-level
noaliasinto a byte-range promise without separate access analysis. - Pin and report every compiler input that can affect the result.
- Preserve baseline behavior through an unchanged fallback whenever a runtime guard is selected.
- Treat refusal as a valid, testable product outcome.
- Keep human-readable output and the versioned JSON report semantically identical.
- Preserve every experiment as reproducible evidence rather than transient terminal text.
- AGENTS.md — operating rules and invariants for every coding agent.
- PLAN.md — living execution plan and acceptance gates.
- docs/PRODUCT_SPEC.md — audience, product surface, and behavior.
- docs/ARCHITECTURE.md — components, data flow, and boundaries.
- docs/SEMANTIC_MODEL.md — evidence strength and alias semantics.
- ADR 0006 — the first typed C source-access model.
- docs/EXPERIMENT_PROTOCOL.md — reproducible counterfactual procedure.
- docs/AGENT_CONTRACT.md — Codex/GPT-5.6 responsibilities and refusals.
- docs/BUILD_CAUSALITY.md — patch atoms, rustc diagnostic identity, subset search, removal witnesses, and safety boundaries.
- docs/DECLINE_CODES.md — stable failure and refusal taxonomy.
- docs/TEST_STRATEGY.md — fixture and adversarial validation matrix.
- docs/GUARDED_REPAIR_VALIDATION.md — checked guard, fallback, sanitizer, optimization-record, and benchmark evidence.
- docs/BUILD_WEEK.md — official challenge requirement check and the non-decorative GPT‑5.6/Codex role.
- docs/THREAT_MODEL.md — untrusted repository and toolchain risks.
- docs/R3_R8_COMPLETION_AUDIT.md — requirement-to-evidence audit for completed R3–R8 release capabilities.
- docs/phases — capability phases with entry and exit gates.
- logs — append-only build, experiment, validation, failure, and model-use evidence.
- schemas — machine-readable configuration and report contracts.
- fixtures — positive, fallback, refusal, and already-optimized cases.
- integrations/codex/whyvec — installable Codex plugin and workflow skill.
- crates/whyvec-domain — compileable evidence and lifecycle invariants.
- crates/whyvec-experiment — deterministic finite intervention search with a three-valued oracle, evidence-safe minimality, and adapter-neutral immutable artifact storage.
- crates/whyvec-obligation — Clang AST-backed source access summaries, typed obligation declines, and semantic replay.
- crates/whyvec-opt — retained Clang/LLVM optimization-causality query and report assembly.
- crates/whyvec-build — isolated Git/compiler build oracle, adapter-owned diagnostic identity, and causal report generation.
- crates/whyvec-cli — build and optimization explain/replay command-line product surface.
- scripts — repository and pinned-Clang fixture validation.
- tools/whyvec-llvm-transform.cpp — pinned-LLVM typed IR intervention helper used by the optimization pack.
- tools/whyvec-llvm-loop-identity.cpp — LLVM loop analysis and structural identity helper with ambiguity refusal.
This repository contains executable build-causality, LLVM optimization, GCC-observation, source-obligation, guarded-validation, semantic-replay, and Codex action-planning paths. Their supported and residual surfaces are tracked in PLAN.md, and completed capabilities retain validation evidence in the appropriate log.
WhyVec is licensed under the MIT License.