Skip to content

fix: speed up brain inbox classification with gemini-cli#142

Open
atomantic wants to merge 4 commits intomainfrom
worktree-fix-brain-gemini-speed
Open

fix: speed up brain inbox classification with gemini-cli#142
atomantic wants to merge 4 commits intomainfrom
worktree-fix-brain-gemini-speed

Conversation

@atomantic
Copy link
Copy Markdown
Owner

Summary

  • Brain inbox classification with gemini-cli was slow because the provider had no default model — gemini fell back to gemini-2.5-pro (a thinking model), and because --prompt was never passed the CLI also went through its interactive-mode-detection path over /dev/null stdin.
  • brain.js callAI() now sends gemini-cli prompts via --prompt, forces --output-format text, and defaults the model to gemini-2.5-flash-lite (thinking disabled) when none is set.
  • Sample providers config populates models/defaultModel/lightModel/mediumModel/heavyModel for gemini-cli so new installs pick up the fast model automatically.

Test plan

  • cd server && npm test — 2371 tests pass
  • Live check: capture a thought via Brain with defaultProvider: gemini-cli and confirm classification completes in a few seconds instead of tens of seconds

Gemini CLI was invoked without --prompt (forcing interactive-mode
detection over /dev/null stdin) and with no model set, so the classify
path fell back to gemini-2.5-pro — a thinking model. Switch to
gemini-2.5-flash-lite by default, pass --prompt, and set
--output-format text for clean parsing. Update sample provider config
with model tiers so new installs pick up the fast model automatically.
Copilot AI review requested due to automatic review settings April 15, 2026 22:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves Brain’s CLI provider integration specifically for gemini-cli to avoid slow “thinking model” defaults and interactive-mode detection overhead during inbox classification.

Changes:

  • Default gemini-cli model to gemini-2.5-flash-lite when no model is configured.
  • Invoke gemini-cli with --prompt and enforce --output-format text to keep calls non-interactive and faster.
  • Update sample provider config to include Gemini model tiers and a fast default model.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
server/services/brain.js Adjusts gemini-cli invocation: adds model fallback, --output-format text, and passes prompt via --prompt.
data.sample/providers.json Sets gemini-cli models and default/light/medium/heavy model fields so new installs use a fast model by default.
.changelog/NEXT.md Documents the Brain gemini-cli performance fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/services/brain.js Outdated
Comment thread server/services/brain.js
…ompt

Addresses Copilot review on PR #142:
- Strengthen the brain.js comment to call out that gemini-cli invocation in
  this path intentionally differs from runner.js/agentCliSpawning.js, which
  stream prompts via stdin. Brain runs headless with stdin ignored, so the
  prompt must go via --prompt and --output-format text to stay non-interactive.
- Add spawn-mocked unit tests in brain.test.js pinning: prompt-via-flag,
  forced --output-format text, the gemini-2.5-flash-lite fallback when no
  model is set, explicit-model-override precedence, no duplicate --output-format
  when provider args already specify it, and the unchanged positional-arg
  behavior for non-gemini CLI providers.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/services/brain.test.js Outdated
Comment thread server/services/brain.js Outdated
Addresses Copilot round-2 review on PR #142:
- brain.js: the gemini-cli fast-model fallback now resolves to
  provider.lightModel first and only hard-codes gemini-2.5-flash-lite when
  nothing is configured. The sample providers.json already populates
  lightModel, so user-configured preferences win without code changes.
- brain.test.js: drop the CLI test provider timeout from 1000ms to 50ms
  so the uncleared setTimeout in callAI() doesn't keep the event loop busy
  at the tail of the suite. Add coverage for the new lightModel path.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/services/brain.js
Addresses Copilot round-3 review on PR #142: before this change callAI
silently fell back to a concrete gemini-cli model, but runDailyDigest,
runWeeklyReview, captureThought, and retryClassification persisted
ai.modelId using the caller's original (possibly null) override. Cost
and debug attribution could read "modelId: null" for a request that
actually ran on gemini-2.5-flash-lite.

- callAI now returns { content, model, providerId } so the resolved
  model is visible to every caller.
- runDailyDigest, runWeeklyReview, and classifyInBackground now store
  the returned model/providerId in their ai metadata (inbox entry is
  patched after classification completes so the initial "intent" record
  is overwritten with what actually ran).
- New test pins the digest path: with gemini-cli, no defaultModel, and
  no lightModel configured, ai.modelId persists as
  gemini-2.5-flash-lite, not null.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants