Skip to content

refactor(session): extract application coordinators#1961

Merged
zerob13 merged 31 commits into
devfrom
task/session-application-coordinators
Jul 13, 2026
Merged

refactor(session): extract application coordinators#1961
zerob13 merged 31 commits into
devfrom
task/session-application-coordinators

Conversation

@zerob13

@zerob13 zerob13 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • extract session lifecycle, turn, agent-assignment, and projection behavior into four composition-owned coordinators
  • inject consumer-owned narrow ports into SessionService, ChatService, Remote, and Cron
  • keep AgentSessionPresenter as a compatibility façade whose migrated core methods only forward
  • move Cron session-starter wiring into the composition root and remove route-runtime priming
  • preserve Stage 1 foreign capability owners while integrating the coordinator boundary
  • add characterization coverage, architecture guards, maintained documentation, and refreshed baselines

Why

AgentSessionPresenter combined unrelated application transactions, policies, projection state, and consumer wiring behind one broad contract. This made ownership unclear and let typed routes, Remote, and Cron depend on substantially more behavior than they used.

The new coordinators make those ownership boundaries explicit while preserving existing route, event, persistence, DeepChat, direct-ACP, Remote, and Cron behavior.

Integration

Validation

  • focused coordinator/service/route/Remote/Cron integration suite: 408 passed, 15 skipped
  • architecture Guard suite: 60 passed
  • pnpm run format
  • pnpm run i18n — 0 missing, 0 invalid
  • pnpm run lint
  • pnpm run typecheck — node and web
  • pnpm run test:main — 3980 passed, 198 skipped
  • pnpm run test:renderer — 1257 passed
  • pnpm run lint:architecture
  • git diff --check
  • independent acceptance review: AC1–AC11 passed with no P1/P2/P3 findings

Notes

  • the branch adds no skipped tests
  • the PR remains a draft

Summary by CodeRabbit

  • New Features

    • Added dedicated session coordination across lifecycle, turn messaging, assignment, and projection, now used by session creation/restore, remote control, and scheduled (cron) runs.
  • Bug Fixes

    • Improved session title generation behavior, message/pending input handling, and rollback/cleanup ordering.
    • Strengthened tool interaction permission checks (including ACP scenarios).
    • More reliable session deletion and transfer/ACP configuration flows, with safer session projection updates.
  • Documentation

    • Updated architecture and flow diagrams, navigation guides, and baseline/guard documentation to match the new session pipeline.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a899d442-e9e4-45fa-9204-68b224227d05

📥 Commits

Reviewing files that changed from the base of the PR and between 7976a37 and b4dd7ec.

📒 Files selected for processing (3)
  • docs/FLOWS.md
  • src/main/presenter/sessionApplication/lifecycleCoordinator.ts
  • test/main/presenter/sessionApplication/agentAssignmentCoordinator.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • test/main/presenter/sessionApplication/agentAssignmentCoordinator.test.ts
  • docs/FLOWS.md
  • src/main/presenter/sessionApplication/lifecycleCoordinator.ts

📝 Walkthrough

Walkthrough

This PR extracts session lifecycle, turn, assignment, and projection behavior into session-application coordinators and typed ports. AgentSessionPresenter becomes a compatibility-forwarding façade, while Session, Chat, Remote, Cron, architecture guards, normalization helpers, tests, and documentation are updated.

Changes

Session application migration

