Repository navigation
feat(probes): instrument inference seam + prompt assembly (#206, #195) - #1545
Merged
Merged
Conversation
Iteration 1 of the inference-latency campaign (#195). Sprinkles probes at the load-bearing seams the substrate's RTOS debugger manual marked unchecked. With #196's on_close fix already on canary, `time_sync!` / `time_probe!` spans now persist to the JSONL sink — the timing data this commit produces is captureable end-to-end for the first time. ## What's instrumented **`inference/llamacpp_adapter.rs::generate_text`** — the dominant cost on LCD tier (95%+ wall-clock per 2026-06-06 baseline). The function was effectively a black box from the operator's POV: the existing `runtime::logger("llamacpp")` lines describe shape but not duration, and `tok_per_sec` was kept in a private `RwLock<f64>` (last-throughput-only). Probes added: - `inference.generate.enter` — request fingerprint at entry (model, persona_id, msg_count, max_tokens, has_system_prompt, parts_image, parts_audio). Pairs with `.exit` via span ancestry. - `time_sync!("inference.render_chat", ...)` — chat-template rendering. Synchronous + small, but cumulative across many turns. Bracketing it lets the operator subtract it from `forward.*` cleanly. - `time_probe!("inference.forward.text", ...)` — pure-text scheduler-managed path. The actual LLM decode. - `time_probe!("inference.forward.multimodal", ...)` — mtmd path (image / audio). Distinct seam because it bypasses the scheduler and runs single-flight. - `inference.generate.exit` — pairs with `.enter`. Carries the campaign's headline metric `tok_per_sec` plus duration_ms, tokens_out, text_len, model. A `jq` filter on `class == "inference.generate.exit"` is the latency dashboard in JSONL form. **`persona/prompt_assembly.rs::assemble`** — the leading indicator for "why is prefill slow." When engrams / social signals / matched-angle grow unbounded, `system_message_len` shadows tok/s in the timing breakdown. Probe at the function tail carries the composition shape: system_message_len, message_count, estimated_tokens, matched_angle_present, engrams_count, social_signals_present, voice_mode, multi_party_strategy. ## Doctrine alignment Per [[jtag-probes-are-rtos-debugger]] (Joel 2026-06-06): every probe site names the surrounding vars the way a breakpoint inspector would show locals. Easy one-liners; the macros do the plumbing. `class` strings follow the canonical taxonomy in `docs/architecture/RTOS-DEBUGGER-PROBES.md` (updated in this commit per the "When you add a probe, update this manual" rule). Per [[no-rust-gates-around-cognition]]: probes observe, they DO NOT decide. None of these emit changes control flow. The existing `runtime::logger` and `last_throughput_tok_s` paths remain untouched — probes are additive. Per [[init-once-handle-then-lease-zero-copy-refs]]: the macros expand to `tracing::event!` / `tracing::info_span!` calls that inherit `tracing`'s `release_max_level_*` compile-time gates. Zero cost when off; auditable per task #198 if a hot loop later needs the visitor allocation reviewed. ## Manual update `docs/architecture/RTOS-DEBUGGER-PROBES.md`: - Added the new classes to the taxonomy (`persona.prompt.assemble` with full field list; `inference.generate.{enter,exit}`; the three new `timing` seams). - Marked the prompt-assembly checklist item DONE. - Marked the llamacpp-adapter checklist item DONE with the specific call-site list and the campaign cross-reference. ## Validation - `cargo check --features metal,accelerate` — clean - `cargo test --lib persona::prompt_assembly` — 12/12 pass - `cargo test --lib inference::llamacpp` — 12/12 pass - 24/24 green across the two affected modules ## Next iteration Iteration 2 (separate slice): run a real continuum boot with CONTINUUM_PROBE_FILE set, exercise the persona service loop against the multi-persona stress fixture (#1518's baseline), `jq` the JSONL to identify the dominant bottleneck. Optimize THAT. Iterate. Until tok_per_sec on the LCD tier hits the M5-class target. Co-Authored-By: Claude Opus 4.7 <[email protected]>
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Iteration 1 of the inference-latency campaign (#195). With #196's on_close fix already merged,
time_sync!/time_probe!spans persist to the JSONL sink end-to-end — so the timing data this commit produces is now captureable for the first time.What's instrumented
inference/llamacpp_adapter.rs::generate_textThe dominant cost on LCD tier (95%+ wall-clock per 2026-06-06 baseline). Until this PR the function was a black box from the operator's POV —
tok_per_seclived in a privateRwLock<f64>(last-throughput-only).inference.generate.enter— request fingerprint at entry (model, persona_id, msg_count, max_tokens, has_system_prompt, parts_image, parts_audio)time_sync!("inference.render_chat", ...)— chat-template rendering (sub-ms typically, but cumulative)time_probe!("inference.forward.text", ...)— pure-text scheduler-managed forward passtime_probe!("inference.forward.multimodal", ...)— mtmd single-flight path (image / audio)inference.generate.exit— carries the headline metrictok_per_secplus duration_ms, tokens_out, text_len, model. Ajqfilter on this class IS the latency dashboardpersona/prompt_assembly.rs::assembleThe leading indicator for "why is prefill slow." Carries
system_message_len,message_count,estimated_tokens,matched_angle_present,engrams_count,social_signals_present,voice_mode,multi_party_strategy.Manual update
docs/architecture/RTOS-DEBUGGER-PROBES.md:Doctrine alignment
[[jtag-probes-are-rtos-debugger]]— every site names surrounding vars the way a breakpoint inspector would. One-liners; macros do the plumbing.[[no-rust-gates-around-cognition]]— probes observe, they DO NOT decide. Zero control-flow change. The existingruntime::logger+last_throughput_tok_spaths are untouched.[[init-once-handle-then-lease-zero-copy-refs]]— macros expand totracing::event!/info_span!which inheritrelease_max_level_*compile-time gates. Zero cost when off.Validation
cargo check --features metal,accelerate— cleancargo test --lib persona::prompt_assembly— 12/12 passcargo test --lib inference::llamacpp— 12/12 passNext iteration (separate slice)
Run a real continuum boot with
CONTINUUM_PROBE_FILE=/tmp/continuum-probes.jsonl+CONTINUUM_PROBE_CLASSES=inference,persona.prompt,timing. Exercise the persona service loop.jqthe JSONL to identify the dominant bottleneck. Optimize that. Iterate.Reference: substrate task #206 (this PR), task #195 (the campaign).
🤖 Generated with Claude Code