design+realize: RLM-336 text streaming through the completion boundary #350

Merged
nsaspy merged 5 commits from research/text-streaming into main 2026-09-04 18:29:31 +00:00
Owner

ADADR design and realization slices for issue #336 (text streaming). Research record RLM-RESEARCH-336 was approved for realization in PR #349.

Design (approved by the operator on 2026-09-04)

  • rage/336-text-streaming-design.org resolves research OQ1-OQ6 and records the adversarial review. Decision gate: GO with operator evidence.

Realization (within the approved scope)

  • One trusted completion option text_delta_handler(Handler) selecting the chain streaming transport (model_stream_execute) inside the existing bounded async worker. Absent option = byte-identical model_complete_execute path. Combining with injected planner_handler/model_handler fails fast (conflicting_stream_option).
  • Closed completion-level stream_message{} vocabulary keyed by stream_call{operation, depth, seq}; chain stream_event{} shape stays private; exactly-once started (before first delta) and completed (post-validation); no completion on error/cancel paths.
  • The validated stream_result.response stays authoritative: usage exactly once; hard delta_final_divergence gate with preserved usage; transport-dict stream errors carry observed stream_usage; cancellation stays conservative.
  • ui_stream_handler/3 projects to canonical agent_event(message_started/model_delta/message_completed) with bijective message ids; UI v1 wire protocol unchanged; no scheduler, trajectory, trace, or persistence changes.

Evidence

  • Focused fixture-server suite: 13/13 (lifecycle, conflict, divergence, cancellation, usage-on-error, recursive CallRef attribution, UI projection).
  • Complete deterministic suite: 1192/1192; benchmark deterministic 16/16; CLI demo smoke green.
  • Live gate: REAL OpenRouter completion streaming passed with credentials; router-safe without; registered in the live lane + CI static load.
  • All machine-recorded in the tracked .prolog ledger (task issue-336-realize) at the pushed HEAD.

Non-goals (unchanged): no scheduler/event-bus changes, no SSE transport changes, no direct-mode native streaming, no trajectory-shape or UI protocol changes, no reasoning-delta delivery.

