Skip to content

fix: prevent infinite loop on Escape from policy generation error#9

Merged
jesseturner21 merged 1 commit intomainfrom
fix/policy-generate-description-truncation
Mar 20, 2026
Merged

fix: prevent infinite loop on Escape from policy generation error#9
jesseturner21 merged 1 commit intomainfrom
fix/policy-generate-description-truncation

Conversation

@jesseturner21
Copy link
Owner

@jesseturner21 jesseturner21 commented Mar 20, 2026

Summary

  • Fixes an infinite loop where pressing Escape on a policy generation error would re-trigger the API call instead of navigating back to the description step
  • Root cause: the double goBack() pattern (immediate + setTimeout) suffered from stale closures — both calls saw the same step, so the loading step's useEffect would re-fire generation
  • Uses a skipGeneration ref to let the useEffect detect back-navigation and call goBack() with the correct step in scope, reaching the description step without re-triggering generation
  • Also preserves the user's previous description text when navigating back, so they can edit it rather than retyping from scratch

Test plan

  • All 2526 unit tests pass
  • Lint, prettier, secretlint, typecheck all pass
  • TUI test: Error → Escape → lands on description step (not loading loop)
  • TUI test: Description is pre-filled with previous text after Escape back

Evidence

Generation error on the review step

Generation error

After Escape from error — lands on description step with text pre-filled

Description prefilled after escape

Successful generation result before pressing Escape

Generation result

🤖 Generated with Claude Code

@github-actions github-actions bot added the size/m PR size: M label Mar 20, 2026
@github-actions
Copy link

github-actions bot commented Mar 20, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 41.48% 4976 / 11995
🔵 Statements 41.1% 5272 / 12825
🔵 Functions 40.3% 910 / 2258
🔵 Branches 42.9% 3219 / 7503
Generated in workflow #37 for commit cd44505 by the Vitest Coverage Report Action

@github-actions
Copy link

Package Tarball

aws-agentcore-0.3.0-preview.6.1.tgz

How to install

npm install https://github.com/jesseturner21/agentcore-cli/releases/download/pr-9-tarball/aws-agentcore-0.3.0-preview.6.1.tgz

@jesseturner21 jesseturner21 force-pushed the fix/policy-generate-description-truncation branch from 187fda2 to ea35977 Compare March 20, 2026 19:43
@github-actions github-actions bot added size/xs PR size: XS and removed size/m PR size: M labels Mar 20, 2026
…error

When the policy generation API returned an error, pressing Escape on the
review step would loop back to the loading step and re-trigger the API
call, creating an infinite loop. The root cause was the double goBack()
pattern (one immediate, one via setTimeout) suffering from stale closures
— both calls saw the same step, so the second never reached the
description step, while the first landed on loading and re-fired the
useEffect.

The fix uses a skipGeneration ref: when navigating back from review, the
ref is set to true and a single goBack() moves to the loading step. The
useEffect detects the ref, resets it, and calls goBack() again (now with
the correct step in scope) to reach the description step — without ever
starting generation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jesseturner21 jesseturner21 force-pushed the fix/policy-generate-description-truncation branch from ea35977 to cd44505 Compare March 20, 2026 19:47
@github-actions github-actions bot added size/xs PR size: XS and removed size/xs PR size: XS labels Mar 20, 2026
@jesseturner21 jesseturner21 merged commit 9504b59 into main Mar 20, 2026
17 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/xs PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant