diff --git a/config/reliability-gates.jsonc b/config/reliability-gates.jsonc index a2993e76354..3b3211ff7b4 100644 --- a/config/reliability-gates.jsonc +++ b/config/reliability-gates.jsonc @@ -10346,7 +10346,8 @@ "assertions": [ "legacy hosts without acknowledgement cannot stamp client options as applied", "client-built commands retain their known applied state", - "fallback agents own draft state without inheriting requested-agent options" + "fallback agents own draft state without inheriting requested-agent options", + "paired-runtime receipts target the authoritative web-surface agent tab" ] } ], diff --git a/src/renderer/src/hooks/useComposerState-host-context-boundaries.test.ts b/src/renderer/src/hooks/useComposerState-host-context-boundaries.test.ts index 89d754d8a86..c2707c9b7f7 100644 --- a/src/renderer/src/hooks/useComposerState-host-context-boundaries.test.ts +++ b/src/renderer/src/hooks/useComposerState-host-context-boundaries.test.ts @@ -755,6 +755,7 @@ describe('useComposerState host-context boundaries', () => { 'startupSessionOptions: { agent: tuiAgent, values: startupPlan.sessionOptions }' ) expect(fullSubmit).toContain('resolveCreatedAgentAppliedSessionOptions') + expect(fullSubmit).toContain('resolveLaunchAgentTabId') expect(fullSubmit).not.toContain('platform: CLIENT_PLATFORM') const quickSubmit = sourceBetween( diff --git a/src/renderer/src/hooks/useComposerState.ts b/src/renderer/src/hooks/useComposerState.ts index c4578b4ba84..6d3d7253bb1 100644 --- a/src/renderer/src/hooks/useComposerState.ts +++ b/src/renderer/src/hooks/useComposerState.ts @@ -15,7 +15,10 @@ import { } from '@/lib/github-links' import { activateAndRevealWorktree, type AgentStartedTelemetry } from '@/lib/worktree-activation' import { runBackgroundWorktreeCreation } from '@/lib/worktree-creation-flow' -import { resolveCreatedAgentAppliedSessionOptions } from '@/lib/worktree-creation-agent-seeds' +import { + resolveCreatedAgentAppliedSessionOptions, + resolveLaunchAgentTabId +} from '@/lib/worktree-creation-agent-seeds' import { findPendingLinkedWorkItemCreationId, type WorktreeCreationRequest @@ -3919,8 +3922,13 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS backendSpawnedStartup && !backendStartup ? (worktree.createdWithAgent ?? tuiAgent) : tuiAgent - const optionScopeKey = - (activation !== false ? activation.primaryTabId : null) ?? result.startupTerminal?.tabId + const optionScopeKey = resolveLaunchAgentTabId(useAppStore.getState(), { + agent: createdAgent, + worktreeId: worktree.id, + primaryTabId: activation === false ? null : activation.primaryTabId, + startupTerminalTabId: result.startupTerminal?.tabId, + backendSpawned: backendSpawnedStartup + }) if (optionScopeKey) { seedNativeChatAppliedSessionOptions( optionScopeKey, diff --git a/src/renderer/src/lib/worktree-creation-agent-seeds.ts b/src/renderer/src/lib/worktree-creation-agent-seeds.ts index 4eb58fa79d2..c3f341c1db7 100644 --- a/src/renderer/src/lib/worktree-creation-agent-seeds.ts +++ b/src/renderer/src/lib/worktree-creation-agent-seeds.ts @@ -38,7 +38,7 @@ export function resolveCreatedAgentAppliedSessionOptions(args: { * (e.g. "dev server", "logs", "shell") the worktree's first tab runs no agent, * and activation's `primaryTabId` is only the worktree's primary tab. */ -function resolveLaunchAgentTabId( +export function resolveLaunchAgentTabId( state: AppStoreSnapshot, args: { agent: TuiAgent