Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): rp-022 rp-023 fix the cold-check budget and the stale rename probe
M2d4332260fa4
diff --git a/desktop-app/ui/src/gfs/__tests__/dragAdjudication.test.tsx b/desktop-app/ui/src/gfs/__tests__/dragAdjudication.test.tsxindex 9438f8ba9..0b491f4df 100644--- a/desktop-app/ui/src/gfs/__tests__/dragAdjudication.test.tsx+++ b/desktop-app/ui/src/gfs/__tests__/dragAdjudication.test.tsx@@ -3,6 +3,7 @@ import { type ReactNode } from 'react'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { QueryClient, QueryClientProvider } from '@tanstack/react-query'import { cleanup, renderHook } from '@testing-library/react'+import { desktopQueryKeys } from '@hooks/domain/queryKeys'import { describeGfsReadError, parseHttpStatus } from '@lib/gfsGrantErrors'import { desktopQueryDefaults } from '@lib/queryClient'import {@@ -76,7 +77,7 @@ function renderAdjudication(handleAuthorityFailure?: (message: string) => booleaconst wrapper = ({ children }: { children: ReactNode }) => (<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>)- return renderHook(+ const hook = renderHook(() =>useGfsDragAdjudication({scope: SCOPE,@@ -91,6 +92,7 @@ function renderAdjudication(handleAuthorityFailure?: (message: string) => boolea}),{ wrapper })+ return { ...hook, queryClient }}async function grantedProbes(@@ -272,6 +274,31 @@ describe('useGfsDragAdjudication — required-probe drop admission (R1-H1)', ()})})+describe('useGfsDragAdjudication — the rename probe reads a fresh observation (RP-023)', () => {+ it('re-probes the source instead of trusting a stale cached positive', async () => {+ // The numbered-rename option authorizes a mutation. A cached "write" from+ // an older observation used to answer the probe directly, so a member+ // whose write access had since been revoked was still offered the rename+ // — and the move was only refused later, by the server.+ const message = await affordancesFailureMessage(403, {+ code: 'manage_acl_required',+ message: 'write access was revoked',+ })+ probes = await grantedProbes({ 'src-1': { error: new Error(message) } })+ const { result, queryClient } = renderAdjudication()+ const key = desktopQueryKeys.gfsAffordances(SCOPE, 'src-1', 'main')++ // A minute-old observation of "write": stale, so it may not decide.+ queryClient.setQueryData(key, { held: ['write'] }, { updatedAt: Date.now() - 60_000 })+ expect(await result.current.probeSourceWrite('src-1')).toBe(false)++ // A current observation still answers without a network read: the probe+ // fixture would fail if one were made.+ queryClient.setQueryData(key, { held: ['write'] })+ expect(await result.current.probeSourceWrite('src-1')).toBe(true)+ })+})+describe('useGfsDragAdjudication — probe 401 revokes the session', () => {it('reports a 401 from the affordances probe to the fail-closed classifier', async () => {const message = await affordancesFailureMessage(401, {diff --git a/desktop-app/ui/src/gfs/__tests__/hoverBudget.test.tsx b/desktop-app/ui/src/gfs/__tests__/hoverBudget.test.tsxindex d9ee55044..da924c06d 100644--- a/desktop-app/ui/src/gfs/__tests__/hoverBudget.test.tsx+++ b/desktop-app/ui/src/gfs/__tests__/hoverBudget.test.tsx@@ -233,6 +233,30 @@ describe('gesture-owned hover budget (R1-M2)', () => {expect(decision.allowed).toBe(true)})+ it('does not let one erroring destination burn the cold-check budget (RP-022)', async () => {+ // A destination that answers nothing stays cold, so every hover over it+ // dispatched another probe and every probe spent one slot of the shared+ // budget: ONE failing destination could burn all eight and leave every+ // other target stuck on "checking".+ const h = await setup()+ h.affordances.mockImplementation(async (id: string) => {+ if (id === 'bad') throw new Error('503 upstream unavailable httpStatus=503')+ return h.bits+ })+ const done = vi.fn()+ for (let i = 0; i < DRAG_COLD_CHECK_BUDGET; i++) {+ h.result.current.first.scheduleColdCheck(target('bad'), null, done)+ await h.dwell()+ }+ // The failing target was probed once; the budget still has room for the+ // targets that answer.+ expect(h.affordances.mock.calls.map(call => call[0])).toEqual(['bad'])++ h.result.current.first.scheduleColdCheck(target('good'), null, done)+ await h.dwell()+ expect(h.affordances.mock.calls.map(call => call[0])).toContain('good')+ })+it('cancels a pending dwell when its hook unmounts', async () => {const h = await setup()const done = vi.fn()diff --git a/desktop-app/ui/src/gfs/dragAdjudication.ts b/desktop-app/ui/src/gfs/dragAdjudication.tsindex 0e159311f..5d7221ff1 100644--- a/desktop-app/ui/src/gfs/dragAdjudication.ts+++ b/desktop-app/ui/src/gfs/dragAdjudication.ts@@ -103,6 +103,21 @@ export function useGfsDragAdjudication(deps: GfsDragAdjudicationDeps) {const localGestureRef = useRef({ generation: 0, active: false })const localBudgetRef = useRef(new GfsHoverCheckBudget())const debounceTimerRef = useRef<number | null>(null)+ /**+ * The targets whose cold check already FAILED in this gesture.+ *+ * A destination that answers nothing stays cold, so every hover over it+ * dispatched a fresh probe and every probe spent one slot of the shared+ * cold-check budget. One erroring destination could therefore burn the+ * whole budget and leave every other target stuck on "checking". The+ * failure is remembered for the gesture instead: the target is probed once,+ * and the drop-time priority check is where a failed target gets a fresh+ * read (RP-022).+ */+ const failedColdTargetsRef = useRef<{ generation: number; ids: Set<string> }>({+ generation: -1,+ ids: new Set(),+ })/*** Hand a probe failure to the surface's central fail-closed classifier when@@ -218,6 +233,12 @@ export function useGfsDragAdjudication(deps: GfsDragAdjudicationDeps) {debounceTimerRef.current = window.setTimeout(() => {debounceTimerRef.current = nullif (!isCurrent()) return+ if (failedColdTargetsRef.current.generation !== localGeneration) {+ failedColdTargetsRef.current = { generation: localGeneration, ids: new Set() }+ }+ // Already failed in this gesture: probing it again would spend+ // another budget slot and still answer nothing (RP-022).+ if (failedColdTargetsRef.current.ids.has(target.resourceId)) returnconst warm =readCachedAffordances(target.resourceId) !== null &&(sourceParentId === null || readCachedAffordances(sourceParentId) !== null)@@ -237,7 +258,14 @@ export function useGfsDragAdjudication(deps: GfsDragAdjudicationDeps) {try {if (!isCurrent()) returnif (readCachedAffordances(target.resourceId) === null) {- await fetchAffordances(target.resourceId, AFFORDANCES_HOVER_STALE_MS)+ const probe = await fetchAffordances(target.resourceId, AFFORDANCES_HOVER_STALE_MS)+ if (!probe.ok) {+ // The target answered nothing: remember it for this gesture+ // and stop — the source-parent probe cannot produce a verdict+ // for a target whose own bits are unknown (RP-022).+ if (isCurrent()) failedColdTargetsRef.current.ids.add(target.resourceId)+ return+ }}if (!isCurrent()) returnif (sourceParentId !== null && readCachedAffordances(sourceParentId) === null) {@@ -442,15 +470,22 @@ export function useGfsDragAdjudication(deps: GfsDragAdjudicationDeps) {[deps, fetchAffordances, reportAuthorityFailure, resolveAncestorsUpTo])- /** Fresh (5 s) source-resource write probe for the rename policy. */+ /**+ * Fresh (5 s) source-resource write probe for the rename policy.+ *+ * The rename option authorizes a MUTATION, so it must rest on a current+ * observation. A cached "write" of any age used to answer this probe+ * directly: a member whose write access had since been revoked still got+ * the numbered-rename option offered, and the move was only refused later+ * by the server. The cache is now consulted only through the same+ * freshness window the mutation probes use (RP-023).+ */const probeSourceWrite = useCallback(async (resourceId: string): Promise<boolean> => {- const cached = readCachedAffordances(resourceId)- if (cached?.held.includes('write')) return trueconst fresh = await fetchAffordances(resourceId, AFFORDANCES_MUTATION_STALE_MS)return fresh.ok && fresh.held.includes('write')},- [fetchAffordances, readCachedAffordances]+ [fetchAffordances])return {