Skip to content

feat(session): /fork — branch a session, preserving the original - #418

Merged
jexShain merged 1 commit into
AI-Shell-Team:mainfrom
jexShain:feat/fork-session
Jul 29, 2026
Merged

feat(session): /fork — branch a session, preserving the original#418
jexShain merged 1 commit into
AI-Shell-Team:mainfrom
jexShain:feat/fork-session

Conversation

@jexShain

@jexShain jexShain commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds the /fork built-in command: branch the current session into a new one (copied context), then switch into the fork so the original is preserved at its branch point.

Closes #413

What it does

  • Persists the current snapshot, then fork_session copies the parent's state + metadata into a new session, recording parent_session_uuid + branch_point_message_id, and switches into it.

Data layer (aish-session)

  • SessionRecord gains parent_session_uuid + branch_point_message_id.
  • fork_session / session_roots / list_children; migrate_schema adds the columns additively (idempotent, backward compatible with legacy DBs).
  • delete_session reparents children to root (clearing the dangling branch point) so deleting a forked parent never orphans its descendants.

Scope

Reuses the existing persist_session_snapshot + resume_session_with_options. Self-contained to aish-session (store + models) + the /fork command in aish-shell + i18n.

/sessions (the tree browser) builds on this data layer and will follow in a separate PR.

Verification

  • cargo clippy -p aish-session -p aish-shell --all-targets -- -D warnings clean.
  • aish-session tests pass (9), including fork_session_*, list_children_*, migrate_schema_*, delete_session_reparents_children_to_root.
  • slash_popup_commands tests pass.

Summary by CodeRabbit

  • New Features

    • Added a /fork slash command to branch the current session into a new session while preserving context.
    • The app automatically switches to the forked session and shows success/failure outcomes, including manual resume guidance if switching fails.
    • Added session forking support with parent/branch-point tracking and updated localized UI strings (EN, DE, ES, FR, JA, ZH).
  • Bug Fixes

    • Added automatic compatibility migration for existing session databases.
    • Prevented deleted sessions from leaving invalid branch references (child sessions are safely re-linked).

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the pull request. A maintainer will review it when available.

Please keep the PR focused, explain the why in the description, and make sure local checks pass before requesting review.

Contribution guide: https://github.com/AI-Shell-Team/aish/blob/main/CONTRIBUTING.md

@github-actions

Copy link
Copy Markdown
Contributor

This pull request description looks incomplete. Please update the missing sections below before review.

Missing items:

  • User-visible Changes
  • Compatibility
  • Testing
  • Change Type
  • Scope

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 5 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 51311cf4-a663-48a2-a7c9-8a5da74a13b6

📥 Commits

Reviewing files that changed from the base of the PR and between 004cce6 and bedcd67.

📒 Files selected for processing (11)
  • crates/aish-i18n/locales/de-DE.yaml
  • crates/aish-i18n/locales/en-US.yaml
  • crates/aish-i18n/locales/es-ES.yaml
  • crates/aish-i18n/locales/fr-FR.yaml
  • crates/aish-i18n/locales/ja-JP.yaml
  • crates/aish-i18n/locales/zh-CN.yaml
  • crates/aish-session/src/models.rs
  • crates/aish-session/src/store.rs
  • crates/aish-shell/src/app.rs
  • crates/aish-shell/src/readline.rs
  • crates/aish-shell/tests/slash_popup_commands.rs
📝 Walkthrough

Walkthrough

Adds session lineage metadata and SQLite hierarchy APIs, introduces /fork to copy and switch sessions, updates slash-command completion and tests, and provides fork-related localization strings across supported locales.

Changes

Session forking

Layer / File(s) Summary
Session lineage schema and compatibility
crates/aish-session/src/models.rs, crates/aish-session/src/store.rs
SessionRecord and the SQLite schema now store optional parent-session and branch-point metadata, with additive migration support for legacy databases.
Fork persistence and hierarchy queries
crates/aish-session/src/store.rs
Session lookup mapping, child creation, root/child queries, deletion reparenting, and tests for copying, ordering, errors, and migration are added.
Shell command and localized outcomes
crates/aish-shell/..., crates/aish-i18n/locales/*
/fork persists and forks the active session, resumes the new session, updates slash-command counts, and adds localized command and result messages.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AishShell
  participant SessionStore
  participant ResumeFlow
  AishShell->>AishShell: Persist current session snapshot
  AishShell->>SessionStore: fork_session(parent_uuid, branch_point_message_id, new_uuid)
  SessionStore-->>AishShell: Return forked session
  AishShell->>ResumeFlow: resume_session_with_options(new_uuid)
  ResumeFlow-->>AishShell: Return switch result
Loading

Possibly related PRs

Suggested reviewers: f16shen

Poem

I’m a rabbit with branches to spare,
Forking a session with careful care.
Old paths remain, new trails begin,
Context hops where choices spin.
/fork makes a fresh burrow bright—
Hop back anytime, day or night!

🚥 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 summarizes the main change: adding /fork session branching while preserving the original session.
Linked Issues check ✅ Passed The PR matches #413 by adding /fork, preserving context and state, recording parent/branch metadata, migrating schema, and reparenting children on delete.
Out of Scope Changes check ✅ Passed The changes appear scoped to the fork feature, supporting i18n, tests, and session-tree plumbing needed for the linked requirements.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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 `@crates/aish-shell/src/app.rs`:
- Line 3356: Update handle_fork_command to fetch the parent’s latest history row
via store.get_history(&parent_uuid, 1), use the first entry’s entry.id as the
branch point, and pass it to store.fork_session instead of None; return None
when the history is empty, and do not use entry.history_entry_id.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 155523a5-4f56-42c9-b586-316de701508a

📥 Commits

Reviewing files that changed from the base of the PR and between 78117a9 and c70ad16.

📒 Files selected for processing (11)
  • crates/aish-i18n/locales/de-DE.yaml
  • crates/aish-i18n/locales/en-US.yaml
  • crates/aish-i18n/locales/es-ES.yaml
  • crates/aish-i18n/locales/fr-FR.yaml
  • crates/aish-i18n/locales/ja-JP.yaml
  • crates/aish-i18n/locales/zh-CN.yaml
  • crates/aish-session/src/models.rs
  • crates/aish-session/src/store.rs
  • crates/aish-shell/src/app.rs
  • crates/aish-shell/src/readline.rs
  • crates/aish-shell/tests/slash_popup_commands.rs

Comment thread crates/aish-shell/src/app.rs
`/fork` branches the current session into a new one that copies the parent's
context/state, records the parent link + branch point, and switches into the
fork so the original is preserved at its branch point.

Data layer (aish-session):
- SessionRecord gains parent_session_uuid + branch_point_message_id.
- fork_session copies the parent's state + metadata; session_roots /
  list_children expose the tree; migrate_schema adds the columns additively
  (backward compatible with legacy DBs).
- delete_session reparents children to root (clearing the dangling branch
  point) so deleting a forked parent never orphans its descendants.

Reuses the existing persist_session_snapshot + resume path.

Closes AI-Shell-Team#413
@jexShain
jexShain force-pushed the feat/fork-session branch from 618caea to bedcd67 Compare July 29, 2026 08:49
@jexShain
jexShain merged commit 5fec9f6 into AI-Shell-Team:main Jul 29, 2026
7 checks passed
@jexShain
jexShain deleted the feat/fork-session branch July 29, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: /fork 从当前会话分叉新会话

1 participant