Skip to content

Stop analysis outrunning the serverless function limit - #3

Merged
Hussaincodes01 merged 3 commits into
mainfrom
claude/loving-ritchie-qc78k9
Nov 2, 2026
Merged

Hussaincodes01 merged 3 commits into
mainfrom
claude/loving-ritchie-qc78k9

Conversation

@Hussaincodes01

Copy link
Copy Markdown
Owner

Problem

A live ResNet job stayed in "Finding the hard ideas" for 83 minutes.

  • Each attempt was killed, not failed. Every analysis call on the free Nemotron endpoint ran past Vercel's 300 s function limit and was killed mid-call, so no error handler ran.
  • The retry limit never triggered. analyze_attempts reached 5 against a limit of 3, but the job was never marked failed, and every advance restarted the same doomed call.
  • The HTTP timeout couldn't help. OpenRouter answers 200 at once and keeps a slow non-streaming request alive with periodic bytes, so httpx's read timeout never fires. Production logs show the 200 OK arriving about 3 s into each advance, followed by nothing.

Measurement

A Vercel Sandbox called nvidia/nemotron-3.5-lightning:free with a 67k-character prompt asking for a long JSON reply:

reasoning total time completion tokens of which reasoning
on 112 s 9,720 7,272
off 30 s 1,730 0

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

  • Analysis no longer reasons. LLM_REASONING_ANALYZE=1 turns it back on. Diagram codegen still reasons.
  • Every long-context call has a wall-clock limit. Replies are streamed and stopped at 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 :free model that misses the limit hands over to the next model in the chain. With too little time left, no call starts.
  • Analysis asks for at most 12 concepts (LLM_ANALYSIS_ITEMS), which bounds the reply's length.
  • No more silent loops. The stepper fails a job whose analysis attempts died without recording a failure, with the code analyze_timeout and a message the user can act on.
  • Errors keep their meaning. ProviderErrors raised while sending a request now pass through _chat unchanged, instead of being rewrapped as a generic retryable failure.

Verification

  • pytest passes. New tests cover:
    • streamed replies are assembled correctly and their tokens are counted;
    • a free model that is too slow hands over to the paid one;
    • no call starts when the step is out of time;
    • an error inside the stream keeps its status code;
    • analysis does not reason unless asked;
    • attempts killed mid-call fail the job;
    • each step tells the provider its deadline.
  • ruff check and ruff format --check are clean.

Generated by Claude Code

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
Copilot AI balanced review requested due to automatic review settings October 30, 2026 08:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T08:32:46.141947Z 81a9dc9 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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
@Hussaincodes01
Hussaincodes01 merged commit 8ef0ee2 into main Nov 2, 2026
5 checks passed
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.

3 participants