Skip to content

fix(ai): re-read agent.maxSteps live so a raised limit takes effect mid-run - #54

Merged
ndemianc merged 3 commits into
developfrom
fix/agent-maxsteps-live
Jul 28, 2026
Merged

fix(ai): re-read agent.maxSteps live so a raised limit takes effect mid-run#54
ndemianc merged 3 commits into
developfrom
fix/agent-maxsteps-live

Conversation

@ndemianc

Copy link
Copy Markdown
Contributor

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.

agentFlow read the cap once, as a plain number, when a goal started:

maxSteps: Math.max(1, cfg.get('agent.maxSteps', 25)),   // cfg = a snapshot from goal start

The loop in agent.js (while (step++ < ctx.maxSteps)) then compared against that frozen 25 for the whole run, so raising the setting mid-run never took effect.

The fix

Hand runAgent a live getter that re-reads a fresh config on every access — mirroring the autopilot getter three lines below it, which exists for the same "must be live mid-run" reason:

get maxSteps() { return Math.max(1, aiConfig().get('agent.maxSteps', 25)); },

aiConfig() returns a fresh getConfiguration('levelcode.ai') (VS Code config objects are snapshots, so re-fetching is what makes it live). The loop reads ctx.maxSteps every iteration and never copies it, so a changed limit now applies on the next step:

  • Raise 25 → 1000 while it's running → it continues past 25, live.
  • Lower it mid-run → it stops sooner. Dynamic both ways.
  • The pause card's "paused after N steps" now reports the actual limit in effect, not a stale 25.

Tests

New test/agentMaxSteps.test.js — a source-invariant guard in this suite's existing idiom (webviewCss, providerMode), because a live runAgent needs 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:

  • extension.js passes maxSteps as a getter over a fresh aiConfig() (never a static capture),
  • agent.js gates the loop on ctx.maxSteps directly (never hoisted/destructured).

Full extension suite: 23 passing, 0 failing.

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings July 28, 2026 00:00

Copilot AI 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.

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 maxSteps into runAgent as a live getter that re-reads a fresh aiConfig() 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 maxSteps as 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.

Comment thread extensions/levelcode-ai/test/agentMaxSteps.test.js
Comment thread extensions/levelcode-ai/test/agentMaxSteps.test.js
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 28, 2026 00:03
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@ndemianc
ndemianc merged commit 78ce378 into develop Jul 28, 2026
2 checks passed
@ndemianc
ndemianc deleted the fix/agent-maxsteps-live branch July 28, 2026 00:07
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.

2 participants