DecidrHolon Design Kit

Patterns

Streaming replies after review

Stream replies over POST only after code guards and the reply battery pass, keeping live streaming strictly opt-in behind a stream guard.

Visitors expect a conversational reply that flows smoothly word by word, yet displaying unreviewed model output creates compliance risk, particularly for licensed advisory organisations such as EFS. House note: three-service holon Reference: flow.mjs

The reference holon resolves that tension by holding the reply until both code checks and the reply battery pass (reviewed mode), then pacing the approved words onto the page over a POST event stream. Reference: flow.mjs Reference: server.mjs

Best practices

Reviewed mode versus live mode

The console supports two streaming modes selected by environment configuration (HOLON_CONSOLE_STREAM), with reviewed as the safe default. Reference: server.mjs Reference: flow.mjs

PropertyReviewed mode (default)Live mode (opt-in)
When text appearsOnly after finish() and the reply battery pass. Reference: flow.mjsWord by word as the reply model generates, filtered by StreamGuard. Reference: guards.mjs
Strict-rule turnsHeld until review passes. Reference: flow.mjsForced back to reviewed mode (!fired.some(r => r.strict)). Reference: flow.mjs
Measured first words3.2 to 5.3 seconds. House note: three-service holon1.8 to 2.4 seconds. House note: three-service holon
Review failure UXOnly the fixed replacement streams; bad text is never seen. Reference: flow.mjsAlready-seen text fades across to the fixed replacement. Reference: console.js House note: three-service holon
Variant pricePrepare a reply · Reviewed · $0.05 / reply Reference: task-types.jsonPrepare a reply · Live · $0.06 / reply Reference: task-types.json
JavaScript
const streams = streamMode === 'live' && !fired.some(r => r.strict);
const replyVariant = streams === true ? 'live' : 'reviewed';
step(run, 'reply', { status: 'running', held: !streams }, 'message', replyVariant);

Once review completes in reviewed mode, the flow paces the approved text word by word (28 ms between words) and stops cleanly if the visitor has gone: Reference: flow.mjs

JavaScript
if (!streams && !gone()) {
  const pieces = out.match(/\S+\s*/g) ?? [out];
  for (const w of pieces) {
    firstMs ??= Math.round(now() - t0);
    emit({ type: 'reply.delta', runId: run.id, text: w });
    if (paceMs) await pace(paceMs);
    if (gone()) break;
  }
}

Streaming over POST and the stream guard

Live probes proved that reverse proxies and quick tunnels buffer GET text/event-stream responses until the connection ends, delivering every event at once, while passing POST responses through chunk by chunk. Holon rules §4 Reference: server.mjs House note: three-service holon

To stream reliably over POST /api/say and POST /api/profile-checks:

  1. Parse Accept properly: wantsEventStream() checks media types case-insensitively and honours q=0, returning plain JSON otherwise. Reference: server.mjs
  2. Disable proxy buffering: Send content-type: text/event-stream, cache-control: no-cache, no-store, no-transform, and x-accel-buffering: no, followed by 2 KB of SSE comment padding (: open ...) to flush edge buffers immediately. Reference: server.mjs House note: three-service holon
  3. Isolate sessions: Each session's events go only to its own open POST stream sink, and res.on('close') aborts the flow and removes the sink immediately. Reference: server.mjs

When opt-in live mode is enabled, ReplyExtractor parses text incrementally out of the structured JSON response and passes each chunk through StreamGuard. StreamGuard releases whole words only, holds back trailing digit runs so phone or ID numbers cannot slip through piece by piece, runs leaks() and strayContact(), and caps output at 2 sentences and 60 words. Reference: flow.mjs Reference: guards.mjs

What the person sees while review runs

While checks, rules, reply generation, and review run in reviewed mode, the chat thread displays a quiet waiting bubble (…) and disables the send button so one message runs at a time. Reference: console.js On the operator console's left pane, each stage updates live via run.step events (Received, Screened, Checks, Rules, Reply, Reply checked) so the person sees real progress without seeing unreviewed text. Reference: console.js If the stream drops, the page reconciles against GET /api/state. Reference: console.js

Do

Hold the chat bubble quietly until review passes, then stream the approved reply.

Organisation holon EFS Reviewed reply
Should I move my super into an SMSF?
I can only give general information here. One of the advisers can look at your situation in a first meeting.
HTML
<div class="hx-pane hx-stack">
  <div class="hx-pane-head hx-row">
    <img class="hx-glyph" src="assets/glyphs/organisation.svg" alt="Organisation holon">
    <span class="hx-title">EFS</span>
    <span class="hx-small hx-muted">Reviewed reply</span>
  </div>
  <div class="hx-thread hx-stack">
    <div class="hx-msg-person">Should I move my super into an SMSF?</div>
    <div class="hx-msg-holon">I can only give general information here. One of the advisers can look at your situation in a first meeting.</div>
  </div>
</div>
Don’t

Do not stream unreviewed text over GET or show personal advice before the review finishes.

Organisation holon EFS Unreviewed live stream
Should I move my super into an SMSF?
Yes, moving your super into an SMSF makes sense for you... [replaced after review]
HTML
<div class="hx-pane hx-stack">
  <div class="hx-pane-head hx-row">
    <img class="hx-glyph" src="assets/glyphs/organisation.svg" alt="Organisation holon">
    <span class="hx-title">EFS</span>
    <span class="hx-small hx-muted">Unreviewed live stream</span>
  </div>
  <div class="hx-thread hx-stack">
    <div class="hx-msg-person">Should I move my super into an SMSF?</div>
    <div class="hx-msg-holon">Yes, moving your super into an SMSF makes sense for you... [replaced after review]</div>
  </div>
</div>

Open questions