Software you can plug in and unplug while it runs
A plain-English guide to "A Programming Paradigm for Spatiotemporal Composability" by Yifan Shi, Wei Zhang and Tianyi Cui, the paper behind the Cordis framework.
Adding is easy. Removing means restarting.
Lots of software is assembled from parts at runtime: editor extensions, browser add-ons, chatbot plugins, and, increasingly, AI agent harnesses that add and swap their own tools while serving requests.
Take VS Code. All extensions share one process. The paper counted the top 100 extensions: 87 contain code, and none of those can be unloaded on its own. Disabling one means restarting the extension host, which restarts all of them. VS Code does offer a deactivate hook, but it only runs at shutdown, and it's written separately from the code that set things up, so nobody can check that it cleans up everything.
Dependencies are the other half. Only 7 of the top 100 declare a dependency on another extension, and when one extension does reach another, what it gets back is an untyped any.
The usual workaround is to go coarser: put things in separate processes or containers and let the operating system or Kubernetes restart them. That works, but you pay for spare replicas, and calls that could have been local function calls go over the network.
Temporal composability
The time question. When a component is removed, can everything it changed be fully undone?
Spatial composability
The space question. Can components declare what they need from each other, and can the system react when those things appear, disappear or change?
"Spatiotemporal" in the title just means both at once. The paper treats them as independent problems with one shared solution.
Every change hands back its own undo
Programming-language theory has a name for "something a function does to the world besides returning a value": an effect. Registering a route, adding a listener, starting a timer and opening a socket are all effects.
Cordis's rule is simple. An effect is only allowed if it returns its inverse at the moment it runs. The runtime keeps those inverses on a stack. Unplugging the component runs the stack top-down, newest first.
// a Cordis-style effect: do the thing, hand back how to undo it
ctx.effect(() => {
const timer = setInterval(refresh, 60_000)
return () => clearInterval(timer)
})
deactivate(); anything they forgot leaks.Two details make this work in real code:
- Composites come free. You write an inverse only for the smallest effects. A component built from many effects, or from other components, gets its combined undo automatically. The paper proves this composition is well-behaved (formally, a monoid homomorphism).
- Loading can be interrupted. A component's startup is modelled as a generator that yields one effect at a time. If the system decides mid-startup that the component should stop, it halts at the next step and undoes only what has been done so far.
The undo only has to restore the state it was given, not every possible state. "Delete the route I just added" counts, even though it wouldn't undo someone else's route.
Declare what you need; start only when it's there
The flip side of an effect is a coeffect: something a computation needs from its environment. In Cordis, components share things through a context keyed by name, such as database, server or auth. A component declares the keys it needs up front (inject) and the keys it provides.
Every time a key is provided or withdrawn, the system checks each component's declaration and sorts the change into one of three kinds:
- Activating: the last missing key just arrived, so start the component.
- Deactivating: a key it relies on just left, so stop the component and run its undo stack.
- Neutral: nothing changes for this component.
database and server. Click a provider block to switch it and read how each change is classified. Login lifts up when it becomes Active. The logger is not declared, so changes to it are always neutral.A component therefore never runs with a missing dependency, and a component whose dependency is unavailable simply waits instead of crashing. Classic dependency injection (Spring, Angular, Guice) wires dependencies once at start-up and doesn't react when a provider is later swapped or removed.
Two refinements: isolation lets the same key mean different things in different parts of the tree (handy for multi-tenant setups and tests), and interception attaches metadata to how a key is used, for example "this plugin gets read-only database access", without changing the plugin or the provider.
One context, and why undo order can stop mattering
Undoing one component in strict newest-first order is easy. A real system is harder: many components run interleaved, and you want to remove any one of them while the others stay. Its undo then runs after other components have changed things.
The paper's answer is the context paradigm: every shared thing a component touches must go through the one context, under a key, using only the operations that key offers. With that discipline in place, two components' effects are independent (safe to undo in any order) whenever:
- they touch different keys, which is automatically safe; or
- they touch the same key, and that key's operations commute. The component providing the key is responsible for designing it that way.
This is also where the paper is careful about what "back to how it was" means. free() doesn't restore the exact heap layout from before malloc(). So the guarantee is observational: after undo, no sequence of the key's own operations can tell the difference. Hiding details from an interface (say, not exposing raw addresses) can turn a key that doesn't commute into one that does.
Four states, nine rules
To prove anything about whole systems, the paper defines a small formal model. Each running instance of a component (a fiber) is always in one of four states, and nine rules move it between them. Three rules belong to the orchestrator (insert, retire, remove). Six fire on their own whenever their conditions hold:
- L-Begin: everything declared is available, so start loading.
- L-Iter / L-Finish: perform the next effect; after the last one, become Active.
- L-Leave: something needed went away, so stop providing and start unloading.
- L-Divert: same, but caught mid-load, so back out with only the inverses gathered so far.
- L-Unload: run the undo stack, but only once no other component is still using this one.
That last rule, the guard, matters in practice. When a database goes away, a component that depends on it may still need it to shut down cleanly, for example to hand connections back. So the provider stops advertising itself first, its users tear down while it's still there, and only then does it disappear.
The rules don't specify a scheduler. Any order of rule applications is allowed, so every theorem holds for whatever scheduling a real runtime picks, including asynchronous ones where an in-flight step can't be cancelled.
Five guarantees for the whole system
Section 3 gives guarantees for one component in isolation. Section 4 lifts them to any interleaving of any number of components:
- Preservation: every rule keeps the registry well-formed (valid parent tree, at most one provider per key).
- Recovery exactness (temporal): undoing a component leaves the system as if that component's steps had never happened, while other components' steps stay in place.
- Ordering (spatial): a component starts only when what it declared is present, and a provider leaves only after everyone using it has finished tearing down. A single load never sees half of one provider and half of another.
- Progress: if dependencies have no cycles, the system always settles; the guard can't deadlock.
- Confluence: wherever the system settles, it's the same state you'd get by loading the final configuration from scratch. The history of plugging and unplugging leaves no trace.
Confluence is what makes the configuration file trustworthy. The loader can apply edits incrementally, in any order, and concurrently, and still end up where a clean start would.
Cordis, and 4,000 Koishi plugins
Cordis is the TypeScript implementation. It calls itself a meta-framework: it doesn't do web routing or databases, only composition. It has three layers:
- Core library.
ctx.effectis the single primitive for changing anything;ctx.set/ctx.getprovide and read keys;ctx.useloads a component as a child. Readingctx.databasegoes through a JavaScript Proxy that rejects keys the component didn't declare. - Declarative loader. A YAML/JSON config tree describes which components run with which settings. Edit an entry and the loader does the least disruptive thing: change a setting and only that component reloads; toggle
disabledand it unplugs. - Hot module replacement. When source files change, the affected components are swapped in place without restarting the process. Because each component already owns its effects, there's no need for the hand-placed "accept" boundaries Webpack and Vite ask for. If the new code fails to import, the whole reload rolls back.
Koishi, an open-source chatbot framework, has run on Cordis (v3) for four years. Messaging adapters and database drivers provide keys; feature plugins declare them. Admins disable plugins from a web console and their effects are undone in place. Plugins whose dependency is missing wait instead of erroring, and switching the storage backend reloads only the plugins that use it.
The paper also sketches what the model enables beyond plugins: rolling updates inside one process (load the new version beside the old, shift traffic through a broker, unplug the old one), capability-style access control (a component can only reach what it declared, and the list is known before it runs), and self-modifying AI agent harnesses that can replace their own parts without a restart that would drop in-flight work.
Where the guarantees stop
- Inverses are trusted, not checked. The runtime doesn't verify that an undo really undoes; that's on the author of each smallest effect. The same goes for a key's operations commuting.
- Only what goes through the context counts. A write to a file other programs read, a network message, or a payment can't be un-sent. The paper calls this the system boundary; past it you need to delay the action until it's certain, or compensate (refund, delete).
- Circular dependencies never start. If A needs B and B needs A, both wait forever. This is detectable from the declarations, and the paper shows how to split such pairs into smaller components, at the cost of more of them.
- Keys are matched by name only. Two unrelated packages using the same key name, or a provider changing its interface between versions, isn't caught. Cordis currently leans on npm peer-dependency ranges.
- In-memory state doesn't survive a reload unless it lives in a longer-lived dependency. Classic dynamic-update systems migrate state forward; Cordis starts the new version clean.
- The evidence is one ecosystem in one language. The authors call the Koishi case study an existence-and-adoption result. Overhead and developer-productivity measurements are future work.
Paper: arxiv.org/abs/2608.25512 · PDF · Implementation: Cordis · Case study: Koishi