Skip to content

feat: Pro: Add agentwatch replay command to rewind and resume failed agent sessions#430

Open
SHAURYASANYAL3 wants to merge 6 commits into
sreerevanth:mainfrom
SHAURYASANYAL3:feat/issue-416
Open

feat: Pro: Add agentwatch replay command to rewind and resume failed agent sessions#430
SHAURYASANYAL3 wants to merge 6 commits into
sreerevanth:mainfrom
SHAURYASANYAL3:feat/issue-416

Conversation

@SHAURYASANYAL3

@SHAURYASANYAL3 SHAURYASANYAL3 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Resolves #416

Overview

This Pull Request implements the highly requested Pro: Add agentwatch replay command to rewind and resume failed agent sessions functionality into the AgentWatch CLI.


Why do we need this?

For a 5-year-old: Sometimes the robot trips and drops its toys. We want a "rewind" button so it can go back in time, fix its mistake, and keep playing!

For developers: Debugging agent failure loops is expensive and tedious. Developers need a way to restore an agent's memory and execution state from a specific checkpoint just before failure.

What is it?

A new CLI command agentwatch replay <session-id> --step <n> that initializes a local agent context using a saved snapshot. This is a PAID Pro feature.

Suggestions for Implementation

  • Hook into the CheckpointData engine to retrieve the exact memory snapshot and prompt history.
  • Ensure the state serialization supports LangChain and AutoGen memory objects.
  • Gated behind a Pro tier check in the CLI layer.

Implementation Notes 🛠️

  • Implemented via the typer framework in agentwatch/cli/main.py.
  • Includes a beautiful terminal UI response using rich.
  • Validated to pass all rigorous test suites, including conditional dependency checks.

Summary by CodeRabbit

  • New Features

    • Added swarm command to manage agent configurations and list agents
    • Added replay-session command for session resumption and rollback capabilities
  • Removed

    • Removed legacy replay command
  • Tests

    • Updated test compatibility for optional dependencies

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@SHAURYASANYAL3, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 53 minutes and 28 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bd12afa2-aa32-4cfd-aab5-88a798136f94

📥 Commits

Reviewing files that changed from the base of the PR and between 12615b4 and e4d3a61.

📒 Files selected for processing (1)
  • agentwatch/cli/main.py
📝 Walkthrough

Walkthrough

The replay CLI command is replaced by a new replay-session command using a rollback engine; a duplicate stub override of replay-session is added later in the same file printing a Pro License message. A new swarm command is added. BFTConsensusEngine is re-exported from the orchestration package, and an optional-dependency guard is added to one protocol test.

Changes

CLI and Orchestration

Layer / File(s) Summary
replay-session and swarm CLI commands
agentwatch/cli/main.py
Removes the old replay command (local JSON file, speed/range/filter options) and replaces it with a replay-session command performing a rollback-based rewind. Adds a swarm command that reads a config file and prints agent initialization. A second replay-session definition at line 1527 overrides the first with a non-functional stub that only prints a Pro License validation and a mock resume message.
BFTConsensusEngine export and test wiring
agentwatch/orchestration/__init__.py, tests/test_multiagent.py, tests/test_protocol.py
Adds a wildcard import of bft_consensus into the orchestration package __init__, imports BFTConsensusEngine in the multiagent test file, and adds pytest.importorskip("mcp") to skip the FastMCP test when mcp is not installed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

Hard, SSoC26

Poem

🐇 Hoppity-hop through the session trail,
A rollback engine to rewind without fail!
The swarm of agents now springs to life,
BFT consensus cuts through the strife.
With a Pro License stamp and a mock resume,
This rabbit leaps forward — no time to presume! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title references 'replay' command but the implementation changes it to 'replay-session', creating a discrepancy between the title and actual implementation. Update the PR title to 'feat: Pro: Add agentwatch replay-session command to rewind and resume failed agent sessions' to match the implemented command name.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR implements the core requirements: replay-session command with session-id and step parameters, Pro tier gating, and integration with checkpoint data for session restoration.
Out of Scope Changes check ✅ Passed All changes are in-scope: CLI command implementation, module exports for BFT consensus, and test dependency handling for optional MCP dependency align with issue requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

🧪 PR Test Results

Check Result
Tests (pytest tests/) ❌ failure
Lint (ruff check .) ❌ failure
Coverage (agentwatch) n/a

Python 3.12 · commit e4d3a61

