# multicast Code Mode
`multicast-codemode` is the provider-neutral durable execution layer for multicast
tools. It owns connector discovery, JavaScript harness generation, approval,
replay, cancellation, events, artifacts, rollback, snippets, and lifecycle
state, including callable durable child workflows through `codemode.workflows`.
Executors and stores are traits. Use `multicast-codemode-local` for an embedded
QuickJS runtime, `multicast-codemode-mcp` for the five-tool MCP lifecycle, or place
platform-specific adapters in a standalone extension workspace.
```rust
use std::sync::Arc;
use multicast::cli::Cli;
use multicast_codemode::MulticastConnector;
use multicast_codemode_local::open_codemode;
let codemode = open_codemode(
"codemode.sqlite",
Default::default(),
vec![Arc::new(MulticastConnector::new(cli.tool_catalog()))],
)?;
let execution = codemode.execute("tools.lookup({ id: 42 })").await?;
```
Model-generated programs are JavaScript. The public lifecycle, connectors,
storage, policy, and transport contracts are Rust.
Connector call arguments omit object properties whose JavaScript value is
`undefined`, including nested properties. Explicit `null`, empty objects, and
tag-shaped caller data remain unchanged for connector validation. Arrays retain
their positions and existing extended-value encoding. Results and durable step
values still preserve `undefined`, big integers, and binary values with the
Code Mode codec.
## Retry and recovery
Each connector call receives `ToolContext::call`: its sequence, an execution-scoped
idempotency key, and the attempt number committed before host invocation. Hosts
must namespace keys when sharing an external idempotency store across execution
stores. The default budget is one; `Connector::retry_policy` can opt into up to
eight total attempts. The first durable budget cannot be increased by reopening
or changing configuration.
An automatic retry requires a JSON error with `retryable: true` and host
reconciliation through `Connector::recover`. Interrupted calls also reconcile
before another invocation. `Applied(result)` records an authoritative receipt;
`Retry` asserts that repeating the key is safe or that no effect occurred;
`Uncertain` pauses with `CALL_OUTCOME_UNCERTAIN`. Remote tool annotations grant no
retry authority. Reconciliation must not perform the write itself.
`MulticastConnector::with_retry_policy` supports host-declared read-only or idempotent
local commands. Custom connectors can forward the stable key to a remote service
and inspect that service's receipt store. Cancellation is checked again after
reconciliation, before reserving another attempt. Exhaustion returns
`CALL_ATTEMPTS_EXHAUSTED`; restarting never replenishes the budget.
A recovery pause has an executing call and no pending approval. After the host can
reconcile it, resume checks the outcome again. MCP tasks expose a separate
reconciliation form in both task dialects; accepting it does not authorize a blind
repeat. Ordinary approval pauses still require an approve or reject decision.
See the [workflow composition guide](../../docs/workflow-fluency.md) for definitions,
explicit bindings, recursion, scopes, host limits, and checkpoint upgrade rules.
## Execution history
Starting an execution automatically prunes older terminal history to 50 records.
Results completed, failed, or cancelled in the last 60 seconds are also retained,
so a burst can exceed that count while callers fetch results. The grace starts
at the terminal state update, including for long-running programs.
Hosts can change the grace with
`CodeModeRuntime::with_auto_prune_grace_ms`; zero restores immediate count-based
pruning. Explicit `prune` and `prune_at` bypass the grace, while still honoring
persisted retention deadlines. Live executions remain protected. Retention does
not authorize retries or remove the store's single-owner requirement.