@@ -27,7 +27,6 @@ import { safeErrorLogAttributes } from "../errors/safeLog.ts";
2727import * as Persistence from "../platform/persistence.ts" ;
2828import { runCachePersistence } from "./cachePersistence.ts" ;
2929import { subscribeDynamic } from "../rpc/client.ts" ;
30- import type { RpcSession } from "../rpc/session.ts" ;
3130import * as ShellSnapshotLoader from "./shellSnapshotHttp.ts" ;
3231import type { DeferredShellSnapshot } from "./shellPullRequests.ts" ;
3332import {
@@ -105,8 +104,10 @@ export const makeEnvironmentShellState = Effect.fn("EnvironmentShellState.make")
105104 status : shellStatusForSnapshot ( cachedSnapshot ) ,
106105 } ) ;
107106 const awaitingCompletion = yield * Ref . make ( false ) ;
108- const lastAuthoritativeSession = yield * Ref . make < RpcSession | null > ( null ) ;
109- const activeSubscriptionSession = yield * Ref . make < RpcSession | null > ( null ) ;
107+ // The omission options of the subscription whose snapshot the in-memory
108+ // shell last came from; null while it holds only cached data.
109+ const authoritativeOmission = yield * Ref . make < string | null > ( null ) ;
110+ const activeSubscriptionOmission = yield * Ref . make < string | null > ( null ) ;
110111 const latestLiveSnapshot = yield * Ref . make < Option . Option < OrchestrationV2ShellSnapshot > > (
111112 Option . none ( ) ,
112113 ) ;
@@ -274,9 +275,9 @@ export const makeEnvironmentShellState = Effect.fn("EnvironmentShellState.make")
274275 }
275276 yield * SubscriptionRef . set ( state , next ) ;
276277 if ( receivedSnapshot ) {
277- const session = yield * Ref . get ( activeSubscriptionSession ) ;
278- if ( session !== null ) {
279- yield * Ref . set ( lastAuthoritativeSession , session ) ;
278+ const omission = yield * Ref . get ( activeSubscriptionOmission ) ;
279+ if ( omission !== null ) {
280+ yield * Ref . set ( authoritativeOmission , omission ) ;
280281 }
281282 }
282283 if ( next . snapshot !== initial . snapshot && Option . isSome ( next . snapshot ) ) {
@@ -362,7 +363,6 @@ export const makeEnvironmentShellState = Effect.fn("EnvironmentShellState.make")
362363 subscribeDynamic (
363364 ORCHESTRATION_V2_WS_METHODS . subscribeShell ,
364365 Effect . fn ( "EnvironmentShellState.makeSubscribeInput" ) ( function * ( session ) {
365- yield * Ref . set ( activeSubscriptionSession , session ) ;
366366 const { omitIdleSubagents, omitOlderSettled } = yield * session . initialConfig . pipe (
367367 Effect . map ( ( config ) => ( {
368368 omitIdleSubagents : config . shellThreadFamilies === true ,
@@ -371,13 +371,16 @@ export const makeEnvironmentShellState = Effect.fn("EnvironmentShellState.make")
371371 } ) ) ,
372372 Effect . orElseSucceed ( ( ) => ( { omitIdleSubagents : false , omitOlderSettled : false } ) ) ,
373373 ) ;
374+ const omissionKey = `${ omitIdleSubagents } :${ omitOlderSettled } ` ;
375+ yield * Ref . set ( activeSubscriptionOmission , omissionKey ) ;
374376 yield * Ref . set ( awaitingCompletion , true ) ;
375377 yield * setSynchronizing ;
376378
377- // Foreground resubscriptions on the same live session can resume from
378- // the in-memory cursor. A new session reloads the authoritative HTTP
379- // snapshot so a valid cursor cannot preserve incomplete cached data.
380- const hasAuthoritativeSnapshot = ( yield * Ref . get ( lastAuthoritativeSession ) ) === session ;
379+ // A shell that came from a server snapshot resumes from its in-memory
380+ // cursor, on this session or a new one. Cached data, or a snapshot taken
381+ // with other omissions, reloads the authoritative HTTP snapshot so a
382+ // valid cursor cannot preserve incomplete data.
383+ const hasAuthoritativeSnapshot = ( yield * Ref . get ( authoritativeOmission ) ) === omissionKey ;
381384 let canResume = hasAuthoritativeSnapshot ;
382385 let current = yield * SubscriptionRef . get ( state ) ;
383386 if ( ! hasAuthoritativeSnapshot || Option . isNone ( current . snapshot ) ) {
0 commit comments