Layer / File(s) Summary
Architecture contracts and documentation
docs/architecture/**, docs/guides/**, docs/ARCHITECTURE.md, docs/FLOWS.md
Documentation defines coordinator ownership, presenter compatibility forwarding, consumer-owned ports, migration tasks, and updated architecture baselines.
Architecture enforcement and input normalization
scripts/architecture-guard.mjs, src/main/agent/shared/agentSessionNormalization.ts
AST checks enforce session dependency boundaries and combined-facade restrictions; shared helpers normalize tools, skills, and message inputs.
Coordinator ports and implementation
src/main/presenter/sessionApplication/**
New ports and coordinators implement projection, turn, assignment, lifecycle, transfer, runtime initialization, deletion, ACP handling, and cleanup ordering.
Composition and consumer rewiring
src/main/presenter/index.ts, src/main/routes/**, src/main/presenter/remoteControlPresenter/**, src/main/presenter/cronJobs/**
The composition root creates shared coordinators; SessionService, ChatService, Remote, Cron, and route runtime consume specialized ports.
Validation and integration tests
test/main/**
Tests cover coordinator behavior, rollback and ordering semantics, route and consumer wiring, Cron and Remote flows, ACP handling, and architecture guard rules.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SessionService
  participant ChatService
  participant SessionApplication
  participant AgentManager
  participant TypedBackend
  SessionService->>SessionApplication: create or restore session
  ChatService->>SessionApplication: send, steer, or cancel turn
  SessionApplication->>AgentManager: resolve agent kind and session handle
  AgentManager->>TypedBackend: execute lifecycle or turn operation
  TypedBackend-->>SessionApplication: runtime state or operation result
  SessionApplication-->>SessionService: projected session response
  SessionApplication-->>ChatService: turn result
Loading

Possibly related PRs

Suggested reviewers: zhangmo8

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately captures the main change: extracting session application coordinators.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/session-application-coordinators

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.

@zerob13 zerob13 marked this pull request as ready for review July 13, 2026 14:13

@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

🧹 Nitpick comments (2)
test/main/presenter/sessionApplication/agentAssignmentCoordinator.test.ts (1)

244-272: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Preflight-count coupling is brittle but likely intentional for this characterization suite.

The induced-failure trigger (resolveTransferTarget.mock.calls.length > 2) pins the exact number of preflight calls rather than asserting on arguments. Fine for pinning current ordering behavior, but any future preflight-call-count change (even a behavior-preserving one) would break this test for an unrelated reason.

🤖 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 `@test/main/presenter/sessionApplication/agentAssignmentCoordinator.test.ts`
around lines 244 - 272, Update the failure trigger in the preflight test around
moveAgentSessions to depend on the resolveTransferTarget call arguments or
relevant session/project identity instead of mock.calls.length. Preserve the
intended behavior: one batch entry should fail during preflight before
setSessionAgentContext or updateAgentId is invoked.
src/main/presenter/sessionApplication/lifecycleCoordinator.ts (1)

484-489: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Route warnings through @shared/logger instead of console.warn. These coordinators emit info logs via the app logger but drop warning-level diagnostics onto console.warn, so failures bypass the app's log sinks/formatting and are easily lost in production.

  • src/main/presenter/sessionApplication/lifecycleCoordinator.ts#L484-L489: replace the console.warn cleanup-failure logs (also at L270, L383, L424) with logger.warn.
  • src/main/presenter/sessionApplication/agentAssignmentCoordinator.ts#L426-L433: import @shared/logger and replace the console.warn calls (also at L463, L473, L561, L570) with logger.warn.
🤖 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 `@src/main/presenter/sessionApplication/lifecycleCoordinator.ts` around lines
484 - 489, Replace all specified console.warn calls in lifecycleCoordinator.ts
(lines 270, 383, 424, and 484-489) with the shared logger.warn while preserving
their messages and error arguments. In agentAssignmentCoordinator.ts (lines
426-433, 463, 473, 561, and 570), import `@shared/logger` and route each
corresponding warning through logger.warn instead of console.warn.
🤖 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 `@docs/FLOWS.md`:
- Around line 157-158: Rename the new Mermaid node id in the section 5 flowchart
from Compat to a unique identifier, updating its incoming and outgoing edges
while preserving the existing label and connections. Leave the pre-existing
Compat node used by the Provider acp branch unchanged.

In `@src/main/presenter/sessionApplication/lifecycleCoordinator.ts`:
- Around line 66-78: Update the session-created log in createSession to remove
the user-derived title from its message, while retaining sessionId for
correlation. Leave title generation and session creation unchanged.

---

Nitpick comments:
In `@src/main/presenter/sessionApplication/lifecycleCoordinator.ts`:
- Around line 484-489: Replace all specified console.warn calls in
lifecycleCoordinator.ts (lines 270, 383, 424, and 484-489) with the shared
logger.warn while preserving their messages and error arguments. In
agentAssignmentCoordinator.ts (lines 426-433, 463, 473, 561, and 570), import
`@shared/logger` and route each corresponding warning through logger.warn instead
of console.warn.

In `@test/main/presenter/sessionApplication/agentAssignmentCoordinator.test.ts`:
- Around line 244-272: Update the failure trigger in the preflight test around
moveAgentSessions to depend on the resolveTransferTarget call arguments or
relevant session/project identity instead of mock.calls.length. Preserve the
intended behavior: one batch entry should fail during preflight before
setSessionAgentContext or updateAgentId is invoked.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 64193fe8-71be-4024-8eb8-39322a0f8f5f

📥 Commits

Reviewing files that changed from the base of the PR and between 1357792 and 7976a37.

📒 Files selected for processing (58)
  • docs/ARCHITECTURE.md
  • docs/FLOWS.md
  • docs/README.md
  • docs/architecture/agent-system-layered-runtime/README.md
  • docs/architecture/agent-system.md
  • docs/architecture/baselines/agent-system-layered-runtime-baseline.json
  • docs/architecture/baselines/dependency-report.md
  • docs/architecture/baselines/main-kernel-boundary-baseline.md
  • docs/architecture/baselines/main-kernel-migration-scoreboard.json
  • docs/architecture/baselines/main-kernel-migration-scoreboard.md
  • docs/architecture/session-application-coordinators/plan.md
  • docs/architecture/session-application-coordinators/spec.md
  • docs/architecture/session-application-coordinators/tasks.md
  • docs/architecture/session-boundary-cleanup/spec.md
  • docs/architecture/session-management.md
  • docs/guides/code-navigation.md
  • docs/guides/getting-started.md
  • scripts/architecture-guard.mjs
  • src/main/agent/shared/agentSessionNormalization.ts
  • src/main/presenter/agentSessionPresenter/index.ts
  • src/main/presenter/cronJobs/index.ts
  • src/main/presenter/cronJobs/runSessionStarter.ts
  • src/main/presenter/index.ts
  • src/main/presenter/lifecyclePresenter/hooks/after-start/cronJobsStartHook.ts
  • src/main/presenter/remoteControlPresenter/index.ts
  • src/main/presenter/remoteControlPresenter/interface.ts
  • src/main/presenter/remoteControlPresenter/services/remoteConversationRunner.ts
  • src/main/presenter/sessionApplication/agentAssignmentCoordinator.ts
  • src/main/presenter/sessionApplication/agentAssignmentPolicy.ts
  • src/main/presenter/sessionApplication/lifecycleCoordinator.ts
  • src/main/presenter/sessionApplication/lifecycleDeletionTransaction.ts
  • src/main/presenter/sessionApplication/ports.ts
  • src/main/presenter/sessionApplication/projectionCoordinator.ts
  • src/main/presenter/sessionApplication/turnCoordinator.ts
  • src/main/routes/chat/chatService.ts
  • src/main/routes/hotPathPorts.ts
  • src/main/routes/index.ts
  • src/main/routes/sessions/sessionService.ts
  • test/main/agent/manager/directAcpAgentBackend.test.ts
  • test/main/presenter/agentSessionPresenter/agentSessionPresenter.test.ts
  • test/main/presenter/agentSessionPresenter/assignmentCoordinatorFixture.ts
  • test/main/presenter/agentSessionPresenter/integration.test.ts
  • test/main/presenter/agentSessionPresenter/projectionCoordinatorFixture.ts
  • test/main/presenter/cronJobRunSessionStarter.test.ts
  • test/main/presenter/cronJobs.test.ts
  • test/main/presenter/lifecyclePresenter/hooks/after-start/cronJobsStartHook.test.ts
  • test/main/presenter/remoteControlPresenter/remoteControlPresenter.test.ts
  • test/main/presenter/remoteControlPresenter/remoteConversationRunner.test.ts
  • test/main/presenter/sessionApplication/agentAssignmentCoordinator.test.ts
  • test/main/presenter/sessionApplication/agentAssignmentPolicy.test.ts
  • test/main/presenter/sessionApplication/lifecycleCoordinator.test.ts
  • test/main/presenter/sessionApplication/lifecycleDeletionTransaction.test.ts
  • test/main/presenter/sessionApplication/projectionCoordinator.test.ts
  • test/main/presenter/sessionApplication/turnCoordinator.test.ts
  • test/main/routes/chatService.test.ts
  • test/main/routes/dispatcher.test.ts
  • test/main/routes/sessionService.test.ts
  • test/main/scripts/architectureGuard.test.ts

Comment thread docs/FLOWS.md Outdated
Comment thread src/main/presenter/sessionApplication/lifecycleCoordinator.ts Outdated
@zerob13 zerob13 merged commit e55ff59 into dev Jul 13, 2026
4 checks passed
@zhangmo8 zhangmo8 deleted the task/session-application-coordinators branch July 14, 2026 05:24
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