A cut-off web page is saved as finished

Turns screenshots and recordings into code with OpenAI, Anthropic and Gemini models, and stops any single generation at a $3 spend ceiling.
≈ 900,000 tokens per 1,000 calls, output and prompt tokens spent when a turn hits the output limit and is retried estimate
Audited with leanprompt 0.1.0-dev.15
Estimates, not measurements. Every figure on this page is an estimate from reading the code, not a measurement of the app in use.
- Repository
- abi/screenshot-to-code
- Commit audited
f2e5bbd- leanprompt version
- 0.1.0-dev.15
- Audit date
- Status
- The maintainers have been told about this audit; no response yet.
- Maintainers
- the issue
- How it ran
- 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.
leanprompt read the code at commit f2e5bbd and found 1 place where its LLM calls could use fewer tokens, plus 2 other problems, not scored. Static score: 96 of 100 (an estimate from the findings). The code may have changed since.
Findings
-
LP-GE-05Retry only retryable errors; never retry a truncation unchangedbackend/agent/tools/runtime.py:57· severity high · saves prefill and generation · how often is assumedWhat happens. When a turn is cut off at the 50,000-token output limit, nothing reads why it stopped. On OpenAI the cut-off tool call arrives as broken JSON and the whole broken text is sent back to the model as the tool result. The model is told to try again with the same limit, so it writes the whole file again.
The change. Read the stop reason on each provider (OpenAI status incomplete, Anthropic stop_reason max_tokens, Gemini finishReason MAX_TOKENS). On a cut-off, do not echo the broken arguments back: end the variant with a clear 'output limit reached' error, or continue from the saved file with a higher limit.
Why it helps. Each cut-off turn bills up to 50,000 output tokens, the retry bills them again, and the echoed broken arguments stay in the history and are re-read on every later turn.
Estimate about 225k output and 675k prompt tokens per 1,000 calls
Assumptions. half a percent of turns end at the limit (guess; only high-effort reasoning models or very large pages should); each wasted turn is about 45k output tokens; the echoed text is carried by about 3 later turns; average turn is 30k prompt and 5k output tokens. Applies mostly to OpenAI, where arguments arrive as broken JSON; on Anthropic the cut-off call is accepted as complete (see the notes).
Who reaches this. OpenAI models; Anthropic and Gemini see the cut-off as a silent partial file instead
How often. how often a turn ends at the 50,000-token output limit (OpenAI status incomplete, Anthropic stop_reason max_tokens, Gemini MAX_TOKENS), from the run records the app already writes
Other problems the audit found
Problems read in the code that cost no tokens of their own, such as a cost meter or an error path. Not scored.
-
A cut-off page is saved and shown as finished
backend/agent/providers/anthropic/provider.py:403·LP-GE-12Read the finish reason before using an answer · severity highWhat happens. All three providers cap output at 50,000 tokens (anthropic/provider.py:371, openai.py:531, gemini.py:325) and none reads the stop reason. On Anthropic the SDK (0.84.0, lib/streaming/_messages.py:480) parses partial tool JSON, so a create_file cut off mid-page arrives as a valid but shorter 'content'. runtime.py:103-113 saves it, replies 'Successfully created file', and the page is shown as complete. On Gemini and a no-tool OpenAI turn the same cut-off text is returned as the final answer.
The change. Read final_message.stop_reason (Anthropic), response status and incomplete_details (OpenAI) and finishReason (Gemini) after each turn. On max_tokens, do not run the tool call as success; end the variant with an error or ask the model to continue.
Why it matters. The user sees a half page marked as done and nothing says it was cut.
To check. Mock a final message with stop_reason max_tokens and a half create_file input; the variant should end with an error, not a saved file.
-
Cut-off OpenAI turns are not counted against the $3 limit
backend/agent/providers/openai.py:246·LP-GE-11Meter every billed token, cached and unfinished ones too · severity mediumWhat happens. Usage is read only from the response.completed event. A turn that ends at max_output_tokens finishes with response.incomplete, so state.turn_usage stays None (openai.py:548) and the most expensive turn is never added to the total that engine.py:270-276 checks against GENERATION_MAX_COST_USD. Separately, pricing.py:19-20 says cache writes for gpt-5.6 and 6.x are billed at 1.25x but left at 0.
The change. Read usage on response.incomplete (and response.failed when usage is present) as well as response.completed. Add the cache-write rate once the Responses usage exposes it.
Why it matters. The spend ceiling undercounts exactly the turns that cost the most, so a run can pass $3.
To check. Feed parse_event a response.incomplete event with usage; session.total_cost_usd() should include it.
The maintainers’ response
No response from the maintainers yet.
How this was made
The llm-call-audit skill read the code and wrote findings.json; nothing was run against the project’s providers. The full audit page is what leanprompt report --html writes from the same findings.
Corrections and takedown: email info@podwarden.com or open an issue.