Skip to content

The agent that grows with you

fix(desktop): honour the read-only cron-run latch on tile submits too

Austin Pickett3df634b0238b
diff --git a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts
index 973273ed2ec..61a533af03c 100644
--- a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts
@@ -7,6 +7,7 @@ import type * as HermesModule from '@/hermes'
import { textPart } from '@/lib/chat-messages'
import { createClientSessionState } from '@/lib/chat-runtime'
import { $notifications } from '@/store/notifications'
+import { $readOnlyCronRuns, markCronRunReadOnly } from '@/store/read-only-transcript'
import { setSessionOwnerHint, setSessions } from '@/store/session'
import { $sessionTiles, sessionTileDelegate } from '@/store/session-states'
import type { SessionInfo } from '@/types/hermes'
@@ -895,3 +896,50 @@ describe('useSessionTileDelegate submitToSession', () => {
)
})
})
+
+
+describe('useSessionTileDelegate read-only cron run (#88443)', () => {
+ const storedId = 'cron_job-1_1700000000'
+ const runtimeId = 'rt-cron-zombie'
+
+ beforeEach(() => {
+ setSessions([])
+ $notifications.set([])
+ $readOnlyCronRuns.set(new Set())
+ vi.mocked(getLatestSessionMessages).mockReset()
+ vi.mocked(getLatestSessionMessages).mockImplementation(async () => ({ messages: [], session_id: storedId }))
+ })
+
+ afterEach(() => {
+ setSessions([])
+ $notifications.set([])
+ $readOnlyCronRuns.set(new Set())
+ })
+
+ // The Cron surfaces latch a never-closed run read-only by STORED id; a tile
+ // resumed for that run must honour the same latch as the primary chat's
+ // `submit`, or moving the transcript into a tile reopens the write path.
+ it('refuses submitToSession into a cron run latched read-only', async () => {
+ setSessions([row({ id: storedId, profile: 'work-vps' })])
+ markCronRunReadOnly(storedId)
+
+ const requestGateway = vi.fn(async () => ({}) as never)
+
+ renderTile(requestGateway, {
+ runtimeIdByStoredSessionIdRef: { current: new Map([[storedId, runtimeId]]) },
+ sessionStateByRuntimeIdRef: { current: new Map([[runtimeId, createClientSessionState(storedId, [])]]) }
+ })
+
+ await sessionTileDelegate()!.submitToSession(runtimeId, 'into the dead cron session')
+
+ expect(requestGateway).not.toHaveBeenCalledWith('prompt.submit', expect.anything(), expect.anything())
+ expect(requestGatewayForProfile).not.toHaveBeenCalledWith(
+ 'work-vps',
+ 'prompt.submit',
+ expect.anything(),
+ expect.anything(),
+ expect.anything()
+ )
+ expect($notifications.get().some(note => note.kind === 'info')).toBe(true)
+ })
+})
diff --git a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts
index 6136a9b0410..6237891db48 100644
--- a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts
@@ -18,6 +18,7 @@ import { noteMessageSent } from '@/store/desktop-metrics'
import { notify } from '@/store/notifications'
import {
isReadOnlyRuntimeId,
+ isStoredTranscriptReadOnly,
readOnlyRuntimeIdFor,
resumeWithStoredTranscriptFallback
} from '@/store/read-only-transcript'
@@ -480,17 +481,19 @@ export function useSessionTileDelegate({
return runtimeId
},
submitToSession: async (runtimeId, text) => {
+ const storedSessionId = storedSessionIdForRuntime(runtimeId)
+
// A read-only stored-transcript tile has no live runtime to submit
- // into (#94724). Refuse with the explanation instead of minting a
- // misrouted prompt on a backend that never owned the session.
- if (isReadOnlyRuntimeId(runtimeId)) {
+ // into (#94724), and a never-closed cron run latched read-only by a
+ // Cron surface (#88443) stays closed to writes when it is later opened
+ // as a tile — same gate as the primary chat's `submit`. Refuse with the
+ // explanation instead of minting a misrouted prompt.
+ if (isReadOnlyRuntimeId(runtimeId) || isStoredTranscriptReadOnly(storedSessionId)) {
notify({ kind: 'info', message: translateNow('desktop.readOnlyTranscriptSendBlocked') })
return { runtimeSessionId: runtimeId, storedSessionId: null }
}
- const storedSessionId = storedSessionIdForRuntime(runtimeId)
-
if (storedSessionId) {
const cached = sessionStateByRuntimeIdRef.current.get(runtimeId)
const owner = await ownerForStoredSession(storedSessionId)