Skip to content

Default composer to first agent/model without an eager probe fetch - #154

Merged
soorya-u merged 5 commits into
mainfrom
fix/147-composer-default-agent-model
Aug 6, 2026
Merged

Default composer to first agent/model without an eager probe fetch#154
soorya-u merged 5 commits into
mainfrom
fix/147-composer-default-agent-model

Conversation

@soorya-u

@soorya-u soorya-u commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Reinstate defaulting pendingAgent to agents[0] for draft threads so the composer opens with an agent pre-selected.
  • catalogAgent (which gates the getDraftCatalog probe) simply follows pendingAgent once that default fires, so the model auto-select effect runs immediately too — both the agent and its first model are selected as soon as a new thread is created.
  • The probe's query key is (agentName, projectId) with staleTime: Infinity (see use-draft-catalog.ts), so it's already deduped per project rather than per draft — firing it on every new draft doesn't reintroduce repeated network calls, just one legitimate fetch per project.

An earlier revision of this PR gated the probe behind first focus/interaction with the composer, to avoid re-triggering the eager-fetch behavior that motivated the original default-selection removal. That turned out to only delay the model selection without avoiding any real extra cost (thanks to the query-key caching above), so it's been dropped in favor of the simpler, fully-default-on-mount behavior.

Fixes #147

Test plan

  • bun run check:types (typecheck)
  • ultracite check (lint)
  • bun test:unit — 134 passed
  • Unit tests: shared/hooks/src/agent-catalog/selectors.test.ts
  • Browser/full-stack verification not performed (would require a live worker + registered agent)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Draft threads now automatically select the first available agent when no agent is already pending.
    • Improved agent selection behavior when IDs are missing or unavailable.
  • Tests

    • Added coverage for valid, missing, and unknown agent IDs, including display fallback behavior.

…fetch

Reinstate defaulting pendingAgent to agents[0] for draft threads so the
composer opens with an agent (and once models load, a model) pre-selected.
Keep the getDraftCatalog probe lazy by gating it on a new catalogArmed flag
that only flips once the user actually interacts with the composer (focuses
the prompt editor or opens the agent/model picker), so the default selection
alone never fires the RPC.

Fixes #147.
@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
cyrus Ready Ready Preview Aug 6, 2026 5:33am

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@soorya-u, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1db60335-753b-41a5-913f-66bfa451f2ef

📥 Commits

Reviewing files that changed from the base of the PR and between 6d47f43 and de6b89f.

📒 Files selected for processing (2)
  • apps/server/package.json
  • apps/web/src/components/chat/composer/index.tsx
📝 Walkthrough

Walkthrough

Draft threads now select the first available agent when no pending agent is set. Vitest tests cover explicit selection and display fallback behavior for missing, unknown, and valid IDs.

Changes

Agent selection

Layer / File(s) Summary
Draft agent initialization and selector validation
shared/hooks/src/agent-catalog/use-agent-catalog.ts, shared/hooks/src/agent-catalog/selectors.test.ts
Draft threads initialize the pending agent from the first available agent. Tests validate explicit matches and display fallback to the first catalog option.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • soorya-u/cyrus#73: Directly modifies draft-agent auto-selection behavior in use-agent-catalog.ts.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The change restores first-agent selection, but the summaries indicate that lazy probe gating may be absent, leaving Issue #147's eager-fetch requirement unresolved. Retain interaction-gated getDraftCatalog probing with catalogArmedByThread, armCatalog, and clearCatalogArmed while keeping default agent and model selection.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The selector tests and draft-agent selection logic directly support Issue #147 and the stated composer behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: defaulting the composer to the first agent or model without an eager probe fetch.
✨ 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 fix/147-composer-default-agent-model

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.

Drop the catalogArmed interaction-gating from the previous commit: the
getDraftCatalog probe's query key is scoped to (agent, projectId) with
staleTime Infinity, so it's already deduped per project rather than
per draft. Gating it behind first focus/interaction only delayed the
model selection without avoiding any real extra network cost, and it
diverged from the goal of having both the agent and its first model
selected as soon as a new thread is created.

catalogAgent now simply follows pendingAgent once the default-agent
effect sets it, matching the pre-removal behavior.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@shared/hooks/src/agent-catalog/use-agent-catalog.ts`:
- Around line 168-174: The draft initialization effect should not call
setPendingAgent merely to arm the catalog query, because that enables
getDraftCatalog before user interaction. Introduce and use separate
catalogArmedByThread state for the draft catalog enabled condition, or remove
the default pending-agent selection from this render path while preserving
pendingAgent for actual user selection.
🪄 Autofix

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 Plus

Run ID: b22b8a52-25fb-4bde-9109-cdfb0bd0188c

📥 Commits

Reviewing files that changed from the base of the PR and between bcad6d1 and 6d47f43.

📒 Files selected for processing (2)
  • shared/hooks/src/agent-catalog/selectors.test.ts
  • shared/hooks/src/agent-catalog/use-agent-catalog.ts

Comment thread shared/hooks/src/agent-catalog/use-agent-catalog.ts
The composer previously revealed its real body as soon as agentsQuery
resolved, so a fresh draft briefly rendered with only the default agent
selected while its model was still being fetched. Latch a
draftCatalogSettled flag (reset per draft/project identity) that only
flips once catalog.displayAgent is set and catalog.modelsLoading is
false, and hold ComposerSkeleton until then. The latch is one-way so a
later agent switch mid-typing never re-hides the editor.
CI=1 keeps wrangler d1 migrations apply --local from prompting, which
otherwise blocks bun dev:server in non-interactive shells.
@soorya-u
soorya-u merged commit ffe86ae into main Aug 6, 2026
9 checks passed
@soorya-u
soorya-u deleted the fix/147-composer-default-agent-model branch August 6, 2026 05:41
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.

Composer doesn't auto-select first agent/model on open

1 participant