Skip to content

Measure search_skills end-to-end latency on local 7B model - #1282

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1152-search-skills-latency-bench
May 30, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1152-search-skills-latency-bench

Conversation

@malibio

@malibio malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #1152

Introduces packages/agent/tests/search_skills_latency.rs: a real-model
integration bench that measures wall-clock and per-phase token cost for
three turn scenarios (conversational / single-skill / multi-skill), each
run N=10 times, with results written to
nodespace-docs/development/benchmarks/search-skills-latency.md.

Key finding: Gemma 4 8B consistently bypassed search_skills and called
downstream tools directly. Latency is 1–1.5s (conversational), ~6.8s
(single-skill intent, 5 tool rounds), ~9.5s (multi-skill, 10 rounds).
No fast-path optimization is warranted — the latency driver is downstream
tool-call round trips, not skill discovery overhead.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review — PR #1282: search_skills end-to-end latency benchmark

Overall: This is a net positive change. The harness is well-structured, gracefully skips when no backend is available, and the manually enriched report in `nodespace-docs` meets the spirit of the acceptance criteria. There is one correctness bug in the report path calculation, one misleading doc comment, a missing list marker in the generated markdown, and a moderate concern around methodology validity — none of which are blockers given the WARN fallback and the manually committed `nodespace-docs` report. Approving with the expectation that the path bug is fixed before the next benchmark run.


Findings

[Improvement] Report path calculation is wrong for both execution contexts

File: `packages/agent/tests/search_skills_latency.rs`, lines 611–613

The comment claims to navigate `packages/agent → packages → nodespace-core → nodespace`, but the `.join("../../../..")` (4 levels up) resolves to different wrong directories depending on where the test is run:

  • Primary checkout (`CARGO_MANIFEST_DIR` = `.../nodespace-core/packages/agent`): 4 levels up = `/Users/` — then `nodespace-docs/` does not exist there.
  • Worktree (`CARGO_MANIFEST_DIR` = `.../nodespace-core/.claude/worktrees/issue-.../packages/agent`): 4 levels up = `.../nodespace-core/.claude/` — producing the stray artifact at `.claude/nodespace-docs/development/benchmarks/search-skills-latency.md` that is sitting in the repo right now.

The primary checkout needs 3 levels (`../../..`); the worktree needs 6 levels (`../../../../../..`). These are irreconcilable with a single static path. The WARN fallback silently fires in both contexts and the auto-generated report is never written to the correct location.

Concrete evidence: Two copies of the report exist on disk — one at `.claude/nodespace-docs/...` (auto-generated, 3,720 bytes, 21:12) and the correct one at `nodespace-docs/development/benchmarks/search-skills-latency.md` (manually curated, 6,743 bytes, 21:25). The benchmark wrote to the wrong place; the developer hand-wrote the correct version separately.

Recommended fix: Walk up from `CARGO_MANIFEST_DIR` searching for a `nodespace-docs` sibling, rather than using a hardcoded level count:

```rust
fn find_docs_benchmarks_dir() -> Optionstd::path::PathBuf {
let mut dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
for _ in 0..10 {
let candidate = dir.join("../nodespace-docs/development/benchmarks");
if candidate.exists() {
return Some(candidate);
}
dir = dir.join("..");
}
None
}
```

Alternatively, accept a `NODESPACE_DOCS_DIR` env var as an escape hatch.

[Improvement] Scenario 2 and 3 never actually exercise `search_skills` — results measure direct tool-call routing, not the named cost

File: `packages/agent/tests/search_skills_latency.rs`, lines 523–578

The issue asks to measure "how many extra ms per turn vs the current router." Across all 30 runs in scenarios 2 and 3, `search_skills` was called 0 times — the model went directly to downstream tools. The harness correctly detects and reports this, and the hand-written analysis in `nodespace-docs` handles it well. However, the scenario descriptions in the auto-generated report still say "Model calls search_skills once" and "calls search_skills twice," which is factually incorrect for any run where the model bypasses it.

This is partly a model behaviour issue (Gemma 4 8B is tool-savvy enough to skip the routing step), but the harness has no mechanism to verify or enforce that a scenario actually exercised the named path. For a benchmark intended to isolate `search_skills` overhead, a post-run assertion or at minimum a clear `WARN` when the expected call count differs from actual would make the harness self-auditing:

```rust
if scenario2.runs.iter().all(|r| r.search_skills_calls == 0) {
eprintln!("WARN: search_skills was never called in scenario 2 —
latency does not reflect skill-routing overhead");
}
```

The hand-written report addresses this honestly. The code harness should surface it too.

[Improvement] Misleading `--features testing` in the doc comment

File: `packages/agent/tests/search_skills_latency.rs`, line 12

The run command in the module doc comment recommends:
```
cargo test -p nodespace-agent --test search_skills_latency --features testing -- --nocapture
```

Unlike its peer `ollama_integration.rs`, this binary does not use any `testing`-gated APIs (`set_system_prompt` is not called). The `--features testing` flag is unnecessary and creates confusion about whether the bench compiles without it. The Cargo.toml entry correctly omits `required-features`, so the flag should be dropped from the doc comment.


