Pants (Rust engine, Python rules)
A statically solved rule graph selects typed Python coroutines, a memoized in-memory DAG runs them as a suspending scheduler keyed by generation counters, and every external process is a content-addressed action in a sharded LMDB store, local or behind REAPI.
Last reviewed: November 2, 2026
| Field | Value |
|---|---|
| Language | Rust engine (src/rust, ~86.6k lines in 252 files) + typed Python 3 rules (src/python/pants, ~308k lines) |
| License | Apache-2.0 (LICENSE) |
| Repository | pantsbuild/pants |
| Documentation | pantsbuild.org; in-tree how-does-pants-work.mdx, the-rules-api/concepts.mdx |
| Category | Polyglot build orchestrator; engine companion to pants (monorepo-tooling) |
| Clone (pinned) | $REPOS/build-systems-research/src/pants |
| Commit | 88f57cf3ec558cd2c0e48b339a41155c2b531c60 (2026-11-01), "Per-process sandboxer socket path (#23720)" |
| Tree version | src/python/pants/VERSION is 2.34.0.dev4; no tag points at HEAD |
| Engine crates | src/rust/rule_graph (static solver), src/rust/graph (runtime DAG), src/rust/fs/store |
| Store / remote | Sharded LMDB CAS + action cache; REAPI v2 client for cache, execution and bytestream |
NOTE
Delta against the workspace page. pants (monorepo-tooling) covers pants.toml, BUILD targets, source roots, resolves, the CLI and remote-cache configuration. This page goes below that surface: rule-graph construction, the dirty/clean protocol, digests and snapshots, what the "sandbox" really is, and the command-runner stack that reaches REAPI.
Overview
What it solves
A polyglot monorepo where the dependency graph is already encoded in source imports:
"Pants is a scalable build system for monorepos: codebases containing multiple projects, often using multiple programming languages and frameworks, in a single unified code repository." —
README.md
Design philosophy
Rules (@rule) are pure coroutines with complete type annotations; the engine owns execution, memoization and concurrency:
"A rule is a pure function (or, more precisely, a pure coroutine) that maps a set of statically-declared input types to a statically-declared output type." —
the-rules-api/concepts.mdx
"The engine is designed so that fine-grained invalidation, concurrency, hermeticity, caching, and remote execution happen naturally, without rule authors needing to think about it." —
how-does-pants-work.mdx
That purity is why the runtime DAG is a memo table. Rust owns ordering, invalidation and RPC; Python owns the rules. RuleGraph::new runs once per scheduler (context.rs); the builder exists to "produce a RuleGraph that allows dependency nodes to be found statically" (builder.rs).
How it works
1. Task model & scheduling
Static selection. Rule-graph nodes are RuleEntry, Param, Root and Reentry; a DependencyKey carries the product, the params the callee may consume, the params it must receive, and an optional by-name call signature (rules.rs). The dynamic node graph (Graph<NodeKey>) instantiates that choice for concrete params. The builder propagates live parameters, monomorphizes per valid parameter combination, prunes edges, and keeps UnreachableError entries so a bad plugin fails with a graph explanation (builder.rs, rule_graph/lib.rs).
Suspending execution. A Task node carries interned params, an optional positional argument key and the interned rule entry. On await, Context::get calls Graph::get_inner, which ensures the target entry exists, adds the caller's edge, and awaits its result (graph/context.rs, graph/lib.rs). The caller is suspended, not restarted — JFP §4.3's mechanism on Rust futures; bounded caps local and remote process parallelism separately (context.rs).
Cycles. The graph is a DAG "enforced on mutation" (graph/lib.rs); every 500 ms a watchdog breaks one member of each running SCC, and a node invalidated during a run is retried after 500 ms. RunId scopes a run, RunToken one attempt, and Generation is what dependents observe (entry.rs).
2. Rebuilding & correctness
In concepts terms this is suspending × verifying step traces (the Shake cell), with a constructive action cache below it, so it straddles JFP §5.2 and §5.3. An entry is NotStarted, Running or Completed; a completed value is Clean, Dirty, Uncacheable or UncacheableDependencies (entry.rs). The rebuilder is a verifying step trace: each dependency is recorded as (EntryId, Generation), and cleaning re-requests every dependency and compares generations:
"Unlike the RunToken (which is incremented whenever a node re-runs), the Generation is only incremented when the output of a node has changed." —
entry.rs
That is early cutoff: a re-run whose value compares equal does not advance its generation, so dependents stay clean — exact value equality, not a hash approximation.
Cleaning is speculative and parallel: attempt_cleaning joins all dependency checks with try_join_all, fails fast on the first mismatch, and cancels the rest; a mismatch clears the node's outbound edges and forces a re-run (graph/lib.rs). restartable() decides whether invalidation may propagate through a running node, and cacheable() / _uncacheable_rule mark results that must not outlive a run (node.rs, rules.py). The durable part is the process layer: a process is keyed by its action digest, so a cold daemon can still hit the on-disk action cache.
3. Dependency discovery
Three layers are often confused:
- Rule-to-rule edges are declared by type annotations and
awaitcalls; the Rust solver resolves them statically, and the AST visitor exists so a dynamically chosen call still contributes a static edge (rule_visitor.py). - File-to-file edges inside a target are inferred by parsing source text. Native Rust parsers for Python, JavaScript and Dockerfile live under
src/rust/dep_inference; Python merges their output with explicitdependenciesinresolve_dependencies(graph.py). - Package boundaries are
DependencyRuleallow/deny/warn actions (dep_rules.py).
There is no syscall, FUSE or ptrace tracing: inference is static parsing. find_owners maps a path back to its target, and target-graph cycles are detected separately, with file-level dependencies tolerated (graph.py) — the "declared, then trusted" position of please, not the traced model of buildxl.
4. Store & caching
CAS. Store wraps a local ByteStore and an optional remote one. The local half is ShardedLmdb: because "each LMDB directory can have at most one concurrent writer", it shards by the high bits of the fingerprint into 16 environments by default so writes proceed in parallel (sharded_lmdb/src/lib.rs). Files at or above 512 KiB spill to a filesystem store, a threshold chosen so two to three reads break even (store/local.rs). Loads are local-first, then remote back-fill and a second local read (store/src/lib.rs).
Digests and snapshots. Digest { hash, size_bytes } is the content handle, and a Snapshot is a digest plus a DigestTrie; its PartialEq compares only the digest (store/snapshot.rs). The Snapshot node does not watch paths: it expands globs through Scandir/DigestFile children, the actual invalidation roots (snapshot.rs, nodes/mod.rs).
Action cache. PersistentCache stores small values keyed by CacheKey:
"In order for this to be a cache, rather than storing the value under its own Fingerprint, the value is stored under the Fingerprint of the CacheKey." —
cache/src/lib.rs
A runner stack composes local/workspace and Docker/nailgun dispatch, bounded parallelism, remote execution, and the remote and local action caches (context.rs). ProcessCacheScope decides where a result may be cached; CacheContentBehavior whether a hit's digests are fetched, validated or deferred (process_execution/lib.rs).
5. Hermeticity & provenance
The sandbox is a directory, not a namespace. Each process gets a temporary directory, its input digests are materialized (directly, via the sandboxer, or as symlinks to immutable inputs), and the child runs with a cleared environment:
"It would be really nice not to have to manually set PATH but this is sadly the only way to stop automatic PATH searching." —
process_execution/src/local.rs
Process::env documents the contract: "No other environment variables will be set (except possibly for an empty PATH variable)" (process_execution/lib.rs). Absolute paths outside the sandbox remain readable and no read is intercepted, so hermeticity is enforced by declaration and cache-key construction, not by the kernel. A grep for bubblewrap, bwrap, ptrace, seccomp, landlock and unshare across src/rust/process_execution finds nothing.
The component named sandboxer is not an isolation boundary: it exists because materializing an executable while another fork inherits the write handle causes ETXTBSY, so a dedicated process writes executables over a Unix socket (sandboxer/src/lib.rs).
Provenance is absent: no SLSA, in-toto or attestation code outside Docker test fixtures.
6. Distribution
Distribution is REAPI and only REAPI: remote::CommandRunner speaks build.bazel.remote.execution.v2, submits an ExecuteRequest, waits on the long-running operation, and treats missing remote digests as retryable (remote.rs). The remote cache runner wraps a lower runner and consults the REAPI Action Cache before executing, with its own read/write flags and warning backoff (remote_cache.rs). Byte-store providers are pluggable (REAPI bytestream, file://, GitHub Actions cache), with action-cache providers selected the same way (remote_provider).
ProcessExecutionStrategy has four cases — Local, LocalInWorkspace, RemoteExecution(platform_properties), Docker(image) — each contributing a distinct cache-key value (process_execution/lib.rs); placement and queueing belong to the backend, and Pants runs no server-side graph.
7. Sparkles relevance
sparkles.build_primitives.task is a static, in-process DAG with no daemon and no persistent store, so the borrowings are mechanisms, not architecture:
- Generation counters as the dirty check. Equal output means no generation bump, so dependents stop.
- Per-edge dependency records.
(dependency, generation)makes clean/rebuild reasoning inspectable. - Cycle policy split. Enforce a DAG on mutation, plus a watchdog that kills one SCC member.
- Small-value cache beside a blob store. A key/value cache for action results plus a filesystem/object store for contents is cheaper than one CAS for everything.
Strengths
- Typed rule graph catches configuration errors before execution. Unreachable and shadowed rules are graph diagnostics, not runtime surprises.
- Early cutoff without hashing. Value equality and generation counters keep the check exact.
- A content-addressed process layer. Local cache, remote cache and REAPI execution share one key.
- Fine-grained invalidation. Only
Scandir/DigestFile/PathMetadatanodes are roots; aSnapshotinherits invalidation through them.
Weaknesses
- Hermeticity is declared, not enforced. No namespaces,
ptrace,seccomporlandlock; an undeclared absolute read succeeds invisibly.sandboxernames a materialization workaround, not isolation. - The graph is daemon-resident. Cross-run reuse needs
pantsdalive; a cold start re-derives the graph and relies on the action cache. - Inference is static parsing. Dynamic imports, generated modules and non-import file dependencies need explicit edges; there is no read observation to fall back on.
- Eviction is lease-based and incomplete. The local process cache has TODOs for GC.
- Two languages, a large surface. Rule bugs surface as Python exceptions inside a Rust scheduler, and ~86.6k lines of Rust plus ~308k of Python is a lot to match.
Key design decisions and trade-offs
| Decision | Rationale | Trade-off |
|---|---|---|
| Static rule graph at startup, instantiated at runtime | Type errors and unreachable rules fail before work; edges known for dynamic calls | A solver to maintain; reboots on rule-set changes |
| Suspending scheduler over Rust futures | Minimal work with dynamic dependencies; no restart-and-redo | Every edge is an await; cancellation and invalidation races |
| Generation counters, not hashes, for dirty checks | Cheap, exact early cutoff on comparable values | Only works while the graph is resident; not a portable trace |
| Speculative parallel cleaning, fail-fast | Hides dependency-check latency on wide graphs | Wasted checks on first mismatch; cancellation complexity |
| Directory sandbox with cleared environment | Cheap, portable, needs no kernel features | Undeclared reads allowed; isolation is a convention |
| Sharded LMDB CAS plus FSDB for large files | Parallel writers without a central lock; small values stay fast | Two storage paths; threshold and schema version to manage |
| One action key across local cache, remote cache, exec | A hit is a hit anywhere; backends are swappable | Strict key discipline (strategy, platform, env) |
ProcessCacheScope as a typed enum | Cache lifetime is a deliberate per-process decision | Seven variants and a default to get right |
Sources
pantsbuild/pantsat commit88f57cf3ec558cd2c0e48b339a41155c2b531c60(clone at$REPOS/build-systems-research/src/pants; HEAD dated 2026-11-01). Quotes are verbatim from the files cited inline at that commit.- Engine:
rule_graph/lib.rs,builder.rs,rules.rs,graph/lib.rs,entry.rs,node.rs,graph/context.rs,engine/context.rs,nodes/snapshot.rs,nodes/mod.rs; Python:engine/rules.py,internals/graph.py,rule_visitor.py,dep_rules.py. - Store and execution:
fs/store/src/lib.rs,store/local.rs,store/snapshot.rs,sharded_lmdb/src/lib.rs,cache/src/lib.rs,process_execution/src/lib.rs,local.rs,sandboxer/src/lib.rs,remote/src/remote.rs,remote/src/remote_cache.rs,remote_provider. - Docs in the clone:
how-does-pants-work.mdx,the-rules-api/concepts.mdx. - Siblings: concepts, please, bazel, buck2, buildxl, buildkit, rattle, perfect-dependencies, shake.