@@ -9,7 +9,10 @@ import { matchComposerThreadItems } from "@t3tools/client-runtime/composerThread
99import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/models" ;
1010
1111const EMPTY_THREAD_SHELLS : ReadonlyArray < EnvironmentThreadShell > = [ ] ;
12- import { COMPOSER_CONTEXT_MAX_RECORDS } from "@t3tools/contracts" ;
12+ import {
13+ COMPOSER_CONTEXT_MAX_RECORDS ,
14+ PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS ,
15+ } from "@t3tools/contracts" ;
1316import { Alert } from "react-native" ;
1417import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences" ;
1518import { pullRequestComposerContext , threadComposerContext } from "../../lib/composerContext" ;
@@ -37,6 +40,7 @@ import {
3740 getProviderSlashCommandsForSlashMenu ,
3841 isProviderSkillUserInvocable ,
3942 hasCompleteProviderWorkspaceSnapshot ,
43+ hasCurrentProviderWorkspaceSnapshot ,
4044 resolveProviderSkillsForCwd ,
4145 resolveProviderSlashCommandsForCwd ,
4246} from "@t3tools/client-runtime/providerSkills" ;
@@ -250,7 +254,9 @@ export function useComposerCommandMenu({
250254 selectedProviderStatus ,
251255 projectCwd ,
252256 ) ;
253- const workspaceRefreshKeyRef = useRef < string | null > ( null ) ;
257+ // The last scan this composer asked for. A request inside the TTL is not
258+ // repeated, so a client clock ahead of the server's cannot loop rescans.
259+ const workspaceRefreshKeyRef = useRef < { key : string ; requestedAt : number } | null > ( null ) ;
254260 const [ workspaceRefreshRetry , setWorkspaceRefreshRetry ] = useState < {
255261 key : string ;
256262 notBefore : number ;
@@ -289,17 +295,23 @@ export function useComposerCommandMenu({
289295 useEffect ( ( ) => {
290296 if ( ! environmentId || ! projectCwd || ! selectedProviderInstanceId ) return ;
291297 const key = `${ environmentId } :${ selectedProviderInstanceId } :${ projectCwd } ` ;
292- if ( workspaceRefreshKeyRef . current === key ) return ;
293- if ( hasWorkspaceSnapshot ) {
294- workspaceRefreshKeyRef . current = key ;
298+ const now = Date . now ( ) ;
299+ const lastRequest = workspaceRefreshKeyRef . current ;
300+ if (
301+ lastRequest ?. key === key &&
302+ now - lastRequest . requestedAt < PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS
303+ )
304+ return ;
305+ if ( hasCurrentProviderWorkspaceSnapshot ( selectedProviderStatus , projectCwd , now ) ) {
295306 setWorkspaceRefreshRetry ( null ) ;
296307 return ;
297308 }
298309 const retry = workspaceRefreshRetry ;
299- if ( retry ?. key === key && Date . now ( ) < retry . notBefore ) return ;
300- workspaceRefreshKeyRef . current = key ;
310+ if ( retry ?. key === key && now < retry . notBefore ) return ;
311+ const request = { key, requestedAt : now } ;
312+ workspaceRefreshKeyRef . current = request ;
301313 const retryLater = ( ) => {
302- if ( workspaceRefreshKeyRef . current !== key ) return ;
314+ if ( workspaceRefreshKeyRef . current !== request ) return ;
303315 workspaceRefreshKeyRef . current = null ;
304316 setWorkspaceRefreshRetry ( {
305317 key,
@@ -318,17 +330,15 @@ export function useComposerCommandMenu({
318330 ) ,
319331 projectCwd ,
320332 ) ;
321- if ( ! refreshed && workspaceRefreshKeyRef . current === key ) {
322- retryLater ( ) ;
323- }
333+ if ( ! refreshed ) retryLater ( ) ;
324334 } , retryLater ) ;
325335 } , [
326336 draftMessage ,
327337 environmentId ,
328- hasWorkspaceSnapshot ,
329338 projectCwd ,
330339 refreshProviders ,
331340 selectedProviderInstanceId ,
341+ selectedProviderStatus ,
332342 workspaceRefreshRetry ,
333343 ] ) ;
334344
0 commit comments