Skip to content

Optimize chat and mission summary scans#316

Merged
arul28 merged 1 commit into
mainfrom
ade/complexity-cleanup-20260517
May 17, 2026
Merged

Optimize chat and mission summary scans#316
arul28 merged 1 commit into
mainfrom
ade/complexity-cleanup-20260517

Conversation

@arul28
Copy link
Copy Markdown
Owner

@arul28 arul28 commented May 17, 2026

Summary

  • reduce chat turn-summary allocation and repeated scans
  • collapse mission progress summary filter/map passes into single scans
  • index fan-out completion lookups while preserving first-match behavior

Validation

  • npx vitest run src/renderer/components/chat/AgentChatMessageList.test.tsx src/main/services/orchestrator/orchestratorService.test.ts src/main/services/orchestrator/aiOrchestratorService.test.ts src/main/services/orchestrator/coordinatorTools.test.ts
  • npx vitest run src/renderer/components/chat/AgentChatMessageList.test.tsx
  • npx vitest run src/main/services/orchestrator/orchestratorService.test.ts
  • npm --prefix apps/desktop run typecheck
  • git diff --check
  • eslint on touched files: 0 errors, pre-existing warnings remain in orchestrator files

Summary by CodeRabbit

  • Refactor
    • Updated mission state computation logic across orchestrator services.
    • Improved task tracking data model in chat messages.
    • Simplified URL handling in chat interface.

Review Change Stack

Greptile Summary

Pure performance refactor replacing repeated filter/map/find passes with single-loop accumulations and a Map index across the orchestrator and chat layers. No behavioural changes are intended.

  • orchestratorService.ts: frontier step counts now computed in one loop; checkFanOutCompletion replaces per-child Array.find calls (O(n × m)) with a pre-built Map for O(1) lookups, including succeeded/failed tallying.
  • aiOrchestratorService.ts + coordinatorTools.ts: mission-state progress (completed, active, blocked, failed) collapsed from four independent filter passes into a single iteration over relevantSteps.
  • AgentChatMessageList.tsx: TurnSummary slimmed to integer counts (taskCount, completedTaskCount, changedFileCount), removing the per-file diff-stat and per-task detail arrays that were only ever consumed as aggregates; dead PlanStepIcon component and unused openExternalUrl import removed.

Confidence Score: 4/5

Safe to merge; all changes are equivalent rewrites of existing logic with no altered outputs.

Every loop replacement produces the same results as its predecessor. The only non-trivial subtlety is the first-match guard in the checkFanOutCompletion Map build, which correctly mirrors Array.find but would benefit from a short comment to protect against future edits.

The checkFanOutCompletion section of orchestratorService.ts is worth a quick read to confirm first-match Map behaviour matches expectations for duplicate step keys in the DB result set.

Important Files Changed

Filename Overview
apps/desktop/src/main/services/orchestrator/orchestratorService.ts Two optimizations: frontier counts consolidated from 5 separate filter passes into one loop; checkFanOutCompletion replaced 3 O(n) Array.find calls per child key with a single upfront Map build. First-match semantics are preserved but implicit.
apps/desktop/src/main/services/orchestrator/aiOrchestratorService.ts buildMissionStateProgressFromGraph consolidated from 4 filter/map passes into one loop. Semantics are identical to the original.
apps/desktop/src/main/services/orchestrator/coordinatorTools.ts buildMissionStateProgress consolidated from 4 filter/map passes into one loop, mirroring the change in aiOrchestratorService. No behavioral difference.
apps/desktop/src/renderer/components/chat/AgentChatMessageList.tsx TurnSummary simplified: per-task and per-file detail arrays replaced with integer counts; latestTurnId scan avoids array copy+reverse; dead PlanStepIcon component and unused openExternalUrl import removed.

Fix All in Claude Code

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/desktop/src/main/services/orchestrator/orchestratorService.ts:11367-11372
Adding a brief comment here would make the first-match intent explicit and prevent a well-meaning refactor from accidentally switching to last-match semantics.

```suggestion
      // Build index keyed by stepKey; keep the first occurrence to match prior Array.find semantics.
      const stepByKey = new Map<string, OrchestratorStep>();
      for (const step of allSteps) {
        if (!stepByKey.has(step.stepKey)) {
          stepByKey.set(step.stepKey, step);
        }
      }
```

Reviews (1): Last reviewed commit: "Optimize chat and mission summary scans" | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ade Ignored Ignored May 17, 2026 11:20pm

