Skip to content

PR 2/3: Rust application framework (PyO3) - #97

Draft
ericeil wants to merge 20 commits into
masterfrom
eric/rust
Draft

PR 2/3: Rust application framework (PyO3)#97
ericeil wants to merge 20 commits into
masterfrom
eric/rust

Conversation

@ericeil

@ericeil ericeil commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

PR 2 of 3 — Rust application framework (PyO3)

Part of the stacked split of eric/crucible.
Stack: mastereric/ecosystem (#96, merged) → eric/rusteric/crucible-app.
Base: master — PR #96 landed, so this branch was rebased onto master directly and the last
commit reconciles it with the three APIs master moved underneath it in the meantime.

79 files, +11.8k/-149. The premise: an AutoProver application should be able to ship as a Rust
wheel and nothing else
— no composer-resident Python package. This PR is the host that makes that
true, plus the framework-layer seams it needs. It carries no verification backend; the first one is
PR 3.

What this adds

The generic wheel host — composer/rustapp/*
A wheel supplies a declarative AppDescriptor and answers pure callouts; the host owns all control
flow, all effects, and the entire vertical an application needs (argparse, service setup, pipeline
wiring, frontend, artifact store, main()).

  • descriptor.py — the declarative ABI as pydantic models: phases + CoreSlot mapping, CLI args,
    event kinds, artifact layout, preflight / setup step specs, deliverable mode, RAG corpus tag,
    serialize_toolchain, confine_by_default, nouns. Validated at load, so a malformed wheel fails
    before the run spends anything.
  • wire.py — the runtime ABI, typed to match: tagged inbound unions (CompileOk | CompileFailed,
    ValidateBuildFailed | ValidateVerdicts), outbound AuthorInput / FinalizeInput / Failure,
    and a RustAppModule Protocol whose ten callouts are checked at import — a field renamed in the
    SDK now fails at the boundary instead of reading as "" three frames later.
  • adapter.py / host.py / entry.py / cli.py / frontend.py / store.py / results.py
    the author→compile→judge→validate loop, the bounded in-loop review, the cached shared setup
    artifact, console + TUI frontends, and two-line console/TUI entry-point shims.
  • toolchain.py — the two seams for the analyzed project's build system (below).

The Rust workspace — rust/

  • autoprover-sdk — the ABI (serde types), the Application / FormalizeSession traits, the FFI
    helpers, and the export_app! macro that emits the PyO3 module. Verdict.outcome is a real
    Outcome enum (UPPERCASE serde rename, so the wire bytes are unchanged).
  • example-app (echoprover) — a self-contained demo wheel, so the framework has something to
    round-trip against; it ships with zero bespoke Python (console_main("echoprover")).
  • run-confined gains a maturin bin pyproject so uv sync puts the launcher in .venv/bin
    (the crate itself is upstream, from Command sandbox: confine untrusted native command execution (Landlock + seccomp) #73).

Driver changes — composer/pipeline/{core,ptypes}.py

  • PipelineBackend.preflight — whatever a backend can do before it knows anything about the
    program, run concurrently with system analysis. It is the cheap side of the pair, so it is
    awaited first and its failure cancels the analysis agent racing it; the result type Pre is
    opaque to the driver and threaded into prepare_system. This is what lets a backend that must
    build something gate the workspace before the model is spent, instead of surfacing a broken
    workspace as unfixable compiler errors in the first authored draft.
  • StagedFormalizer replaces the Formalizer.begin no-op hook: prepare_formalization widens
    to a union, and the shared artifact becomes a constructor argument to the only object that uses
    it. No post-hoc writes to a live formalizer — same rule as the rest of the phase chain.
  • PipelineBackend is a nominal ABC, not a structural Protocol, so each backend names its eight
    type arguments in its class line and conformance is checked where the backend is defined.
    (Both prior docstring copies of those arguments had already drifted.)
  • The second overlap (prepare_formalization ∥ extraction) simply awaits each in turn — the
    all-or-none cancellation preflight needs is not something it wanted.

Descriptor-driven RAG — composer/rag/import_format.py, composer/scripts/rag_import.py, composer/tools/rag_env.py
A corpus becomes data, not another bespoke Python builder: a producer emits a common JSON
manifest, one shared importer ingests any manifest (chunking, embedding, batching, dual-path DB
ingestion), and a wheel names its corpus by tag in the descriptor. Registration is a declarative
tag → (factory, connection) pair validated at descriptor load. The mechanism ships corpus-free
KNOWLEDGE_BASES and rag_env._FACTORIES are both empty, and both halves of the first corpus land
with the application that declares it.

Build integration

  • dev includes the apps group, so a bare uv sync builds the Rust artifacts — no manual
    maturin develop / cargo build. [tool.uv] cache-keys over each project's .rs sources
    (cross-crate, so an SDK edit invalidates the wheels) makes the import hook optional.
  • rust-toolchain.toml at the repo root (rustup resolves by CWD); rust/Cargo.lock is tracked,
    since this workspace ships artifacts.
  • CI: pytest's job builds the crates, so test_rustapp stops silently skipping; pyright's job gets
    --no-dev so it doesn't compile Rust it cannot see into.

Report / IO / UI seams

  • ReportBackend gains "none" — a pipeline that records properties without verifying them —
    with its own labels (UNKNOWN → "Unverified", not "Unknown"). The null Solana backend reports
    under it instead of borrowing a real verifier's wording. Outcome.parse handles labels arriving
    from outside the repo, and outcome_label / outcome_glyph are the single place per-outcome
    wording lives (the console rollup and the TUI had drifting copies).
  • RuleVerdict.message + its rendering: a non-GOOD row can carry the backend's diagnostic
    (a counterexample, a failed assertion) into report.json and the HTML.
  • io.context.push_custom_update — the out-of-graph analogue of get_stream_writer(), for a
    backend emitting domain events between graph calls.
  • MultiJobApp.mark_pipeline_done() replaces seven external writes to app._pipeline_done.

Docsapplication-abstraction.md, formalization-abstraction.md, rust-applications.md,
rust-formalization-backends.md, rust-backend-api.md, rust-ioc-loop.md, rust-pure-app.md,
rag-import-format.md, rust/README.md.

What PR 3 (eric/crucible-app) does with all of this

Crucible — the Solana fuzzing backend — is the first real consumer, and because of the seams above
it lands as a pure-Rust app: rust/crucible-app (the wheel + its Askama templates + a committed
crucible_kb.rag.json), two registry entries, and a composer/crucible_launch.py holding the same
two shims echoprover uses. Concretely, per facility:

This PR's facility How PR 3 uses it
preflight Prepares the harness crate, compiles the program to sBPF, and gates a wheel-authored skeleton fixture through the real toolchain — all while system analysis runs. A broken dependency graph or unbuildable program surfaces before the model is spent.
WORKSPACE_TOOLCHAINS Registers the Solana implementation (composer/spec/solana/build.py): warm the cargo cache, cargo-build-sbf the program, fill in an IDL's program id, place the IDL. The host still writes the plan's files and reports the idl context key; it never learns what a build is.
SOURCE_CRATES Registers composer/spec/cargo.py — resolve the analyzed program's crate from its source path. Crucible's harness needs it as a path dependency; when it isn't usable, the wheel switches to IDL-generated types.
StagedFormalizer + setup slot The shared fuzz fixture every component's harness builds on, authored once and cached.
CoreSlot.DISCOVERY Claims its design-doc discovery phase by slot instead of by a magic "discover_design_doc" key.
Typed wire.py ABI Its compile / validate callouts return the tagged variants directly; Verdict::detailed() carries the counterexample.
RuleVerdict.message + rendering What makes a counterexample triageable from the report alone.
ReportBackend closed set Adds "crucible" + its render labels, and swaps adapter.py's cast(ReportBackend, tag) for the validating as_report_backend.
RAG manifest + importer Ships crucible_kb.rag.json as data and adds composer/tools/crucible_rag.py plus the two registry entries (rag/db.KNOWLEDGE_BASES, rag_env._FACTORIES) in one go. No new importer.
event_kinds + push_custom_update Its domain events (harness built, section sealed, counterexample found) reach the TUI/console from between graph calls.
serialize_toolchain / confine_by_default / DeliverableMode::Callout Declared in the descriptor: one toolchain callout at a time, sandbox default → the run-confined launcher (fail-closed), and a crate-shaped deliverable the wheel assembles.
Sandbox argv_prefix seam Consumed here via the none passthrough provider; PR 3 flips the default to real confinement and adds the Rust build grants (private RUSTUP_HOME, cargo-build-sbf tree, offline registry).
test_scenarios/solana_vault The Anchor sample the front-half and e2e gates drive.

Deliberately deferred to PR 3

Earlier revisions of this branch carried these; they moved forward to the backend that actually
needs them, so the framework layer holds no Cargo shape, no chain-specific build, and no verifier's
vocabulary:

  • composer/spec/solana/build.py and composer/spec/cargo.py (+ the RustLanguage facet reaching
    them) — replaced by the two registry seams in rustapp/toolchain.py, which are empty here and
    unregistered in deliberately different ways
    : source_crate degrades to an all-empty
    ProgramCrate (indistinguishable from "nothing to resolve"), workspace_toolchain raises (a
    plan that only places files never asks, so reaching it means the wheel asked for a build nothing
    can perform). composer/sandbox/recipes.py is byte-identical to master again.
  • Crucible's report vocabulary and its member of the closed ReportBackend set — hence the
    cast(ReportBackend, tag) in adapter.py, which PR 3 replaces with the validating helper.
  • The crucible_kb registration (both halves) and composer/tools/crucible_rag.py. It was
    previously half-registered, which passed validation and then degraded to "RAG unavailable" —
    reporting a repo gap as an environment condition. Both registries are empty now, so such a wheel
    fails at descriptor load instead.
  • rust/Cargo.toml's workspace members omit crucible-app.

(The shared Rust prompt fragment templates/rust/_failure_modes.j2 shipped in #96, alongside the
Solana front half that consumes it.)

Review-driven work on this branch

Beyond the original squash, the bulk of the commits here are the review of this branch, applied:
eight correctness fixes (a rollup hiding four of five verdicts per component; asyncio.wait
leaving a cargo build detached on Ctrl-C; a stale rustup symlink; entry points naming a PR-3
module; report rows colliding on a shared property key), then the typing/abstraction pass —
optionality instead of sentinels at four seams, Accepted | Rejected | None instead of
(bool, str), the typed runtime ABI, real APIs where callers had been reaching through private
fields, and the duplicate parser / env builder / dead hook cleanup. Each commit message states the
behaviour change, if any, and the one policy decision flagged-but-not-taken (an unparseable judge
reply fails open).

Verification

  • pytest -m "not expensive"583 passed, 11 deselected (with the demo wheel importable).
  • pyright0 errors.
  • cargo build --manifest-path rust/Cargo.toml — clean (autoprover-sdk, example-app, run-confined).
  • New coverage: 90 tests across test_rustapp* / test_rust_frontend / test_rust_llm_agent,
    plus test_pipeline_overlap, test_rag_import, test_rag_env, test_solana_component_grouping.
  • test_solana_gate is in this PR (it imports composer.rustapp.frontend) but its
    test_scenarios/solana_vault fixture lands in PR 3, so it asserts out at collection-time-adjacent
    _SCENARIO.is_dir(). It is expensive-marked (real LLM + containers), so the routine pass
    deselects it; it is only runnable from the tip of the stack, and its real-LLM run has not been
    executed.

🤖 Generated with Claude Code

@ericeil
ericeil force-pushed the eric/rust branch 3 times, most recently from 4bbeb08 to 7ea1a77 Compare July 23, 2026 19:58
@ericeil
ericeil force-pushed the eric/ecosystem branch 2 times, most recently from 833557a to fe84bae Compare July 23, 2026 20:15
@ericeil
ericeil force-pushed the eric/rust branch 6 times, most recently from 0671f74 to 5361ead Compare July 24, 2026 00:08
@ericeil
ericeil force-pushed the eric/rust branch 2 times, most recently from ee74e24 to 372504a Compare August 3, 2026 21:30
ericeil and others added 15 commits August 4, 2026 11:12
The generic Rust-wheel host (composer/rustapp) + the rust workspace (autoprover-sdk
ABI/export_app! macro, example-app/echoprover), consuming the command-sandbox seam
already upstream (via the `none` passthrough; SandboxConfig.backend_spec ->
{argv_prefix, timeout_s}). Includes composer/spec/solana/build.py (workspace prep),
the rust prompt templates, and the report-layer support the host needs
(report/{schema,render,collect}.py: the ReportBackend set incl. "crucible", the
per-backend outcome_label vocabulary, and Verdict.message diagnostics).

Cross-cutting intermediate forms (finalized in PR3):
- rust/Cargo.toml: workspace members omit crucible-app (added in PR3).
- pyproject.toml / uv.lock: the `apps` group + [tool.uv.sources] omit crucible_app
  (its crate lives in rust/crucible-app, which lands in PR3), so `uv sync`/`uv run`
  resolve here; PR3 re-adds it.
- rustapp/adapter.py: RustFormalizer casts the backend tag directly; PR3 restores the
  validating as_report_backend.
- rust/.gitignore ignores rust/Cargo.lock; the lockfile is untracked here.

Gate: test_rustapp (echoprover decider round-trip; sandbox passthrough) -- 15 passed.
CI pyright (composer/ analyzer sanity_analyzer certora_autosetup) -- 0 errors.
test_solana_gate lives here (imports composer.rustapp.frontend), not PR1.

Stacked-PR 2 of 3 (off eric/ecosystem); see docs/pr-split-plan.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The identity types split upstream: SourceIdentifier is now the neutral type
the ecosystem seam speaks, with SolidityIdentifier and RustIdentifier as its
per-language subtypes. These two sites predate the split and still claimed
Solidity.

Both typecheck either way, because narrow->wide assignment is legal — a
SolidityIdentifier IS a SourceIdentifier. So the checker cannot catch these;
they have to be retargeted by hand.

- rustapp/entry.py: the generic Rust host parses --main-contract into
  SourceFields.contract_name, so it builds the neutral SourceIdentifier. It
  is descriptor-driven and not Solana-specific, so it should not claim a
  language at all.
- tests/test_solana_gate.py: this one does know its target is a Rust
  program, so it builds a RustIdentifier.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Editing Rust required remembering a manual step (`maturin develop` for the app
wheel, `cargo build -p run-confined --release` for the launcher, plus a one-time
`maturin_import_hook site install`). Make the venv the single source of truth
instead:

* `dev` includes the `apps` group, so a bare `uv sync` builds the Rust
  artifacts. The container's UV_NO_DEV=1 still selects none of them, so its
  cargo-less final stage is unaffected.
* `[tool.uv] cache-keys` over each project's `.rs` sources (including
  cross-crate, so an autoprover-sdk edit invalidates echoprover) — uv rebuilds
  on the next `uv run`, and the import hook becomes optional.
* run-confined ships as a maturin `bin` wheel, landing the binary in
  `.venv/bin`; `_resolve_binary` also probes the interpreter's scripts dir,
  since PATH misses it when the venv is not activated. Linux-only, hence the
  `sys_platform` marker.
* rust-toolchain.toml pins the toolchain and lets rustup install it on demand.
  It sits at the repo root because rustup resolves by CWD and ignores
  `--manifest-path`, and cargo runs both from crate dirs and from the root.
* Track rust/Cargo.lock: this workspace ships artifacts, so the dependency
  versions are part of the build.

pyright's job gets `--no-dev` — it would otherwise compile Rust it cannot see
into. pytest's job now does build the crates, so tests/test_rustapp.py stops
silently skipping in CI.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The Crucible work (PR3, `eric/crucible-app`) kept improving the layer beneath
it, so the two branches had drifted: the framework files on `eric/rust` were
stale copies of the same files on `eric/crucible-app`. This lifts the
framework-layer half of that drift down to where it belongs, leaving
`eric/crucible-app` to carry only crucible-specific files.

What comes down, by area:

* **Pipeline driver** — `PipelineBackend.preflight`, run concurrently with
  system analysis and joined by `_all_or_none` so either side failing cancels
  the other. This is what lets a backend that must *build* something gate the
  workspace before the model is spent, instead of surfacing a broken workspace
  as unfixable compiler errors in the first authored draft. `prepare_system`
  takes the preflight result as its third argument; a setup failure now
  surfaces where it happens rather than after extraction.
* **Rust application framework** (`composer/rustapp`, `rust/autoprover-sdk`) —
  the abstract component unit mirroring EVM's, the declarative `preflight` /
  `idl_dest` / setup-artifact slots on the descriptor, the cached shared setup
  artifact, the bounded in-loop review, and IDL-driven type generation for a
  wheel that cannot link the program under test.
* **Cargo/Solana capabilities** — `composer/spec/cargo.py` (resolve a program
  crate from its source path, not its name) and `composer/spec/solana/build.py`
  (fill in an IDL's program id when the project's build omits it; warm the
  cargo cache with the same cargo the sbf build uses).
* **Sandbox recipes** — a private per-run `RUSTUP_HOME`, the `PATH`
  `cargo-build-sbf` install tree, `~/.gitconfig`, a pinned registry protocol,
  and `CARGO_NET_OFFLINE=true` (the spelling every cargo accepts).
* **RAG seam** — `composer/tools/rag_env.py`, which `rustapp/entry.py` already
  imports. The corpus modules stay in PR3; an absent one degrades to no RAG,
  which is this module's documented contract.
* Docs for the above, plus the report template rendering `Verdict.message`.

Also fixes the demo wheel: `rust/example-app`'s descriptor gains
`preflight: None`. It has not compiled since `preflight` was added to
`AppDescriptor` on the crucible branch — that branch's `uv sync` never built the
crates, so nothing noticed. Here it would break the `test_rustapp` gate the
moment the wheel is rebuilt, so it is fixed in the same commit that brings the
SDK change down.

Verified: `cargo check --workspace` and `uv sync` clean, pyright 0 errors, and
the framework/pipeline/sandbox/solana tests plus the `test_rustapp` gate pass —
422 passed vs 363 on the branch before, with no new failures. `test_solana_gate`
fails here for a pre-existing reason: its `test_scenarios/solana_vault` fixture
lives in PR3.
Ported from eric/ecosystem, plus the Rust-side half that branch has no backend for.

`Formalizer.begin` was a defaulted no-op hook that every formalizer inherited and
that the driver called unconditionally. It carried its ordering as a call-order
convention and mutated the formalizer in place, contradicting `Formalizer`'s own
contract ("immutable, fully constructed by prepare_formalization ... never set
post-hoc") — the one thing the rest of the phase chain is built to avoid.

Replace it with `StagedFormalizer`, whose abstract `begin` *returns* the
`Formalizer`. `prepare_formalization` widens to the union of the two, and the
driver picks the arm.

On the Rust side that removes the last post-hoc write to a live formalizer:
`RustFormalizer` no longer takes a `setup_author` and no longer assigns
`_setup_result` / `_context_extra[context_key]` after construction. A wheel that
declares a `setup` step now gets `RustStagedFormalizer`, which authors the shared
artifact and calls the `build` closure `prepare_formalization` handed it; a wheel
that declares none gets its formalizer straight from `build(None)`. Either way the
artifact is in the context blob before any component can read it.

Backends with no shared artifact (prover, foundry, null-Solana) are unchanged:
their narrower `-> Formalizer[...]` return now states that positively instead of
inheriting a no-op.

Also brings over the CLAUDE.md testing notes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Eight fixes from the review of this branch, plus tests for the two that were
behavioural. Nothing here changes the design — see REVIEW-eric-rust.md for the
typing/abstraction work that is still open.

* results: the console/TUI rollup read `next(iter(verdicts.values()))` on the
  strength of "one verdict per delivered unit", but `units()` is one unit per
  *property* — so a component with five properties reported one check and hid
  the other four. One row per verdict now, named by the property title it
  checks (new `RustFormalResult.unit_titles()`), falling back to the unit name.
  A delivered component that bakes no verdict still gets an UNKNOWN row.
  `report.json` was never affected; it goes through `fetch_verdicts`.

* pipeline: `_all_or_none` left its tasks running when the *caller* was
  cancelled — `asyncio.wait` does not touch what it waits on, so a Ctrl-C left
  a multi-minute cargo build detached, still writing into the workdir. It now
  cancels them and re-raises. A task cancelled by a third party counts as a
  failure (and `exception()` is no longer asked of a cancelled task, which
  raises).

* sandbox: the per-run RUSTUP_HOME's `toolchains` symlink was tested with
  `exists()`, which follows the link — a stale link (shared rustup home moved)
  read as absent and `symlink_to` would then raise FileExistsError. Check the
  link itself and re-point it.

* pyproject: drop `console-crucible` / `tui-crucible`. They named
  `composer.crucible_launch`, which lands in PR3 — an entry point pointing at a
  missing module installs happily and fails at ImportError on first use. Same
  for null_backend's `:mod:`composer.crucible`` reference.

* rag_env: the tag -> connection map existed twice (here and
  `rag/db.KNOWLEDGE_BASES`); take it from `KNOWLEDGE_BASES` and keep only the
  tools factory local. Split the two failure modes that were both being
  swallowed: an unregistered tag is a wheel bug, so `validate_rag_db` runs at
  descriptor load like `resolve_ecosystem` does, while an unavailable DB /
  embedding model still degrades to no RAG.

* descriptor: `backend_tag: ReportBackend`. It feeds a closed set, so a wheel
  declaring a tag the report cannot render now fails in `model_validate_json`
  — before the run spends anything — rather than at formalizer construction.
  This caught the demo wheel declaring `backend_tag: "echoprover"`, which no
  report knows: any real echoprover run died in `RustFormalizer.__init__`. It
  borrows `"prover"` now, as the null Solana backend does.

* adapter: `formalize` grouped its report rows as `(property, [one unit])`
  singletons, so two units checking one property became two rows with the same
  key and the store's `dict()` kept the last. Group by property as they arrive.

* mark the `docs/crucible-*.md` citations that land in PR3, so a reader stops
  looking for files this branch doesn't carry.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The wheel's *declarative* ABI was already mirrored as pydantic models
(`descriptor.py`); its *runtime* ABI was not. Python received every payload as a
bare dict and destructured it by string key — `result.get("status") != "ok"`,
`res.get("kind") == "build_failed"` then `res["verdicts"]`, `u.get("target") or
u["unit"]`, `plan.get("files")` — while the Rust side had spelled the same things
as tagged unions all along. A field renamed in autoprover-sdk read as `""` three
call frames later instead of failing at the boundary.

New `composer/rustapp/wire.py`, peer of `descriptor.py`:

* Inbound, tagged: `CompileOk | CompileFailed` (discriminator `status`) and
  `ValidateBuildFailed | ValidateVerdicts` (discriminator `kind`), so
  `isinstance` replaces the string compare and neither variant can be asked for
  the other's fields. Plus `Unit` (whose `target_or_unit()` is no longer
  reimplemented inline), `Verdict`, `WorkspacePrep`, `SandboxGrants`, `Prompt`.
* Outbound: `AuthorInput` (+ `Property`, `ProgramCrate`), `Failure`/`FailureKind`
  (so `{"kind": "judge"}` is a value, not a literal), and `FinalizeInput` —
  currently the only written definition of that payload, since the Rust
  `finalize` still takes an opaque `serde_json::Value`. Growing an `Outcomes`
  struct over there is the follow-up.
* `RustAppModule` Protocol replaces `module: Any` in every signature. Members
  are `Callable` fields so `CALLOUTS` derives from the annotations rather than a
  hand-kept copy; `load_module` checks all ten at import and names the gaps, so a
  wheel built against an older SDK fails at load instead of with an
  AttributeError mid-run. The one cast sits at `import_module`, which is where
  the dynamism actually is.

`component` and `context` stay dicts on purpose: they are opaque JSON the host
only forwards, so typing them would mean inventing a schema for values it never
reads.

Rust side: `Verdict.outcome` becomes an `Outcome` enum (UPPERCASE serde rename,
so the wire bytes don't change), with `Verdict::detailed()` for the failing case
a backend almost always wants. A typo no longer compiles. Python still tolerates
an unknown label (-> UNKNOWN, logged): version skew should cost one row's wording,
not the component's results.

Fallout worth noting:

* `RustFormalResult.verdicts` is `dict[str, Verdict]`; `fetch_verdicts` and the
  console rollup read fields, and `results._parse_outcome` is gone.
* `env: Any` -> `ServiceHost` in the authoring turn, which retired
  `getattr(env, "all_tools", None) or env.rag_tools`.
* `_split_prompt` is gone. A wheel that sends no `instruction` now fails at the
  seam; it used to have its whole payload JSON-dumped into the agent's prompt.
* `from_formalized` deleted — it parsed a Rust `Formalized`/`Command::Publish`
  that no longer exists in the SDK, and only tests called it. `as_report_backend`
  deleted too: pydantic validates `backend_tag` now.
* The stub *wheels* in tests still return JSON strings, as real ones do. Only the
  host's side of the seam moved.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Two reach-throughs, one shape: a caller needed something an object owned, so it
took it out of a private field instead of the object growing a way to ask.

The phase enum. `RustBackend._phase: type` / `_core_phases` were dataclass
*fields*, so `host.build_backend` constructed the backend with underscore-named
keywords, and both callers that needed a phase member indexed the field through
`cast(Any, …)` — `RustPreparedSystem` reaching across objects to do it
(`cast(Any, b._phase)[setup.phase_key]`). They are now public `phase:
type[enum.Enum]` / `core_phases: CorePhases` (the property is redundant — a plain
attribute satisfies the protocol, as ProverBackend and the null Solana backend
already show), and the indexing lives behind one accessor:

    def task_info(self, spec: StepSpec) -> TaskInfo[enum.Enum]

Annotating the field `type[enum.Enum]` is what let the casts go: pyright resolves
EnumMeta's `__getitem__`, so the member comes back typed. Both call sites were
building a TaskInfo from a (phase_key, label) pair anyway, so that is what the
method returns — and since PreflightSpec and SetupSpec now share a `StepSpec`
base carrying `step: ClassVar[str]` (the step's kind), the task id is derived
from the declaration rather than spelled `f"{name}-setup"` at the call site.
ClassVar keeps `step` off the wire, so the Rust structs don't change.

The TUI flag. `MultiJobApp.mark_pipeline_done()` replaces five external
`app._pipeline_done = True` writes across four entry points plus two inside
`ui/pipeline_app.py`; the flag is now touched only by the class that declares it.
The method's docstring records why it exists at all — quitting is refused until
the run ends, so a keypress can't close the app and take every panel with it
mid-stream — which none of the assignments said.

Both new tests assert the property the reach-through existed to provide: that a
step's task carries the member of *the backend's own* enum, since the frontend
looks up section labels by member identity and a member from another copy of the
enum would land the task in no section at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`(bool, str)` carried three meanings. The string was a revise instruction when
the bool was False and an aside when it was True, and `(True, "")` *also* stood
for "this wheel declares no judge" — so every caller had to know which of the
three it was holding, and `_budgeted`'s relent step returned `(True, rejection
text)`, a verdict that read as an acceptance while carrying the opposite.

    Accepted(feedback="")     # the gate opens; feedback is an aside
    Rejected(feedback=...)    # the gate holds; feedback is what to revise
    None                      # no judge for this input — no verdict at all

`_judge_turn` returns `Review | None`, so absence is absence: `author_and_compile`
now re-authors on `isinstance(review, Rejected)`, and both "accepted" and "no
judge" simply fall through. `_budgeted`'s last round produces a real `Accepted`
whose feedback is the unresolved objection — the same behaviour as before, but the
type now says what it does. `_make_judge_hook` narrows `None` away where it cannot
happen (the hook exists only for an input that declared a judge) and says why.

Two `_parse_judge` behaviours were previously implicit in the tuple:

* A rejection with no feedback used to hand the next authoring turn an empty
  revise context — a round spent on "you were rejected" with no statement of
  what to fix. It now says that no reason was given.
* Prose that leads with neither ACCEPT nor REJECT is taken as an acceptance.
  Unchanged, but now stated in the docstring and pinned by a test: the reviewer is
  advisory, in front of the compile/validate gates that actually decide, so an
  unparseable reply lets the draft through rather than burning a revise round on a
  verdict nobody stated. Flipping that is a policy decision — flagged, not taken.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Each of these had a value that looked like data but meant "there isn't one", so
every consumer had to know the convention — and one of them silently didn't.

* `cargo._dep_req` returned `""` for "no anchor-lang requirement to compare",
  which is what a caller comparing versions least wants to receive. It is
  `str | None` now, and `ProgramCrate.anchor` with it; the `""` the Rust struct's
  `#[serde(default)]` fields require is produced at the wire boundary
  (`wire_crate`) and nowhere else.

* `run_llm_agent` JSON-dumped a missing result, so a turn where the agent never
  called the result tool handed back the literal string "null" — which went on to
  `compile` as if it were the authored artifact and spent an attempt on a build
  nobody could have fixed. It returns `str | None`; both loops treat "no artifact"
  as its own failure, costing an attempt but never reaching the toolchain, and the
  next prompt is told what actually happened. A judge turn that ends without a
  verdict is likewise not a rejection: it fails open, same reasoning as an
  unparseable reply.

* `resolve_program_id` / `idl_with_program_id` took the crate as a dict and read
  it with `crate.get("dir", ".")` — a Python-to-Python call flattening a typed
  value and then papering over its absence by scanning the root as if it were the
  crate, matching against a set of empty names. They take `ProgramCrate | None`,
  and the fallback is stated once, where it happens. `run_workspace_prep` gets the
  resolved crate threaded in rather than reconstructing it from the wire copy,
  whose emptiness no longer says whether anything was resolved.

* `RustFormalizer._idl` collapsed "prep placed no IDL" into `""` on the way in;
  it keeps `None` and flattens at `finalize`, which is the only place the payload
  promises a string.

The fourth bullet of the review's §4 (`context_key if descriptor.setup else
"setup"`, an unreachable fallback inventing a context key) went away with the
typed-ABI commit, which made `build` take the key alongside the artifact.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Two places where a string was doing a type's job.

The design-doc discovery task's phase was found by looking for a declared phase
whose *key* was literally "discover_design_doc". The descriptor already has a
mechanism for "this declared phase fills that role" — `core_slot` — so a magic
key was a second, undocumented one: a convention a wheel author had to spell
exactly right, with no error if they didn't, and `-> Any` at the end of it.

`CoreSlot` gains `DISCOVERY`, and `CoreSlot.required()` names the four the driver
itself tags and every application must map — so the new slot is optional, and
unclaimed still falls back to the first declared phase. Mirrored in the Rust
`CoreSlot` (additive: existing wheels don't mention it).

The other: two glyph tables with identical contents, one keyed by `Outcome`
(the console rollup) and one by raw strings (the TUI), because the emit payload
carried `"GOOD"`/`"BAD"` as literals. They are now `render.outcome_glyph`, beside
`outcome_label` — the same question, how an outcome reads to a human — and the
tolerant `str -> Outcome | None` is `Outcome.parse`, used by the frontend and by
`wire.Verdict`'s validator instead of each keeping its own known-values set. An
outcome this host doesn't recognize loses its glyph, not its line.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Section 7 of the review: the duplication and dead code.

- build_arg_parser is the only parser. rust_entry_point re-declared the same
  nine arguments inline, and the copy had already lost every help string. The
  declared-flag dests no longer ride out of _add_declared_args as a return
  value either: _arg_dest/_declared_args derive them, so "declared" and
  "collected" cannot drift apart.
- build_default_env replaces build_neutral_env plus _default_env_builder's
  inner closure, which were the same six lines twice differing in rag_tools=.
  rust_entry_point binds rag_db=descriptor.rag_db_default with partial, which
  also keeps the corpus lookup lazy. Renamed because "neutral" described only
  one of the two behaviours; docs/rust-pure-app.md §5.1 records the landed name
  for the proposal it implements.
- Deleted _before_formalize: a no-op hook with no overrider, on a branch whose
  thesis is that applications ship no Python. What it documented is now a
  comment where it matters, and the "hooks an application backend may override"
  banner over _context went with it.
- _run_blocking has one body, guarding on nullcontext() when there is no
  semaphore.
- Hoisted the function-local imports that had no reason to be local (io.context,
  diagnostics.timing, sandbox.recipes); the spec.solana.build one stays and now
  says why the generic host doesn't name a chain at import time.
- RUST_FORBIDDEN_READ is one literal instead of being rebound four lines after
  it is defined.
- RustLanguage.source_crate is a method: as a Callable field it advertised an
  injection point that source_crate_of's isinstance dispatch makes meaningless.
- AppDescriptor.unit_noun(plural=) owns the component_noun fallback and the
  pluralization that cli.py spelled twice; cli.py's helpers take
  app: RustApplication.
- store.py: dict comprehension -> dict().

Tests: new test_rustapp_toolchain_sem.py covers _run_blocking (serialize_toolchain
had no coverage at all, so a rewrite of that guard could have gone unnoticed) —
including that four concurrent callouts never overlap and a raising one releases
the permit. test_rustapp.py pins the help text the duplicate parser had lost, the
declared-arg threading, and unit_noun.

pyright 0 errors; 463 passed, 11 deselected with the demo wheel importable.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
crucible_kb was half registered: composer.rag.db.KNOWLEDGE_BASES carried its
connection and rag_env._FACTORIES carried a factory, but the module that factory
imports (composer.tools.crucible_rag) lands in PR3. The tag therefore passed
validate_rag_db — both halves present — and then build_rag_tools caught the
ModuleNotFoundError in its degrade-on-anything path and logged "RAG unavailable",
reporting a repo gap as an environment condition. That is the confusion rag_env's
two failure modes exist to keep apart, and it was reachable: a wheel declaring
crucible_kb would have run with no RAG and a single warning line.

Both registries are empty now, so such a wheel fails at descriptor load with "not
a registered RAG corpus" instead, and PR3 adds the tools module, the _FACTORIES
entry and the KNOWLEDGE_BASES entry in one go. CRUCIBLE_DEFAULT_CONNECTION goes
with them (nothing else read it), as does the comment naming
composer.scripts.rag_import, which does not exist on this branch either. The
error message now says "none is registered yet" rather than "known: []".

The pyproject.toml crucible comments stay: nothing there points at a missing
module (the entry points that did were deleted earlier), so they only explain why
those lists look short.

Tests: new tests/test_rag_env.py — the registry had no coverage at all. Includes
half-registrations (either half) still refusing, which is the shape that slipped
through, and a stub registration that doubles as the spec for what PR3 adds.

pyright 0 errors; 470 passed, 11 deselected.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`_all_or_none` gave both of the driver's overlaps one fate, which is more
than either needs.

The preflight is cheap by construction, so there is nothing to save by
cancelling it: await it first, and let its failure cancel the analysis
agent racing it — the direction where the spend actually is. An analysis
failure now waits the preflight out and reports itself.

The second pair (`prepare_formalization` ∥ extraction) goes back to
awaiting each in turn, no cancellation either way.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`.sandbox_cargo` / `.sandbox_rustup` / `.sandbox_tmp` were spelled out in the
recipes that create them, in the forbidden-read regex that has to hide them from
the source tools' file listing, and in a test's assertions. Hoist them to
SANDBOX_{CARGO,RUSTUP,TMP}_DIR next to the functions that create them, and build
the regex branches from those via re.escape (the joined pattern is byte-identical
to the old literal).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ericeil and others added 2 commits August 4, 2026 11:16
This branch is the Rust *backend* framework (PR2) on the ecosystem seam (PR1). It
had also accumulated the code for building the program **under analysis** — which
belongs to the backend that does that, not to the framework. A Rust backend need
not build a crate to validate a program, nor depend on the analyzed crate, nor use
the sandbox at all, so none of it can sit in the layer every Rust backend shares.
It moves forward to `eric/crucible-app` (PR3).

What goes, by area:

* **The Solana build capability** — `composer/spec/solana/build.py` in full
  (`build_program`, `warm_cargo_cache`, the `Anchor.toml`/`declare_id!` program-id
  resolution, the IDL address fill-in), and the warm/build/place-IDL half of
  `run_workspace_prep` that drove it.
* **Cargo crate resolution** — `composer/spec/cargo.py`, plus the `RustLanguage`
  facet and `source_crate_of` dispatch it was reached through. `ecosystem.py` is
  back to what PR1 wrote: `RUST = Language(...)`.
* **Sandbox recipes** — the private per-run `RUSTUP_HOME`, the `PATH`
  `cargo-build-sbf` install tree, `~/.gitconfig`, the pinned registry protocol,
  `CARGO_NET_OFFLINE=true`, and the `SANDBOX_*` scratch-dir constants.
  `composer/sandbox/recipes.py` is byte-identical to master again.
* **The confined-build exclusions** in `RUST_FORBIDDEN_READ` (`.sandbox_cargo` /
  `.sandbox_rustup` / `.sandbox_tmp` / nested `target/`). PR1 had already deferred
  these to "the layer that introduces confined Rust builds" and PR2 took delivery;
  the premise was wrong, and the NOTE now names the *backend* instead.
* **Crucible's report vocabulary** — the `"crucible"` outcome/group labels and
  `ReportTerms`, and its member of the closed `ReportBackend` set.

Two seams replace the imports, both in `composer/rustapp/toolchain.py`, both empty
here and registered per chain by the application that needs them:

* `WORKSPACE_TOOLCHAINS` — executes the toolchain half of a `workspace_prep` plan.
  The host still writes the plan's `files` (ecosystem-neutral) and reports the IDL
  path back as the `idl` context key; it just no longer knows what a build is. It
  takes the analyzed `SourceFields` rather than a resolved crate, so the framework
  holds no Cargo shape. **Unregistered raises** — a plan that only places files
  never asks, so reaching it means the wheel asked for a build nothing can perform,
  and skipping it would resurface as a compile error the authoring agent can't fix.
* `SOURCE_CRATES` — resolves `AuthorInput.program_crate`. **Unregistered degrades**
  to an all-empty `ProgramCrate`: that is already what Solidity and an unreadable
  layout yield, and the SDK's `ProgramCrate::resolved` fills it from the wheel's own
  convention, so "no resolver" and "nothing to resolve" are honestly the same answer.

The wheel ABI is untouched (`WorkspacePrep`, `ProgramCrate`, `AuthorInput`, the
`Sandbox` argv prefix), so PR3 re-adds no interface — only implementations.

The null Solana backend was reporting under `backend_tag="crucible"`, borrowing a
real verifier's wording for an all-UNKNOWN report. The closed `ReportBackend` set
gains **`"none"`** for it — a pipeline that records properties without verifying
them — whose `UNKNOWN` reads "Unverified" rather than "Unknown". Three framework
test fixtures that named their fake wheel `"crucible"` are now `"demoprover"`, and
the verdict-rollup / report tests assert a generic backend's words.

Generic mechanism that pointedly stays: `Verdict.message` and its rendering,
`Outcome.parse`, `outcome_label`/`outcome_glyph`, and the `argv_prefix` confinement
seam a wheel may or may not use.

Verified: `pytest -m "not expensive"` 439 passed / 11 deselected, `pyright` 0
errors. The forward half is a patch verified both ways against this tree: applied,
476 passed / 0 errors; reverse-applied, back to exactly this state.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The ecosystem PR (#96) landed on master, so this branch rebases onto master
directly instead of onto `eric/ecosystem`. Master moved three APIs underneath
the Rust framework in the meantime; this is the reconciliation.

* **The source-tool read filter is a predicate** (#120, plus the graphcore
  `vfs-forbidden-predicates` bump the rebase brings in). `FS_FORBIDDEN_READ`
  is gone; `build_default_env` takes `GlobalExcludeArg` — the `str |
  Callable[[PurePath], bool]` union `Language.default_forbidden_read` already
  declares — and defaults to `fs_forbidden_read`. `RUST_FORBIDDEN_READ` stays
  a pattern: nothing in the Cargo layout needs carving back out of an excluded
  directory, which is the case the predicate exists for.
* **`TieredProviders.provider_kind` is now `provider_service`.** Same rename
  `composer/pipeline/cli.py` carries for the built-in entry points.
* **`llm_factory` is gone from `composer.workflow.services`** — an unused
  import here and in `test_solana_gate.py`, so both just drop it.
* `InMemoryTextFile` takes a `ContentRenderer`, not a `provider` string.

Verified: pyright 0 errors, 573 passed / 11 deselected. (`hypothesis` was
missing from the local venv, not from `pyproject.toml`'s test group — a local
gap, present on master too, not something this branch introduces.)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ericeil
ericeil changed the base branch from eric/ecosystem to master August 4, 2026 18:35
ericeil and others added 3 commits August 4, 2026 16:12
`PipelineBackend` was a structural `Protocol`, so a backend's eight type
arguments were never written anywhere a checker could see them — each one
restated them in a docstring instead, and both had drifted: the null Solana
backend listed 7 of the 8 (no `Pre`), and `ProverBackend` claimed
`A = ComponentSpec` when its store is keyed by `ComponentSpec | InvariantSpec`.
Conformance was only checked where a backend reached `run_pipeline`, and a
renamed member would have silently stopped matching there rather than at the
definition.

It is now an `ABC` with the three methods abstract, and each backend names its
type arguments in its `class` line.

The four non-method members stay read-only properties — the shape the Protocol
already declared — because that is what nominal inheritance allows: a mutable
attribute override is invariant, which would reject `ProverBackend` narrowing
its store to `ProverArtifactStore` (its prepared system needs
`write_component_runs`) and `RustBackend` deriving its guidance from the wheel's
descriptor. Declaring them as attributes instead rejects the derived properties;
declaring them as properties breaks any same-named dataclass field at runtime,
since the generated `__init__` assigns through a setter-less property. So each
backend holds its store in a field and returns it from the accessor.

The driver's signature is unchanged, so `run_pipeline`, `cli.Continuation`, and
both entry points needed no edits; the partial backend stubs in the pipeline
tests still duck-type, as the driver never does an `isinstance`.

One trade: pyright cannot flag a subclass that omits an abstract property (an
inherited declaration counts as declared), so that mistake now surfaces as a
`TypeError` at construction rather than at the call site.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The manifest format and its importer arrived with the Crucible application, but
nothing in either is Crucible's: `import_format.py` is a pydantic schema with no
RAG-stack imports at all, and `rag_import.py` reads any manifest and drives the
shared `BlockBuilder` + the dual-path DB ingestion. They belong with the
descriptor-driven RAG seam (`composer/tools/rag_env.py`, `KNOWLEDGE_BASES`) that
already lives here, so an application contributes a corpus as data rather than as
composer-resident Python.

This also settles two dangling references on this branch: `docs/rust-backend-api.md`
already pointed at `composer.scripts.rag_import` as the mechanism a wheel's corpus
arrives through, and the comment naming it in `composer/rag/db.py` had to be dropped
when the crucible registration was deferred. Both are accurate again. `KNOWLEDGE_BASES`
stays empty and `rag_env._FACTORIES` is untouched — the mechanism ships corpus-free,
and both halves of the first corpus still land with the application that declares it.

`docs/rag-import-format.md` comes along, rewritten where it assumed the Crucible app
was present: §4's registry example is empty rather than seeded, §7 lists what the
mechanism ships instead of what Crucible did with it, and the links into
`rust/crucible-app/` are gone. Crucible remains named as the first adopter, with its
own corpus documented on its own branch.

Tests: new tests/test_rag_import.py — the importer had no coverage. Pins both indexes
being fed, `part` numbering across sections and across manifests sharing a DB (the
`(headers, part)` unique key spans both), per-section code-ref tagging, the long-section
split, and the version / unresolvable-target refusals. It needs spaCy transitively via
`text_processors`, so it `importorskip`s like `test_rustapp` does for its wheel.

pyright 0 errors; 583 passed, 11 deselected.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…the rest

The five rust-* design notes were written as successive proposals, each
superseding the last: the IoC decider loop, the passive-service API that
replaced it, the pure-app seams that made Crucible descriptor-driven, and the
PyO3 tier survey behind all of it. What shipped is the union of the last three,
so four of the five documented code that no longer exists — `RustSession`,
`resume`, `Command`/`Observation`, `Effects`, `drive_session` — alongside a
`composer/crucible/` package and a `rust/crucible-app` crate that are no longer
in this tree at all.

Replace them with one reference for the seam as built: the ten callouts, the
descriptor, the run end to end (preflight ∥ analysis, the staged setup artifact,
the fused author→validate loop), the in-loop judge, target-shared verdicts, the
two chain seams, confinement, and what a new application actually writes. Only
current design; the proposals, tier surveys and work breakdowns are dropped.
Section numbers are stable so code comments can cite them, and every inbound
reference is repointed.

The three docs that survive on this branch had drifted against the same
refactors, so correct them too rather than leave them contradicting the new one:

- application-abstraction: the per-app `run_*_pipeline` wrapper it documents is
  gone — both apps now go through the shared `cli_pipeline` and its
  continuation, the ecosystem is an explicit driver argument, and both phase
  enums grew a discovery phase.
- formalization-abstraction: `Formalizer`/`PreparedSystem`/`ComponentOutcome`
  are all generic over the unit type, the driver's data types live in ptypes,
  and `StagedFormalizer` — half of what `prepare_formalization` may return —
  was missing entirely. Line-number citations had drifted; replace them with
  symbol names so they can't drift again.
- command-sandbox: the mechanism is accurate, every consumer reference was not
  (`RealEffects`, `warm_cargo_cache`, `build_program`, the Crucible store and
  repo resolution), and it linked to a doc and two gate tests that aren't here.

Also fix two code comments that repeated a doc claim shown to be false: header
paths are neither left-packed nor truncated (`_normalize_head` maps position to
column and raises past six), and `run_local_command` no longer backs a
`RunCommand` effect.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant