State, Events, and Artifacts: Recording Task Progress So It Can Be Resumed
Using revision/CAS, lease fencing, causal event chains, and content hashes to turn recovery and auditing from model narration into a verifiable protocol.
On this page · 21 sections
When an Agent says "the task is complete," all that proves is that it generated that sentence. For a task that runs concurrently, retries, waits on the user, recovers across processes, and may even trigger external side effects, the system must also answer four more specific questions:
- which execution is currently valid;
- which actions actually happened;
- which version of the inputs a result corresponds to;
- exactly which set of bytes was delivered.
The Marshall Runtime answers these questions with three kinds of records: State, Event, and Artifact. They are not three progress documents in different formats; they are three distinct consistency responsibilities. The table below compares which question each record answers and what it cannot replace:
| Record | Question it answers | Typical way to read it | What it cannot replace |
|---|---|---|---|
| State | Where the currently valid execution stands | Read the current projection directly | Cannot explain the full history |
| Event | Why the current state was reached | Audit or recover along the causal chain | Not suited to computing the current state from scratch every time |
| Artifact | What content downstream actually consumes | Resolve exactly by path and Hash | Cannot say whether an action was authorized or whether it succeeded |
The point of this design is not "storing a few more JSON files." It is to establish a closed proof: State points to the current execution, Events prove the causal order of decisions and actions, and Artifacts prove that output content has not been quietly swapped out.
The Short Version
- Saying "done" proves only that the Agent generated that sentence; State, Event, and Artifact carry three distinct consistency responsibilities, and only together do they form a closed proof.
- State is the current projection: Revision/CAS guarantees that concurrent conflicts are never lost silently, the Lease limits ownership with a time window, and the Fence rejects late writes from former owners.
- Event is an append-only Ledger: the Hash Chain provides tamper evidence, not a signed identity, and Decision → Action → Outcome keeps approved, initiated, and confirmed by Readback apart.
- An Artifact's path and Hash must appear as a pair. Recovery validates all three layers together and may end in continuing or in a Block; the design has real costs and is not a general-purpose distributed transaction.
State: the current projection must carry concurrency semantics
The core identity of StateV3 can be compressed into the following set of fields:
audit_id / workflow_version / stage
attempt / run_id / active_generation / resume_epoch
revision / lease.fencing_token
They all look like version numbers, but their responsibilities differ:
attemptdistinguishes different attempts at a Stage;run_ididentifies this specific run;active_generationselects the currently valid set of computations and artifacts;resume_epochdistinguishes points in time after a Question Gate resume within the same Generation;revisionis the concurrent-write version of the State file itself;fencing_tokendistinguishes the Owners that acquired execution rights one after another.
Even if a result returned by a Worker is correct in content, it cannot enter the current projection as long as it is bound to an old run_id, an old Generation, an old Resume Epoch, or an old Fence. Correct content and a valid execution are two different things.
Revision/CAS prevents lost updates
Every State modification must carry the expected_revision the caller read. This is CAS (Compare-And-Swap), that is, compare the version first and write only if it matches.
The Runtime rereads the current state inside the lock, and only if the actual Revision equals the expected value does it run the Mutator, validate the StateV3 contract, increment the Revision, and atomically replace the file:
read revision = n
compute candidate
CAS(expected = n)
current == n -> validate -> write revision n + 1
current != n -> RevisionConflict
Without this step, several parallel executors could all start from the same Revision and each write a new State that looks complete, with the later writer overwriting the earlier writer's Worker Result, Approval, or Delivery.
CAS does not judge which business conclusion is more correct; it only guarantees that concurrent conflicts are never lost silently.
Atomic replacement also has an easily overlooked edge: the system call may already have completed the replacement while the caller receives only an exception from the cleanup phase. Marshall labels this case StateCommitAmbiguous and requires an exact Readback (that is, reading back the state actually on disk) before deciding whether to retry. Replaying the write directly would mishandle "unknown whether it succeeded" as "definitely failed."
The Lease decides who is working; the Fence decides who can still commit
The Lease in State contains the Owner, a Token Hash, the acquisition time, the expiry time, and a monotonically increasing fencing_token. The Bearer Token is returned only to the holder, while the persistence layer stores the Hash; an ordinary State Mutation must prove that it still holds the currently valid Lease.
Lease expiry cannot immediately stop a Worker that has already been dispatched. The old process may merely have been paused by the network, and it may keep committing after it resumes.
When a new Owner acquires the Lease, the Fence increases from n to n + 1, and subsequent Results, Capabilities, and Actions are all bound to the new Fence. That way, even if the old Owner is still alive, it is just a Zombie Writer: it holds an expired Bearer but cannot get past the current fence.
Lease and Fence therefore solve two different problems:
- the Lease limits current ownership with a time window;
- the Fence rejects late writes from former owners with a monotonic generation number.
If the downstream is an external Provider, the Fence is effective only when the Provider Gateway, the Mutation Intent, or the Readback protocol continues to propagate it. A number in local State cannot automatically revoke a request that has already been sent to an external system.
Event: what is recorded is not log text but causal constraints
Marshall's memory/events.jsonl is an append-only Ledger, that is, a record file that is only ever extended at the end and never rewrites history. Each Event contains:
sequence / event_id / audit_id / kind / actor
parent_event_id / decision_id / action_id / outcome_id
payload / metrics / previous_hash / event_hash
Three rules link the records into a chain:
sequencemust increase contiguously from 1;previous_hashmust equal theevent_hashof the preceding record;- the current Hash is computed over canonicalized JSON.
Deleting, inserting, reordering, or modifying historical records breaks the chain that follows.
What a Hash Chain provides is tamper evidence, not a signed identity. As long as an attacker can rewrite the entire Ledger and replace the root of trust, SHA-256 alone cannot prove who wrote it. It therefore still depends on file ownership, permissions, locks, and external trust boundaries, and must not be described as an unforgeable ledger.
Decision → Action → Outcome
For an action with side effects, recording a single "execution succeeded" entry is not enough. EventV1 splits the causality into three steps, shown below:
The Runtime mechanically validates the relationships:
- a
decision'sdecision_idmust equal its own Event ID; - an
actionmust reference a Decision that has already appeared, and take it as its Parent; - an
outcomemust reference an Action that has already appeared and is not yet finished, and take it as its Parent; - an Action can be terminated by at most one Outcome.
This adds an important layer of semantics over ordinary logging: an Action cannot appear out of thin air, and an Outcome cannot appear before its Action. For questions such as "has it already been pushed?" or "has the Provider been updated?", the system can distinguish approved, initiated, and confirmed by Readback, rather than collapsing the three into one boolean.
observation and checkpoint, meanwhile, cover non-side-effect observations and recovery anchors. They can record input snapshots, recovery evidence, or consistency checks, but they cannot pass for a complete causal chain of an external Mutation.
Truncation recovery must preserve the bad tail
The most common failure of an append-only file is not a record modified in the middle, but a process crashing while writing the last record. Marshall opens a narrow recovery path only for "a proven interruption of the final write":
- if the last segment parses as a complete, causally valid Event that is missing only its newline, the newline is appended;
- if the last segment cannot be parsed, the raw Tail is first saved by Hash as immutable quarantined evidence under the same Audit, and the file is then truncated to the last fully verified newline;
- if the Tail parses but violates the Schema, the Hash, or causality, the Runtime Fails Closed, that is, it refuses to continue; semantic corruption must not be disguised as an interrupted write;
- after recovery, a Receipt is generated and a subsequent Checkpoint must explicitly acknowledge it; until it is acknowledged, further Appends are forbidden.
This strategy preserves two facts: the verifiable Prefix is still trustworthy, and the bad Tail has not been deleted without a trace.
Artifact: the path only locates; the Hash defines the content
What the Artifact Registry registers is not "some file name" but a content binding:
artifact_id
path
sha256
dependencies
retention_class / expires_at
status / registered_at
Before registration, the file must actually exist and its actual Fingerprint must equal the declared SHA-256; the same Artifact ID cannot be rebound to different content. Only by checking both path and Hash on a downstream read can the following kind of error be avoided:
design/final.md still exists
but its content has changed from Hash A to Hash B
State still references the old design A
Checking only the path would treat B as A. Storing only the Hash without a controlled path would make it impossible to resolve the actual bytes within the Audit Package. The two must appear as a pair.
An Artifact can also declare dependencies and a retention policy. During cleanup, content that an Active Artifact still depends on, or that is marked legal_hold or never, cannot enter an ordinary Purge. Deletion is not a simple unlink; it has to go through candidate computation, authorization, and a Purge Receipt. Otherwise the audit chain might reference a piece of evidence that can no longer be read.
For an external Delivery, the Registry requires that the referenced Artifact be registered and that the associated Mutation Intent have succeeded; the Target, Provider Locator, and Readback Hash in the Intent must match the Delivery exactly. In other words, the existence of a local artifact does not mean external delivery is complete, and a completed external delivery must be closed by a readback from the Provider side.
How the three layers form a recoverable causal chain
Take a Worker producing a design report as an example:
State
current identity = attempt a / generation g / resume r / fence f
node = post-draft-critic in_progress
Event
Decision D: select a security-perspective review
Action A: Dispatch worker-x, parent = D
Outcome O: Worker Report published, parent = A
Artifact
worker-x-report.json
sha256:...
dependencies = [context-manifest, design-draft]
On recovery, the Node cannot be marked Completed just because the report file is there. The Runtime must also verify:
- whether the report's identity equals the current State;
- whether the Dispatch has a legitimate Decision;
- whether the Outcome corresponds to the same Action;
- whether the report's path and Hash match;
- whether the Context and Draft it depends on are still the original versions.
If any one of these fails, the report can only go down the Stale or Late Result path.
This mapping shares its thinking with W3C PROV-O: an Artifact resembles an Entity, an executed action resembles an Activity, the Parent/Worker resembles an Agent, and used and wasGeneratedBy express the provenance relationships of inputs and outputs. Marshall uses its own JSON contracts and does not implement full PROV-O; what is borrowed here is the modeling principle of Provenance.
Recovery is not "continuing from the next line of State"
A safe recovery process includes at least the following checks:
- read and validate the StateV3 Schema, the Revision, and the current execution identity;
- validate the Events' contiguous Sequence, Hash Chain, Audit Identity, and causal references;
- check for any unacknowledged Ledger Recovery Receipt or Partial Commit;
- validate the path, Hash, dependencies, and Freshness of every Artifact referenced by State;
- distinguish Current Results, Stale Results, and Late Results by
attempt / run / generation / resume / fence; - on seeing an Action without an Outcome, first read the state of the target system or Provider for Reconciliation rather than blindly resending;
- compute the single safe next step and project it back into State through a new Revision CAS.
The result of recovery may be to continue, or it may be to Block. In the following cases, automatically picking the "most likely" branch amplifies the damage:
- the result of an external action cannot be read back;
- the Events contain a record that parses but is invalid;
- no unique binding can be established between State and Artifact.
The dual-write window between State and Event
State and Event live in different files; they are not naturally a single transaction. If the State CAS fails after the Event has been written, or the State has been replaced but the result of the Event Append call is uncertain, a dual-write window can open.
A mature protocol must specify, for every kind of cross-store operation:
- a fixed write order;
- a unique Operation ID and Payload Hash;
- which side is the rebuildable projection;
- which Readback determines, after a failure, what has already happened;
- whether a Partial Commit Journal, a Recovery Receipt, or a Checkpoint is required;
- a global lock order, so that recoveries do not wait on each other.
Some of Marshall's recovery paths use the fixed order state.lock → events.lock and perform the State CAS while the Event Snapshot is still protected by the lock; Patch Promotion has a separate Partial Commit Journal. This reduces ambiguity on specific paths, but it should not be understood as a general-purpose distributed transaction on a file system.
Common failure modes
State Lost Update
Two executors write from the same Revision, each overwriting the other. The fix is Revision CAS, not "trying to call serially."
Expired Lease Zombie
An old Worker returns a high-quality result after its Lease has expired. The fix is the Fence, the Generation, and the Run Identity; the result cannot be readmitted just because its content looks reasonable.
Event before Decision / Outcome without Action
The log order looks complete, yet the causality does not exist. The Parent and ID constraints on Decision/Action/Outcome must be verified by code, not implied by field names.
Truncated or Rewritten Ledger
Only a provable interruption at the very end may be recovered; corruption in the middle, or a tail record that parses but is invalid, must stop the process. A Hash Chain can detect rewriting, but it cannot replace signatures and access control.
Orphan Artifact
A file exists but no current State references it; or the Registry has a record, but the file's bytes have changed. It cannot automatically become the current result; it should be quarantined and handled only after its Retention has been checked.
Late Result Re-enters Current State
Writing a late result straight back into the Active Node reintroduces old inputs into the new execution. A Late Result should be kept as evidence, but it must stay separate from the current projection.
Local Success Masks External Uncertainty
The local Outcome is written as a success, but the Provider has no corresponding Readback. External facts can be proven only by a Provider Locator, a Revision, or a content Hash; a local self-report is no substitute.
Where it applies, and the trade-offs
The three layers of State/Event/Artifact fit tasks that genuinely have the following properties:
- cross-process recovery;
- multiple Writers;
- asynchronous Workers;
- external actions that cannot be safely repeated;
- long-retention audit requirements;
- pipelines that must bind outputs to exact input versions.
The costs are just as real: Schema migrations, locks and atomic writes, Hash computation, Recovery branches, retention policies, a test matrix, and more disk I/O.
More importantly, the team must decide who the Authority is for each kind of record; it cannot treat State, Event, and Artifact all as the final truth at once.
Marshall is not pure Event Sourcing either: it stores the current State, while Events mainly carry causality, auditing, and recovery evidence, and it does not promise that every external system can be rebuilt merely by replaying all Events.
Temporal's Durable Execution, W3C Provenance, and Event Sourcing can all serve as design references, but their runtime guarantees do not automatically carry over to a file-based Runtime.
References
- W3C PROV-O: the standard Provenance model of Entity, Activity, and Agent, along with usage, generation, and attribution relationships.
- Martin Fowler: Event Sourcing: the responsibilities of current state versus the event sequence, the value of replay, and the complexity introduced by interacting with external systems.
- Temporal Documentation: a design reference for durable execution and failure recovery; used here only as an analogy, not as a claim that Marshall has Temporal's server-side history and replay guarantees.
Related notes
Agent Architecture: Should the Program or the Model Decide the Next Step
The difference between Workflow, Autonomous, and Hybrid is not the framework but who decides the next step. This article covers when each pattern fits, how each one fails, and a selection method that starts from task conditions.
LLM Runtime: Which Layer Should Own Rate Limits, Retries, and Routing
Once the second business, the second provider, and the second tenant show up, calling the SDK directly is no longer enough. This piece covers the responsibility boundary of an LLM Runtime, multi-model routing, reliability under high concurrency, and how to choose an observability approach.
Working on something similar?
I'm always happy to compare notes on distributed systems, delivery, and applied AI.
[email protected]