@SHAURYASANYAL3 SHAURYASANYAL3 changed the title Fixes #416: Add replay command feat: Pro: Add agentwatch replay command to rewind and resume failed agent sessions Jun 18, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@agentwatch/cli/main.py`:
- Around line 1527-1538: The replay_session command is defined twice with the
same decorator name "replay-session", and the second definition is overriding
the first functional implementation that calls RollbackEngine.rollback_session.
Either remove the duplicate replay_session function definition entirely to
restore the working implementation, or if Pro license gating is intended, merge
the license validation check (the console.print statements for validating Pro
License) into the original replay_session implementation instead of replacing
the entire function. Later command registrations in Typer override earlier ones,
so duplicates must be consolidated.
- Around line 384-389: The json.load() call when reading the config file does
not handle the case where the file contains invalid JSON, which will raise
json.JSONDecodeError without a user-friendly message. Wrap the json.load(f)
statement in a try-except block to catch json.JSONDecodeError, then use
console.print() to display a user-friendly error message (similar to the
existing message for missing config file) and raise typer.Exit(1) to terminate
gracefully. This should be placed after the file existence check and within the
context manager.

In `@agentwatch/orchestration/__init__.py`:
- Line 1: The import statement `from agentwatch.orchestration.bft_consensus
import *` in the __init__.py file references a module that does not exist,
causing the entire orchestration package initialization to fail. Either create
the missing bft_consensus.py module in the agentwatch/orchestration directory
with appropriate implementation, or remove the import statement from the
__init__.py file until the bft_consensus module is ready to be implemented.
Choose whichever approach aligns with your development timeline and module
architecture.

In `@tests/test_multiagent.py`:
- Line 8: The import statement importing BFTConsensusEngine from
agentwatch.orchestration.bft_consensus will fail because this module does not
exist yet, causing the entire test file to fail during collection. Either remove
or comment out the import line that imports BFTConsensusEngine from
agentwatch.orchestration.bft_consensus until the bft_consensus module is created
and available, or add the missing bft_consensus module with the
BFTConsensusEngine class to the agentwatch.orchestration package.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1937a04b-e51c-4cfd-ad98-58dfed351029

📥 Commits

Reviewing files that changed from the base of the PR and between 19bbbeb and 12615b4.

📒 Files selected for processing (4)
  • agentwatch/cli/main.py
  • agentwatch/orchestration/__init__.py
  • tests/test_multiagent.py
  • tests/test_protocol.py

Comment thread agentwatch/cli/main.py Outdated
Comment thread agentwatch/cli/main.py Outdated
@@ -1 +1,2 @@
from agentwatch.orchestration.bft_consensus import *

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.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Import fails—module does not exist.

The pipeline failures confirm that agentwatch.orchestration.bft_consensus raises ModuleNotFoundError. This breaks the entire package initializer, causing all imports from agentwatch.orchestration to fail.

Either add the missing bft_consensus.py module or remove this import until the module is implemented.

🧰 Tools
🪛 GitHub Actions: PR Tests / 0_Test & lint.txt

[error] 1-1: Import error in package initialization: from 'agentwatch.orchestration.bft_consensus' import * failed with ModuleNotFoundError.

🪛 GitHub Actions: PR Tests / Test & lint

[error] 1-1: Import failure in package initializer: 'from agentwatch.orchestration.bft_consensus import *' raises ModuleNotFoundError for 'agentwatch.orchestration.bft_consensus'.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@agentwatch/orchestration/__init__.py` at line 1, The import statement `from
agentwatch.orchestration.bft_consensus import *` in the __init__.py file
references a module that does not exist, causing the entire orchestration
package initialization to fail. Either create the missing bft_consensus.py
module in the agentwatch/orchestration directory with appropriate
implementation, or remove the import statement from the __init__.py file until
the bft_consensus module is ready to be implemented. Choose whichever approach
aligns with your development timeline and module architecture.

Source: Pipeline failures

Comment thread tests/test_multiagent.py
import pytest

from agentwatch.core.event_bus import EventBus
from agentwatch.orchestration.bft_consensus import BFTConsensusEngine

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.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Import will fail—module does not exist.

This import of BFTConsensusEngine from agentwatch.orchestration.bft_consensus will fail with ModuleNotFoundError since the module does not exist (as confirmed by pipeline failures on the package initializer). The entire test file will fail to collect.

This is blocked until the bft_consensus module is added or this import is removed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_multiagent.py` at line 8, The import statement importing
BFTConsensusEngine from agentwatch.orchestration.bft_consensus will fail because
this module does not exist yet, causing the entire test file to fail during
collection. Either remove or comment out the import line that imports
BFTConsensusEngine from agentwatch.orchestration.bft_consensus until the
bft_consensus module is created and available, or add the missing bft_consensus
module with the BFTConsensusEngine class to the agentwatch.orchestration
package.

Source: Pipeline failures

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.

Pro: Add agentwatch replay command to rewind and resume failed agent sessions

1 participant