feat: reuse empty artifact chat sessions - #742
Conversation
|
Warning Review limit reached
More reviews will be available in 29 minutes and 59 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. 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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds ChangesEmpty AI Session Reuse with Surface-Conditional Creation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 29c820edba
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (emptySessionId) { | ||
| if (get().ai.config.currentSessionId !== emptySessionId) { | ||
| get().ai.switchSession(emptySessionId); | ||
| } | ||
| return emptySessionId; |
There was a problem hiding this comment.
Avoid no-oping New session on renamed empty chats
When the current artifact's empty session has been renamed, the CLI still enables the New session button because AssistantChatContainer only disables empty sessions with default-generated names, but this branch finds that same empty session and returns it instead of creating another one. In that scenario clicking New session appears to do nothing and prevents starting a separate blank chat until the user sends a message or deletes/modifies the draft; either disable the caller for all empty sessions or avoid reusing the current renamed draft.
Useful? React with 👍 / 👎.
29c820e to
a369d63
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a369d63995
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (emptySessionId) { | ||
| if (currentSessionId !== emptySessionId) { | ||
| get().ai.switchSession(emptySessionId); | ||
| } | ||
| return emptySessionId; |
There was a problem hiding this comment.
Preserve requested session options when reusing
When createArtifactScopedSession is called with name, modelProvider, or model and the artifact already has another empty chat, this branch switches to that old chat and returns before createSession(name, modelProvider, model) runs. Callers of this exported API can therefore request a specifically named/modelled session but silently get an existing draft with the previous name/model instead; skip reuse or update the reused draft when explicit options are supplied.
Useful? React with 👍 / 👎.
a369d63 to
2070608
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 20706086cf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| state.pivot.ensurePivot(artifactId, {title: uniqueTitle}); | ||
| } | ||
| state.artifacts.setCurrentArtifact(artifactId); | ||
| state.artifactAi.createArtifactScopedSession(); |
There was a problem hiding this comment.
Avoid switching chats during AI-created artifacts
The CLI app registers these commands in the default AI command tool path (apps/sqlrooms-cli-ui/src/store.ts:714), and that tool invokes them with surface: 'ai' (packages/ai/src/tools/commandTools.ts:158). When a running assistant uses a create-artifact command, this new side effect creates/switches to a blank session for the new artifact while the original session keeps streaming in the old artifact's history, so the user loses the visible in-progress answer; keep this initial-chat creation in the tabstrip/UI caller or gate it away from AI/MCP command executions. The identical call in the dashboard-specific branch below has the same issue.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/artifacts/src/ai/artifactAiSessionHelpers.ts (1)
118-154: 💤 Low valueConsider adding complete TSDoc with parameter and return documentation.
The exported function has a basic comment but is missing
@paramand@returnstags. As per coding guidelines, exported functions should have TSDoc.Consider expanding to:
/** * Returns the most recently opened empty AI session explicitly owned by * `artifactId`. * * An empty session is one that is not running, has no UI messages, and has * no prompt text (ignoring whitespace). * * `@param` options - Session selection options * `@param` options.sessions - Available sessions to search * `@param` options.aiSessionArtifacts - Session-to-artifact ownership mapping * `@param` options.artifactId - Target artifact ID * `@param` options.excludeSessionIds - Session IDs to skip during selection * `@returns` The ID of the most recently opened empty session, or undefined if none found */🤖 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 `@packages/artifacts/src/ai/artifactAiSessionHelpers.ts` around lines 118 - 154, The exported function `getEmptyAiSessionIdForArtifact` has only a basic comment describing its return value but is missing complete TSDoc documentation. Add `@param` tags documenting each property of the destructured options parameter (sessions, aiSessionArtifacts, artifactId, excludeSessionIds) and a `@returns` tag that documents the return type and what it represents. Also expand the description comment to clarify what constitutes an empty session.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@packages/artifacts/src/ai/artifactAiSessionHelpers.ts`:
- Around line 118-154: The exported function `getEmptyAiSessionIdForArtifact`
has only a basic comment describing its return value but is missing complete
TSDoc documentation. Add `@param` tags documenting each property of the
destructured options parameter (sessions, aiSessionArtifacts, artifactId,
excludeSessionIds) and a `@returns` tag that documents the return type and what
it represents. Also expand the description comment to clarify what constitutes
an empty session.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ac26fb5c-93f7-4cc9-a51c-2ee6bd5b82f9
📒 Files selected for processing (6)
apps/sqlrooms-cli-ui/src/createDashboardCommands.tspackages/artifacts/README.mdpackages/artifacts/__tests__/artifactAiSessions.test.tspackages/artifacts/src/ai/artifactAiSessionHelpers.tspackages/artifacts/src/ai/artifactAiSlice.tspackages/artifacts/src/ai/index.ts
2070608 to
af01a24
Compare
There was a problem hiding this comment.
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 `@apps/sqlrooms-cli-ui/src/createDashboardCommands.ts`:
- Line 149: The destructuring assignment in the
DashboardCreateArtifactCommandInput block does not handle the case where input
is undefined, which will cause a runtime error. Add a null check or provide a
fallback value (such as an empty object) before destructuring the title and
layoutType properties from input to ensure the code safely handles the case when
input is omitted or undefined.
🪄 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: 1f4510ea-6b15-49ab-9104-4f1b1071217d
📒 Files selected for processing (6)
apps/sqlrooms-cli-ui/src/createDashboardCommands.tspackages/artifacts/README.mdpackages/artifacts/__tests__/artifactAiSessions.test.tspackages/artifacts/src/ai/artifactAiSessionHelpers.tspackages/artifacts/src/ai/artifactAiSlice.tspackages/artifacts/src/ai/index.ts
✅ Files skipped from review due to trivial changes (1)
- packages/artifacts/README.md
🚧 Files skipped from review as they are similar to previous changes (4)
- packages/artifacts/tests/artifactAiSessions.test.ts
- packages/artifacts/src/ai/artifactAiSessionHelpers.ts
- packages/artifacts/src/ai/index.ts
- packages/artifacts/src/ai/artifactAiSlice.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af01a24f4c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| (session.uiMessages?.length ?? 0) === 0 && | ||
| (session.prompt ?? '').trim().length === 0 |
There was a problem hiding this comment.
Require message fields for empty-session selection
When callers use the newly exported getEmptyAiSessionIdForArtifact with the public ArtifactAiSession shape, prompt and uiMessages are optional, but this check defaults missing values to empty. An external caller can therefore pass a valid minimal non-running session summary that actually represents a used chat and have it selected as a reusable empty draft; require these fields for this helper or treat missing values as non-empty.
Useful? React with 👍 / 👎.
af01a24 to
c2e139b
Compare
Summary
Why
New artifacts should be immediately ready for artifact-scoped chat, but repeated chat creation should not accumulate duplicate blank sessions.
lastOpenedAtremains the recency signal;createdAtis left intact.Validation
pnpm --filter @sqlrooms/artifacts test -- artifactAiSessionspnpm --filter @sqlrooms/artifacts typecheckpnpm --filter sqlrooms-cli-app typecheckpnpm buildknip,turbo typecheck,turbo testSummary by CodeRabbit