fix(composer): persist permission mode picks without sending a message #40577
Closedmkantautas(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromrefs/pull/40577/headopened View on GitHubtanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
juliusmarminge added labelstakeover:in-progress
- @@ -0,0 +60,21 @@60+ if (61+ runtimeMode === durableRuntimeMode &&62+ (activeWriteMode === undefined || activeWriteMode === runtimeMode)63+ ) {64+ if (currentDraftMode !== undefined) {65+ updateComposerDraftSettings(threadKey, { runtimeMode: undefined });66+ }67+ return;68+ }69+70+ const seq = (runtimeModeSelectionSeq.get(threadKey) ?? 0) + 1;71+ runtimeModeSelectionSeq.set(threadKey, seq);72+73+ const canPersistImmediately =74+ isPendingCreation !== true &&75+ readEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope) &&76+ canPersistThreadRuntimeModeImmediately({ thread, projection });77+78+ if (!canPersistImmediately) {79+ updateComposerDraftSettings(threadKey, {80+ runtimeMode: runtimeMode === durableRuntimeMode ? undefined : runtimeMode,
Pushed17ebe28
Pushedff79ab7
- @@ -36,9 +36,15 @@3636 readonly messageId: MessageId;3737 readonly createdAt: string;3838 readonly setRuntimeMode: Command<SetThreadRuntimeModeInput, E>;39+ readonly onRuntimeModePersisted?: (runtimeMode: RuntimeMode) => void;3940 readonly setInteractionMode: Command<SetThreadInteractionModeInput, E>;4041 readonly startTurn: Command<StartThreadTurnInput, E>;4142 readonly resumeQueue: Command<ResumeThreadQueueInput, E>;4243 }): Promise<AtomCommandResult<unknown, E>> {4344 const { thread, runtimeMode, interactionMode, createdAt } = input;4445 const environmentId = thread.environmentId;46+ // A turn on an existing thread, held queued ones included, runs with the thread's saved modes.47+ if (runtimeMode !== thread.runtimeMode) {48+ const saved = await input.setRuntimeMode({49+ environmentId,50+ input: { threadId: thread.id, runtimeMode, createdAt },
juliusmarminge added labelstakeover:needs-julius
juliusmarminge removed labelstakeover:in-progress
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
github-actions[bot](GitHub profile, opens in a new tab) removed labelsneeds-rebase
Sign in to join this conversation.
Walkthrough
Web and mobile runtime-mode selections can persist immediately when thread state permits. The server rejects certain changes that would interrupt active work. Client draft overrides are released when they match the persisted mode, including during queued delivery and thread resume.
Changes: Runtime-mode selection and persistence
packages/contracts/src/orchestrationV2.ts,packages/client-runtime/src/operations/commands.ts,packages/client-runtime/src/state/threadWorkflows.ts,packages/client-runtime/src/state/threadCommands.ts,packages/client-runtime/src/state/*.test.tspreserveActiveSession. Client helpers determine when a mode can be persisted immediately and identify busy-selection errors. Thread commands expose the durable snapshot and optimistic runtime-mode updates.apps/server/src/orchestration-v2/Orchestrator.ts,apps/server/src/ws.ts,apps/server/src/orchestration-v2/Orchestrator.control-reads.test.tsprovider_selection_busy.apps/web/src/composerDraftStore.ts,apps/web/src/composerDraftStore.test.ts,apps/mobile/src/state/use-composer-drafts.ts,apps/mobile/src/state/threadOutboxDelivery.ts,apps/mobile/src/state/threadOutboxDelivery.permissions.test.ts,apps/mobile/src/features/threads/resume-thread.ts,apps/mobile/src/features/threads/ThreadRouteScreen.tsx,apps/web/src/components/chat/useComposerResume.tsapps/web/src/components/ChatView.tsx,apps/web/src/components/chat/useComposerSelection.ts,apps/web/src/components/chat/useComposerSelection.browser.test.tsx,apps/mobile/src/state/thread-runtime-mode.ts,apps/mobile/src/state/thread-runtime-mode.test.ts,apps/mobile/src/features/threads/ManagedRuntimeModeNotice.tsx,apps/mobile/src/features/threads/ThreadDetailScreen.tsx,apps/mobile/src/features/threads/ThreadSettingsSheet.tsx,apps/web/src/i18n/translations/*.json,apps/mobile/src/i18n/translations/*.jsonEstimated code review effort: 4 (Complex) | ~50 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
Possibly related issues
pingdotgg/t3code#29632— The PR persists existing-thread picker selections immediately instead of waiting for the next composer send.pingdotgg/t3code#39866— The PR changes the same runtime-mode switching path, but the running-turn policy gap appears to remain.Possibly related PRs
setRuntimeModebehavior.Suggested labels:
bugfixSuggested reviewers:
juliusmarminge,maria-rcks,macroscopeappMerge Risk:
Low · up to
ff79aUsing Resume to save a changed permission mode with a held queue and no run to continue can stop a provider session that has a pending request, losing that request. The case is narrow, and the fix is to pass the active-session guard on that save.
Pre-merge checks:
4
Full details: Title check
Explanation
The title "fix(composer): persist permission mode picks without sending a message" names the main change: permission-mode picks on existing threads are now saved to the server right away, without a send. The raw summary and objectives confirm this is the core change across web, mobile, server, and shared packages. It is a conventional commit title in plain language and stays concise.
Full details: Description check
Explanation
The description follows the repository template's Problem, Fix, Scope, and Verification sections, with a commit-style title outside the template. The Problem section explains the bug with reproduction steps and environment. The Fix section explains the change across packages. The Verification section lists the focused tests, typechecks, and lint results. The Scope section is missing: it does not state a linked issue and does not explain why the change needs no issue. It cites related PRs (
#39892,#30162,#31739) but does not link an issue that shows the bug. The Change section is also not labeled as the template requires. The Change section is labeled Fix, not Change, and the Scope heading is absent. The description also does not include before/after screenshots or a recording, though the template asks for them on UI changes, and this PR changes web and mobile UI.Resolution
Add a Scope section that links the issue showing this bug, or explains why no issue is needed. If a maintainer requested this PR, link that request. Add before/after screenshots or a short recording of the permission picker for the web composer and mobile settings, since this PR changes UI behavior. Rename the Fix section to Change to match the template.
Finishing Touches
Generate unit tests (beta)