This is an edited Chinese-language deep-dive of the paper *A Programming Paradigm for Spatiotemporal Composability* (Yifan Shi, Wei Zhang — Peking University; Tianyi Cui — Peking University / DeepSeek-AI). The original article is long (88 pages, 8 sections, 124 references); below is a structured English summary.
Key points
- Thesis: Classical *effects* and *coeffects* — normally static annotations in type systems — should be reified as first-class runtime mechanisms, unified into a single "context type." The result is a programming paradigm in which components can be freely plugged and unplugged at runtime: unloading fully rolls back side effects, and dependency lifecycles trigger automatic reconnection.
- Motivation — why unloading is hard:
- VS Code's extension host must restart after an extension is deactivated/uninstalled, because
deactivateis only an optional cleanup callback, splitting creation from destruction (failure of *locality of concern*). Cross-extension dependencies are rare (only 7 of the top-100 extensions declare dependencies on non-builtin extensions) and untyped (any). - Self-evolving AI agent harnesses need even more: without temporal composability, every self-modification requires a full restart, losing in-process state; a bad self-modification can destroy the very process needed for recovery. Without spatial composability, modules must handle dependency churn with ad hoc code.
- Coarse-grained alternatives (OS processes, containers) discard in-process state, need redundant replicas, and cannot express dependencies between components within the same address space.
- Two orthogonal dimensions, mapped to classical theory:
- *Temporal composability* — can an uninstalled component's environmental changes be fully and safely rolled back? (Corresponds to effects: how a computation modifies its environment.)
- *Spatial composability* — can dependencies between components be declared, resolved, and adaptively maintained? (Corresponds to coeffects: how a computation depends on its environment.)
- Revertible effects (temporal): An effect is modeled as
Γ → Γ × (Γ → Γ)— applying a transformation yields the new context *plus its own inverse*. The effect context∂Γ ≔ Γ × (Γ → Γ)pairs current stateγwith an accumulatorφ, the composition of all applied inverses (a recovery function). Theorem 5 showstrackΓis a monoid homomorphism; Theorem 7 establishes the soundness invariantφ(γ) = γ₀, sorecoverΓ(γ, φ) ≔ (φ(γ), idΓ)always restores the initial state. Corollary 21 shows that when effect transformation monoids commute (independence), inverses can be applied in any order — enabling concurrent plug/unplug of interleaved components. - Reactive coeffects (spatial): Dependency declarations become contracts (specifications); coeffects are treated as effects and hence also revertible, with isolation and interception semantics. When dependencies appear, disappear, or change owners, the runtime responsively re-wires the topology instead of leaving each module to poll and adapt on its own.
- Unified context Γ∞: The two mechanisms merge into a layered context supporting hierarchical composition — the literal metaphor of plugging and unplugging — with observational equivalence (≃) characterizing when two configurations behave identically.
- Metatheory: A dynamic combinable calculus is developed with formal theorems covering tracking, recovery, ordering, and dependency management.
- Implementation — Cordis meta-framework: Three layers: a core library providing context/effect primitives, and a loader handling reconciliation and HMR (hot module replacement), so plugin code can be swapped in place.
- Empirical validation — Koishi: An ecosystem of 4,000+ community plugins built on Cordis, demonstrating the paradigm at production scale.
- Positioning: Classic static composition (function calls, imports, inheritance) is fixed at compile time; container orchestration buys rollback only at the cost of restarts and coarse granularity; OSGi-style systems can declare dependencies but cannot cleanly clean up in place. Only the combination of revertible effects and reactive coeffects achieves both dimensions at component granularity — turning correctness from an author-discipline problem into a structural property.
Conclusion
The paper's design goal is explicitly forward-looking: preparing for self-evolving systems. If an agent harness must modify its own tools, sandboxes, memory, and sub-agent orchestration while serving requests, it needs exactly these guarantees — safe in-place rollback of any self-modification, and automatic re-wiring of dependencies as components come and go.