The page leanprompt report --html writes for HKUDS/DeepTutor at commit 122cd98, audited 2026-11-29. Every figure on this page is an estimate from reading the code, not a measurement of the app in use. Corrections and takedown: email info@podwarden.com or open an issue. Back to the audit of HKUDS/DeepTutor

leanprompt audit of HKUDS/DeepTutor

Unattended audit: nobody was asked during the run, so priority, volume and prices were left open; the questions for the owner are listed at the end.

2 places where this app pays for tokens it doesn't need

The biggest, at deeptutor/runtime/agentic/labeled_step.py:184, about 1.8M tokens per 1,000 calls: the research, question and page-index loops, and the context pre-pass, call chat.completions.create themselves and never add cache_control.

Together about 1.8M tokens per 1,000 calls An estimate from the code, not a measurement. Findings that overlap are counted once.

Tokens per 1,000 calls, by finding, and each one's share of the total

Plus 12 other problems the audit found, listed after the findings. Not scored.

What this costs you

Every figure here is an estimate from the code, not a measurement. Findings the audit marked as overlapping are counted once in the totals, the largest of each group; other findings can still overlap. Money is not part of the score. The table lists this app's findings first, largest first, then its open questions, then the questions for the server's administrator, then the findings the project already knows about, which are not in the totals.

FindingWhereTokens per 1,000 calls
LP-PC-01deeptutor/runtime/agentic/labeled_step.py:1841.8M not cached; the fix writes 300k to the cache at the write price
LP-PC-01deeptutor/capabilities/explore_context/explorer.py:428240k not cached; the fix writes 40k to the cache at the write price

To see this in money, add to leanprompt.yaml:

  • volume: {calls_per_month: N}: how many calls the app makes a month (with targets:, on each entry)
  • prices: per model: input, cached_input and output per 1M tokens (US dollars, or set currency), with source and checked date (or, self-hosted, engine: {prefill_tokens_per_second: N})

leanprompt never guesses a volume or a price. Your coding agent can look up the provider's current price page and add it with the date; how.

What's wrong and what to change

2 open, 0 fixed. Largest first, by the audit's estimate of tokens lost per 1,000 calls.

The research, question and page-index loops, and the context pre-pass, call chat.completions.create themselves and never add cache_control.

Finding 1. deeptutor/runtime/agentic/labeled_step.py:184 high LP-PC-01 how often is assumed

The chat loop got its breakpoints in #2081; these paths did not. A Claude model reached through OpenRouter caches nothing on them, so every round of a tool loop pays full price for the system prompt, tool schemas and all earlier rounds.