Nitpicks

  • Nit: `packages/agent/tests/search_skills_latency.rs`, line 463: The `search_skills` sentence in the Methodology section is missing its `- ` list marker, so it renders as a standalone paragraph rather than a continuation of the bullet list.

  • Nit: The auto-generated report from `build_report()` does not include a date or hardware context — the manually written `nodespace-docs` report adds these by hand. A `chrono::Local::now()` timestamp in `build_report()` would make reruns self-documenting without manual intervention.

  • Nit: `percentile_wall_ms` will panic on an empty `runs` vec (usize underflow on `vals.len() - 1`). All call sites have `is_empty()` guards so this is unreachable in practice, but adding a guard inside the function itself (`if vals.is_empty() { return 0; }`) removes the footgun.

  • Nit: `ollama_running()` and `first_ollama_model()` are copy-pasted verbatim from `ollama_integration.rs`. Rust integration test binaries cannot share modules directly, but a `tests/common/mod.rs` helper (imported via `mod common;`) would consolidate these if a third test binary ever needs the same utilities.


Acceptance Criteria Status (Issue #1152)

Criterion Status
Bench harness for `LocalAgentService::send_message` with real model Met — Ollama + GGUF fallback
Three scenarios, N=10 Met
Wall-clock and per-phase token latency Partial — wall-clock and cumulative prompt/completion tokens; per-round breakdown not exposed by `InferenceUsage` API
Results in `nodespace-docs/development/benchmarks/` Met by manual commit; auto-write path is broken
Fast-path decision Met — correctly recommends no fast-path; latency driver is downstream tool rounds, not skill routing

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with the path-calculation bug and misleading doc comment flagged in the detailed review above as pre-merge fixes. The harness structure, skip logic, stats calculations, and the manually committed nodespace-docs report all meet the acceptance criteria. The finding that Gemma 4 8B bypasses search_skills entirely is architecturally significant and is handled honestly in the hand-written analysis.

- Fix report path: replace hardcoded level-count with find_docs_benchmarks_dir()
  that walks up the directory tree searching for the nodespace-docs sibling,
  working correctly in both primary checkout and worktree layouts
- Add WARN when scenarios 2/3 never call search_skills (self-auditing)
- Fix percentile_wall_ms() panic on empty vec with early return guard
- Add date timestamp to build_report() for self-documenting reruns
- Fix missing bullet prefix on search_skills line in Methodology section
- Update scenario descriptions to describe intent rather than prescribing
  behavior (avoids factual mismatch when model bypasses search_skills)
- Remove --features testing from doc comment (this binary doesn't use
  any testing-gated APIs)

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Address-Review Summary

All reviewer recommendations addressed. One skipped (with rationale).

✅ Addressed (6)

  1. Report path fixed — replaced ../../../.. hardcoded depth with find_docs_benchmarks_dir() that walks up the tree searching for the nodespace-docs sibling, working correctly in both primary checkout and worktree layouts
  2. Self-auditing WARN — harness now emits WARN: search_skills was never called in scenario N when expected routing doesn't occur, making future reruns on different models immediately diagnostic
  3. Removed --features testing from doc comment — this binary has no testing-gated API dependencies
  4. Fixed percentile_wall_ms empty-vec footgun — added early return 0 guard
  5. Added date timestamp to build_report() — reruns are now self-documenting without manual intervention
  6. Fixed missing - bullet in Methodology section — search_skills line now correctly part of the list

⏭️ Skipped (1)

  • tests/common/mod.rs consolidation — only 2 test binaries share ollama_running/first_ollama_model. Extracting a shared module is premature for two files; revisit if a third test binary needs the same utilities.

No re-review needed

All changes are mechanical (path fix, guard, formatting, warn emission). No logic or architectural changes introduced.

@malibio
malibio merged commit 14111a8 into main May 30, 2026
@malibio
malibio deleted the worktree-issue-1152-search-skills-latency-bench branch May 30, 2026 20:13
malibio added a commit that referenced this pull request Jun 22, 2026
* Add search_skills end-to-end latency benchmark harness (closes #1152)

Introduces packages/agent/tests/search_skills_latency.rs: a real-model
integration bench that measures wall-clock and per-phase token cost for
three turn scenarios (conversational / single-skill / multi-skill), each
run N=10 times, with results written to
nodespace-docs/development/benchmarks/search-skills-latency.md.

Key finding: Gemma 4 8B consistently bypassed search_skills and called
downstream tools directly. Latency is 1–1.5s (conversational), ~6.8s
(single-skill intent, 5 tool rounds), ~9.5s (multi-skill, 10 rounds).
No fast-path optimization is warranted — the latency driver is downstream
tool-call round trips, not skill discovery overhead.

Co-Authored-By: Claude <[email protected]>

* Address review feedback on search_skills latency bench (PR #1282)

- Fix report path: replace hardcoded level-count with find_docs_benchmarks_dir()
  that walks up the directory tree searching for the nodespace-docs sibling,
  working correctly in both primary checkout and worktree layouts
- Add WARN when scenarios 2/3 never call search_skills (self-auditing)
- Fix percentile_wall_ms() panic on empty vec with early return guard
- Add date timestamp to build_report() for self-documenting reruns
- Fix missing bullet prefix on search_skills line in Methodology section
- Update scenario descriptions to describe intent rather than prescribing
  behavior (avoids factual mismatch when model bypasses search_skills)
- Remove --features testing from doc comment (this binary doesn't use
  any testing-gated APIs)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Measure search_skills end-to-end latency on local 7B model

1 participant