Skip to content

fix: natural cursor movement and plan state bug - #508

Merged
rschardosin merged 1 commit into
mainfrom
fix/natural-cursor-movement-and-plan-state-bug
Sep 8, 2026
Merged

rschardosin merged 1 commit into
mainfrom
fix/natural-cursor-movement-and-plan-state-bug

Conversation

@rschardosin

Copy link
Copy Markdown
Contributor

Summary

This PR fixes two issues:

  1. Critical Bug: Stale Approved Plan Blocking New Plans

    • When a user approved a plan in one planning turn, entering plan mode in a subsequent turn would fail permanently with blocked_active_approved_plan
    • Root cause: AllowActivePlanReplacement() had a guard that refused to clear the activePlanApproved flag
    • Fix: Modified AllowActivePlanReplacement() to unconditionally clear the stale approval flag when entering plan mode
    • Added regression tests: TestChatAgent_AllowPlanReplacement_OverridesApproved and TestChatAgent_GraphPlanMode_ClearsStaleApprovedPlan
  2. Feature: Natural Cursor Movement for Tutorial Recordings

    • Cursor movements were robotic and instant, making tutorial recordings look unnatural
    • Added duration_ms parameter to MoveMouseAnimated() that distributes movement over milliseconds using cubic ease-in-out interpolation
    • Per-step overlay syncing ensures smooth visual glide
    • Backward-compatible: duration_ms=0 (default) preserves instant movement
    • Enhanced tool descriptions with anti-pattern warnings and recommended duration values (300–2500ms based on distance)

Changes

Backend (Go)

  • pkg/agent/chat_agent.go — Fixed AllowActivePlanReplacement() to unconditionally clear activePlanApproved flag
  • pkg/agent/plan_persistence_test.go — Added regression tests for stale plan state
  • pkg/browser/demo_overlay.go — Added durationMs parameter with cubic ease-in-out interpolation
  • pkg/browser/demo_overlay_test.go — Updated test signatures for new parameter
  • pkg/tools/browser_interact.go — Updated caller to pass new parameter
  • pkg/tools/browser_demo.go — Added DurationMs field to BrowserMoveCursorArgs
  • pkg/tools/browser_demo_test.go — Added test for duration parameter
  • pkg/tools/browser_tools.go — Improved tool description with anti-pattern warnings and recommended values

Testing

  • All existing tests pass
  • New regression tests verify plan state fix
  • Cursor movement tested with various duration_ms and steps combinations
  • Manual verification: single call with duration_ms=600 produces smooth ease-in-out motion

Impact

  • Plan Mode: Users can now create multiple plans in sequential turns without getting blocked by stale approval state
  • Tutorial Recordings: Cursor movements now appear natural and human-like when duration_ms is used
  • LLM Guidance: Tool descriptions now explicitly warn against chaining calls and provide recommended duration values

This commit addresses two issues:

1. **Stale Approved Plan Bug Fix (Critical)**
   - Fixed AllowActivePlanReplacement() guard preventing new plans in plan mode
   - When entering Plan/Graph-Plan mode, any prior approval is now unconditionally cleared
   - Prevents blocked_active_approved_plan errors that rendered the plan system unusable
   - Added regression tests: TestChatAgent_AllowPlanReplacement_OverridesApproved,
     TestChatAgent_GraphPlanMode_ClearsStaleApprovedPlan

2. **Natural Cursor Movement Feature**
   - Added duration_ms parameter to browser_move_cursor tool
   - Cursor now glides with cubic ease-in-out acceleration when duration_ms > 0
   - Implements per-step overlay sync so visible cursor tracks movement smoothly
   - Maintains backward compatibility: duration_ms=0 (default) keeps instant movement
   - Enhanced tool descriptions with anti-pattern warnings and recommended values

Changes:
- pkg/agent/chat_agent.go: AllowActivePlanReplacement clears stale approval flag
- pkg/agent/plan_persistence_test.go: Added 2 regression tests
- pkg/browser/demo_overlay.go: MoveMouseAnimated accepts durationMs with ease-in-out loop
- pkg/browser/demo_overlay_test.go: Updated tests for new signature
- pkg/tools/browser_demo.go: Added DurationMs field to BrowserMoveCursorArgs
- pkg/tools/browser_demo_test.go: Added test for DurationMs parameter
- pkg/tools/browser_interact.go: Updated BrowserClick caller to pass durationMs=0
- pkg/tools/browser_tools.go: Enhanced tool description with anti-pattern guidance

All tests pass. The plan system is now functional in plan mode, and cursor animations
in tutorials can now be smooth and human-like with a single tool call.
@rschardosin
rschardosin force-pushed the fix/natural-cursor-movement-and-plan-state-bug branch from bcb32b2 to 56788b2 Compare September 8, 2026 04:37
@rschardosin
rschardosin merged commit 8fe11d7 into main Sep 8, 2026
5 checks passed
@rschardosin
rschardosin deleted the fix/natural-cursor-movement-and-plan-state-bug branch September 8, 2026 15:55
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