Spatiotemporal Composability for Agent Hosts: Hot Reload and Rollback in Practice
Long-running agents call tools, persist sessions, and accumulate state over hours or days. Restarting a host process to ship code loses sessions and increases latency. This article describes spatiotemporal composability as an engineering approach: treat change in time and structure in space together so plugins can be replaced, composed, and rolled back while the host keeps running. It is a design discussion without formal proofs or experiment data; treat numbers and methods as starting points to validate against your own load.
Long-running agents call tools, persist sessions, and accumulate state over hours or days. If a host can upgrade code only by restarting the process, sessions are lost and latency rises. Spatiotemporal composability is an engineering design: handle change along time and space together so plugins can be swapped, composed, and rolled back at runtime. This is a design discussion, not a formal proof or experimental report. Treat the numbers and methods as a starting point and validate them against your own workload.
What spatiotemporal composability means
The time dimension is about change: how to update while running, how versions evolve, and how to return to a previous consistent state after failure. The space dimension is about structure: how plugins depend on each other, which plugins share an address space, and which need isolation.
The two dimensions must be designed together. Hot reload without a dependency graph can load a new plugin that still needs an old interface that has already been unloaded. Isolation without transactions can leave half-written state after a failed plugin.
A minimal viable host: the plugin manifest
Each plugin should declare at least:
- name: globally unique plugin name.
- version: semantic version, for example 1.2.0.
- interface: exported interface version and a digest of function signatures, used at load time to check the contract.
- depends: dependency list as name plus version range, for example
memory >=2.0 <3.0. - isolation: isolation level (see the table below).
- hooks: lifecycle hooks
on_load,on_activate,on_deactivate,on_unload, each with a timeout. - state_schema: version of the state structure, used to decide whether state can migrate directly on upgrade.
Hot-reload state machine
A hot reload advances through these states:
- Validate: check manifest format, interface contract, and dependency version ranges. On failure, reject immediately and skip later steps.
- Preload: load the new version in an isolated memory region and run
on_load. The old version keeps serving requests. - Double-buffer switch: at a safe point (no in-flight calls), atomically replace the plugin pointer. New requests go to the new version.
- Refcount reclaim: when in-flight calls on the old version finish and the refcount hits zero, the framework runs
on_unloadand frees resources. - Commit or rollback: after the switch, if health checks fail or a runtime exception appears within the timeout, restore the snapshot taken before the switch.
Concurrency: only one update transaction per plugin at a time. Changing the dependency graph requires a global topology lock. Default lock timeout is 30 seconds; on timeout, abort the update and log it. Waiting for old-version reclaim also needs an upper bound; after that, mark the version pending reclaim so one long call cannot stall the whole upgrade.
Scope of rollback
Rollback restores three things: code version, dependency graph, and runtime bindings such as event subscriptions and timers. The snapshot is taken before the switch and includes plugin version pointers, a copy of the dependency graph, and the binding table.
Rollback cannot undo external side effects. Email already sent, payments already committed, and data already written to remote systems cannot be pulled back automatically. Two mitigations: carry idempotency keys on external calls so retries do not double-execute; design compensating actions for side-effecting operations (refund, discard a draft).
State needs its own treatment. If the new version changes the state structure, the old version may not understand it, and rollback can lose or corrupt data. When state_schema changes, require forward and reverse migration functions, or snapshot state before the switch and retain it for a period.
Connection caches must be handled too. If the new version changes connection parameters, invalidate old connections on switch and let the new version rebuild them so old sockets are not reused under new logic.
Isolation levels
| Level | Implementation | What is isolated | When to use |
|---|---|---|---|
| Namespace | Logical partition in the same process | Names, config, event channels | Trusted plugins only. Does not stop memory errors or global state corruption |
| Thread | Dedicated thread, shared address space | Execution context | Avoids blocking; crash or out-of-bounds still affects the host |
| Process | Separate OS process | Memory and faults | Strong fault isolation; IPC adds latency; good for untrusted or high-risk code |
| WASM | In-process sandbox runtime | Memory, syscalls, and resources | Good for model-generated code. Set memory and compute quotas; host APIs need explicit grants |
Audited internal tools can use namespaces. Third-party and model-generated code should prefer WASM or processes. Higher isolation costs more on hot reload, so do not put every plugin at the highest level.
Exception classes and handling
- Recoverable errors: syntax errors, contract mismatch, missing dependencies. Reject the update and roll back as a whole; the host stays as it was.
- Recoverable but need throttling: memory near the limit for a long time, or CPU saturated. Pause loading new plugins, limit concurrent updates, drop disposable caches, scale out or migrate some plugins if needed.
- Unrecoverable errors: resources exhausted, host cannot allocate more memory, or state is corrupted. Circuit-break: stop accepting updates, isolate the bad plugin, let an external supervisor (process manager or orchestrator) restart the host and restore from the latest consistent snapshot.
Read-only mode should not be the default degradation. It only helps when the read path needs no new allocations and query results can be buffered in advance. When resources are fully exhausted, read-only can still fail, so treat it as optional and validate it before production.
Cycle detection
On load, topologically sort the dependency graph:
- Compute in-degree for each plugin (how many plugins depend on it).
- Repeatedly take plugins with in-degree 0 into the load queue and decrease in-degree of their dependents.
- If plugins remain after the queue is empty, there is a cycle.
- Report the plugins on the cycle with the full path, for example
A → B → C → A, and reject the update.
Failure example: plugin billing depends on memory, and a new memory version declares a dependency on billing. Updating memory detects the cycle, the transaction is rejected, the error includes the full cycle path, and the host keeps running the old versions.
Self-evolution loop and metrics
When an agent sees task failure or a capability gap, it can generate a patch or a new tool and submit it to the host as a transactional hot update. On success, persist it in the version store. On failure, roll back and record the reason for the next generation attempt.
Unify metrics for this loop (the original draft ends here; define the exact set against your own operations).
