Harness Durability

The HarnessAgent (adk-harness) states its durability as invariants (spec 3.1 §7.12). Each row below is a test in adk-harness/tests/durability_tests.rs, which simulates a crash by dropping the harness — runner, stores and connections — in the middle of a run and opening a new one over the same SQLite file.

InvariantMechanismTest
A completed bash, write_file, edit_file, apply_patch or delegation never runs twice after a crash, retry or resumeThe tools are NonIdempotent, so the runner's action ledger records each call; before a turn, Harness::send and Harness::resume answer the calls a stopped process left unanswered from the ledger (already_succeeded, already_failed or outcome_unknown), and nothing executesa_completed_bash_never_runs_twice_after_a_crash
A held approval survives process loss and is answered from any processThe approval store is durable; another harness over the same store lists it, decides it and resumes the calla_held_approval_survives_process_loss_and_is_answered_from_another_harness
A resumed run is governed by the current mode and rulesThe policy reads the mode and rule stores at evaluation time; an approved call resumed after tightening to ReadOnly is refuseda_resumed_run_is_governed_by_the_current_mode_not_the_one_it_parked_under
Loosening cancels held callsHarness::set_mode answers every held call "cancelled by mode change" before writing; a held rm runs zero times after switching to Autoa_held_rm_in_ask_runs_zero_times_after_switching_to_auto
A plan step survives process lossThe plan graph is checkpointed; after a restart the gate is decided in the new process and only the remaining step runsa_plan_step_survives_process_loss
A held edit approved from a new process runs onceThe file tools' read records — the sha256 each agent last read or wrote per file — persist with the session (read_records), so the edit finds the read that preceded it; a file changed since is refused as devtools.stale, never edited against content nobody reviewed (spec 3.1 §7.33 fix 5)a_held_edit_parked_by_a_goal_runs_once_when_approved_from_a_new_process
Only one process works a runDurableWorker claims runs under fenced leases; two workers over one store complete the run oncea_durable_goal_survives_killing_the_process
An approved plan runs after a restartPlans are checkpointed in the store plan_checkpoint_store(url) names; a new process over the same database finds the plan and runs every stepan_approved_plan_runs_after_a_restart (checkpoint_store_tests.rs)
The Graph goal engine continues its thread after a restartThe goal's graph is checkpointed in the same store; the restarted process decides the held call and finishes on the first process's threadthe_goal_graph_continues_its_thread_after_a_restart (checkpoint_store_tests.rs)

After a crash

What to run after a crash, a kill -9 or a power loss depends on how the harness ran. adk-rust keeps its state in harness.db, or in the --store backend; under --ephemeral nothing is kept, so nothing resumes.

The harness ran asRunWhat happens
adk-rust goaladk-rust goal "GOAL" --until "CMD" --resumeContinues the latest unfinished goal in this workspace, or the one in --session ID, in its session at the iteration it reached. The stopped process's run is reclaimed once its 10-second lease lapses. A run parked on a held call that is still undecided runs nothing: the command lists the call and exits 3
adk-rust goal on a running kernelNothingThe goal is the kernel's process and keeps running when the terminal following it stops; adk-rust ps shows it
adk-rust code, or the REPL in its own processadk-rust code --session ID "continue", or adk-rust --session ID (--continue for the latest session in this workspace)A turn is not a durable run, so nothing resumes by itself. The next message in the session first answers every call the stopped turn left unanswered from the action ledger, then runs; held calls with decisions run first, once
The kernel, adk-rust upadk-rust up with the same --home and --store; a kernel installed with up --install restarts by itselfEach process the crash stopped is reclaimed once its lease lapses (30 seconds, DurableWorkerConfig::lease_ttl) and resumes from its checkpoint. Sleepers stay asleep, and cron occurrences missed while it was down fire as each wake's MissedFirePolicy picks them. Held calls stay in the approvals inbox, and a freeze in force at the crash still holds
An app on HarnessLaunchercargo run -- upAs adk-rust up, over the stores the app gave: HarnessLauncher::with_kernel_stores for the kernel's runs, processes, cron cursors and kill switch, with_session_service for sessions, and the harness's approval_store and action_ledger. A store left at its default is in memory and keeps nothing across the crash

What every form guarantees over durable stores:

