refactor(session): split boundary owners - #1957
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe PR narrows ChangesSession boundary cleanup
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Renderer
participant MainKernelRouteRuntime
participant SessionOwner
participant SQLitePresenter
Renderer->>MainKernelRouteRuntime: invoke typed session route
MainKernelRouteRuntime->>SessionOwner: delegate search, translation, export, or dashboard
SessionOwner->>SQLitePresenter: read session, transcript, or usage data
SQLitePresenter-->>SessionOwner: return persisted data
SessionOwner-->>Renderer: return typed result
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/presenter/usageStatsService.ts (1)
210-220: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winFallback path re-fetches and re-sorts the full candidate set on every page.
When
listAssistantUsageCandidatesPageis absent, each iteration of therunBackfillwhileloop callslistAssistantUsageCandidates()(all rows) and re-sorts them, giving roughly O(n²·log n) work over the backfill. Sort once outside the loop (or cache the sorted array) and page against it.🤖 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/usageStatsService.ts` around lines 210 - 220, Update the fallback pagination flow used by runBackfill so listAssistantUsageCandidates() is fetched and sorted only once outside the while loop, then reuse the cached sorted candidates for each cursor page. Preserve the existing created_at/id ordering, cursor filtering, and limit behavior.
🤖 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 `@src/main/agent/shared/assistantModelSelection.ts`:
- Line 13: Update the backend check in the assistant model selection flow to
safely handle optional or unknown agentId values before accessing .kind on
resolveBackend(). Fall back to the default translation model when
agentManager.resolveBackend(agentId) cannot resolve a backend, while preserving
deepchat-specific model selection for valid backends.
---
Nitpick comments:
In `@src/main/presenter/usageStatsService.ts`:
- Around line 210-220: Update the fallback pagination flow used by runBackfill
so listAssistantUsageCandidates() is fetched and sorted only once outside the
while loop, then reuse the cached sorted candidates for each cursor page.
Preserve the existing created_at/id ordering, cursor filtering, and limit
behavior.
🪄 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: 89aa0e2a-db8f-4211-9e40-39e538640e6a
📒 Files selected for processing (51)
docs/ARCHITECTURE.mddocs/FLOWS.mddocs/architecture/agent-system-layered-runtime/README.mddocs/architecture/agent-system.mddocs/architecture/baselines/agent-system-layered-runtime-baseline.jsondocs/architecture/baselines/dependency-report.mddocs/architecture/baselines/main-kernel-boundary-baseline.mddocs/architecture/baselines/main-kernel-migration-scoreboard.jsondocs/architecture/baselines/main-kernel-migration-scoreboard.mddocs/architecture/session-boundary-cleanup/plan.mddocs/architecture/session-boundary-cleanup/spec.mddocs/architecture/session-boundary-cleanup/tasks.mddocs/architecture/session-management.mddocs/guides/code-navigation.mddocs/guides/getting-started.mdscripts/architecture-guard.mjssrc/main/agent/shared/assistantModelSelection.tssrc/main/agent/shared/availableAgentCatalog.tssrc/main/presenter/agentSessionPresenter/index.tssrc/main/presenter/exporter/agentSessionExporter.tssrc/main/presenter/floatingButtonPresenter/index.tssrc/main/presenter/index.tssrc/main/presenter/lifecyclePresenter/hooks/after-start/disabledSearchToolCleanupHook.tssrc/main/presenter/lifecyclePresenter/hooks/after-start/legacyImportHook.tssrc/main/presenter/lifecyclePresenter/hooks/after-start/rtkHealthCheckHook.tssrc/main/presenter/lifecyclePresenter/hooks/after-start/sqliteMainlineNormalizationHook.tssrc/main/presenter/lifecyclePresenter/hooks/after-start/usageStatsBackfillHook.tssrc/main/presenter/sqlitePresenter/index.tssrc/main/presenter/startupMigrations/legacyChatImportService.tssrc/main/presenter/startupMigrations/sessionDataMigrations.tssrc/main/presenter/usageStatsService.tssrc/main/routes/index.tssrc/main/routes/sessions/sessionHistorySearch.tssrc/main/routes/sessions/sessionTranslation.tssrc/renderer/src/stores/ui/spotlight.tssrc/shared/contracts/routes/sessions.routes.tssrc/shared/types/presenters/agent-session.presenter.d.tssrc/shared/types/presenters/index.d.tstest/main/agent/shared/availableAgentCatalog.test.tstest/main/presenter/agentSessionPresenter/agentSessionPresenter.test.tstest/main/presenter/exporter/agentSessionExporter.test.tstest/main/presenter/floatingButtonPresenter/index.test.tstest/main/presenter/lifecyclePresenter/startupMaintenanceHooks.test.tstest/main/presenter/sessionBoundaryComposition.test.tstest/main/presenter/startupMigrations/legacyChatImportService.test.tstest/main/presenter/startupMigrations/sessionDataMigrations.test.tstest/main/presenter/usageStatsService.test.tstest/main/routes/dispatcher.test.tstest/main/routes/sessions/sessionHistorySearch.test.tstest/main/routes/sessions/sessionTranslation.test.tstest/main/scripts/architectureGuard.test.ts
💤 Files with no reviewable changes (2)
- src/shared/types/presenters/agent-session.presenter.d.ts
- test/main/presenter/agentSessionPresenter/agentSessionPresenter.test.ts
Summary
AgentSessionPresenterWhy
AgentSessionPresenterremained a God Object after the layered runtime refactor. Unrelated route, migration, maintenance, export, and catalog policies still accumulated behind its public interface and startup hooks depended on unsafe presenter casts. This change establishes explicit ownership boundaries without changing route contracts or session behavior.Impact
AgentSessionPresenteris reduced from 4077 to 2636 linesValidation
pnpm run format/pnpm run format:checkpnpm run i18npnpm run lintpnpm run typecheckpnpm run test:main— 3753 passed, 194 skippedpnpm run lint:architecturepnpm run architecture:baselinegit diff --checkArchitecture cycle count remains 36 and DeepChat loop dependency metrics remain zero.
Summary by CodeRabbit