ADADR design and realization slices for issue #336 (text streaming). Research record RLM-RESEARCH-336 was approved for realization in PR #349. ## Design (approved by the operator on 2026-09-04) - `rage/336-text-streaming-design.org` resolves research OQ1-OQ6 and records the adversarial review. Decision gate: GO with operator evidence. ## Realization (within the approved scope) - One trusted completion option `text_delta_handler(Handler)` selecting the chain streaming transport (`model_stream_execute`) inside the existing bounded async worker. Absent option = byte-identical `model_complete_execute` path. Combining with injected `planner_handler`/`model_handler` fails fast (`conflicting_stream_option`). - Closed completion-level `stream_message{}` vocabulary keyed by `stream_call{operation, depth, seq}`; chain `stream_event{}` shape stays private; exactly-once `started` (before first delta) and `completed` (post-validation); no completion on error/cancel paths. - The validated `stream_result.response` stays authoritative: usage exactly once; hard `delta_final_divergence` gate with preserved usage; transport-dict stream errors carry observed `stream_usage`; cancellation stays conservative. - `ui_stream_handler/3` projects to canonical `agent_event(message_started/model_delta/message_completed)` with bijective message ids; UI v1 wire protocol unchanged; no scheduler, trajectory, trace, or persistence changes. ## Evidence - Focused fixture-server suite: 13/13 (lifecycle, conflict, divergence, cancellation, usage-on-error, recursive CallRef attribution, UI projection). - Complete deterministic suite: 1192/1192; benchmark deterministic 16/16; CLI demo smoke green. - Live gate: REAL OpenRouter completion streaming passed with credentials; router-safe without; registered in the live lane + CI static load. - All machine-recorded in the tracked `.prolog` ledger (task issue-336-realize) at the pushed HEAD. Non-goals (unchanged): no scheduler/event-bus changes, no SSE transport changes, no direct-mode native streaming, no trajectory-shape or UI protocol changes, no reasoning-delta delivery.
research: operator approves RLM-RESEARCH-336 for realization
Some checks failed
Tree-sitter FFI / Direct SWI-Prolog Tree-sitter FFI (pull_request) Failing after 18s
CI / Deterministic unit and load checks (pull_request) Has been cancelled
CI / REAL OpenRouter integration (pull_request) Has been cancelled
Nix flake / Flake package and clean runtime load (pull_request) Has been cancelled
Clean SWI pack install / Install and load copied pack (pull_request) Has been cancelled
Paid OpenRouter / Pinned paid OpenRouter integration (pull_request) Has been cancelled
4531b1e6da
Operator directive in the 2026-09-04 session authorizes implementation
(reviewed PR #349 head bd457a546f).
ADADR design slice resolving OQ1-OQ6 from approved RLM-RESEARCH-336:

- One trusted completion option text_delta_handler(Handler) selecting
  model_stream_execute inside the existing bounded async worker; absent
  option is byte-identical to today's model_complete_execute path.
- Closed completion-level stream_message{} vocabulary with
  CallRef{operation, depth, seq}; chain stream_event{} shape stays private;
  completion runtime owns started/completed lifecycle (first-delta start,
  post-validation complete, exactly once per CallRef).
- Reasoning deltas aggregated and consistency-checked but not delivered;
  no coalescing; conflict rule fails fast when combined with injected
  planner/model handlers; transport-dict stream errors carry observed
  stream_usage; divergence is a hard error, never silent reconciliation.
- Conversation/UI surfaces consume the handler via host-side projection to
  canonical agent_event terms; UI v1 protocol unchanged.

Design approval is the pending human gate on PR #350; implementation is not
authorized by this commit. Verification ledger refreshed for task
issue-336-design.
design: record operator design approval for RLM-336
Some checks failed
Tree-sitter FFI / Direct SWI-Prolog Tree-sitter FFI (pull_request) Failing after 53s
CI / Deterministic unit and load checks (pull_request) Has been cancelled
CI / REAL OpenRouter integration (pull_request) Has been cancelled
Nix flake / Flake package and clean runtime load (pull_request) Has been cancelled
Clean SWI pack install / Install and load copied pack (pull_request) Has been cancelled
Paid OpenRouter / Pinned paid OpenRouter integration (pull_request) Has been cancelled
15261a3e5a
The operator approved the RLM-336 design in the 2026-09-04 session after
the design-approval gate was presented on PR #350. Decision gate moves to
GO with the operator directive as evidence; realization is authorized within
the recorded scope. Verification ledger invariant updated from
decision-gate-pending to decision-gate-approved.
Implements the approved design (rage/336-text-streaming-design.org, PR #350):

- Trusted text_delta_handler(Handler) completion option selects the chain
  streaming transport inside the existing bounded async worker; absent
  option keeps the byte-identical model_complete_execute path; combining
  the option with injected planner/model handlers fails fast with
  conflicting_stream_option.
- Internal pump delivers the closed stream_message{} vocabulary
  (started/delta/completed keyed by stream_call{operation, depth, seq});
  chain stream_event{} shape stays private; started fires exactly once
  before the first delta; completed fires exactly once only after the
  delta-aggregate consistency check; error and cancellation paths never
  fabricate completion.
- Validated stream_result.response stays authoritative: usage recorded
  exactly once; delta-aggregate divergence is a hard delta_final_divergence
  error with preserved usage; transport-dict stream errors carry observed
  stream_usage; mid-stream cancellation stays conservative.
- ui_stream_handler/3 in the UI facade projects the vocabulary to canonical
  agent_event terms with bijective host-scoped message ids; UI v1 wire
  protocol unchanged.
- Deterministic fixture-server suite (13 tests) covering lifecycle,
  conflict, divergence, cancellation, usage-on-error, recursive CallRef
  attribution and UI projection; router-safe credentialed live OpenRouter
  completion streaming gate registered in the live lane and CI.
- docs/completion-runtime.md documents the contract; roadmap notes the
  model-text canonical event producer.
verify: record issue-336 realization observations at final HEAD
Some checks failed
Tree-sitter FFI / Direct SWI-Prolog Tree-sitter FFI (pull_request) Failing after 37s
CI / REAL OpenRouter integration (pull_request) Has been skipped
Paid OpenRouter / Pinned paid OpenRouter integration (pull_request) Failing after 1m23s
Clean SWI pack install / Install and load copied pack (pull_request) Successful in 1m42s
CI / Deterministic unit and load checks (pull_request) Successful in 2m57s
Nix flake / Flake package and clean runtime load (pull_request) Failing after 5m34s
9006c22508
Focused streaming suite 13/13, complete deterministic suite 1192/1192,
live OpenRouter completion streaming gate passed with real credentials,
router-safe load without credentials, research approval and static load
green. All machine-recorded against bef1b6e.
nsaspy changed title from design: RLM-336 text streaming through the completion boundary to design+realize: RLM-336 text streaming through the completion boundary 2026-09-04 17:01:45 +00:00
Author
Owner

Realization pushed through 9006c22 (design approval 15261a3, implementation bef1b6e, verification ledger 9006c22).

Real OpenRouter live evidence (credentialed, this worktree): real SSE deltas through the completion boundary, aggregate text == validated final response, usage recorded exactly once, CallRef-attributed lifecycle started/delta/completed delivered exactly once per call.

Deterministic: focused streaming suite 13/13; full suite 1192/1192 (97 suites); benchmark deterministic 16/16; CLI demo smoke; research-approval gate green (21 tracked records).

Merge closes the implementation of #336 per the ADADR decision gate recorded in rage/336-text-streaming-design.org.

Realization pushed through 9006c22 (design approval 15261a3, implementation bef1b6e, verification ledger 9006c22). Real OpenRouter live evidence (credentialed, this worktree): real SSE deltas through the completion boundary, aggregate text == validated final response, usage recorded exactly once, CallRef-attributed lifecycle started/delta/completed delivered exactly once per call. Deterministic: focused streaming suite 13/13; full suite 1192/1192 (97 suites); benchmark deterministic 16/16; CLI demo smoke; research-approval gate green (21 tracked records). Merge closes the implementation of #336 per the ADADR decision gate recorded in rage/336-text-streaming-design.org.
Author
Owner

Local verification of the failing remote lanes (head 9006c22), run by the operator directive 'local nix tests then merge when local works':

  • nix.yml all four steps locally: nix flake check --no-update-lock-file (all checks passed), nix build .# (exit 0), packaged library load outside checkout via nix develop (OK), packaged wrapper prolog-rlm-swipl (OK).
  • Paid OpenRouter first step locally with pinned model z-ai/glm-5.3-flash and real credentials: swipl -q -s test/run_live_openrouter.pl exit 0, including the new live_completion_stream_openrouter suite (real SSE deltas through the completion boundary, aggregate == validated final, usage once).
  • Deterministic: CI job 269 success (1192/1192); focused streaming suite 13/13.

The re-dispatched CI nix (run 300), paid (299) and tree-sitter (301) failures reproduce nowhere locally with identical commands; they are runner/infra failures, not branch failures. Merging per the operator's explicit local-verification directive; the lane issues remain tracked (#340 tree-sitter runner; nix/paid runner issues stay open for the CI owners).

Local verification of the failing remote lanes (head 9006c22), run by the operator directive 'local nix tests then merge when local works': - nix.yml all four steps locally: nix flake check --no-update-lock-file (all checks passed), nix build .# (exit 0), packaged library load outside checkout via nix develop (OK), packaged wrapper prolog-rlm-swipl (OK). - Paid OpenRouter first step locally with pinned model z-ai/glm-5.3-flash and real credentials: swipl -q -s test/run_live_openrouter.pl exit 0, including the new live_completion_stream_openrouter suite (real SSE deltas through the completion boundary, aggregate == validated final, usage once). - Deterministic: CI job 269 success (1192/1192); focused streaming suite 13/13. The re-dispatched CI nix (run 300), paid (299) and tree-sitter (301) failures reproduce nowhere locally with identical commands; they are runner/infra failures, not branch failures. Merging per the operator's explicit local-verification directive; the lane issues remain tracked (#340 tree-sitter runner; nix/paid runner issues stay open for the CI owners).
nsaspy merged commit 2962d89635 into main 2026-09-04 18:29:31 +00:00
Sign in to join this conversation.
No description provided.