Shadow
Shadow has two jobs. It gives developers and agents a place to work that looks like production, built from a sanitized copy of production data that keeps moving forward. And it gives them a repeatable way to check a change: run the current build and the candidate from the same starting state, with the same inputs, and compare what each did. Keeping the two jobs apart matters, because a world that keeps moving cannot also be the fixed starting point of an experiment.
Shadow is a design. The pieces it builds on exist: separate dev and prod configuration, seeding and provisioning steps, graph and Service instrumentation, trace propagation and nightly backups. Publishing bases, the workspace lifecycle and the comparator are not built. Capture and replay is the build design for recording operations and running them again.
Bases, workspaces and runs#
- Base. A trusted materializer reads approved production data, sanitizes it under a versioned policy, validates it and publishes an immutable base revision.
shadow-currentnames the latest accepted base. - Workspace. A developer or agent forks one base into isolated, writable resources with its own credentials, lease and expiry. There are two trust tiers, dev and prod, and a workspace is a dev instance, not a third environment.
- Run. A verification run pins one base until it ends. Exploratory work can refresh from a newer base; a run cannot.
A run fixes everything that decides its result:
(next_state, observations, effect_intents)
= Run(artifacts, initial_state, admitted_inputs; dependency_policy, nondeterminism_control)
Artifacts are every build involved: client, services, framework, configuration and migrations, identified by content hash, because a Git commit does not capture uncommitted changes. Initial state covers every store that takes part. Dependency policy says which effects really happen. Nondeterminism control says which clocks, random values and orderings are recorded or simulated.
To compare two builds, fork both from the same base, give them the same input, and keep the next base publication outside both runs. Yesterday's traffic replayed against today's base is a production-shaped test, not a reproduction of yesterday: reproducing a past failure needs the past state or a recording of the boundary.
Three ways to run#
| Profile | State and dependencies | What a pass means |
|---|---|---|
| Live Shadow | Real isolated stores and approved sandbox dependencies | The change works in a production-shaped world |
| Controlled replay | A pinned base or recorded boundaries, fixed inputs and controlled ordering | The result repeats, within the stated fidelity |
| Performance and faults | Real dependencies at representative capacity, with injected faults | The system holds its targets and recovers, for this topology and workload |
Where effects stay real#
Every operation in a run gets exactly one policy, chosen before the run starts:
| Policy | Effect |
|---|---|
REAL_SHADOW | Runs against a verified, isolated workspace resource |
RECORDED | Returns the recorded result of a matching operation |
SIMULATED | Runs a named, versioned model with stated limits |
DENY | Blocks the effect and reports it |
APPROVED_SANDBOX | Runs against an external sandbox that was explicitly approved |
Several layers may observe the same call, but only one substitutes its result. A call with no matching record fails the run; it never falls through to a real dependency. Safety comes from the workspace's authority, not from the HTTP method: an isolated insert can be safe, while an idempotent write to production is never within a dev workspace's rights. Recorded model answers test orchestration, not model quality.
Isolating each store#
| Store | How a workspace gets its own copy | Watch out for |
|---|---|---|
| Postgres | A real restore or clone, or an isolated database with all required state | An overlay schema with search_path does not merge base rows; sequences, constraints, grants and row-level security need explicit handling |
| R2 | Immutable base objects plus the workspace's own writes and deletions | Never read through to production on a miss |
| D1 and KV | Separate seeded resources | An empty local store is not the base |
| Durable Objects | An isolated namespace, with stored state exported and restored by the application | Memory, live sockets and pending alarms cannot be cloned |
| Queues and workflows | Workspace-owned names and IDs | Either run the producer or inject its recorded event, never both |
| Memgraph and ClickHouse | An isolated instance or a verified access scope | Rebuilding a projection does not test its original ingestion |
| Clients | Seeded local database, cache and pending work, with fresh workspace sessions | Never copy production refresh tokens, device keys or notification destinations |
A shared dev resource can be fine for functional work, but it cannot support a claim about uncontended performance.
Publishing a base#
Only the materializer may read production. It publishes in five steps:
- Take a consistent snapshot of each source and note its position.
- Transform it under the privacy and schema policy into a staging base.
- Where change data capture is used, apply committed changes up to a later position, saving progress together with the applied changes.
- Validate integrity, relationships, schema, policy and checkpoint completeness.
- Publish the base and move
shadow-currentto it in one step, keeping the previous base if anything failed.
Start with snapshots; add change data capture only when freshness really requires it, because logical replication does not copy DDL or sequences and a lagging slot retains WAL. A base across several stores is a vector of source positions, not one global transaction. Deletions survive rebuilds, so an old snapshot can never bring back removed data, and a changed sanitization policy creates a new base.
Checking a change#
Three checks work together:
| Check | Purpose |
|---|---|
| Contract assertions | Stored state, authorization, invariants, visible output and approved effects meet the requirement |
| Baseline against candidate | The same state and input reveal regressions, or confirm an approved change |
| Production evidence | Captured behaviour adds realism and known edge cases |
Production can contain a bug, so matching the baseline is never enough on its own. Comparators may ignore only fields declared nondeterministic; they never hide ordering, authorization or duplicate effects. A result is one of passed, assertion failed, policy blocked, capture incomplete, provisioning failed or measurement failed. A denied dependency that did nothing is not a pass, and neither is a missing trace.
Existing tools keep their roles: Kotlin tests, Karate, Playwright, Maestro, k6 and Worker runtime tests each cover their own layer, and Shadow supplies the state, inputs and comparison around them.
Example: send, retry, reconnect#
One base holds two fresh workspace users, a conversation and some history. Baseline and candidate each get writable copies. The run covers sending a message, storing it, delivering it in real time and creating a push intent; real push delivery is denied.
- Send one message with idempotency key
k. - Let the database commit it.
- Lose the acknowledgement after the commit.
- Reconnect and retry the same send with
k. - Read the stored state, the real-time output and the push intent, without injecting the downstream event a second time.
The assertions: one stored message, one stable message ID, one visible message, and no effect outside the workspace. A build that stores two rows fails; the fixed build stores one. The failure is kept as a capsule: build, base and assertion versions, the workload and key, where the fault was injected, the causal journal, the state difference and trace references. The capsule rebuilds the starting state and reproduces the failed assertion, so it can become a regression test.
Clients and live updates#
A user journey goes from an action through local and graph state, backend effects and delivery to what is drawn on screen, so backend replay alone is not enough. Client runs pin the client and service builds, the device and its seeded local data, and cover offline sends, restarts, reconnects, stale caches, denied permissions and notification taps. Android, iOS, web and desktop are checked separately; the same semantics do not mean the same timing.
A clean start does not test an update. To verify a live update, start work on the old revision, update, and check state migration, new admissions, stale callbacks and draining. Rollback has to handle migrated data, not only old code.
Agents#
An agent proposes a change, selects the graph scopes it affects and runs the same tasks a person would. Unknown dynamic paths, shared schemas, auth, configuration and serialization widen the scope; the absence of observed traffic does not prove there is no dependency. A fast corpus runs while editing, larger journeys at checkpoints, and full release profiles before a release.
Acceptance belongs to the product requirement and its approved assertions. A candidate cannot pass by re-recording mocks, weakening a comparator, changing expected output or deleting a failing capsule; changing the oracle is a separate, reviewed action. Recorded content is untrusted input, including text later shown to an agent, and can never authorize commands or change acceptance rules. Agents work through Conductor and the workspace kernel, not through a second runner.
Privacy#
Classify fields before anything is exported, and keep only what a test needs. Transforms must preserve the equality, relationships and formats a test depends on; hashing a value does not anonymize a person. Workspaces get fresh credentials. Capsules carry an access scope, a policy version and a retention period: pinning a capsule keeps a useful case within policy, not forever, and deletion requests reach bases, raw artifacts, catalogs and old snapshots.