feat(workflow): cap agent calls per run - #121
Open
Waishnav wants to merge 2 commits into
Open
Conversation
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR introduces a shared, concurrency-safe cap of 256 agent calls per workflow run.
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The shared runtime counter is checked and incremented synchronously, nested workflows reuse that runtime, overflow is rejected before provider execution, and the new typed error is accepted throughout the workflow contract and persistence paths.
|
| Filename | Overview |
|---|---|
| src/workflow-api.ts | Enforces the shared agent-call limit with synchronous allocation before cache, semaphore, and provider paths. |
| src/workflow-contracts.ts | Adds the new call-limit error kind to the validated public workflow error contract. |
| src/workflow-errors.ts | Extends WorkflowEngineError typing so call-limit failures survive existing normalization and persistence paths. |
| src/workflow-engine.test.ts | Verifies concurrent allocation at the boundary permits the final call and rejects overflow without provider execution. |
| src/workflow-types.ts | Defines the fixed maximum of 256 agent calls per workflow runtime. |
| src/workflow-types.test.ts | Locks the new workflow limit constant to its intended value. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Agent call requested] --> B{Shared call index below 256?}
B -- No --> C[Throw call_limit]
B -- Yes --> D[Allocate and increment index]
D --> E[Check replay decision]
E -- Cache hit --> F[Return cached response]
E -- Execute --> G[Acquire shared semaphore]
G --> H[Run provider]
H --> I[Release semaphore]
Reviews (1): Last reviewed commit: "test(workflow): cover agent call budget ..." | Re-trigger Greptile
This was referenced Jul 30, 2026
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.
A workflow script could issue an unbounded number of agent calls, including through nested workflows, allowing a runaway run to consume provider capacity indefinitely.
Workflow runs now share a hard budget of 256 agent calls across the entire nested runtime. Each call reserves a slot atomically before semaphore acquisition or provider execution, so concurrent branches cannot overshoot the limit. The next call fails with a typed
call_limiterror, and recorded call counts remain consistent with executed work.Stack
Based on #120 and final in the active refinement chain above #94.
Summary by CodeRabbit
New Features
Bug Fixes
Tests