GuaranteeMechanism
A call in flight at the crash never runs twiceBefore the session continues, each call the stopped process left unanswered is answered from the action ledger — already_succeeded, already_failed, or outcome_unknown when the ledger holds no outcome, as for a non-idempotent call that began and never finished — and no tool executes (Runner::recover_unanswered_calls). The model decides whether to call it again, as a new call
A held call survivesThe approval store is durable; a decision from any process or surface runs the call once
One process works a runLeases are fenced. A reclaimed run starts a new attempt; a run that already used max_attempts (3 by default, NewRun::DEFAULT_MAX_ATTEMPTS) fails at its next reclaim instead of resuming
The current mode governsA resumed run reads the mode and standing rules at evaluation, not those it parked under

To see where things stand:

QuestionCommand
Which processes the kernel holds, and in what stateadk-rust ps (a running kernel only)
What a session did before the crashadk-rust sessions show ID; a call with no result after it was in flight, and its recovered answer appears once the session continues. adk-rust sessions list lists the ids
Which calls wait for a decisionadk-rust approvals list: the kernel's inbox and the calls sessions hold in harness.db

One backend per deployment

Sessions, approvals, the action ledger, modes, goals, read records, durable runs and plan checkpoints can share one SQLite file. plan_checkpoint_store(url) opens the plan checkpointer from a store URL, adk_harness::checkpointer_from_url, so it can name the same database (spec 3.1 §7.11, §13 Q5); without it or plan_checkpointer(..), plans live in memory and do not survive a restart:

use std::sync::Arc;

use adk_core::{ActionLedger, ApprovalStore, DurableRunStore, Llm};
use adk_harness::{Harness, HarnessAgent, SqliteGoalStore, SqliteModeStore, SqliteReadRecords};
use adk_runner::Runner;
use adk_session::{SessionService, SqliteActionLedger, SqliteApprovalStore, SqliteRunStore, SqliteSessionService};

async fn open(model: Arc<dyn Llm>, url: &str) -> Result<Harness, Box<dyn std::error::Error>> {
    let pool = sqlx::SqlitePool::connect(url).await?;
    let sessions = SqliteSessionService::from_pool(pool.clone());
    sessions.migrate().await?;
    let approvals = SqliteApprovalStore::from_pool(pool.clone());
    approvals.migrate().await?;
    let ledger = SqliteActionLedger::from_pool(pool.clone());
    ledger.migrate().await?;
    let modes = SqliteModeStore::new(pool.clone());
    modes.migrate().await?;
    let goals = SqliteGoalStore::new(pool.clone());
    goals.migrate().await?;
    let reads = SqliteReadRecords::new(pool.clone());
    reads.migrate().await?;
    let runs = SqliteRunStore::from_pool(pool.clone());
    runs.migrate().await?;
    let checkpointer = adk_graph::SqliteCheckpointer::from_pool(pool).await?;

    let agent = Arc::new(
        HarnessAgent::builder("harness")
            .model(model)
            .workspace(adk_devtools::Workspace::new(".").allow_bash(true))
            .mode_store(Arc::new(modes))
            .goal_store(Arc::new(goals))
            .read_records(Arc::new(reads))
            .approval_store(Arc::new(approvals) as Arc<dyn ApprovalStore>)
            .plan_checkpointer(Arc::new(checkpointer))
            .build()?,
    );
    let sessions: Arc<dyn SessionService> = Arc::new(sessions);
    let runner = agent
        .configure_runner(Runner::builder().app_name("my-app").agent(agent.clone()).session_service(sessions))
        .action_ledger(Arc::new(ledger) as Arc<dyn ActionLedger>)
        .build()?;
    Ok(Harness::with_runner(agent, runner)?.with_run_store(Arc::new(runs) as Arc<dyn DurableRunStore>))
}

Note: without read_records(..) the read records live in process memory, and an edit_file call approved after a restart fails with devtools.not_read until the model reads the file again. adk-rust keeps them in harness.db.

adk-rust — the REPL, code, goal, serve and adk-rust up — keeps the action ledger (SqliteActionLedger) and the spend ledger (SqliteSpendLedger) in harness.db too, so a call with side effects that began before a restart, kill -9 included, is answered from its record rather than run again. With a store key, a failed call's error text is not kept: the record says the tool returned an error.

Shared backends

Replicas of a served harness share PostgreSQL or Redis instead of a file (spec 3.1 §13 Q2):

