Skip to content

feat(cli): support session forking and history loading in CLI#20

Open
srimon12 wants to merge 3 commits into
AstraBert:mainfrom
srimon12:feat/cli-session-fork
Open

feat(cli): support session forking and history loading in CLI#20
srimon12 wants to merge 3 commits into
AstraBert:mainfrom
srimon12:feat/cli-session-fork

Conversation

@srimon12

@srimon12 srimon12 commented Jun 29, 2026

Copy link
Copy Markdown

Adds a --fork <session_id> CLI flag to allow initializing a new session from an existing parent session's history.

This copies events from the specified parent session to the new child session on startup and records a SessionFork event.

Key Changes:

  • Added a --fork option to CLI arguments.
  • Pre-populates the new session's event history with the parent session's events from the backend store on initialization.

Summary by CodeRabbit

  • New Features

    • Added a new --fork option to clone an existing session into a fresh session ID.
    • When used without other input, the app now confirms the cloned session ID and exits cleanly.
    • The TUI now starts from the cloned session when forking is used.
  • Bug Fixes

    • Prevents creating a fork from an empty session.
    • Ensures the copied session history is preserved under the new session ID before continuing.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@srimon12, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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 reviews.

How do review limits work?

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

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, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: afdd7d32-1a70-44e0-9086-0174551723a3

📥 Commits

Reviewing files that changed from the base of the PR and between 34c9ab8 and 09bd1ef.

📒 Files selected for processing (2)
  • microagents-cli/src/main.rs
  • microagents-events/src/lib.rs
📝 Walkthrough

Walkthrough

Adds a --fork <ID> CLI flag to microagents-cli. A new fork_session async function clones a parent session's events into a new UUID-backed session. main computes a resolved_session_id from either the fork result or --session-id, and both the headless and TUI paths use this resolved ID.

Fork Session Feature

Layer / File(s) Summary
--fork arg, fork_session helper, and resolved_session_id wiring
microagents-cli/src/main.rs
Args gains fork: Option<String> for --fork <ID>; fork_session loads parent session events, rejects empty sessions, generates a new UUID, and writes cloned events; main derives resolved_session_id from the fork or --session-id, prints and exits if only forking, and passes the resolved ID to both headless and TUI run paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hop! A session splits in two,
The past is cloned, the future new.
A UUID born from one before,
Fork and run — then run some more.
What once was lost can start again,
Down the rabbit hole... and then! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding CLI session forking and loading prior session history.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@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: 2

🤖 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 `@microagents-cli/src/main.rs`:
- Around line 140-156: The fork flow in main currently clones parent events and
returns the new session id, but it never persists the SessionFork marker event.
After the child session is created in the event replay loop, add a write for the
SessionFork event through storage so the lineage is recorded distinctly from a
normal resumed session. Use the existing session-writing path in main alongside
the SessionInit and other event handling to place this marker at the right point
in the fork process.
- Around line 163-169: The forked startup logic in main.rs is treating
`--session-id` as the only way to continue into the TUI after `fork_session`,
which makes plain `--fork <parent>` exit early unless an unrelated value is
passed. Update the `resolved_session_id` handling so the forked TUI path uses
`Some(new_sid)` when `args.fork` is present and no prompt is provided, and
reserve the early return only for an explicit clone-only mode if you add one.
Keep the fix centered on `fork_session`, `resolved_session_id`, and the
`args.prompt` / `args.session_id` branch.
🪄 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: 8d1dc15b-0b86-4d31-acde-a6eaaebc6a2f

📥 Commits

Reviewing files that changed from the base of the PR and between a5408c9 and 34c9ab8.

📒 Files selected for processing (1)
  • microagents-cli/src/main.rs

Comment thread microagents-cli/src/main.rs
Comment thread microagents-cli/src/main.rs
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