What to change
In run_labeled_step (and the explorer's _call_llm) call the same helper agent_loop._apply_prompt_caching uses: OpenAICompatProvider.supports_prompt_caching_for(model), the binding check, then OpenAICompatProvider._apply_cache_control(messages, tools, stable_history_end=False).
Why it matters
Anthropic caches a prefix only at a cache_control breakpoint. A loop of N rounds re-sends a growing prefix N times; with marks, rounds 2..N read it at the cached rate instead of the full input rate.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: how many calls per 1,000 run through run_agentic_loop, run_labeled_step or the explorer loop on an OpenRouter profile whose model id starts with anthropic/ or claude (usage.sqlite3 rows with cache_read_input_tokens = 0 for those sources)
Who reaches this
only OpenRouter profiles that route anthropic/ or claude models; native Anthropic bindings get marks in their provider
Overlaps
Finding 2 loses some of the same tokens; the totals count the larger once.
Estimate
about 1.8M prompt tokens per 1,000 calls not served from cache on affected profiles (estimate)
What the estimate assumes

average_call 12,000 prompt tokens; 30% of calls run through these loops; about 8,000 reusable tokens per such call (system, tools, earlier rounds); one write per loop priced at 1.25x. Only OpenRouter-Claude profiles are affected.

How to check the fix Run one research or question turn on an OpenRouter anthropic/ model: on the second and later rounds cache_read_input_tokens rises from 0 to about the size of the system prompt plus earlier rounds.

The context pre-pass lays its first messages out so the bytes before the question are stable (_cache_shaped_messages says 'becomes a cache hit'), but its request carries no cache_control, so on an OpenRouter Claude profile the stable prefix is never cached.

Finding 2. deeptutor/capabilities/explore_context/explorer.py:428 medium LP-PC-01 how often is assumed

What to change
Apply the shared cache-marking helper to kwargs before the create call, as agent_loop does.
Why it matters
The layout work only pays when the provider is told where the prefix ends.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: how many chat turns attach sources that trigger the explore_context pre-pass on an OpenRouter-Claude profile
Who reaches this
only OpenRouter-Claude profiles, only turns with attached sources
Estimate
about 240k prompt tokens per 1,000 calls (estimate)
What the estimate assumes

4% of calls are exploration rounds; about 6,000 reusable tokens each.

How to check the fix cache_read_input_tokens on the second round of an exploration is above 0.

Other problems the audit found

Problems the audit checked in the code that cost no tokens of their own, such as a spend meter that ignores cache tokens or a cut-off answer accepted as complete. They are not scored. Check each one before you change anything.

reason tool returns an answer cut off at max_tokens as if complete

Note 1. deeptutor/tools/reason.py:104 LP-GE-12 medium not scored

reason() streams with llm_stream and no StreamOutcome, then returns the joined text. A reply the provider stopped at the 4096-token default cap (hidden reasoning tokens count against it) goes back to the calling loop as a finished analysis. The TypeScript engine's model tool flags the same case with truncated: true (packages/chat-engine/src/tools/model-tool.ts:83).

What to change
Pass outcome=StreamOutcome() to llm_stream and add outcome.truncated to the returned dict and the ToolResult metadata; optionally append a one-line note to the answer.

How to check the fix Set the solve max_tokens to 50, call reason, and check the result says truncated.

brainstorm tool returns an answer cut off at max_tokens as if complete

Note 2. deeptutor/tools/brainstorm.py:89 LP-GE-12 medium not scored

Same shape as reason: llm_stream with no StreamOutcome; the 2048-token default cap can end the idea list mid-item and the result is returned as complete.

What to change
Same as reason: pass outcome=StreamOutcome() and report outcome.truncated.

How to check the fix Set the brainstorm max_tokens to 50 and check the result reports truncated.

Research note summary accepts a cut-off reply

Note 3. deeptutor/agents/research/pipeline.py:1272 LP-GE-12 low not scored

The non-streaming note call reads choices[0].message.content and never looks at finish_reason; a reply cut at the note budget becomes the stored note.

What to change
Read response.choices[0].finish_reason and fall back to cleaned[:600] when it is a truncation reason (finish_was_truncated).

How to check the fix With the note budget set to 20 tokens the stored note equals the raw-answer fallback.

Question tool summarizer accepts a cut-off summary

Note 4. deeptutor/agents/question/pipeline.py:1122 LP-GE-12 low not scored

The streamed summary is joined and passed forward; finish_reason is never read, so a summary cut at tool_summarizer.max_tokens (default 800) replaces the raw tool result.

What to change
Track the last chunk's finish_reason and pass the raw tool result forward when it is a truncation reason.

How to check the fix With max_tokens 20 the raw result is passed forward and a notice is shown.

Context exploration accepts a cut-off investigation

Note 5. deeptutor/capabilities/explore_context/explorer.py:327 LP-GE-12 low not scored

_call_llm never reads finish_reason; a final round stopped at the loop max_tokens is injected into the answer as the investigation.

What to change
Record finish_reason in _CallResult and, when truncated, fall back to the single pass or mark the briefing as partial.

How to check the fix With a tiny loop budget the briefing header says it is partial.

Cache writes are never recorded for OpenAI GPT-5.6+ or OpenRouter

Note 6. deeptutor/services/llm/usage_frame.py:146 LP-GE-11 medium not scored

usage_breakdown reads cache writes only from cache_creation_input_tokens (Anthropic's field). OpenAI's Responses usage reports input_tokens_details.cache_write_tokens and OpenRouter reports prompt_tokens_details.cache_write_tokens, and neither is read, so the usage ledger and the chat usage footer show no cache write column for them even though DeepTutor itself turns on explicit caching for GPT-5.6+ (openai_compat_provider.py:962), where writes cost 1.25x the input rate (checked on 2026-11-28).

What to change
Read cache_write_tokens from input_tokens_details and prompt_tokens_details as a second source for counts['cache_creation_input_tokens'].

How to check the fix Feed usage_breakdown a frame with input_tokens_details.cache_write_tokens = 7000 and check cache_creation_input_tokens is 7000.

Cost summary prices every unlisted model as gpt-4o-mini and ignores cache pricing

Note 7. deeptutor/logging/stats/llm_stats.py:56 LP-GE-11 low not scored

get_pricing falls back to the gpt-4o-mini rate for any model not in a table of nine older ids, and UsageTracker.summary multiplies all prompt tokens, cached ones included, by that one input rate. The CLI prints the result as cost=$ (deeptutor_cli/common.py:385). The number is a rough estimate for a current model.

What to change
Label the figure as an estimate, or return None for an unlisted model instead of a gpt-4o-mini price.

How to check the fix A claude-sonnet-5-5 run prints no cost or a labelled estimate.

Codex OAuth responses drop the usage the parser can read

Note 8. deeptutor/services/llm/provider_core/openai_codex_provider.py:318 LP-GE-11 low not scored

_request_codex calls consume_sse(response, on_content_delta) without on_provider_event, so the usage the Responses parser reads from response.completed (parsing.py, _response_usage) is discarded and LLMResponse carries no usage for this binding. Whether the ChatGPT endpoint sends usage is not established here.

What to change
Pass an on_provider_event hook that keeps the usage event and return it on LLMResponse.

How to check the fix With a Codex profile the usage ledger records prompt and completion tokens for a call.

Codex path ignores max_tokens

Note 9. deeptutor/services/llm/provider_core/openai_codex_provider.py:169 LP-GE-17 low not scored

chat() does del max_tokens, temperature, so the per-stage budgets and the truncation handling built on them do nothing on this binding. May be a limit of the endpoint; not checked.

What to change
Document it next to the del, or forward max_output_tokens if the endpoint accepts it.

How to check the fix A tiny budget on a Codex profile either ends the reply early or the code comment says why not.

Anthropic thinking raises the configured output cap

Note 10. deeptutor/services/llm/provider_core/anthropic_provider.py:454 LP-GE-17 low not scored

With thinking on for the older (budget-token) families, max_tokens becomes max(max_tokens, budget + 4096), so a stage configured at a few hundred tokens (topic naming sends 60) is sent at 5,120 to 8,192 when a reasoning effort is set. Not confirmed that task calls carry an effort.

What to change
Skip thinking for calls whose cap is below the minimum budget, or document the override.

How to check the fix Log the final max_tokens for complete(max_tokens=60) on a claude-sonnet-4-5 profile with effort medium.

Wizard fallback model lists name retired and deprecated OpenAI models

Note 11. deeptutor_cli/init_wizard.py:63 LP-GE-13 low not scored

The OpenAI fallback list (used when GET /models fails) offers o4-mini, retired 2026-10-23, and gpt-4o-mini, gpt-4o, gpt-4.1 and gpt-4.1-mini, listed as Deprecated for 2027-01-14 (OpenAI deprecations page, checked on 2026-11-28).

What to change
Replace them with models the page lists as active.

How to check the fix Every id in LLM_FALLBACK_MODELS['openai'] is absent from the deprecations table.

Anthropic default model id is retired

Note 12. deeptutor/runtime/agentic/client.py:347 LP-GE-13 high not scored

claude-sonnet-4-20250514 is retired since 2026-06-15 (Anthropic deprecations page, checked on 2026-11-28); used when no model is configured.

What to change
Already proposed in #2888.
In progress
open PR that moves both Anthropic fallbacks to a current model https://github.com/HKUDS/DeepTutor/pull/2888

How to check the fix See #2888.

Fix it with your coding agent

Paste this into Claude Code, Codex, Cursor or any coding assistant. It will check each finding against your code and propose fixes one at a time, asking before it changes anything.

Please check and fix the LLM-call findings from a leanprompt audit of this repository.

1. If the leanprompt skills are not installed for you here, install them: npx leanprompt@0.1.0-dev.15 install
2. Read .leanprompt/findings.json and leanprompt-report.md. If they are missing, use the list below.
3. Check each finding against the code before you change anything. The audit can be wrong: if a finding does not hold, tell me why and leave that code alone.
4. Fix one finding at a time. Show me the change as a small diff and apply it only after I say yes.
5. Prove each fix with the measure-loop skill: a before and after on the same scenario. Ask me before running anything that sends real, billed requests.
6. When a fix is proved, set "fixed": true on its finding in .leanprompt/findings.json and run npx leanprompt@0.1.0-dev.15 score.

Findings, largest first:
1. LP-PC-01 at deeptutor/runtime/agentic/labeled_step.py:184: The research, question and page-index loops, and the context pre-pass, call chat.completions.create themselves and never add cache_control. The chat loop got its breakpoints in #2081; these paths did not. A Claude model reached through OpenRouter caches nothing on them, so every round of a tool loop pays full price for the system prompt, tool schemas and all earlier rounds.
2. LP-PC-01 at deeptutor/capabilities/explore_context/explorer.py:428: The context pre-pass lays its first messages out so the bytes before the question are stable (_cache_shaped_messages says 'becomes a cache hit'), but its request carries no cache_control, so on an OpenRouter Claude profile the stable prefix is never cached.

Other problems found (check each against the code first; not scored):
- reason tool returns an answer cut off at max_tokens as if complete (deeptutor/tools/reason.py:104) [LP-GE-12]: reason() streams with llm_stream and no StreamOutcome, then returns the joined text. A reply the provider stopped at the 4096-token default cap (hidden reasoning tokens count against it) goes back to the calling loop as a finished analysis. The TypeScript engine's model tool flags the same case with truncated: true (packages/chat-engine/src/tools/model-tool.ts:83). Change: Pass outcome=StreamOutcome() to llm_stream and add outcome.truncated to the returned dict and the ToolResult metadata; optionally append a one-line note to the answer.
- brainstorm tool returns an answer cut off at max_tokens as if complete (deeptutor/tools/brainstorm.py:89) [LP-GE-12]: Same shape as reason: llm_stream with no StreamOutcome; the 2048-token default cap can end the idea list mid-item and the result is returned as complete. Change: Same as reason: pass outcome=StreamOutcome() and report outcome.truncated.
- Research note summary accepts a cut-off reply (deeptutor/agents/research/pipeline.py:1272) [LP-GE-12]: The non-streaming note call reads choices[0].message.content and never looks at finish_reason; a reply cut at the note budget becomes the stored note. Change: Read response.choices[0].finish_reason and fall back to cleaned[:600] when it is a truncation reason (finish_was_truncated).
- Question tool summarizer accepts a cut-off summary (deeptutor/agents/question/pipeline.py:1122) [LP-GE-12]: The streamed summary is joined and passed forward; finish_reason is never read, so a summary cut at tool_summarizer.max_tokens (default 800) replaces the raw tool result. Change: Track the last chunk's finish_reason and pass the raw tool result forward when it is a truncation reason.
- Context exploration accepts a cut-off investigation (deeptutor/capabilities/explore_context/explorer.py:327) [LP-GE-12]: _call_llm never reads finish_reason; a final round stopped at the loop max_tokens is injected into the answer as the investigation. Change: Record finish_reason in _CallResult and, when truncated, fall back to the single pass or mark the briefing as partial.
- Cache writes are never recorded for OpenAI GPT-5.6+ or OpenRouter (deeptutor/services/llm/usage_frame.py:146) [LP-GE-11]: usage_breakdown reads cache writes only from cache_creation_input_tokens (Anthropic's field). OpenAI's Responses usage reports input_tokens_details.cache_write_tokens and OpenRouter reports prompt_tokens_details.cache_write_tokens, and neither is read, so the usage ledger and the chat usage footer show no cache write column for them even though DeepTutor itself turns on explicit caching for GPT-5.6+ (openai_compat_provider.py:962), where writes cost 1.25x the input rate (checked on 2026-11-28). Change: Read cache_write_tokens from input_tokens_details and prompt_tokens_details as a second source for counts['cache_creation_input_tokens'].
- Cost summary prices every unlisted model as gpt-4o-mini and ignores cache pricing (deeptutor/logging/stats/llm_stats.py:56) [LP-GE-11]: get_pricing falls back to the gpt-4o-mini rate for any model not in a table of nine older ids, and UsageTracker.summary multiplies all prompt tokens, cached ones included, by that one input rate. The CLI prints the result as cost=$ (deeptutor_cli/common.py:385). The number is a rough estimate for a current model. Change: Label the figure as an estimate, or return None for an unlisted model instead of a gpt-4o-mini price.
- Codex OAuth responses drop the usage the parser can read (deeptutor/services/llm/provider_core/openai_codex_provider.py:318) [LP-GE-11]: _request_codex calls consume_sse(response, on_content_delta) without on_provider_event, so the usage the Responses parser reads from response.completed (parsing.py, _response_usage) is discarded and LLMResponse carries no usage for this binding. Whether the ChatGPT endpoint sends usage is not established here. Change: Pass an on_provider_event hook that keeps the usage event and return it on LLMResponse.
- Codex path ignores max_tokens (deeptutor/services/llm/provider_core/openai_codex_provider.py:169) [LP-GE-17]: chat() does del max_tokens, temperature, so the per-stage budgets and the truncation handling built on them do nothing on this binding. May be a limit of the endpoint; not checked. Change: Document it next to the del, or forward max_output_tokens if the endpoint accepts it.
- Anthropic thinking raises the configured output cap (deeptutor/services/llm/provider_core/anthropic_provider.py:454) [LP-GE-17]: With thinking on for the older (budget-token) families, max_tokens becomes max(max_tokens, budget + 4096), so a stage configured at a few hundred tokens (topic naming sends 60) is sent at 5,120 to 8,192 when a reasoning effort is set. Not confirmed that task calls carry an effort. Change: Skip thinking for calls whose cap is below the minimum budget, or document the override.
- Wizard fallback model lists name retired and deprecated OpenAI models (deeptutor_cli/init_wizard.py:63) [LP-GE-13]: The OpenAI fallback list (used when GET /models fails) offers o4-mini, retired 2026-10-23, and gpt-4o-mini, gpt-4o, gpt-4.1 and gpt-4.1-mini, listed as Deprecated for 2027-01-14 (OpenAI deprecations page, checked on 2026-11-28). Change: Replace them with models the page lists as active.
- Anthropic default model id is retired (deeptutor/runtime/agentic/client.py:347) [LP-GE-13]: claude-sonnet-4-20250514 is retired since 2026-06-15 (Anthropic deprecations page, checked on 2026-11-28); used when no model is configured. Change: Already proposed in #2888.

Score

One number from 0 to 100 for how well this app avoids paying for the same tokens twice; higher is better. It is computed from the findings above (static) or from your usage log (measured).

91static
E, prefill reuse
0.85
S, prefix stability
1.00
G, generation waste
0.00
Default shares
0 of 2

Findings scored with severity defaults, not estimates. The fewer, the more the static score says about this app.

A static score is an estimate from the audit's findings, not a measurement.

Scored 2026-11-29 (the date on the machine that ran it).

Questions for the owner

These were not answered during the audit. Until they are, the page shows tokens only and ranks the advice without a priority.

  • Priority: which matters most for this app, cost, speed or quality (or weights)? Not set, so the advice uses equal weights. Answer with priority: in leanprompt.yaml.
  • Volume: how many calls does the app make a month? Answer with volume: {calls_per_month: N, source: "..."} in leanprompt.yaml.
  • Prices: what does each model cost (input, cached input, output per 1M tokens, with the source and the date it was read, and the currency if not US dollars)? Answer with prices: in leanprompt.yaml.