Skip to content

fix(mothership): keep a new chat's effort pick changed while its first send is pending - #8662

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/effort-pick-pending-send
Oct 6, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
fix/effort-pick-pending-send

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Raised by cubic on the release PR: #8654 (comment)

On a new chat, the first send captures the effort pick (X) and the server stores it on the chat it opens. If the user changes the picker to Y while that send is still pending, the change goes to newChatEffort (there is no chat id yet). On admission, useChat adopted the captured X onto the new chat and cleared newChatEffort, so Y was lost: the picker showed X and the next turn ran at X. The dedup-conflict adoption (409 naming the chat the first attempt opened) had the same problem.

Adopting newChatEffort ?? effortChoice locally is not enough on its own: admission already stored X on the server, so a reload would bring X back.

Fix

  • At admission, useChat reads the live new-chat pick. If it differs from the pick the send carried, it adopts it locally and saves it to the chat through the existing per-chat effort save (PUT /api/mothership/chats/[chatId]/effort), so local and server state agree. A failed save rolls back by pick token as before, falling back to the stored value. If the pick is unset or unchanged, behaviour is unchanged and no extra save fires.
  • On a dedup conflict (409 naming the chat an earlier attempt opened), the client cannot know which pick that attempt stored, so it adopts the latest pick and always saves it.
  • The effort mutation's options move into one factory. useSetMothershipChatEffort(chatId) is unchanged; a new saveMothershipChatEffort(queryClient, chatId, effort) runs the same mutation through a MutationObserver for a chat id learned mid-send. Both use the same per-chat scope, so the admission save and any later composer pick for that chat land in order, and other chats never wait on it.

Test plan

  • New use-chat.dom.test.tsx case: pick low, send, change the pick to high while the send is pending, admit. Asserts the chat keeps high and exactly one effort save goes to that chat. Fails on current staging (expected 'low' to be 'high'), passes with the fix.
  • Same case with the pick unchanged asserts no effort save fires.
  • New dedup case: a 409 naming the earlier attempt's chat adopts the latest pick and saves it to that chat. Also fails on current staging, passes with the fix.
  • Existing effort mutation test passes unchanged.
  • tsc --noEmit, biome, check:audits, and the home hooks, user-input, mothership-chats, effort store, and organization-home suites pass.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@vercel

vercel Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 6, 2026 4:24am UTC

Request Review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts
Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Outdated
@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Saves chat effort preference when a new message opens a chat.

The PR appears safe to merge; no outstanding findings remain.

Summary

The PR preserves an effort pick changed during a new chat’s first pending send and saves that pick to the admitted chat. It also covers deduplicated admission and keeps effort saves ordered per chat. Both previous Greptile findings are resolved.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Send with captured effort] --> B[Chat admitted or identified by 409]
  B --> C[Read latest new-chat pick]
  C --> D[Adopt pick for chat]
  D --> E{Pick changed or 409?}
  E -- Yes --> F[Save through per-chat mutation scope]
  E -- No --> G[No additional save]
Loading

Reviews (3) · Last reviewed commit: "fix(mothership): detach the effort save ..."

Comment thread apps/sim/hooks/queries/mothership-chats.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/hooks/queries/mothership-chats.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@waleedlatif1
waleedlatif1 enabled auto-merge (squash) October 6, 2026 04:28
@waleedlatif1
waleedlatif1 merged commit a766a03 into staging Oct 6, 2026
24 checks passed

This branch was previously deployed

1 inactive deployment
Preview — 320f99f5 Deployed Oct 6, 2026 by vercel[bot]
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