StorePostgreSQL (feature postgres)Redis (feature redis)
ModesPostgresModeStoreRedisModeStore
Standing rulesPostgresStandingRuleStoreRedisStandingRuleStore
Read recordsPostgresReadRecordsRedisReadRecords
Plan and goal checkpointscheckpointer_from_url("postgres://…")checkpointer_from_url("redis://…")

Sessions, approvals and durable runs come from adk-session's stores on the same backend, which the features turn on. Both rule stores keep a version per app that every grant and revocation increments with the change, and answer rules_for from a cache only while the stored version matches, so a revocation through one replica is refused by every replica from its next call (spec 3.1 §9.2 I4). mongodb, neo4j and firestore add those checkpointers to checkpointer_from_url. See Running replicas.

use std::sync::Arc;

use adk_core::Llm;
use adk_harness::{HarnessAgent, PostgresModeStore, PostgresStandingRuleStore};

async fn replica(model: Arc<dyn Llm>, url: &str) -> adk_core::Result<HarnessAgent> {
    let pool = sqlx::PgPool::connect(url).await.map_err(|error| adk_core::AdkError::config(error.to_string()))?;
    let modes = PostgresModeStore::new(pool.clone());
    modes.migrate().await?;
    let rules = PostgresStandingRuleStore::new(pool);
    rules.migrate().await?;
    HarnessAgent::builder("harness")
        .model(model)
        .workspace(adk_devtools::Workspace::new(".").allow_bash(true))
        .mode_store(Arc::new(modes))
        .standing_rules(Arc::new(rules))
        .plan_checkpoint_store(url)
        .await?
        .build()
}

The encrypted store

Feature encrypted seals every payload of the harness's stores at rest (spec 3.1 §7.12, §9.2 I57). One StoreKeyring { current, previous } is resolved once at startup from a StoreKeySource: Secret { provider, name } (an adk-auth secret provider), Keychain { service, account } (the OS keychain) or Env(var). Sessions wrap in adk_session::EncryptedSession, held calls and decisions in adk_session::EncryptedApprovalStore, and the SQLite mode, rule, shell-ledger, goal and fact stores take the keyring through with_keyring; each payload column holds an adk-enc:v1: AES-256-GCM envelope bound to its row, and identifiers, timestamps and status columns stay plaintext for indexing.

InvariantMechanismTest
No payload reaches disk in plaintextEvery store seals before the write; the conformance suite scans the database file for planted sentinelsencrypted_store_no_sentinel_reaches_the_file
A wrong or missing key fails the open, never a plaintext fallbackSqliteStoreMarker records the key id; each store refuses an envelope it has no key for and a plaintext row while a key is configuredencrypted_store_a_database_written_under_a_key_refuses_to_open_without_it
Rotation retires the old keyrewrap on each store re-seals rows under the new key; compact vacuums the file so freed pages carry no plaintext; afterwards the old key opens nothingencrypted_store_rotation_reseals_every_row_and_the_old_key_opens_nothing
A store can be encrypted in placerewrap seals rows written before any key (sessions and approvals with legacy migration on)encrypted_store_rotation_seals_rows_written_before_the_key

Plan checkpoints seal the same way: SealedCheckpointer wraps any checkpointer and seals each checkpoint's state, metadata, child ledger and pending writes into one envelope bound to its thread and checkpoint ids, and rewrap_sqlite re-seals the graph_checkpoints table of a SQLite database under a new key.

encrypted_store_conformance_tests!(keyring = …) generates the four cases over a temporary harness.db. StoreRotation describes a rotation and produces the harness.store.key_rotated audit record (key ids, stores, rows, duration); the CLI's adk-rust store rotate-key is the operator's entry point (see The harness in your terminal).

use adk_harness::encrypted::{StoreKeySource, StoreKeyring};
use adk_harness::{SqliteFactStore, SqliteModeStore};
use adk_session::{EncryptedSession, SqliteSessionService};

async fn sealed(pool: sqlx::SqlitePool) -> adk_core::Result<()> {
    let keyring = StoreKeyring::resolve(&StoreKeySource::Env("ADK_STORE_KEY".into())).await?;
    let sessions = EncryptedSession::new(
        SqliteSessionService::from_pool(pool.clone()),
        keyring.current_key(),
        keyring.previous_keys(),
    );
    let modes = SqliteModeStore::new(pool.clone()).with_keyring(keyring.clone());
    let facts = SqliteFactStore::new(pool).with_keyring(keyring);
    let _ = (sessions, modes, facts);
    Ok(())
}