@@ -136,7 +136,7 @@ const WORKSPACE_SNAPSHOT_RETRY_COOLDOWN_MS = 10_000;
136136// A cwd that never scans, such as a deleted worktree, would otherwise retry forever.
137137const WORKSPACE_SNAPSHOT_MAX_ATTEMPTS = 3 ;
138138
139- interface ProviderWorkspaceSnapshotRefreshState {
139+ export interface ProviderWorkspaceSnapshotRefreshState {
140140 /**
141141 * When the last scan was requested. A request inside the TTL is not
142142 * repeated, so a client clock ahead of the server's cannot loop rescans.
@@ -147,13 +147,16 @@ interface ProviderWorkspaceSnapshotRefreshState {
147147 /** Failed scans within the current request TTL. */
148148 readonly failedAttempts : number ;
149149 readonly hadSnapshot : boolean ;
150+ /** The server published a partial snapshot and is still discovering. */
151+ readonly snapshotPending : boolean ;
150152}
151153
152154const initialProviderWorkspaceSnapshotRefreshState : ProviderWorkspaceSnapshotRefreshState = {
153155 requestedAt : null ,
154156 retryNotBefore : null ,
155157 failedAttempts : 0 ,
156158 hadSnapshot : false ,
159+ snapshotPending : false ,
157160} ;
158161
159162/**
@@ -172,6 +175,8 @@ function planProviderWorkspaceSnapshotRefresh(
172175 readonly recheckAt : number | null ;
173176} {
174177 const hasSnapshot = hasCompleteProviderWorkspaceSnapshot ( provider , cwd ) ;
178+ const pending =
179+ ( provider && resolveProviderWorkspaceSnapshot ( provider , cwd ) ?. slashCommandsPending ) === true ;
175180 // Losing a snapshot (the server dropped it) lifts both the TTL and the retry
176181 // cooldown so the scan happens at once.
177182 const lost = previous . hadSnapshot && ! hasSnapshot ;
@@ -188,6 +193,7 @@ function planProviderWorkspaceSnapshotRefresh(
188193 ? 0
189194 : previous . failedAttempts ,
190195 hadSnapshot : hasSnapshot ,
196+ snapshotPending : pending ,
191197 } ;
192198 const refresh =
193199 ( requestedAt === null || now - requestedAt >= PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS ) &&
@@ -196,8 +202,6 @@ function planProviderWorkspaceSnapshotRefresh(
196202 if ( refresh ) {
197203 return { state : { ...state , requestedAt : now } , refresh : true , recheckAt : null } ;
198204 }
199- const pending =
200- ( provider && resolveProviderWorkspaceSnapshot ( provider , cwd ) ?. slashCommandsPending ) === true ;
201205 return { state, refresh : false , recheckAt : pending ? retryNotBefore : null } ;
202206}
203207
@@ -223,6 +227,23 @@ function failProviderWorkspaceSnapshotRefresh(
223227 } ;
224228}
225229
230+ /**
231+ * A scan is in flight, or the server is still discovering, for a cwd without a
232+ * complete snapshot, so its skills and commands may still arrive. A failed scan
233+ * clears `requestedAt`, and exhausted attempts end it, so this cannot stay true
234+ * for a scan that will not finish.
235+ */
236+ export function isProviderWorkspaceSnapshotScanning (
237+ state : ProviderWorkspaceSnapshotRefreshState | undefined ,
238+ ) : boolean {
239+ return (
240+ state !== undefined &&
241+ ( state . requestedAt !== null || state . snapshotPending ) &&
242+ ! state . hadSnapshot &&
243+ state . failedAttempts < WORKSPACE_SNAPSHOT_MAX_ATTEMPTS
244+ ) ;
245+ }
246+
226247type WorkspaceSnapshotStatus = "absent" | "pending" | "complete" ;
227248
228249function resolveWorkspaceSnapshotStatus (
@@ -330,6 +351,8 @@ export function createProviderWorkspaceSnapshotRefreshAtomFamily(input: {
330351 ) . pipe ( Atom . withLabel ( `provider-workspace-snapshot-refresh:${ key } ` ) ) ;
331352 return refreshAtom ;
332353 } ) ;
333- return ( target : ProviderWorkspaceSnapshotRefreshTarget ) : Atom . Atom < unknown > =>
354+ return (
355+ target : ProviderWorkspaceSnapshotRefreshTarget ,
356+ ) : Atom . Atom < ProviderWorkspaceSnapshotRefreshState > =>
334357 family ( { environmentId : target . environmentId , instanceId : target . instanceId , cwd : target . cwd } ) ;
335358}
0 commit comments