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
- Default to
reviewedstreaming so no unverified word reaches the visitor. Hold the reply untilfinish()and the reply battery pass, then stream the approved text word by word. Reference: flow.mjs Reference: server.mjs House note: three-service holon - Always stream server-sent events over
POST, neverGET. Quick tunnels and buffering proxies hold aGETevent stream until the request finishes, whereas aPOSTresponse passes through chunk by chunk. Holon rules §4 Reference: server.mjs House note: three-service holon - Disable live streaming automatically when a strict rule applies. Even when opt-in live mode is active, personal-advice and personal-details turns always fall back to
reviewedmode. Reference: flow.mjs House note: three-service holon - Protect opt-in live streaming with
StreamGuard. Buffer partial words and trailing digit runs until safe, and halt immediately on a canary leak or stray contact detail. Reference: guards.mjs - Abort the flow the instant the visitor disconnects. Attach an abort signal to the response
closeevent so an abandoned tab triggers zero further model calls. Reference: server.mjs Reference: flow.mjs
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
| Property | Reviewed mode (default) | Live mode (opt-in) |
|---|---|---|
| When text appears | Only after finish() and the reply battery pass. Reference: flow.mjs | Word by word as the reply model generates, filtered by StreamGuard. Reference: guards.mjs |
| Strict-rule turns | Held until review passes. Reference: flow.mjs | Forced back to reviewed mode (!fired.some(r => r.strict)). Reference: flow.mjs |
| Measured first words | 3.2 to 5.3 seconds. House note: three-service holon | 1.8 to 2.4 seconds. House note: three-service holon |
| Review failure UX | Only the fixed replacement streams; bad text is never seen. Reference: flow.mjs | Already-seen text fades across to the fixed replacement. Reference: console.js House note: three-service holon |
| Variant price | Prepare a reply · Reviewed · $0.05 / reply Reference: task-types.json | Prepare a reply · Live · $0.06 / reply Reference: task-types.json |
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
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:
- Parse
Acceptproperly:wantsEventStream()checks media types case-insensitively and honoursq=0, returning plain JSON otherwise. Reference: server.mjs - Disable proxy buffering: Send
content-type: text/event-stream,cache-control: no-cache, no-store, no-transform, andx-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 - Isolate sessions: Each session's events go only to its own open
POSTstream sink, andres.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
Hold the chat bubble quietly until review passes, then stream the approved reply.
<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>Do not stream unreviewed text over GET or show personal advice before the review finishes.
<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>