fix(ai): re-read agent.maxSteps live so a raised limit takes effect mid-run - #54
Merged
Conversation
…id-run
The step cap was captured once, as a plain number, when a goal started
(maxSteps: cfg.get('agent.maxSteps')). Raising it from 25 to 1000 while
autopilot was running had no effect — the loop kept comparing against the
frozen 25 and paused at "step limit" anyway.
Hand runAgent a LIVE getter instead, mirroring the neighbouring `autopilot`
getter: it re-reads a fresh getConfiguration on every access, and agent.js's
loop already gates on ctx.maxSteps each iteration, so a changed limit now
takes effect on the very next step (both directions). The pause card also
reports the actual limit in effect rather than the stale 25.
Guarded by a source-invariant test (test/agentMaxSteps.test.js) in the same
style as webviewCss/providerMode — a live runAgent needs a workspace +
provider this pure-unit suite doesn't stand up — asserting both ends: the
getter in extension.js (never a snapshot) and the live ctx.maxSteps read in
agent.js (never hoisted/destructured).
Full extension suite: 23 passing, 0 failing.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes autopilot’s step-limit behavior so levelcode.ai.agent.maxSteps is re-read live during an in-progress agent run (instead of being snapshotted at goal start), allowing users to raise/lower the cap mid-run and have it take effect on the next step.
Changes:
- Pass
maxStepsintorunAgentas a live getter that re-reads a freshaiConfig()each access. - Add a source-invariant unit test guarding (a) the contributed setting shape and (b) that both the extension call-site and agent loop continue to treat
maxStepsas live.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| extensions/levelcode-ai/extension.js | Switches maxSteps passed to runAgent from a snapshotted number to a live getter re-reading aiConfig(). |
| extensions/levelcode-ai/test/agentMaxSteps.test.js | Adds a regression test ensuring agent.maxSteps remains live (and the setting remains unbounded above). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
The bug
In autopilot, changing Maximum tool-use steps (
levelcode.ai.agent.maxSteps) from 25 to 1000 had no effect — the agent still paused at "step limit" after 25.agentFlowread the cap once, as a plain number, when a goal started:The loop in
agent.js(while (step++ < ctx.maxSteps)) then compared against that frozen25for the whole run, so raising the setting mid-run never took effect.The fix
Hand
runAgenta live getter that re-reads a fresh config on every access — mirroring theautopilotgetter three lines below it, which exists for the same "must be live mid-run" reason:aiConfig()returns a freshgetConfiguration('levelcode.ai')(VS Code config objects are snapshots, so re-fetching is what makes it live). The loop readsctx.maxStepsevery iteration and never copies it, so a changed limit now applies on the next step:Tests
New
test/agentMaxSteps.test.js— a source-invariant guard in this suite's existing idiom (webviewCss,providerMode), because a liverunAgentneeds a workspace + provider the pure-unit suite deliberately doesn't stand up. It locks down both ends and fails loudly if either regresses to a snapshot:maxStepsas a getter over a freshaiConfig()(never a static capture),ctx.maxStepsdirectly (never hoisted/destructured).Full extension suite: 23 passing, 0 failing.
🤖 Generated with Claude Code