Skip to content

refactor: isolate core session runtime state - #138

Merged
github-actions[bot] merged 1 commit into
mainfrom
refactor/core-lifecycle
Aug 2, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
refactor/core-lifecycle

Conversation

@mohitranka

@mohitranka mohitranka commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Extract per-turn bookkeeping into TurnState.
  • Encapsulate queue, background tasks, receivers, and subagent HITL channels in TaskRuntime.
  • Extract multi-step turn execution into TurnCoordinator.
  • Add a SessionPersistence boundary around the durable journal.
  • Update TUI call sites to use session accessors.

Validation

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo test -p forge-core --lib --locked
  • cargo test --workspace --all-targets --locked
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Added session controls for viewing queued work and background tasks, including background-task cancellation.
    • Improved orchestration of agent turns, including human-input pauses, continuation, turn limits, and failure handling.
  • Bug Fixes

    • Preserved reliable handling of orphaned shell tasks, task completion, human-input updates, and malformed task dispatches.
  • Refactor

    • Consolidated session state management while preserving existing behavior across the terminal interface and background task workflows.

@github-actions
github-actions Bot enabled auto-merge (squash) August 2, 2026 10:36
@coderabbitai

coderabbitai Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6a6ac22d-1ce8-4030-b676-aea41222fa40

📥 Commits

Reviewing files that changed from the base of the PR and between 1b8bb52 and 637af86.

📒 Files selected for processing (14)
  • crates/forge-core/src/background.rs
  • crates/forge-core/src/lib.rs
  • crates/forge-core/src/persistence.rs
  • crates/forge-core/src/resume.rs
  • crates/forge-core/src/subagent.rs
  • crates/forge-core/src/task_runtime.rs
  • crates/forge-core/src/turn.rs
  • crates/forge-core/src/turn_state.rs
  • crates/forge-tui/src/app/input.rs
  • crates/forge-tui/src/app/render.rs
  • crates/forge-tui/src/app/tests/commands.rs
  • crates/forge-tui/src/app/tests/edge.rs
  • crates/forge-tui/src/app/tests/tasks.rs
  • crates/forge-tui/src/app/turn.rs

📝 Walkthrough

Walkthrough

AgentSession now encapsulates persistence, task runtime, and turn state. Turn execution uses TurnCoordinator. Background tasks, subagents, and TUI code use the new runtime accessors.

Changes

Session runtime encapsulation

Layer / File(s) Summary
Runtime boundaries and session wiring
crates/forge-core/src/{lib.rs,persistence.rs,task_runtime.rs}
Session persistence, task storage, queue operations, accessors, and cancellation wiring now use dedicated runtime types.
Turn state and coordination
crates/forge-core/src/{lib.rs,turn.rs,turn_state.rs,resume.rs}
Turn-local bookkeeping and model-turn execution now use TurnState and TurnCoordinator.
Background tasks and subagents
crates/forge-core/src/{background.rs,subagent.rs}
Shell-task polling, orphan reconciliation, HITL routing, and subagent lifecycle handling now use TaskRuntime.
TUI runtime access
crates/forge-tui/src/app/*
Queue and background-task reads and cancellation now use AgentSession accessors.

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

Sequence Diagram(s)

sequenceDiagram
  participant AgentSession
  participant TurnCoordinator
  participant Model
  AgentSession->>TurnCoordinator: run(session, stream_tx)
  TurnCoordinator->>Model: execute streamed model step
  Model-->>TurnCoordinator: model response
  TurnCoordinator-->>AgentSession: completed or HITL response
Loading
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/core-lifecycle

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

@github-actions
github-actions Bot merged commit 7d7978c into main Aug 2, 2026
6 checks passed
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