# reactive dom signals for prompts

- Status: `experiment`
- Track: [reactive prompt architectures](https://aifoc.us/labs/reactive-prompts/)
- Layer: 5. Local Compute, Wasm & Zero-Framework UI
- Updated: 1 December 2026
- Live demo: https://reactive-dom-signals-for-prompts.kinlan-test.workers.dev
- Source: https://github.com/PaulKinlan/reactive-dom-signals-for-prompts

## Inspired by

- [the projects behind my ai focus posts](https://aifoc.us/projects/)
- [what falling ai model latency means for the web](https://aifoc.us/latency/)

## Hypothesis

- **Claim:** Modeling multi-step prompt workflows as a dependency DAG triggered by DOM mutations prevents wasted sibling reruns via structured-clone caching and avoids stale race overwrites via `AbortController`.
- **Confirms it:** Rapid edits to one leaf input abort superseded in-flight `ReadableStream` requests while unaffected upstream sibling nodes report cache hits.
- **Falsifies or bounds it:** Chained downstream prompts re-execute redundantly when upstream edits produce semantically identical JSON values or abort storms throttle edge limits.

> **Why this exists:** In multi-step generation workflows, editing a single word in one input field often re-runs the entire pipeline from scratch and wastes money, or produces stale out-of-order streams when two edits overlap. Modeling prompt pipelines as a reactive DOM signal graph automatically aborts obsolete in-flight `fetch()` streams via `AbortController` while reusing cached outputs from unaffected steps.


## What this lab tests

[Reactive DOM Signals](https://reactive-dom-signals-for-prompts.kinlan-test.workers.dev) ([GitHub](https://github.com/PaulKinlan/reactive-dom-signals-for-prompts)) links `MutationObserver` text edits to a 5-node dependency DAG that caches unchanged sibling branches via `structuredClone` and aborts superseded `ReadableStream` responses through [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).


## Open questions to iterate on

- How far can structural early-cutoff diffing push cache hit rates across multi-turn document workflows?
- Which parts of DOM observation belong in `MutationObserver` versus explicit custom elements like `<ai-prompt>`?

## Iteration log

- **2026-12-01:** Built `MutationObserver` 5-node DAG scheduler with `structuredClone` memoization and NDJSON `AbortController` teardown.
- **2026-12-01:** Reordered the page around the hypothesis and live DAG demo, added CSP-safe DOM syntax highlighting for setup code and JSON inspectors, tightened 700px embed responsiveness, and enforced no-cache headers across HTML, CSS, and JS assets.

## Primitives tested

- `AbortController`
- `MutationObserver`
- `Structured Clone Cache`
- `ReadableStream`

## Connected labs in other tracks

- [reactive prompt models rosetta stone](https://aifoc.us/labs/reactive-prompts/reactive-prompt-rosetta/) — Expands this initial prototype to benchmark six competing reactive abstractions side by side.
- [declarative <ai-prompt> cells & pinning studio](https://aifoc.us/labs/reactive-prompts/reactive-prompt-cells/) — Moves DAG wiring from JS glue directly into HTML custom-element attributes.

---
Canonical: https://aifoc.us/labs/reactive-prompts/reactive-dom-signals-for-prompts/
