node-outline
Depends on: topic, audience
Waiting for initial wave...
Web Platform + Edge Systems Prototype
Signal-driven DAG dependency scheduling binds DOM MutationObserver events to a
structuredClone memoization cache, edge ReadableStream execution,
and immediate AbortController cancellation for superseded streams.
Re-running a full multi-step prompt pipeline on every keystroke wastes compute and lets slow
out-of-order responses overwrite newer edits. Modeling the pipeline as a MutationObserver-driven
dependency DAG preserves unaffected sibling outputs via structuredClone caching and cancels
superseded fetch() streams via AbortController.
Confirm: Rapid leaf edits abort in-flight NDJSON streams (abortedCount >= 2)
while node-compliance resolves from cache. Falsify: Downstream nodes re-run
redundantly on unchanged inputs or abort storms cause stale writes.
Click 1. Simulate Rapid Multi-Edit Burst below and watch
In-Flight Streams Aborted and Cached Sibling Hits update in the telemetry strip
and execution timeline.
Trigger deterministic signal schedules to observe mid-stream aborts, sibling cache hits, and DOM mutation capture.
Dispatches 3 topic updates 180ms apart via #topic-surface. Triggers automatic
AbortController cancellation (abortedCount >= 2) while keeping
node-compliance cached.
Cycles the audience signal. Recomputes node-outline and
node-final-draft while serving node-compliance from cache
(cacheHits++).
Mutates the contenteditable DOM node and places the caret inside so
MutationObserver drives incremental streaming without resetting untouched branches.
Edit any signal below to trigger topological DAG invalidation.
node-outline
node-outline
node-compliance only
node-compliance remains isolated from topic and audience edits.
Incremental NDJSON chunks rendered via textContent (zero innerHTML).
node-outlineDepends on: topic, audience
Waiting for initial wave...
node-complianceDepends on: constraints only
Waiting for initial wave...
node-final-draftDepends on: node-outline, node-compliance
Waiting for initial wave...
Exclusive <details name="wire"> disclosures tracing abort signals, memoized entries, and compute plans.
structuredClone){}
planRecompute() Output{}
Ad-hoc input listeners chained to sequential fetch() calls re-execute unchanged upstream steps
on every keystroke and allow slow responses to overwrite newer edits. Binding MutationObserver
to a topological DAG scheduler with structuredClone sibling caches and
AbortController cancellation isolates dirty subgraphs and terminates stale edge streams.
// Imperative listeners re-run full chains and race on out-of-order responses
topicInput.addEventListener("input", async () => {
const outline = await (await fetch("/api/outline", { method: "POST", body: topicInput.value })).text();
const compliance = await (await fetch("/api/compliance", { method: "POST", body: constraints.value })).text();
const draft = await (await fetch("/api/draft", { method: "POST", body: outline + compliance })).text();
// An earlier slow fetch can resolve last and overwrite newer DOM output
outputPre.textContent = draft;
});
// public/app.js — MutationObserver drives SignalDagScheduler with abort & cache reuse
const scheduler = new SignalDagScheduler({
initialSignals: { topic: readTopicText(), audience: audienceSelect.value, constraints: constraintsSelect.value },
executor: edgeStreamExecutor // Streams NDJSON from POST /api/stream-step with AbortSignal
});
const topicObserver = new MutationObserver(() => {
void scheduler.updateSignal("topic", readTopicText());
});
topicObserver.observe(topicSurface, { characterData: true, childList: true, subtree: true });
// Only dirty nodes (node-outline -> node-final-draft) re-run; node-compliance stays cached
Live DOM signal elements in public/index.html, the DAG_SPEC dependency graph and
planRecompute() planner in public/lib/signal-dag.js, MutationObserver
+ AbortController NDJSON reader in public/app.js, and
createStepStreamResponse() in src/worker.ts.
<!-- 1. Page HTML Setup (public/index.html) -->
<div id="topic-surface" class="topic-surface" contenteditable="true" role="textbox">Incremental DOM invalidation for streaming prompt pipelines</div>
<select id="audience-select"><option value="browser-engineers">browser-engineers</option></select>
<select id="constraints-select"><option value="strict-csp-zero-innerhtml">strict-csp-zero-innerhtml</option></select>
<pre tabindex="0" class="node-output"><code id="out-node-outline"></code></pre>
<pre tabindex="0" class="node-output"><code id="out-node-compliance"></code></pre>
<pre tabindex="0" class="node-output"><code id="out-node-final-draft"></code></pre>
<script type="module" src="/app.js"></script>
// 2. Concrete DAG_SPEC & planRecompute() Contract (public/lib/signal-dag.js)
export const COMPUTE_ORDER = Object.freeze(["node-outline", "node-compliance", "node-final-draft"]);
export const DAG_SPEC = Object.freeze({
topic: Object.freeze({ id: "topic", kind: "signal", deps: Object.freeze([]), label: "Source: topic" }),
audience: Object.freeze({ id: "audience", kind: "signal", deps: Object.freeze([]), label: "Source: audience" }),
constraints: Object.freeze({ id: "constraints", kind: "signal", deps: Object.freeze([]), label: "Source: constraints" }),
"node-outline": Object.freeze({ id: "node-outline", kind: "compute", deps: Object.freeze(["topic", "audience"]), label: "node-outline" }),
"node-compliance": Object.freeze({ id: "node-compliance", kind: "compute", deps: Object.freeze(["constraints"]), label: "node-compliance" }),
"node-final-draft": Object.freeze({ id: "node-final-draft", kind: "compute", deps: Object.freeze(["node-outline", "node-compliance"]), label: "node-final-draft" })
});
const plan = planRecompute({ generation, signals, cache, nodeStates, activeNodeIds }, changedKey, newValues);
// Returns { generation, dirtyNodes, preservedNodes, abortTargets, steps }
// Step actions: "reuse-sibling" | "cache-hit" | "await-inflight" | "recompute"
// 3. MutationObserver, AbortController NDJSON Consumer & Worker Stream (public/app.js + src/worker.ts)
const topicObserver = new MutationObserver(() => { void scheduler.updateSignal("topic", readTopicText()); });
topicObserver.observe(topicSurface, { characterData: true, childList: true, subtree: true });
const response = await fetch("/api/stream-step", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ nodeId, inputs: context.inputs, depHash: context.depHash, generation: context.generation, chunkDelayMs }),
signal
});
const reader = response.body.getReader(); // Decodes NDJSON frames into context.onChunk() -> outEl.textContent
// src/worker.ts createStepStreamResponse(payload, request.signal):
// Streams 8 NDJSON chunks via ReadableStream and attaches signal?.addEventListener("abort", onSignalAbort, { once: true })
// plus ReadableStream.cancel(reason) so superseded HTTP connections clear timers immediately on the edge.
// public/lib/signal-dag.js & public/app.js — topological planRecompute + AbortController NDJSON
const plan = planRecompute({ generation, signals, cache, nodeStates, activeNodeIds }, changedKey, newValues);
// plan.abortTargets lists in-flight dirty nodes; scheduler aborts each via AbortController("superseded")
// Preserved sibling inputs use structuredClone + computeDependencyHash(nodeId, inputs) for cache hits
const response = await fetch("/api/stream-step", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ nodeId, inputs: context.inputs, depHash: context.depHash, generation }),
signal // Aborts client reader and fires Worker request.signal teardown immediately
});
const reader = response.body.getReader(); // Incrementally decodes NDJSON deltas into .textContent
Manual debounce timers, redundant re-fetches of unchanged sibling prompt branches, and race conditions where late responses overwrite newer DOM edits.
Topologically ordered dependencies (DAG_SPEC), deterministic FNV-1a depHash keys, structuredClone cache snapshots, and explicit AbortController lifecycles.
The web platform lacks native reactive DOM signal primitives and dependency-aware fetch schedulers, requiring userland MutationObserver + AbortController + ReadableStream plumbing.