Skip to content

agent: show partial results when a run hits its credit limit - #299

Merged
rakshith48 merged 2 commits into
mainfrom
agent/partial-results
Oct 2, 2026
Merged

rakshith48 merged 2 commits into
mainfrom
agent/partial-results

Conversation

@rakshith48

@rakshith48 rakshith48 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

What this does

When an agent run stops because it hit its credit limit, the CLI now shows what the agent found so far, instead of just printing an error.

  • Prints a clear "Stopped at credit limit" notice with the run's message.
  • Shows the partial result:
    • --json: the output includes partial, partialSchemaValid and stopReason, plus success: false and error.
    • Human output: the partial is labelled "Partial Result (incomplete)", with "matches schema" or "does not match schema" when the server sends that.
    • If the server recovered nothing, it says "No partial result was recovered."
  • Says how to continue: send a follow-up on the thread (the next turn picks up from the partial), or rerun with a higher --max-credits.
  • --wait runs still exit 1, the same as any other failed run.
  • firecrawl agent thread <id> shows each run's partial and adds a "continue" hint when the latest turn stopped at its credit limit.

When the new fields are missing, nothing changes. That covers older servers and the default setup, since the server flag starts off. Other failed runs still print Error: ... and exit 1 exactly as before.

Notes

  • The pinned SDK (firecrawl@4.40.0) does not have these fields in its types yet, so the CLI reads them defensively from the raw response. It does not bump to an unreleased SDK.
  • A plain status check (firecrawl agent <job-id>, without --wait) still exits 0 for a failed run, as it does today. It now also shows the notice and the partial.
  • In --json mode, or with -o, the notice goes to stderr so the JSON or file output stays clean.

Merge order

Merge this after firecrawl/firecrawl#4812 is deployed. Source PRs:

Testing

  • pnpm run format:check, pnpm run type-check, pnpm run build and pnpm test all pass (663 tests).
  • New end-to-end tests against the local fake API cover: a waited run in JSON and human mode, a credit stop with no partial, an unrelated failure staying the same, a status check, and a thread listing.

🤖 Generated with Claude Code


Summary by cubic

Shows what an agent found so far when a run stops at its credit limit, instead of just printing an error.

  • Adds a credit-limit notice with the run's message and how to continue: follow up on the thread or rerun with a higher --max-credits.
  • JSON output now includes partial, partialSchemaValid, and stopReason; human output labels the partial "Partial Result (incomplete)" and notes schema validity when the server sends it.
  • firecrawl agent thread <id> shows each run's partial and adds a continue hint when the latest turn stopped at its credit limit.
  • Waited runs still exit 1, and output is unchanged when the new fields are absent (older servers).
  • Credit-limit JSON output is flushed before exiting so piped results aren't cut off.
  • In --json or --output mode, the notice goes to stderr to keep stdout pure JSON or the file clean.
  • Merge after the server change exposing these fields is deployed.

Written for commit d6c6ac8. Summary will update on new commits.

Review in cubic

When a run fails with stopReason "credit_limit_reached", print a clear
notice with the run's message, output the partial result (JSON keeps
partial, partialSchemaValid and stopReason; human output labels it
incomplete and shows schema validity), and say how to continue: follow
up on the thread or rerun with a higher --max-credits. Waited runs still
exit 1. Thread listings show per-run partials and a continue hint when
the latest turn stopped at its credit limit.

The pinned SDK (4.40.0) does not type these fields yet, so they are read
defensively; with the fields absent, output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rakshith48
rakshith48 marked this pull request as ready for review October 2, 2026 14:44

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Shadow auto-approve: would not auto-approve because issues were found.

Fix all with cubic | Re-trigger cubic

Comment thread src/commands/agent.ts
Comment thread src/commands/agent.ts Outdated
Comment thread src/commands/agent.ts Outdated
Comment thread src/__tests__/alexandria-beta.test.ts
- The credit-limit failure path now sets process.exitCode = 1 and returns
  instead of calling process.exit(1), so a large JSON result piped to
  another program is no longer cut off at 64 KiB. Exit status stays 1.
- `agent thread --json` (and --output) now prints the continuation hint
  on stderr when the latest turn stopped at its credit limit; stdout
  stays pure JSON.
- Tests: --output sends the "in <path>" notice to stderr and the result
  to the file; plain text mode keeps the notice off stderr; thread --json
  hint goes to stderr; a large piped JSON result arrives whole with exit 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Adds credit-limit stop handling to the agent CLI: failed runs now surface the recovered partial, stop reason, and continue hints in human, JSON, and thread output, guarded so older servers are unchanged. Bounded, well-tested output improvement.

Re-trigger cubic

@rakshith48
rakshith48 merged commit f326d9d into main Oct 2, 2026
8 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.

1 participant