Repository navigation
Stop analysis outrunning the serverless function limit - #3
Merged
Merged
Conversation
A real job (ResNet) sat in "analyzing" for 83 minutes. Each analyze call on the free Nemotron endpoint ran past Vercel's 300s function limit and was killed mid-call, so no error handler ran; the attempt counter climbed to 5 (max 3) without the job ever failing, and every advance restarted the same doomed call. The HTTP read timeout never fired because OpenRouter answers 200 at once and keeps a slow non-streaming request alive with periodic bytes. Measured from a Vercel Sandbox on the free endpoint (~86 tokens/s), the same 67k-character analysis took 112s with reasoning (7,272 reasoning tokens) and 30s without. - Analysis no longer reasons (LLM_REASONING_ANALYZE=1 opts back in); diagram codegen still does. - Every long-context call is streamed and stopped at a wall-clock budget: LLM_CALL_TIMEOUT_S (120s) and never past the step's end plus the scene grace, which the stepper now hands the provider. A free model that misses it hands over to the next model in the chain; with too little time left no call starts at all. - Analysis asks for at most 12 concepts (LLM_ANALYSIS_ITEMS), bounding the reply. - The stepper fails a job whose analyze attempts died without recording a failure, instead of looping forever. - ProviderErrors raised while sending pass through _chat unchanged rather than being rewrapped as a generic retryable failure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BgiEmhLGtyG2FWJkiiwD1M
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81a9dc9c59
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…sage Two review findings on the streaming call: - The elapsed-time check ran between lines, so a host that accepted the request and then went silent blocked the read itself until the 300s HTTP read timeout — past the function limit, the failure this change exists to prevent. A watchdog timer now closes the stream at the call budget, which unblocks the read; it is reported as too slow, so a ':free' model hands over to the next one. - Usage on an OpenRouter stream is opt-in. Without it a call bills as zero tokens and the job's dollar ceiling cannot trip. OpenRouter streams now send stream_options.include_usage; other hosts (Mistral rejects unknown fields) are not sent it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BgiEmhLGtyG2FWJkiiwD1M
Measured from a Vercel Sandbox, four diagram-sized calls side by side on the free Nemotron endpoint (all four completed, so parallel scenes are fine there): unbounded reasoning 66s (2,923 reasoning tokens), effort "low" 49s, capped at 800 tokens 15s (799 used: the cap is honoured), reasoning off 8s. OpenRouter requests now send reasoning.max_tokens (LLM_REASONING_MAX_TOKENS, default 800; 0 restores unbounded reasoning). The model still plans the diagram's layout before writing it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BgiEmhLGtyG2FWJkiiwD1M
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.
Problem
A live ResNet job stayed in "Finding the hard ideas" for 83 minutes.
analyze_attemptsreached 5 against a limit of 3, but the job was never marked failed, and every advance restarted the same doomed call.200at once and keeps a slow non-streaming request alive with periodic bytes, so httpx's read timeout never fires. Production logs show the200 OKarriving about 3 s into each advance, followed by nothing.Measurement
A Vercel Sandbox called
nvidia/nemotron-3.5-lightning:freewith a 67k-character prompt asking for a long JSON reply:The real analysis is larger than this (a schema in the prompt, up to 40 concepts, retries when a reply doesn't validate), so with reasoning on it can't fit in one step.
Changes
LLM_REASONING_ANALYZE=1turns it back on. Diagram codegen still reasons.LLM_CALL_TIMEOUT_S(120 s), and never later than the end of the step plus the grace period a started scene gets; the stepper now passes that deadline to the provider. A:freemodel that misses the limit hands over to the next model in the chain. With too little time left, no call starts.LLM_ANALYSIS_ITEMS), which bounds the reply's length.analyze_timeoutand a message the user can act on.ProviderErrors raised while sending a request now pass through_chatunchanged, instead of being rewrapped as a generic retryable failure.Verification
pytestpasses. New tests cover:ruff checkandruff format --checkare clean.Generated by Claude Code