Skip to content

Profile AI-Chat turn latency on OpenAI-compatible endpoints and the local engine #3704

Closed

Description

@malibio

Problem

An AI-Chat turn is slow, and the daemon log cannot say where the time goes. One question ("How many tasks are assigned to Anoop?") on deepseek/deepseek-v4.1-flash via OpenRouter took about 25s for the turn, plus about 6s of routing probe on the first load of the model. The same model answers a one-sentence prompt directly in about 1.2s.

What was observed (daemon log, one turn, no 429s)

Step Wall time
Routing probe: Stage 1 plus probe request (first load of a model only) ~6s
Stage 1 routing request (4 tools) ~0.4s
Main request (10 tool schemas) to first tool call ~8.3s
Follow-up after the tool result (4 messages) ~3.2s
search_nodes natural-language to filter translation call (1 message, no tools) ~2.1s
Second round (6 messages) to completion ~11s

Each row is one sequential request; the turn's ~25s is their sum. About five requests per prompt, each waiting for the last.

A second capture, Mistral Large on the same pipeline for "Could you check the status of tasks assigned to Michael": 5 rounds and about 96s. First main request 27s; the one-message, no-tool call after each search_nodes took 4s, 21s and 23s in later rounds.

What is not known

The log has no per-request duration, prompt size, or token usage, so the slow requests cannot be split into prompt size, reasoning tokens, provider queueing, or generating tool-call arguments. A reasoning model can spend its whole budget on reasoning (observed directly: deepseek-v4-flash with a small max_tokens returned no content). Nothing has been measured on a local model.

Proposed work

This issue is the measurement. What to change in the context the model is given, and the test prompts to measure against, are in #3706.

  • Log per-request duration, time to first token, prompt tokens and completion tokens (including reasoning tokens) for OpenAI-compatible requests, at info level, and the same for the local engine.
  • Log, per request, the assembled context's size by section and the tool schemas' size by tool.
  • Measure the AI-Chat context is neither targeted nor grounded: too much that does not bear on the message, too little on what it is about #3706 test prompts end to end on a reasoning remote model, a non-reasoning remote model and a local model, and attribute the time.
  • From the measurements, list candidate improvements, for example: tool surface size per request, number of sequential rounds, the natural-language filter translation call, running the routing probe off the user's critical path, and caching a failed probe.

Acceptance Criteria

Activity

  1. changed the title [-]Profile AI-Chat turn latency on OpenAI-compatible endpoints[/-] [+]Profile AI-Chat turns (latency, context size, accuracy) and find how best to improve them[/+] on Oct 8, 2026
  2. changed the title [-]Profile AI-Chat turns (latency, context size, accuracy) and find how best to improve them[/-] [+]Profile AI-Chat turn latency on OpenAI-compatible endpoints and the local engine[/+] on Oct 8, 2026
  3. malibio commented on Oct 10, 2026

    @malibio
    CollaboratorAuthor

    Measurements (PR #3716; logging merged in #3709)

    Per-request logging is in (duration, first byte, prompt/completion/reasoning tokens, section sizes), and the grounding eval can now run on a remote provider, so the breakdown below is from the logs of the final runs: 8 scenarios × 3 reps, OpenRouter.

    Model Requests Avg request Avg first byte Prompt tokens Reasoning tokens
    Claude Haiku 5.5 (reasoning, adaptive) 84 1.7s 0.96s 814K 5,657
    Gemma 4 31B (non-reasoning) 78 1.6s 0.31s 529K 0

    A lookup turn is three sequential requests on both models: the Stage-1 routing request (~1.1K prompt tokens, ~0.8s), the main request with the six lookup tools (~6.6K, ~1.9s) and the follow-up after the tool result (~6.9K, ~1.9s), about 5s end to end. A write turn is longer (the assign turn is ~9s). Of Haiku's completions, about 40% are reasoning tokens (none on most requests, ~100–200 on the others). Time to first byte is where the two differ most: ~0.3s against ~1s.

    Not re-measured: the DeepSeek ~25s and Mistral Large ~96s captures in this issue. The Mistral Large capture guessed custom:assignee and repeated a call until the duplicate guard fired; #3716 and #3709 change what the tools answer in those situations, but that model was not re-run, so the effect on its five rounds is unknown.

    Criteria

    • Each OpenAI-compatible and local request logs duration, time to first token and prompt/completion/reasoning tokens.
    • Measured breakdown on a reasoning remote, a non-reasoning remote and a local model: the first two are above; the local one is on the AI-Chat context is neither targeted nor grounded: too much that does not bear on the message, too little on what it is about #3706 comment. Per-step time attribution for the ~25s DeepSeek capture is not redone.
    • Improvements filed as separate issues. Candidates the numbers support: the routing request is a third of a lookup turn's requests; the follow-up request re-sends the full tool surface (~16.6K bytes of schemas) to answer from one tool result. Neither is filed yet.
  4. malibio commented on Oct 10, 2026

    @malibio
    CollaboratorAuthor

    Update on the final tree (PR #3716, af216c1)

    Improvement folded into #3716

    The Stage-1 routing request was the first of a lookup turn's sequential requests, and for a question about what the workspace holds its answer was overridden anyway. It is no longer made for those messages. Per lookup turn:

    • remote models: routing time 540-800ms → 24-64ms; 3 requests → 2 (Gemma 4 31B 78 → 61 requests over the same 24 turns, Haiku 84 → 59, smoke tests included).
    • local model: a 2.5s request removed. Turn time is too noisy to show it (the same suite swung between 13s and 23s per turn across runs), so only the request-level figure is claimed.

    What the numbers say about the other candidates

    • Re-sending the tool surface on the follow-up request: not worth changing. Locally the follow-up carries the same ~7K prompt tokens and takes a median 2.5s with a 0.7s first chunk, because the engine reuses its prefix cache. Remote, the follow-up and first requests take about the same time.
    • The cost that remains is the first request's prefill (local, lookup turn): 6.7K prompt tokens, a median 15.3s of which 13.9s is before the first token. About 11K bytes are the system prompt and 16.6K bytes the six tool schemas (search_nodes 5.3K, run_query 3.9K, search_semantic 2.9K). Shrinking it means trimming tool descriptions or narrowing the lookup tool set, either of which needs a measured pass against the routing and agent evals; it is not a safe edit without one.

    Criteria

  5. self-assigned this
    on Oct 11, 2026
  6. malibio commented on Oct 11, 2026

    @malibio
    CollaboratorAuthor

    Closing as complete. All three criteria are met: per-request logging landed with #3709; the breakdown on a reasoning remote, a non-reasoning remote and a local model is in the comments above and on #3706; and the improvements the measurements supported are made rather than filed: the Stage-1 routing request is skipped for lookup turns (#3716), and the remaining lever named above, the size of a lookup turn's first request, was trimmed in #3717 (prompt tokens 6.77K to 6.41K, no measurable change in time to first token). Not redone: the DeepSeek and Mistral Large captures in the description were not re-run after these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions