Cordis explained
arXiv 2608.25512 · 92 pages · Peking University & DeepSeek-AI

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.

In short: most plugin systems can add code while running but can't cleanly remove it, so they restart. Cordis makes every change a component makes to the shared program carry its own undo, and makes every component declare what it needs so it starts and stops automatically as those things come and go. The paper proves that, under stated conditions, removing any component puts the system back exactly as if it had never been loaded. It runs today under Koishi, a chatbot framework with over 4,000 community plugins.
Four components in one program. The Login component needs a database and a web server; the Chat bot needs Login. Green arrows are live dependencies. Switch a component off and watch the ones that depend on it shut down first, then everything they added to the environment disappear. Switch it back on and they return by themselves.
1 · The problem

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.

Analogy: a power strip where unplugging one lamp cuts power to the whole house. You'd stop unplugging things, and that's roughly what plugin ecosystems do.
Restart vs unplug. Each plugin has been running for a while and has built up a cache and an open connection. Uninstall one in each mode. A restart throws away every other plugin's state too; the paper cites seconds to minutes to rebuild it.

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.

2 · Time: revertible effects

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)
})
Analogy: a hotel that lets you move the furniture, as long as you leave a note on the door for each change saying how to put it back. At checkout, housekeeping reads the notes from the top of the pile down.
The undo stack vs a hand-written cleanup. Add effects in any order, then unplug. In Cordis mode each effect pushed its own inverse, so nothing is missed. In hand-written mode, cleanup is whatever someone remembered to put in deactivate(); anything they forgot leaks.

Two details make this work in real code:

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.

3 · Space: reactive coeffects

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:

One component, two declared keys. Login declares database and server. Toggle the providers and read how each change is classified. 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.

4 · Putting them together

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:

Undoing out of order. Components A and B each add an entry, then A is removed while B stays. In a keyed table (routes, event listeners) each entry has its own id, so A's undo deletes exactly its own entry. In an ordered chain (middleware), A's undo can only say "remove the last one", which removes B's instead.

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.

Analogy: two people hanging coats on a numbered rack can collect them in any order. Two people stacking plates can't: whoever's plate is on top has to go first.
5 · The calculus

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:

Step through the rules. The four-state diagram is Figure 1 of the paper; the rule just applied lights up. Load all three components, then switch the database off and step again. The database announces it's leaving, Login and Chat start unloading, Chat finishes first, then Login, and the database undoes its own effects last.

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.

6 · What's proved

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:

Many schedules, one result. Each run starts six components in a random order, switches one provider off part-way, then back on. Run a hundred and count how many different final states come out. This is a small simulation of the paper's rules, not the proof itself.

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.

7 · In practice

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:

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.

4,000+community plugins on Koishi
4 yearsin production
87 / 100top VS Code extensions that need a restart to remove
7 / 100that declare a dependency on another extension

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.

8 · Not perfect yet

Where the guarantees stop

One sentence: make every change a component makes return its own undo, make every component declare what it needs, route everything shared through one context, and you can prove that plugging and unplugging parts of a running program, in any order, leaves it exactly where a clean start would.

Paper: PDF (arXiv 2608.25512v1) · Implementation: Cordis · Case study: Koishi