Skip to content

feat(actions): add undo replay phase one#171

Closed
Ridanshi wants to merge 3 commits into
sahoo-tech:mainfrom
Ridanshi:feature/undo-replay-system
Closed

feat(actions): add undo replay phase one#171
Ridanshi wants to merge 3 commits into
sahoo-tech:mainfrom
Ridanshi:feature/undo-replay-system

Conversation

@Ridanshi
Copy link
Copy Markdown
Contributor

@Ridanshi Ridanshi commented May 16, 2026

Summary

Completes the full undo/replay system as specified in the issue.

  • ActionRecord extended with is_undoable, undo_instruction,
    undone, and interval fields; SQLite schema updated to match.
  • Undoable mixin and GuidanceDispatcher stub added to
    action_logger.py — dispatcher logs instructions and is designed for
    extension (UI/notifications).
  • undo_last() walks backward through the in-memory stack to find
    the last undoable action, marks its ID in _undone_ids (safe
    double-undo, idempotent), and optionally dispatches the undo
    instruction via an injected GuidanceDispatcher.
  • replay_session() is an async generator that streams
    ActionRecord objects in chronological order from SQLite, sleeping
    interval / speed between actions. Raises ValueError for speed ≤ 0.
  • POST /api/v1/actions/replay accepts {"session_id", "speed"}
    and returns the ordered action list immediately (no timing delays);
    returns 400 for invalid speed.
  • POST /api/v1/actions/undo returns 409 when no undoable
    action remains (including after a double-undo).
  • /ws/replay/{session_id}?speed=<float> streams replay_action
    events one per action with timing, then replay_complete. Reports
    error on invalid speed or exception. Reuses FastAPI's native
    WebSocket — no new framework introduced.
  • KeyboardListener in core/hybrid/keyboard_listener.py binds
    Ctrl+Z via pynput.keyboard.GlobalHotKeys in a daemon thread,
    fires only when mode_manager.current_mode == "passive", and
    silently disables itself if pynput is unavailable (e.g. CI).

Test plan

  • 32/32 tests pass (pytest tests/unit/test_action_logger.py tests/integration/test_actions_context.py)
  • Double-undo returns None / HTTP 409 on second call
  • Non-undoable actions are skipped; only is_undoable=True actions are reversed
  • replay_session yields actions in chronological order with correct intervals
  • replay_session raises ValueError for speed ≤ 0
  • Replay does not modify in-memory stack or _undone_ids
  • WebSocket empty-session sends replay_complete immediately
  • WebSocket invalid speed sends {"event": "error"} message
  • clear_session clears both _stack and _undone_ids

@Ridanshi Ridanshi force-pushed the feature/undo-replay-system branch from 4b54fd8 to c0c398a Compare May 17, 2026 08:40
Add in-memory action history, safe undo handling, and simple replay endpoints without introducing persistence or runtime hooks.
@Ridanshi Ridanshi force-pushed the feature/undo-replay-system branch from c0c398a to ad91b42 Compare May 17, 2026 11:33
…esign

- Add clear_session(session_id) async method to ActionLogger so the
  DELETE /context endpoint can filter by session rather than clearing all
- Fix integration tests to use action_logger.clear() / record_action()
  instead of the removed _stack deque attribute
- Add is_undoable=True to the undo test fixture so undo_last() can find it
- Remove datetime object from ActionRecord constructor (let default str run)
- Rename test_delete_context_clears_deque -> test_delete_context_clears_session_actions
  to match the actual behaviour being verified
- Fix 409 assertion to match the actual detail "Nothing in the undo stack"
@Ridanshi Ridanshi force-pushed the feature/undo-replay-system branch from ad91b42 to 40fc371 Compare May 17, 2026 11:35
@sahoo-tech
Copy link
Copy Markdown
Owner

After reviewing the PR, it does not currently meet the required project standards and therefore cannot be accepted at this stage. You may either work on improving the implementation and retry with the necessary changes, or choose another available issue to contribute to.

Please ensure that future submissions follow the project guidelines, coding standards, and required implementation quality before raising a PR for review
(Note:-All the Tests failed please check properly and retry)

@sahoo-tech sahoo-tech closed this May 21, 2026
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