@arul28 arul28 merged commit 339d012 into main May 17, 2026
10 of 11 checks passed
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 48ebcc6c-190c-4a8b-998a-8b91a9e6a32f

📥 Commits

Reviewing files that changed from the base of the PR and between 38130e5 and 0924d0e.

📒 Files selected for processing (4)
  • apps/desktop/src/main/services/orchestrator/aiOrchestratorService.ts
  • apps/desktop/src/main/services/orchestrator/coordinatorTools.ts
  • apps/desktop/src/main/services/orchestrator/orchestratorService.ts
  • apps/desktop/src/renderer/components/chat/AgentChatMessageList.tsx

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Walkthrough

This PR optimizes orchestrator service performance by consolidating multiple filter/map passes into single-pass loops, and refactors the chat message list's turn summary from array-based to count-based data representation, updating dependent UI wiring accordingly.

Changes

Orchestrator Service Performance Optimizations

Layer / File(s) Summary
Mission progress aggregation refactor
apps/desktop/src/main/services/orchestrator/aiOrchestratorService.ts, apps/desktop/src/main/services/orchestrator/coordinatorTools.ts
buildMissionStateProgressFromGraph and buildMissionStateProgress consolidate step status aggregation into single iteration loops, replacing separate filter(...).length and filter(...).map(...) calls for computing completedSteps, activeWorkers, blockedSteps, and failedSteps.
Context snapshot and fan-out completion optimization
apps/desktop/src/main/services/orchestrator/orchestratorService.ts
createContextSnapshotForAttempt replaces multi-filter frontier counting with a single-pass loop. checkFanOutCompletion pre-indexes steps into a stepByKey map and uses map lookups instead of repeated allSteps.find(...) calls for resolving parent/child steps and counting outcomes.

Chat Message List Turn Summary Data Model Refactor

Layer / File(s) Summary
Turn summary type and derivation logic
apps/desktop/src/renderer/components/chat/AgentChatMessageList.tsx
TurnSummary is refactored to report taskCount, completedTaskCount, and changedFileCount instead of per-task/per-file arrays and addition/deletion totals. deriveTurnSummary scans backward to find the latest turnId, accumulates changed file paths in a Set, derives task counts from latest todo_update or plan entries, and returns the new count-based shape. Supporting changes remove the unused openExternalUrl import and PlanStepIcon helper function.
UI component wiring updates
apps/desktop/src/renderer/components/chat/AgentChatMessageList.tsx
TurnDivider task line now uses completedTaskCount/taskCount instead of filtering summary.tasks. The review changes navigation handler checks changedFileCount instead of files.length.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes


Suggested labels

desktop

✨ 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 ade/complexity-cleanup-20260517

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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 and usage tips.

@arul28 arul28 deleted the ade/complexity-cleanup-20260517 branch May 17, 2026 23:20
@capy-ai
Copy link
Copy Markdown

capy-ai Bot commented May 17, 2026

Capy auto-review is paused for this organization because the monthly auto-review limit has been reached. Increase the limit or turn it off in billing settings to resume automatic reviews.

Comment on lines +11367 to +11372
const stepByKey = new Map<string, OrchestratorStep>();
for (const step of allSteps) {
if (!stepByKey.has(step.stepKey)) {
stepByKey.set(step.stepKey, step);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Adding a brief comment here would make the first-match intent explicit and prevent a well-meaning refactor from accidentally switching to last-match semantics.

Suggested change
const stepByKey = new Map<string, OrchestratorStep>();
for (const step of allSteps) {
if (!stepByKey.has(step.stepKey)) {
stepByKey.set(step.stepKey, step);
}
}
// Build index keyed by stepKey; keep the first occurrence to match prior Array.find semantics.
const stepByKey = new Map<string, OrchestratorStep>();
for (const step of allSteps) {
if (!stepByKey.has(step.stepKey)) {
stepByKey.set(step.stepKey, step);
}
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/main/services/orchestrator/orchestratorService.ts
Line: 11367-11372

Comment:
Adding a brief comment here would make the first-match intent explicit and prevent a well-meaning refactor from accidentally switching to last-match semantics.

```suggestion
      // Build index keyed by stepKey; keep the first occurrence to match prior Array.find semantics.
      const stepByKey = new Map<string, OrchestratorStep>();
      for (const step of allSteps) {
        if (!stepByKey.has(step.stepKey)) {
          stepByKey.set(step.stepKey, step);
        }
      }
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

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