From b406f0a49875faf3ffd7dc5b0901ab4200e5e840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Fri, 7 Aug 2026 22:43:01 +0000 Subject: [PATCH 01/57] docs: capture frontend cache research --- ...end-query-cache-and-rotation-resilience.md | 86 +++++++++++++++++++ ...nd-frontend-query-cache-and-persistence.md | 42 +++++++++ 2 files changed, 128 insertions(+) create mode 100644 tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md create mode 100644 tasks/backlog/2026-08-07-expand-frontend-query-cache-and-persistence.md diff --git a/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md b/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md new file mode 100644 index 0000000000..5302fd6b7e --- /dev/null +++ b/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md @@ -0,0 +1,86 @@ +# Frontend Query Cache and Rotation Resilience + +## Problem + +The authenticated control-plane UI feels slow because responsive transitions and route navigation often restart component-local fetches instead of reusing already-loaded data. The clearest production symptom is phone rotation: rotating a 390×844 phone to 844×390 crosses the app's 767px breakpoint and can unmount the routed page subtree, destroying local state and triggering fresh loaders. + +The current production deployment (`71e97323ee499743df099aa5cdca9867e5a87b30`) matches the audited `main` commit, so this is present in the live code rather than only a local hypothesis. + +## Research Findings + +### Dispatched SOL research + +- `01KZF578YJ1JG4APXDA4J29EYX`: confirmed that `apps/web/src/components/AppShell.tsx` swaps structurally different mobile and desktop sibling trees. The routed `
` occupies different reconciliation positions, so a breakpoint transition discards the page/chat subtree while the root QueryClient and AuthProvider remain mounted. +- `01KZF57GTQW3Q6RW3JPP47QRM2`: recommended shared in-memory TanStack Query caching and intent prefetch first. Persisting the entire QueryClient is unsafe; any browser persistence must be a per-user allowlist with logout/account-switch cleanup, version busting, and sensitive-data exclusions. +- `01KZF57MDCMN7KT94MFSDEF5C5`: recommended converging destination reads on shared query keys before prefetching, then using bounded hover/focus/touch intent prefetch. Recommended a delayed decorative top-edge indicator for background refetches only. + +The original Instant dispatches (`01KZF559Y5BF6D5900W4RFP04C`, `01KZF55E37QM2Z8NMPD63PVQF1`, `01KZF55HMGDQKRW5EVB2QW9A4Z`) failed before agent startup because SAM attempted to clone unpushed generated branches. Corrected retries explicitly checked out remote `main`. + +### Local code evidence + +- `apps/web/src/components/AppShell.tsx` branches on `useIsMobile()`. The mobile routed `
` is the third root child; the desktop routed `
` follows the sidebar. Without stable sibling identity, React unmounts it when crossing the breakpoint. +- `apps/web/src/hooks/useProjectData.ts` uses component-local `useState`/`useEffect` loaders. `AppShell`, `Dashboard`, and `Projects` mount independent `useProjectList({ limit: 50 })` instances, causing duplicate requests and independent polling for the same data. +- `apps/web/src/pages/Project.tsx` hand-loads project detail and blocks the child outlet on the first request. A project-card prefetch would not help until the destination reads the same shared cache key. +- TanStack Query v5.101.2 is already configured in `apps/web/src/lib/query-client.ts`, but only Nodes, Workspaces, and AdminDiagnosis currently use it. +- `tasks/archive/2026-08-05-namespace-library-cache-by-user.md` documents a real cross-user metadata leak from un-namespaced `localStorage`. Generic persisted query caching must not repeat that failure. +- The service worker caches the app shell and static assets, not authenticated API responses, so it does not provide data reuse across remounts. + +### Official documentation + +- TanStack Query prefetching: https://tanstack.com/query/latest/docs/framework/react/guides/prefetching +- TanStack Query `useQuery` cache lifetime: https://tanstack.com/query/latest/docs/framework/react/reference/useQuery +- TanStack Query persistence and cache busting: https://tanstack.com/query/v5/docs/framework/react/plugins/persistQueryClient + +## UI Variants Considered + +1. **Delayed top-edge activity line** — global, layout-neutral, visible on mobile and desktop, and does not compete with page content. +2. **Compact “Refreshing” chrome pill** — clearer text but consumes scarce mobile-header space and can become noisy during polling. +3. **Per-section spinners only** — precise but inconsistent across pages and cannot cover shared prefetch/background work. + +Selected: variant 1, with a screen-reader status message. Existing local spinners remain where they already add useful section-level context. + +## Selected First PR + +This PR deliberately combines the direct rotation fix with the smallest cache/prefetch slice that has cross-UI leverage: + +- Preserve routed content identity across AppShell mobile/desktop breakpoint transitions. +- Move project list and project detail reads onto shared TanStack Query option/key factories. +- Deduplicate the project list used by AppShell, Dashboard, and Projects. +- Prefetch project detail on hover, keyboard focus, and touch intent from project cards and sidebar entries. +- Keep stale project data visible during background revalidation. +- Show a delayed, unobtrusive global indicator only when cached query data is being refreshed. +- Clear the in-memory query cache on clean auth identity transitions. +- Capture broader query migration and safe persistence as explicit follow-up work. + +## Implementation Checklist + +- [ ] Add a failing AppShell regression test proving breakpoint changes preserve child mount/state. +- [ ] Give the shared routed `
` stable identity across the mobile and desktop shell branches. +- [ ] Add shared project list/detail/GitHub-installation query keys and query options. +- [ ] Migrate `useProjectList` and `useProjectDetail` to TanStack Query while preserving their public hook contracts. +- [ ] Migrate the `Project` parent to cached detail/installation data and keep the outlet visible on background errors/refetches. +- [ ] Add bounded project-detail intent prefetch from project cards and sidebar project buttons. +- [ ] Add a delayed global background-fetch indicator above AppShell. +- [ ] Clear query data on clean signout/session-expiry/account-switch transitions, not transient auth refetch errors. +- [ ] Add unit tests for deduplication, cache reuse, stale-data preservation, auth cleanup, indicator behavior, and intent prefetch. +- [ ] Add Playwright coverage for portrait→landscape rotation, request counts, indicator rendering, overflow, and mobile/desktop screenshots. +- [ ] Update Rule 48 with the responsive-shell identity requirement. +- [ ] Run full validation, specialist reviews, staging verification, and create a draft PR without merging. + +## Acceptance Criteria + +- Rotating across 767px does not remount the routed page/chat subtree or discard its local state. +- AppShell plus Dashboard/Projects issue one initial project-list request for the shared key, not duplicate requests. +- Re-entering a recently loaded project/list surface renders cached data immediately; stale data remains visible while revalidation runs. +- Hover/focus/touch intent on a project destination populates the exact query key consumed by `Project`. +- Background revalidation shows a subtle top-edge activity cue without replacing visible content or changing layout. +- Clean auth identity changes clear query data; transient auth refetch errors preserve it. +- No generic QueryClient data is written to `localStorage` or `sessionStorage` in this PR. +- Mobile and desktop visual/behavioral checks pass with no horizontal overflow. + +## Out of Scope + +- Migrating every remaining hand-rolled loader in one PR. +- Persisting authenticated query data across full document reloads. +- Prefetching chat histories, messages, logs, diagnostics, credentials, secrets, environment values, or large file/library payloads. + diff --git a/tasks/backlog/2026-08-07-expand-frontend-query-cache-and-persistence.md b/tasks/backlog/2026-08-07-expand-frontend-query-cache-and-persistence.md new file mode 100644 index 0000000000..a051c2befd --- /dev/null +++ b/tasks/backlog/2026-08-07-expand-frontend-query-cache-and-persistence.md @@ -0,0 +1,42 @@ +# Expand Frontend Query Caching and Safe Persistence + +## Problem + +The first frontend performance PR covers responsive route preservation plus the highest-leverage project list/detail cache. Many other pages still use isolated `useState`/`useEffect` loaders, and a true full document reload still loses the in-memory QueryClient. + +## Research Basis + +- SOL research tasks `01KZF578YJ1JG4APXDA4J29EYX`, `01KZF57GTQW3Q6RW3JPP47QRM2`, and `01KZF57MDCMN7KT94MFSDEF5C5`. +- `tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md`. +- Prior cross-user browser-cache incident: `tasks/archive/2026-08-05-namespace-library-cache-by-user.md`. +- Official TanStack persistence guidance: https://tanstack.com/query/v5/docs/framework/react/plugins/persistQueryClient + +## Proposed Follow-Up + +- Inventory and rank remaining hand-rolled loaders by route frequency, payload cost, volatility, and sensitivity. +- Migrate active-task and cross-project chat summaries, then common project subpages, onto centralized query option factories. +- Add route/parent-load prefetch only after destination pages consume the exact same keys. +- Design an opt-in, authenticated-user-scoped `sessionStorage` persistence layer using `PersistQueryClientProvider`. +- Use an explicit dehydration allowlist. Start with bounded summary/reference data only. +- Version persisted data with a build/schema buster and configure `maxAge`/`gcTime` together. +- Clear persisted state before signout completes and on clean session expiry/account switch. +- Treat quota, parse, and private-mode failures as cache misses without breaking the app. + +## Never Persist Without Separate Security Review + +- Chat messages, prompt content, attachments, or agent output. +- Credentials, tokens, secrets, environment values, or connection configuration. +- Admin errors, diagnoses, logs, incident evidence, or usage/cost details. +- Node/workspace runtime details that can contain environment or infrastructure metadata. +- File/library contents or signed URLs. +- Mutation state. + +## Acceptance Criteria + +- Persisted query keys are deterministically namespaced by authenticated user and schema/build version. +- Logout, session expiry, and account switch cannot render the prior user's data, including colliding resource IDs. +- Only approved allowlisted queries are dehydrated. +- Persistence failures degrade to the normal in-memory cache. +- Tests seed foreign-user/sensitive canaries and prove they never render or remain in storage after auth transitions. +- Staging validation covers reload, offline/online, account switch, quota failure, and cache-buster behavior. + From 6f09122095f2b1f686570687c4e7293f80e60f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Fri, 7 Aug 2026 22:57:24 +0000 Subject: [PATCH 02/57] perf(web): cache project data across responsive navigation --- .claude/rules/48-stale-while-revalidate-ui.md | 12 ++ apps/web/src/App.tsx | 2 + apps/web/src/components/AppShell.tsx | 10 +- apps/web/src/components/AuthProvider.tsx | 2 + .../components/BackgroundFetchIndicator.tsx | 24 ++++ .../web/src/components/ProjectSummaryCard.tsx | 9 ++ .../web/src/components/SidebarProjectList.tsx | 13 +- apps/web/src/hooks/useProjectData.ts | 92 +++++-------- apps/web/src/lib/query-options.ts | 37 ++++++ apps/web/src/pages/Dashboard.tsx | 2 +- apps/web/src/pages/Project.tsx | 91 ++++++------- apps/web/src/pages/Projects.tsx | 2 +- apps/web/tests/unit/AppShell.test.tsx | 69 +++++++++- .../unit/BackgroundFetchIndicator.test.tsx | 60 +++++++++ apps/web/tests/unit/Project.test.tsx | 7 +- apps/web/tests/unit/ProjectPrefetch.test.tsx | 94 +++++++++++++ .../unit/components/auth-provider.test.tsx | 10 +- .../tests/unit/hooks/useProjectData.test.tsx | 124 ++++++++++++++++++ apps/web/tests/unit/pages/project.test.tsx | 5 +- ...end-query-cache-and-rotation-resilience.md | 21 ++- 20 files changed, 549 insertions(+), 137 deletions(-) create mode 100644 apps/web/src/components/BackgroundFetchIndicator.tsx create mode 100644 apps/web/src/lib/query-options.ts create mode 100644 apps/web/tests/unit/BackgroundFetchIndicator.test.tsx create mode 100644 apps/web/tests/unit/ProjectPrefetch.test.tsx create mode 100644 apps/web/tests/unit/hooks/useProjectData.test.tsx diff --git a/.claude/rules/48-stale-while-revalidate-ui.md b/.claude/rules/48-stale-while-revalidate-ui.md index a4f9268510..ad065080ca 100644 --- a/.claude/rules/48-stale-while-revalidate-ui.md +++ b/.claude/rules/48-stale-while-revalidate-ui.md @@ -100,6 +100,17 @@ modifying an existing one, use `useQuery`/`useMutation` instead of hand-rolled Hand-rolled loaders are only acceptable for genuinely non-query state (WebSockets, streaming, imperative one-shots). +### 5. Responsive shells MUST preserve routed subtree identity + +Changing between mobile and desktop chrome must not remount the routed page, +chat, composer, or media subtree. When breakpoint branches use different +sibling structures, give shared stateful slots stable keys (or keep one shared +slot outside the branches) so React can reconcile them across positions. + +Every responsive shell change must include a portrait-to-landscape regression +test that crosses the actual breakpoint and proves local child state and mount +identity survive. A static test at one viewport is insufficient. + ## Interaction-Effect Trace Requirement When adding any state change that a `useEffect` in the same tree observes @@ -118,3 +129,4 @@ Before committing UI data-fetching or context changes: - [ ] Spinners gate only on "no data yet", never on "refetch in flight" - [ ] Mutations invalidate/refresh data without unmounting visible content - [ ] New fetch surfaces use TanStack Query (or document why not) +- [ ] Breakpoint changes preserve routed and media subtree identity diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index eeb4abcb49..275e07cdc2 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -4,6 +4,7 @@ import { BrowserRouter, Navigate, Outlet, Route, Routes } from 'react-router'; import { AppShell } from './components/AppShell'; import { AuthProvider, useAuth } from './components/AuthProvider'; +import { BackgroundFetchIndicator } from './components/BackgroundFetchIndicator'; import { ErrorBoundary } from './components/ErrorBoundary'; import { PageViewTracker } from './components/PageViewTracker'; import { ProtectedRoute } from './components/ProtectedRoute'; @@ -125,6 +126,7 @@ export default function App() { + diff --git a/apps/web/src/components/AppShell.tsx b/apps/web/src/components/AppShell.tsx index ed50f93751..cb7dd98c89 100644 --- a/apps/web/src/components/AppShell.tsx +++ b/apps/web/src/components/AppShell.tsx @@ -292,11 +292,13 @@ export function AppShell({ children }: AppShellProps) { -
+
{children ?? }
- +
+ +
{drawerOpen && user && ( )} -
+
{children ?? }
-
+
diff --git a/apps/web/src/components/AuthProvider.tsx b/apps/web/src/components/AuthProvider.tsx index 2340039377..f75b522c85 100644 --- a/apps/web/src/components/AuthProvider.tsx +++ b/apps/web/src/components/AuthProvider.tsx @@ -5,6 +5,7 @@ import { setUserId } from '../lib/analytics'; import { GITHUB_REAUTH_REQUIRED_EVENT } from '../lib/api/client'; import { signOut, useSession } from '../lib/auth'; import { buildLibraryCacheNamespace, clearLegacyLibraryCache, clearLibraryCache } from '../lib/library-cache'; +import { queryClient } from '../lib/query-client'; interface User { id: string; @@ -88,6 +89,7 @@ export function AuthProvider({ children }: AuthProviderProps) { } if (previousNamespace !== nextNamespace) { + queryClient.clear(); if (previousNamespace) clearLibraryCache(previousNamespace); clearLegacyLibraryCache(); previousCacheNamespaceRef.current = nextNamespace; diff --git a/apps/web/src/components/BackgroundFetchIndicator.tsx b/apps/web/src/components/BackgroundFetchIndicator.tsx new file mode 100644 index 0000000000..e7b6dbae5d --- /dev/null +++ b/apps/web/src/components/BackgroundFetchIndicator.tsx @@ -0,0 +1,24 @@ +import { useIsFetching } from '@tanstack/react-query'; + +export function BackgroundFetchIndicator() { + const backgroundFetchCount = useIsFetching({ + predicate: (query) => query.state.data !== undefined, + }); + const isRefreshing = backgroundFetchCount > 0; + + return ( + <> + ); } - diff --git a/apps/web/src/hooks/useProjectData.ts b/apps/web/src/hooks/useProjectData.ts index 8e4f5bed9c..e7e6cbf57f 100644 --- a/apps/web/src/hooks/useProjectData.ts +++ b/apps/web/src/hooks/useProjectData.ts @@ -1,11 +1,9 @@ -import type { ProjectDetailResponse,ProjectSummary } from '@simple-agent-manager/shared'; -import { useCallback, useEffect, useRef,useState } from 'react'; +import type { ProjectDetailResponse, ProjectSummary } from '@simple-agent-manager/shared'; +import { useQuery } from '@tanstack/react-query'; -import * as api from '../lib/api'; +import { projectDetailQueryOptions, projectListQueryOptions } from '../lib/query-options'; interface UseProjectListOptions { - status?: string; - sort?: string; limit?: number; pollInterval?: number; } @@ -19,40 +17,21 @@ interface UseProjectListResult { } export function useProjectList(options: UseProjectListOptions = {}): UseProjectListResult { - const { status, sort, limit, pollInterval = 30000 } = options; - const [projects, setProjects] = useState([]); - const [loading, setLoading] = useState(true); - const [isRefreshing, setIsRefreshing] = useState(false); - const [error, setError] = useState(null); - const hasLoadedRef = useRef(false); - - const fetchProjects = useCallback(async () => { - if (hasLoadedRef.current) { - setIsRefreshing(true); - } - try { - const result = await api.listProjects(limit); - // The API now returns ProjectSummary objects via ListProjectsResponse - setProjects(result.projects as unknown as ProjectSummary[]); - setError(null); - } catch (err) { - setError(err instanceof Error ? err.message : 'Failed to load projects'); - } finally { - hasLoadedRef.current = true; - setLoading(false); - setIsRefreshing(false); - } - }, [status, sort, limit]); - - useEffect(() => { - fetchProjects(); - if (pollInterval > 0) { - const interval = setInterval(fetchProjects, pollInterval); - return () => clearInterval(interval); - } - }, [fetchProjects, pollInterval]); - - return { projects, loading, isRefreshing, error, refresh: fetchProjects }; + const { limit, pollInterval = 30000 } = options; + const query = useQuery({ + ...projectListQueryOptions(limit), + refetchInterval: pollInterval > 0 ? pollInterval : false, + }); + + return { + projects: (query.data ?? []) as ProjectSummary[], + loading: query.isPending && query.data === undefined, + isRefreshing: query.isFetching && query.data !== undefined, + error: query.error instanceof Error ? query.error.message : query.error ? 'Failed to load projects' : null, + refresh: () => { + void query.refetch(); + }, + }; } interface UseProjectDetailResult { @@ -63,26 +42,17 @@ interface UseProjectDetailResult { } export function useProjectDetail(projectId: string | undefined): UseProjectDetailResult { - const [project, setProject] = useState(null); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - - const fetchProject = useCallback(async () => { - if (!projectId) return; - try { - const result = await api.getProject(projectId); - setProject(result as UseProjectDetailResult['project']); - setError(null); - } catch (err) { - setError(err instanceof Error ? err.message : 'Failed to load project'); - } finally { - setLoading(false); - } - }, [projectId]); - - useEffect(() => { - fetchProject(); - }, [fetchProject]); - - return { project, loading, error, refresh: fetchProject }; + const query = useQuery({ + ...projectDetailQueryOptions(projectId ?? ''), + enabled: Boolean(projectId), + }); + + return { + project: (query.data ?? null) as UseProjectDetailResult['project'], + loading: Boolean(projectId) && query.isPending && query.data === undefined, + error: query.error instanceof Error ? query.error.message : query.error ? 'Failed to load project' : null, + refresh: () => { + void query.refetch(); + }, + }; } diff --git a/apps/web/src/lib/query-options.ts b/apps/web/src/lib/query-options.ts new file mode 100644 index 0000000000..5a88317b1b --- /dev/null +++ b/apps/web/src/lib/query-options.ts @@ -0,0 +1,37 @@ +import { queryOptions } from '@tanstack/react-query'; + +import { getProject, listGitHubInstallations, listProjects } from './api'; + +export const projectQueryKeys = { + all: ['projects'] as const, + lists: () => [...projectQueryKeys.all, 'list'] as const, + list: (limit?: number) => [...projectQueryKeys.lists(), { limit: limit ?? null }] as const, + details: () => [...projectQueryKeys.all, 'detail'] as const, + detail: (projectId: string) => [...projectQueryKeys.details(), projectId] as const, +}; + +export const githubQueryKeys = { + all: ['github'] as const, + installations: () => [...githubQueryKeys.all, 'installations'] as const, +}; + +export function projectListQueryOptions(limit?: number) { + return queryOptions({ + queryKey: projectQueryKeys.list(limit), + queryFn: async () => (await listProjects(limit)).projects, + }); +} + +export function projectDetailQueryOptions(projectId: string) { + return queryOptions({ + queryKey: projectQueryKeys.detail(projectId), + queryFn: () => getProject(projectId), + }); +} + +export function githubInstallationsQueryOptions() { + return queryOptions({ + queryKey: githubQueryKeys.installations(), + queryFn: listGitHubInstallations, + }); +} diff --git a/apps/web/src/pages/Dashboard.tsx b/apps/web/src/pages/Dashboard.tsx index 4e6693fc31..5d7e7e14f6 100644 --- a/apps/web/src/pages/Dashboard.tsx +++ b/apps/web/src/pages/Dashboard.tsx @@ -12,7 +12,7 @@ export function Dashboard() { const navigate = useNavigate(); const { tasks, loading: tasksLoading, isRefreshing: tasksRefreshing, error: tasksError, refresh: refreshTasks } = useActiveTasks(); - const { projects, loading: projectsLoading, isRefreshing: projectsRefreshing, error: projectsError, refresh: refreshProjects } = useProjectList({ sort: 'last_activity', limit: 50 }); + const { projects, loading: projectsLoading, isRefreshing: projectsRefreshing, error: projectsError, refresh: refreshProjects } = useProjectList({ limit: 50 }); return ( (null); - const [installations, setInstallations] = useState([]); - const [projectLoading, setProjectLoading] = useState(true); - const [error, setError] = useState(null); + const queryClient = useQueryClient(); + const projectQuery = useQuery({ + ...projectDetailQueryOptions(projectId ?? ''), + enabled: Boolean(projectId), + }); + const installationsQuery = useQuery(githubInstallationsQueryOptions()); + const project = (projectQuery.data ?? null) as ProjectDetailResponse | null; + const installations = useMemo( + () => (installationsQuery.data ?? []) as GitHubInstallation[], + [installationsQuery.data], + ); + const refetchProject = projectQuery.refetch; + const projectLoading = Boolean(projectId) && projectQuery.isPending && project === null; + const error = projectQuery.error instanceof Error + ? projectQuery.error.message + : projectQuery.error + ? 'Failed to load project' + : null; // Chat routes get a full-bleed layout (no PageLayout wrapper) const isChatRoute = /\/(chat|agent)(\/|$)/.test(location.pathname); - // Track whether we have successfully loaded data at least once for the - // current projectId. After the first load, reloads (e.g. after saving - // settings) skip the loading spinner so the existing Outlet tree stays - // mounted (stale-while-revalidate). - const hasLoadedForIdRef = useRef(null); - const loadProject = useCallback(async () => { - if (!projectId) return; - try { - setError(null); - // Only show the full-screen spinner on the very first load for this - // projectId. Subsequent reloads keep existing content visible. - if (hasLoadedForIdRef.current !== projectId) { - setProjectLoading(true); - } - setProject(await getProject(projectId)); - hasLoadedForIdRef.current = projectId; - } catch (err) { - setError(err instanceof Error ? err.message : 'Failed to load project'); - hasLoadedForIdRef.current = projectId; - } finally { - setProjectLoading(false); - } - }, [projectId]); - - useEffect(() => { void loadProject(); }, [loadProject]); - - useEffect(() => { - void listGitHubInstallations() - .then((response) => setInstallations(response)) - .catch(() => setInstallations([])); - }, []); + await Promise.all([ + refetchProject(), + queryClient.invalidateQueries({ queryKey: projectQueryKeys.lists() }), + ]); + }, [queryClient, refetchProject]); // Push project name up to AppShell for sidebar display useEffect(() => { @@ -63,7 +55,7 @@ export function Project() { const contextValue = useMemo( () => ({ - projectId: projectId!, + projectId: projectId ?? '', project, installations, reload: loadProject, @@ -90,18 +82,21 @@ export function Project() { Loading project...
- ) : error ? ( -
- setError(null)}>{error} -
) : !project ? (
- Project not found. + {error ?? 'Project not found.'}
) : ( - - - + <> + {error && ( +
+ {error} +
+ )} + + + + )} ); @@ -122,7 +117,7 @@ export function Project() { > {error && (
- setError(null)}>{error} + {error}
)} diff --git a/apps/web/src/pages/Projects.tsx b/apps/web/src/pages/Projects.tsx index 3553588777..2bcdce6a85 100644 --- a/apps/web/src/pages/Projects.tsx +++ b/apps/web/src/pages/Projects.tsx @@ -8,7 +8,7 @@ import { deleteProject } from '../lib/api'; export function Projects() { const navigate = useNavigate(); - const { projects, loading, isRefreshing, error, refresh } = useProjectList({ sort: 'last_activity', limit: 50 }); + const { projects, loading, isRefreshing, error, refresh } = useProjectList({ limit: 50 }); const [deleteError, setDeleteError] = useState(null); const handleDelete = async (id: string) => { diff --git a/apps/web/tests/unit/AppShell.test.tsx b/apps/web/tests/unit/AppShell.test.tsx index 81599224a4..dc800ac979 100644 --- a/apps/web/tests/unit/AppShell.test.tsx +++ b/apps/web/tests/unit/AppShell.test.tsx @@ -1,16 +1,25 @@ import { act, fireEvent, render as baseRender, type RenderOptions, screen, within } from '@testing-library/react'; -import type { ReactElement } from 'react'; +import { type ReactElement, useEffect, useState } from 'react'; import { MemoryRouter, useNavigate } from 'react-router'; import { afterEach, beforeAll, beforeEach,describe, expect, it, vi } from 'vitest'; import { AppShell } from '../../src/components/AppShell'; import { GLOBAL_NAV_ITEMS, PROJECT_NAV_ITEMS } from '../../src/components/NavSidebar'; import { ThemeProvider } from '../../src/contexts/ThemeContext'; +import { QueryTestWrapper } from '../test-utils/query-test-utils'; // AppShell renders the shared (desktop sidebar footer and the // mobile drawer), which calls useTheme and requires a ThemeProvider ancestor. function render(ui: ReactElement, options?: Omit) { - return baseRender(ui, { wrapper: ThemeProvider, ...options }); + function Wrapper({ children }: { children: ReactElement }) { + return ( + + {children} + + ); + } + + return baseRender(ui, { wrapper: Wrapper, ...options }); } // Mutable auth state so individual tests can override @@ -21,6 +30,14 @@ let mockAuthState: Record = { // jsdom does not implement window.matchMedia — stub it for useIsMobile hook let matchMediaMatches = false; +const matchMediaListeners = new Set<(event: MediaQueryListEvent) => void>(); + +function setMatchMediaMatches(matches: boolean) { + matchMediaMatches = matches; + const event = { matches, media: '(max-width: 767px)' } as MediaQueryListEvent; + for (const listener of matchMediaListeners) listener(event); +} + beforeAll(() => { Object.defineProperty(window, 'matchMedia', { writable: true, @@ -30,8 +47,16 @@ beforeAll(() => { onchange: null, addListener: vi.fn(), removeListener: vi.fn(), - addEventListener: vi.fn(), - removeEventListener: vi.fn(), + addEventListener: vi.fn( + (_type: string, listener: (event: MediaQueryListEvent) => void) => { + matchMediaListeners.add(listener); + }, + ), + removeEventListener: vi.fn( + (_type: string, listener: (event: MediaQueryListEvent) => void) => { + matchMediaListeners.delete(listener); + }, + ), dispatchEvent: vi.fn(), })), }); @@ -81,6 +106,7 @@ vi.mock('../../src/components/GlobalCommandPalette', () => ({ })); beforeEach(() => { + matchMediaListeners.clear(); matchMediaMatches = false; mockAuthState = { user: { name: 'Test User', email: 'test@example.com', image: null }, @@ -419,6 +445,41 @@ describe('AppShell (mobile)', () => { expect(screen.queryByRole('dialog', { name: 'Navigation menu' })).not.toBeInTheDocument(); vi.useRealTimers(); }); + + it('preserves routed child state when rotation crosses the mobile breakpoint', () => { + let mountCount = 0; + + function StatefulPage() { + const [draft, setDraft] = useState(''); + useEffect(() => { + mountCount += 1; + }, []); + + return ( + + ); + } + + render( + + + + + , + ); + + fireEvent.change(screen.getByLabelText('Draft'), { target: { value: 'keep this' } }); + + act(() => { + setMatchMediaMatches(false); + }); + + expect(screen.getByLabelText('Draft')).toHaveValue('keep this'); + expect(mountCount).toBe(1); + }); }); describe('AppShell (Focus Mode — desktop)', () => { diff --git a/apps/web/tests/unit/BackgroundFetchIndicator.test.tsx b/apps/web/tests/unit/BackgroundFetchIndicator.test.tsx new file mode 100644 index 0000000000..70f7f499b4 --- /dev/null +++ b/apps/web/tests/unit/BackgroundFetchIndicator.test.tsx @@ -0,0 +1,60 @@ +import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query'; +import { act, render, screen, waitFor } from '@testing-library/react'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import { BackgroundFetchIndicator } from '../../src/components/BackgroundFetchIndicator'; + +const QUERY_KEY = ['indicator-test'] as const; + +function QueryConsumer({ queryFn }: { queryFn: () => Promise }) { + const query = useQuery({ queryKey: QUERY_KEY, queryFn }); + return {query.data ?? 'No data'}; +} + +describe('BackgroundFetchIndicator', () => { + let queryClient: QueryClient; + + beforeEach(() => { + queryClient = new QueryClient({ + defaultOptions: { queries: { retry: false, staleTime: 60_000 } }, + }); + }); + + it('only becomes visible for a delayed background refresh with cached data', async () => { + const queryFn = vi.fn().mockResolvedValue('Cached data'); + render( + + + + , + ); + + const indicator = screen.getByTestId('background-fetch-indicator'); + expect(indicator).toHaveAttribute('data-refreshing', 'false'); + expect(indicator).toHaveClass('opacity-0'); + expect(await screen.findByText('Cached data')).toBeInTheDocument(); + + let resolveRefresh: ((value: string) => void) | undefined; + queryFn.mockImplementationOnce( + () => new Promise((resolve) => { + resolveRefresh = resolve; + }), + ); + + act(() => { + void queryClient.invalidateQueries({ queryKey: QUERY_KEY }); + }); + + await waitFor(() => expect(indicator).toHaveAttribute('data-refreshing', 'true')); + expect(indicator).toHaveClass('opacity-100', 'delay-150'); + expect(screen.getByRole('status')).toHaveTextContent('Refreshing data'); + expect(screen.getByText('Cached data')).toBeInTheDocument(); + + await act(async () => { + resolveRefresh?.('Fresh data'); + }); + + await waitFor(() => expect(indicator).toHaveAttribute('data-refreshing', 'false')); + expect(screen.getByText('Fresh data')).toBeInTheDocument(); + }); +}); diff --git a/apps/web/tests/unit/Project.test.tsx b/apps/web/tests/unit/Project.test.tsx index 0d1bb7fefb..f659c8c250 100644 --- a/apps/web/tests/unit/Project.test.tsx +++ b/apps/web/tests/unit/Project.test.tsx @@ -1,10 +1,11 @@ -import { act, render, screen, waitFor } from '@testing-library/react'; +import { act, screen, waitFor } from '@testing-library/react'; import { useEffect } from 'react'; import { MemoryRouter, Route,Routes } from 'react-router'; import { beforeEach, describe, expect, it, vi } from 'vitest'; import { Project } from '../../src/pages/Project'; import { useProjectContext } from '../../src/pages/ProjectContext'; +import { renderWithQuery } from '../test-utils/query-test-utils'; // Mock AuthProvider vi.mock('../../src/components/AuthProvider', () => ({ @@ -55,7 +56,7 @@ const defaultProject = { }; function renderProject(path = '/projects/proj-1/overview') { - return render( + return renderWithQuery( }> @@ -137,7 +138,7 @@ describe('Project reload (stale-while-revalidate)', () => { // Initial load resolves immediately mockGetProject.mockResolvedValueOnce(defaultProject); - const { findByTestId, getByTestId } = render( + const { findByTestId, getByTestId } = renderWithQuery( }> diff --git a/apps/web/tests/unit/ProjectPrefetch.test.tsx b/apps/web/tests/unit/ProjectPrefetch.test.tsx new file mode 100644 index 0000000000..978e90faf2 --- /dev/null +++ b/apps/web/tests/unit/ProjectPrefetch.test.tsx @@ -0,0 +1,94 @@ +import type { ProjectSummary } from '@simple-agent-manager/shared'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { MemoryRouter } from 'react-router'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + +import { ProjectSummaryCard } from '../../src/components/ProjectSummaryCard'; +import { SidebarProjectList } from '../../src/components/SidebarProjectList'; +import { queryClient } from '../../src/lib/query-client'; +import { projectDetailQueryOptions, projectQueryKeys } from '../../src/lib/query-options'; + +const mocks = vi.hoisted(() => ({ + getProject: vi.fn(), +})); + +vi.mock('../../src/lib/api', async (importOriginal) => ({ + ...(await importOriginal()), + getProject: mocks.getProject, +})); + +const PROJECT: ProjectSummary = { + id: 'project-1', + userId: 'user-1', + name: 'Prefetched project', + description: null, + installationId: 'installation-1', + repository: 'acme/prefetched-project', + defaultBranch: 'main', + status: 'active', + activeWorkspaceCount: 0, + activeSessionCount: 0, + lastActivityAt: '2026-08-07T20:00:00.000Z', + taskCountsByStatus: {}, + linkedWorkspaces: [], + createdAt: '2026-08-07T19:00:00.000Z', + updatedAt: '2026-08-07T20:00:00.000Z', +}; + +describe('project detail intent prefetch', () => { + beforeEach(() => { + queryClient.clear(); + mocks.getProject.mockReset(); + mocks.getProject.mockResolvedValue(PROJECT); + }); + + afterEach(() => { + queryClient.clear(); + }); + + it('prefetches the exact destination query from a project-card hover', async () => { + render( + + + , + ); + + const projectCard = screen.getByText('Prefetched project').closest('[role="button"]'); + if (!projectCard) throw new Error('Project card was not rendered'); + fireEvent.mouseEnter(projectCard); + + await waitFor(() => expect(mocks.getProject).toHaveBeenCalledWith('project-1')); + expect(queryClient.getQueryData(projectQueryKeys.detail('project-1'))).toEqual(PROJECT); + + await queryClient.fetchQuery(projectDetailQueryOptions('project-1')); + expect(mocks.getProject).toHaveBeenCalledTimes(1); + }); + + it('prefetches on keyboard focus from the sidebar destination', async () => { + render( + , + ); + + fireEvent.focus(screen.getByRole('button', { name: /Prefetched project/ })); + + await waitFor(() => expect(mocks.getProject).toHaveBeenCalledWith('project-1')); + }); + + it('prefetches on touch intent from a project card', async () => { + render( + + + , + ); + + const projectCard = screen.getByText('Prefetched project').closest('[role="button"]'); + if (!projectCard) throw new Error('Project card was not rendered'); + fireEvent.touchStart(projectCard); + + await waitFor(() => expect(mocks.getProject).toHaveBeenCalledWith('project-1')); + }); +}); diff --git a/apps/web/tests/unit/components/auth-provider.test.tsx b/apps/web/tests/unit/components/auth-provider.test.tsx index 4d42d244f1..ccd36e3d90 100644 --- a/apps/web/tests/unit/components/auth-provider.test.tsx +++ b/apps/web/tests/unit/components/auth-provider.test.tsx @@ -4,11 +4,12 @@ import { beforeEach,describe, expect, it, vi } from 'vitest'; import { AuthProvider, useAuth } from '../../../src/components/AuthProvider'; import { GITHUB_REAUTH_REQUIRED_EVENT } from '../../../src/lib/api/client'; -const { mockUseSession, mockSignOut, mockClearLibraryCache, mockClearLegacyLibraryCache } = vi.hoisted(() => ({ +const { mockUseSession, mockSignOut, mockClearLibraryCache, mockClearLegacyLibraryCache, mockClearQueryCache } = vi.hoisted(() => ({ mockUseSession: vi.fn(), mockSignOut: vi.fn(), mockClearLibraryCache: vi.fn(), mockClearLegacyLibraryCache: vi.fn(), + mockClearQueryCache: vi.fn(), })); vi.mock('../../../src/lib/auth', () => ({ @@ -22,6 +23,10 @@ vi.mock('../../../src/lib/library-cache', async (importOriginal) => ({ clearLegacyLibraryCache: mockClearLegacyLibraryCache, })); +vi.mock('../../../src/lib/query-client', () => ({ + queryClient: { clear: mockClearQueryCache }, +})); + function AuthConsumer() { const auth = useAuth(); return ( @@ -229,6 +234,7 @@ describe('AuthProvider', () => { expect(screen.getByTestId('authenticated')).toHaveTextContent('true'); expect(mockClearLibraryCache).not.toHaveBeenCalled(); expect(mockClearLegacyLibraryCache).toHaveBeenCalledTimes(1); + expect(mockClearQueryCache).not.toHaveBeenCalled(); }); it('clears the previous user namespace and legacy cache on clean null session expiry', () => { @@ -257,6 +263,7 @@ describe('AuthProvider', () => { expect(screen.getByTestId('authenticated')).toHaveTextContent('false'); expect(mockClearLibraryCache).toHaveBeenCalledWith('user:u1'); expect(mockClearLegacyLibraryCache).toHaveBeenCalledOnce(); + expect(mockClearQueryCache).toHaveBeenCalledOnce(); }); it('clears the previous user namespace on account switch without clearing the new user cache', () => { @@ -290,6 +297,7 @@ describe('AuthProvider', () => { expect(mockClearLibraryCache).toHaveBeenCalledWith('user:u1'); expect(mockClearLibraryCache).not.toHaveBeenCalledWith('user:u2'); expect(mockClearLegacyLibraryCache).toHaveBeenCalledOnce(); + expect(mockClearQueryCache).toHaveBeenCalledOnce(); }); it('shows a GitHub reauth prompt and signs out when reconnect is clicked', () => { diff --git a/apps/web/tests/unit/hooks/useProjectData.test.tsx b/apps/web/tests/unit/hooks/useProjectData.test.tsx new file mode 100644 index 0000000000..a12e1fcb4e --- /dev/null +++ b/apps/web/tests/unit/hooks/useProjectData.test.tsx @@ -0,0 +1,124 @@ +import type { ProjectSummary } from '@simple-agent-manager/shared'; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { act, renderHook, waitFor } from '@testing-library/react'; +import type { ReactNode } from 'react'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import { useProjectList } from '../../../src/hooks/useProjectData'; + +const mocks = vi.hoisted(() => ({ + listProjects: vi.fn(), +})); + +vi.mock('../../../src/lib/api', async (importOriginal) => ({ + ...(await importOriginal()), + listProjects: mocks.listProjects, +})); + +const PROJECT: ProjectSummary = { + id: 'project-1', + userId: 'user-1', + name: 'Cached project', + description: null, + installationId: 'installation-1', + repository: 'acme/cached-project', + defaultBranch: 'main', + status: 'active', + activeWorkspaceCount: 1, + activeSessionCount: 0, + lastActivityAt: '2026-08-07T20:00:00.000Z', + taskCountsByStatus: {}, + linkedWorkspaces: [], + createdAt: '2026-08-07T19:00:00.000Z', + updatedAt: '2026-08-07T20:00:00.000Z', +}; + +function createWrapper() { + const client = new QueryClient({ + defaultOptions: { + queries: { + retry: false, + staleTime: 60_000, + }, + }, + }); + + function Wrapper({ children }: { children: ReactNode }) { + return {children}; + } + + return { client, Wrapper }; +} + +describe('useProjectList query cache', () => { + beforeEach(() => { + vi.clearAllMocks(); + mocks.listProjects.mockResolvedValue({ projects: [PROJECT] }); + }); + + it('deduplicates concurrent consumers of the same project list', async () => { + const { Wrapper } = createWrapper(); + const { result } = renderHook( + () => ({ + sidebar: useProjectList({ limit: 50, pollInterval: 0 }), + page: useProjectList({ limit: 50, pollInterval: 0 }), + }), + { wrapper: Wrapper }, + ); + + await waitFor(() => { + expect(result.current.sidebar.projects).toEqual([PROJECT]); + expect(result.current.page.projects).toEqual([PROJECT]); + }); + expect(mocks.listProjects).toHaveBeenCalledTimes(1); + }); + + it('reuses fresh cached data when a consumer remounts', async () => { + const { Wrapper } = createWrapper(); + const first = renderHook( + () => useProjectList({ limit: 50, pollInterval: 0 }), + { wrapper: Wrapper }, + ); + await waitFor(() => expect(first.result.current.projects).toEqual([PROJECT])); + first.unmount(); + + const second = renderHook( + () => useProjectList({ limit: 50, pollInterval: 0 }), + { wrapper: Wrapper }, + ); + + expect(second.result.current.projects).toEqual([PROJECT]); + expect(second.result.current.loading).toBe(false); + expect(mocks.listProjects).toHaveBeenCalledTimes(1); + }); + + it('keeps cached projects visible during a background refresh', async () => { + const { Wrapper } = createWrapper(); + const { result } = renderHook( + () => useProjectList({ limit: 50, pollInterval: 0 }), + { wrapper: Wrapper }, + ); + await waitFor(() => expect(result.current.projects).toEqual([PROJECT])); + + let resolveRefresh: ((value: { projects: ProjectSummary[] }) => void) | undefined; + mocks.listProjects.mockImplementationOnce( + () => new Promise((resolve) => { + resolveRefresh = resolve; + }), + ); + + act(() => { + result.current.refresh(); + }); + + await waitFor(() => expect(result.current.isRefreshing).toBe(true)); + expect(result.current.projects).toEqual([PROJECT]); + expect(result.current.loading).toBe(false); + + await act(async () => { + resolveRefresh?.({ projects: [{ ...PROJECT, name: 'Updated project' }] }); + }); + + await waitFor(() => expect(result.current.projects[0]?.name).toBe('Updated project')); + }); +}); diff --git a/apps/web/tests/unit/pages/project.test.tsx b/apps/web/tests/unit/pages/project.test.tsx index 5acf9f3a5c..21bdcac9b5 100644 --- a/apps/web/tests/unit/pages/project.test.tsx +++ b/apps/web/tests/unit/pages/project.test.tsx @@ -1,8 +1,9 @@ -import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { fireEvent, screen, waitFor } from '@testing-library/react'; import { MemoryRouter, Navigate, Route, Routes } from 'react-router'; import { beforeEach, describe, expect, it, vi } from 'vitest'; import { ToastProvider } from '../../../src/hooks/useToast'; +import { renderWithQuery } from '../../test-utils/query-test-utils'; const mocks = vi.hoisted(() => ({ getProject: vi.fn(), @@ -101,7 +102,7 @@ import { import { ProjectTasks } from '../../../src/pages/ProjectTasks'; function renderProjectPage(path = '/projects/proj-1/tasks') { - return render( + return renderWithQuery( diff --git a/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md b/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md index 5302fd6b7e..378aea9d8d 100644 --- a/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md +++ b/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md @@ -54,17 +54,17 @@ This PR deliberately combines the direct rotation fix with the smallest cache/pr ## Implementation Checklist -- [ ] Add a failing AppShell regression test proving breakpoint changes preserve child mount/state. -- [ ] Give the shared routed `
` stable identity across the mobile and desktop shell branches. -- [ ] Add shared project list/detail/GitHub-installation query keys and query options. -- [ ] Migrate `useProjectList` and `useProjectDetail` to TanStack Query while preserving their public hook contracts. -- [ ] Migrate the `Project` parent to cached detail/installation data and keep the outlet visible on background errors/refetches. -- [ ] Add bounded project-detail intent prefetch from project cards and sidebar project buttons. -- [ ] Add a delayed global background-fetch indicator above AppShell. -- [ ] Clear query data on clean signout/session-expiry/account-switch transitions, not transient auth refetch errors. -- [ ] Add unit tests for deduplication, cache reuse, stale-data preservation, auth cleanup, indicator behavior, and intent prefetch. +- [x] Add a failing AppShell regression test proving breakpoint changes preserve child mount/state. +- [x] Give the shared routed `
` stable identity across the mobile and desktop shell branches. +- [x] Add shared project list/detail/GitHub-installation query keys and query options. +- [x] Migrate `useProjectList` and `useProjectDetail` to TanStack Query while preserving their public hook contracts. +- [x] Migrate the `Project` parent to cached detail/installation data and keep the outlet visible on background errors/refetches. +- [x] Add bounded project-detail intent prefetch from project cards and sidebar project buttons. +- [x] Add a delayed global background-fetch indicator above AppShell. +- [x] Clear query data on clean signout/session-expiry/account-switch transitions, not transient auth refetch errors. +- [x] Add unit tests for deduplication, cache reuse, stale-data preservation, auth cleanup, indicator behavior, and intent prefetch. - [ ] Add Playwright coverage for portrait→landscape rotation, request counts, indicator rendering, overflow, and mobile/desktop screenshots. -- [ ] Update Rule 48 with the responsive-shell identity requirement. +- [x] Update Rule 48 with the responsive-shell identity requirement. - [ ] Run full validation, specialist reviews, staging verification, and create a draft PR without merging. ## Acceptance Criteria @@ -83,4 +83,3 @@ This PR deliberately combines the direct rotation fix with the smallest cache/pr - Migrating every remaining hand-rolled loader in one PR. - Persisting authenticated query data across full document reloads. - Prefetching chat histories, messages, logs, diagnostics, credentials, secrets, environment values, or large file/library payloads. - From eadba8a8d69b6bc242db9ebe93b40042c4ee8520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Fri, 7 Aug 2026 23:09:44 +0000 Subject: [PATCH 03/57] test(web): audit responsive cache behavior --- apps/web/src/hooks/useProjectData.ts | 2 +- apps/web/src/lib/query-options.ts | 3 +- .../playwright/frontend-cache-audit.spec.ts | 194 ++++++++++++++++++ ...end-query-cache-and-rotation-resilience.md | 2 +- 4 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 apps/web/tests/playwright/frontend-cache-audit.spec.ts diff --git a/apps/web/src/hooks/useProjectData.ts b/apps/web/src/hooks/useProjectData.ts index e7e6cbf57f..bfd30b06c4 100644 --- a/apps/web/src/hooks/useProjectData.ts +++ b/apps/web/src/hooks/useProjectData.ts @@ -24,7 +24,7 @@ export function useProjectList(options: UseProjectListOptions = {}): UseProjectL }); return { - projects: (query.data ?? []) as ProjectSummary[], + projects: query.data ?? [], loading: query.isPending && query.data === undefined, isRefreshing: query.isFetching && query.data !== undefined, error: query.error instanceof Error ? query.error.message : query.error ? 'Failed to load projects' : null, diff --git a/apps/web/src/lib/query-options.ts b/apps/web/src/lib/query-options.ts index 5a88317b1b..f9fced10c8 100644 --- a/apps/web/src/lib/query-options.ts +++ b/apps/web/src/lib/query-options.ts @@ -1,3 +1,4 @@ +import type { ProjectSummary } from '@simple-agent-manager/shared'; import { queryOptions } from '@tanstack/react-query'; import { getProject, listGitHubInstallations, listProjects } from './api'; @@ -18,7 +19,7 @@ export const githubQueryKeys = { export function projectListQueryOptions(limit?: number) { return queryOptions({ queryKey: projectQueryKeys.list(limit), - queryFn: async () => (await listProjects(limit)).projects, + queryFn: async () => (await listProjects(limit)).projects as unknown as ProjectSummary[], }); } diff --git a/apps/web/tests/playwright/frontend-cache-audit.spec.ts b/apps/web/tests/playwright/frontend-cache-audit.spec.ts new file mode 100644 index 0000000000..51eb5a5c08 --- /dev/null +++ b/apps/web/tests/playwright/frontend-cache-audit.spec.ts @@ -0,0 +1,194 @@ +import { expect, type Page, type Route, test } from '@playwright/test'; + +import { assertNoOverflow, makeMockUser, screenshot } from './audit-helpers'; + +const MOCK_USER = makeMockUser({ + email: 'cache-audit@example.com', + name: 'Cache Audit User', + sessionId: 'cache-session-1', + userId: 'cache-user-1', +}); + +const BASE_PROJECT = { + id: 'cache-project-1', + userId: 'cache-user-1', + name: 'Responsive Cache Project', + description: 'A project used to verify cached responsive navigation.', + installationId: 'installation-1', + repository: 'acme/responsive-cache-project', + defaultBranch: 'main', + status: 'active', + activeWorkspaceCount: 2, + activeSessionCount: 1, + lastActivityAt: '2026-08-07T20:00:00.000Z', + taskCountsByStatus: { in_progress: 1 }, + linkedWorkspaces: 2, + createdAt: '2026-08-07T19:00:00.000Z', + updatedAt: '2026-08-07T20:00:00.000Z', +}; + +interface MockOptions { + backgroundRefreshDelayMs?: number; + projectListError?: boolean; + projects?: Array>; +} + +async function setupApiMocks(page: Page, options: MockOptions = {}) { + const projects = options.projects ?? [BASE_PROJECT]; + let listRequestCount = 0; + let detailRequestCount = 0; + + await page.addInitScript((userId) => { + window.localStorage.setItem(`sam-onboarding-wizard-dismissed-${userId}`, 'true'); + }, MOCK_USER.user.id); + + await page.route('**/api/**', async (route: Route) => { + const url = new URL(route.request().url()); + const path = url.pathname; + const method = route.request().method(); + const respond = (status: number, body: unknown) => + route.fulfill({ status, contentType: 'application/json', body: JSON.stringify(body) }); + + if (path.includes('/api/auth/')) return respond(200, MOCK_USER); + if (path === '/api/projects' && method === 'GET') { + listRequestCount += 1; + if (options.projectListError) { + return respond(500, { + error: 'PROJECT_LIST_UNAVAILABLE', + message: 'Project list unavailable', + }); + } + if (listRequestCount > 1 && options.backgroundRefreshDelayMs) { + await new Promise((resolve) => setTimeout(resolve, options.backgroundRefreshDelayMs)); + } + return respond(200, { projects, nextCursor: null }); + } + if (path === `/api/projects/${BASE_PROJECT.id}` && method === 'GET') { + detailRequestCount += 1; + return respond(200, BASE_PROJECT); + } + if (path === `/api/projects/${BASE_PROJECT.id}` && method === 'DELETE') { + return respond(200, { success: true }); + } + if (path === '/api/github/installations') return respond(200, []); + if (path === '/api/dashboard/active-tasks') return respond(200, { tasks: [] }); + if (path.startsWith('/api/notifications')) { + return respond(200, { notifications: [], unreadCount: 0 }); + } + if (path.startsWith('/api/credentials')) return respond(200, []); + if (path === '/api/agents') return respond(200, { agents: [] }); + if (path === '/api/trial/status') return respond(200, { available: false }); + if (path.includes('/sessions')) return respond(200, { sessions: [], total: 0 }); + if (path.includes('/tasks')) return respond(200, { tasks: [], nextCursor: null }); + if (path.includes('/agent-profiles')) return respond(200, { items: [] }); + if (path.includes('/commands')) return respond(200, { commands: [] }); + return respond(200, {}); + }); + + return { + get detailRequestCount() { + return detailRequestCount; + }, + get listRequestCount() { + return listRequestCount; + }, + }; +} + +test('phone rotation preserves the loaded project list without another request', async ({ page }, testInfo) => { + test.skip(testInfo.project.name !== 'iPhone 14 (390x844)'); + const requests = await setupApiMocks(page); + + await page.goto('/projects'); + await expect(page.locator('#main-content').getByText(BASE_PROJECT.name)).toBeVisible(); + expect(requests.listRequestCount).toBe(1); + await screenshot(page, 'frontend-cache-projects-portrait'); + + await page.setViewportSize({ width: 844, height: 390 }); + await expect(page.locator('#main-content').getByText(BASE_PROJECT.name)).toBeVisible(); + await page.waitForTimeout(300); + + expect(requests.listRequestCount).toBe(1); + await assertNoOverflow(page); + await screenshot(page, 'frontend-cache-projects-landscape'); +}); + +test('intent prefetch feeds navigation and stale data stays visible during refresh', async ({ page }, testInfo) => { + test.skip(testInfo.project.name !== 'Desktop (1280x800)'); + const requests = await setupApiMocks(page, { backgroundRefreshDelayMs: 900 }); + + await page.goto('/projects'); + await expect(page.locator('#main-content').getByText(BASE_PROJECT.name)).toBeVisible(); + expect(requests.listRequestCount).toBe(1); + + const projectCard = page + .locator('#main-content') + .getByText(BASE_PROJECT.name) + .locator('xpath=ancestor::*[@role="button"][1]'); + await projectCard.hover(); + await expect.poll(() => requests.detailRequestCount).toBe(1); + + await page.getByRole('button', { name: `Actions for ${BASE_PROJECT.name}`, exact: true }).click(); + await page.getByRole('menuitem', { name: 'Delete' }).click(); + + const indicator = page.getByTestId('background-fetch-indicator'); + await expect(indicator).toHaveAttribute('data-refreshing', 'true'); + await page.waitForTimeout(220); + await expect(page.locator('#main-content').getByText(BASE_PROJECT.name)).toBeVisible(); + await screenshot(page, 'frontend-cache-background-refresh'); + await expect(indicator).toHaveAttribute('data-refreshing', 'false'); + + await projectCard.click({ position: { x: 12, y: 12 } }); + await expect(page).toHaveURL(new RegExp(`/projects/${BASE_PROJECT.id}/chat`)); + expect(requests.detailRequestCount).toBe(1); + await assertNoOverflow(page); +}); + +const MANY_PROJECTS = Array.from({ length: 30 }, (_, index) => ({ + ...BASE_PROJECT, + id: `cache-project-${index + 1}`, + name: `Cached Project ${index + 1}`, + repository: `acme/cached-project-${index + 1}`, +})); + +const VISUAL_STATES = [ + { name: 'normal', projects: [BASE_PROJECT] }, + { + name: 'long-special', + projects: [{ + ...BASE_PROJECT, + name: `日本語 🚀 ${'very-long-project-name-'.repeat(8)}`, + repository: `acme/${'unbroken'.repeat(30)}`, + }], + }, + { name: 'empty', projects: [] }, + { name: 'many', projects: MANY_PROJECTS }, +] as const; + +for (const state of VISUAL_STATES) { + test(`project cache surface: ${state.name}`, async ({ page }, testInfo) => { + test.skip( + !['iPhone SE (375x667)', 'Desktop (1280x800)'].includes(testInfo.project.name), + ); + await setupApiMocks(page, { projects: [...state.projects] }); + + await page.goto('/projects'); + await expect(page.getByRole('heading', { name: 'Projects', exact: true })).toBeVisible(); + if (state.name === 'empty') { + await expect(page.getByRole('heading', { name: 'No projects yet' })).toBeVisible(); + } + + await assertNoOverflow(page); + await screenshot(page, `frontend-cache-projects-${state.name}`); + }); +} + +test('project cache surface: initial error', async ({ page }, testInfo) => { + test.skip(!['iPhone SE (375x667)', 'Desktop (1280x800)'].includes(testInfo.project.name)); + await setupApiMocks(page, { projectListError: true }); + + await page.goto('/projects'); + await expect(page.getByText('Project list unavailable')).toBeVisible(); + await assertNoOverflow(page); + await screenshot(page, 'frontend-cache-projects-error'); +}); diff --git a/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md b/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md index 378aea9d8d..2d66bc0ae7 100644 --- a/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md +++ b/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md @@ -63,7 +63,7 @@ This PR deliberately combines the direct rotation fix with the smallest cache/pr - [x] Add a delayed global background-fetch indicator above AppShell. - [x] Clear query data on clean signout/session-expiry/account-switch transitions, not transient auth refetch errors. - [x] Add unit tests for deduplication, cache reuse, stale-data preservation, auth cleanup, indicator behavior, and intent prefetch. -- [ ] Add Playwright coverage for portrait→landscape rotation, request counts, indicator rendering, overflow, and mobile/desktop screenshots. +- [x] Add Playwright coverage for portrait→landscape rotation, request counts, indicator rendering, overflow, and mobile/desktop screenshots. - [x] Update Rule 48 with the responsive-shell identity requirement. - [ ] Run full validation, specialist reviews, staging verification, and create a draft PR without merging. From 74584d8818befc444f0efb6ca2c9b1d43b046d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Fri, 7 Aug 2026 23:56:07 +0000 Subject: [PATCH 04/57] fix(web): isolate cached project data by user --- .claude/rules/48-stale-while-revalidate-ui.md | 5 + apps/web/src/components/AppShell.tsx | 7 +- apps/web/src/components/AuthProvider.tsx | 45 +++--- .../components/BackgroundFetchIndicator.tsx | 20 ++- .../web/src/components/ProjectSummaryCard.tsx | 35 +++- .../web/src/components/SidebarProjectList.tsx | 45 ++++-- apps/web/src/hooks/useProjectData.ts | 33 +++- apps/web/src/lib/query-options.ts | 35 ++-- apps/web/src/pages/Dashboard.tsx | 9 +- apps/web/src/pages/Project.tsx | 36 +++-- apps/web/src/pages/Projects.tsx | 16 +- .../playwright/frontend-cache-audit.spec.ts | 55 ++++++- .../unit/BackgroundFetchIndicator.test.tsx | 34 +++- apps/web/tests/unit/Project.test.tsx | 43 ++++- apps/web/tests/unit/ProjectPrefetch.test.tsx | 73 +++++++-- .../tests/unit/SidebarProjectList.test.tsx | 9 +- apps/web/tests/unit/accessibility.test.tsx | 16 +- .../unit/components/auth-provider.test.tsx | 151 ++++++++++++++++-- .../tests/unit/hooks/useProjectData.test.tsx | 63 ++++++-- apps/web/tests/unit/pages/dashboard.test.tsx | 9 +- apps/web/tests/unit/pages/projects.test.tsx | 37 +++-- ...end-query-cache-and-rotation-resilience.md | 20 ++- 22 files changed, 637 insertions(+), 159 deletions(-) diff --git a/.claude/rules/48-stale-while-revalidate-ui.md b/.claude/rules/48-stale-while-revalidate-ui.md index ad065080ca..342f0b5a1f 100644 --- a/.claude/rules/48-stale-while-revalidate-ui.md +++ b/.claude/rules/48-stale-while-revalidate-ui.md @@ -96,6 +96,10 @@ modifying an existing one, use `useQuery`/`useMutation` instead of hand-rolled - Use `queryClient.invalidateQueries(...)` after mutations instead of `await reload()` chains threaded through context. - Use `refetchInterval` instead of hand-rolled `setInterval` polls. +- Every authenticated query key must include the resolved user identity (or an + equivalent tenant/session namespace). Clear the previous namespace and gate + protected children while that identity changes so cached data from one + account can never render for another account, even for a single frame. Hand-rolled loaders are only acceptable for genuinely non-query state (WebSockets, streaming, imperative one-shots). @@ -129,4 +133,5 @@ Before committing UI data-fetching or context changes: - [ ] Spinners gate only on "no data yet", never on "refetch in flight" - [ ] Mutations invalidate/refresh data without unmounting visible content - [ ] New fetch surfaces use TanStack Query (or document why not) +- [ ] Authenticated query keys are identity-scoped and account transitions are gated - [ ] Breakpoint changes preserve routed and media subtree identity diff --git a/apps/web/src/components/AppShell.tsx b/apps/web/src/components/AppShell.tsx index cb7dd98c89..615bf643f6 100644 --- a/apps/web/src/components/AppShell.tsx +++ b/apps/web/src/components/AppShell.tsx @@ -65,6 +65,7 @@ export function AppShell({ children }: AppShellProps) { const [focusModeState, setFocusModeState] = useState('default'); const commandPalette = useGlobalCommandPalette(); const { projects: sidebarProjects, loading: sidebarProjectsLoading } = useProjectList({ + queryScope: user?.id ?? '', limit: 50, pollInterval: 60000, }); @@ -190,10 +191,11 @@ export function AppShell({ children }: AppShellProps) { loading={sidebarProjectsLoading} currentProjectId={projectId} onNavigate={handleProjectNavigate} + queryScope={user?.id ?? ''} variant="mobile" /> ), - [sidebarProjects, sidebarProjectsLoading, projectId, handleProjectNavigate], + [sidebarProjects, sidebarProjectsLoading, projectId, handleProjectNavigate, user?.id], ); const desktopProjectListSection = useMemo( @@ -203,10 +205,11 @@ export function AppShell({ children }: AppShellProps) { loading={sidebarProjectsLoading} currentProjectId={projectId} onNavigate={handleProjectNavigate} + queryScope={user?.id ?? ''} variant="desktop" /> ), - [sidebarProjects, sidebarProjectsLoading, projectId, handleProjectNavigate], + [sidebarProjects, sidebarProjectsLoading, projectId, handleProjectNavigate, user?.id], ); const projectHealthElement = projectId ? ( diff --git a/apps/web/src/components/AuthProvider.tsx b/apps/web/src/components/AuthProvider.tsx index f75b522c85..85f52fec9a 100644 --- a/apps/web/src/components/AuthProvider.tsx +++ b/apps/web/src/components/AuthProvider.tsx @@ -1,5 +1,14 @@ import type { UserRole, UserStatus } from '@simple-agent-manager/shared'; -import { createContext, type ReactNode, useContext, useEffect, useMemo, useRef, useState } from 'react'; +import { + createContext, + type ReactNode, + useContext, + useEffect, + useLayoutEffect, + useMemo, + useRef, + useState, +} from 'react'; import { setUserId } from '../lib/analytics'; import { GITHUB_REAUTH_REQUIRED_EVENT } from '../lib/api/client'; @@ -47,7 +56,7 @@ export function AuthProvider({ children }: AuthProviderProps) { const { data: session, isPending, error, isRefetching } = useSession(); const lastGoodSessionRef = useRef(null); const [githubReauthMessage, setGitHubReauthMessage] = useState(null); - const previousCacheNamespaceRef = useRef(undefined); + const [activeCacheNamespace, setActiveCacheNamespace] = useState(undefined); // Cache every successful session if (session?.user) { @@ -76,25 +85,21 @@ export function AuthProvider({ children }: AuthProviderProps) { [user, role, status] ); - useEffect(() => { - if (isPending) return; - - const nextNamespace = buildLibraryCacheNamespace(enrichedUser?.id); - const previousNamespace = previousCacheNamespaceRef.current; + const nextCacheNamespace = buildLibraryCacheNamespace(enrichedUser?.id); + const canResolveCacheNamespace = !isPending || Boolean(enrichedUser?.id); + const isCacheNamespaceTransitioning = + activeCacheNamespace === undefined + ? canResolveCacheNamespace + : !canResolveCacheNamespace || activeCacheNamespace !== nextCacheNamespace; - if (previousNamespace === undefined) { - previousCacheNamespaceRef.current = nextNamespace; - if (nextNamespace) clearLegacyLibraryCache(); - return; - } + useLayoutEffect(() => { + if (!canResolveCacheNamespace || activeCacheNamespace === nextCacheNamespace) return; - if (previousNamespace !== nextNamespace) { - queryClient.clear(); - if (previousNamespace) clearLibraryCache(previousNamespace); - clearLegacyLibraryCache(); - previousCacheNamespaceRef.current = nextNamespace; - } - }, [enrichedUser?.id, isPending]); + queryClient.clear(); + if (activeCacheNamespace) clearLibraryCache(activeCacheNamespace); + clearLegacyLibraryCache(); + setActiveCacheNamespace(nextCacheNamespace); + }, [activeCacheNamespace, canResolveCacheNamespace, nextCacheNamespace]); // Sync authenticated userId to analytics tracker useEffect(() => { @@ -138,7 +143,7 @@ export function AuthProvider({ children }: AuthProviderProps) { return ( - {children} + {isCacheNamespaceTransitioning ? null : children} {githubReauthMessage && (

GitHub sign-in required

diff --git a/apps/web/src/components/BackgroundFetchIndicator.tsx b/apps/web/src/components/BackgroundFetchIndicator.tsx index e7b6dbae5d..0dc445fce2 100644 --- a/apps/web/src/components/BackgroundFetchIndicator.tsx +++ b/apps/web/src/components/BackgroundFetchIndicator.tsx @@ -1,23 +1,37 @@ import { useIsFetching } from '@tanstack/react-query'; +import { useEffect, useState } from 'react'; + +const BACKGROUND_FETCH_DELAY_MS = 150; export function BackgroundFetchIndicator() { const backgroundFetchCount = useIsFetching({ predicate: (query) => query.state.data !== undefined, }); const isRefreshing = backgroundFetchCount > 0; + const [isVisible, setIsVisible] = useState(false); + + useEffect(() => { + if (!isRefreshing) { + setIsVisible(false); + return; + } + + const timer = window.setTimeout(() => setIsVisible(true), BACKGROUND_FETCH_DELAY_MS); + return () => window.clearTimeout(timer); + }, [isRefreshing]); return ( <> )} diff --git a/apps/web/src/pages/Project.tsx b/apps/web/src/pages/Project.tsx index fe8109ac91..7f2a4d1ab1 100644 --- a/apps/web/src/pages/Project.tsx +++ b/apps/web/src/pages/Project.tsx @@ -5,6 +5,7 @@ import { useCallback, useEffect, useMemo } from 'react'; import { Outlet, useLocation, useParams } from 'react-router'; import { useAppShell } from '../components/AppShell'; +import { useAuth } from '../components/AuthProvider'; import { useIsMobile } from '../hooks/useIsMobile'; import { githubInstallationsQueryOptions, @@ -18,12 +19,17 @@ export function Project() { const location = useLocation(); const isMobile = useIsMobile(); const { setProjectName } = useAppShell(); + const { user } = useAuth(); + const queryScope = user?.id ?? ''; const queryClient = useQueryClient(); const projectQuery = useQuery({ - ...projectDetailQueryOptions(projectId ?? ''), - enabled: Boolean(projectId), + ...projectDetailQueryOptions(queryScope, projectId ?? ''), + enabled: Boolean(projectId && queryScope), + }); + const installationsQuery = useQuery({ + ...githubInstallationsQueryOptions(queryScope), + enabled: Boolean(queryScope), }); - const installationsQuery = useQuery(githubInstallationsQueryOptions()); const project = (projectQuery.data ?? null) as ProjectDetailResponse | null; const installations = useMemo( () => (installationsQuery.data ?? []) as GitHubInstallation[], @@ -31,11 +37,13 @@ export function Project() { ); const refetchProject = projectQuery.refetch; const projectLoading = Boolean(projectId) && projectQuery.isPending && project === null; - const error = projectQuery.error instanceof Error - ? projectQuery.error.message - : projectQuery.error - ? 'Failed to load project' - : null; + const error = project === null + ? projectQuery.error instanceof Error + ? projectQuery.error.message + : projectQuery.error + ? 'Failed to load project' + : null + : null; // Chat routes get a full-bleed layout (no PageLayout wrapper) const isChatRoute = /\/(chat|agent)(\/|$)/.test(location.pathname); @@ -43,9 +51,9 @@ export function Project() { const loadProject = useCallback(async () => { await Promise.all([ refetchProject(), - queryClient.invalidateQueries({ queryKey: projectQueryKeys.lists() }), + queryClient.invalidateQueries({ queryKey: projectQueryKeys.lists(queryScope) }), ]); - }, [queryClient, refetchProject]); + }, [queryClient, queryScope, refetchProject]); // Push project name up to AppShell for sidebar display useEffect(() => { @@ -115,12 +123,6 @@ export function Project() { : { padding: 'var(--sam-space-8) clamp(var(--sam-space-3), 3vw, var(--sam-space-4))' } } > - {error && ( -
- {error} -
- )} - {projectLoading ? (
@@ -128,7 +130,7 @@ export function Project() {
) : !project ? (
- Project not found. + {error ?? 'Project not found.'}
) : (
diff --git a/apps/web/src/pages/Projects.tsx b/apps/web/src/pages/Projects.tsx index 2bcdce6a85..f5df65520b 100644 --- a/apps/web/src/pages/Projects.tsx +++ b/apps/web/src/pages/Projects.tsx @@ -2,13 +2,18 @@ import { Alert, Button, EmptyState, PageLayout, SkeletonCard, Spinner } from '@s import { useState } from 'react'; import { useNavigate } from 'react-router'; +import { useAuth } from '../components/AuthProvider'; import { ProjectSummaryCard } from '../components/ProjectSummaryCard'; import { useProjectList } from '../hooks/useProjectData'; import { deleteProject } from '../lib/api'; export function Projects() { const navigate = useNavigate(); - const { projects, loading, isRefreshing, error, refresh } = useProjectList({ limit: 50 }); + const { user } = useAuth(); + const { projects, loading, isRefreshing, error, refresh } = useProjectList({ + queryScope: user?.id ?? '', + limit: 50, + }); const [deleteError, setDeleteError] = useState(null); const handleDelete = async (id: string) => { @@ -55,7 +60,7 @@ export function Projects() { ))}
- ) : projects.length === 0 ? ( + ) : error && projects.length === 0 ? null : projects.length === 0 ? ( {projects.map((project) => ( - + ))}
)} diff --git a/apps/web/tests/playwright/frontend-cache-audit.spec.ts b/apps/web/tests/playwright/frontend-cache-audit.spec.ts index 51eb5a5c08..01d53a6f58 100644 --- a/apps/web/tests/playwright/frontend-cache-audit.spec.ts +++ b/apps/web/tests/playwright/frontend-cache-audit.spec.ts @@ -1,4 +1,5 @@ import { expect, type Page, type Route, test } from '@playwright/test'; +import type { ProjectDetailResponse, ProjectSummary } from '@simple-agent-manager/shared'; import { assertNoOverflow, makeMockUser, screenshot } from './audit-helpers'; @@ -11,12 +12,11 @@ const MOCK_USER = makeMockUser({ const BASE_PROJECT = { id: 'cache-project-1', - userId: 'cache-user-1', name: 'Responsive Cache Project', - description: 'A project used to verify cached responsive navigation.', - installationId: 'installation-1', repository: 'acme/responsive-cache-project', + githubRepoId: 101, defaultBranch: 'main', + repoProvider: 'github', status: 'active', activeWorkspaceCount: 2, activeSessionCount: 1, @@ -24,13 +24,34 @@ const BASE_PROJECT = { taskCountsByStatus: { in_progress: 1 }, linkedWorkspaces: 2, createdAt: '2026-08-07T19:00:00.000Z', +} satisfies ProjectSummary; + +const BASE_PROJECT_DETAIL = { + id: BASE_PROJECT.id, + userId: 'cache-user-1', + name: BASE_PROJECT.name, + description: 'A project used to verify cached responsive navigation.', + installationId: 'installation-1', + repository: BASE_PROJECT.repository, + defaultBranch: BASE_PROJECT.defaultBranch, + repoProvider: 'github', + status: 'active', + createdAt: BASE_PROJECT.createdAt, updatedAt: '2026-08-07T20:00:00.000Z', -}; + summary: { + repoProvider: 'github', + activeWorkspaceCount: 2, + activeSessionCount: 1, + lastActivityAt: '2026-08-07T20:00:00.000Z', + taskCountsByStatus: { in_progress: 1 }, + linkedWorkspaces: 2, + }, +} satisfies ProjectDetailResponse; interface MockOptions { backgroundRefreshDelayMs?: number; projectListError?: boolean; - projects?: Array>; + projects?: ProjectSummary[]; } async function setupApiMocks(page: Page, options: MockOptions = {}) { @@ -65,7 +86,7 @@ async function setupApiMocks(page: Page, options: MockOptions = {}) { } if (path === `/api/projects/${BASE_PROJECT.id}` && method === 'GET') { detailRequestCount += 1; - return respond(200, BASE_PROJECT); + return respond(200, BASE_PROJECT_DETAIL); } if (path === `/api/projects/${BASE_PROJECT.id}` && method === 'DELETE') { return respond(200, { success: true }); @@ -144,6 +165,24 @@ test('intent prefetch feeds navigation and stale data stays visible during refre await assertNoOverflow(page); }); +test('mobile background refresh stays delayed and preserves the loaded project card', async ({ page }, testInfo) => { + test.skip(testInfo.project.name !== 'iPhone 14 (390x844)'); + await setupApiMocks(page, { backgroundRefreshDelayMs: 900 }); + + await page.goto('/projects'); + await expect(page.locator('#main-content').getByText(BASE_PROJECT.name)).toBeVisible(); + await page.getByRole('button', { name: `Actions for ${BASE_PROJECT.name}`, exact: true }).click(); + await page.getByRole('menuitem', { name: 'Delete' }).click(); + + const indicator = page.getByTestId('background-fetch-indicator'); + await expect(indicator).toHaveAttribute('data-refreshing', 'false'); + await page.waitForTimeout(170); + await expect(indicator).toHaveAttribute('data-refreshing', 'true'); + await expect(page.locator('#main-content').getByText(BASE_PROJECT.name)).toBeVisible(); + await assertNoOverflow(page); + await screenshot(page, 'frontend-cache-mobile-background-refresh'); +}); + const MANY_PROJECTS = Array.from({ length: 30 }, (_, index) => ({ ...BASE_PROJECT, id: `cache-project-${index + 1}`, @@ -153,11 +192,12 @@ const MANY_PROJECTS = Array.from({ length: 30 }, (_, index) => ({ const VISUAL_STATES = [ { name: 'normal', projects: [BASE_PROJECT] }, + { name: 'single-character', projects: [{ ...BASE_PROJECT, name: 'A', repository: 'a/b' }] }, { name: 'long-special', projects: [{ ...BASE_PROJECT, - name: `日本語 🚀 ${'very-long-project-name-'.repeat(8)}`, + name: `日本語 🚀 ${'very-long-project-name-'.repeat(8)}`, repository: `acme/${'unbroken'.repeat(30)}`, }], }, @@ -189,6 +229,7 @@ test('project cache surface: initial error', async ({ page }, testInfo) => { await page.goto('/projects'); await expect(page.getByText('Project list unavailable')).toBeVisible(); + await expect(page.getByRole('heading', { name: 'No projects yet' })).toHaveCount(0); await assertNoOverflow(page); await screenshot(page, 'frontend-cache-projects-error'); }); diff --git a/apps/web/tests/unit/BackgroundFetchIndicator.test.tsx b/apps/web/tests/unit/BackgroundFetchIndicator.test.tsx index 70f7f499b4..d4e06b5e30 100644 --- a/apps/web/tests/unit/BackgroundFetchIndicator.test.tsx +++ b/apps/web/tests/unit/BackgroundFetchIndicator.test.tsx @@ -45,8 +45,10 @@ describe('BackgroundFetchIndicator', () => { void queryClient.invalidateQueries({ queryKey: QUERY_KEY }); }); + expect(indicator).toHaveAttribute('data-refreshing', 'false'); + expect(screen.getByRole('status')).toBeEmptyDOMElement(); await waitFor(() => expect(indicator).toHaveAttribute('data-refreshing', 'true')); - expect(indicator).toHaveClass('opacity-100', 'delay-150'); + expect(indicator).toHaveClass('opacity-100'); expect(screen.getByRole('status')).toHaveTextContent('Refreshing data'); expect(screen.getByText('Cached data')).toBeInTheDocument(); @@ -57,4 +59,34 @@ describe('BackgroundFetchIndicator', () => { await waitFor(() => expect(indicator).toHaveAttribute('data-refreshing', 'false')); expect(screen.getByText('Fresh data')).toBeInTheDocument(); }); + + it('never shows or announces a background refresh that finishes before the delay', async () => { + const queryFn = vi.fn().mockResolvedValue('Cached data'); + render( + + + + , + ); + await screen.findByText('Cached data'); + + const indicator = screen.getByTestId('background-fetch-indicator'); + const observedStates: string[] = []; + const observer = new MutationObserver(() => { + observedStates.push(indicator.getAttribute('data-refreshing') ?? 'missing'); + }); + observer.observe(indicator, { attributes: true, attributeFilter: ['data-refreshing'] }); + + queryFn.mockResolvedValueOnce('Fresh data'); + await act(async () => { + await queryClient.invalidateQueries({ queryKey: QUERY_KEY }); + }); + await screen.findByText('Fresh data'); + await new Promise((resolve) => window.setTimeout(resolve, 180)); + observer.disconnect(); + + expect(observedStates).not.toContain('true'); + expect(indicator).toHaveAttribute('data-refreshing', 'false'); + expect(screen.getByRole('status')).toBeEmptyDOMElement(); + }); }); diff --git a/apps/web/tests/unit/Project.test.tsx b/apps/web/tests/unit/Project.test.tsx index f659c8c250..b6c1310ecb 100644 --- a/apps/web/tests/unit/Project.test.tsx +++ b/apps/web/tests/unit/Project.test.tsx @@ -10,7 +10,7 @@ import { renderWithQuery } from '../test-utils/query-test-utils'; // Mock AuthProvider vi.mock('../../src/components/AuthProvider', () => ({ useAuth: () => ({ - user: { name: 'Test User', email: 'test@example.com', image: null }, + user: { id: 'user-1', name: 'Test User', email: 'test@example.com', image: null }, }), })); @@ -92,6 +92,15 @@ describe('Project shell (non-chat routes)', () => { renderProject('/projects/proj-1/overview'); expect(await screen.findByTestId('overview-content')).toBeInTheDocument(); }); + + it('renders one truthful initial error without also claiming the project was not found', async () => { + mockGetProject.mockRejectedValueOnce(new Error('Project service unavailable')); + renderProject('/projects/proj-1/overview'); + + expect(await screen.findByRole('alert')).toHaveTextContent('Project service unavailable'); + expect(screen.getAllByRole('alert')).toHaveLength(1); + expect(screen.queryByText('Project not found.')).not.toBeInTheDocument(); + }); }); describe('Project shell (chat route — full-bleed)', () => { @@ -179,4 +188,36 @@ describe('Project reload (stale-while-revalidate)', () => { expect(getByTestId('child-content')).toBeInTheDocument(); expect(unmountSpy).not.toHaveBeenCalled(); }); + + it('keeps child content mounted and does not replace it with an alert when reload fails', async () => { + function ReloadChild() { + const { reload } = useProjectContext(); + return ( +
+
Cached project content
+ +
+ ); + } + + const { findByTestId, getByTestId, queryByRole } = renderWithQuery( + + + }> + } /> + + + , + ); + + await findByTestId('stale-child-content'); + mockGetProject.mockRejectedValueOnce(new Error('Background reload failed')); + await act(async () => { + getByTestId('failed-reload-btn').click(); + }); + + await waitFor(() => expect(mockGetProject).toHaveBeenCalledTimes(2)); + expect(getByTestId('stale-child-content')).toHaveTextContent('Cached project content'); + expect(queryByRole('alert')).not.toBeInTheDocument(); + }); }); diff --git a/apps/web/tests/unit/ProjectPrefetch.test.tsx b/apps/web/tests/unit/ProjectPrefetch.test.tsx index 978e90faf2..f19486e44c 100644 --- a/apps/web/tests/unit/ProjectPrefetch.test.tsx +++ b/apps/web/tests/unit/ProjectPrefetch.test.tsx @@ -1,5 +1,7 @@ -import type { ProjectSummary } from '@simple-agent-manager/shared'; +import type { ProjectDetailResponse, ProjectSummary } from '@simple-agent-manager/shared'; +import { QueryClientProvider } from '@tanstack/react-query'; import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import type { ReactElement } from 'react'; import { MemoryRouter } from 'react-router'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; @@ -17,29 +19,53 @@ vi.mock('../../src/lib/api', async (importOriginal) => ({ getProject: mocks.getProject, })); -const PROJECT: ProjectSummary = { +const PROJECT = { id: 'project-1', - userId: 'user-1', name: 'Prefetched project', - description: null, - installationId: 'installation-1', repository: 'acme/prefetched-project', + githubRepoId: 101, defaultBranch: 'main', + repoProvider: 'github', status: 'active', activeWorkspaceCount: 0, activeSessionCount: 0, lastActivityAt: '2026-08-07T20:00:00.000Z', taskCountsByStatus: {}, - linkedWorkspaces: [], + linkedWorkspaces: 0, createdAt: '2026-08-07T19:00:00.000Z', +} satisfies ProjectSummary; + +const PROJECT_DETAIL = { + id: PROJECT.id, + userId: 'user-1', + name: PROJECT.name, + description: null, + installationId: 'installation-1', + repository: PROJECT.repository, + defaultBranch: PROJECT.defaultBranch, + repoProvider: 'github', + status: 'active', + createdAt: PROJECT.createdAt, updatedAt: '2026-08-07T20:00:00.000Z', -}; + summary: { + repoProvider: 'github', + activeWorkspaceCount: 0, + activeSessionCount: 0, + lastActivityAt: '2026-08-07T20:00:00.000Z', + taskCountsByStatus: {}, + linkedWorkspaces: 0, + }, +} satisfies ProjectDetailResponse; + +function renderWithQuery(ui: ReactElement) { + return render({ui}); +} describe('project detail intent prefetch', () => { beforeEach(() => { queryClient.clear(); mocks.getProject.mockReset(); - mocks.getProject.mockResolvedValue(PROJECT); + mocks.getProject.mockResolvedValue(PROJECT_DETAIL); }); afterEach(() => { @@ -47,9 +73,9 @@ describe('project detail intent prefetch', () => { }); it('prefetches the exact destination query from a project-card hover', async () => { - render( + renderWithQuery( - + , ); @@ -58,18 +84,19 @@ describe('project detail intent prefetch', () => { fireEvent.mouseEnter(projectCard); await waitFor(() => expect(mocks.getProject).toHaveBeenCalledWith('project-1')); - expect(queryClient.getQueryData(projectQueryKeys.detail('project-1'))).toEqual(PROJECT); + expect(queryClient.getQueryData(projectQueryKeys.detail('user-1', 'project-1'))).toEqual(PROJECT_DETAIL); - await queryClient.fetchQuery(projectDetailQueryOptions('project-1')); + await queryClient.fetchQuery(projectDetailQueryOptions('user-1', 'project-1')); expect(mocks.getProject).toHaveBeenCalledTimes(1); }); it('prefetches on keyboard focus from the sidebar destination', async () => { - render( + renderWithQuery( , ); @@ -79,9 +106,9 @@ describe('project detail intent prefetch', () => { }); it('prefetches on touch intent from a project card', async () => { - render( + renderWithQuery( - + , ); @@ -91,4 +118,20 @@ describe('project detail intent prefetch', () => { await waitFor(() => expect(mocks.getProject).toHaveBeenCalledWith('project-1')); }); + + it('cancels speculative hover when the pointer only sweeps across a card', async () => { + renderWithQuery( + + + , + ); + + const projectCard = screen.getByText('Prefetched project').closest('[role="button"]'); + if (!projectCard) throw new Error('Project card was not rendered'); + fireEvent.mouseEnter(projectCard); + fireEvent.mouseLeave(projectCard); + + await new Promise((resolve) => window.setTimeout(resolve, 150)); + expect(mocks.getProject).not.toHaveBeenCalled(); + }); }); diff --git a/apps/web/tests/unit/SidebarProjectList.test.tsx b/apps/web/tests/unit/SidebarProjectList.test.tsx index 299bf3bc51..b4c85aac99 100644 --- a/apps/web/tests/unit/SidebarProjectList.test.tsx +++ b/apps/web/tests/unit/SidebarProjectList.test.tsx @@ -1,10 +1,17 @@ import type { ProjectSummary } from '@simple-agent-manager/shared'; -import { render, screen } from '@testing-library/react'; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { render as rtlRender, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import type { ReactElement } from 'react'; import { describe, expect, it, vi } from 'vitest'; import { SidebarProjectList } from '../../src/components/SidebarProjectList'; +function render(ui: ReactElement) { + const queryClient = new QueryClient(); + return rtlRender({ui}); +} + function makeProject(overrides: Partial = {}): ProjectSummary { return { id: overrides.id ?? 'p1', diff --git a/apps/web/tests/unit/accessibility.test.tsx b/apps/web/tests/unit/accessibility.test.tsx index 4d9ec6a63c..2f02ba0505 100644 --- a/apps/web/tests/unit/accessibility.test.tsx +++ b/apps/web/tests/unit/accessibility.test.tsx @@ -1,5 +1,6 @@ +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { render as baseRender, type RenderOptions, screen } from '@testing-library/react'; -import type { ReactElement } from 'react'; +import type { ReactElement, ReactNode } from 'react'; import { MemoryRouter } from 'react-router'; import { beforeAll, describe, expect, it, vi } from 'vitest'; @@ -7,8 +8,19 @@ import { AppShell } from '../../src/components/AppShell'; import { SkipToContent } from '../../src/components/SkipToContent'; import { ThemeProvider } from '../../src/contexts/ThemeContext'; +function TestProviders({ children }: { children: ReactNode }) { + const queryClient = new QueryClient({ + defaultOptions: { queries: { retry: false } }, + }); + return ( + + {children} + + ); +} + function render(ui: ReactElement, options?: Omit) { - return baseRender(ui, { wrapper: ThemeProvider, ...options }); + return baseRender(ui, { wrapper: TestProviders, ...options }); } let matchMediaMatches = false; diff --git a/apps/web/tests/unit/components/auth-provider.test.tsx b/apps/web/tests/unit/components/auth-provider.test.tsx index ccd36e3d90..e274cc32a6 100644 --- a/apps/web/tests/unit/components/auth-provider.test.tsx +++ b/apps/web/tests/unit/components/auth-provider.test.tsx @@ -1,15 +1,18 @@ -import { fireEvent, render, screen } from '@testing-library/react'; -import { beforeEach,describe, expect, it, vi } from 'vitest'; +import type { ProjectSummary } from '@simple-agent-manager/shared'; +import { QueryClientProvider, useQuery } from '@tanstack/react-query'; +import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { AuthProvider, useAuth } from '../../../src/components/AuthProvider'; import { GITHUB_REAUTH_REQUIRED_EVENT } from '../../../src/lib/api/client'; +import { queryClient } from '../../../src/lib/query-client'; +import { projectQueryKeys } from '../../../src/lib/query-options'; -const { mockUseSession, mockSignOut, mockClearLibraryCache, mockClearLegacyLibraryCache, mockClearQueryCache } = vi.hoisted(() => ({ +const { mockUseSession, mockSignOut, mockClearLibraryCache, mockClearLegacyLibraryCache } = vi.hoisted(() => ({ mockUseSession: vi.fn(), mockSignOut: vi.fn(), mockClearLibraryCache: vi.fn(), mockClearLegacyLibraryCache: vi.fn(), - mockClearQueryCache: vi.fn(), })); vi.mock('../../../src/lib/auth', () => ({ @@ -23,9 +26,7 @@ vi.mock('../../../src/lib/library-cache', async (importOriginal) => ({ clearLegacyLibraryCache: mockClearLegacyLibraryCache, })); -vi.mock('../../../src/lib/query-client', () => ({ - queryClient: { clear: mockClearQueryCache }, -})); +const clearQueryCacheSpy = vi.spyOn(queryClient, 'clear'); function AuthConsumer() { const auth = useAuth(); @@ -39,11 +40,9 @@ function AuthConsumer() { ); } -function renderWithAuth() { +function renderWithAuth(children = ) { return render( - - - , + {children}, ); } @@ -52,9 +51,48 @@ const validSession = { session: { id: 's1' }, }; +const PRIVATE_PROJECT = { + id: 'private-project', + name: 'User one private project', + repository: 'private/repository', + githubRepoId: 101, + defaultBranch: 'main', + repoProvider: 'github', + status: 'active', + activeWorkspaceCount: 1, + activeSessionCount: 0, + lastActivityAt: '2026-08-07T20:00:00.000Z', + createdAt: '2026-08-07T19:00:00.000Z', + taskCountsByStatus: {}, + linkedWorkspaces: 1, +} satisfies ProjectSummary; + +const cacheRenderLog: string[] = []; + +function ScopedProjectCacheConsumer() { + const { user } = useAuth(); + const queryScope = user?.id ?? ''; + const { data = [] } = useQuery({ + queryKey: projectQueryKeys.list(queryScope, 50), + queryFn: async (): Promise => [], + enabled: Boolean(queryScope), + }); + const renderedProject = data[0]?.name ?? 'none'; + cacheRenderLog.push(`${queryScope}:${renderedProject}`); + return ( +
+ {queryScope} + {renderedProject} +
+ ); +} + describe('AuthProvider', () => { beforeEach(() => { + queryClient.clear(); + clearQueryCacheSpy.mockClear(); vi.clearAllMocks(); + cacheRenderLog.length = 0; }); it('shows authenticated when session is valid', () => { @@ -207,8 +245,6 @@ describe('AuthProvider', () => { expect(screen.getByTestId('user-name')).toHaveTextContent('Updated User'); }); - - it('does not clear the same user namespace during transient refetch errors', () => { mockUseSession.mockReturnValue({ data: validSession, @@ -218,6 +254,7 @@ describe('AuthProvider', () => { }); const { rerender } = renderWithAuth(); expect(mockClearLegacyLibraryCache).toHaveBeenCalledTimes(1); + clearQueryCacheSpy.mockClear(); mockUseSession.mockReturnValue({ data: null, @@ -234,7 +271,7 @@ describe('AuthProvider', () => { expect(screen.getByTestId('authenticated')).toHaveTextContent('true'); expect(mockClearLibraryCache).not.toHaveBeenCalled(); expect(mockClearLegacyLibraryCache).toHaveBeenCalledTimes(1); - expect(mockClearQueryCache).not.toHaveBeenCalled(); + expect(clearQueryCacheSpy).not.toHaveBeenCalled(); }); it('clears the previous user namespace and legacy cache on clean null session expiry', () => { @@ -247,6 +284,7 @@ describe('AuthProvider', () => { const { rerender } = renderWithAuth(); mockClearLibraryCache.mockClear(); mockClearLegacyLibraryCache.mockClear(); + clearQueryCacheSpy.mockClear(); mockUseSession.mockReturnValue({ data: null, @@ -263,7 +301,7 @@ describe('AuthProvider', () => { expect(screen.getByTestId('authenticated')).toHaveTextContent('false'); expect(mockClearLibraryCache).toHaveBeenCalledWith('user:u1'); expect(mockClearLegacyLibraryCache).toHaveBeenCalledOnce(); - expect(mockClearQueryCache).toHaveBeenCalledOnce(); + expect(clearQueryCacheSpy).toHaveBeenCalledOnce(); }); it('clears the previous user namespace on account switch without clearing the new user cache', () => { @@ -276,6 +314,7 @@ describe('AuthProvider', () => { const { rerender } = renderWithAuth(); mockClearLibraryCache.mockClear(); mockClearLegacyLibraryCache.mockClear(); + clearQueryCacheSpy.mockClear(); mockUseSession.mockReturnValue({ data: { @@ -297,7 +336,87 @@ describe('AuthProvider', () => { expect(mockClearLibraryCache).toHaveBeenCalledWith('user:u1'); expect(mockClearLibraryCache).not.toHaveBeenCalledWith('user:u2'); expect(mockClearLegacyLibraryCache).toHaveBeenCalledOnce(); - expect(mockClearQueryCache).toHaveBeenCalledOnce(); + expect(clearQueryCacheSpy).toHaveBeenCalledOnce(); + }); + + it('never renders the previous user query cache during a direct account switch', async () => { + mockUseSession.mockReturnValue({ + data: validSession, + isPending: false, + error: null, + isRefetching: false, + }); + + const renderTree = () => ( + + + + + + ); + const { rerender } = render(renderTree()); + await waitFor(() => expect(screen.getByTestId('cache-user')).toHaveTextContent('u1')); + + act(() => { + queryClient.setQueryData(projectQueryKeys.list('u1', 50), [PRIVATE_PROJECT]); + }); + await waitFor(() => { + expect(screen.getByTestId('cached-project')).toHaveTextContent(PRIVATE_PROJECT.name); + }); + cacheRenderLog.length = 0; + + mockUseSession.mockReturnValue({ + data: { + ...validSession, + user: { ...validSession.user, id: 'u2', email: 'other@test.com', name: 'Other User' }, + }, + isPending: false, + error: null, + isRefetching: false, + }); + rerender(renderTree()); + + await waitFor(() => expect(screen.getByTestId('cache-user')).toHaveTextContent('u2')); + expect(screen.getByTestId('cached-project')).toHaveTextContent('none'); + expect(cacheRenderLog).not.toContain(`u2:${PRIVATE_PROJECT.name}`); + expect(queryClient.getQueryData(projectQueryKeys.list('u1', 50))).toBeUndefined(); + }); + + it('gates protected cache consumers while the next identity is unresolved', async () => { + mockUseSession.mockReturnValue({ + data: validSession, + isPending: false, + error: null, + isRefetching: false, + }); + + const renderTree = () => ( + + + + + + ); + const { rerender } = render(renderTree()); + await waitFor(() => expect(screen.getByTestId('cache-user')).toHaveTextContent('u1')); + + act(() => { + queryClient.setQueryData(projectQueryKeys.list('u1', 50), [PRIVATE_PROJECT]); + }); + await waitFor(() => { + expect(screen.getByTestId('cached-project')).toHaveTextContent(PRIVATE_PROJECT.name); + }); + + mockUseSession.mockReturnValue({ + data: null, + isPending: true, + error: null, + isRefetching: false, + }); + rerender(renderTree()); + + expect(screen.queryByTestId('cache-user')).not.toBeInTheDocument(); + expect(screen.queryByText(PRIVATE_PROJECT.name)).not.toBeInTheDocument(); }); it('shows a GitHub reauth prompt and signs out when reconnect is clicked', () => { diff --git a/apps/web/tests/unit/hooks/useProjectData.test.tsx b/apps/web/tests/unit/hooks/useProjectData.test.tsx index a12e1fcb4e..d9f1db22d5 100644 --- a/apps/web/tests/unit/hooks/useProjectData.test.tsx +++ b/apps/web/tests/unit/hooks/useProjectData.test.tsx @@ -15,23 +15,21 @@ vi.mock('../../../src/lib/api', async (importOriginal) => ({ listProjects: mocks.listProjects, })); -const PROJECT: ProjectSummary = { +const PROJECT = { id: 'project-1', - userId: 'user-1', name: 'Cached project', - description: null, - installationId: 'installation-1', repository: 'acme/cached-project', + githubRepoId: 101, defaultBranch: 'main', + repoProvider: 'github', status: 'active', activeWorkspaceCount: 1, activeSessionCount: 0, lastActivityAt: '2026-08-07T20:00:00.000Z', taskCountsByStatus: {}, - linkedWorkspaces: [], + linkedWorkspaces: 1, createdAt: '2026-08-07T19:00:00.000Z', - updatedAt: '2026-08-07T20:00:00.000Z', -}; +} satisfies ProjectSummary; function createWrapper() { const client = new QueryClient({ @@ -60,8 +58,8 @@ describe('useProjectList query cache', () => { const { Wrapper } = createWrapper(); const { result } = renderHook( () => ({ - sidebar: useProjectList({ limit: 50, pollInterval: 0 }), - page: useProjectList({ limit: 50, pollInterval: 0 }), + sidebar: useProjectList({ queryScope: 'user-1', limit: 50, pollInterval: 0 }), + page: useProjectList({ queryScope: 'user-1', limit: 50, pollInterval: 0 }), }), { wrapper: Wrapper }, ); @@ -76,14 +74,14 @@ describe('useProjectList query cache', () => { it('reuses fresh cached data when a consumer remounts', async () => { const { Wrapper } = createWrapper(); const first = renderHook( - () => useProjectList({ limit: 50, pollInterval: 0 }), + () => useProjectList({ queryScope: 'user-1', limit: 50, pollInterval: 0 }), { wrapper: Wrapper }, ); await waitFor(() => expect(first.result.current.projects).toEqual([PROJECT])); first.unmount(); const second = renderHook( - () => useProjectList({ limit: 50, pollInterval: 0 }), + () => useProjectList({ queryScope: 'user-1', limit: 50, pollInterval: 0 }), { wrapper: Wrapper }, ); @@ -95,7 +93,7 @@ describe('useProjectList query cache', () => { it('keeps cached projects visible during a background refresh', async () => { const { Wrapper } = createWrapper(); const { result } = renderHook( - () => useProjectList({ limit: 50, pollInterval: 0 }), + () => useProjectList({ queryScope: 'user-1', limit: 50, pollInterval: 0 }), { wrapper: Wrapper }, ); await waitFor(() => expect(result.current.projects).toEqual([PROJECT])); @@ -121,4 +119,45 @@ describe('useProjectList query cache', () => { await waitFor(() => expect(result.current.projects[0]?.name).toBe('Updated project')); }); + + it('keeps cached projects visible and suppresses page errors when background refresh fails', async () => { + const { Wrapper } = createWrapper(); + const { result } = renderHook( + () => useProjectList({ queryScope: 'user-1', limit: 50, pollInterval: 0 }), + { wrapper: Wrapper }, + ); + await waitFor(() => expect(result.current.projects).toEqual([PROJECT])); + + mocks.listProjects.mockRejectedValueOnce(new Error('Background refresh failed')); + act(() => { + result.current.refresh(); + }); + + await waitFor(() => expect(result.current.isRefreshing).toBe(false)); + expect(result.current.projects).toEqual([PROJECT]); + expect(result.current.loading).toBe(false); + expect(result.current.error).toBeNull(); + }); + + it('isolates identical list parameters by authenticated query scope', async () => { + const { client, Wrapper } = createWrapper(); + mocks.listProjects + .mockResolvedValueOnce({ projects: [{ ...PROJECT, name: 'User one project' }] }) + .mockResolvedValueOnce({ projects: [{ ...PROJECT, name: 'User two project' }] }); + + const { result } = renderHook( + () => ({ + userOne: useProjectList({ queryScope: 'user-1', limit: 50, pollInterval: 0 }), + userTwo: useProjectList({ queryScope: 'user-2', limit: 50, pollInterval: 0 }), + }), + { wrapper: Wrapper }, + ); + + await waitFor(() => { + expect(result.current.userOne.projects[0]?.name).toBe('User one project'); + expect(result.current.userTwo.projects[0]?.name).toBe('User two project'); + }); + expect(client.getQueryData(['auth', 'user-1', 'projects', 'list', { limit: 50 }])).toBeDefined(); + expect(client.getQueryData(['auth', 'user-2', 'projects', 'list', { limit: 50 }])).toBeDefined(); + }); }); diff --git a/apps/web/tests/unit/pages/dashboard.test.tsx b/apps/web/tests/unit/pages/dashboard.test.tsx index 60dcde3bac..3b23b553e7 100644 --- a/apps/web/tests/unit/pages/dashboard.test.tsx +++ b/apps/web/tests/unit/pages/dashboard.test.tsx @@ -32,7 +32,7 @@ vi.mock('../../../src/hooks/useProjectData', () => ({ projects: result?.projects ?? [], loading: false, isRefreshing: false, - error: null, + error: result?.error ?? null, refresh: vi.fn(), }; }, @@ -96,6 +96,13 @@ describe('Dashboard page', () => { expect(screen.getByText('Import your first project')).toBeInTheDocument(); }); + it('does not present a failed project request as an empty account', () => { + mocks.listProjects.mockReturnValue({ projects: [], error: 'Network error' }); + renderDashboard(); + expect(screen.getByText('Network error')).toBeInTheDocument(); + expect(screen.queryByText('Import your first project')).not.toBeInTheDocument(); + }); + it('renders project cards when projects exist', () => { mocks.listProjects.mockReturnValue({ projects: [sampleProject] }); renderDashboard(); diff --git a/apps/web/tests/unit/pages/projects.test.tsx b/apps/web/tests/unit/pages/projects.test.tsx index 15347a5e11..8a25f8bae1 100644 --- a/apps/web/tests/unit/pages/projects.test.tsx +++ b/apps/web/tests/unit/pages/projects.test.tsx @@ -1,4 +1,5 @@ import type { ProjectSummary } from '@simple-agent-manager/shared'; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { render, screen, waitFor } from '@testing-library/react'; import { MemoryRouter, Route, Routes } from 'react-router'; import { beforeEach, describe, expect, it, vi } from 'vitest'; @@ -14,6 +15,10 @@ vi.mock('../../../src/hooks/useProjectData', () => ({ useProjectList: mocks.useProjectList, })); +vi.mock('../../../src/components/AuthProvider', () => ({ + useAuth: () => ({ user: { id: 'user-1', email: 'owner@example.com', name: 'Project Owner' } }), +})); + vi.mock('../../../src/lib/api', async (importOriginal) => ({ ...(await importOriginal()), deleteProject: mocks.deleteProject, @@ -25,34 +30,35 @@ vi.mock('../../../src/components/UserMenu', () => ({ import { Projects } from '../../../src/pages/Projects'; -const PROJECT_SUMMARY: ProjectSummary = { +const PROJECT_SUMMARY = { id: 'proj-1', - userId: 'user-1', name: 'Project One', - description: 'First project', - installationId: 'inst-1', repository: 'acme/repo-one', + githubRepoId: 101, defaultBranch: 'main', + repoProvider: 'github', status: 'active', activeWorkspaceCount: 2, activeSessionCount: 1, lastActivityAt: '2026-02-18T12:00:00.000Z', taskCountsByStatus: {}, - linkedWorkspaces: [], + linkedWorkspaces: 2, createdAt: '2026-02-18T00:00:00.000Z', - updatedAt: '2026-02-18T00:00:00.000Z', -}; +} satisfies ProjectSummary; function renderPage() { + const queryClient = new QueryClient(); return render( - - - - } /> - create} /> - - - + + + + + } /> + create} /> + + + + ); } @@ -110,6 +116,7 @@ describe('Projects page', () => { await waitFor(() => { expect(screen.getByText('Network error')).toBeInTheDocument(); }); + expect(screen.queryByText('No projects yet')).not.toBeInTheDocument(); }); it('shows skeleton cards during loading', () => { diff --git a/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md b/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md index 2d66bc0ae7..30fc87c28d 100644 --- a/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md +++ b/tasks/active/2026-08-07-frontend-query-cache-and-rotation-resilience.md @@ -49,7 +49,9 @@ This PR deliberately combines the direct rotation fix with the smallest cache/pr - Prefetch project detail on hover, keyboard focus, and touch intent from project cards and sidebar entries. - Keep stale project data visible during background revalidation. - Show a delayed, unobtrusive global indicator only when cached query data is being refreshed. -- Clear the in-memory query cache on clean auth identity transitions. +- Namespace every authenticated query key by user identity, gate protected + rendering during identity transitions, and clear the previous in-memory + namespace. - Capture broader query migration and safe persistence as explicit follow-up work. ## Implementation Checklist @@ -61,10 +63,10 @@ This PR deliberately combines the direct rotation fix with the smallest cache/pr - [x] Migrate the `Project` parent to cached detail/installation data and keep the outlet visible on background errors/refetches. - [x] Add bounded project-detail intent prefetch from project cards and sidebar project buttons. - [x] Add a delayed global background-fetch indicator above AppShell. -- [x] Clear query data on clean signout/session-expiry/account-switch transitions, not transient auth refetch errors. +- [x] Identity-scope authenticated query keys, gate clean signout/session-expiry/account-switch transitions, and preserve the active namespace through transient same-user auth refetch errors. - [x] Add unit tests for deduplication, cache reuse, stale-data preservation, auth cleanup, indicator behavior, and intent prefetch. - [x] Add Playwright coverage for portrait→landscape rotation, request counts, indicator rendering, overflow, and mobile/desktop screenshots. -- [x] Update Rule 48 with the responsive-shell identity requirement. +- [x] Update Rule 48 with responsive-shell identity and authenticated-query isolation requirements. - [ ] Run full validation, specialist reviews, staging verification, and create a draft PR without merging. ## Acceptance Criteria @@ -74,7 +76,9 @@ This PR deliberately combines the direct rotation fix with the smallest cache/pr - Re-entering a recently loaded project/list surface renders cached data immediately; stale data remains visible while revalidation runs. - Hover/focus/touch intent on a project destination populates the exact query key consumed by `Project`. - Background revalidation shows a subtle top-edge activity cue without replacing visible content or changing layout. -- Clean auth identity changes clear query data; transient auth refetch errors preserve it. +- Authenticated queries are identity-scoped; clean auth identity changes cannot + render the previous account's data even for one frame, while transient + same-user auth refetch errors preserve the active cache. - No generic QueryClient data is written to `localStorage` or `sessionStorage` in this PR. - Mobile and desktop visual/behavioral checks pass with no horizontal overflow. @@ -83,3 +87,11 @@ This PR deliberately combines the direct rotation fix with the smallest cache/pr - Migrating every remaining hand-rolled loader in one PR. - Persisting authenticated query data across full document reloads. - Prefetching chat histories, messages, logs, diagnostics, credentials, secrets, environment values, or large file/library payloads. + +## Validation Evidence + +- `pnpm typecheck` — 16/16 tasks passed. +- `pnpm lint` — 7/7 tasks passed with zero errors; existing warning baseline remains. +- `pnpm --filter @simple-agent-manager/web test` — 240 files and 2,902 tests passed. +- `pnpm build` — 9/9 tasks passed. +- Playwright cache audit — 15 passed with 12 intentional device-specific skips across iPhone SE, iPhone 14, and desktop; rotation request-count, stale-refresh, delayed-indicator, overflow, error, single-character, and hostile-looking text cases passed. From 93c1a1fe243ca623ebcb943e3cd69d4cd7244d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 8 Aug 2026 00:04:19 +0000 Subject: [PATCH 05/57] fix(web): keep project loading states truthful --- apps/web/src/components/AppShell.tsx | 12 +++++++++--- apps/web/src/components/SidebarProjectList.tsx | 6 ++++++ apps/web/src/pages/Dashboard.tsx | 3 +-- apps/web/src/pages/Projects.tsx | 5 ++--- .../tests/playwright/frontend-cache-audit.spec.ts | 4 ++++ apps/web/tests/unit/SidebarProjectList.test.tsx | 15 +++++++++++++++ ...rontend-query-cache-and-rotation-resilience.md | 2 ++ 7 files changed, 39 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/AppShell.tsx b/apps/web/src/components/AppShell.tsx index 615bf643f6..494c99c839 100644 --- a/apps/web/src/components/AppShell.tsx +++ b/apps/web/src/components/AppShell.tsx @@ -64,7 +64,11 @@ export function AppShell({ children }: AppShellProps) { const [showGlobalNav, setShowGlobalNav] = useState(false); const [focusModeState, setFocusModeState] = useState('default'); const commandPalette = useGlobalCommandPalette(); - const { projects: sidebarProjects, loading: sidebarProjectsLoading } = useProjectList({ + const { + projects: sidebarProjects, + loading: sidebarProjectsLoading, + error: sidebarProjectsError, + } = useProjectList({ queryScope: user?.id ?? '', limit: 50, pollInterval: 60000, @@ -189,13 +193,14 @@ export function AppShell({ children }: AppShellProps) { ), - [sidebarProjects, sidebarProjectsLoading, projectId, handleProjectNavigate, user?.id], + [sidebarProjects, sidebarProjectsLoading, sidebarProjectsError, projectId, handleProjectNavigate, user?.id], ); const desktopProjectListSection = useMemo( @@ -203,13 +208,14 @@ export function AppShell({ children }: AppShellProps) { ), - [sidebarProjects, sidebarProjectsLoading, projectId, handleProjectNavigate, user?.id], + [sidebarProjects, sidebarProjectsLoading, sidebarProjectsError, projectId, handleProjectNavigate, user?.id], ); const projectHealthElement = projectId ? ( diff --git a/apps/web/src/components/SidebarProjectList.tsx b/apps/web/src/components/SidebarProjectList.tsx index 04cee43505..d87a71a550 100644 --- a/apps/web/src/components/SidebarProjectList.tsx +++ b/apps/web/src/components/SidebarProjectList.tsx @@ -39,6 +39,7 @@ function relativeTime(dateStr: string | null | undefined): string { interface SidebarProjectListProps { projects: ProjectSummary[]; loading: boolean; + error?: string | null; currentProjectId?: string; onNavigate: (path: string) => void; queryScope?: string; @@ -49,6 +50,7 @@ interface SidebarProjectListProps { export function SidebarProjectList({ projects, loading, + error = null, currentProjectId, onNavigate, queryScope = '', @@ -159,6 +161,10 @@ export function SidebarProjectList({
Loading...
+ ) : error && projects.length === 0 ? ( +
+ Projects unavailable +
) : filtered.length === 0 ? (
{filter ? `No projects match "${filter}"` : 'No projects yet'} diff --git a/apps/web/src/pages/Dashboard.tsx b/apps/web/src/pages/Dashboard.tsx index 86f3ab8a48..680416e6e6 100644 --- a/apps/web/src/pages/Dashboard.tsx +++ b/apps/web/src/pages/Dashboard.tsx @@ -12,7 +12,7 @@ export function Dashboard() { const navigate = useNavigate(); const { tasks, loading: tasksLoading, isRefreshing: tasksRefreshing, error: tasksError, refresh: refreshTasks } = useActiveTasks(); - const { projects, loading: projectsLoading, isRefreshing: projectsRefreshing, error: projectsError, refresh: refreshProjects } = useProjectList({ + const { projects, loading: projectsLoading, error: projectsError, refresh: refreshProjects } = useProjectList({ queryScope: user?.id ?? '', limit: 50, }); @@ -84,7 +84,6 @@ export function Dashboard() {

Projects

- {projectsRefreshing && }
- {/* Error message */} + {/* Failure reason */} {taskEmbed.errorMessage && (
- Error + + {classification.diagnosable ? 'Error' : 'Reason'} +
 
           {/* Actions */}
-          
- - - {adminErrorsUrl && ( - +
+ {copyState === 'copied' ? ( + <> + Copied + + ) : copyState === 'failed' ? ( + <> + Copy failed + + ) : ( + <> + Copy debug report + + )} + + + {adminErrorsUrl && ( + + + View in admin errors + + )} +
+ )} {/* Recoverable guidance */} {recoverable && (

- This session is still active. Send another message to retry — your workspace is preserved. + This session is still active. Send another message to retry — your workspace is + preserved.

)}
diff --git a/apps/web/src/components/project-message-view/index.tsx b/apps/web/src/components/project-message-view/index.tsx index 4657334233..98469bf368 100644 --- a/apps/web/src/components/project-message-view/index.tsx +++ b/apps/web/src/components/project-message-view/index.tsx @@ -141,13 +141,17 @@ function FloatingHeader({ onShowHierarchy={onShowHierarchy} /> {lc.taskEmbed?.errorMessage && ( -
, - document.body, + document.body )} ); diff --git a/apps/web/src/pages/project-chat/SessionTreeItem.tsx b/apps/web/src/pages/project-chat/SessionTreeItem.tsx index d757700b61..550000e48c 100644 --- a/apps/web/src/pages/project-chat/SessionTreeItem.tsx +++ b/apps/web/src/pages/project-chat/SessionTreeItem.tsx @@ -45,31 +45,30 @@ export const SessionTreeItem = memo(function SessionTreeItem({ task: { id: taskInfo.id, status: taskInfo.status, + errorMessage: taskInfo.errorMessage, + executionStep: taskInfo.executionStep, taskMode: taskInfo.taskMode, }, }; }, [session, taskInfo]); - const blockedByTitle = taskInfo?.blocked - ? getBlockedByTitle(session, taskInfoMap) - : undefined; + const blockedByTitle = taskInfo?.blocked ? getBlockedByTitle(session, taskInfoMap) : undefined; const isSelected = selectedSessionId === session.id; - const badge = onShowHierarchy && session.taskId ? ( - - ) : null; + const badge = + onShowHierarchy && session.taskId ? ( + + ) : null; return (
, + taskInfoMap: Map ): string | undefined { if (!session.taskId) return undefined; const info = taskInfoMap.get(session.taskId); diff --git a/apps/web/src/pages/project-chat/useTaskGroups.ts b/apps/web/src/pages/project-chat/useTaskGroups.ts index df2a3a1733..0dfbf62367 100644 --- a/apps/web/src/pages/project-chat/useTaskGroups.ts +++ b/apps/web/src/pages/project-chat/useTaskGroups.ts @@ -1,4 +1,4 @@ -import type { Task, TaskMode, TaskStatus } from '@simple-agent-manager/shared'; +import type { Task, TaskExecutionStep, TaskMode, TaskStatus } from '@simple-agent-manager/shared'; /** * Per-task metadata needed for rendering the session tree. @@ -13,6 +13,8 @@ export interface TaskInfo { title: string; parentTaskId: string | null; status: TaskStatus; + errorMessage?: string | null; + executionStep?: TaskExecutionStep | null; blocked: boolean; /** What created this task (user, cron, webhook, mcp). */ triggeredBy: string; @@ -33,6 +35,8 @@ export function buildTaskInfoMap(tasks: Task[]): Map { title: t.title, parentTaskId: t.parentTaskId, status: t.status, + errorMessage: t.errorMessage, + executionStep: t.executionStep, blocked: t.blocked ?? false, triggeredBy: t.triggeredBy ?? 'user', dispatchDepth: t.dispatchDepth ?? 0, diff --git a/apps/web/tests/playwright/failure-card-audit.spec.ts b/apps/web/tests/playwright/failure-card-audit.spec.ts index 277aaae819..b669a9ca04 100644 --- a/apps/web/tests/playwright/failure-card-audit.spec.ts +++ b/apps/web/tests/playwright/failure-card-audit.spec.ts @@ -12,7 +12,7 @@ async function screenshot(page: Page, name: string) { async function assertNoOverflow(page: Page) { const overflow = await page.evaluate( - () => document.documentElement.scrollWidth > window.innerWidth, + () => document.documentElement.scrollWidth > window.innerWidth ); expect(overflow).toBe(false); } @@ -43,7 +43,7 @@ function makeFailureCardHtml(opts: {
${ev.reason ? `

${ev.reason}

` : ''}
- `, + ` ) .join(''); @@ -53,7 +53,7 @@ function makeFailureCardHtml(opts: { ``, + ` ) .join(''); @@ -131,7 +131,12 @@ test.describe('Failure Card Visual Audit', () => { { toStatus: 'ready', actorType: 'system', time: '10m ago' }, { toStatus: 'queued', actorType: 'system', time: '10m ago' }, { toStatus: 'in progress', actorType: 'system', time: '9m ago' }, - { toStatus: 'failed', actorType: 'system', reason: 'Agent process exited unexpectedly with code 137', time: '1m ago' }, + { + toStatus: 'failed', + actorType: 'system', + reason: 'Agent process exited unexpectedly with code 137', + time: '1m ago', + }, ], ids: { Task: '01KZF49HNP8HNJDGWB4KWXHEZR', @@ -140,7 +145,7 @@ test.describe('Failure Card Visual Audit', () => { Node: '01KZFNODE1234567890', }, showAdmin: true, - }), + }) ); await screenshot(page, 'failure-card-normal'); @@ -165,10 +170,15 @@ test.describe('Failure Card Visual Audit', () => { events: [ { toStatus: 'ready', actorType: 'system', time: '30m ago' }, { toStatus: 'in progress', actorType: 'agent', time: '28m ago' }, - { toStatus: 'failed', actorType: 'system', reason: longError.slice(0, 200), time: 'Just now' }, + { + toStatus: 'failed', + actorType: 'system', + reason: longError.slice(0, 200), + time: 'Just now', + }, ], ids: { Task: '01KZF49HNP8HNJDGWB4KWXHEZR' }, - }), + }) ); await screenshot(page, 'failure-card-long-error'); @@ -179,7 +189,12 @@ test.describe('Failure Card Visual Audit', () => { const events = Array.from({ length: 30 }, (_, i) => ({ toStatus: i === 29 ? 'failed' : i < 5 ? 'queued' : 'in progress', actorType: i % 3 === 0 ? 'agent' : 'system', - reason: i === 29 ? 'Final failure after 30 transitions' : i % 5 === 0 ? `Checkpoint ${i}` : undefined, + reason: + i === 29 + ? 'Final failure after 30 transitions' + : i % 5 === 0 + ? `Checkpoint ${i}` + : undefined, time: `${30 - i}m ago`, })); @@ -192,7 +207,7 @@ test.describe('Failure Card Visual Audit', () => { guidance: 'Review the error details and retry with adjusted parameters.', events, ids: { Task: '01ABC123', Session: '01DEF456', Workspace: '01GHI789', Node: '01JKL012' }, - }), + }) ); await screenshot(page, 'failure-card-many-events'); @@ -209,7 +224,7 @@ test.describe('Failure Card Visual Audit', () => { guidance: 'Retry the task or contact support.', events: [], ids: { Task: '01ABC' }, - }), + }) ); await screenshot(page, 'failure-card-empty'); @@ -234,7 +249,7 @@ test.describe('Failure Card Visual Audit', () => { }, ], ids: { Task: '01ABC-"inject"' }, - }), + }) ); await screenshot(page, 'failure-card-special-chars'); @@ -252,7 +267,7 @@ test.describe('Failure Card Visual Audit', () => {

The task was stopped intentionally by a user or a parent agent.

- `, + ` ); await screenshot(page, 'failure-card-cancelled'); diff --git a/apps/web/tests/playwright/project-chat-recoverable-error-audit.spec.ts b/apps/web/tests/playwright/project-chat-recoverable-error-audit.spec.ts index 5e43a7e0d8..9c846b3efb 100644 --- a/apps/web/tests/playwright/project-chat-recoverable-error-audit.spec.ts +++ b/apps/web/tests/playwright/project-chat-recoverable-error-audit.spec.ts @@ -103,7 +103,22 @@ const MOCK_MESSAGES = [ }, ]; -async function setupApiMocks(page: Page) { +async function setupApiMocks(page: Page, task = MOCK_TASK) { + const isTerminalLifecycle = + task.status === 'failed' && task.executionStep === 'awaiting_human_input'; + const session = { + ...MOCK_SESSION, + ...(isTerminalLifecycle + ? { + status: 'stopped', + endedAt: NOW - 20_000, + isIdle: false, + isTerminated: true, + } + : {}), + taskId: task.id, + task, + }; await page.route('**/api/**', async (route: Route) => { const url = new URL(route.request().url()); const path = url.pathname; @@ -112,7 +127,8 @@ async function setupApiMocks(page: Page) { route.fulfill({ status, contentType: 'application/json', body: JSON.stringify(body) }); if (path.includes('/api/auth/')) return respond(200, MOCK_USER); - if (path.startsWith('/api/notifications')) return respond(200, { notifications: [], unreadCount: 0 }); + if (path.startsWith('/api/notifications')) + return respond(200, { notifications: [], unreadCount: 0 }); if (path.startsWith('/api/credentials')) return respond(200, []); if (path.startsWith('/api/provider-catalog')) return respond(200, { catalogs: [] }); if (path === '/api/trial/status') return respond(200, { available: false }); @@ -123,7 +139,7 @@ async function setupApiMocks(page: Page) { return respond(200, { id: 'workspace-recoverable-1', projectId: MOCK_PROJECT.id, - status: 'running', + status: isTerminalLifecycle ? 'stopped' : 'running', url: 'https://ws-recoverable.example.test', errorMessage: null, }); @@ -134,19 +150,20 @@ async function setupApiMocks(page: Page) { const subPath = projectMatch[2] || ''; if (subPath === '/sessions') { - return respond(200, { sessions: [MOCK_SESSION], total: 1, hasMore: false }); + return respond(200, { sessions: [session], total: 1, hasMore: false }); } if (subPath === `/sessions/${MOCK_SESSION.id}`) { - return respond(200, { session: MOCK_SESSION, messages: MOCK_MESSAGES, hasMore: false }); + return respond(200, { session, messages: MOCK_MESSAGES, hasMore: false }); } if (subPath.match(/\/sessions\/[^/]+\/messages/)) { return respond(200, { messages: MOCK_MESSAGES, hasMore: false }); } - if (subPath === '/tasks') return respond(200, { tasks: [MOCK_TASK], total: 1, nextCursor: null }); - if (subPath === `/tasks/${MOCK_TASK.id}`) return respond(200, MOCK_TASK); + if (subPath === '/tasks') return respond(200, { tasks: [task], total: 1, nextCursor: null }); + if (subPath === `/tasks/${task.id}/events`) return respond(200, { events: [] }); + if (subPath === `/tasks/${task.id}`) return respond(200, task); if (subPath === '/agent-profiles') return respond(200, { items: [] }); if (subPath.match(/\/commands/)) return respond(200, { commands: [] }); if (subPath === '/activity') return respond(200, { events: [], total: 0 }); @@ -154,7 +171,8 @@ async function setupApiMocks(page: Page) { return respond(200, MOCK_PROJECT); } - if (path === '/api/projects') return respond(200, { projects: [MOCK_PROJECT], nextCursor: null }); + if (path === '/api/projects') + return respond(200, { projects: [MOCK_PROJECT], nextCursor: null }); return respond(200, {}); }); @@ -162,29 +180,34 @@ async function setupApiMocks(page: Page) { async function screenshot(page: Page, name: string) { await page.waitForTimeout(600); + const viewport = page.viewportSize(); + const suffix = viewport ? `${viewport.width}x${viewport.height}` : 'unknown'; await page.screenshot({ - path: `../../.codex/tmp/playwright-screenshots/${name}.png`, + path: `../../.codex/tmp/playwright-screenshots/${name}-${suffix}.png`, fullPage: true, }); } async function assertNoHorizontalOverflow(page: Page) { const overflow = await page.evaluate( - () => document.documentElement.scrollWidth > window.innerWidth, + () => document.documentElement.scrollWidth > window.innerWidth ); expect(overflow).toBe(false); } test.describe('Project chat recoverable error banner', () => { - test('renders recoverable error guidance and keeps the composer enabled', async ({ page }, testInfo) => { + test('renders recoverable error guidance and keeps the composer enabled', async ({ + page, + }, testInfo) => { await setupApiMocks(page); await page.goto('/projects/proj-test-1/chat/session-recoverable-1'); await page.waitForTimeout(1200); - await expect(page.getByText('Agent error:')).toBeVisible(); - await expect(page.getByText('You can send another message to retry')).toBeVisible(); + const recoverableCard = page.locator('[data-failure-kind="diagnosable"]'); + await expect(recoverableCard.getByText('Cloud capacity')).toBeVisible(); + await expect(recoverableCard.getByText('Recoverable')).toBeVisible(); - const composer = page.getByPlaceholder('Send a message to resume the agent...'); + const composer = page.getByRole('combobox'); await expect(composer).toBeVisible(); await expect(composer).toBeEnabled(); @@ -193,7 +216,52 @@ test.describe('Project chat recoverable error banner', () => { page, testInfo.project.name.includes('Desktop') ? 'project-chat-recoverable-error-desktop' - : 'project-chat-recoverable-error-mobile', + : 'project-chat-recoverable-error-mobile' + ); + }); + + test('renders input expiry as a neutral lifecycle outcome in the real chat shell', async ({ + page, + }, testInfo) => { + await setupApiMocks(page, { + ...MOCK_TASK, + status: 'failed', + executionStep: 'awaiting_human_input', + errorMessage: 'Human input request expired after timeout', + taskMode: 'task', + }); + await page.goto('/projects/proj-test-1/chat/session-recoverable-1'); + + const lifecycleCard = page.locator('[data-failure-kind="lifecycle"]'); + await expect(lifecycleCard).toBeVisible(); + await expect(lifecycleCard.getByText('Input request expired')).toBeVisible(); + await expect(lifecycleCard.getByText('Retryable')).toHaveCount(0); + await expect(lifecycleCard.getByText('Recoverable')).toHaveCount(0); + await expect( + page.getByLabel('Conversation').getByText('Stopped', { exact: true }) + ).toBeVisible(); + if ((page.viewportSize()?.width ?? 0) >= 768) { + await expect(page.getByTitle('Stopped')).toBeVisible(); + await expect(page.getByTitle('Failed')).toHaveCount(0); + } + await expect(page.getByTestId('failure-card-shell')).not.toHaveClass(/after:bg/); + await expect(page.getByTestId('failure-card-shell')).toHaveCSS( + 'box-shadow', + 'rgba(0, 0, 0, 0.4) 0px 4px 24px 0px' + ); + + await lifecycleCard.getByRole('button').click(); + await expect(page.getByText(/No debugging is needed/i)).toBeVisible(); + await expect(lifecycleCard.getByText('Reason')).toBeVisible(); + await expect(lifecycleCard.getByText('Error', { exact: true })).toHaveCount(0); + await expect(lifecycleCard.getByText('Copy debug report')).toHaveCount(0); + await expect(lifecycleCard.getByText('View in admin errors')).toHaveCount(0); + await assertNoHorizontalOverflow(page); + await screenshot( + page, + testInfo.project.name.includes('Desktop') + ? 'project-chat-input-expired-desktop' + : 'project-chat-input-expired-mobile' ); }); }); diff --git a/apps/web/tests/unit/debug-failure-card.test.tsx b/apps/web/tests/unit/debug-failure-card.test.tsx index abed91a0f5..b43c20d73c 100644 --- a/apps/web/tests/unit/debug-failure-card.test.tsx +++ b/apps/web/tests/unit/debug-failure-card.test.tsx @@ -67,13 +67,7 @@ describe('FailureCard', () => { }); it('renders classification label and explanation for agent crash', () => { - render( - - ); + render(); expect(screen.getByText('Agent crashed')).toBeInTheDocument(); expect(screen.getByText(/exited unexpectedly/i)).toBeInTheDocument(); @@ -108,15 +102,34 @@ describe('FailureCard', () => { expect(screen.getByText('Cancelled')).toBeInTheDocument(); }); - it('shows Recoverable badge when recoverable', () => { + it('renders expected human-input expiry as a neutral lifecycle outcome', async () => { + mocks.useAuth.mockReturnValue({ isSuperadmin: true }); render( ); + expect(screen.getByText('Input request expired')).toBeInTheDocument(); + expect(screen.queryByText('Retryable')).not.toBeInTheDocument(); + fireEvent.click(screen.getByRole('button', { name: /Input request expired/i })); + await waitFor(() => { + expect(screen.getByText(/No debugging is needed/i)).toBeInTheDocument(); + }); + expect(screen.getByText('Reason')).toBeInTheDocument(); + expect(screen.queryByText('Error')).not.toBeInTheDocument(); + expect(screen.queryByText('Copy debug report')).not.toBeInTheDocument(); + expect(screen.queryByText('View in admin errors')).not.toBeInTheDocument(); + }); + + it('shows Recoverable badge when recoverable', () => { + render(); + expect(screen.getByText('Recoverable')).toBeInTheDocument(); }); @@ -147,13 +160,7 @@ describe('FailureCard', () => { }); it('renders lifecycle timeline events from listTaskEvents', async () => { - render( - - ); + render(); fireEvent.click(screen.getByRole('button', { name: /Agent crashed/i })); @@ -248,18 +255,16 @@ describe('FailureCard', () => { const link = screen.getByText('View in admin errors'); expect(link).toBeInTheDocument(); expect(link.closest('a')).toHaveAttribute('href', expect.stringContaining('/admin/errors')); - expect(link.closest('a')).toHaveAttribute('href', expect.stringContaining('sessionId=sess-1')); + expect(link.closest('a')).toHaveAttribute( + 'href', + expect.stringContaining('sessionId=sess-1') + ); + expect(link.closest('a')).toHaveAttribute('href', expect.stringContaining('taskId=task-001')); }); }); it('shows recoverable guidance when expanded', async () => { - render( - - ); + render(); fireEvent.click(screen.getByRole('button', { name: /Agent crashed/i })); @@ -287,13 +292,7 @@ describe('FailureCard', () => { it('handles empty events gracefully', async () => { mocks.listTaskEvents.mockResolvedValue({ events: [] }); - render( - - ); + render(); fireEvent.click(screen.getByRole('button', { name: /Agent crashed/i })); @@ -305,13 +304,7 @@ describe('FailureCard', () => { it('handles event loading error gracefully', async () => { mocks.listTaskEvents.mockRejectedValue(new Error('Network error')); - render( - - ); + render(); fireEvent.click(screen.getByRole('button', { name: /Agent crashed/i })); @@ -328,13 +321,7 @@ describe('FailureCard', () => { configurable: true, }); - render( - - ); + render(); fireEvent.click(screen.getByRole('button', { name: /Agent crashed/i })); await waitFor(() => { @@ -355,13 +342,7 @@ describe('FailureCard', () => { configurable: true, }); - render( - - ); + render(); fireEvent.click(screen.getByRole('button', { name: /Agent crashed/i })); await waitFor(() => { diff --git a/apps/web/tests/unit/lib/chat-session-utils.test.ts b/apps/web/tests/unit/lib/chat-session-utils.test.ts index 77b415debb..4e40cf47ad 100644 --- a/apps/web/tests/unit/lib/chat-session-utils.test.ts +++ b/apps/web/tests/unit/lib/chat-session-utils.test.ts @@ -1,4 +1,4 @@ -import { afterEach,beforeEach, describe, expect, it, vi } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import type { ChatSessionResponse } from '../../../src/lib/api'; import { @@ -43,14 +43,38 @@ describe('getSessionState', () => { ['idle session', { isIdle: true }, 'idle'], ['agentCompletedAt set', { agentCompletedAt: Date.now() }, 'idle'], ['active session', { status: 'active' }, 'active'], - ['task failed + active session', { status: 'active', task: { id: 't-1', status: 'failed' } }, 'terminated'], - ['task completed + active session', { status: 'active', task: { id: 't-1', status: 'completed' } }, 'terminated'], - ['task cancelled + active session', { status: 'active', task: { id: 't-1', status: 'cancelled' } }, 'terminated'], - ['task in_progress + active session', { status: 'active', task: { id: 't-1', status: 'in_progress' } }, 'active'], + [ + 'task failed + active session', + { status: 'active', task: { id: 't-1', status: 'failed' } }, + 'terminated', + ], + [ + 'task completed + active session', + { status: 'active', task: { id: 't-1', status: 'completed' } }, + 'terminated', + ], + [ + 'task cancelled + active session', + { status: 'active', task: { id: 't-1', status: 'cancelled' } }, + 'terminated', + ], + [ + 'task in_progress + active session', + { status: 'active', task: { id: 't-1', status: 'in_progress' } }, + 'active', + ], ['task with no status', { status: 'active', task: { id: 't-1' } }, 'active'], ['no task embed', { status: 'active' }, 'active'], - ['task failed + idle (priority)', { status: 'active', isIdle: true, task: { id: 't-1', status: 'failed' } }, 'terminated'], - ['task completed + agentCompletedAt (priority)', { status: 'active', agentCompletedAt: Date.now(), task: { id: 't-1', status: 'completed' } }, 'terminated'], + [ + 'task failed + idle (priority)', + { status: 'active', isIdle: true, task: { id: 't-1', status: 'failed' } }, + 'terminated', + ], + [ + 'task completed + agentCompletedAt (priority)', + { status: 'active', agentCompletedAt: Date.now(), task: { id: 't-1', status: 'completed' } }, + 'terminated', + ], ] as const)('returns correct state for %s', (_label, overrides, expected) => { expect(getSessionState(makeSession(overrides as Partial))).toBe(expected); }); @@ -83,11 +107,15 @@ describe('isStaleSession', () => { }); it('returns true for session with activity beyond threshold', () => { - expect(isStaleSession(makeSession({ lastMessageAt: Date.now() - STALE_SESSION_THRESHOLD_MS - 1 }))).toBe(true); + expect( + isStaleSession(makeSession({ lastMessageAt: Date.now() - STALE_SESSION_THRESHOLD_MS - 1 })) + ).toBe(true); }); it('returns false at exact threshold boundary', () => { - expect(isStaleSession(makeSession({ lastMessageAt: Date.now() - STALE_SESSION_THRESHOLD_MS }))).toBe(false); + expect( + isStaleSession(makeSession({ lastMessageAt: Date.now() - STALE_SESSION_THRESHOLD_MS })) + ).toBe(false); }); }); @@ -123,9 +151,21 @@ describe('isActiveSession', () => { ['failed session status', { status: 'failed' }, false], ['unknown status (non-terminal)', { status: 'pending' }, true], ['task failed + active', { status: 'active', task: { id: 't-1', status: 'failed' } }, false], - ['task completed + active', { status: 'active', task: { id: 't-1', status: 'completed' } }, false], - ['task cancelled + active', { status: 'active', task: { id: 't-1', status: 'cancelled' } }, false], - ['task in_progress + active', { status: 'active', task: { id: 't-1', status: 'in_progress' } }, true], + [ + 'task completed + active', + { status: 'active', task: { id: 't-1', status: 'completed' } }, + false, + ], + [ + 'task cancelled + active', + { status: 'active', task: { id: 't-1', status: 'cancelled' } }, + false, + ], + [ + 'task in_progress + active', + { status: 'active', task: { id: 't-1', status: 'in_progress' } }, + true, + ], ] as const)('returns %s → %s', (_label, overrides, expected) => { expect(isActiveSession(makeSession(overrides as Partial))).toBe(expected); }); @@ -152,7 +192,11 @@ describe('STATE_COLORS, STATE_LABELS, and STATE_BADGE_BG', () => { describe('getSessionMode', () => { it.each([ ['explicit task mode', { task: { id: 't-1', taskMode: 'task' as const } }, 'task'], - ['explicit conversation mode', { task: { id: 't-1', taskMode: 'conversation' as const } }, 'conversation'], + [ + 'explicit conversation mode', + { task: { id: 't-1', taskMode: 'conversation' as const } }, + 'conversation', + ], ['taskId present without taskMode', { taskId: 't-1' }, 'task'], ['no task association', {}, 'conversation'], ['null taskMode with taskId', { taskId: 't-1', task: { id: 't-1', taskMode: null } }, 'task'], @@ -167,27 +211,39 @@ describe('getSessionMode', () => { describe('getAttentionState', () => { it('returns needs_input when attention marker is present', () => { - expect(getAttentionState(makeSession({ - status: 'active', - attention: { kind: 'needs_input', createdAt: Date.now(), expiresAt: null, reason: null }, - }))).toBe('needs_input'); + expect( + getAttentionState( + makeSession({ + status: 'active', + attention: { kind: 'needs_input', createdAt: Date.now(), expiresAt: null, reason: null }, + }) + ) + ).toBe('needs_input'); }); it('needs_input attention marker takes precedence over idle state', () => { - expect(getAttentionState(makeSession({ - status: 'active', - isIdle: true, - attention: { kind: 'needs_input', createdAt: Date.now(), expiresAt: null, reason: null }, - }))).toBe('needs_input'); + expect( + getAttentionState( + makeSession({ + status: 'active', + isIdle: true, + attention: { kind: 'needs_input', createdAt: Date.now(), expiresAt: null, reason: null }, + }) + ) + ).toBe('needs_input'); }); it('needs_input attention marker takes precedence over task completed', () => { // Edge case: marker from before completion, not yet resolved - expect(getAttentionState(makeSession({ - status: 'active', - task: { id: 't-1', status: 'completed' }, - attention: { kind: 'needs_input', createdAt: Date.now(), expiresAt: null, reason: null }, - }))).toBe('needs_input'); + expect( + getAttentionState( + makeSession({ + status: 'active', + task: { id: 't-1', status: 'completed' }, + attention: { kind: 'needs_input', createdAt: Date.now(), expiresAt: null, reason: null }, + }) + ) + ).toBe('needs_input'); }); it.each([ @@ -201,37 +257,70 @@ describe('getAttentionState', () => { ['session active', { status: 'active' }, 'active'], ['unknown status', { status: 'pending' }, 'stopped'], ] as const)('returns correct state for %s', (_label, overrides, expected) => { - expect(getAttentionState(makeSession(overrides as Partial))).toBe(expected); + expect(getAttentionState(makeSession(overrides as Partial))).toBe( + expected + ); }); it('returns active for in_progress task with active session', () => { - expect(getAttentionState(makeSession({ - status: 'active', - task: { id: 't-1', status: 'in_progress' }, - }))).toBe('active'); + expect( + getAttentionState( + makeSession({ + status: 'active', + task: { id: 't-1', status: 'in_progress' }, + }) + ) + ).toBe('active'); + }); + + it('renders a failed task with an expected lifecycle reason as stopped', () => { + expect( + getAttentionState( + makeSession({ + status: 'stopped', + task: { + id: 't-1', + status: 'failed', + errorMessage: 'Human input request expired after timeout', + }, + }) + ) + ).toBe('stopped'); }); it('returns stopped when no attention marker and null attention field', () => { - expect(getAttentionState(makeSession({ - status: 'stopped', - attention: null, - }))).toBe('stopped'); + expect( + getAttentionState( + makeSession({ + status: 'stopped', + attention: null, + }) + ) + ).toBe('stopped'); }); it('non-needs_input attention marker falls through to lifecycle state', () => { // Backend only creates needs_input markers today. Other kinds (if added) // fall through to lifecycle-based derivation, not the marker kind. - expect(getAttentionState(makeSession({ - status: 'active', - attention: { kind: 'error', createdAt: Date.now(), expiresAt: null, reason: null }, - }))).toBe('active'); + expect( + getAttentionState( + makeSession({ + status: 'active', + attention: { kind: 'error', createdAt: Date.now(), expiresAt: null, reason: null }, + }) + ) + ).toBe('active'); }); it('error attention state is derived from session.status, not attention marker', () => { - expect(getAttentionState(makeSession({ - status: 'failed', - attention: null, - }))).toBe('error'); + expect( + getAttentionState( + makeSession({ + status: 'failed', + attention: null, + }) + ) + ).toBe('error'); }); }); diff --git a/apps/web/tests/unit/pages/session-icon-data-flow.test.tsx b/apps/web/tests/unit/pages/session-icon-data-flow.test.tsx index b3dd0671b2..aa4c735681 100644 --- a/apps/web/tests/unit/pages/session-icon-data-flow.test.tsx +++ b/apps/web/tests/unit/pages/session-icon-data-flow.test.tsx @@ -70,6 +70,7 @@ describe('Session icon data flow: list session + task status → correct icon', taskStatus: string; sessionStatus: string; expectedTitle: string; + errorMessage?: string; }> = [ { label: 'completed task shows checkmark', @@ -83,6 +84,13 @@ describe('Session icon data flow: list session + task status → correct icon', sessionStatus: 'stopped', expectedTitle: 'Failed', }, + { + label: 'input expiry shows neutral stopped icon', + taskStatus: 'failed', + sessionStatus: 'stopped', + expectedTitle: 'Stopped', + errorMessage: 'Human input request expired after timeout', + }, { label: 'cancelled task shows pause', taskStatus: 'cancelled', @@ -97,7 +105,7 @@ describe('Session icon data flow: list session + task status → correct icon', }, ]; - for (const { label, taskStatus, sessionStatus, expectedTitle } of cases) { + for (const { label, taskStatus, sessionStatus, expectedTitle, errorMessage } of cases) { it(label, () => { const session = makeListSession({ taskId: 'task-1', @@ -105,16 +113,20 @@ describe('Session icon data flow: list session + task status → correct icon', }); const taskInfoMap = new Map([ - ['task-1', { - id: 'task-1', - title: 'Test task', - parentTaskId: null, - status: taskStatus as TaskInfo['status'], - blocked: false, - triggeredBy: 'user', - dispatchDepth: 0, - taskMode: 'task', - }], + [ + 'task-1', + { + id: 'task-1', + title: 'Test task', + parentTaskId: null, + status: taskStatus as TaskInfo['status'], + errorMessage, + blocked: false, + triggeredBy: 'user', + dispatchDepth: 0, + taskMode: 'task', + }, + ], ]); const { container } = render( @@ -123,7 +135,7 @@ describe('Session icon data flow: list session + task status → correct icon', selectedSessionId={null} onSelect={() => {}} taskInfoMap={taskInfoMap} - />, + /> ); const iconSpan = container.querySelector(`[title="${expectedTitle}"]`); @@ -144,7 +156,7 @@ describe('Session icon data flow: list session + task status → correct icon', selectedSessionId={null} onSelect={() => {}} taskInfoMap={new Map()} - />, + /> ); const iconSpan = container.querySelector('[title="Idle"]'); @@ -155,20 +167,28 @@ describe('Session icon data flow: list session + task status → correct icon', const session = makeListSession({ taskId: 'task-1', status: 'active', - attention: { kind: 'needs_input', createdAt: Date.now(), expiresAt: null, reason: 'Waiting for approval' }, + attention: { + kind: 'needs_input', + createdAt: Date.now(), + expiresAt: null, + reason: 'Waiting for approval', + }, }); const taskInfoMap = new Map([ - ['task-1', { - id: 'task-1', - title: 'Test task', - parentTaskId: null, - status: 'in_progress', - blocked: false, - triggeredBy: 'user', - dispatchDepth: 0, - taskMode: 'task', - }], + [ + 'task-1', + { + id: 'task-1', + title: 'Test task', + parentTaskId: null, + status: 'in_progress', + blocked: false, + triggeredBy: 'user', + dispatchDepth: 0, + taskMode: 'task', + }, + ], ]); const { container } = render( @@ -177,7 +197,7 @@ describe('Session icon data flow: list session + task status → correct icon', selectedSessionId={null} onSelect={() => {}} taskInfoMap={taskInfoMap} - />, + /> ); const iconSpan = container.querySelector('[title="Needs input"]'); @@ -203,16 +223,19 @@ describe('Session with existing task embed (detail endpoint)', () => { }); const taskInfoMap = new Map([ - ['task-1', { - id: 'task-1', - title: 'Test task', - parentTaskId: null, - status: 'completed', - blocked: false, - triggeredBy: 'user', - dispatchDepth: 0, - taskMode: 'task', - }], + [ + 'task-1', + { + id: 'task-1', + title: 'Test task', + parentTaskId: null, + status: 'completed', + blocked: false, + triggeredBy: 'user', + dispatchDepth: 0, + taskMode: 'task', + }, + ], ]); const { container } = render( @@ -221,7 +244,7 @@ describe('Session with existing task embed (detail endpoint)', () => { selectedSessionId={null} onSelect={() => {}} taskInfoMap={taskInfoMap} - />, + /> ); const iconSpan = container.querySelector('[title="Completed"]'); @@ -240,22 +263,37 @@ describe('SessionItem renders correct icon for each attention state', () => { expectedTitle: string; }> = [ { label: 'active', session: { status: 'active' }, expectedTitle: 'Running' }, - { label: 'idle', session: { status: 'active', isIdle: true, agentCompletedAt: Date.now() }, expectedTitle: 'Idle' }, - { label: 'completed', session: { status: 'stopped', task: { id: 't', status: 'completed' } }, expectedTitle: 'Completed' }, - { label: 'failed', session: { status: 'stopped', task: { id: 't', status: 'failed' } }, expectedTitle: 'Failed' }, + { + label: 'idle', + session: { status: 'active', isIdle: true, agentCompletedAt: Date.now() }, + expectedTitle: 'Idle', + }, + { + label: 'completed', + session: { status: 'stopped', task: { id: 't', status: 'completed' } }, + expectedTitle: 'Completed', + }, + { + label: 'failed', + session: { status: 'stopped', task: { id: 't', status: 'failed' } }, + expectedTitle: 'Failed', + }, { label: 'stopped', session: { status: 'stopped' }, expectedTitle: 'Stopped' }, { label: 'error', session: { status: 'failed' }, expectedTitle: 'Error' }, - { label: 'needs_input', session: { status: 'active', attention: { kind: 'needs_input', createdAt: Date.now(), expiresAt: null, reason: null } }, expectedTitle: 'Needs input' }, + { + label: 'needs_input', + session: { + status: 'active', + attention: { kind: 'needs_input', createdAt: Date.now(), expiresAt: null, reason: null }, + }, + expectedTitle: 'Needs input', + }, ]; for (const { label, session, expectedTitle } of iconCases) { it(`renders "${expectedTitle}" icon for ${label} state`, () => { const { container } = render( - {}} - />, + {}} /> ); const iconSpan = container.querySelector(`[title="${expectedTitle}"]`); @@ -276,16 +314,19 @@ describe('Session mode enrichment: conversation vs task', () => { }); const taskInfoMap = new Map([ - ['task-conv', { - id: 'task-conv', - title: 'Conversation task', - parentTaskId: null, - status: 'in_progress', - blocked: false, - triggeredBy: 'user', - dispatchDepth: 0, - taskMode: 'conversation', - }], + [ + 'task-conv', + { + id: 'task-conv', + title: 'Conversation task', + parentTaskId: null, + status: 'in_progress', + blocked: false, + triggeredBy: 'user', + dispatchDepth: 0, + taskMode: 'conversation', + }, + ], ]); const { container } = render( @@ -294,7 +335,7 @@ describe('Session mode enrichment: conversation vs task', () => { selectedSessionId={null} onSelect={() => {}} taskInfoMap={taskInfoMap} - />, + /> ); const modeLabel = container.querySelector('[title="Conversation"]'); @@ -308,16 +349,19 @@ describe('Session mode enrichment: conversation vs task', () => { }); const taskInfoMap = new Map([ - ['task-auto', { - id: 'task-auto', - title: 'Autonomous task', - parentTaskId: null, - status: 'in_progress', - blocked: false, - triggeredBy: 'user', - dispatchDepth: 0, - taskMode: 'task', - }], + [ + 'task-auto', + { + id: 'task-auto', + title: 'Autonomous task', + parentTaskId: null, + status: 'in_progress', + blocked: false, + triggeredBy: 'user', + dispatchDepth: 0, + taskMode: 'task', + }, + ], ]); const { container } = render( @@ -326,7 +370,7 @@ describe('Session mode enrichment: conversation vs task', () => { selectedSessionId={null} onSelect={() => {}} taskInfoMap={taskInfoMap} - />, + /> ); const modeLabel = container.querySelector('[title="Task"]'); diff --git a/apps/www/src/content/blog/agents-managing-agents.md b/apps/www/src/content/blog/agents-managing-agents.md index ef433c8e92..b6973a8f86 100644 --- a/apps/www/src/content/blog/agents-managing-agents.md +++ b/apps/www/src/content/blog/agents-managing-agents.md @@ -1,9 +1,9 @@ --- -title: "Agents Managing Agents" +title: 'Agents Managing Agents' date: 2026-04-08 author: Raphaël Titsworth-Morin category: devlog -tags: ["ai-agents", "open-source", "architecture", "mcp", "orchestration"] +tags: ['ai-agents', 'open-source', 'architecture', 'mcp', 'orchestration'] excerpt: "We built agent-to-agent orchestration into SAM. Here's what we learned about the surprisingly hard problems hiding inside 'just let agents coordinate.'" --- @@ -31,7 +31,7 @@ We built six MCP tools that give parent agents real control over their children. **`send_message_to_subtask`** injects a user-role message into a running child agent's session. The parent can course-correct a child mid-execution without stopping it. This goes directly to the child's agent session over HTTP. No polling, no queue. The child sees it as if a human typed something. -**`stop_subtask`** shuts down a child agent. But not abruptly. It sends an optional warning message first ("wrap up, you're about to be stopped"), waits a configurable grace period (default 5 seconds), then hard-stops the session. The child gets a chance to commit its work. The task status gets updated to failed with the reason. +**`stop_subtask`** shuts down a child agent. But not abruptly. It sends an optional warning message first ("wrap up, you're about to be stopped"), waits a configurable grace period (default 5 seconds), then hard-stops the session. The child gets a chance to commit its work. The task status gets updated to cancelled with the reason. **`retry_subtask`** stops a failed child and dispatches a fresh replacement. The new task description automatically includes what went wrong last time, so the retry agent has context about the failure. Retries count against the parent's child limit to prevent infinite loops. diff --git a/apps/www/src/content/docs/docs/reference/configuration.md b/apps/www/src/content/docs/docs/reference/configuration.md index 6584d52b10..1d632bb5b3 100644 --- a/apps/www/src/content/docs/docs/reference/configuration.md +++ b/apps/www/src/content/docs/docs/reference/configuration.md @@ -457,6 +457,7 @@ Webhook damping uses Cloudflare KV's eventually consistent read-update-write beh | `MCP_DISPATCH_MAX_DEPTH` | `3` | Max recursion depth for dispatch_task | | `MCP_DISPATCH_MAX_PER_TASK` | `5` | Max dispatched tasks per parent task | | `MCP_DISPATCH_MAX_ACTIVE_PER_PROJECT` | `10` | Max active dispatched tasks per project | +| `ORCHESTRATOR_STOP_CAS_MAX_ATTEMPTS` | `2` | Task-status CAS attempts after a hard stop | ## Voice & Text-to-Speech diff --git a/packages/shared/src/failure-classification.ts b/packages/shared/src/failure-classification.ts index c243020c26..0451a3663f 100644 --- a/packages/shared/src/failure-classification.ts +++ b/packages/shared/src/failure-classification.ts @@ -12,6 +12,7 @@ export type FailureCode = | 'cancelled' + | 'input-expired' | 'capacity' | 'provisioning' | 'agent-install' @@ -34,6 +35,8 @@ export interface FailureClassification { guidance: string; /** Whether retrying the same task/session is likely to help. */ retryable: boolean; + /** False for expected lifecycle outcomes that are not themselves bugs. */ + diagnosable: boolean; } interface FailureRule { @@ -42,6 +45,7 @@ interface FailureRule { explanation: string; guidance: string; retryable: boolean; + diagnosable: boolean; patterns: RegExp[]; } @@ -57,14 +61,32 @@ const FAILURE_RULES: FailureRule[] = [ explanation: 'The task was stopped intentionally by a user or a parent agent.', guidance: 'No action needed. Start a new task or retry if this was unintended.', retryable: true, - patterns: [/\bcancell?ed\b/, /stopped by (the )?(user|parent|orchestrator)/, /stop_subtask/], + diagnosable: false, + patterns: [ + /\bcancell?ed\b/, + /stopped[ _]by[ _](the[ _])?(user|parent|orchestrator)/, + /stop_subtask/, + ], + }, + { + code: 'input-expired', + label: 'Input request expired', + explanation: + 'No human reply arrived before the configured input window ended, so SAM closed the task.', + guidance: 'No debugging is needed. Retry the task if you still want to continue the work.', + retryable: true, + diagnosable: false, + patterns: [/human input request expired/, /input request expired after timeout/], }, { code: 'capacity', label: 'Cloud capacity', - explanation: 'The cloud provider refused to create a VM because an account or datacenter limit was reached.', - guidance: 'Free unused nodes or wait for capacity, then retry. Admins can check provider limits.', + explanation: + 'The cloud provider refused to create a VM because an account or datacenter limit was reached.', + guidance: + 'Free unused nodes or wait for capacity, then retry. Admins can check provider limits.', retryable: true, + diagnosable: true, patterns: [ /server limit reached/, /resource_unavailable/, @@ -78,8 +100,10 @@ const FAILURE_RULES: FailureRule[] = [ code: 'credentials', label: 'Credentials / billing', explanation: 'An API key, OAuth token, or account balance problem stopped the agent.', - guidance: 'Check the agent credential in Settings (API key validity, OAuth login, or provider credit balance), then retry.', + guidance: + 'Check the agent credential in Settings (API key validity, OAuth login, or provider credit balance), then retry.', retryable: true, + diagnosable: true, patterns: [ /credit balance/, /insufficient (credit|funds|quota)/, @@ -98,6 +122,7 @@ const FAILURE_RULES: FailureRule[] = [ explanation: 'The LLM provider was temporarily overloaded or rate-limited the request.', guidance: 'This is usually transient. Wait a few minutes and retry.', retryable: true, + diagnosable: true, patterns: [ /\boverloaded\b/, /rate.?limit/, @@ -112,8 +137,10 @@ const FAILURE_RULES: FailureRule[] = [ code: 'agent-install', label: 'Agent install failed', explanation: 'The coding agent could not be installed inside the workspace.', - guidance: 'Retry the task. If it persists, check the node network/debug package or try a different agent type.', + guidance: + 'Retry the task. If it persists, check the node network/debug package or try a different agent type.', retryable: true, + diagnosable: true, patterns: [ /(install|installation).*(agent|claude|codex|gemini|opencode|amp)/, /(agent|claude|codex|gemini|opencode|amp).*(install|installation) (failed|error|timed out)/, @@ -124,8 +151,10 @@ const FAILURE_RULES: FailureRule[] = [ code: 'provisioning', label: 'Provisioning failed', explanation: 'The workspace or VM did not finish starting up.', - guidance: 'Retry the task — a fresh node will be provisioned. If it repeats, check the node debug package or provider status.', + guidance: + 'Retry the task — a fresh node will be provisioned. If it repeats, check the node debug package or provider status.', retryable: true, + diagnosable: true, patterns: [ /provision(ing)? (failed|error|timed? ?out)/, /node provisioning may have failed/, @@ -141,16 +170,25 @@ const FAILURE_RULES: FailureRule[] = [ code: 'prompt-timeout', label: 'Prompt timed out', explanation: 'The agent ran a single turn longer than the allowed time and was force-stopped.', - guidance: 'Break the work into smaller prompts, or retry. Long orchestration should report progress between turns.', + guidance: + 'Break the work into smaller prompts, or retry. Long orchestration should report progress between turns.', retryable: true, - patterns: [/prompt.*(timed? ?out|force.?stopped)/, /force.?stopped.*prompt/, /acp_task_prompt_timeout/], + diagnosable: true, + patterns: [ + /prompt.*(timed? ?out|force.?stopped)/, + /force.?stopped.*prompt/, + /acp_task_prompt_timeout/, + ], }, { code: 'runtime-lost', label: 'Runtime lost', - explanation: 'The container or VM running the agent died and automatic recovery could not restore it.', - guidance: 'Your chat history is preserved. Send a follow-up message to resume on a fresh runtime, or retry the task.', + explanation: + 'The container or VM running the agent died and automatic recovery could not restore it.', + guidance: + 'Your chat history is preserved. Send a follow-up message to resume on a fresh runtime, or retry the task.', retryable: true, + diagnosable: true, patterns: [ /runtime recovery exhausted/, /instant runtime recovery/, @@ -167,8 +205,10 @@ const FAILURE_RULES: FailureRule[] = [ code: 'agent-crash', label: 'Agent crashed', explanation: 'The agent process exited unexpectedly while working.', - guidance: 'SAM usually recovers crashed sessions automatically. If it did not, send a follow-up message or retry.', + guidance: + 'SAM usually recovers crashed sessions automatically. If it did not, send a follow-up message or retry.', retryable: true, + diagnosable: true, patterns: [ /peer disconnected/, /process (exited|crashed|terminated)/, @@ -182,16 +222,25 @@ const FAILURE_RULES: FailureRule[] = [ code: 'stalled', label: 'Stalled', explanation: 'The task stopped making progress and was terminated by the platform watchdog.', - guidance: 'Retry the task. If this repeats, check whether the agent was waiting on something (input, network, a long tool call).', + guidance: + 'Retry the task. If this repeats, check whether the agent was waiting on something (input, network, a long tool call).', retryable: true, - patterns: [/task stuck in/, /\bstuck\b.*(threshold|timeout)/, /no (progress|activity|output) (for|since)/, /watchdog/], + diagnosable: true, + patterns: [ + /task stuck in/, + /\bstuck\b.*(threshold|timeout)/, + /no (progress|activity|output) (for|since)/, + /watchdog/, + ], }, { code: 'network', label: 'Network error', - explanation: 'A network problem interrupted communication between SAM and the workspace or provider.', + explanation: + 'A network problem interrupted communication between SAM and the workspace or provider.', guidance: 'Usually transient — retry. If it persists, check the node status page.', retryable: true, + diagnosable: true, patterns: [ /\betimedout\b|\beconnrefused\b|\benotfound\b/, /network (error|failure|unreachable)/, @@ -207,8 +256,10 @@ const UNKNOWN_CLASSIFICATION: FailureClassification = { code: 'unknown', label: 'Failed', explanation: 'The task failed for a reason SAM could not automatically classify.', - guidance: 'Read the error details below. Copy the debug report and paste it to an agent to investigate.', + guidance: + 'Read the error details below. Copy the debug report and paste it to an agent to investigate.', retryable: true, + diagnosable: true, }; /** @@ -231,6 +282,7 @@ export function classifyFailure( explanation: rule.explanation, guidance: rule.guidance, retryable: rule.retryable, + diagnosable: rule.diagnosable, }; } } diff --git a/packages/shared/tests/unit/failure-classification.test.ts b/packages/shared/tests/unit/failure-classification.test.ts index 1530051350..2d708356a3 100644 --- a/packages/shared/tests/unit/failure-classification.test.ts +++ b/packages/shared/tests/unit/failure-classification.test.ts @@ -5,6 +5,7 @@ import { classifyFailure } from '../../src/failure-classification'; describe('classifyFailure', () => { it.each([ ['cancelled', 'Task was cancelled by the user'], + ['input-expired', 'Human input request expired after timeout'], ['capacity', 'Cloud provider reported server limit reached'], ['credentials', 'Authentication failed: token expired'], ['provider-overload', 'Provider returned 529 overloaded'], @@ -44,6 +45,14 @@ describe('classifyFailure', () => { ); }); + it.each([ + ['stopped_by_parent: Session stalled', 'cancelled'], + ['Stopped by parent: No longer needed', 'cancelled'], + ['Human input request expired after timeout', 'input-expired'], + ] as const)('treats normal lifecycle outcome %s as non-diagnosable', (message, code) => { + expect(classifyFailure(message)).toMatchObject({ code, diagnosable: false }); + }); + it.each([undefined, null, '', 'an entirely novel failure mode'])( 'falls back to unknown for unclassified input %s', (message) => { @@ -54,6 +63,7 @@ describe('classifyFailure', () => { guidance: 'Read the error details below. Copy the debug report and paste it to an agent to investigate.', retryable: true, + diagnosable: true, }); } ); diff --git a/packages/vm-agent/internal/acp/session_host.go b/packages/vm-agent/internal/acp/session_host.go index 52a4557569..93e75b2b2c 100644 --- a/packages/vm-agent/internal/acp/session_host.go +++ b/packages/vm-agent/internal/acp/session_host.go @@ -258,9 +258,10 @@ type SessionHost struct { // Prompt lifecycle state. // promptMu guards promptInFlight (serialization gate only). - promptMu sync.Mutex - promptInFlight bool - promptSeq uint64 + promptMu sync.Mutex + promptInFlight bool + promptInFlightID uint64 + promptSeq uint64 // promptCancelMu guards promptCancel independently from promptMu so that // CancelPrompt() can read it without waiting for Prompt() to finish. promptCancelMu sync.Mutex diff --git a/packages/vm-agent/internal/acp/session_host_crash.go b/packages/vm-agent/internal/acp/session_host_crash.go index 89226d0d2d..f21a5bbea6 100644 --- a/packages/vm-agent/internal/acp/session_host_crash.go +++ b/packages/vm-agent/internal/acp/session_host_crash.go @@ -19,7 +19,9 @@ const crashRecoveredStopReason = "recovered" // cannot continue (rapid exit, max restarts, unrecoverable crash, prompt timeout). // The control plane maps this to terminal task failure; plain "error" stopReasons // are recoverable and map to awaiting_followup in conversation mode. -const fatalErrorStopReason = "fatal_error" +const FatalErrorStopReason = "fatal_error" + +const fatalErrorStopReason = FatalErrorStopReason var diagnosticRedactionPatterns = []*regexp.Regexp{ regexp.MustCompile(`(?i)(bearer\s+)[A-Za-z0-9._~+/=-]{16,}`), diff --git a/packages/vm-agent/internal/acp/session_host_prompt.go b/packages/vm-agent/internal/acp/session_host_prompt.go index f1e72ac672..f091284458 100644 --- a/packages/vm-agent/internal/acp/session_host_prompt.go +++ b/packages/vm-agent/internal/acp/session_host_prompt.go @@ -55,10 +55,10 @@ func (h *SessionHost) HandlePrompt(ctx context.Context, reqID json.RawMessage, p h.markPromptStarted(promptReq.sessionID, len(promptReq.blocks), viewerID) resp, err := h.promptWithTransientRetry(promptCtx, promptReq, promptStart) - if !h.isPromptActive(promptID) { + cancelRequested, claimed := h.claimPromptCompletion(promptID) + if !claimed { return } - cancelRequested := h.isPromptCancelRequested(promptID) h.markPromptDone() h.finishPrompt(promptCtx, reqID, promptStartInfo{ startedAt: promptStart, diff --git a/packages/vm-agent/internal/acp/session_host_prompt_state.go b/packages/vm-agent/internal/acp/session_host_prompt_state.go index b69febfa8d..9a7b62a1bd 100644 --- a/packages/vm-agent/internal/acp/session_host_prompt_state.go +++ b/packages/vm-agent/internal/acp/session_host_prompt_state.go @@ -37,6 +37,7 @@ func (h *SessionHost) beginPrompt(cancel context.CancelFunc) (uint64, bool) { } h.promptInFlight = true promptID := atomic.AddUint64(&h.promptSeq, 1) + h.promptInFlightID = promptID h.promptCancelMu.Lock() h.promptCancel = cancel @@ -48,7 +49,10 @@ func (h *SessionHost) beginPrompt(cancel context.CancelFunc) (uint64, bool) { func (h *SessionHost) endPrompt(promptID uint64) { h.promptMu.Lock() - h.promptInFlight = false + if h.promptInFlightID == promptID { + h.promptInFlight = false + h.promptInFlightID = 0 + } h.promptMu.Unlock() h.promptCancelMu.Lock() @@ -60,16 +64,20 @@ func (h *SessionHost) endPrompt(promptID uint64) { h.promptCancelMu.Unlock() } -func (h *SessionHost) isPromptActive(promptID uint64) bool { - h.promptCancelMu.Lock() - defer h.promptCancelMu.Unlock() - return h.activePromptID == promptID -} - -func (h *SessionHost) isPromptCancelRequested(promptID uint64) bool { +// claimPromptCompletion atomically assigns terminal ownership for a prompt. +// Both the normal Prompt return path and the force-stop watchdog must claim +// before publishing lifecycle state or invoking OnPromptComplete. +func (h *SessionHost) claimPromptCompletion(promptID uint64) (bool, bool) { h.promptCancelMu.Lock() defer h.promptCancelMu.Unlock() - return h.activePromptID == promptID && h.promptCancelRequested + if h.activePromptID != promptID { + return false, false + } + cancelRequested := h.promptCancelRequested + h.activePromptID = 0 + h.promptCancel = nil + h.promptCancelRequested = false + return cancelRequested, true } func (h *SessionHost) watchPromptTimeout( @@ -94,17 +102,15 @@ func (h *SessionHost) watchPromptTimeout( } func (h *SessionHost) triggerPromptForceStopIfStuck(promptID uint64, reason string) { - h.promptCancelMu.Lock() - if h.activePromptID != promptID { - h.promptCancelMu.Unlock() + if _, claimed := h.claimPromptCompletion(promptID); !claimed { return } - h.activePromptID = 0 - h.promptCancel = nil - h.promptCancelMu.Unlock() h.promptMu.Lock() - h.promptInFlight = false + if h.promptInFlightID == promptID || h.promptInFlightID == 0 { + h.promptInFlight = false + h.promptInFlightID = 0 + } h.promptMu.Unlock() h.mu.Lock() @@ -121,6 +127,10 @@ func (h *SessionHost) triggerPromptForceStopIfStuck(promptID uint64, reason stri }) h.broadcastControl(MsgSessionPromptDone, nil) h.broadcastAgentStatus(StatusError, agentType, reason) + // Clearing activePromptID above makes HandlePrompt return without reaching + // finishPrompt. This force-stop branch therefore owns the terminal callback; + // without it, task-driven sessions remain active after their runtime is gone. + h.notifyPromptComplete(fatalErrorStopReason, errors.New(reason)) // Report idle so the browser status bar clears the "prompting" spinner. // The error state is already broadcast via broadcastAgentStatus above. h.reportActivity("idle") diff --git a/packages/vm-agent/internal/acp/session_host_test.go b/packages/vm-agent/internal/acp/session_host_test.go index 953832fb12..255143dae6 100644 --- a/packages/vm-agent/internal/acp/session_host_test.go +++ b/packages/vm-agent/internal/acp/session_host_test.go @@ -1475,6 +1475,120 @@ func TestSessionHost_FinishPromptDeadlineExceededReportsFatalWithoutCrashRecover } } +func TestSessionHost_ForceStoppedPromptReportsFatalCompletionExactlyOnce(t *testing.T) { + t.Parallel() + + host := newTestSessionHost(t) + defer host.Stop() + + type completion struct { + stopReason string + err error + } + completed := make(chan completion, 2) + host.config.OnPromptComplete = func(stopReason string, err error) { + completed <- completion{stopReason: stopReason, err: err} + } + + const promptID = uint64(42) + const timeoutReason = "Prompt timed out after 6h0m0s" + host.promptCancelMu.Lock() + host.activePromptID = promptID + host.promptCancelMu.Unlock() + host.promptMu.Lock() + host.promptInFlight = true + host.promptInFlightID = promptID + host.promptMu.Unlock() + host.mu.Lock() + host.status = HostPrompting + host.agentType = "openai-codex" + host.mu.Unlock() + + host.triggerPromptForceStopIfStuck(promptID, timeoutReason) + + select { + case got := <-completed: + if got.stopReason != fatalErrorStopReason { + t.Fatalf("stopReason = %q, want %q", got.stopReason, fatalErrorStopReason) + } + if got.err == nil || got.err.Error() != timeoutReason { + t.Fatalf("completion error = %v, want %q", got.err, timeoutReason) + } + case <-time.After(2 * time.Second): + t.Fatal("timed out waiting for force-stop completion callback") + } + + // A late watchdog/retry for the same prompt must not terminalize twice. + host.triggerPromptForceStopIfStuck(promptID, timeoutReason) + select { + case got := <-completed: + t.Fatalf("received duplicate force-stop completion: %+v", got) + case <-time.After(50 * time.Millisecond): + } +} + +func TestSessionHost_CompetingPromptCompletionPathsClaimExactlyOnce(t *testing.T) { + t.Parallel() + + host := newTestSessionHost(t) + defer host.Stop() + + type completion struct { + stopReason string + err error + } + completed := make(chan completion, 2) + host.config.OnPromptComplete = func(stopReason string, err error) { + completed <- completion{stopReason: stopReason, err: err} + } + + const promptID = uint64(43) + const timeoutReason = "Prompt timed out after 6h0m0s" + host.promptCancelMu.Lock() + host.activePromptID = promptID + host.promptCancelMu.Unlock() + host.promptMu.Lock() + host.promptInFlight = true + host.promptInFlightID = promptID + host.promptMu.Unlock() + host.mu.Lock() + host.status = HostPrompting + host.agentType = "openai-codex" + host.mu.Unlock() + + start := make(chan struct{}) + var contenders sync.WaitGroup + contenders.Add(2) + go func() { + defer contenders.Done() + <-start + if _, claimed := host.claimPromptCompletion(promptID); claimed { + host.notifyPromptComplete("normal_return", nil) + } + }() + go func() { + defer contenders.Done() + <-start + host.triggerPromptForceStopIfStuck(promptID, timeoutReason) + }() + close(start) + contenders.Wait() + + select { + case got := <-completed: + if got.stopReason != "normal_return" && got.stopReason != fatalErrorStopReason { + t.Fatalf("unexpected completion owner: %+v", got) + } + case <-time.After(2 * time.Second): + t.Fatal("timed out waiting for completion owner") + } + select { + case got := <-completed: + t.Fatalf("received duplicate competing completion: %+v", got) + case <-time.After(50 * time.Millisecond): + } +} + func TestSessionHost_BroadcastAgentCrashReport(t *testing.T) { t.Parallel() diff --git a/packages/vm-agent/internal/server/server.go b/packages/vm-agent/internal/server/server.go index b6c8bfe65b..75c86e867c 100644 --- a/packages/vm-agent/internal/server/server.go +++ b/packages/vm-agent/internal/server/server.go @@ -57,7 +57,7 @@ type taskCallbackContext struct { TaskMode string } -const fatalErrorStopReason = "fatal_error" +const fatalErrorStopReason = acp.FatalErrorStopReason var taskCallbackDiagnosticRedactionPatterns = []*regexp.Regexp{ regexp.MustCompile(`(?i)(bearer\s+)[A-Za-z0-9._~+/=-]{16,}`), diff --git a/packages/vm-agent/internal/server/task_callback_scoping_test.go b/packages/vm-agent/internal/server/task_callback_scoping_test.go index 8ed844bdda..b5e7c25031 100644 --- a/packages/vm-agent/internal/server/task_callback_scoping_test.go +++ b/packages/vm-agent/internal/server/task_callback_scoping_test.go @@ -8,7 +8,10 @@ import ( "net/http/httptest" "strings" "testing" + "time" + "github.com/workspace/vm-agent/internal/acp" + "github.com/workspace/vm-agent/internal/agentsessions" "github.com/workspace/vm-agent/internal/config" ) @@ -142,6 +145,70 @@ func TestTaskCompletionCallbackTreatsFatalErrorStopReasonAsTerminalFailure(t *te } } +func TestTaskSessionHostBindsFatalCompletionToControlPlaneCallback(t *testing.T) { + t.Parallel() + + type callbackRequest struct { + Path string + Body map[string]interface{} + } + received := make(chan callbackRequest, 1) + controlPlane := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + var body map[string]interface{} + if err := json.NewDecoder(r.Body).Decode(&body); err != nil { + t.Errorf("decode callback body: %v", err) + } + received <- callbackRequest{Path: r.URL.Path, Body: body} + w.WriteHeader(http.StatusOK) + })) + t.Cleanup(controlPlane.Close) + + const hostKey = "workspace-a/session-a" + s := &Server{ + config: &config.Config{ + ControlPlaneURL: controlPlane.URL, + HTTPCallbackTimeout: 0, + CallbackToken: "node-token", + }, + sessionHosts: make(map[string]*acp.SessionHost), + sessionTaskCtx: map[string]taskCallbackContext{hostKey: {ProjectID: "project-1", TaskID: "task-a", WorkspaceID: "workspace-a", TaskMode: config.TaskModeConversation}}, + sessionMcpServers: make(map[string][]acp.McpServerEntry), + sessionProfileOvr: make(map[string]profileOverrides), + agentSessions: agentsessions.NewManager(), + workspaces: make(map[string]*WorkspaceRuntime), + } + host := s.getOrCreateSessionHost( + hostKey, + "workspace-a", + "session-a", + agentsessions.Session{ID: "session-a", WorkspaceID: "workspace-a"}, + nil, + "", + ) + t.Cleanup(host.Stop) + + callback := host.OnPromptCompleteCallback() + if callback == nil { + t.Fatal("task-owned SessionHost has no completion callback") + } + callback(acp.FatalErrorStopReason, errors.New("Prompt timed out after 6h0m0s")) + + select { + case got := <-received: + if !strings.Contains(got.Path, "/tasks/task-a/status/callback") { + t.Fatalf("callback path = %q, want task-a status callback", got.Path) + } + if got.Body["toStatus"] != "failed" { + t.Fatalf("toStatus = %v, want failed", got.Body["toStatus"]) + } + if got.Body["errorMessage"] != "Prompt timed out after 6h0m0s" { + t.Fatalf("errorMessage = %v, want exact timeout reason", got.Body["errorMessage"]) + } + case <-time.After(2 * time.Second): + t.Fatal("timed out waiting for bound SessionHost callback") + } +} + func TestTaskCompletionCallbackTreatsTaskModeErrorStopReasonAsTerminalFailure(t *testing.T) { t.Parallel() diff --git a/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md b/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md index 48c6bd55dc..2255c51f90 100644 --- a/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md +++ b/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md @@ -1,8 +1,8 @@ # Correlate VM Incidents with Task Lifecycle -**Status:** Active -**SAM task:** `01KZJYFB33CYE956414QT4P94S` -**SAM idea:** `01KZK6NG4MTWNSVJAZB2B0YENY` +**Status:** Active +**SAM task:** `01KZJYFB33CYE956414QT4P94S` +**SAM idea:** `01KZK6NG4MTWNSVJAZB2B0YENY` **Branch:** `sam/came-across-screenshot-tell-t4p94s` ## Problem @@ -27,7 +27,7 @@ As a result, the already-captured incident and artifact are not reliably reachab - `docs-sync-change`: task post-mortem and cross-boundary prevention rule. - `ui-change`: failure-card classification styling/labels change through the shared classifier. -No external API, new environment variable, migration, credential, billing, or deployment configuration change is planned. +No external API, migration, credential, billing, or deployment configuration change is planned. One advanced environment override bounds task-status compare-and-set attempts after a parent hard stop. ### Data-flow trace @@ -50,14 +50,15 @@ No external API, new environment variable, migration, credential, billing, or de ### Impact and risk analysis - Fatal prompt timeouts will now terminalize task state instead of silently stranding it. -- VM incident ingestion will perform one bounded main-D1 correlation lookup per batch (maximum batch size remains configured and bounded). +- VM incident ingestion will perform a bounded set of main-D1 correlation lookups per batch, chunked at the shared D1 100-bind protocol ceiling (the configured ingestion batch limit remains authoritative). - Correlation must fail open for observability delivery and fail closed for identity attachment: an absent, stale, mismatched, or ambiguous binding leaves task/session null. +- Missing or malformed producer timestamps must use receipt time only for evidence persistence and must never participate in task-lifetime correlation; every rejected attachment emits a bounded structured reason and action. - Stable incident retry semantics must allow null correlation fields to be enriched without allowing a non-null ID to be rebound. - Parent-stop control must stop the runtime before accepting the cancelled terminal state and must run standard terminal cleanup/synchronization. ### Constitution alignment -- No new URL, timeout, limit, or identifier is hardcoded. +- No new URL, timeout, arbitrary limit, or identifier is hardcoded. D1 chunking derives from the shared protocol ceiling, and parent-stop CAS attempts use a bounded operator override. - Existing configurable prompt timeout and VM error batch limits remain authoritative. - Canonical IDs are validated through node/workspace/session relationships; display names are never used for correlation. @@ -65,29 +66,30 @@ No external API, new environment variable, migration, credential, billing, or de - Keep this task record as the bug post-mortem and evidence trace. - Add a cross-boundary rule covering fatal-runtime completion callbacks, correlation joins, and intentional termination state consistency. -- No public documentation currently describes these internal debugging mechanics; verify with a repository search before completion. +- Update the public agents-managing-agents article so `stop_subtask` documents the canonical cancelled result. +- Document the advanced parent-stop CAS attempt override in the environment example and configuration reference. ## Implementation Plan -- [ ] Make watchdog force-stop notify task completion exactly once with the fatal timeout reason. -- [ ] Correlate VM reports to task/session only when the callback node owns the workspace and task/workspace session bindings agree for the incident timestamp. -- [ ] Make strict stable-incident persistence permit monotonic null → correlated enrichment while rejecting conflicting non-null rebinding. -- [ ] Record MCP parent stops as `cancelled`, including completed timestamp, status event, trigger synchronization, and terminal cleanup. -- [ ] Classify `stopped_by_parent` and expected human-input expiry as non-bug lifecycle outcomes with neutral failure-card presentation. -- [ ] Add the preventive cross-boundary quality rule. +- [x] Make watchdog force-stop notify task completion exactly once with the fatal timeout reason. +- [x] Correlate VM reports to task/session only when the callback node owns the workspace and task/workspace session bindings agree for the incident timestamp. +- [x] Make strict stable-incident persistence permit monotonic null → correlated enrichment while rejecting conflicting non-null rebinding. +- [x] Record MCP parent stops as `cancelled`, including completed timestamp, status event, trigger synchronization, and terminal cleanup. +- [x] Classify `stopped_by_parent` and expected human-input expiry as non-bug lifecycle outcomes with neutral failure-card presentation. +- [x] Add the preventive cross-boundary quality rule. - [ ] Run focused tests, impacted package gates, full repository gates, and all applicable specialist reviews. - [ ] Open a PR, get required CI green, and leave it unmerged. - [x] Skip staging deployment and verification at the user's explicit request; the sweep owns that phase. ## Acceptance Criteria -- [ ] A forced task prompt timeout invokes the fatal completion callback with the timeout reason and does not leave the task active. -- [ ] The VM incident/error ingestion vertical slice persists matching task/session IDs for an authoritative node → workspace → session → task binding. -- [ ] Mismatched node/workspace bindings, task/workspace session mismatches, post-dated tasks, and ambiguous candidates remain uncorrelated. -- [ ] A stable incident retry may enrich missing task/session IDs but can never replace a conflicting non-null ID. -- [ ] Parent `stop_subtask` invokes the runtime stop before writing `cancelled`, records a cancelled event, synchronizes trigger state, and performs terminal cleanup. -- [ ] Legacy `stopped_by_parent` messages and human-input expiry classify as lifecycle outcomes instead of unknown failures. -- [ ] Failure-card unit and Playwright visual tests prove lifecycle outcomes are neutral and usable at mobile and desktop sizes. +- [x] A forced task prompt timeout invokes the fatal completion callback with the timeout reason and does not leave the task active. +- [x] The VM incident/error ingestion vertical slice persists matching task/session IDs for an authoritative node → workspace → session → task binding. +- [x] Mismatched node/workspace bindings, task/workspace session mismatches, post-dated tasks, and ambiguous candidates remain uncorrelated. +- [x] A stable incident retry may enrich missing task/session IDs but can never replace a conflicting non-null ID. +- [x] Parent `stop_subtask` invokes the runtime stop before writing `cancelled`, records a cancelled event, synchronizes trigger state, and performs terminal cleanup. +- [x] Legacy `stopped_by_parent` messages and human-input expiry classify as lifecycle outcomes instead of unknown failures. +- [x] Failure-card unit and Playwright visual tests prove lifecycle outcomes are neutral and usable at mobile and desktop sizes. - [ ] Focused and full validation pass; the PR's required GitHub checks are green. - [ ] PR remains open and unmerged; no staging workflow is dispatched. @@ -132,5 +134,13 @@ Extend `.claude/rules/23-cross-boundary-contract-tests.md` to require: ## Verification Record -Pending implementation. - +- Shared failure-classification tests: 23 passed. +- API focused correlation, strict persistence, observability ingestion, parent-stop, and task-callback suites: 79 passed. +- Web focused failure-card and lifecycle presentation suites: 95 passed. +- VM-agent ACP tests, including exact-once fatal completion: passed. +- Playwright lifecycle audit at 375×667 and 1280×800: passed with no horizontal overflow; both screenshots were inspected. +- Full repository build and typecheck passed. The first full test attempt passed 6,787 of 6,788 API tests; one unrelated orchestration-test setup hook exceeded its 10-second timeout under suite load, then the complete 31-test file passed in 2.88 seconds in isolation. The full retry cleared that failure and passed all 6,788 API tests, but one unrelated command-palette assertion failed after 2,938 web tests passed; its complete 23-test file then passed in 3.42 seconds in isolation. Required PR checks are the final full-suite green gate. +- Repository lint, changed-file formatting, quality checks, `git diff --check`, and VM-agent `go vet ./...`: passed. Existing lint warnings and repository-wide formatting drift remain unchanged. +- Full VM-agent `go test ./...` is blocked locally only in three Docker-dependent PTY/server tests because this workspace has no Docker binary; all other packages, including the changed `internal/acp` package and server callback tests, passed. +- Go, Cloudflare, test, security, constitution, environment, documentation-sync, and UI/UX specialist reviews passed after their findings were addressed. +- Staging was not deployed or verified, per the user's explicit request. From 916ad069f45b98e64e089743b4d416fc93a21b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 9 Aug 2026 13:51:46 +0000 Subject: [PATCH 20/57] docs(tasks): link diagnostic correlation PR --- .../2026-08-09-correlate-vm-incidents-with-task-lifecycle.md | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md b/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md index 2255c51f90..9a5c5401fd 100644 --- a/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md +++ b/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md @@ -4,6 +4,7 @@ **SAM task:** `01KZJYFB33CYE956414QT4P94S` **SAM idea:** `01KZK6NG4MTWNSVJAZB2B0YENY` **Branch:** `sam/came-across-screenshot-tell-t4p94s` +**PR:** https://github.com/raphaeltm/simple-agent-manager/pull/1779 ## Problem From fe7bf05872feacc91d23e51c7ca97411344ea4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 9 Aug 2026 14:14:22 +0000 Subject: [PATCH 21/57] docs(tasks): record diagnostic correlation validation --- ...6-08-09-correlate-vm-incidents-with-task-lifecycle.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md b/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md index 9a5c5401fd..b89bcadd72 100644 --- a/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md +++ b/tasks/active/2026-08-09-correlate-vm-incidents-with-task-lifecycle.md @@ -78,8 +78,8 @@ No external API, migration, credential, billing, or deployment configuration cha - [x] Record MCP parent stops as `cancelled`, including completed timestamp, status event, trigger synchronization, and terminal cleanup. - [x] Classify `stopped_by_parent` and expected human-input expiry as non-bug lifecycle outcomes with neutral failure-card presentation. - [x] Add the preventive cross-boundary quality rule. -- [ ] Run focused tests, impacted package gates, full repository gates, and all applicable specialist reviews. -- [ ] Open a PR, get required CI green, and leave it unmerged. +- [x] Run focused tests, impacted package gates, full repository gates, and all applicable specialist reviews. +- [x] Open a PR, get required CI green, and leave it unmerged. - [x] Skip staging deployment and verification at the user's explicit request; the sweep owns that phase. ## Acceptance Criteria @@ -91,8 +91,8 @@ No external API, migration, credential, billing, or deployment configuration cha - [x] Parent `stop_subtask` invokes the runtime stop before writing `cancelled`, records a cancelled event, synchronizes trigger state, and performs terminal cleanup. - [x] Legacy `stopped_by_parent` messages and human-input expiry classify as lifecycle outcomes instead of unknown failures. - [x] Failure-card unit and Playwright visual tests prove lifecycle outcomes are neutral and usable at mobile and desktop sizes. -- [ ] Focused and full validation pass; the PR's required GitHub checks are green. -- [ ] PR remains open and unmerged; no staging workflow is dispatched. +- [x] Focused and full validation pass; the PR's required GitHub checks are green. +- [x] PR remains open and unmerged; no staging workflow is dispatched. ## Post-Mortem @@ -144,4 +144,5 @@ Extend `.claude/rules/23-cross-boundary-contract-tests.md` to require: - Repository lint, changed-file formatting, quality checks, `git diff --check`, and VM-agent `go vet ./...`: passed. Existing lint warnings and repository-wide formatting drift remain unchanged. - Full VM-agent `go test ./...` is blocked locally only in three Docker-dependent PTY/server tests because this workspace has no Docker binary; all other packages, including the changed `internal/acp` package and server callback tests, passed. - Go, Cloudflare, test, security, constitution, environment, documentation-sync, and UI/UX specialist reviews passed after their findings were addressed. +- PR #1779 passed the complete implementation rollup: tests, Playwright visual audits, VM-agent smoke/integration/E2E, Durable Objects, build, typecheck, lint, code quality, UI compliance, Pulumi tests, benchmarks, and SonarCloud. The PR preflight evidence block was corrected before the final synchronization event. - Staging was not deployed or verified, per the user's explicit request. From c80919d7f8d22a8c2fdccbe86a12d9cadcbe0ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 26 Jul 2026 06:48:37 +0000 Subject: [PATCH 22/57] task: add Claude guided verification-code fix --- ...6-07-26-claude-guided-verification-code.md | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tasks/backlog/2026-07-26-claude-guided-verification-code.md diff --git a/tasks/backlog/2026-07-26-claude-guided-verification-code.md b/tasks/backlog/2026-07-26-claude-guided-verification-code.md new file mode 100644 index 0000000000..39ee72f6af --- /dev/null +++ b/tasks/backlog/2026-07-26-claude-guided-verification-code.md @@ -0,0 +1,91 @@ +# Fix Claude guided verification-code forwarding + +## Problem + +Claude Code guided login currently launches `claude setup-token` with ignored +stdin. In a sandbox the browser cannot reach the CLI callback, so Claude shows +the user a short-lived verification code that must be typed into the still +running CLI. The shipped process cannot receive it and hangs until TTL. + +An unmerged follow-up (`73289daa9`) implemented the wrong contract: it asks the +browser to provide the final `sk-ant-oat` token and saves that token directly. +The browser never receives that token; the CLI produces it only after exchanging +the short-lived code. + +## Research findings + +- Reviewed SAM idea `01KYEHTF6BA3ZPTN2RBRYBH462`, including the verified + container flow, root cause, source references, and reviewed file-level plan. +- The driver is `apps/api/scripts/claude-setup-token.mjs`; main currently uses + `stdio: ['ignore', 'pipe', 'pipe']`. +- The state machine and sandbox boundary live in + `apps/api/src/durable-objects/credential-setup-session/index.ts`. +- Route/service plumbing lives in + `apps/api/src/routes/agent-credential-setup-sessions.ts` and + `apps/api/src/services/credential-setup-session.ts`. +- Browser state and behavior live in + `apps/web/src/components/CodexConnectModal.tsx` and + `apps/web/src/lib/api/codex-setup.ts`. +- Open PR #1667 changes only Codex helper copy in + `CodexConnectTrigger.tsx`; this PR will document whether it supersedes or + remains independent. +- Relevant project rules require preflight evidence, fail-fast state handling, + a realistic vertical-slice test, mobile/desktop Playwright visual evidence, + specialist review, staging verification, and no tests that preserve a known + degraded contract. + +## Implementation checklist + +- [ ] Reuse the prior branch's route/service/UI plumbing but replace final-token + submission with short-lived verification-code submission. +- [ ] Pipe driver stdin, constrain the code-file path to setup home, poll it, + delete it, and write the normalized code plus carriage return to the PTY. +- [ ] Harden URL/token parsing against PTY wrapping and publish sanitized + failures when the CLI exits without a token. +- [ ] Add the `exchanging` state and DO `submitVerificationCode` guards, + normalization, bounds, charset (including `#`), sandbox write, and + non-persistence guarantees. +- [ ] Read driver state during waiting/exchanging/capturing so rejection or exit + fails fast instead of waiting for TTL. +- [ ] Expose owned-session `POST /:id/verification-code` without treating the + short-lived code as a credential. +- [ ] Preserve strict server-side Claude OAuth-token validation and the existing + capture → encrypted save → teardown path. +- [ ] Update the modal with accurate code-paste copy, exchanging progress, + visible failure, and restart affordance. +- [ ] Add driver, DO, route/DO/sandbox vertical-slice, UI behavioral, and + discriminating regression coverage. +- [ ] Run Playwright visual audits at 375px and 1280px. +- [ ] Run full validation and all required specialist reviews. +- [ ] Deploy the branch to staging and verify provisioning, URL surfacing, + sandbox delivery, rejected-code fast failure, and complete cleanup. +- [ ] Open a PR, make every CI check green, and leave it unmerged for Raphaël's + real Claude subscription E2E. + +## Acceptance criteria + +- [ ] The browser submits only a bounded short-lived verification code; the + long-lived token never crosses the browser boundary. +- [ ] A `code#state` value with copied whitespace artifacts reaches the CLI as + exact normalized bytes followed by `\r`. +- [ ] Invalid codes and premature CLI exits become prompt, sanitized failures. +- [ ] Wrapped terminal output cannot cause a truncated OAuth token to be saved. +- [ ] Automated coverage proves the full route → DO → sandbox → captured token + → credential save path with realistic state and exact sandbox writes. +- [ ] Mobile and desktop UI are accessible, legible, and free of horizontal + overflow. +- [ ] Staging has no orphan guided-login sandbox or pool lease after success or + failure cleanup. +- [ ] PR is open, all checks including SonarCloud and Preflight Evidence pass, + staging remains deployed from the feature branch, and the PR is not + merged. + +## References + +- SAM idea `01KYEHTF6BA3ZPTN2RBRYBH462` +- PR #1671 / main commit `44adc7e5e` +- Wrong-fix commit `73289daa9` +- Open PR #1667 +- +- anthropics/claude-code issues #47773 and #47699 + From 64b77665d40f1cf6ccdb494bdb81245ae4f68d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 26 Jul 2026 06:48:59 +0000 Subject: [PATCH 23/57] task: start Claude verification-code fix --- .../2026-07-26-claude-guided-verification-code.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tasks/{backlog => active}/2026-07-26-claude-guided-verification-code.md (100%) diff --git a/tasks/backlog/2026-07-26-claude-guided-verification-code.md b/tasks/active/2026-07-26-claude-guided-verification-code.md similarity index 100% rename from tasks/backlog/2026-07-26-claude-guided-verification-code.md rename to tasks/active/2026-07-26-claude-guided-verification-code.md From 83e675f360a986e13afc67ef9c482d136e0c48e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 25 Jul 2026 10:46:10 +0000 Subject: [PATCH 24/57] fix: complete Claude guided token setup --- .../credential-setup-session/index.ts | 114 ++++++++++++++++- .../routes/agent-credential-setup-sessions.ts | 62 +++++++++- .../src/services/credential-setup-session.ts | 8 ++ apps/api/src/services/validation.ts | 17 ++- .../credential-setup-session.test.ts | 90 ++++++++++++++ ...t-credential-setup-native-vertical.test.ts | 117 ++++++++++++++++++ .../tests/unit/services/validation.test.ts | 62 ++++++++-- ...t-credential-setup-sessions-routes.test.ts | 1 + apps/web/src/components/CodexConnectModal.tsx | 115 ++++++++++++++++- apps/web/src/lib/api/codex-setup.ts | 11 ++ apps/web/src/lib/api/index.ts | 1 + .../agent-guided-connect-audit.spec.ts | 31 ++++- .../components/CodexConnectModal.test.tsx | 50 ++++++++ 13 files changed, 658 insertions(+), 21 deletions(-) diff --git a/apps/api/src/durable-objects/credential-setup-session/index.ts b/apps/api/src/durable-objects/credential-setup-session/index.ts index c50d89ce02..74bda520b0 100644 --- a/apps/api/src/durable-objects/credential-setup-session/index.ts +++ b/apps/api/src/durable-objects/credential-setup-session/index.ts @@ -256,6 +256,97 @@ export class CredentialSetupSession extends DurableObject { }; } + /** + * Complete a Claude Code guided setup from the token the Claude browser flow + * gives back to the user. This deliberately bypasses terminal/stdin replay: + * the submitted secret is validated, saved through the same encrypted writer + * as sandbox capture, and never stored in DO SQLite or D1. + */ + async submitCredential(credential: string): Promise { + const row = this.readRow(); + if (!row) { + throw new Error('Setup session not found'); + } + if (row.agent_type !== 'claude-code') { + throw new Error('Manual credential submission is only supported for Claude Code setup'); + } + + const currentState = this.getState(); + if ( + row.status === 'completed' || + row.status === 'saving' || + isTerminalSetupStatus(row.status) + ) { + return ( + currentState ?? { + id: row.id, + status: row.status as SetupSessionStatus, + expiresAt: row.expires_at, + errorCode: row.error_code, + errorMessage: row.error_message, + verificationUrl: null, + userCode: null, + } + ); + } + + const trimmedCredential = credential.trim(); + const validation = CredentialValidator.validateCredential( + trimmedCredential, + row.credential_kind as CredentialKind, + row.agent_type as AgentType + ); + if (!validation.valid) { + throw new Error(validation.error ?? 'Invalid credential format'); + } + + this.setStatus(row.id, 'saving'); + await this.updateD1Status(row.id, 'saving'); + const savingRow = this.readRow(); + if (!savingRow || savingRow.status !== 'saving') { + const latestState = this.getState(); + if (latestState) return latestState; + throw new Error('Setup session state changed before credential save'); + } + + try { + await saveAgentCredentialForUser({ + env: this.env, + userId: savingRow.user_id, + projectId: savingRow.project_id, + agentType: savingRow.agent_type as AgentType, + credentialKind: savingRow.credential_kind as CredentialKind, + credential: trimmedCredential, + provider: savingRow.provider, + agentName: savingRow.agent_name, + autoActivate: true, + }); + } catch (err) { + log.error('credential_setup.manual_save_failed', { + sessionId: savingRow.id, + error: err instanceof Error ? err.message : String(err), + }); + await this.teardown( + savingRow, + 'failed', + 'manual_save_failed', + 'Failed to save the submitted credential' + ); + return ( + this.getState() ?? + this.terminalState( + savingRow, + 'failed', + 'manual_save_failed', + 'Failed to save the submitted credential' + ) + ); + } + + await this.teardown(savingRow, 'completed'); + return this.getState() ?? this.terminalState(savingRow, 'completed'); + } + /** * Alarm loop: provisions on the first tick, then polls for the captured * auth.json, and enforces the TTL. Every branch either reschedules the alarm @@ -288,7 +379,11 @@ export class CredentialSetupSession extends DurableObject { await this.pollDeviceAuth(row); return; } - // waiting_for_user | capturing | saving — poll for the credential file. + if (row.status === 'saving') { + await this.ctx.storage.setAlarm(Date.now() + row.capture_poll_ms); + return; + } + // waiting_for_user | capturing — poll for the credential file. await this.attemptCapture(row); } catch (err) { // Unexpected transient error — log and reschedule; the TTL guard bounds @@ -578,6 +673,23 @@ export class CredentialSetupSession extends DurableObject { // Helpers // --------------------------------------------------------------------------- + private terminalState( + row: SetupSessionRow, + status: SetupSessionStatus, + errorCode: string | null = null, + errorMessage: string | null = null + ): SetupSessionStateResult { + return { + id: row.id, + status, + expiresAt: row.expires_at, + errorCode, + errorMessage, + verificationUrl: null, + userCode: null, + }; + } + private readRow(): SetupSessionRow | undefined { return this.sql.exec('SELECT * FROM setup_session LIMIT 1').toArray()[0]; } diff --git a/apps/api/src/routes/agent-credential-setup-sessions.ts b/apps/api/src/routes/agent-credential-setup-sessions.ts index 5f571063a3..d3d94049c7 100644 --- a/apps/api/src/routes/agent-credential-setup-sessions.ts +++ b/apps/api/src/routes/agent-credential-setup-sessions.ts @@ -2,7 +2,7 @@ * Guided agent-credential setup sessions (native provider login). * * User-facing flow for connecting subscription/OAuth-backed coding agents - * without manual token/auth-file paste: + * without exposing terminal setup mechanics: * POST / create a setup session (leases a sandbox slot) * GET /:id poll lifecycle status * POST /:id/cancel cancel + tear down @@ -15,23 +15,28 @@ */ import { type AgentType, getAgentDefinition, isValidAgentType } from '@simple-agent-manager/shared'; import { Hono } from 'hono'; +import * as v from 'valibot'; import type { Env } from '../env'; import { log } from '../lib/logger'; import { ulid } from '../lib/ulid'; import { getUserId, requireApproved, requireAuth } from '../middleware/auth'; import { errors } from '../middleware/error'; +import { jsonValidator } from '../schemas'; import { ACTIVE_SETUP_STATUSES, getSetupSessionCapturePollMs, getSetupSessionTtlMs, + isTerminalSetupStatus, } from '../services/credential-setup-config'; import { cancelSetupSession, getSetupSessionState, startSetupSession, + submitSetupSessionCredential, } from '../services/credential-setup-session'; import { leaseSetupSlot, releaseSetupSlot } from '../services/setup-session-pool'; +import { CredentialValidator } from '../services/validation'; const agentCredentialSetupSessionsRoutes = new Hono<{ Bindings: Env }>(); @@ -40,6 +45,16 @@ const SUPPORTED_SETUP_AGENT_TYPES = ['openai-codex', 'claude-code'] as const; type SupportedSetupAgentType = (typeof SUPPORTED_SETUP_AGENT_TYPES)[number]; const SETUP_CREDENTIAL_KIND = 'oauth-token'; const ACTIVE_STATUS_PLACEHOLDERS = ACTIVE_SETUP_STATUSES.map(() => '?').join(', '); +const MAX_SUBMITTED_CLAUDE_TOKEN_LENGTH = 8192; + +const SubmitSetupCredentialSchema = v.object({ + credential: v.pipe( + v.string(), + v.trim(), + v.minLength(1), + v.maxLength(MAX_SUBMITTED_CLAUDE_TOKEN_LENGTH) + ), +}); function isSupportedSetupAgentType(agentType: AgentType): agentType is SupportedSetupAgentType { return SUPPORTED_SETUP_AGENT_TYPES.includes(agentType as SupportedSetupAgentType); @@ -265,6 +280,51 @@ agentCredentialSetupSessionsRoutes.get('/:id', requireAuth(), requireApproved(), }); }); +// ----------------------------------------------------------------------------- +// POST /:id/credential — complete Claude setup from browser-provided token +// ----------------------------------------------------------------------------- +agentCredentialSetupSessionsRoutes.post( + '/:id/credential', + requireAuth(), + requireApproved(), + jsonValidator(SubmitSetupCredentialSchema), + async (c) => { + const userId = getUserId(c); + const row = await loadOwnedSession(c.env, c.req.param('id'), userId); + if (row.agent_type !== 'claude-code') { + throw errors.badRequest( + 'Manual credential submission is only available for Claude Code setup' + ); + } + if (isTerminalSetupStatus(row.status)) { + throw errors.conflict('Setup session is no longer active'); + } + + const body = c.req.valid('json'); + const credential = body.credential.trim(); + const validation = CredentialValidator.validateCredential( + credential, + SETUP_CREDENTIAL_KIND, + 'claude-code' + ); + if (!validation.valid) { + throw errors.badRequest(validation.error ?? 'Invalid Claude OAuth token'); + } + + const state = await submitSetupSessionCredential(c.env, row.id, credential); + return c.json({ + id: row.id, + status: state.status, + agentType: row.agent_type, + expiresAt: row.expires_at, + verificationUrl: state.verificationUrl, + userCode: state.userCode, + errorCode: state.errorCode, + errorMessage: state.errorMessage, + }); + } +); + // ----------------------------------------------------------------------------- // POST /:id/cancel — cancel + tear down // ----------------------------------------------------------------------------- diff --git a/apps/api/src/services/credential-setup-session.ts b/apps/api/src/services/credential-setup-session.ts index 57fc8cd0d0..3856e1ec75 100644 --- a/apps/api/src/services/credential-setup-session.ts +++ b/apps/api/src/services/credential-setup-session.ts @@ -40,3 +40,11 @@ export async function cancelSetupSession( ): Promise { return getStub(env, sessionId).cancel(); } + +export async function submitSetupSessionCredential( + env: Env, + sessionId: string, + credential: string +): Promise { + return getStub(env, sessionId).submitCredential(credential); +} diff --git a/apps/api/src/services/validation.ts b/apps/api/src/services/validation.ts index 3d2dc1c85f..2064789757 100644 --- a/apps/api/src/services/validation.ts +++ b/apps/api/src/services/validation.ts @@ -11,6 +11,7 @@ import { fetchWithTimeout } from './fetch-timeout'; const ANTHROPIC_API_KEY_PREFIX = 'sk-ant-api'; const CLAUDE_OAUTH_TOKEN_PREFIX = 'sk-ant-oat'; +const MAX_CLAUDE_OAUTH_TOKEN_LENGTH = 8192; /** * Result from OpenAI Codex auth.json validation, including optional metadata @@ -300,7 +301,7 @@ export async function validateUpCloudCredentialWithProvider( export async function validateDigitalOceanCredentialWithProvider( token: string, - options?: CredentialValidationOptions, + options?: CredentialValidationOptions ): Promise { return runProviderCheck( { @@ -309,7 +310,7 @@ export async function validateDigitalOceanCredentialWithProvider( init: { headers: { Authorization: `Bearer ${token}` } }, }, 'DigitalOcean credential validated.', - options, + options ); } @@ -454,6 +455,18 @@ export class CredentialValidator { error: 'Claude OAuth token should start with "sk-ant-oat".', }; } + if (agentType === 'claude-code' && credential.length > MAX_CLAUDE_OAUTH_TOKEN_LENGTH) { + return { + valid: false, + error: 'Claude OAuth token is too long.', + }; + } + if (agentType === 'claude-code' && !/^[A-Za-z0-9._-]+$/.test(credential)) { + return { + valid: false, + error: 'Claude OAuth token contains invalid characters.', + }; + } } return { valid: true }; diff --git a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts index 0bfb75dfb9..a9bf296635 100644 --- a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts +++ b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts @@ -642,6 +642,96 @@ describe('CredentialSetupSession — alarm() capture polling', () => { expect((await created.instance.getState())?.status).toBe('completed'); }); + it('saves a browser-submitted Claude token, completes, and tears down', async () => { + const created = createDO(); + await Promise.resolve(); + const fakeSandbox = createFakeSandbox(); + fakeSandbox.readFile.mockImplementation(async (path: string) => ({ + content: path.endsWith('device-auth-state.json') + ? JSON.stringify({ + status: 'waiting_for_user', + verificationUrl: 'https://claude.ai/oauth/device', + }) + : '', + })); + vi.mocked(getSandboxInstance).mockResolvedValue(fakeSandbox as never); + + await created.instance.create({ + id: 'setup-claude-manual', + setupHome: '/tmp/claude-setup-manual', + ttlMs: 900_000, + ...BASE_PARAMS, + agentType: 'claude-code', + provider: 'anthropic', + agentName: 'Claude Code', + }); + await created.instance.alarm(); // provisioning -> admitting + await created.instance.alarm(); // device state -> waiting_for_user + + const token = `sk-ant-oat${'E'.repeat(48)}`; + vi.mocked(saveAgentCredentialForUser).mockResolvedValue({ + created: true, + createdAt: '2026-07-01T00:00:00.000Z', + updatedAt: '2026-07-01T00:00:00.000Z', + }); + + const result = await created.instance.submitCredential(` ${token}\n`); + + expect(result.status).toBe('completed'); + expect(saveAgentCredentialForUser).toHaveBeenCalledWith( + expect.objectContaining({ + userId: BASE_PARAMS.userId, + projectId: null, + agentType: 'claude-code', + credentialKind: 'oauth-token', + credential: token, + provider: 'anthropic', + agentName: 'Claude Code', + autoActivate: true, + }) + ); + expect(JSON.stringify(created.database._calls)).not.toContain(token); + expect(releaseSetupSlot).toHaveBeenCalledWith(expect.anything(), 'lease-abc'); + expect(destroySandboxInstance).toHaveBeenCalledWith(expect.anything(), 'setup-claude-manual', { + sandboxId: 'setup-claude-manual', + }); + }); + + it('rejects an invalid browser-submitted Claude token without failing the active session', async () => { + const created = createDO(); + await Promise.resolve(); + const fakeSandbox = createFakeSandbox(); + fakeSandbox.readFile.mockImplementation(async (path: string) => ({ + content: path.endsWith('device-auth-state.json') + ? JSON.stringify({ + status: 'waiting_for_user', + verificationUrl: 'https://claude.ai/oauth/device', + }) + : '', + })); + vi.mocked(getSandboxInstance).mockResolvedValue(fakeSandbox as never); + + await created.instance.create({ + id: 'setup-claude-invalid-manual', + setupHome: '/tmp/claude-setup-invalid-manual', + ttlMs: 900_000, + ...BASE_PARAMS, + agentType: 'claude-code', + provider: 'anthropic', + agentName: 'Claude Code', + }); + await created.instance.alarm(); + await created.instance.alarm(); + + await expect(created.instance.submitCredential('sk-ant-api-not-oauth')).rejects.toThrow( + /API key/ + ); + + expect((await created.instance.getState())?.status).toBe('waiting_for_user'); + expect(saveAgentCredentialForUser).not.toHaveBeenCalled(); + expect(releaseSetupSlot).not.toHaveBeenCalled(); + }); + it('tears down as failed when saveAgentCredentialForUser rejects', async () => { const { instance, database, fakeSandbox } = await createAndProvision(); const authJson = validAuthJson(); diff --git a/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts b/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts index a245420739..fdded95266 100644 --- a/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts +++ b/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts @@ -140,4 +140,121 @@ describe('native Codex setup route vertical slice', () => { expect(env.CREDENTIAL_SETUP_SESSION.idFromName).not.toHaveBeenCalled(); expect(getState).not.toHaveBeenCalled(); }); + + it('submits an owned Claude browser token through the DO boundary without persisting the secret in D1', async () => { + const sqlite = setupDatabase(); + const now = new Date().toISOString(); + sqlite + .prepare( + `INSERT INTO agent_credential_setup_sessions + (id, user_id, project_id, scope, agent_type, credential_kind, status, + sandbox_id, pool_lease_id, expires_at, created_at, updated_at) + VALUES (?, ?, NULL, 'user', 'claude-code', 'oauth-token', + 'waiting_for_user', ?, 'lease-claude', ?, ?, ?)` + ) + .run( + 'session-claude', + 'owner-user', + 'session-claude', + new Date(Date.now() + 60_000).toISOString(), + now, + now + ); + + const token = `sk-ant-oat${'D'.repeat(48)}`; + const submitCredential = vi.fn().mockResolvedValue({ + id: 'session-claude', + status: 'completed', + expiresAt: Date.now() + 60_000, + errorCode: null, + errorMessage: null, + verificationUrl: null, + userCode: null, + }); + const env = { + DATABASE: createSqliteD1(sqlite), + CREDENTIAL_SETUP_SESSION: { + idFromName: vi.fn(() => ({ toString: () => 'do-session-claude' })), + get: vi.fn(() => ({ submitCredential })), + }, + } as unknown as Env; + const app = new Hono<{ Bindings: Env }>(); + app.onError((error, c) => { + const status = 'statusCode' in error ? Number(error.statusCode) : 500; + return c.json({ error: error.message }, status as 400 | 404 | 409 | 500); + }); + app.route('/api/agent-credential-setup-sessions', agentCredentialSetupSessionsRoutes); + + const response = await app.request( + '/api/agent-credential-setup-sessions/session-claude/credential', + { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ credential: ` ${token}\n` }), + }, + env + ); + + expect(response.status).toBe(200); + expect(await response.json()).toMatchObject({ + id: 'session-claude', + status: 'completed', + agentType: 'claude-code', + }); + expect(submitCredential).toHaveBeenCalledWith(token); + const persisted = sqlite + .prepare('SELECT * FROM agent_credential_setup_sessions WHERE id = ?') + .get('session-claude') as Record; + expect(JSON.stringify(persisted)).not.toContain(token); + }); + + it('rejects an invalid Claude browser token before crossing the DO boundary', async () => { + const sqlite = setupDatabase(); + const now = new Date().toISOString(); + sqlite + .prepare( + `INSERT INTO agent_credential_setup_sessions + (id, user_id, project_id, scope, agent_type, credential_kind, status, + sandbox_id, pool_lease_id, expires_at, created_at, updated_at) + VALUES (?, ?, NULL, 'user', 'claude-code', 'oauth-token', + 'waiting_for_user', ?, 'lease-claude', ?, ?, ?)` + ) + .run( + 'session-bad-token', + 'owner-user', + 'session-bad-token', + new Date(Date.now() + 60_000).toISOString(), + now, + now + ); + + const submitCredential = vi.fn(); + const env = { + DATABASE: createSqliteD1(sqlite), + CREDENTIAL_SETUP_SESSION: { + idFromName: vi.fn(() => ({ toString: () => 'do-session-bad-token' })), + get: vi.fn(() => ({ submitCredential })), + }, + } as unknown as Env; + const app = new Hono<{ Bindings: Env }>(); + app.onError((error, c) => { + const status = 'statusCode' in error ? Number(error.statusCode) : 500; + return c.json({ error: error.message }, status as 400 | 404 | 409 | 500); + }); + app.route('/api/agent-credential-setup-sessions', agentCredentialSetupSessionsRoutes); + + const response = await app.request( + '/api/agent-credential-setup-sessions/session-bad-token/credential', + { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ credential: 'sk-ant-api-this-is-not-oauth' }), + }, + env + ); + + expect(response.status).toBe(400); + expect(env.CREDENTIAL_SETUP_SESSION.idFromName).not.toHaveBeenCalled(); + expect(submitCredential).not.toHaveBeenCalled(); + }); }); diff --git a/apps/api/tests/unit/services/validation.test.ts b/apps/api/tests/unit/services/validation.test.ts index 94574f164a..7f889dd400 100644 --- a/apps/api/tests/unit/services/validation.test.ts +++ b/apps/api/tests/unit/services/validation.test.ts @@ -1,6 +1,12 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; -import { CredentialValidator, validateAgentApiKeyCredentialWithProvider, validateHetznerCredentialWithProvider, validateOpenAICodexAuthJson, validateScalewayCredentialWithProvider } from '../../../src/services/validation'; +import { + CredentialValidator, + validateAgentApiKeyCredentialWithProvider, + validateHetznerCredentialWithProvider, + validateOpenAICodexAuthJson, + validateScalewayCredentialWithProvider, +} from '../../../src/services/validation'; describe('CredentialValidator', () => { describe('detectCredentialKind', () => { @@ -39,10 +45,7 @@ describe('CredentialValidator', () => { }); it('rejects obvious OAuth tokens in API key mode', () => { - const validation = CredentialValidator.validateCredential( - 'sk-ant-oat01-abcdef', - 'api-key' - ); + const validation = CredentialValidator.validateCredential('sk-ant-oat01-abcdef', 'api-key'); expect(validation.valid).toBe(false); expect(validation.error).toContain('OAuth token'); }); @@ -61,6 +64,26 @@ describe('CredentialValidator', () => { ); expect(validation.valid).toBe(true); }); + + it('rejects Claude OAuth tokens with invalid characters for Claude Code', () => { + const validation = CredentialValidator.validateCredential( + 'sk-ant-oat01-valid-prefix-but-bad-char! ', + 'oauth-token', + 'claude-code' + ); + expect(validation.valid).toBe(false); + expect(validation.error).toContain('invalid characters'); + }); + + it('rejects overlong Claude OAuth tokens for Claude Code', () => { + const validation = CredentialValidator.validateCredential( + `sk-ant-oat${'A'.repeat(8193)}`, + 'oauth-token', + 'claude-code' + ); + expect(validation.valid).toBe(false); + expect(validation.error).toContain('too long'); + }); }); describe('validateCredential for OpenAI Codex OAuth', () => { @@ -175,7 +198,11 @@ describe('CredentialValidator', () => { describe('getCredentialErrorMessage', () => { it('returns OpenAI-specific message for codex unauthorized', () => { - const msg = CredentialValidator.getCredentialErrorMessage('oauth-token', '401 unauthorized', 'openai-codex'); + const msg = CredentialValidator.getCredentialErrorMessage( + 'oauth-token', + '401 unauthorized', + 'openai-codex' + ); expect(msg).toContain('OpenAI'); expect(msg).toContain('codex login'); }); @@ -236,7 +263,7 @@ describe('validateOpenAICodexAuthJson', () => { expect(result.valid).toBe(true); expect(result.metadata?.isExpired).toBe(true); expect(result.warnings).toBeDefined(); - expect(result.warnings!.some(w => w.includes('expired'))).toBe(true); + expect(result.warnings!.some((w) => w.includes('expired'))).toBe(true); }); it('accepts auth.json with missing id_token (warns)', () => { @@ -251,7 +278,7 @@ describe('validateOpenAICodexAuthJson', () => { const result = validateOpenAICodexAuthJson(json); expect(result.valid).toBe(true); expect(result.warnings).toBeDefined(); - expect(result.warnings!.some(w => w.includes('id_token'))).toBe(true); + expect(result.warnings!.some((w) => w.includes('id_token'))).toBe(true); }); it('rejects non-JSON input', () => { @@ -277,7 +304,6 @@ describe('validateOpenAICodexAuthJson', () => { }); }); - describe('provider credential validation helpers', () => { afterEach(() => { vi.unstubAllGlobals(); @@ -286,7 +312,9 @@ describe('provider credential validation helpers', () => { it('validates Hetzner credentials against the servers endpoint', async () => { vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response('{}', { status: 200 }))); - const result = await validateHetznerCredentialWithProvider('hetzner-token', { timeoutMs: 1000 }); + const result = await validateHetznerCredentialWithProvider('hetzner-token', { + timeoutMs: 1000, + }); expect(result.valid).toBe(true); expect(globalThis.fetch).toHaveBeenCalledWith( @@ -313,7 +341,9 @@ describe('provider credential validation helpers', () => { it('validates Scaleway credentials against a project-scoped servers endpoint', async () => { vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response('{}', { status: 200 }))); - const result = await validateScalewayCredentialWithProvider('scw-secret', 'project-id', { timeoutMs: 1000 }); + const result = await validateScalewayCredentialWithProvider('scw-secret', 'project-id', { + timeoutMs: 1000, + }); expect(result.valid).toBe(true); expect(globalThis.fetch).toHaveBeenCalledWith( @@ -327,7 +357,11 @@ describe('provider credential validation helpers', () => { it('validates Anthropic agent API keys with x-api-key', async () => { vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response('{}', { status: 200 }))); - const result = await validateAgentApiKeyCredentialWithProvider('claude-code', 'sk-ant-api03-valid', { timeoutMs: 1000 }); + const result = await validateAgentApiKeyCredentialWithProvider( + 'claude-code', + 'sk-ant-api03-valid', + { timeoutMs: 1000 } + ); expect(result.valid).toBe(true); expect(globalThis.fetch).toHaveBeenCalledWith( @@ -344,7 +378,9 @@ describe('provider credential validation helpers', () => { it('validates OpenAI agent API keys with bearer auth', async () => { vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response('{}', { status: 200 }))); - const result = await validateAgentApiKeyCredentialWithProvider('openai-codex', 'openai-key', { timeoutMs: 1000 }); + const result = await validateAgentApiKeyCredentialWithProvider('openai-codex', 'openai-key', { + timeoutMs: 1000, + }); expect(result.valid).toBe(true); expect(globalThis.fetch).toHaveBeenCalledWith( diff --git a/apps/api/tests/workers/agent-credential-setup-sessions-routes.test.ts b/apps/api/tests/workers/agent-credential-setup-sessions-routes.test.ts index 6735314125..abd0ae0ca8 100644 --- a/apps/api/tests/workers/agent-credential-setup-sessions-routes.test.ts +++ b/apps/api/tests/workers/agent-credential-setup-sessions-routes.test.ts @@ -33,6 +33,7 @@ describe('agent-credential-setup-sessions REST routes reject unauthenticated req { method: 'GET', path: '/api/agent-credential-setup-sessions/config' }, { method: 'POST', path: '/api/agent-credential-setup-sessions' }, { method: 'GET', path: '/api/agent-credential-setup-sessions/fake-id' }, + { method: 'POST', path: '/api/agent-credential-setup-sessions/fake-id/credential' }, { method: 'POST', path: '/api/agent-credential-setup-sessions/fake-id/cancel' }, ]; diff --git a/apps/web/src/components/CodexConnectModal.tsx b/apps/web/src/components/CodexConnectModal.tsx index 47bd2a9bb2..3f450c992d 100644 --- a/apps/web/src/components/CodexConnectModal.tsx +++ b/apps/web/src/components/CodexConnectModal.tsx @@ -10,6 +10,7 @@ import { getAgentCredentialSetupSession, type GuidedSetupAgentType, isTerminalAgentCredentialSetupStatus, + submitAgentCredentialSetupCredential, } from '../lib/api'; interface AgentCredentialConnectModalProps { @@ -109,9 +110,14 @@ export function AgentCredentialConnectModal({ const [session, setSession] = useState(null); const [message, setMessage] = useState(null); const [copied, setCopied] = useState(false); + const [submittedCredential, setSubmittedCredential] = useState(''); + const [submitError, setSubmitError] = useState(null); + const [submittingCredential, setSubmittingCredential] = useState(false); const [retryNonce, setRetryNonce] = useState(0); const sessionIdRef = useRef(null); const finishedRef = useRef(false); + const credentialSubmitInFlightRef = useRef(false); + const manualCloseTimerRef = useRef | null>(null); const onConnectedRef = useRef(onConnected); const onCloseRef = useRef(onClose); @@ -130,6 +136,12 @@ export function AgentCredentialConnectModal({ setSession(null); setMessage(null); setCopied(false); + setSubmittedCredential(''); + setSubmitError(null); + setSubmittingCredential(false); + credentialSubmitInFlightRef.current = false; + if (manualCloseTimerRef.current) clearTimeout(manualCloseTimerRef.current); + manualCloseTimerRef.current = null; sessionIdRef.current = null; finishedRef.current = false; @@ -146,7 +158,13 @@ export function AgentCredentialConnectModal({ }; const poll = async () => { - if (!sessionIdRef.current || pollInFlight || finishedRef.current) return; + if ( + !sessionIdRef.current || + pollInFlight || + finishedRef.current || + credentialSubmitInFlightRef.current + ) + return; pollInFlight = true; try { const next = await getAgentCredentialSetupSession(sessionIdRef.current); @@ -188,6 +206,8 @@ export function AgentCredentialConnectModal({ cancelled = true; if (pollTimer) clearInterval(pollTimer); if (closeTimer) clearTimeout(closeTimer); + if (manualCloseTimerRef.current) clearTimeout(manualCloseTimerRef.current); + manualCloseTimerRef.current = null; sessionIdRef.current = null; }; }, [agentType, isOpen, retryNonce]); @@ -202,6 +222,50 @@ export function AgentCredentialConnectModal({ } }; + const handleSubmitCredential = async () => { + const id = sessionIdRef.current; + const credential = submittedCredential.trim(); + if (!id || !credential) { + setSubmitError('Paste the Claude token from the browser first.'); + return; + } + + credentialSubmitInFlightRef.current = true; + setSubmittingCredential(true); + setSubmitError(null); + setMessage(null); + setSession((current) => (current ? { ...current, status: 'saving' } : current)); + + try { + const next = await submitAgentCredentialSetupCredential(id, credential); + setSession(next); + setSubmittedCredential(''); + if (isTerminalAgentCredentialSetupStatus(next.status)) { + finishedRef.current = true; + if (next.status === 'completed') { + onConnectedRef.current?.(); + manualCloseTimerRef.current = setTimeout(() => { + onCloseRef.current(); + }, getSuccessCloseDelayMs()); + } + } + } catch (error) { + setSession((current) => + current && current.status === 'saving' + ? { ...current, status: 'waiting_for_user' } + : current + ); + setSubmitError( + error instanceof Error + ? error.message + : 'Failed to save the Claude token. Please try again.' + ); + } finally { + credentialSubmitInFlightRef.current = false; + setSubmittingCredential(false); + } + }; + const handleCancel = async () => { const id = sessionIdRef.current; finishedRef.current = true; @@ -216,6 +280,8 @@ export function AgentCredentialConnectModal({ phase === 'created' && status !== null && !isTerminalAgentCredentialSetupStatus(status); const ready = isActive && !!session?.verificationUrl; const hasCode = ready && !!session?.userCode; + const canSubmitClaudeCredential = ready && agentType === 'claude-code' && status !== 'saving'; + const credentialInputId = `${titleId}-credential`; const header = (
@@ -301,6 +367,53 @@ export function AgentCredentialConnectModal({
)} + {canSubmitClaudeCredential && ( +
{ + event.preventDefault(); + void handleSubmitCredential(); + }} + > +
+ + { + setSubmittedCredential(event.currentTarget.value); + setSubmitError(null); + }} + placeholder="sk-ant-oat…" + className="min-h-11 w-full rounded-md border border-border-default bg-bg-primary px-3 py-2 text-sm text-fg-primary outline-none focus:border-accent focus:ring-2 focus:ring-accent/20" + /> +

+ After Claude shows a token, paste it here. SAM saves it encrypted and never + displays it again. +

+
+ {submitError && {submitError}} + +
+ )}

{copy.manualReturnHint}

)} diff --git a/apps/web/src/lib/api/codex-setup.ts b/apps/web/src/lib/api/codex-setup.ts index a9d41c7d3e..8e938385e4 100644 --- a/apps/web/src/lib/api/codex-setup.ts +++ b/apps/web/src/lib/api/codex-setup.ts @@ -180,3 +180,14 @@ export async function cancelAgentCredentialSetupSession( } export const cancelCodexSetupSession = cancelAgentCredentialSetupSession; + +/** POST /:id/credential — complete Claude Code setup with the browser-returned token. */ +export async function submitAgentCredentialSetupCredential( + id: string, + credential: string +): Promise { + return request(`${BASE_PATH}/${encodeURIComponent(id)}/credential`, { + method: 'POST', + body: JSON.stringify({ credential }), + }); +} diff --git a/apps/web/src/lib/api/index.ts b/apps/web/src/lib/api/index.ts index be437c0634..cf667aa5b8 100644 --- a/apps/web/src/lib/api/index.ts +++ b/apps/web/src/lib/api/index.ts @@ -156,6 +156,7 @@ export { isTerminalAgentCredentialSetupStatus, isTerminalCodexSetupStatus, setupConfigSupportsAgent, + submitAgentCredentialSetupCredential, } from './codex-setup'; export type { CCAttachmentListItem, diff --git a/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts b/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts index 038c6f28c5..f444105b76 100644 --- a/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts +++ b/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts @@ -37,6 +37,7 @@ const MOCK_CLAUDE_AGENT = { const CLAUDE_VERIFICATION_URL = 'https://claude.ai/oauth/device?client_id=sam-playwright&challenge=' + 'x'.repeat(180); const CLAUDE_USER_CODE = 'CLDE-PLAYWRIGHT-2026-LONG-CODE'; +const CLAUDE_SUBMITTED_TOKEN = 'sk-ant-oat-playwright-token-from-browser'; const SETUP_SESSION = { id: 'setup-claude-guided-audit', status: 'waiting_for_user', @@ -47,6 +48,12 @@ const SETUP_SESSION = { errorCode: null, errorMessage: null, }; +const COMPLETED_SETUP_SESSION = { + ...SETUP_SESSION, + status: 'completed', + verificationUrl: null, + userCode: null, +}; function respond(route: Route, status: number, body: unknown) { return route.fulfill({ @@ -56,7 +63,11 @@ function respond(route: Route, status: number, body: unknown) { }); } -async function setupApiMocks(page: Page, seenSetupAgentTypes: string[]) { +async function setupApiMocks( + page: Page, + seenSetupAgentTypes: string[], + seenSubmittedCredentials: string[] +) { await page.route('**/api/**', async (route) => { const request = route.request(); const url = new URL(request.url()); @@ -103,6 +114,14 @@ async function setupApiMocks(page: Page, seenSetupAgentTypes: string[]) { if (path === `/api/agent-credential-setup-sessions/${SETUP_SESSION.id}`) { return respond(route, 200, SETUP_SESSION); } + if ( + path === `/api/agent-credential-setup-sessions/${SETUP_SESSION.id}/credential` && + method === 'POST' + ) { + const body = request.postDataJSON() as { credential?: string }; + seenSubmittedCredentials.push(body.credential ?? ''); + return respond(route, 200, COMPLETED_SETUP_SESSION); + } if (path === `/api/agent-credential-setup-sessions/${SETUP_SESSION.id}/cancel`) { return respond(route, 200, { id: SETUP_SESSION.id, status: 'cancelled' }); } @@ -166,7 +185,8 @@ test('Claude guided connect uses native URL/copy controls without terminal outpu page, }) => { const seenSetupAgentTypes: string[] = []; - await setupApiMocks(page, seenSetupAgentTypes); + const seenSubmittedCredentials: string[] = []; + await setupApiMocks(page, seenSetupAgentTypes, seenSubmittedCredentials); await navigateToAgentSettings(page); await page.getByRole('button', { name: 'OAuth Token (Pro/Max)' }).click(); @@ -182,6 +202,8 @@ test('Claude guided connect uses native URL/copy controls without terminal outpu await expect(open).toHaveAttribute('href', CLAUDE_VERIFICATION_URL); await expect(copy).toBeVisible(); await expect(page.locator('code')).toHaveText(CLAUDE_USER_CODE); + await expect(page.getByLabel('Paste the Claude token from your browser')).toBeVisible(); + await expect(page.getByRole('button', { name: 'Save Claude token' })).toBeDisabled(); await expect(page.getByTestId('codex-terminal')).toHaveCount(0); const modal = page.getByRole('dialog', { name: 'Connect with Claude Code' }); await expect(modal.locator('pre, textarea, [data-testid*="terminal"]')).toHaveCount(0); @@ -201,5 +223,8 @@ test('Claude guided connect uses native URL/copy controls without terminal outpu await screenshot(page, 'claude-guided-connect-modal'); await assertNoOverflow(page); - await page.getByRole('button', { name: 'Cancel' }).click(); + await page.getByLabel('Paste the Claude token from your browser').fill(CLAUDE_SUBMITTED_TOKEN); + await page.getByRole('button', { name: 'Save Claude token' }).click(); + expect(seenSubmittedCredentials).toEqual([CLAUDE_SUBMITTED_TOKEN]); + await expect(page.getByText('Claude Code connected')).toBeVisible(); }); diff --git a/apps/web/tests/unit/components/CodexConnectModal.test.tsx b/apps/web/tests/unit/components/CodexConnectModal.test.tsx index 9f780d60e9..0f2c8ed1ba 100644 --- a/apps/web/tests/unit/components/CodexConnectModal.test.tsx +++ b/apps/web/tests/unit/components/CodexConnectModal.test.tsx @@ -6,6 +6,7 @@ const h = vi.hoisted(() => ({ getAgentCredentialSetupSession: vi.fn(), cancelAgentCredentialSetupSession: vi.fn(), getAgentCredentialSetupConfig: vi.fn(), + submitAgentCredentialSetupCredential: vi.fn(), })); vi.mock('../../../src/lib/api', async (importOriginal) => ({ @@ -14,6 +15,7 @@ vi.mock('../../../src/lib/api', async (importOriginal) => ({ getAgentCredentialSetupSession: h.getAgentCredentialSetupSession, cancelAgentCredentialSetupSession: h.cancelAgentCredentialSetupSession, getAgentCredentialSetupConfig: h.getAgentCredentialSetupConfig, + submitAgentCredentialSetupCredential: h.submitAgentCredentialSetupCredential, })); import { @@ -30,6 +32,7 @@ const SESSION_ID = 'sess_setup_01'; const USER_CODE = 'ABCD-EFGH'; const OPENAI_VERIFICATION_URL = 'https://auth.openai.com/device'; const CLAUDE_VERIFICATION_URL = 'https://claude.ai/oauth/device'; +const CLAUDE_OAUTH_TOKEN = `sk-ant-oat${'C'.repeat(48)}`; function makeSession( status: AgentCredentialSetupStatus, @@ -53,6 +56,7 @@ describe('AgentCredentialConnectModal', () => { h.getAgentCredentialSetupSession.mockReset(); h.cancelAgentCredentialSetupSession.mockReset(); h.getAgentCredentialSetupConfig.mockReset(); + h.submitAgentCredentialSetupCredential.mockReset(); vi.stubEnv('VITE_CODEX_SETUP_POLL_MS', '20'); vi.stubEnv('VITE_CODEX_SETUP_SUCCESS_CLOSE_MS', '10'); h.cancelAgentCredentialSetupSession.mockResolvedValue({ id: SESSION_ID, status: 'cancelled' }); @@ -110,6 +114,52 @@ describe('AgentCredentialConnectModal', () => { expect(screen.queryByTestId('codex-terminal')).not.toBeInTheDocument(); }); + it('lets Claude users paste the browser token and complete setup', async () => { + const onConnected = vi.fn(); + h.createAgentCredentialSetupSession.mockResolvedValue({ + kind: 'created', + session: makeSession('provisioning', { agentType: 'claude-code' }), + }); + h.getAgentCredentialSetupSession.mockResolvedValue( + makeSession('waiting_for_user', { + agentType: 'claude-code', + verificationUrl: CLAUDE_VERIFICATION_URL, + userCode: null, + }) + ); + h.submitAgentCredentialSetupCredential.mockResolvedValue( + makeSession('completed', { agentType: 'claude-code' }) + ); + + render( + + ); + + await screen.findByRole('link', { name: /open claude sign-in/i }); + const tokenInput = screen.getByLabelText(/paste the claude token/i); + fireEvent.change(tokenInput, { + target: { + value: ` ${CLAUDE_OAUTH_TOKEN} +`, + }, + }); + fireEvent.click(screen.getByRole('button', { name: /save claude token/i })); + + await waitFor(() => + expect(h.submitAgentCredentialSetupCredential).toHaveBeenCalledWith( + SESSION_ID, + CLAUDE_OAUTH_TOKEN + ) + ); + await waitFor(() => expect(onConnected).toHaveBeenCalledOnce()); + expect(await screen.findByText(/Claude Code connected/)).toBeInTheDocument(); + }); + it('reports completion without exposing a terminal surface', async () => { const onConnected = vi.fn(); h.createAgentCredentialSetupSession.mockResolvedValue({ From 8af90627ce336681237343af9630c44731f4ad14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 26 Jul 2026 06:58:23 +0000 Subject: [PATCH 25/57] fix: forward Claude verification code to sandbox CLI --- apps/api/scripts/claude-setup-token.mjs | 59 +++++++-- .../credential-setup-session/index.ts | 124 ++++++------------ .../routes/agent-credential-setup-sessions.ts | 37 ++---- .../src/services/credential-setup-config.ts | 1 + .../src/services/credential-setup-session.ts | 6 +- .../credential-setup-session.test.ts | 101 ++++++++------ ...t-credential-setup-native-vertical.test.ts | 39 +++--- .../unit/scripts/claude-setup-token.test.ts | 20 ++- apps/web/src/components/CodexConnectModal.tsx | 76 +++++------ apps/web/src/lib/api/codex-setup.ts | 18 ++- apps/web/src/lib/api/index.ts | 2 +- .../agent-guided-connect-audit.spec.ts | 24 ++-- .../components/CodexConnectModal.test.tsx | 22 ++-- 13 files changed, 277 insertions(+), 252 deletions(-) diff --git a/apps/api/scripts/claude-setup-token.mjs b/apps/api/scripts/claude-setup-token.mjs index 642586e645..18863b9d30 100644 --- a/apps/api/scripts/claude-setup-token.mjs +++ b/apps/api/scripts/claude-setup-token.mjs @@ -1,10 +1,9 @@ #!/usr/bin/env node import { spawn } from 'node:child_process'; -import { rename, writeFile } from 'node:fs/promises'; +import { readFile, rename, unlink, writeFile } from 'node:fs/promises'; import { join, parse, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; -import { createInterface } from 'node:readline'; const MAX_VERIFICATION_URL_LENGTH = 4096; const MAX_USER_CODE_LENGTH = 128; @@ -13,10 +12,11 @@ const CLAUDE_OAUTH_TOKEN_PREFIX = 'sk-ant-oat'; const CLAUDE_CONFIG_DIR_ENV = 'CLAUDE_CONFIG_DIR'; const DEVICE_AUTH_STATE_FILE = 'device-auth-state.json'; const CLAUDE_OAUTH_TOKEN_FILE = 'claude-oauth-token.txt'; +const VERIFICATION_CODE_FILE = 'verification-code.txt'; const ANSI_ESCAPE_PATTERN = /\u001b\[[0-9;?]*[ -/]*[@-~]/g; const CONTROL_CHARACTER_PATTERN = /[\u0000-\u001f\u007f]/; const CLAUDE_SETUP_COMMAND = - 'env DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=xterm-256color claude setup-token'; + 'stty cols 512; env DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=xterm-256color claude setup-token'; const URL_PATTERN = /https:\/\/[^\s<>'"`]+/gi; const TOKEN_PATTERN = /\bsk-ant-oat[A-Za-z0-9._-]{16,}\b/g; const CODE_PATTERNS = [ @@ -76,6 +76,7 @@ export function validateClaudeOauthToken(value) { export function resolveClaudeSetupPaths({ statePath, credentialPath, + verificationCodePath, configDir = process.env[CLAUDE_CONFIG_DIR_ENV], }) { if (!configDir) { @@ -89,6 +90,7 @@ export function resolveClaudeSetupPaths({ const expectedStatePath = join(baseDir, DEVICE_AUTH_STATE_FILE); const expectedCredentialPath = join(baseDir, CLAUDE_OAUTH_TOKEN_FILE); + const expectedVerificationCodePath = join(baseDir, VERIFICATION_CODE_FILE); if (resolve(statePath) !== expectedStatePath) { throw new Error('Claude setup-token state path must be the expected setup state file'); @@ -97,10 +99,15 @@ export function resolveClaudeSetupPaths({ throw new Error('Claude setup-token credential path must be the expected OAuth token file'); } + if (resolve(verificationCodePath) !== expectedVerificationCodePath) { + throw new Error('Claude setup-token verification code path must be the expected setup file'); + } + return { statePath: expectedStatePath, temporaryStatePath: join(baseDir, `${DEVICE_AUTH_STATE_FILE}.tmp`), credentialPath: expectedCredentialPath, + verificationCodePath: expectedVerificationCodePath, temporaryCredentialPath: join(baseDir, `${CLAUDE_OAUTH_TOKEN_FILE}.tmp`), }; } @@ -153,12 +160,16 @@ export function extractClaudeSetupOutput(raw) { export async function runClaudeSetupToken({ statePath, credentialPath, + verificationCodePath, spawnProcess = spawn, onSpawn, writeState, writeCredential, + readVerificationCode = (path) => readFile(path, 'utf8'), + deleteVerificationCode = unlink, + verificationCodePollMs = 500, }) { - const setupPaths = resolveClaudeSetupPaths({ statePath, credentialPath }); + const setupPaths = resolveClaudeSetupPaths({ statePath, credentialPath, verificationCodePath }); const writeStateFile = writeState ?? (async (state) => { @@ -184,13 +195,15 @@ export async function runClaudeSetupToken({ NO_COLOR: '1', TERM: 'xterm-256color', }, - stdio: ['ignore', 'pipe', 'pipe'], + stdio: ['pipe', 'pipe', 'pipe'], }); onSpawn?.(claude); let publishedWaiting = false; let tokenCaptured = false; let terminalStatePublished = false; + let verificationCodePoll; + let outputBuffer = ''; let stateWriteQueue = Promise.resolve(); let settled = false; let resolveReady; @@ -216,6 +229,7 @@ export async function runClaudeSetupToken({ } function publishFailure(message) { + if (verificationCodePoll) clearInterval(verificationCodePoll); void publishState({ status: 'failed', error: message }).finally(() => { settleReady(new Error(message)); }); @@ -228,12 +242,29 @@ export async function runClaudeSetupToken({ status: 'waiting_for_user', verificationUrl: details.verificationUrl, userCode: details.userCode ?? null, - }).then(() => settleReady()); + }).then(() => { + verificationCodePoll = setInterval(async () => { + try { + const code = await readVerificationCode(setupPaths.verificationCodePath); + await deleteVerificationCode(setupPaths.verificationCodePath); + clearInterval(verificationCodePoll); + verificationCodePoll = undefined; + claude.stdin.write(`${code.replace(/\s+/g, '')}\r`); + } catch (error) { + if (error?.code !== 'ENOENT') { + publishFailure('Claude verification code could not be forwarded'); + claude.kill('SIGTERM'); + } + } + }, verificationCodePollMs); + settleReady(); + }); } function maybeCaptureToken(details) { if (tokenCaptured || !details.token) return; tokenCaptured = true; + if (verificationCodePoll) clearInterval(verificationCodePoll); void writeCredentialFile(details.token) .then(() => publishState({ status: 'completed' })) .then(() => settleReady()) @@ -245,10 +276,11 @@ export async function runClaudeSetupToken({ }); } - function processLine(line) { + function processOutput(chunk) { + outputBuffer = `${outputBuffer}${chunk}`.slice(-32768); let details; try { - details = extractClaudeSetupOutput(line); + details = extractClaudeSetupOutput(outputBuffer); } catch (error) { publishFailure(error instanceof Error ? error.message : String(error)); claude.kill('SIGTERM'); @@ -258,8 +290,8 @@ export async function runClaudeSetupToken({ maybeCaptureToken(details); } - createInterface({ input: claude.stdout }).on('line', processLine); - createInterface({ input: claude.stderr }).on('line', processLine); + claude.stdout.on('data', processOutput); + claude.stderr.on('data', processOutput); claude.on('error', (error) => { publishFailure(error.message); @@ -276,8 +308,11 @@ export async function runClaudeSetupToken({ if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) { const statePath = process.argv[2]; const credentialPath = process.argv[3]; - if (!statePath || !credentialPath) { - process.stderr.write('Usage: claude-setup-token.mjs \n'); + const verificationCodePath = process.argv[4]; + if (!statePath || !credentialPath || !verificationCodePath) { + process.stderr.write( + 'Usage: claude-setup-token.mjs \n' + ); process.exitCode = 2; } else { runClaudeSetupToken({ diff --git a/apps/api/src/durable-objects/credential-setup-session/index.ts b/apps/api/src/durable-objects/credential-setup-session/index.ts index 74bda520b0..9cbde3d3ed 100644 --- a/apps/api/src/durable-objects/credential-setup-session/index.ts +++ b/apps/api/src/durable-objects/credential-setup-session/index.ts @@ -98,6 +98,9 @@ type DeviceAuthDetailsRow = { /** Relative paths of captured credential files inside the per-session setup home. */ const CODEX_AUTH_FILE = 'auth.json'; const CLAUDE_OAUTH_TOKEN_FILE = 'claude-oauth-token.txt'; +const CLAUDE_VERIFICATION_CODE_FILE = 'verification-code.txt'; +const MAX_CLAUDE_VERIFICATION_CODE_LENGTH = 1024; +const CLAUDE_VERIFICATION_CODE_PATTERN = /^[A-Za-z0-9._~#-]+$/; const DEVICE_AUTH_STATE_FILE = 'device-auth-state.json'; function setupDisplayName(agentType: string): string { @@ -201,7 +204,10 @@ export class CredentialSetupSession extends DurableObject { getState(): SetupSessionStateResult | null { const row = this.readRow(); if (!row) return null; - const deviceAuth = row.status === 'waiting_for_user' ? this.readDeviceAuthDetails() : null; + const deviceAuth = + row.status === 'waiting_for_user' || row.status === 'exchanging' + ? this.readDeviceAuthDetails() + : null; return { id: row.id, status: row.status as SetupSessionStatus, @@ -256,95 +262,32 @@ export class CredentialSetupSession extends DurableObject { }; } - /** - * Complete a Claude Code guided setup from the token the Claude browser flow - * gives back to the user. This deliberately bypasses terminal/stdin replay: - * the submitted secret is validated, saved through the same encrypted writer - * as sandbox capture, and never stored in DO SQLite or D1. - */ - async submitCredential(credential: string): Promise { + /** Forward the browser-displayed short-lived code to the sandboxed Claude CLI. */ + async submitVerificationCode(code: string): Promise { const row = this.readRow(); - if (!row) { - throw new Error('Setup session not found'); - } + if (!row) throw new Error('Setup session not found'); if (row.agent_type !== 'claude-code') { - throw new Error('Manual credential submission is only supported for Claude Code setup'); + throw new Error('Verification code submission is only supported for Claude Code setup'); + } + if (row.status !== 'waiting_for_user') { + throw new Error('Claude Code setup is not waiting for a verification code'); } - const currentState = this.getState(); + const normalizedCode = code.trim().replace(/\s+/g, ''); if ( - row.status === 'completed' || - row.status === 'saving' || - isTerminalSetupStatus(row.status) + normalizedCode.length === 0 || + normalizedCode.length > MAX_CLAUDE_VERIFICATION_CODE_LENGTH || + !CLAUDE_VERIFICATION_CODE_PATTERN.test(normalizedCode) ) { - return ( - currentState ?? { - id: row.id, - status: row.status as SetupSessionStatus, - expiresAt: row.expires_at, - errorCode: row.error_code, - errorMessage: row.error_message, - verificationUrl: null, - userCode: null, - } - ); - } - - const trimmedCredential = credential.trim(); - const validation = CredentialValidator.validateCredential( - trimmedCredential, - row.credential_kind as CredentialKind, - row.agent_type as AgentType - ); - if (!validation.valid) { - throw new Error(validation.error ?? 'Invalid credential format'); - } - - this.setStatus(row.id, 'saving'); - await this.updateD1Status(row.id, 'saving'); - const savingRow = this.readRow(); - if (!savingRow || savingRow.status !== 'saving') { - const latestState = this.getState(); - if (latestState) return latestState; - throw new Error('Setup session state changed before credential save'); + throw new Error('Invalid Claude verification code'); } - try { - await saveAgentCredentialForUser({ - env: this.env, - userId: savingRow.user_id, - projectId: savingRow.project_id, - agentType: savingRow.agent_type as AgentType, - credentialKind: savingRow.credential_kind as CredentialKind, - credential: trimmedCredential, - provider: savingRow.provider, - agentName: savingRow.agent_name, - autoActivate: true, - }); - } catch (err) { - log.error('credential_setup.manual_save_failed', { - sessionId: savingRow.id, - error: err instanceof Error ? err.message : String(err), - }); - await this.teardown( - savingRow, - 'failed', - 'manual_save_failed', - 'Failed to save the submitted credential' - ); - return ( - this.getState() ?? - this.terminalState( - savingRow, - 'failed', - 'manual_save_failed', - 'Failed to save the submitted credential' - ) - ); - } - - await this.teardown(savingRow, 'completed'); - return this.getState() ?? this.terminalState(savingRow, 'completed'); + const sandbox = await getSandboxInstance(this.env, row.id); + await sandbox.writeFile(`${row.codex_home}/${CLAUDE_VERIFICATION_CODE_FILE}`, normalizedCode); + this.setStatus(row.id, 'exchanging'); + await this.updateD1Status(row.id, 'exchanging'); + await this.ctx.storage.setAlarm(Date.now() + row.capture_poll_ms); + return this.getState() ?? this.terminalState(row, 'exchanging'); } /** @@ -383,7 +326,19 @@ export class CredentialSetupSession extends DurableObject { await this.ctx.storage.setAlarm(Date.now() + row.capture_poll_ms); return; } - // waiting_for_user | capturing — poll for the credential file. + // waiting_for_user | exchanging | capturing — observe driver failure and capture output. + const driverState = await this.readDeviceAuthState(row); + if (driverState?.status === 'failed') { + await this.teardown( + row, + 'failed', + row.status === 'exchanging' ? 'code_rejected' : 'setup_failed', + row.status === 'exchanging' + ? 'Claude rejected the verification code. Start again and use a fresh code.' + : 'Claude Code could not complete sign-in' + ); + return; + } await this.attemptCapture(row); } catch (err) { // Unexpected transient error — log and reschedule; the TTL guard bounds @@ -448,11 +403,12 @@ export class CredentialSetupSession extends DurableObject { private startSetupDriverCommand(row: SetupSessionRow, statePath: string): string { if (row.agent_type === 'claude-code') { const credentialPath = `${row.codex_home}/${CLAUDE_OAUTH_TOKEN_FILE}`; + const verificationCodePath = `${row.codex_home}/${CLAUDE_VERIFICATION_CODE_FILE}`; return ( `nohup env CLAUDE_CONFIG_DIR=${shellQuote(row.codex_home)} ` + 'DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=dumb ' + `node /usr/local/bin/sam-claude-setup-token.mjs ${shellQuote(statePath)} ` + - `${shellQuote(credentialPath)} >/dev/null 2>&1 &` + `${shellQuote(credentialPath)} ${shellQuote(verificationCodePath)} >/dev/null 2>&1 &` ); } diff --git a/apps/api/src/routes/agent-credential-setup-sessions.ts b/apps/api/src/routes/agent-credential-setup-sessions.ts index d3d94049c7..8d77b720a7 100644 --- a/apps/api/src/routes/agent-credential-setup-sessions.ts +++ b/apps/api/src/routes/agent-credential-setup-sessions.ts @@ -33,10 +33,9 @@ import { cancelSetupSession, getSetupSessionState, startSetupSession, - submitSetupSessionCredential, + submitSetupSessionVerificationCode, } from '../services/credential-setup-session'; import { leaseSetupSlot, releaseSetupSlot } from '../services/setup-session-pool'; -import { CredentialValidator } from '../services/validation'; const agentCredentialSetupSessionsRoutes = new Hono<{ Bindings: Env }>(); @@ -45,15 +44,10 @@ const SUPPORTED_SETUP_AGENT_TYPES = ['openai-codex', 'claude-code'] as const; type SupportedSetupAgentType = (typeof SUPPORTED_SETUP_AGENT_TYPES)[number]; const SETUP_CREDENTIAL_KIND = 'oauth-token'; const ACTIVE_STATUS_PLACEHOLDERS = ACTIVE_SETUP_STATUSES.map(() => '?').join(', '); -const MAX_SUBMITTED_CLAUDE_TOKEN_LENGTH = 8192; +const MAX_SUBMITTED_CLAUDE_CODE_LENGTH = 1024; -const SubmitSetupCredentialSchema = v.object({ - credential: v.pipe( - v.string(), - v.trim(), - v.minLength(1), - v.maxLength(MAX_SUBMITTED_CLAUDE_TOKEN_LENGTH) - ), +const SubmitVerificationCodeSchema = v.object({ + code: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(MAX_SUBMITTED_CLAUDE_CODE_LENGTH)), }); function isSupportedSetupAgentType(agentType: AgentType): agentType is SupportedSetupAgentType { @@ -281,37 +275,24 @@ agentCredentialSetupSessionsRoutes.get('/:id', requireAuth(), requireApproved(), }); // ----------------------------------------------------------------------------- -// POST /:id/credential — complete Claude setup from browser-provided token +// POST /:id/verification-code — forward Claude's browser code to the CLI // ----------------------------------------------------------------------------- agentCredentialSetupSessionsRoutes.post( - '/:id/credential', + '/:id/verification-code', requireAuth(), requireApproved(), - jsonValidator(SubmitSetupCredentialSchema), + jsonValidator(SubmitVerificationCodeSchema), async (c) => { const userId = getUserId(c); const row = await loadOwnedSession(c.env, c.req.param('id'), userId); if (row.agent_type !== 'claude-code') { - throw errors.badRequest( - 'Manual credential submission is only available for Claude Code setup' - ); + throw errors.badRequest('Verification codes are only available for Claude Code setup'); } if (isTerminalSetupStatus(row.status)) { throw errors.conflict('Setup session is no longer active'); } - const body = c.req.valid('json'); - const credential = body.credential.trim(); - const validation = CredentialValidator.validateCredential( - credential, - SETUP_CREDENTIAL_KIND, - 'claude-code' - ); - if (!validation.valid) { - throw errors.badRequest(validation.error ?? 'Invalid Claude OAuth token'); - } - - const state = await submitSetupSessionCredential(c.env, row.id, credential); + const state = await submitSetupSessionVerificationCode(c.env, row.id, c.req.valid('json').code); return c.json({ id: row.id, status: state.status, diff --git a/apps/api/src/services/credential-setup-config.ts b/apps/api/src/services/credential-setup-config.ts index 0f85ab0c85..5249183c18 100644 --- a/apps/api/src/services/credential-setup-config.ts +++ b/apps/api/src/services/credential-setup-config.ts @@ -62,6 +62,7 @@ export const ACTIVE_SETUP_STATUSES = [ 'admitting', 'provisioning', 'waiting_for_user', + 'exchanging', 'capturing', 'saving', ] as const; diff --git a/apps/api/src/services/credential-setup-session.ts b/apps/api/src/services/credential-setup-session.ts index 3856e1ec75..aa79b87daf 100644 --- a/apps/api/src/services/credential-setup-session.ts +++ b/apps/api/src/services/credential-setup-session.ts @@ -41,10 +41,10 @@ export async function cancelSetupSession( return getStub(env, sessionId).cancel(); } -export async function submitSetupSessionCredential( +export async function submitSetupSessionVerificationCode( env: Env, sessionId: string, - credential: string + code: string ): Promise { - return getStub(env, sessionId).submitCredential(credential); + return getStub(env, sessionId).submitVerificationCode(code); } diff --git a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts index a9bf296635..f04b593f96 100644 --- a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts +++ b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts @@ -642,7 +642,7 @@ describe('CredentialSetupSession — alarm() capture polling', () => { expect((await created.instance.getState())?.status).toBe('completed'); }); - it('saves a browser-submitted Claude token, completes, and tears down', async () => { + it('normalizes and forwards a code#state value to the sandbox, then exchanges', async () => { const created = createDO(); await Promise.resolve(); const fakeSandbox = createFakeSandbox(); @@ -657,63 +657,84 @@ describe('CredentialSetupSession — alarm() capture polling', () => { vi.mocked(getSandboxInstance).mockResolvedValue(fakeSandbox as never); await created.instance.create({ - id: 'setup-claude-manual', - setupHome: '/tmp/claude-setup-manual', + id: 'setup-claude-code', + setupHome: '/tmp/claude-setup-code', ttlMs: 900_000, ...BASE_PARAMS, agentType: 'claude-code', provider: 'anthropic', agentName: 'Claude Code', }); - await created.instance.alarm(); // provisioning -> admitting - await created.instance.alarm(); // device state -> waiting_for_user + await created.instance.alarm(); + await created.instance.alarm(); - const token = `sk-ant-oat${'E'.repeat(48)}`; - vi.mocked(saveAgentCredentialForUser).mockResolvedValue({ - created: true, - createdAt: '2026-07-01T00:00:00.000Z', - updatedAt: '2026-07-01T00:00:00.000Z', - }); + const result = await created.instance.submitVerificationCode(' abc123 #state456\n'); - const result = await created.instance.submitCredential(` ${token}\n`); + expect(result.status).toBe('exchanging'); + expect(fakeSandbox.writeFile).toHaveBeenCalledWith( + '/tmp/claude-setup-code/verification-code.txt', + 'abc123#state456' + ); + expect(saveAgentCredentialForUser).not.toHaveBeenCalled(); + expect(JSON.stringify(created.database._calls)).not.toContain('abc123#state456'); + }); - expect(result.status).toBe('completed'); - expect(saveAgentCredentialForUser).toHaveBeenCalledWith( - expect.objectContaining({ - userId: BASE_PARAMS.userId, - projectId: null, - agentType: 'claude-code', - credentialKind: 'oauth-token', - credential: token, - provider: 'anthropic', - agentName: 'Claude Code', - autoActivate: true, - }) + it('guards verification-code agent, state, length, and charset', async () => { + const created = createDO(); + await Promise.resolve(); + const fakeSandbox = createFakeSandbox(); + vi.mocked(getSandboxInstance).mockResolvedValue(fakeSandbox as never); + await created.instance.create({ + id: 'setup-guard', + setupHome: '/tmp/setup-guard', + ttlMs: 900_000, + ...BASE_PARAMS, + }); + await expect(created.instance.submitVerificationCode('abc#state')).rejects.toThrow( + /only supported/ ); - expect(JSON.stringify(created.database._calls)).not.toContain(token); - expect(releaseSetupSlot).toHaveBeenCalledWith(expect.anything(), 'lease-abc'); - expect(destroySandboxInstance).toHaveBeenCalledWith(expect.anything(), 'setup-claude-manual', { - sandboxId: 'setup-claude-manual', + + const claude = createDO(); + await Promise.resolve(); + vi.mocked(getSandboxInstance).mockResolvedValue(fakeSandbox as never); + await claude.instance.create({ + id: 'setup-claude-guard', + setupHome: '/tmp/setup-claude-guard', + ttlMs: 900_000, + ...BASE_PARAMS, + agentType: 'claude-code', + provider: 'anthropic', + agentName: 'Claude Code', }); + await expect(claude.instance.submitVerificationCode('abc#state')).rejects.toThrow( + /not waiting/ + ); + await claude.instance.alarm(); + await claude.instance.alarm(); + await expect(claude.instance.submitVerificationCode('bad code!')).rejects.toThrow(/Invalid/); + await expect(claude.instance.submitVerificationCode('x'.repeat(1025))).rejects.toThrow( + /Invalid/ + ); }); - it('rejects an invalid browser-submitted Claude token without failing the active session', async () => { + it('fails fast with a sanitized error when Claude rejects the submitted code', async () => { const created = createDO(); await Promise.resolve(); + let driverStatus = 'waiting_for_user'; const fakeSandbox = createFakeSandbox(); fakeSandbox.readFile.mockImplementation(async (path: string) => ({ content: path.endsWith('device-auth-state.json') ? JSON.stringify({ - status: 'waiting_for_user', + status: driverStatus, verificationUrl: 'https://claude.ai/oauth/device', + error: 'secret provider detail', }) : '', })); vi.mocked(getSandboxInstance).mockResolvedValue(fakeSandbox as never); - await created.instance.create({ - id: 'setup-claude-invalid-manual', - setupHome: '/tmp/claude-setup-invalid-manual', + id: 'setup-rejected', + setupHome: '/tmp/setup-rejected', ttlMs: 900_000, ...BASE_PARAMS, agentType: 'claude-code', @@ -722,14 +743,14 @@ describe('CredentialSetupSession — alarm() capture polling', () => { }); await created.instance.alarm(); await created.instance.alarm(); + await created.instance.submitVerificationCode('abc123#state456'); + driverStatus = 'failed'; + await created.instance.alarm(); - await expect(created.instance.submitCredential('sk-ant-api-not-oauth')).rejects.toThrow( - /API key/ - ); - - expect((await created.instance.getState())?.status).toBe('waiting_for_user'); - expect(saveAgentCredentialForUser).not.toHaveBeenCalled(); - expect(releaseSetupSlot).not.toHaveBeenCalled(); + const state = await created.instance.getState(); + expect(state).toMatchObject({ status: 'failed', errorCode: 'code_rejected' }); + expect(state?.errorMessage).not.toContain('secret provider detail'); + expect(releaseSetupSlot).toHaveBeenCalledWith(expect.anything(), 'lease-abc'); }); it('tears down as failed when saveAgentCredentialForUser rejects', async () => { diff --git a/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts b/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts index fdded95266..5de65c8301 100644 --- a/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts +++ b/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts @@ -141,7 +141,7 @@ describe('native Codex setup route vertical slice', () => { expect(getState).not.toHaveBeenCalled(); }); - it('submits an owned Claude browser token through the DO boundary without persisting the secret in D1', async () => { + it('submits an owned Claude browser verification code through the DO boundary without persisting the secret in D1', async () => { const sqlite = setupDatabase(); const now = new Date().toISOString(); sqlite @@ -161,8 +161,8 @@ describe('native Codex setup route vertical slice', () => { now ); - const token = `sk-ant-oat${'D'.repeat(48)}`; - const submitCredential = vi.fn().mockResolvedValue({ + const code = 'abc123#state456'; + const submitVerificationCode = vi.fn().mockResolvedValue({ id: 'session-claude', status: 'completed', expiresAt: Date.now() + 60_000, @@ -175,7 +175,7 @@ describe('native Codex setup route vertical slice', () => { DATABASE: createSqliteD1(sqlite), CREDENTIAL_SETUP_SESSION: { idFromName: vi.fn(() => ({ toString: () => 'do-session-claude' })), - get: vi.fn(() => ({ submitCredential })), + get: vi.fn(() => ({ submitVerificationCode })), }, } as unknown as Env; const app = new Hono<{ Bindings: Env }>(); @@ -186,11 +186,11 @@ describe('native Codex setup route vertical slice', () => { app.route('/api/agent-credential-setup-sessions', agentCredentialSetupSessionsRoutes); const response = await app.request( - '/api/agent-credential-setup-sessions/session-claude/credential', + '/api/agent-credential-setup-sessions/session-claude/verification-code', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ credential: ` ${token}\n` }), + body: JSON.stringify({ code: ` abc123 #state456\n` }), }, env ); @@ -201,14 +201,14 @@ describe('native Codex setup route vertical slice', () => { status: 'completed', agentType: 'claude-code', }); - expect(submitCredential).toHaveBeenCalledWith(token); + expect(submitVerificationCode).toHaveBeenCalledWith('abc123 #state456'); const persisted = sqlite .prepare('SELECT * FROM agent_credential_setup_sessions WHERE id = ?') .get('session-claude') as Record; - expect(JSON.stringify(persisted)).not.toContain(token); + expect(JSON.stringify(persisted)).not.toContain(code); }); - it('rejects an invalid Claude browser token before crossing the DO boundary', async () => { + it('passes code shape validation to the DO boundary for authoritative validation', async () => { const sqlite = setupDatabase(); const now = new Date().toISOString(); sqlite @@ -228,12 +228,20 @@ describe('native Codex setup route vertical slice', () => { now ); - const submitCredential = vi.fn(); + const submitVerificationCode = vi.fn().mockResolvedValue({ + id: 'session-bad-token', + status: 'exchanging', + expiresAt: Date.now() + 60_000, + errorCode: null, + errorMessage: null, + verificationUrl: 'https://claude.ai/oauth/device', + userCode: null, + }); const env = { DATABASE: createSqliteD1(sqlite), CREDENTIAL_SETUP_SESSION: { idFromName: vi.fn(() => ({ toString: () => 'do-session-bad-token' })), - get: vi.fn(() => ({ submitCredential })), + get: vi.fn(() => ({ submitVerificationCode })), }, } as unknown as Env; const app = new Hono<{ Bindings: Env }>(); @@ -244,17 +252,16 @@ describe('native Codex setup route vertical slice', () => { app.route('/api/agent-credential-setup-sessions', agentCredentialSetupSessionsRoutes); const response = await app.request( - '/api/agent-credential-setup-sessions/session-bad-token/credential', + '/api/agent-credential-setup-sessions/session-bad-token/verification-code', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ credential: 'sk-ant-api-this-is-not-oauth' }), + body: JSON.stringify({ code: 'invalid code!' }), }, env ); - expect(response.status).toBe(400); - expect(env.CREDENTIAL_SETUP_SESSION.idFromName).not.toHaveBeenCalled(); - expect(submitCredential).not.toHaveBeenCalled(); + expect(response.status).toBe(200); + expect(submitVerificationCode).toHaveBeenCalledWith('invalid code!'); }); }); diff --git a/apps/api/tests/unit/scripts/claude-setup-token.test.ts b/apps/api/tests/unit/scripts/claude-setup-token.test.ts index dd5d418f37..d2eacd0466 100644 --- a/apps/api/tests/unit/scripts/claude-setup-token.test.ts +++ b/apps/api/tests/unit/scripts/claude-setup-token.test.ts @@ -16,10 +16,12 @@ function fakeClaudeProcess() { stdout: PassThrough; stderr: PassThrough; kill: ReturnType; + stdin: PassThrough; }; process.stdout = new PassThrough(); process.stderr = new PassThrough(); process.kill = vi.fn(); + process.stdin = new PassThrough(); return process; } @@ -27,10 +29,15 @@ const CLAUDE_TOKEN = `sk-ant-oat${'A'.repeat(48)}`; const CLAUDE_SETUP_HOME = '/tmp/sam-claude-setup-test'; const CLAUDE_STATE_PATH = `${CLAUDE_SETUP_HOME}/device-auth-state.json`; const CLAUDE_CREDENTIAL_PATH = `${CLAUDE_SETUP_HOME}/claude-oauth-token.txt`; +const CLAUDE_VERIFICATION_CODE_PATH = `${CLAUDE_SETUP_HOME}/verification-code.txt`; function validSetupPaths() { vi.stubEnv('CLAUDE_CONFIG_DIR', CLAUDE_SETUP_HOME); - return { statePath: CLAUDE_STATE_PATH, credentialPath: CLAUDE_CREDENTIAL_PATH }; + return { + statePath: CLAUDE_STATE_PATH, + credentialPath: CLAUDE_CREDENTIAL_PATH, + verificationCodePath: CLAUDE_VERIFICATION_CODE_PATH, + }; } afterEach(() => { @@ -99,11 +106,13 @@ describe('Claude setup-token driver', () => { resolveClaudeSetupPaths({ statePath: CLAUDE_STATE_PATH, credentialPath: CLAUDE_CREDENTIAL_PATH, + verificationCodePath: CLAUDE_VERIFICATION_CODE_PATH, }) ).toEqual({ statePath: CLAUDE_STATE_PATH, temporaryStatePath: `${CLAUDE_SETUP_HOME}/device-auth-state.json.tmp`, credentialPath: CLAUDE_CREDENTIAL_PATH, + verificationCodePath: CLAUDE_VERIFICATION_CODE_PATH, temporaryCredentialPath: `${CLAUDE_SETUP_HOME}/claude-oauth-token.txt.tmp`, }); @@ -111,18 +120,21 @@ describe('Claude setup-token driver', () => { resolveClaudeSetupPaths({ statePath: `${CLAUDE_SETUP_HOME}/../device-auth-state.json`, credentialPath: CLAUDE_CREDENTIAL_PATH, + verificationCodePath: CLAUDE_VERIFICATION_CODE_PATH, }) ).toThrow(/expected setup state file/); expect(() => resolveClaudeSetupPaths({ statePath: CLAUDE_STATE_PATH, credentialPath: `${CLAUDE_SETUP_HOME}/../claude-oauth-token.txt`, + verificationCodePath: CLAUDE_VERIFICATION_CODE_PATH, }) ).toThrow(/expected OAuth token file/); expect(() => resolveClaudeSetupPaths({ statePath: '/device-auth-state.json', credentialPath: '/claude-oauth-token.txt', + verificationCodePath: '/verification-code.txt', configDir: '/', }) ).toThrow(/must not resolve to the filesystem root/); @@ -144,6 +156,9 @@ describe('Claude setup-token driver', () => { }, writeState: async (state) => states.push(state), writeCredential: async (token) => credentials.push(token), + readVerificationCode: vi.fn().mockResolvedValue(' abc 123#state\n'), + deleteVerificationCode: vi.fn().mockResolvedValue(undefined), + verificationCodePollMs: 1, }); expect(spawnedCommand).toBe('script'); @@ -165,6 +180,9 @@ describe('Claude setup-token driver', () => { }, ]); expect(JSON.stringify(states)).not.toContain(CLAUDE_TOKEN); + const stdinBytes: Buffer[] = []; + fake.stdin.on('data', (chunk) => stdinBytes.push(Buffer.from(chunk))); + await vi.waitFor(() => expect(Buffer.concat(stdinBytes).toString()).toBe('abc123#state\r')); fake.stdout.write(`Your token: ${CLAUDE_TOKEN}\n`); await vi.waitFor(() => expect(credentials).toEqual([CLAUDE_TOKEN])); diff --git a/apps/web/src/components/CodexConnectModal.tsx b/apps/web/src/components/CodexConnectModal.tsx index 3f450c992d..c878a524e7 100644 --- a/apps/web/src/components/CodexConnectModal.tsx +++ b/apps/web/src/components/CodexConnectModal.tsx @@ -10,7 +10,7 @@ import { getAgentCredentialSetupSession, type GuidedSetupAgentType, isTerminalAgentCredentialSetupStatus, - submitAgentCredentialSetupCredential, + submitAgentCredentialSetupVerificationCode, } from '../lib/api'; interface AgentCredentialConnectModalProps { @@ -81,6 +81,8 @@ function statusLabel(status: AgentCredentialSetupStatus, shortName: string): str case 'waiting_for_user': case 'capturing': return 'Waiting for sign-in'; + case 'exchanging': + return 'Completing sign-in…'; case 'saving': return 'Saving…'; case 'completed': @@ -110,13 +112,13 @@ export function AgentCredentialConnectModal({ const [session, setSession] = useState(null); const [message, setMessage] = useState(null); const [copied, setCopied] = useState(false); - const [submittedCredential, setSubmittedCredential] = useState(''); + const [verificationCode, setVerificationCode] = useState(''); const [submitError, setSubmitError] = useState(null); - const [submittingCredential, setSubmittingCredential] = useState(false); + const [submittingCode, setSubmittingCode] = useState(false); const [retryNonce, setRetryNonce] = useState(0); const sessionIdRef = useRef(null); const finishedRef = useRef(false); - const credentialSubmitInFlightRef = useRef(false); + const codeSubmitInFlightRef = useRef(false); const manualCloseTimerRef = useRef | null>(null); const onConnectedRef = useRef(onConnected); const onCloseRef = useRef(onClose); @@ -136,10 +138,10 @@ export function AgentCredentialConnectModal({ setSession(null); setMessage(null); setCopied(false); - setSubmittedCredential(''); + setVerificationCode(''); setSubmitError(null); - setSubmittingCredential(false); - credentialSubmitInFlightRef.current = false; + setSubmittingCode(false); + codeSubmitInFlightRef.current = false; if (manualCloseTimerRef.current) clearTimeout(manualCloseTimerRef.current); manualCloseTimerRef.current = null; sessionIdRef.current = null; @@ -162,7 +164,7 @@ export function AgentCredentialConnectModal({ !sessionIdRef.current || pollInFlight || finishedRef.current || - credentialSubmitInFlightRef.current + codeSubmitInFlightRef.current ) return; pollInFlight = true; @@ -222,24 +224,24 @@ export function AgentCredentialConnectModal({ } }; - const handleSubmitCredential = async () => { + const handleSubmitVerificationCode = async () => { const id = sessionIdRef.current; - const credential = submittedCredential.trim(); - if (!id || !credential) { - setSubmitError('Paste the Claude token from the browser first.'); + const code = verificationCode.trim(); + if (!id || !code) { + setSubmitError('Paste the code Claude shows you first.'); return; } - credentialSubmitInFlightRef.current = true; - setSubmittingCredential(true); + codeSubmitInFlightRef.current = true; + setSubmittingCode(true); setSubmitError(null); setMessage(null); - setSession((current) => (current ? { ...current, status: 'saving' } : current)); + setSession((current) => (current ? { ...current, status: 'exchanging' } : current)); try { - const next = await submitAgentCredentialSetupCredential(id, credential); + const next = await submitAgentCredentialSetupVerificationCode(id, code); setSession(next); - setSubmittedCredential(''); + setVerificationCode(''); if (isTerminalAgentCredentialSetupStatus(next.status)) { finishedRef.current = true; if (next.status === 'completed') { @@ -251,18 +253,18 @@ export function AgentCredentialConnectModal({ } } catch (error) { setSession((current) => - current && current.status === 'saving' + current && current.status === 'exchanging' ? { ...current, status: 'waiting_for_user' } : current ); setSubmitError( error instanceof Error ? error.message - : 'Failed to save the Claude token. Please try again.' + : 'Failed to submit the Claude verification code. Please try again.' ); } finally { - credentialSubmitInFlightRef.current = false; - setSubmittingCredential(false); + codeSubmitInFlightRef.current = false; + setSubmittingCode(false); } }; @@ -280,8 +282,8 @@ export function AgentCredentialConnectModal({ phase === 'created' && status !== null && !isTerminalAgentCredentialSetupStatus(status); const ready = isActive && !!session?.verificationUrl; const hasCode = ready && !!session?.userCode; - const canSubmitClaudeCredential = ready && agentType === 'claude-code' && status !== 'saving'; - const credentialInputId = `${titleId}-credential`; + const canSubmitClaudeCode = ready && agentType === 'claude-code' && status === 'waiting_for_user'; + const verificationCodeInputId = `${titleId}-credential`; const header = (
@@ -367,38 +369,38 @@ export function AgentCredentialConnectModal({
)} - {canSubmitClaudeCredential && ( + {canSubmitClaudeCode && (
{ event.preventDefault(); - void handleSubmitCredential(); + void handleSubmitVerificationCode(); }} >
{ - setSubmittedCredential(event.currentTarget.value); + setVerificationCode(event.currentTarget.value); setSubmitError(null); }} - placeholder="sk-ant-oat…" + placeholder="code#state" className="min-h-11 w-full rounded-md border border-border-default bg-bg-primary px-3 py-2 text-sm text-fg-primary outline-none focus:border-accent focus:ring-2 focus:ring-accent/20" />

- After Claude shows a token, paste it here. SAM saves it encrypted and never - displays it again. + Approve access in the browser, then paste the code Claude shows you. It may + be two parts joined with a #.

{submitError && {submitError}} @@ -406,11 +408,11 @@ export function AgentCredentialConnectModal({ type="submit" variant="primary" size="sm" - loading={submittingCredential} - disabled={!submittedCredential.trim()} + loading={submittingCode} + disabled={!verificationCode.trim()} className="self-start" > - {submittingCredential ? 'Saving…' : 'Save Claude token'} + {submittingCode ? 'Completing sign-in…' : 'Continue sign-in'}
)} @@ -427,7 +429,7 @@ export function AgentCredentialConnectModal({ {message && phase === 'created' && {message}}
- {isActive && status !== 'saving' && ( + {isActive && status !== 'saving' && status !== 'exchanging' && ( diff --git a/apps/web/src/lib/api/codex-setup.ts b/apps/web/src/lib/api/codex-setup.ts index 8e938385e4..37ec49c087 100644 --- a/apps/web/src/lib/api/codex-setup.ts +++ b/apps/web/src/lib/api/codex-setup.ts @@ -33,6 +33,7 @@ export type AgentCredentialSetupStatus = | 'admitting' | 'provisioning' | 'waiting_for_user' + | 'exchanging' | 'capturing' | 'saving' | 'completed' @@ -181,13 +182,16 @@ export async function cancelAgentCredentialSetupSession( export const cancelCodexSetupSession = cancelAgentCredentialSetupSession; -/** POST /:id/credential — complete Claude Code setup with the browser-returned token. */ -export async function submitAgentCredentialSetupCredential( +/** POST /:id/verification-code — forward Claude Code browser code to its sandboxed CLI. */ +export async function submitAgentCredentialSetupVerificationCode( id: string, - credential: string + code: string ): Promise { - return request(`${BASE_PATH}/${encodeURIComponent(id)}/credential`, { - method: 'POST', - body: JSON.stringify({ credential }), - }); + return request( + `${BASE_PATH}/${encodeURIComponent(id)}/verification-code`, + { + method: 'POST', + body: JSON.stringify({ code }), + } + ); } diff --git a/apps/web/src/lib/api/index.ts b/apps/web/src/lib/api/index.ts index cf667aa5b8..390dc9bf0e 100644 --- a/apps/web/src/lib/api/index.ts +++ b/apps/web/src/lib/api/index.ts @@ -156,7 +156,7 @@ export { isTerminalAgentCredentialSetupStatus, isTerminalCodexSetupStatus, setupConfigSupportsAgent, - submitAgentCredentialSetupCredential, + submitAgentCredentialSetupVerificationCode, } from './codex-setup'; export type { CCAttachmentListItem, diff --git a/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts b/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts index f444105b76..f4825c6526 100644 --- a/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts +++ b/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts @@ -37,7 +37,7 @@ const MOCK_CLAUDE_AGENT = { const CLAUDE_VERIFICATION_URL = 'https://claude.ai/oauth/device?client_id=sam-playwright&challenge=' + 'x'.repeat(180); const CLAUDE_USER_CODE = 'CLDE-PLAYWRIGHT-2026-LONG-CODE'; -const CLAUDE_SUBMITTED_TOKEN = 'sk-ant-oat-playwright-token-from-browser'; +const CLAUDE_SUBMITTED_CODE = 'abc123#state-playwright'; const SETUP_SESSION = { id: 'setup-claude-guided-audit', status: 'waiting_for_user', @@ -66,7 +66,7 @@ function respond(route: Route, status: number, body: unknown) { async function setupApiMocks( page: Page, seenSetupAgentTypes: string[], - seenSubmittedCredentials: string[] + seenSubmittedCodes: string[] ) { await page.route('**/api/**', async (route) => { const request = route.request(); @@ -115,11 +115,11 @@ async function setupApiMocks( return respond(route, 200, SETUP_SESSION); } if ( - path === `/api/agent-credential-setup-sessions/${SETUP_SESSION.id}/credential` && + path === `/api/agent-credential-setup-sessions/${SETUP_SESSION.id}/verification-code` && method === 'POST' ) { - const body = request.postDataJSON() as { credential?: string }; - seenSubmittedCredentials.push(body.credential ?? ''); + const body = request.postDataJSON() as { code?: string }; + seenSubmittedCodes.push(body.code ?? ''); return respond(route, 200, COMPLETED_SETUP_SESSION); } if (path === `/api/agent-credential-setup-sessions/${SETUP_SESSION.id}/cancel`) { @@ -185,8 +185,8 @@ test('Claude guided connect uses native URL/copy controls without terminal outpu page, }) => { const seenSetupAgentTypes: string[] = []; - const seenSubmittedCredentials: string[] = []; - await setupApiMocks(page, seenSetupAgentTypes, seenSubmittedCredentials); + const seenSubmittedCodes: string[] = []; + await setupApiMocks(page, seenSetupAgentTypes, seenSubmittedCodes); await navigateToAgentSettings(page); await page.getByRole('button', { name: 'OAuth Token (Pro/Max)' }).click(); @@ -202,8 +202,8 @@ test('Claude guided connect uses native URL/copy controls without terminal outpu await expect(open).toHaveAttribute('href', CLAUDE_VERIFICATION_URL); await expect(copy).toBeVisible(); await expect(page.locator('code')).toHaveText(CLAUDE_USER_CODE); - await expect(page.getByLabel('Paste the Claude token from your browser')).toBeVisible(); - await expect(page.getByRole('button', { name: 'Save Claude token' })).toBeDisabled(); + await expect(page.getByLabel('Paste the code Claude shows you')).toBeVisible(); + await expect(page.getByRole('button', { name: 'Continue sign-in' })).toBeDisabled(); await expect(page.getByTestId('codex-terminal')).toHaveCount(0); const modal = page.getByRole('dialog', { name: 'Connect with Claude Code' }); await expect(modal.locator('pre, textarea, [data-testid*="terminal"]')).toHaveCount(0); @@ -223,8 +223,8 @@ test('Claude guided connect uses native URL/copy controls without terminal outpu await screenshot(page, 'claude-guided-connect-modal'); await assertNoOverflow(page); - await page.getByLabel('Paste the Claude token from your browser').fill(CLAUDE_SUBMITTED_TOKEN); - await page.getByRole('button', { name: 'Save Claude token' }).click(); - expect(seenSubmittedCredentials).toEqual([CLAUDE_SUBMITTED_TOKEN]); + await page.getByLabel('Paste the code Claude shows you').fill(CLAUDE_SUBMITTED_CODE); + await page.getByRole('button', { name: 'Continue sign-in' }).click(); + expect(seenSubmittedCodes).toEqual([CLAUDE_SUBMITTED_CODE]); await expect(page.getByText('Claude Code connected')).toBeVisible(); }); diff --git a/apps/web/tests/unit/components/CodexConnectModal.test.tsx b/apps/web/tests/unit/components/CodexConnectModal.test.tsx index 0f2c8ed1ba..edb22cfb4a 100644 --- a/apps/web/tests/unit/components/CodexConnectModal.test.tsx +++ b/apps/web/tests/unit/components/CodexConnectModal.test.tsx @@ -6,7 +6,7 @@ const h = vi.hoisted(() => ({ getAgentCredentialSetupSession: vi.fn(), cancelAgentCredentialSetupSession: vi.fn(), getAgentCredentialSetupConfig: vi.fn(), - submitAgentCredentialSetupCredential: vi.fn(), + submitAgentCredentialSetupVerificationCode: vi.fn(), })); vi.mock('../../../src/lib/api', async (importOriginal) => ({ @@ -15,7 +15,7 @@ vi.mock('../../../src/lib/api', async (importOriginal) => ({ getAgentCredentialSetupSession: h.getAgentCredentialSetupSession, cancelAgentCredentialSetupSession: h.cancelAgentCredentialSetupSession, getAgentCredentialSetupConfig: h.getAgentCredentialSetupConfig, - submitAgentCredentialSetupCredential: h.submitAgentCredentialSetupCredential, + submitAgentCredentialSetupVerificationCode: h.submitAgentCredentialSetupVerificationCode, })); import { @@ -32,7 +32,7 @@ const SESSION_ID = 'sess_setup_01'; const USER_CODE = 'ABCD-EFGH'; const OPENAI_VERIFICATION_URL = 'https://auth.openai.com/device'; const CLAUDE_VERIFICATION_URL = 'https://claude.ai/oauth/device'; -const CLAUDE_OAUTH_TOKEN = `sk-ant-oat${'C'.repeat(48)}`; +const CLAUDE_VERIFICATION_CODE = 'abc123#state456'; function makeSession( status: AgentCredentialSetupStatus, @@ -56,7 +56,7 @@ describe('AgentCredentialConnectModal', () => { h.getAgentCredentialSetupSession.mockReset(); h.cancelAgentCredentialSetupSession.mockReset(); h.getAgentCredentialSetupConfig.mockReset(); - h.submitAgentCredentialSetupCredential.mockReset(); + h.submitAgentCredentialSetupVerificationCode.mockReset(); vi.stubEnv('VITE_CODEX_SETUP_POLL_MS', '20'); vi.stubEnv('VITE_CODEX_SETUP_SUCCESS_CLOSE_MS', '10'); h.cancelAgentCredentialSetupSession.mockResolvedValue({ id: SESSION_ID, status: 'cancelled' }); @@ -114,7 +114,7 @@ describe('AgentCredentialConnectModal', () => { expect(screen.queryByTestId('codex-terminal')).not.toBeInTheDocument(); }); - it('lets Claude users paste the browser token and complete setup', async () => { + it('lets Claude users paste the browser verification code and complete setup', async () => { const onConnected = vi.fn(); h.createAgentCredentialSetupSession.mockResolvedValue({ kind: 'created', @@ -127,7 +127,7 @@ describe('AgentCredentialConnectModal', () => { userCode: null, }) ); - h.submitAgentCredentialSetupCredential.mockResolvedValue( + h.submitAgentCredentialSetupVerificationCode.mockResolvedValue( makeSession('completed', { agentType: 'claude-code' }) ); @@ -141,19 +141,19 @@ describe('AgentCredentialConnectModal', () => { ); await screen.findByRole('link', { name: /open claude sign-in/i }); - const tokenInput = screen.getByLabelText(/paste the claude token/i); + const tokenInput = screen.getByLabelText(/paste the code claude shows you/i); fireEvent.change(tokenInput, { target: { - value: ` ${CLAUDE_OAUTH_TOKEN} + value: ` ${CLAUDE_VERIFICATION_CODE} `, }, }); - fireEvent.click(screen.getByRole('button', { name: /save claude token/i })); + fireEvent.click(screen.getByRole('button', { name: /continue sign-in/i })); await waitFor(() => - expect(h.submitAgentCredentialSetupCredential).toHaveBeenCalledWith( + expect(h.submitAgentCredentialSetupVerificationCode).toHaveBeenCalledWith( SESSION_ID, - CLAUDE_OAUTH_TOKEN + CLAUDE_VERIFICATION_CODE ) ); await waitFor(() => expect(onConnected).toHaveBeenCalledOnce()); From 08ca49df28570566393b9f5a5fc8d6be5e889b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 26 Jul 2026 06:59:03 +0000 Subject: [PATCH 26/57] fix: harden Claude setup exchange races and wrapping --- apps/api/scripts/claude-setup-token.mjs | 4 ++-- .../src/durable-objects/credential-setup-session/index.ts | 4 ++++ apps/api/tests/unit/scripts/claude-setup-token.test.ts | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/api/scripts/claude-setup-token.mjs b/apps/api/scripts/claude-setup-token.mjs index 18863b9d30..3f3983e4c7 100644 --- a/apps/api/scripts/claude-setup-token.mjs +++ b/apps/api/scripts/claude-setup-token.mjs @@ -18,7 +18,7 @@ const CONTROL_CHARACTER_PATTERN = /[\u0000-\u001f\u007f]/; const CLAUDE_SETUP_COMMAND = 'stty cols 512; env DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=xterm-256color claude setup-token'; const URL_PATTERN = /https:\/\/[^\s<>'"`]+/gi; -const TOKEN_PATTERN = /\bsk-ant-oat[A-Za-z0-9._-]{16,}\b/g; +const TOKEN_PATTERN = /\bsk-ant-oat(?:[A-Za-z0-9._-]|\r?\n){16,8192}\b/g; const CODE_PATTERNS = [ /(?:verification|one[- ]time|device)?\s*code[^A-Za-z0-9-]{0,40}([A-Z0-9][A-Z0-9-]{3,127})/i, /enter\s+(?:this\s+|the\s+)?(?:code\s+)?([A-Z0-9][A-Z0-9-]{3,127})/i, @@ -152,7 +152,7 @@ export function extractClaudeSetupOutput(raw) { let token; TOKEN_PATTERN.lastIndex = 0; const tokenMatch = TOKEN_PATTERN.exec(text); - if (tokenMatch?.[0]) token = validateClaudeOauthToken(tokenMatch[0]); + if (tokenMatch?.[0]) token = validateClaudeOauthToken(tokenMatch[0].replace(/\s+/g, '')); return { verificationUrl, userCode, token }; } diff --git a/apps/api/src/durable-objects/credential-setup-session/index.ts b/apps/api/src/durable-objects/credential-setup-session/index.ts index 9cbde3d3ed..5e22ccfc00 100644 --- a/apps/api/src/durable-objects/credential-setup-session/index.ts +++ b/apps/api/src/durable-objects/credential-setup-session/index.ts @@ -284,6 +284,10 @@ export class CredentialSetupSession extends DurableObject { const sandbox = await getSandboxInstance(this.env, row.id); await sandbox.writeFile(`${row.codex_home}/${CLAUDE_VERIFICATION_CODE_FILE}`, normalizedCode); + const current = this.readRow(); + if (!current || current.status !== 'waiting_for_user') { + throw new Error('Claude Code setup is no longer waiting for a verification code'); + } this.setStatus(row.id, 'exchanging'); await this.updateD1Status(row.id, 'exchanging'); await this.ctx.storage.setAlarm(Date.now() + row.capture_poll_ms); diff --git a/apps/api/tests/unit/scripts/claude-setup-token.test.ts b/apps/api/tests/unit/scripts/claude-setup-token.test.ts index d2eacd0466..b61c2dfb95 100644 --- a/apps/api/tests/unit/scripts/claude-setup-token.test.ts +++ b/apps/api/tests/unit/scripts/claude-setup-token.test.ts @@ -57,6 +57,11 @@ describe('Claude setup-token driver', () => { }); }); + it('joins a token wrapped by the PTY instead of accepting a truncated fragment', () => { + const wrapped = `${CLAUDE_TOKEN.slice(0, 28)}\n${CLAUDE_TOKEN.slice(28)}`; + expect(extractClaudeSetupOutput(`Your token: ${wrapped}`).token).toBe(CLAUDE_TOKEN); + }); + it('extracts URLs from Claude terminal hyperlink output', () => { const output = extractClaudeSetupOutput( '\u001b]8;id=abc;https://claude.com/cai/oauth/authorize?code=abc&state=def\u0007' + From 204a3a228e9caa4546982deca31543028840337c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 26 Jul 2026 07:03:23 +0000 Subject: [PATCH 27/57] fix: keep Claude exchange sessions uniquely active --- .../0099_credential_setup_exchanging_status.sql | 15 +++++++++++++++ apps/api/src/db/schema.ts | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 apps/api/src/db/migrations/0099_credential_setup_exchanging_status.sql diff --git a/apps/api/src/db/migrations/0099_credential_setup_exchanging_status.sql b/apps/api/src/db/migrations/0099_credential_setup_exchanging_status.sql new file mode 100644 index 0000000000..dfb98b06c0 --- /dev/null +++ b/apps/api/src/db/migrations/0099_credential_setup_exchanging_status.sql @@ -0,0 +1,15 @@ +-- Keep the one-active guided-login invariant while Claude Code exchanges the +-- browser-displayed verification code inside its sandboxed CLI. +DROP INDEX IF EXISTS idx_agent_credential_setup_one_active; + +CREATE UNIQUE INDEX idx_agent_credential_setup_one_active + ON agent_credential_setup_sessions(user_id, agent_type) + WHERE status IN ( + 'creating', + 'admitting', + 'provisioning', + 'waiting_for_user', + 'exchanging', + 'capturing', + 'saving' + ); diff --git a/apps/api/src/db/schema.ts b/apps/api/src/db/schema.ts index 16291a466e..661a2de1d4 100644 --- a/apps/api/src/db/schema.ts +++ b/apps/api/src/db/schema.ts @@ -243,7 +243,7 @@ export const agentCredentialSetupSessions = sqliteTable( scope: text('scope').notNull().default('user'), // 'user' | 'project' agentType: text('agent_type').notNull(), credentialKind: text('credential_kind').notNull().default('oauth-token'), - /** creating|admitting|provisioning|waiting_for_user|capturing|saving|completed|failed|cancelled|expired */ + /** creating|admitting|provisioning|waiting_for_user|exchanging|capturing|saving|completed|failed|cancelled|expired */ status: text('status').notNull().default('creating'), /** Cloudflare Sandbox id (== setup session id, 1:1, never shared across users). */ sandboxId: text('sandbox_id').notNull(), @@ -265,7 +265,7 @@ export const agentCredentialSetupSessions = sqliteTable( oneActive: uniqueIndex('idx_acss_one_active') .on(table.userId, table.agentType) .where( - sql`status IN ('creating', 'admitting', 'provisioning', 'waiting_for_user', 'capturing', 'saving')` + sql`status IN ('creating', 'admitting', 'provisioning', 'waiting_for_user', 'exchanging', 'capturing', 'saving')` ), sweep: index('idx_acss_sweep').on(table.status, table.expiresAt), userLookup: index('idx_acss_user').on(table.userId, table.createdAt), From 98f1e0821af9e9d2d5a86d4aa6e9214043f70dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 26 Jul 2026 07:30:01 +0000 Subject: [PATCH 28/57] fix(api): wire Claude verification path into driver entrypoint --- apps/api/scripts/claude-setup-token.mjs | 34 +++++++++++-------- .../unit/scripts/claude-setup-token.test.ts | 24 +++++++++++++ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/apps/api/scripts/claude-setup-token.mjs b/apps/api/scripts/claude-setup-token.mjs index 3f3983e4c7..241c938984 100644 --- a/apps/api/scripts/claude-setup-token.mjs +++ b/apps/api/scripts/claude-setup-token.mjs @@ -305,24 +305,30 @@ export async function runClaudeSetupToken({ return ready; } -if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) { - const statePath = process.argv[2]; - const credentialPath = process.argv[3]; - const verificationCodePath = process.argv[4]; +export function runClaudeSetupTokenCli(argv = process.argv, runner = runClaudeSetupToken) { + const statePath = argv[2]; + const credentialPath = argv[3]; + const verificationCodePath = argv[4]; if (!statePath || !credentialPath || !verificationCodePath) { process.stderr.write( 'Usage: claude-setup-token.mjs \n' ); process.exitCode = 2; - } else { - runClaudeSetupToken({ - statePath, - credentialPath, - onSpawn: (claude) => { - process.once('SIGTERM', () => claude.kill('SIGTERM')); - }, - }).catch(() => { - process.exitCode = 1; - }); + return; } + + return runner({ + statePath, + credentialPath, + verificationCodePath, + onSpawn: (claude) => { + process.once('SIGTERM', () => claude.kill('SIGTERM')); + }, + }); +} + +if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) { + Promise.resolve(runClaudeSetupTokenCli()).catch(() => { + process.exitCode = 1; + }); } diff --git a/apps/api/tests/unit/scripts/claude-setup-token.test.ts b/apps/api/tests/unit/scripts/claude-setup-token.test.ts index b61c2dfb95..9ba737da17 100644 --- a/apps/api/tests/unit/scripts/claude-setup-token.test.ts +++ b/apps/api/tests/unit/scripts/claude-setup-token.test.ts @@ -7,6 +7,7 @@ import { extractClaudeSetupOutput, resolveClaudeSetupPaths, runClaudeSetupToken, + runClaudeSetupTokenCli, validateClaudeOauthToken, validateClaudeVerificationUrl, } from '../../../scripts/claude-setup-token.mjs'; @@ -145,6 +146,29 @@ describe('Claude setup-token driver', () => { ).toThrow(/must not resolve to the filesystem root/); }); + it('forwards all three executable arguments into the driver', async () => { + const runner = vi.fn().mockResolvedValue(undefined); + + await runClaudeSetupTokenCli( + [ + 'node', + 'claude-setup-token.mjs', + CLAUDE_STATE_PATH, + CLAUDE_CREDENTIAL_PATH, + CLAUDE_VERIFICATION_CODE_PATH, + ], + runner + ); + + expect(runner).toHaveBeenCalledWith( + expect.objectContaining({ + statePath: CLAUDE_STATE_PATH, + credentialPath: CLAUDE_CREDENTIAL_PATH, + verificationCodePath: CLAUDE_VERIFICATION_CODE_PATH, + }) + ); + }); + it('publishes non-secret actionable state and writes only the token to the credential file', async () => { const fake = fakeClaudeProcess(); const states: Array> = []; From c782f3c4fdb5564684ba609c3889009a6cee39f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 26 Jul 2026 07:49:52 +0000 Subject: [PATCH 29/57] fix(api): fail fast on rejected Claude verification codes --- apps/api/scripts/claude-setup-token.mjs | 8 +++++ .../unit/scripts/claude-setup-token.test.ts | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/apps/api/scripts/claude-setup-token.mjs b/apps/api/scripts/claude-setup-token.mjs index 241c938984..743718fde1 100644 --- a/apps/api/scripts/claude-setup-token.mjs +++ b/apps/api/scripts/claude-setup-token.mjs @@ -19,6 +19,7 @@ const CLAUDE_SETUP_COMMAND = 'stty cols 512; env DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=xterm-256color claude setup-token'; const URL_PATTERN = /https:\/\/[^\s<>'"`]+/gi; const TOKEN_PATTERN = /\bsk-ant-oat(?:[A-Za-z0-9._-]|\r?\n){16,8192}\b/g; +const OAUTH_REJECTION_PATTERN = /OAuth error:[\s\S]{0,256}status code\s*4\d\d/i; const CODE_PATTERNS = [ /(?:verification|one[- ]time|device)?\s*code[^A-Za-z0-9-]{0,40}([A-Z0-9][A-Z0-9-]{3,127})/i, /enter\s+(?:this\s+|the\s+)?(?:code\s+)?([A-Z0-9][A-Z0-9-]{3,127})/i, @@ -200,6 +201,7 @@ export async function runClaudeSetupToken({ onSpawn?.(claude); let publishedWaiting = false; + let verificationCodeForwarded = false; let tokenCaptured = false; let terminalStatePublished = false; let verificationCodePoll; @@ -249,6 +251,7 @@ export async function runClaudeSetupToken({ await deleteVerificationCode(setupPaths.verificationCodePath); clearInterval(verificationCodePoll); verificationCodePoll = undefined; + verificationCodeForwarded = true; claude.stdin.write(`${code.replace(/\s+/g, '')}\r`); } catch (error) { if (error?.code !== 'ENOENT') { @@ -287,6 +290,11 @@ export async function runClaudeSetupToken({ return; } maybePublishWaiting(details); + if (verificationCodeForwarded && OAUTH_REJECTION_PATTERN.test(stripAnsi(outputBuffer))) { + publishFailure('Claude rejected the verification code'); + claude.kill('SIGTERM'); + return; + } maybeCaptureToken(details); } diff --git a/apps/api/tests/unit/scripts/claude-setup-token.test.ts b/apps/api/tests/unit/scripts/claude-setup-token.test.ts index 9ba737da17..39e1a84644 100644 --- a/apps/api/tests/unit/scripts/claude-setup-token.test.ts +++ b/apps/api/tests/unit/scripts/claude-setup-token.test.ts @@ -220,6 +220,35 @@ describe('Claude setup-token driver', () => { expect(fake.kill).toHaveBeenCalledWith('SIGTERM'); }); + it('publishes a sanitized failure when Claude rejects a forwarded code but stays open', async () => { + const fake = fakeClaudeProcess(); + const states: Array> = []; + + const ready = runClaudeSetupToken({ + ...validSetupPaths(), + spawnProcess: () => fake, + writeState: async (state) => states.push(state), + writeCredential: vi.fn().mockResolvedValue(undefined), + readVerificationCode: vi.fn().mockResolvedValue('garbage#rejected-code'), + deleteVerificationCode: vi.fn().mockResolvedValue(undefined), + verificationCodePollMs: 1, + }); + + fake.stdout.write('Open https://claude.com/cai/oauth/authorize\n'); + await ready; + await vi.waitFor(() => expect(fake.stdin.read()?.toString()).toBe('garbage#rejected-code\r')); + fake.stdout.write('OAuth error: Request failed with status code 400\nPress Enter to retry.'); + + await vi.waitFor(() => + expect(states.at(-1)).toEqual({ + status: 'failed', + error: 'Claude rejected the verification code', + }) + ); + expect(JSON.stringify(states)).not.toContain('garbage#rejected-code'); + expect(fake.kill).toHaveBeenCalledWith('SIGTERM'); + }); + it('fails safely when the CLI exits before returning an OAuth token', async () => { const fake = fakeClaudeProcess(); const states: Array> = []; From 108392a44713e076979cd14150b94a64b15668e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 26 Jul 2026 08:17:37 +0000 Subject: [PATCH 30/57] docs(task): archive Claude guided login fix --- ...6-07-26-claude-guided-verification-code.md | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) rename tasks/{active => archive}/2026-07-26-claude-guided-verification-code.md (60%) diff --git a/tasks/active/2026-07-26-claude-guided-verification-code.md b/tasks/archive/2026-07-26-claude-guided-verification-code.md similarity index 60% rename from tasks/active/2026-07-26-claude-guided-verification-code.md rename to tasks/archive/2026-07-26-claude-guided-verification-code.md index 39ee72f6af..bafba3d54b 100644 --- a/tasks/active/2026-07-26-claude-guided-verification-code.md +++ b/tasks/archive/2026-07-26-claude-guided-verification-code.md @@ -36,47 +36,47 @@ the short-lived code. ## Implementation checklist -- [ ] Reuse the prior branch's route/service/UI plumbing but replace final-token +- [x] Reuse the prior branch's route/service/UI plumbing but replace final-token submission with short-lived verification-code submission. -- [ ] Pipe driver stdin, constrain the code-file path to setup home, poll it, +- [x] Pipe driver stdin, constrain the code-file path to setup home, poll it, delete it, and write the normalized code plus carriage return to the PTY. -- [ ] Harden URL/token parsing against PTY wrapping and publish sanitized +- [x] Harden URL/token parsing against PTY wrapping and publish sanitized failures when the CLI exits without a token. -- [ ] Add the `exchanging` state and DO `submitVerificationCode` guards, +- [x] Add the `exchanging` state and DO `submitVerificationCode` guards, normalization, bounds, charset (including `#`), sandbox write, and non-persistence guarantees. -- [ ] Read driver state during waiting/exchanging/capturing so rejection or exit +- [x] Read driver state during waiting/exchanging/capturing so rejection or exit fails fast instead of waiting for TTL. -- [ ] Expose owned-session `POST /:id/verification-code` without treating the +- [x] Expose owned-session `POST /:id/verification-code` without treating the short-lived code as a credential. -- [ ] Preserve strict server-side Claude OAuth-token validation and the existing +- [x] Preserve strict server-side Claude OAuth-token validation and the existing capture → encrypted save → teardown path. -- [ ] Update the modal with accurate code-paste copy, exchanging progress, +- [x] Update the modal with accurate code-paste copy, exchanging progress, visible failure, and restart affordance. -- [ ] Add driver, DO, route/DO/sandbox vertical-slice, UI behavioral, and +- [x] Add driver, DO, route/DO/sandbox vertical-slice, UI behavioral, and discriminating regression coverage. -- [ ] Run Playwright visual audits at 375px and 1280px. -- [ ] Run full validation and all required specialist reviews. -- [ ] Deploy the branch to staging and verify provisioning, URL surfacing, +- [x] Run Playwright visual audits at 375px and 1280px. +- [x] Run full validation and all required specialist reviews. +- [x] Deploy the branch to staging and verify provisioning, URL surfacing, sandbox delivery, rejected-code fast failure, and complete cleanup. -- [ ] Open a PR, make every CI check green, and leave it unmerged for Raphaël's +- [x] Open a PR, make every CI check green, and leave it unmerged for Raphaël's real Claude subscription E2E. ## Acceptance criteria -- [ ] The browser submits only a bounded short-lived verification code; the +- [x] The browser submits only a bounded short-lived verification code; the long-lived token never crosses the browser boundary. -- [ ] A `code#state` value with copied whitespace artifacts reaches the CLI as +- [x] A `code#state` value with copied whitespace artifacts reaches the CLI as exact normalized bytes followed by `\r`. -- [ ] Invalid codes and premature CLI exits become prompt, sanitized failures. -- [ ] Wrapped terminal output cannot cause a truncated OAuth token to be saved. -- [ ] Automated coverage proves the full route → DO → sandbox → captured token +- [x] Invalid codes and premature CLI exits become prompt, sanitized failures. +- [x] Wrapped terminal output cannot cause a truncated OAuth token to be saved. +- [x] Automated coverage proves the full route → DO → sandbox → captured token → credential save path with realistic state and exact sandbox writes. -- [ ] Mobile and desktop UI are accessible, legible, and free of horizontal +- [x] Mobile and desktop UI are accessible, legible, and free of horizontal overflow. -- [ ] Staging has no orphan guided-login sandbox or pool lease after success or +- [x] Staging has no orphan guided-login sandbox or pool lease after success or failure cleanup. -- [ ] PR is open, all checks including SonarCloud and Preflight Evidence pass, +- [x] PR is open, all checks including SonarCloud and Preflight Evidence pass, staging remains deployed from the feature branch, and the PR is not merged. @@ -89,3 +89,11 @@ the short-lived code. - - anthropics/claude-code issues #47773 and #47699 + +## Completion evidence + +- PR: https://github.com/raphaeltm/simple-agent-manager/pull/1678 (open, unmerged) +- Final staging deploy: https://github.com/raphaeltm/simple-agent-manager/actions/runs/30193502104 (`c3505f311`, success) +- Live no-account verification: session `01KYEQ1PNJVAADQPMXMMG4FX1V` surfaced a trusted Claude URL in 12.5s, accepted a `code#state`-shaped rejected value, and surfaced sanitized `code_rejected` in 5.0s; cleanup returned 200 and D1 had zero active setup rows. +- CI: all applicable checks green, including Test, Playwright Visual Tests, SonarCloud, Preflight Evidence, and Specialist Review Evidence. +- Remaining explicit human gate: Raphaël must complete the successful OAuth exchange on staging with his real Claude subscription before merge. From 2b7e900ce02a662b13437379f99f415c8600e838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 26 Jul 2026 09:53:55 +0000 Subject: [PATCH 31/57] fix(api): submit Claude verification code as paste plus separate Enter The Claude Code prompt treats one large stdin chunk as a paste and absorbs an inline trailing carriage return: realistic ~100-char codes were typed into the field but never submitted, so the guided login sat in 'exchanging' until the session TTL (reproduced against claude v2.1.220; 21-char test codes submit, which is why staging verification passed). Write the code, then send Enter as a separate write after a settle delay. Also fail visibly instead of stalling: any post-forward 'OAuth error:' screen is terminal (the previous pattern required a 'status code 4xx' wording that 401/state-mismatch/network failures never print), and a bounded exchange deadline reports 'exchange_timeout' distinctly through the DO when the CLI produces no recognizable outcome. Both knobs are env-configurable (CLAUDE_SETUP_ENTER_DELAY_MS, CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS). Co-Authored-By: Claude Fable 5 --- apps/api/scripts/claude-setup-token.mjs | 67 +++++++++- .../credential-setup-session/index.ts | 29 ++-- apps/api/src/env.ts | 2 + .../credential-setup-session.test.ts | 37 +++++ .../unit/scripts/claude-setup-token.test.ts | 126 +++++++++++++++++- 5 files changed, 241 insertions(+), 20 deletions(-) diff --git a/apps/api/scripts/claude-setup-token.mjs b/apps/api/scripts/claude-setup-token.mjs index 743718fde1..d35457f3aa 100644 --- a/apps/api/scripts/claude-setup-token.mjs +++ b/apps/api/scripts/claude-setup-token.mjs @@ -19,7 +19,19 @@ const CLAUDE_SETUP_COMMAND = 'stty cols 512; env DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=xterm-256color claude setup-token'; const URL_PATTERN = /https:\/\/[^\s<>'"`]+/gi; const TOKEN_PATTERN = /\bsk-ant-oat(?:[A-Za-z0-9._-]|\r?\n){16,8192}\b/g; -const OAUTH_REJECTION_PATTERN = /OAuth error:[\s\S]{0,256}status code\s*4\d\d/i; +// The Ink error screen always renders `OAuth error: ` and then waits for a +// retry keypress without exiting — treat ANY such marker after the code was +// forwarded as terminal. Requiring a specific status-code suffix here made real +// failures (401 "Authentication failed", state mismatch, network errors) hang +// until the session TTL. +const OAUTH_REJECTION_PATTERN = /OAuth error:/i; +const DEFAULT_VERIFICATION_ENTER_DELAY_MS = 1000; +const DEFAULT_EXCHANGE_TIMEOUT_MS = 120_000; + +function positiveIntFromEnv(name, fallback) { + const value = Number(process.env[name]); + return Number.isFinite(value) && value > 0 ? value : fallback; +} const CODE_PATTERNS = [ /(?:verification|one[- ]time|device)?\s*code[^A-Za-z0-9-]{0,40}([A-Z0-9][A-Z0-9-]{3,127})/i, /enter\s+(?:this\s+|the\s+)?(?:code\s+)?([A-Z0-9][A-Z0-9-]{3,127})/i, @@ -169,6 +181,14 @@ export async function runClaudeSetupToken({ readVerificationCode = (path) => readFile(path, 'utf8'), deleteVerificationCode = unlink, verificationCodePollMs = 500, + verificationEnterDelayMs = positiveIntFromEnv( + 'CLAUDE_SETUP_ENTER_DELAY_MS', + DEFAULT_VERIFICATION_ENTER_DELAY_MS + ), + exchangeTimeoutMs = positiveIntFromEnv( + 'CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS', + DEFAULT_EXCHANGE_TIMEOUT_MS + ), }) { const setupPaths = resolveClaudeSetupPaths({ statePath, credentialPath, verificationCodePath }); const writeStateFile = @@ -205,6 +225,8 @@ export async function runClaudeSetupToken({ let tokenCaptured = false; let terminalStatePublished = false; let verificationCodePoll; + let verificationEnterTimer; + let exchangeDeadlineTimer; let outputBuffer = ''; let stateWriteQueue = Promise.resolve(); let settled = false; @@ -230,11 +252,22 @@ export async function runClaudeSetupToken({ return stateWriteQueue; } - function publishFailure(message) { + function clearForwardingTimers() { if (verificationCodePoll) clearInterval(verificationCodePoll); - void publishState({ status: 'failed', error: message }).finally(() => { - settleReady(new Error(message)); - }); + verificationCodePoll = undefined; + if (verificationEnterTimer) clearTimeout(verificationEnterTimer); + verificationEnterTimer = undefined; + if (exchangeDeadlineTimer) clearTimeout(exchangeDeadlineTimer); + exchangeDeadlineTimer = undefined; + } + + function publishFailure(message, code) { + clearForwardingTimers(); + void publishState({ status: 'failed', error: message, ...(code ? { code } : {}) }).finally( + () => { + settleReady(new Error(message)); + } + ); } function maybePublishWaiting(details) { @@ -252,7 +285,27 @@ export async function runClaudeSetupToken({ clearInterval(verificationCodePoll); verificationCodePoll = undefined; verificationCodeForwarded = true; - claude.stdin.write(`${code.replace(/\s+/g, '')}\r`); + // Claude Code's interactive prompt treats one large stdin chunk as a + // paste and absorbs a trailing carriage return instead of submitting + // (reproduced with ~100-char real codes; short test codes submit). + // Write the code, then send Enter as a SEPARATE write after a settle + // delay so the CLI registers a real submit keypress. + claude.stdin.write(code.replace(/\s+/g, '')); + verificationEnterTimer = setTimeout(() => { + verificationEnterTimer = undefined; + claude.stdin.write('\r'); + // The exchange is a bounded HTTP round-trip: any outcome the parser + // does not recognize (unknown error wording, hung request) must fail + // visibly instead of stalling until the session TTL. + exchangeDeadlineTimer = setTimeout(() => { + exchangeDeadlineTimer = undefined; + publishFailure( + 'Claude did not finish the verification code exchange in time', + 'exchange_timeout' + ); + claude.kill('SIGTERM'); + }, exchangeTimeoutMs); + }, verificationEnterDelayMs); } catch (error) { if (error?.code !== 'ENOENT') { publishFailure('Claude verification code could not be forwarded'); @@ -267,7 +320,7 @@ export async function runClaudeSetupToken({ function maybeCaptureToken(details) { if (tokenCaptured || !details.token) return; tokenCaptured = true; - if (verificationCodePoll) clearInterval(verificationCodePoll); + clearForwardingTimers(); void writeCredentialFile(details.token) .then(() => publishState({ status: 'completed' })) .then(() => settleReady()) diff --git a/apps/api/src/durable-objects/credential-setup-session/index.ts b/apps/api/src/durable-objects/credential-setup-session/index.ts index 5e22ccfc00..f442a571d6 100644 --- a/apps/api/src/durable-objects/credential-setup-session/index.ts +++ b/apps/api/src/durable-objects/credential-setup-session/index.ts @@ -120,6 +120,8 @@ interface DeviceAuthState { verificationUrl?: string; userCode?: string; error?: string | null; + /** Optional machine-readable failure class from the driver (e.g. `exchange_timeout`). */ + code?: string; } export class CredentialSetupSession extends DurableObject { @@ -333,14 +335,16 @@ export class CredentialSetupSession extends DurableObject { // waiting_for_user | exchanging | capturing — observe driver failure and capture output. const driverState = await this.readDeviceAuthState(row); if (driverState?.status === 'failed') { - await this.teardown( - row, - 'failed', - row.status === 'exchanging' ? 'code_rejected' : 'setup_failed', - row.status === 'exchanging' - ? 'Claude rejected the verification code. Start again and use a fresh code.' - : 'Claude Code could not complete sign-in' - ); + const exchangeTimedOut = driverState.code === 'exchange_timeout'; + let errorCode = 'setup_failed'; + let errorMessage = 'Claude Code could not complete sign-in'; + if (row.status === 'exchanging') { + errorCode = exchangeTimedOut ? 'exchange_timeout' : 'code_rejected'; + errorMessage = exchangeTimedOut + ? 'Claude sign-in did not complete in time. Start again and paste a fresh code.' + : 'Claude rejected the verification code. Start again and use a fresh code.'; + } + await this.teardown(row, 'failed', errorCode, errorMessage); return; } await this.attemptCapture(row); @@ -408,9 +412,16 @@ export class CredentialSetupSession extends DurableObject { if (row.agent_type === 'claude-code') { const credentialPath = `${row.codex_home}/${CLAUDE_OAUTH_TOKEN_FILE}`; const verificationCodePath = `${row.codex_home}/${CLAUDE_VERIFICATION_CODE_FILE}`; + const enterDelayEnv = this.env.CLAUDE_SETUP_ENTER_DELAY_MS + ? ` CLAUDE_SETUP_ENTER_DELAY_MS=${shellQuote(this.env.CLAUDE_SETUP_ENTER_DELAY_MS)}` + : ''; + const exchangeTimeoutEnv = this.env.CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS + ? ` CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS=${shellQuote(this.env.CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS)}` + : ''; return ( `nohup env CLAUDE_CONFIG_DIR=${shellQuote(row.codex_home)} ` + - 'DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=dumb ' + + 'DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=dumb' + + `${enterDelayEnv}${exchangeTimeoutEnv} ` + `node /usr/local/bin/sam-claude-setup-token.mjs ${shellQuote(statePath)} ` + `${shellQuote(credentialPath)} ${shellQuote(verificationCodePath)} >/dev/null 2>&1 &` ); diff --git a/apps/api/src/env.ts b/apps/api/src/env.ts index d37be00a1e..7c3282c694 100644 --- a/apps/api/src/env.ts +++ b/apps/api/src/env.ts @@ -138,6 +138,8 @@ export interface Env extends WebhookTriggerEnv, TaskRecoveryEnv { SETUP_SESSION_TTL_MS?: string; // Setup session lifetime in ms before auto-teardown (default: 900000 = 15 min) SETUP_SESSION_CAPTURE_POLL_MS?: string; // credential capture poll interval in ms (default: 3000) CODEX_DEVICE_AUTH_REQUEST_TIMEOUT_MS?: string; // App-server JSON-RPC request timeout in ms (default: 30000) + CLAUDE_SETUP_ENTER_DELAY_MS?: string; // Claude guided-login: delay before the separate Enter keypress after pasting the code into the sandboxed CLI (default: 1000) + CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS?: string; // Claude guided-login: max wait for the CLI code exchange after submission before failing visibly (default: 120000) SETUP_SESSION_SWEEP_MAX_CANDIDATES?: string; // Max expired sessions torn down per cron sweep (default: 50) POOL_LEASE_BUFFER_MS?: string; // Grace beyond TTL before a leaked pool lease self-prunes (default: 300000 = 5 min) // Deployment signing keys (Ed25519 — separate from callback JWT) diff --git a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts index f04b593f96..2eb9d8831c 100644 --- a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts +++ b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts @@ -753,6 +753,43 @@ describe('CredentialSetupSession — alarm() capture polling', () => { expect(releaseSetupSlot).toHaveBeenCalledWith(expect.anything(), 'lease-abc'); }); + it('reports a driver exchange timeout distinctly from a rejected code', async () => { + const created = createDO(); + await Promise.resolve(); + let driverState: Record = { + status: 'waiting_for_user', + verificationUrl: 'https://claude.ai/oauth/device', + }; + const fakeSandbox = createFakeSandbox(); + fakeSandbox.readFile.mockImplementation(async (path: string) => ({ + content: path.endsWith('device-auth-state.json') ? JSON.stringify(driverState) : '', + })); + vi.mocked(getSandboxInstance).mockResolvedValue(fakeSandbox as never); + await created.instance.create({ + id: 'setup-exchange-timeout', + setupHome: '/tmp/setup-exchange-timeout', + ttlMs: 900_000, + ...BASE_PARAMS, + agentType: 'claude-code', + provider: 'anthropic', + agentName: 'Claude Code', + }); + await created.instance.alarm(); + await created.instance.alarm(); + await created.instance.submitVerificationCode('abc123#state456'); + driverState = { + status: 'failed', + error: 'Claude did not finish the verification code exchange in time', + code: 'exchange_timeout', + }; + await created.instance.alarm(); + + const state = await created.instance.getState(); + expect(state).toMatchObject({ status: 'failed', errorCode: 'exchange_timeout' }); + expect(state?.errorMessage).toContain('did not complete in time'); + expect(releaseSetupSlot).toHaveBeenCalledWith(expect.anything(), 'lease-abc'); + }); + it('tears down as failed when saveAgentCredentialForUser rejects', async () => { const { instance, database, fakeSandbox } = await createAndProvision(); const authJson = validAuthJson(); diff --git a/apps/api/tests/unit/scripts/claude-setup-token.test.ts b/apps/api/tests/unit/scripts/claude-setup-token.test.ts index 39e1a84644..579d53af10 100644 --- a/apps/api/tests/unit/scripts/claude-setup-token.test.ts +++ b/apps/api/tests/unit/scripts/claude-setup-token.test.ts @@ -188,6 +188,7 @@ describe('Claude setup-token driver', () => { readVerificationCode: vi.fn().mockResolvedValue(' abc 123#state\n'), deleteVerificationCode: vi.fn().mockResolvedValue(undefined), verificationCodePollMs: 1, + verificationEnterDelayMs: 1, }); expect(spawnedCommand).toBe('script'); @@ -209,9 +210,12 @@ describe('Claude setup-token driver', () => { }, ]); expect(JSON.stringify(states)).not.toContain(CLAUDE_TOKEN); - const stdinBytes: Buffer[] = []; - fake.stdin.on('data', (chunk) => stdinBytes.push(Buffer.from(chunk))); - await vi.waitFor(() => expect(Buffer.concat(stdinBytes).toString()).toBe('abc123#state\r')); + // The code and the Enter keypress MUST be separate stdin writes: Claude + // Code's prompt treats one large chunk as a paste and absorbs an inline + // trailing \r, leaving the code typed but never submitted. + const stdinWrites: string[] = []; + fake.stdin.on('data', (chunk) => stdinWrites.push(chunk.toString())); + await vi.waitFor(() => expect(stdinWrites).toEqual(['abc123#state', '\r'])); fake.stdout.write(`Your token: ${CLAUDE_TOKEN}\n`); await vi.waitFor(() => expect(credentials).toEqual([CLAUDE_TOKEN])); @@ -232,11 +236,14 @@ describe('Claude setup-token driver', () => { readVerificationCode: vi.fn().mockResolvedValue('garbage#rejected-code'), deleteVerificationCode: vi.fn().mockResolvedValue(undefined), verificationCodePollMs: 1, + verificationEnterDelayMs: 1, }); fake.stdout.write('Open https://claude.com/cai/oauth/authorize\n'); await ready; - await vi.waitFor(() => expect(fake.stdin.read()?.toString()).toBe('garbage#rejected-code\r')); + const stdinWrites: string[] = []; + fake.stdin.on('data', (chunk) => stdinWrites.push(chunk.toString())); + await vi.waitFor(() => expect(stdinWrites).toEqual(['garbage#rejected-code', '\r'])); fake.stdout.write('OAuth error: Request failed with status code 400\nPress Enter to retry.'); await vi.waitFor(() => @@ -249,6 +256,117 @@ describe('Claude setup-token driver', () => { expect(fake.kill).toHaveBeenCalledWith('SIGTERM'); }); + it('submits realistic-length codes even though the CLI paste widget absorbs an inline carriage return', async () => { + // Discriminating regression for the 2026-07-26 production hang: model the + // real Claude Code prompt, which inserts a large single chunk as pasted + // TEXT (an inline trailing \r is absorbed, not executed) and only submits + // on a subsequent standalone Enter keypress. The pre-fix driver (one + // `code\r` write) never submits here and this test times out. + const fake = fakeClaudeProcess(); + const states: Array> = []; + const realisticCode = `${'A'.repeat(60)}#${'B'.repeat(43)}`; + let pastedBuffer = ''; + + fake.stdin.on('data', (chunk) => { + const text = chunk.toString(); + if (text === '\r' && pastedBuffer.length > 0) { + // Standalone Enter after pasted text: the CLI submits and the exchange + // fails upstream (invalid test code), rendering the Ink error screen. + fake.stdout.write('OAuth error: Request failed with status code 400\nPress Enter to retry.'); + return; + } + // Large chunk (with or without inline \r): inserted as text, not submitted. + pastedBuffer += text.replace(/\r/g, ''); + }); + + const ready = runClaudeSetupToken({ + ...validSetupPaths(), + spawnProcess: () => fake, + writeState: async (state) => states.push(state), + writeCredential: vi.fn().mockResolvedValue(undefined), + readVerificationCode: vi.fn().mockResolvedValue(realisticCode), + deleteVerificationCode: vi.fn().mockResolvedValue(undefined), + verificationCodePollMs: 1, + verificationEnterDelayMs: 5, + }); + + fake.stdout.write('Open https://claude.com/cai/oauth/authorize\n'); + await ready; + + await vi.waitFor(() => + expect(states.at(-1)).toEqual({ + status: 'failed', + error: 'Claude rejected the verification code', + }) + ); + expect(pastedBuffer).toBe(realisticCode); + expect(fake.kill).toHaveBeenCalledWith('SIGTERM'); + }); + + it('treats any post-forward OAuth error screen as terminal, not only status-code wordings', async () => { + const fake = fakeClaudeProcess(); + const states: Array> = []; + + const ready = runClaudeSetupToken({ + ...validSetupPaths(), + spawnProcess: () => fake, + writeState: async (state) => states.push(state), + writeCredential: vi.fn().mockResolvedValue(undefined), + readVerificationCode: vi.fn().mockResolvedValue('expired#code'), + deleteVerificationCode: vi.fn().mockResolvedValue(undefined), + verificationCodePollMs: 1, + verificationEnterDelayMs: 1, + }); + + fake.stdout.write('Open https://claude.com/cai/oauth/authorize\n'); + await ready; + const stdinWrites: string[] = []; + fake.stdin.on('data', (chunk) => stdinWrites.push(chunk.toString())); + await vi.waitFor(() => expect(stdinWrites).toEqual(['expired#code', '\r'])); + // Real 401 wording from claude v2.1.220 — contains no "status code" suffix. + fake.stdout.write( + 'OAuth error: Authentication failed: Invalid authorization code\nPress Enter to retry.' + ); + + await vi.waitFor(() => + expect(states.at(-1)).toEqual({ + status: 'failed', + error: 'Claude rejected the verification code', + }) + ); + expect(fake.kill).toHaveBeenCalledWith('SIGTERM'); + }); + + it('fails fast with exchange_timeout when the exchange produces no recognizable outcome', async () => { + const fake = fakeClaudeProcess(); + const states: Array> = []; + + runClaudeSetupToken({ + ...validSetupPaths(), + spawnProcess: () => fake, + writeState: async (state) => states.push(state), + writeCredential: vi.fn().mockResolvedValue(undefined), + readVerificationCode: vi.fn().mockResolvedValue('hung#exchange'), + deleteVerificationCode: vi.fn().mockResolvedValue(undefined), + verificationCodePollMs: 1, + verificationEnterDelayMs: 1, + exchangeTimeoutMs: 25, + }); + + fake.stdout.write('Open https://claude.com/cai/oauth/authorize\n'); + // The CLI accepts the code + Enter and then goes silent (hung request, + // unknown error wording, dead spinner): the driver must not stall until the + // session TTL. + await vi.waitFor(() => + expect(states.at(-1)).toEqual({ + status: 'failed', + error: 'Claude did not finish the verification code exchange in time', + code: 'exchange_timeout', + }) + ); + expect(fake.kill).toHaveBeenCalledWith('SIGTERM'); + }); + it('fails safely when the CLI exits before returning an OAuth token', async () => { const fake = fakeClaudeProcess(); const states: Array> = []; From 494ac8ca60750bcd5dba21daeca7137b02439b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Mon, 27 Jul 2026 05:48:42 +0000 Subject: [PATCH 32/57] fix: classify Claude guided-login exchange failures and surface CLI detail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The driver flattened every post-forward 'OAuth error:' render into 'Claude rejected the verification code', discarding the CLI line that distinguishes an incomplete paste (missing #state half — instant local failure), a server rejection (status-code wording), and a sandbox network failure. Reproduced each wording live against claude v2.1.220; renders arrive with characters dropped by Ink redraws, so classification tolerates that mangling. - driver: extract the last OAuth error line after a settle window (CLAUDE_SETUP_REJECTION_SETTLE_MS, default 400ms), redact token-like runs, classify into code_incomplete / code_rejected / exchange_network_error, and publish a bounded detail field alongside the failure state - DO: map the new failure classes to accurate guidance and append the sanitized detail as '[CLI: ...]' (printable ASCII, capped, sk-ant redacted); the driver's free-form error field is still never surfaced - modal: block a claude-code paste missing its '#' half before burning the setup session, with copy-the-entire-code guidance Verified end-to-end against the real CLI: no-# paste -> code_incomplete with the CLI's own 'full code was copied' advice; full-format fake code -> code_rejected with 'status code 400' detail. Co-Authored-By: Claude Fable 5 --- apps/api/scripts/claude-setup-token.mjs | 102 +++++++++++++-- .../credential-setup-session/index.ts | 54 +++++++- .../credential-setup-session.test.ts | 63 +++++++++ .../unit/scripts/claude-setup-token.test.ts | 121 ++++++++++++++++++ apps/web/src/components/CodexConnectModal.tsx | 9 ++ .../components/CodexConnectModal.test.tsx | 36 ++++++ 6 files changed, 370 insertions(+), 15 deletions(-) diff --git a/apps/api/scripts/claude-setup-token.mjs b/apps/api/scripts/claude-setup-token.mjs index d35457f3aa..6d49ecdece 100644 --- a/apps/api/scripts/claude-setup-token.mjs +++ b/apps/api/scripts/claude-setup-token.mjs @@ -25,8 +25,21 @@ const TOKEN_PATTERN = /\bsk-ant-oat(?:[A-Za-z0-9._-]|\r?\n){16,8192}\b/g; // failures (401 "Authentication failed", state mismatch, network errors) hang // until the session TTL. const OAUTH_REJECTION_PATTERN = /OAuth error:/i; +// Ink redraws overwrite characters in place, so the surviving text can drop +// letters and spaces ("Requstfailed withstatus code 400"). Classification +// patterns must tolerate that mangling — match with optional gaps, never on +// exact prose. +const OAUTH_ERROR_LINE_PATTERN = /OAuth error:\s*([^\n\r]*)/gi; +const OAUTH_RETRY_SUFFIX_PATTERN = /Press\s*Enter\s*to\s*retry.*$/i; +const OAUTH_INCOMPLETE_CODE_PATTERN = /invalid\s*c\w{0,3}de/i; +const OAUTH_STATUS_CODE_PATTERN = /status\s*code\s*(\d{3})/i; +const OAUTH_NETWORK_ERROR_PATTERN = + /(ECONN|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|EHOSTUNREACH|ENETUNREACH|getaddrinfo|socket|network|fetch\s*fail|tunnel|conn\w{0,4}ion|CONNECT\s*response)/i; +const SECRET_LIKE_PATTERN = /sk-ant[A-Za-z0-9._-]*/gi; +const MAX_OAUTH_ERROR_DETAIL_LENGTH = 160; const DEFAULT_VERIFICATION_ENTER_DELAY_MS = 1000; const DEFAULT_EXCHANGE_TIMEOUT_MS = 120_000; +const DEFAULT_REJECTION_SETTLE_MS = 400; function positiveIntFromEnv(name, fallback) { const value = Number(process.env[name]); @@ -170,6 +183,54 @@ export function extractClaudeSetupOutput(raw) { return { verificationUrl, userCode, token }; } +/** + * Pull the last rendered `OAuth error: ` line out of the (ANSI-stripped) + * CLI output and reduce it to a short, non-secret diagnostic. The wording is the + * only signal distinguishing an incomplete paste, a server 4xx, and a sandbox + * network failure — discarding it turns every failure into "code rejected". + */ +export function extractOauthErrorDetail(text) { + let lastLine; + OAUTH_ERROR_LINE_PATTERN.lastIndex = 0; + for (const match of text.matchAll(OAUTH_ERROR_LINE_PATTERN)) { + if (match[1]) lastLine = match[1]; + } + if (!lastLine) return null; + const detail = lastLine + .replace(OAUTH_RETRY_SUFFIX_PATTERN, '') + .replace(SECRET_LIKE_PATTERN, '[redacted]') + .replace(new RegExp(CONTROL_CHARACTER_PATTERN.source, 'g'), ' ') + .replace(/\s+/g, ' ') + .trim() + .slice(0, MAX_OAUTH_ERROR_DETAIL_LENGTH); + return detail || null; +} + +/** + * Classify an OAuth error line into a machine-readable failure class so the + * control plane can give accurate guidance instead of always claiming the code + * was rejected. + */ +export function classifyOauthError(detail) { + const text = detail ?? ''; + if (OAUTH_INCOMPLETE_CODE_PATTERN.test(text)) { + return { + code: 'code_incomplete', + message: 'Claude reported the pasted verification code was incomplete', + }; + } + if (OAUTH_STATUS_CODE_PATTERN.test(text)) { + return { code: 'code_rejected', message: 'Claude rejected the verification code' }; + } + if (OAUTH_NETWORK_ERROR_PATTERN.test(text)) { + return { + code: 'exchange_network_error', + message: 'Claude sign-in failed with a network error during the code exchange', + }; + } + return { code: 'code_rejected', message: 'Claude rejected the verification code' }; +} + export async function runClaudeSetupToken({ statePath, credentialPath, @@ -189,6 +250,10 @@ export async function runClaudeSetupToken({ 'CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS', DEFAULT_EXCHANGE_TIMEOUT_MS ), + rejectionSettleMs = positiveIntFromEnv( + 'CLAUDE_SETUP_REJECTION_SETTLE_MS', + DEFAULT_REJECTION_SETTLE_MS + ), }) { const setupPaths = resolveClaudeSetupPaths({ statePath, credentialPath, verificationCodePath }); const writeStateFile = @@ -227,6 +292,7 @@ export async function runClaudeSetupToken({ let verificationCodePoll; let verificationEnterTimer; let exchangeDeadlineTimer; + let rejectionSettleTimer; let outputBuffer = ''; let stateWriteQueue = Promise.resolve(); let settled = false; @@ -259,15 +325,20 @@ export async function runClaudeSetupToken({ verificationEnterTimer = undefined; if (exchangeDeadlineTimer) clearTimeout(exchangeDeadlineTimer); exchangeDeadlineTimer = undefined; + if (rejectionSettleTimer) clearTimeout(rejectionSettleTimer); + rejectionSettleTimer = undefined; } - function publishFailure(message, code) { + function publishFailure(message, code, detail) { clearForwardingTimers(); - void publishState({ status: 'failed', error: message, ...(code ? { code } : {}) }).finally( - () => { - settleReady(new Error(message)); - } - ); + void publishState({ + status: 'failed', + error: message, + ...(code ? { code } : {}), + ...(detail ? { detail } : {}), + }).finally(() => { + settleReady(new Error(message)); + }); } function maybePublishWaiting(details) { @@ -343,9 +414,22 @@ export async function runClaudeSetupToken({ return; } maybePublishWaiting(details); - if (verificationCodeForwarded && OAUTH_REJECTION_PATTERN.test(stripAnsi(outputBuffer))) { - publishFailure('Claude rejected the verification code'); - claude.kill('SIGTERM'); + if ( + verificationCodeForwarded && + !rejectionSettleTimer && + OAUTH_REJECTION_PATTERN.test(stripAnsi(outputBuffer)) + ) { + // The error screen can arrive across several PTY chunks; wait one settle + // window so the captured detail is the complete rendered line, then + // classify it so the control plane can distinguish an incomplete paste, + // a server rejection, and a sandbox network failure. + rejectionSettleTimer = setTimeout(() => { + rejectionSettleTimer = undefined; + const detail = extractOauthErrorDetail(stripAnsi(outputBuffer)); + const { code, message } = classifyOauthError(detail); + publishFailure(message, code, detail); + claude.kill('SIGTERM'); + }, rejectionSettleMs); return; } maybeCaptureToken(details); diff --git a/apps/api/src/durable-objects/credential-setup-session/index.ts b/apps/api/src/durable-objects/credential-setup-session/index.ts index f442a571d6..4622e672c7 100644 --- a/apps/api/src/durable-objects/credential-setup-session/index.ts +++ b/apps/api/src/durable-objects/credential-setup-session/index.ts @@ -122,6 +122,26 @@ interface DeviceAuthState { error?: string | null; /** Optional machine-readable failure class from the driver (e.g. `exchange_timeout`). */ code?: string; + /** Optional short diagnostic extracted from the provider CLI's error screen. */ + detail?: string | null; +} + +/** + * The driver state file is written inside the sandbox, so treat its diagnostic + * text as untrusted: printable ASCII only, secrets redacted, hard length cap. + * The driver's free-form `error` field is never surfaced — only this bounded + * detail — mirroring the sanitized-failure posture of the existing mapping. + */ +const MAX_DRIVER_DETAIL_LENGTH = 160; +function sanitizeDriverDetail(detail: string | null | undefined): string | null { + if (typeof detail !== 'string') return null; + const cleaned = detail + .replace(/sk-ant[A-Za-z0-9._-]*/gi, '[redacted]') + .replace(/[^\x20-\x7e]+/g, ' ') + .replace(/\s+/g, ' ') + .trim() + .slice(0, MAX_DRIVER_DETAIL_LENGTH); + return cleaned.length > 0 ? cleaned : null; } export class CredentialSetupSession extends DurableObject { @@ -335,16 +355,38 @@ export class CredentialSetupSession extends DurableObject { // waiting_for_user | exchanging | capturing — observe driver failure and capture output. const driverState = await this.readDeviceAuthState(row); if (driverState?.status === 'failed') { - const exchangeTimedOut = driverState.code === 'exchange_timeout'; let errorCode = 'setup_failed'; let errorMessage = 'Claude Code could not complete sign-in'; if (row.status === 'exchanging') { - errorCode = exchangeTimedOut ? 'exchange_timeout' : 'code_rejected'; - errorMessage = exchangeTimedOut - ? 'Claude sign-in did not complete in time. Start again and paste a fresh code.' - : 'Claude rejected the verification code. Start again and use a fresh code.'; + switch (driverState.code) { + case 'exchange_timeout': + errorCode = 'exchange_timeout'; + errorMessage = + 'Claude sign-in did not complete in time. Start again and paste a fresh code.'; + break; + case 'code_incomplete': + errorCode = 'code_incomplete'; + errorMessage = + 'The pasted code was incomplete. Copy the entire code Claude shows — it has a # in the middle — then start again.'; + break; + case 'exchange_network_error': + errorCode = 'exchange_network_error'; + errorMessage = + 'The sign-in sandbox hit a network error talking to Claude. Start again in a moment.'; + break; + default: + errorCode = 'code_rejected'; + errorMessage = + 'Claude rejected the verification code. Start again and use a fresh code.'; + } } - await this.teardown(row, 'failed', errorCode, errorMessage); + const detail = sanitizeDriverDetail(driverState.detail); + await this.teardown( + row, + 'failed', + errorCode, + detail ? `${errorMessage} [CLI: ${detail}]` : errorMessage + ); return; } await this.attemptCapture(row); diff --git a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts index 2eb9d8831c..6fdb7e5415 100644 --- a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts +++ b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts @@ -790,6 +790,69 @@ describe('CredentialSetupSession — alarm() capture polling', () => { expect(releaseSetupSlot).toHaveBeenCalledWith(expect.anything(), 'lease-abc'); }); + it('maps incomplete-paste and network driver failures distinctly and surfaces sanitized CLI detail', async () => { + const scenarios = [ + { + id: 'setup-incomplete', + driver: { + status: 'failed', + error: 'Claude reported the pasted verification code was incomplete', + code: 'code_incomplete', + detail: 'Invalidcode. Please makesure the fullcde wascopied', + }, + expectCode: 'code_incomplete', + expectMessage: 'entire code', + expectDetail: '[CLI: Invalidcode. Please makesure the fullcde wascopied]', + }, + { + id: 'setup-network', + driver: { + status: 'failed', + error: 'Claude sign-in failed with a network error during the code exchange', + code: 'exchange_network_error', + detail: `connctECONNREFUSED 10.0.0.1:443 sk-ant-oat${'A'.repeat(20)} junk`, + }, + expectCode: 'exchange_network_error', + expectMessage: 'network error', + expectDetail: '[CLI: connctECONNREFUSED 10.0.0.1:443 [redacted] junk]', + }, + ] as const; + + for (const scenario of scenarios) { + const created = createDO(); + await Promise.resolve(); + let driverState: Record = { + status: 'waiting_for_user', + verificationUrl: 'https://claude.ai/oauth/device', + }; + const fakeSandbox = createFakeSandbox(); + fakeSandbox.readFile.mockImplementation(async (path: string) => ({ + content: path.endsWith('device-auth-state.json') ? JSON.stringify(driverState) : '', + })); + vi.mocked(getSandboxInstance).mockResolvedValue(fakeSandbox as never); + await created.instance.create({ + id: scenario.id, + setupHome: `/tmp/${scenario.id}`, + ttlMs: 900_000, + ...BASE_PARAMS, + agentType: 'claude-code', + provider: 'anthropic', + agentName: 'Claude Code', + }); + await created.instance.alarm(); + await created.instance.alarm(); + await created.instance.submitVerificationCode('abc123#state456'); + driverState = scenario.driver; + await created.instance.alarm(); + + const state = await created.instance.getState(); + expect(state).toMatchObject({ status: 'failed', errorCode: scenario.expectCode }); + expect(state?.errorMessage).toContain(scenario.expectMessage); + expect(state?.errorMessage).toContain(scenario.expectDetail); + expect(state?.errorMessage).not.toContain('sk-ant'); + } + }); + it('tears down as failed when saveAgentCredentialForUser rejects', async () => { const { instance, database, fakeSandbox } = await createAndProvision(); const authJson = validAuthJson(); diff --git a/apps/api/tests/unit/scripts/claude-setup-token.test.ts b/apps/api/tests/unit/scripts/claude-setup-token.test.ts index 579d53af10..d47dd512c7 100644 --- a/apps/api/tests/unit/scripts/claude-setup-token.test.ts +++ b/apps/api/tests/unit/scripts/claude-setup-token.test.ts @@ -4,7 +4,9 @@ import { PassThrough } from 'node:stream'; import { afterEach, describe, expect, it, vi } from 'vitest'; import { + classifyOauthError, extractClaudeSetupOutput, + extractOauthErrorDetail, resolveClaudeSetupPaths, runClaudeSetupToken, runClaudeSetupTokenCli, @@ -105,6 +107,39 @@ describe('Claude setup-token driver', () => { expect(() => validateClaudeOauthToken('sk-ant-api03-not-oauth')).toThrow(/invalid OAuth token/); }); + it('extracts the last OAuth error line, strips the retry suffix, and redacts token-like runs', () => { + expect( + extractOauthErrorDetail( + 'OAuth error: transient thing\nredraw\nOAuth error: Requstfailed withstatus code 400PressEntertoretry.' + ) + ).toBe('Requstfailed withstatus code 400'); + expect(extractOauthErrorDetail(`OAuth error: leaked ${CLAUDE_TOKEN} value`)).toBe( + 'leaked [redacted] value' + ); + expect(extractOauthErrorDetail(`OAuth error: ${'x'.repeat(500)}`)).toHaveLength(160); + expect(extractOauthErrorDetail('no marker at all')).toBeNull(); + }); + + it('classifies OAuth error wordings, tolerating Ink overwrite mangling', () => { + // Live-captured renders from claude v2.1.220 (characters dropped by redraws). + expect(classifyOauthError('Invalidcode. Please makesure the fullcde wascopied').code).toBe( + 'code_incomplete' + ); + expect(classifyOauthError('Requstfailed withstatus code 400').code).toBe('code_rejected'); + expect(classifyOauthError('Request failed with status code 429').code).toBe('code_rejected'); + expect(classifyOauthError('connctECONNREFUSED 127.0.0.1:9').code).toBe( + 'exchange_network_error' + ); + expect(classifyOauthError('Prxy conncion ended before receving CONNECT response').code).toBe( + 'exchange_network_error' + ); + // Server-side "Invalid authorization code" is a rejection, not an incomplete paste. + expect(classifyOauthError('Authentication failed: Invalid authorization code').code).toBe( + 'code_rejected' + ); + expect(classifyOauthError(null).code).toBe('code_rejected'); + }); + it('derives setup file paths from CLAUDE_CONFIG_DIR and rejects path escapes', async () => { vi.stubEnv('CLAUDE_CONFIG_DIR', CLAUDE_SETUP_HOME); @@ -237,6 +272,7 @@ describe('Claude setup-token driver', () => { deleteVerificationCode: vi.fn().mockResolvedValue(undefined), verificationCodePollMs: 1, verificationEnterDelayMs: 1, + rejectionSettleMs: 1, }); fake.stdout.write('Open https://claude.com/cai/oauth/authorize\n'); @@ -250,6 +286,8 @@ describe('Claude setup-token driver', () => { expect(states.at(-1)).toEqual({ status: 'failed', error: 'Claude rejected the verification code', + code: 'code_rejected', + detail: 'Request failed with status code 400', }) ); expect(JSON.stringify(states)).not.toContain('garbage#rejected-code'); @@ -288,6 +326,7 @@ describe('Claude setup-token driver', () => { deleteVerificationCode: vi.fn().mockResolvedValue(undefined), verificationCodePollMs: 1, verificationEnterDelayMs: 5, + rejectionSettleMs: 1, }); fake.stdout.write('Open https://claude.com/cai/oauth/authorize\n'); @@ -297,6 +336,8 @@ describe('Claude setup-token driver', () => { expect(states.at(-1)).toEqual({ status: 'failed', error: 'Claude rejected the verification code', + code: 'code_rejected', + detail: 'Request failed with status code 400', }) ); expect(pastedBuffer).toBe(realisticCode); @@ -316,6 +357,7 @@ describe('Claude setup-token driver', () => { deleteVerificationCode: vi.fn().mockResolvedValue(undefined), verificationCodePollMs: 1, verificationEnterDelayMs: 1, + rejectionSettleMs: 1, }); fake.stdout.write('Open https://claude.com/cai/oauth/authorize\n'); @@ -324,6 +366,9 @@ describe('Claude setup-token driver', () => { fake.stdin.on('data', (chunk) => stdinWrites.push(chunk.toString())); await vi.waitFor(() => expect(stdinWrites).toEqual(['expired#code', '\r'])); // Real 401 wording from claude v2.1.220 — contains no "status code" suffix. + // "Invalid authorization code" is a SERVER rejection and must NOT be + // classified as the local incomplete-paste error ("Invalid code. Please + // make sure the full code was copied"). fake.stdout.write( 'OAuth error: Authentication failed: Invalid authorization code\nPress Enter to retry.' ); @@ -332,6 +377,82 @@ describe('Claude setup-token driver', () => { expect(states.at(-1)).toEqual({ status: 'failed', error: 'Claude rejected the verification code', + code: 'code_rejected', + detail: 'Authentication failed: Invalid authorization code', + }) + ); + expect(fake.kill).toHaveBeenCalledWith('SIGTERM'); + }); + + it('classifies the local incomplete-paste error distinctly, tolerating Ink overwrite mangling', async () => { + // Reproduced live against claude v2.1.220: a code pasted WITHOUT its + // `#state` half fails instantly and locally with "Invalid code. Please + // make sure the full code was copied" — advice the driver previously + // swallowed, reporting "code rejected … use a fresh code" instead. The + // rendered line arrives with characters overwritten by Ink redraws. + const fake = fakeClaudeProcess(); + const states: Array> = []; + + const ready = runClaudeSetupToken({ + ...validSetupPaths(), + spawnProcess: () => fake, + writeState: async (state) => states.push(state), + writeCredential: vi.fn().mockResolvedValue(undefined), + readVerificationCode: vi.fn().mockResolvedValue('A'.repeat(64)), + deleteVerificationCode: vi.fn().mockResolvedValue(undefined), + verificationCodePollMs: 1, + verificationEnterDelayMs: 1, + rejectionSettleMs: 1, + }); + + fake.stdout.write('Open https://claude.com/cai/oauth/authorize\n'); + await ready; + const stdinWrites: string[] = []; + fake.stdin.on('data', (chunk) => stdinWrites.push(chunk.toString())); + await vi.waitFor(() => expect(stdinWrites).toEqual(['A'.repeat(64), '\r'])); + fake.stdout.write('OAuth error: Invalidcode. Please makesure the fullcde wascopiedPressEntertoretry.'); + + await vi.waitFor(() => + expect(states.at(-1)).toEqual({ + status: 'failed', + error: 'Claude reported the pasted verification code was incomplete', + code: 'code_incomplete', + detail: 'Invalidcode. Please makesure the fullcde wascopied', + }) + ); + expect(fake.kill).toHaveBeenCalledWith('SIGTERM'); + }); + + it('classifies connection failures as exchange_network_error, not a rejected code', async () => { + const fake = fakeClaudeProcess(); + const states: Array> = []; + + const ready = runClaudeSetupToken({ + ...validSetupPaths(), + spawnProcess: () => fake, + writeState: async (state) => states.push(state), + writeCredential: vi.fn().mockResolvedValue(undefined), + readVerificationCode: vi.fn().mockResolvedValue('real#code'), + deleteVerificationCode: vi.fn().mockResolvedValue(undefined), + verificationCodePollMs: 1, + verificationEnterDelayMs: 1, + rejectionSettleMs: 1, + }); + + fake.stdout.write('Open https://claude.com/cai/oauth/authorize\n'); + await ready; + const stdinWrites: string[] = []; + fake.stdin.on('data', (chunk) => stdinWrites.push(chunk.toString())); + await vi.waitFor(() => expect(stdinWrites).toEqual(['real#code', '\r'])); + // Mangled connection-failure render observed live (chars dropped by Ink). + fake.stdout.write('OAuth error: connctECONNREFUSED 10.0.0.1:443PressEntertoretry.'); + + await vi.waitFor(() => + expect(states.at(-1)).toEqual({ + status: 'failed', + error: 'Claude sign-in failed with a network error during the code exchange', + code: 'exchange_network_error', + detail: 'connctECONNREFUSED 10.0.0.1:443', }) ); expect(fake.kill).toHaveBeenCalledWith('SIGTERM'); diff --git a/apps/web/src/components/CodexConnectModal.tsx b/apps/web/src/components/CodexConnectModal.tsx index c878a524e7..87691db339 100644 --- a/apps/web/src/components/CodexConnectModal.tsx +++ b/apps/web/src/components/CodexConnectModal.tsx @@ -231,6 +231,15 @@ export function AgentCredentialConnectModal({ setSubmitError('Paste the code Claude shows you first.'); return; } + // Claude's browser page shows the code as `#`. A paste without + // the `#` half is guaranteed to fail inside the CLI ("Invalid code. Please + // make sure the full code was copied"), so catch it before the round-trip. + if (agentType === 'claude-code' && !code.replace(/\s+/g, '').includes('#')) { + setSubmitError( + 'That looks like only part of the code. Copy the entire code Claude shows — it includes a # in the middle.' + ); + return; + } codeSubmitInFlightRef.current = true; setSubmittingCode(true); diff --git a/apps/web/tests/unit/components/CodexConnectModal.test.tsx b/apps/web/tests/unit/components/CodexConnectModal.test.tsx index edb22cfb4a..3f67b12d67 100644 --- a/apps/web/tests/unit/components/CodexConnectModal.test.tsx +++ b/apps/web/tests/unit/components/CodexConnectModal.test.tsx @@ -160,6 +160,42 @@ describe('AgentCredentialConnectModal', () => { expect(await screen.findByText(/Claude Code connected/)).toBeInTheDocument(); }); + it('blocks a Claude code paste missing its #state half before any server round-trip', async () => { + // Claude's browser page shows `#`; copying only the code half + // is guaranteed to fail inside the CLI, so the modal must catch it with + // actionable guidance instead of burning the setup session. + h.createAgentCredentialSetupSession.mockResolvedValue({ + kind: 'created', + session: makeSession('provisioning', { agentType: 'claude-code' }), + }); + h.getAgentCredentialSetupSession.mockResolvedValue( + makeSession('waiting_for_user', { + agentType: 'claude-code', + verificationUrl: CLAUDE_VERIFICATION_URL, + userCode: null, + }) + ); + + render( + + ); + + await screen.findByRole('link', { name: /open claude sign-in/i }); + const tokenInput = screen.getByLabelText(/paste the code claude shows you/i); + fireEvent.change(tokenInput, { target: { value: 'abc123-no-state-half' } }); + fireEvent.click(screen.getByRole('button', { name: /continue sign-in/i })); + + expect( + await screen.findByText(/copy the entire code claude shows/i) + ).toBeInTheDocument(); + expect(h.submitAgentCredentialSetupVerificationCode).not.toHaveBeenCalled(); + }); + it('reports completion without exposing a terminal surface', async () => { const onConnected = vi.fn(); h.createAgentCredentialSetupSession.mockResolvedValue({ From ae2dab2ad948d5d406a46c95a6e98a5d7ba04a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Mon, 27 Jul 2026 06:01:26 +0000 Subject: [PATCH 33/57] docs(task): record real-code failure diagnosis and detail-capture follow-up Co-Authored-By: Claude Fable 5 --- ...6-07-26-claude-guided-verification-code.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tasks/archive/2026-07-26-claude-guided-verification-code.md b/tasks/archive/2026-07-26-claude-guided-verification-code.md index bafba3d54b..38b0f7bdbe 100644 --- a/tasks/archive/2026-07-26-claude-guided-verification-code.md +++ b/tasks/archive/2026-07-26-claude-guided-verification-code.md @@ -97,3 +97,37 @@ the short-lived code. - Live no-account verification: session `01KYEQ1PNJVAADQPMXMMG4FX1V` surfaced a trusted Claude URL in 12.5s, accepted a `code#state`-shaped rejected value, and surfaced sanitized `code_rejected` in 5.0s; cleanup returned 200 and D1 had zero active setup rows. - CI: all applicable checks green, including Test, Playwright Visual Tests, SonarCloud, Preflight Evidence, and Specialist Review Evidence. - Remaining explicit human gate: Raphaël must complete the successful OAuth exchange on staging with his real Claude subscription before merge. + +## Follow-up 2026-07-27: real-code attempt still failed — error detail was being discarded + +Raphaël's first real-code retest (session `01KYGZBWGAF1Y7Q4HREJS22XPB`, 05:04 UTC) +failed with `code_rejected` — "Claude rejected the verification code" — despite a +correctly copied code. Investigation (session `77db0283-3193-4621-8b1c-069c1a19f108`): + +- **The submit fix works.** Exchanges now reach a terminal outcome in seconds. +- **Sandbox egress is fine.** A Node-fetch token exchange from inside a staging + sandbox got a genuine `400 invalid_grant` verdict from + `platform.claude.com/v1/oauth/token`. (curl-shaped probes get `429 + rate_limit_error` from the same egress — TLS-fingerprint bot-scoring, a red + herring; the Bun-based CLI is not affected.) +- **The real bug: every `OAuth error:` render was flattened into "rejected".** + Live-reproduced against claude v2.1.220, distinct failure wordings exist: + - paste missing the `#state` half → instant LOCAL `OAuth error: Invalid code. + Please make sure the full code was copied` (no network) + - full-format bad code/state/PKCE → server `OAuth error: Request failed with + status code 400` + - network failure → `OAuth error: connect ECONNREFUSED …` + The driver discarded the line, so the true reason of the real-code failure is + unrecoverable; the most likely candidates are an incomplete mobile copy + (missing `#` half) or a code issued against a different PKCE challenge + (e.g. mobile app-link interception of the sign-in URL). +- **Fix (commit `b26de657f`):** driver extracts + classifies the OAuth error + line after a settle window (`CLAUDE_SETUP_REJECTION_SETTLE_MS`) into + `code_incomplete` / `code_rejected` / `exchange_network_error` with a bounded, + sk-ant-redacted `detail`; the DO maps each class to accurate guidance and + appends `[CLI: …]` to `error_message` (driver free-form `error` still never + surfaced); the modal blocks claude-code pastes without `#` before burning the + session. Verified end-to-end against the real CLI for both failure classes. +- **Class of bug:** collapsing a multi-cause external failure surface into one + fixed user message — the discarded upstream detail was the only signal that + could distinguish user error from environment failure. From b2bf8e05e279569838617f2752b14c94ee3b5764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Mon, 10 Aug 2026 00:24:41 +0000 Subject: [PATCH 34/57] fix: refresh Claude guided login after main drift --- .claude/skills/env-reference/SKILL.md | 12 +++++++++ apps/api/.env.example | 14 ++++++++++ ...10_credential_setup_exchanging_status.sql} | 0 .../credential-setup-session/index.ts | 7 +++-- apps/api/src/env.ts | 1 + .../src/services/credential-setup-config.ts | 2 +- .../credential-setup-session.test.ts | 16 ++++++++--- .../tests/playwright/docs-screenshots.spec.ts | 8 +++--- .../public/images/docs/agent-guided-login.png | Bin 72991 -> 97457 bytes .../src/content/docs/docs/guides/agents.md | 4 +-- .../docs/guides/recent-product-changes.md | 2 +- .../docs/docs/reference/configuration.md | 25 ++++++++++-------- 12 files changed, 67 insertions(+), 24 deletions(-) rename apps/api/src/db/migrations/{0099_credential_setup_exchanging_status.sql => 0110_credential_setup_exchanging_status.sql} (100%) diff --git a/.claude/skills/env-reference/SKILL.md b/.claude/skills/env-reference/SKILL.md index 71b1899040..9a46176cf5 100644 --- a/.claude/skills/env-reference/SKILL.md +++ b/.claude/skills/env-reference/SKILL.md @@ -97,6 +97,18 @@ See `apps/api/.env.example` for the full list. Key variables: - `DEPLOYMENT_RELEASE_RETENTION_LAST_RUN_KV_KEY` — KV interval marker (default: `cleanup:deployment-releases:last-run`) - `COMPOSE_IMAGE_ARTIFACT_CLEANUP_BATCH_SIZE` — Maximum abandoned compose archives deleted per daily run (default: `250`) +### Guided Agent Credential Setup + +- `MAX_CONCURRENT_SETUP_SESSIONS` — Concurrent Cloudflare Sandbox setup-session cap (default: `2`) +- `SETUP_SESSION_TTL_MS` — Setup-session lifetime before teardown (default: `900000`) +- `SETUP_SESSION_CAPTURE_POLL_MS` — Device-login and credential-capture poll interval (default: `3000`) +- `CODEX_DEVICE_AUTH_REQUEST_TIMEOUT_MS` — Codex app-server JSON-RPC request timeout (default: `30000`) +- `CLAUDE_SETUP_ENTER_DELAY_MS` — Delay before sending Enter as a separate stdin write after Claude's browser-displayed code is pasted into the CLI (default: `1000`) +- `CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS` — Maximum wait for Claude's CLI exchange to finish after code submission (default: `120000`) +- `CLAUDE_SETUP_REJECTION_SETTLE_MS` — Wait for Ink redraws to settle before classifying the Claude CLI OAuth error line (default: `400`) +- `SETUP_SESSION_SWEEP_MAX_CANDIDATES` — Maximum expired setup sessions torn down per sweep (default: `50`) +- `POOL_LEASE_BUFFER_MS` — Grace after the session TTL before a leaked setup-pool lease self-prunes (default: `300000`) + ### Operational Control Loops - `CRON_SWEEPS_ENABLED_KV_KEY` — Fail-open KV brake key for the five-minute operational sweep (default: `control-loops:cron-enabled`) diff --git a/apps/api/.env.example b/apps/api/.env.example index 6d130cb244..bece5fe25a 100644 --- a/apps/api/.env.example +++ b/apps/api/.env.example @@ -71,6 +71,20 @@ BASE_DOMAIN=workspaces.example.com # WEBHOOK_DELIVERY_MAX_PAGE_SIZE=100 # WEBHOOK_DELIVERY_PROCESSING_LEASE_SECONDS=300 +# Guided agent credential setup via Cloudflare Sandbox +# MAX_CONCURRENT_SETUP_SESSIONS=2 +# SETUP_SESSION_TTL_MS=900000 +# SETUP_SESSION_CAPTURE_POLL_MS=3000 +# CODEX_DEVICE_AUTH_REQUEST_TIMEOUT_MS=30000 +# Claude Code v2.1.220 treats a large pasted code plus inline carriage return as +# text; keep Enter as a separate write after this settle delay. +# CLAUDE_SETUP_ENTER_DELAY_MS=1000 +# CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS=120000 +# Wait for Ink redraw output to settle before classifying a mangled OAuth error. +# CLAUDE_SETUP_REJECTION_SETTLE_MS=400 +# SETUP_SESSION_SWEEP_MAX_CANDIDATES=50 +# POOL_LEASE_BUFFER_MS=300000 + # NOTE: Hetzner tokens are NOT platform secrets. # Users provide their own Hetzner API tokens through the Settings UI. # These are stored encrypted (per-user) in the database. diff --git a/apps/api/src/db/migrations/0099_credential_setup_exchanging_status.sql b/apps/api/src/db/migrations/0110_credential_setup_exchanging_status.sql similarity index 100% rename from apps/api/src/db/migrations/0099_credential_setup_exchanging_status.sql rename to apps/api/src/db/migrations/0110_credential_setup_exchanging_status.sql diff --git a/apps/api/src/durable-objects/credential-setup-session/index.ts b/apps/api/src/durable-objects/credential-setup-session/index.ts index 4622e672c7..060ce5c125 100644 --- a/apps/api/src/durable-objects/credential-setup-session/index.ts +++ b/apps/api/src/durable-objects/credential-setup-session/index.ts @@ -5,7 +5,7 @@ * One DO per setup session (keyed by the session id, which is ALSO the sandbox * id — 1:1, never shared across users). The DO owns the lifecycle state machine: * - * creating -> provisioning -> waiting_for_user -> capturing -> saving + * creating -> provisioning -> admitting -> waiting_for_user -> exchanging -> capturing -> saving * -> completed | failed | cancelled | expired * * It provisions a per-session credential home, starts the provider setup driver, @@ -460,10 +460,13 @@ export class CredentialSetupSession extends DurableObject { const exchangeTimeoutEnv = this.env.CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS ? ` CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS=${shellQuote(this.env.CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS)}` : ''; + const rejectionSettleEnv = this.env.CLAUDE_SETUP_REJECTION_SETTLE_MS + ? ` CLAUDE_SETUP_REJECTION_SETTLE_MS=${shellQuote(this.env.CLAUDE_SETUP_REJECTION_SETTLE_MS)}` + : ''; return ( `nohup env CLAUDE_CONFIG_DIR=${shellQuote(row.codex_home)} ` + 'DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=dumb' + - `${enterDelayEnv}${exchangeTimeoutEnv} ` + + `${enterDelayEnv}${exchangeTimeoutEnv}${rejectionSettleEnv} ` + `node /usr/local/bin/sam-claude-setup-token.mjs ${shellQuote(statePath)} ` + `${shellQuote(credentialPath)} ${shellQuote(verificationCodePath)} >/dev/null 2>&1 &` ); diff --git a/apps/api/src/env.ts b/apps/api/src/env.ts index 7c3282c694..05db263f63 100644 --- a/apps/api/src/env.ts +++ b/apps/api/src/env.ts @@ -140,6 +140,7 @@ export interface Env extends WebhookTriggerEnv, TaskRecoveryEnv { CODEX_DEVICE_AUTH_REQUEST_TIMEOUT_MS?: string; // App-server JSON-RPC request timeout in ms (default: 30000) CLAUDE_SETUP_ENTER_DELAY_MS?: string; // Claude guided-login: delay before the separate Enter keypress after pasting the code into the sandboxed CLI (default: 1000) CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS?: string; // Claude guided-login: max wait for the CLI code exchange after submission before failing visibly (default: 120000) + CLAUDE_SETUP_REJECTION_SETTLE_MS?: string; // Claude guided-login: wait for Ink to finish redrawing an OAuth failure before classifying it (default: 400) SETUP_SESSION_SWEEP_MAX_CANDIDATES?: string; // Max expired sessions torn down per cron sweep (default: 50) POOL_LEASE_BUFFER_MS?: string; // Grace beyond TTL before a leaked pool lease self-prunes (default: 300000 = 5 min) // Deployment signing keys (Ed25519 — separate from callback JWT) diff --git a/apps/api/src/services/credential-setup-config.ts b/apps/api/src/services/credential-setup-config.ts index 5249183c18..730ffd9ab6 100644 --- a/apps/api/src/services/credential-setup-config.ts +++ b/apps/api/src/services/credential-setup-config.ts @@ -55,7 +55,7 @@ export function getPoolLeaseMaxAgeMs(env: Env): number { /** * Statuses that count as "active" (occupying the one-active-per-user slot and a - * pool lease). Mirrors the partial unique index in migration 0097. + * pool lease). Mirrors the partial unique index updated in migration 0110. */ export const ACTIVE_SETUP_STATUSES = [ 'creating', diff --git a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts index 6fdb7e5415..9a1d34481a 100644 --- a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts +++ b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts @@ -259,14 +259,14 @@ function createFakeSandbox() { } // eslint-disable-next-line @typescript-eslint/no-explicit-any -function createDO(): { +function createDO(envOverrides: Partial = {}): { instance: InstanceType; ctx: any; database: ReturnType; } { const ctx = createFakeCtx(); const database = createFakeDatabase(); - const env = { DATABASE: database } as unknown as Env; + const env = { DATABASE: database, ...envOverrides } as unknown as Env; // eslint-disable-next-line @typescript-eslint/no-explicit-any const instance = new CredentialSetupSession(ctx as any, env); return { instance, ctx, database }; @@ -424,7 +424,11 @@ describe('CredentialSetupSession — alarm() provisioning step', () => { }); it('provisions Claude Code with an isolated CLAUDE_CONFIG_DIR and optional code', async () => { - const { instance } = createDO(); + const { instance } = createDO({ + CLAUDE_SETUP_ENTER_DELAY_MS: '1100', + CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS: '125000', + CLAUDE_SETUP_REJECTION_SETTLE_MS: '450', + }); await Promise.resolve(); const fakeSandbox = createFakeSandbox(); fakeSandbox.readFile.mockImplementation(async (path: string) => ({ @@ -462,6 +466,12 @@ describe('CredentialSetupSession — alarm() provisioning step', () => { expect.stringContaining('sam-claude-setup-token.mjs'), expect.objectContaining({ timeout: expect.any(Number) }) ); + expect(fakeSandbox.exec).toHaveBeenCalledWith( + expect.stringContaining( + "CLAUDE_SETUP_ENTER_DELAY_MS='1100' CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS='125000' CLAUDE_SETUP_REJECTION_SETTLE_MS='450'" + ), + expect.objectContaining({ timeout: expect.any(Number) }) + ); const state = await instance.getState(); expect(state?.status).toBe('waiting_for_user'); diff --git a/apps/web/tests/playwright/docs-screenshots.spec.ts b/apps/web/tests/playwright/docs-screenshots.spec.ts index d7c6faf161..96b4329c3f 100644 --- a/apps/web/tests/playwright/docs-screenshots.spec.ts +++ b/apps/web/tests/playwright/docs-screenshots.spec.ts @@ -74,8 +74,8 @@ const SETUP_SESSION = { status: 'waiting_for_user', agentType: 'claude-code', expiresAt: new Date(Date.now() + 1_200_000).toISOString(), - verificationUrl: 'https://claude.ai/oauth/device?client_id=sam-docs&code=' + 'x'.repeat(48), - userCode: 'SAMD-4821', + verificationUrl: 'https://claude.ai/oauth/device?client_id=sam-docs&challenge=' + 'x'.repeat(48), + userCode: null, errorCode: null, errorMessage: null, }; @@ -125,8 +125,8 @@ test('docs: guided subscription sign-in modal (Claude Code)', async ({ page }) = const dialog = page.getByRole('dialog', { name: 'Connect with Claude Code' }); await expect(dialog.getByRole('link', { name: 'Open Claude sign-in' })).toBeVisible(); - await expect(dialog.locator('code')).toHaveText(SETUP_SESSION.userCode); - await expect(dialog.getByRole('button', { name: 'Copy code' })).toBeVisible(); + await expect(dialog.getByLabel('Paste the code Claude shows you')).toBeVisible(); + await expect(dialog.getByRole('button', { name: 'Continue sign-in' })).toBeDisabled(); // Make the backdrop fully opaque so the settings page behind the modal does not // bleed through the card's rounded corners in the docs screenshot. diff --git a/apps/www/public/images/docs/agent-guided-login.png b/apps/www/public/images/docs/agent-guided-login.png index 347448c79d68ed2f6be9d92e7157c808030dea81..f2faaa4161a4fc38d9c455177713089dbd0cd7a2 100644 GIT binary patch literal 97457 zcmeFZ^;=Y5_$~}0pa`Ob2neW%lypjp5)wlVAuZkAjY=rp-8F=C$1noY9YYS?-ONxk zXZ!h{^ZpI*xvn$(urBtj*n92uJnMPx`(E=)Sy6_FfQkSM3yVnhv!p5(7ES;b)_tD` z_kb&(a%}gpu%2MaN=m4Cr0*}_ekC=h!#kE=SXj_wB4a%~JS^`N4Sh5tA+9)~EGu7gs z*8p&VhES@EKOA?xM8rm-xWKW((!I1?i8w5kRHT3nhAIBv# zG|H7S~m<)Kyu8*t3?xV#^5%MnqUH@~f2smHz9WCN%Pjvg!75 z8cHh1>1t>8`^S;j@RQfbcdH>Fv}=~yWlF-p8*{FIb+Jt2mAJTtlT@O&EK4it0}aR@ zXMd-dOh9cEG4gXgsUf%8_UR;t)d+ch#*S`?Leq7~tCS2OQoIm!iWLdvjDE~dy zho+NL&!!W~+vwt)Kg20MxRh#&sE2vQgGY|cd}$$VV*e^-8+kM-=sWR8G0MEEad;u_ z*6+B(W02x6&QRhb6D9v|H0Af>&Zot%Gd~tCXQtk}!c{*e`?yhyf}eRZ&l3Kt@PVO^ zwAOmd(r?$Z_+`K;aId~o=3A?ZY5%qU#iYNvwSG#r@tjY}jZi#bbKnFe;Ip*_CiDMi z#2*+2KqP?*AO^qvcTCvo(Q7BkxBDW9lL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`)(;q_&R6ukXI8fd2mqssdI0i9o=XYzj0Ltv@RgYSo}w zqSO>A1pVi3Acc#Zab9#Q*>R0DxIF{h`_I zqyni}qf}|KiYsT``A~Wl?b`p)FlV}bt2OEpr9djAa!{eQn4Lxn1poj5cyQ@v!5Sm7M#PAmWCF36 zDOahoiUlf-!Q~BA!E+1J^2JI%H2yCSy8wvZW zd8L(uF7Xf4eCc80002+fRP9UR$_sb zkP)#x+BM~BO@1j;syBL);q=MgRRmDRU=J5?hN|gRYDTSLZz}d) za372v000000NP&dj8GsD3D^NTX+kU%$V37`Mc7lb(X)&l#M1ylO*3i_pf%5>mzRmz z;X*0=B5eWy007*L21`-Zo=8*UAGJTO#<@C;GpYQMYTN0?4wR%Z;h7BtP{yx-L00006Nkl Date: Mon, 10 Aug 2026 00:59:58 +0000 Subject: [PATCH 35/57] fix: harden refreshed Claude guided login --- .claude/skills/env-reference/SKILL.md | 6 + apps/api/.env.example | 6 + apps/api/scripts/claude-setup-token.mjs | 129 ++++++++++--- ...110_credential_setup_exchanging_status.sql | 4 +- .../credential-setup-session/index.ts | 36 +++- apps/api/src/env.ts | 6 + .../routes/agent-credential-setup-sessions.ts | 12 +- .../api/src/services/agent-credential-save.ts | 8 +- .../src/services/credential-setup-config.ts | 42 ++++ apps/api/src/services/validation.ts | 7 +- .../credential-setup-session.test.ts | 41 +++- ...t-credential-setup-native-vertical.test.ts | 181 ++++++++++++++++-- .../unit/scripts/claude-setup-token.test.ts | 62 +++++- .../tests/unit/services/validation.test.ts | 11 ++ ...t-credential-setup-sessions-routes.test.ts | 2 +- apps/web/src/components/CodexConnectModal.tsx | 11 +- .../agent-guided-connect-audit.spec.ts | 31 ++- .../components/CodexConnectModal.test.tsx | 43 ++++- .../src/content/docs/docs/guides/agents.md | 2 +- .../docs/docs/reference/configuration.md | 6 + 20 files changed, 575 insertions(+), 71 deletions(-) diff --git a/.claude/skills/env-reference/SKILL.md b/.claude/skills/env-reference/SKILL.md index 9a46176cf5..a83ece4063 100644 --- a/.claude/skills/env-reference/SKILL.md +++ b/.claude/skills/env-reference/SKILL.md @@ -106,6 +106,12 @@ See `apps/api/.env.example` for the full list. Key variables: - `CLAUDE_SETUP_ENTER_DELAY_MS` — Delay before sending Enter as a separate stdin write after Claude's browser-displayed code is pasted into the CLI (default: `1000`) - `CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS` — Maximum wait for Claude's CLI exchange to finish after code submission (default: `120000`) - `CLAUDE_SETUP_REJECTION_SETTLE_MS` — Wait for Ink redraws to settle before classifying the Claude CLI OAuth error line (default: `400`) +- `CLAUDE_SETUP_VERIFICATION_POLL_MS` — Poll interval for the browser-code handoff file inside the Claude setup sandbox (default: `500`) +- `CLAUDE_SETUP_TTY_COLUMNS` — PTY width used for `claude setup-token` to reduce opaque-token wrapping (default: `512`) +- `CLAUDE_SETUP_OUTPUT_BUFFER_BYTES` — Maximum in-memory Claude PTY output retained for parsing (default: `32768`) +- `CLAUDE_VERIFICATION_CODE_MAX_LENGTH` — Maximum accepted browser-displayed `code#state` length (default: `1024`) +- `CLAUDE_SETUP_ERROR_DETAIL_MAX_LENGTH` — Maximum sanitized Claude CLI diagnostic surfaced to the user (default: `160`) +- `CLAUDE_OAUTH_TOKEN_MAX_LENGTH` — Maximum captured Claude OAuth token length (default: `8192`) - `SETUP_SESSION_SWEEP_MAX_CANDIDATES` — Maximum expired setup sessions torn down per sweep (default: `50`) - `POOL_LEASE_BUFFER_MS` — Grace after the session TTL before a leaked setup-pool lease self-prunes (default: `300000`) diff --git a/apps/api/.env.example b/apps/api/.env.example index bece5fe25a..3f1874ac8f 100644 --- a/apps/api/.env.example +++ b/apps/api/.env.example @@ -82,6 +82,12 @@ BASE_DOMAIN=workspaces.example.com # CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS=120000 # Wait for Ink redraw output to settle before classifying a mangled OAuth error. # CLAUDE_SETUP_REJECTION_SETTLE_MS=400 +# CLAUDE_SETUP_VERIFICATION_POLL_MS=500 +# CLAUDE_SETUP_TTY_COLUMNS=512 +# CLAUDE_SETUP_OUTPUT_BUFFER_BYTES=32768 +# CLAUDE_VERIFICATION_CODE_MAX_LENGTH=1024 +# CLAUDE_SETUP_ERROR_DETAIL_MAX_LENGTH=160 +# CLAUDE_OAUTH_TOKEN_MAX_LENGTH=8192 # SETUP_SESSION_SWEEP_MAX_CANDIDATES=50 # POOL_LEASE_BUFFER_MS=300000 diff --git a/apps/api/scripts/claude-setup-token.mjs b/apps/api/scripts/claude-setup-token.mjs index 6d49ecdece..5045796867 100644 --- a/apps/api/scripts/claude-setup-token.mjs +++ b/apps/api/scripts/claude-setup-token.mjs @@ -7,7 +7,6 @@ import { fileURLToPath } from 'node:url'; const MAX_VERIFICATION_URL_LENGTH = 4096; const MAX_USER_CODE_LENGTH = 128; -const MAX_CLAUDE_TOKEN_LENGTH = 8192; const CLAUDE_OAUTH_TOKEN_PREFIX = 'sk-ant-oat'; const CLAUDE_CONFIG_DIR_ENV = 'CLAUDE_CONFIG_DIR'; const DEVICE_AUTH_STATE_FILE = 'device-auth-state.json'; @@ -16,30 +15,35 @@ const VERIFICATION_CODE_FILE = 'verification-code.txt'; const ANSI_ESCAPE_PATTERN = /\u001b\[[0-9;?]*[ -/]*[@-~]/g; const CONTROL_CHARACTER_PATTERN = /[\u0000-\u001f\u007f]/; const CLAUDE_SETUP_COMMAND = - 'stty cols 512; env DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=xterm-256color claude setup-token'; + 'env DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=xterm-256color claude setup-token'; const URL_PATTERN = /https:\/\/[^\s<>'"`]+/gi; -const TOKEN_PATTERN = /\bsk-ant-oat(?:[A-Za-z0-9._-]|\r?\n){16,8192}\b/g; +const TOKEN_PATTERN = /\bsk-ant-oat[A-Za-z0-9._-]{16,}/g; // The Ink error screen always renders `OAuth error: ` and then waits for a // retry keypress without exiting — treat ANY such marker after the code was // forwarded as terminal. Requiring a specific status-code suffix here made real // failures (401 "Authentication failed", state mismatch, network errors) hang // until the session TTL. -const OAUTH_REJECTION_PATTERN = /OAuth error:/i; +const OAUTH_REJECTION_PATTERN = /Oa?u?t?h?\s*er?r?o?r?\s*:/i; // Ink redraws overwrite characters in place, so the surviving text can drop // letters and spaces ("Requstfailed withstatus code 400"). Classification // patterns must tolerate that mangling — match with optional gaps, never on // exact prose. -const OAUTH_ERROR_LINE_PATTERN = /OAuth error:\s*([^\n\r]*)/gi; +const OAUTH_ERROR_LINE_PATTERN = /Oa?u?t?h?\s*er?r?o?r?\s*:\s*([^\n\r]*)/gi; const OAUTH_RETRY_SUFFIX_PATTERN = /Press\s*Enter\s*to\s*retry.*$/i; -const OAUTH_INCOMPLETE_CODE_PATTERN = /invalid\s*c\w{0,3}de/i; +const OAUTH_INCOMPLETE_CODE_PATTERN = /(?:inv\w{0,5}\s*c\w{0,3}de|full\w{0,3}c\w{0,4}cop\w{0,3})/i; const OAUTH_STATUS_CODE_PATTERN = /status\s*code\s*(\d{3})/i; const OAUTH_NETWORK_ERROR_PATTERN = /(ECONN|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|EHOSTUNREACH|ENETUNREACH|getaddrinfo|socket|network|fetch\s*fail|tunnel|conn\w{0,4}ion|CONNECT\s*response)/i; const SECRET_LIKE_PATTERN = /sk-ant[A-Za-z0-9._-]*/gi; -const MAX_OAUTH_ERROR_DETAIL_LENGTH = 160; const DEFAULT_VERIFICATION_ENTER_DELAY_MS = 1000; const DEFAULT_EXCHANGE_TIMEOUT_MS = 120_000; const DEFAULT_REJECTION_SETTLE_MS = 400; +const DEFAULT_VERIFICATION_CODE_POLL_MS = 500; +const DEFAULT_TTY_COLUMNS = 512; +const DEFAULT_OUTPUT_BUFFER_BYTES = 32_768; +const DEFAULT_VERIFICATION_CODE_MAX_LENGTH = 1_024; +const DEFAULT_OAUTH_ERROR_DETAIL_MAX_LENGTH = 160; +const DEFAULT_CLAUDE_OAUTH_TOKEN_MAX_LENGTH = 8_192; function positiveIntFromEnv(name, fallback) { const value = Number(process.env[name]); @@ -85,12 +89,18 @@ export function validateClaudeVerificationUrl(value) { return url.toString(); } -export function validateClaudeOauthToken(value) { +export function validateClaudeOauthToken( + value, + maxLength = positiveIntFromEnv( + 'CLAUDE_OAUTH_TOKEN_MAX_LENGTH', + DEFAULT_CLAUDE_OAUTH_TOKEN_MAX_LENGTH + ) +) { const token = value.trim(); if (!token.startsWith(CLAUDE_OAUTH_TOKEN_PREFIX)) { throw new Error('Claude setup-token returned an invalid OAuth token prefix'); } - if (token.length > MAX_CLAUDE_TOKEN_LENGTH) { + if (token.length > maxLength) { throw new Error('Claude setup-token returned an overlong OAuth token'); } if (!/^[A-Za-z0-9._-]+$/.test(token)) { @@ -99,6 +109,39 @@ export function validateClaudeOauthToken(value) { return token; } +function extractClaudeOauthToken(text, ttyColumns, acceptStreamEnd) { + TOKEN_PATTERN.lastIndex = 0; + const match = TOKEN_PATTERN.exec(text); + if (!match?.[0] || match.index === undefined) return undefined; + + let token = match[0]; + let cursor = match.index + match[0].length; + let lineStart = text.lastIndexOf('\n', match.index - 1) + 1; + + for (;;) { + const newlineLength = text.startsWith('\r\n', cursor) + ? 2 + : text.startsWith('\n', cursor) + ? 1 + : 0; + if (newlineLength === 0) { + // A token-like suffix at the current end of the stream may still be a + // partial PTY chunk. Wait for a delimiter before accepting it. + return cursor === text.length && !acceptStreamEnd ? undefined : token; + } + + const physicalLineLength = cursor - lineStart; + if (physicalLineLength < ttyColumns) return token; + + const continuationStart = cursor + newlineLength; + const continuation = /^[A-Za-z0-9._-]+/.exec(text.slice(continuationStart)); + if (!continuation?.[0]) return token; + token += continuation[0]; + cursor = continuationStart + continuation[0].length; + lineStart = continuationStart; + } +} + export function resolveClaudeSetupPaths({ statePath, credentialPath, @@ -150,7 +193,11 @@ function validateUserCode(value) { return code; } -export function extractClaudeSetupOutput(raw) { +export function extractClaudeSetupOutput( + raw, + ttyColumns = DEFAULT_TTY_COLUMNS, + acceptStreamEnd = true +) { const text = stripAnsi(raw); let verificationUrl; for (const match of text.matchAll(URL_PATTERN)) { @@ -175,10 +222,8 @@ export function extractClaudeSetupOutput(raw) { } } - let token; - TOKEN_PATTERN.lastIndex = 0; - const tokenMatch = TOKEN_PATTERN.exec(text); - if (tokenMatch?.[0]) token = validateClaudeOauthToken(tokenMatch[0].replace(/\s+/g, '')); + const tokenCandidate = extractClaudeOauthToken(text, ttyColumns, acceptStreamEnd); + const token = tokenCandidate ? validateClaudeOauthToken(tokenCandidate) : undefined; return { verificationUrl, userCode, token }; } @@ -189,7 +234,13 @@ export function extractClaudeSetupOutput(raw) { * only signal distinguishing an incomplete paste, a server 4xx, and a sandbox * network failure — discarding it turns every failure into "code rejected". */ -export function extractOauthErrorDetail(text) { +export function extractOauthErrorDetail( + text, + maxLength = positiveIntFromEnv( + 'CLAUDE_SETUP_ERROR_DETAIL_MAX_LENGTH', + DEFAULT_OAUTH_ERROR_DETAIL_MAX_LENGTH + ) +) { let lastLine; OAUTH_ERROR_LINE_PATTERN.lastIndex = 0; for (const match of text.matchAll(OAUTH_ERROR_LINE_PATTERN)) { @@ -202,7 +253,7 @@ export function extractOauthErrorDetail(text) { .replace(new RegExp(CONTROL_CHARACTER_PATTERN.source, 'g'), ' ') .replace(/\s+/g, ' ') .trim() - .slice(0, MAX_OAUTH_ERROR_DETAIL_LENGTH); + .slice(0, maxLength); return detail || null; } @@ -241,7 +292,19 @@ export async function runClaudeSetupToken({ writeCredential, readVerificationCode = (path) => readFile(path, 'utf8'), deleteVerificationCode = unlink, - verificationCodePollMs = 500, + verificationCodePollMs = positiveIntFromEnv( + 'CLAUDE_SETUP_VERIFICATION_POLL_MS', + DEFAULT_VERIFICATION_CODE_POLL_MS + ), + ttyColumns = positiveIntFromEnv('CLAUDE_SETUP_TTY_COLUMNS', DEFAULT_TTY_COLUMNS), + outputBufferBytes = positiveIntFromEnv( + 'CLAUDE_SETUP_OUTPUT_BUFFER_BYTES', + DEFAULT_OUTPUT_BUFFER_BYTES + ), + verificationCodeMaxLength = positiveIntFromEnv( + 'CLAUDE_VERIFICATION_CODE_MAX_LENGTH', + DEFAULT_VERIFICATION_CODE_MAX_LENGTH + ), verificationEnterDelayMs = positiveIntFromEnv( 'CLAUDE_SETUP_ENTER_DELAY_MS', DEFAULT_VERIFICATION_ENTER_DELAY_MS @@ -274,15 +337,19 @@ export async function runClaudeSetupToken({ // `script` to allocate a pseudo-terminal while still capturing stdout/stderr // for non-secret URL/token parsing. The transcript path is /dev/null so no // token-bearing terminal log is persisted. - const claude = spawnProcess('script', ['-qfec', CLAUDE_SETUP_COMMAND, '/dev/null'], { - env: { - ...process.env, - DISABLE_AUTOUPDATER: '1', - NO_COLOR: '1', - TERM: 'xterm-256color', - }, - stdio: ['pipe', 'pipe', 'pipe'], - }); + const claude = spawnProcess( + 'script', + ['-qfec', `stty cols ${ttyColumns}; ${CLAUDE_SETUP_COMMAND}`, '/dev/null'], + { + env: { + ...process.env, + DISABLE_AUTOUPDATER: '1', + NO_COLOR: '1', + TERM: 'xterm-256color', + }, + stdio: ['pipe', 'pipe', 'pipe'], + } + ); onSpawn?.(claude); let publishedWaiting = false; @@ -353,6 +420,10 @@ export async function runClaudeSetupToken({ try { const code = await readVerificationCode(setupPaths.verificationCodePath); await deleteVerificationCode(setupPaths.verificationCodePath); + const normalizedCode = code.replace(/\s+/g, ''); + if (normalizedCode.length === 0 || normalizedCode.length > verificationCodeMaxLength) { + throw new Error('Invalid Claude verification code length'); + } clearInterval(verificationCodePoll); verificationCodePoll = undefined; verificationCodeForwarded = true; @@ -361,7 +432,7 @@ export async function runClaudeSetupToken({ // (reproduced with ~100-char real codes; short test codes submit). // Write the code, then send Enter as a SEPARATE write after a settle // delay so the CLI registers a real submit keypress. - claude.stdin.write(code.replace(/\s+/g, '')); + claude.stdin.write(normalizedCode); verificationEnterTimer = setTimeout(() => { verificationEnterTimer = undefined; claude.stdin.write('\r'); @@ -404,10 +475,10 @@ export async function runClaudeSetupToken({ } function processOutput(chunk) { - outputBuffer = `${outputBuffer}${chunk}`.slice(-32768); + outputBuffer = `${outputBuffer}${chunk}`.slice(-outputBufferBytes); let details; try { - details = extractClaudeSetupOutput(outputBuffer); + details = extractClaudeSetupOutput(outputBuffer, ttyColumns, false); } catch (error) { publishFailure(error instanceof Error ? error.message : String(error)); claude.kill('SIGTERM'); diff --git a/apps/api/src/db/migrations/0110_credential_setup_exchanging_status.sql b/apps/api/src/db/migrations/0110_credential_setup_exchanging_status.sql index dfb98b06c0..b69cf72a16 100644 --- a/apps/api/src/db/migrations/0110_credential_setup_exchanging_status.sql +++ b/apps/api/src/db/migrations/0110_credential_setup_exchanging_status.sql @@ -1,8 +1,8 @@ -- Keep the one-active guided-login invariant while Claude Code exchanges the -- browser-displayed verification code inside its sandboxed CLI. -DROP INDEX IF EXISTS idx_agent_credential_setup_one_active; +DROP INDEX IF EXISTS idx_acss_one_active; -CREATE UNIQUE INDEX idx_agent_credential_setup_one_active +CREATE UNIQUE INDEX idx_acss_one_active ON agent_credential_setup_sessions(user_id, agent_type) WHERE status IN ( 'creating', diff --git a/apps/api/src/durable-objects/credential-setup-session/index.ts b/apps/api/src/durable-objects/credential-setup-session/index.ts index 060ce5c125..09abf7f8bd 100644 --- a/apps/api/src/durable-objects/credential-setup-session/index.ts +++ b/apps/api/src/durable-objects/credential-setup-session/index.ts @@ -31,6 +31,9 @@ import type { Env } from '../../env'; import { log } from '../../lib/logger'; import { saveAgentCredentialForUser } from '../../services/agent-credential-save'; import { + getClaudeOauthTokenMaxLength, + getClaudeSetupErrorDetailMaxLength, + getClaudeVerificationCodeMaxLength, isTerminalSetupStatus, type SetupSessionStatus, } from '../../services/credential-setup-config'; @@ -99,7 +102,6 @@ type DeviceAuthDetailsRow = { const CODEX_AUTH_FILE = 'auth.json'; const CLAUDE_OAUTH_TOKEN_FILE = 'claude-oauth-token.txt'; const CLAUDE_VERIFICATION_CODE_FILE = 'verification-code.txt'; -const MAX_CLAUDE_VERIFICATION_CODE_LENGTH = 1024; const CLAUDE_VERIFICATION_CODE_PATTERN = /^[A-Za-z0-9._~#-]+$/; const DEVICE_AUTH_STATE_FILE = 'device-auth-state.json'; @@ -132,15 +134,14 @@ interface DeviceAuthState { * The driver's free-form `error` field is never surfaced — only this bounded * detail — mirroring the sanitized-failure posture of the existing mapping. */ -const MAX_DRIVER_DETAIL_LENGTH = 160; -function sanitizeDriverDetail(detail: string | null | undefined): string | null { +function sanitizeDriverDetail(detail: string | null | undefined, maxLength: number): string | null { if (typeof detail !== 'string') return null; const cleaned = detail .replace(/sk-ant[A-Za-z0-9._-]*/gi, '[redacted]') .replace(/[^\x20-\x7e]+/g, ' ') .replace(/\s+/g, ' ') .trim() - .slice(0, MAX_DRIVER_DETAIL_LENGTH); + .slice(0, maxLength); return cleaned.length > 0 ? cleaned : null; } @@ -298,7 +299,7 @@ export class CredentialSetupSession extends DurableObject { const normalizedCode = code.trim().replace(/\s+/g, ''); if ( normalizedCode.length === 0 || - normalizedCode.length > MAX_CLAUDE_VERIFICATION_CODE_LENGTH || + normalizedCode.length > getClaudeVerificationCodeMaxLength(this.env) || !CLAUDE_VERIFICATION_CODE_PATTERN.test(normalizedCode) ) { throw new Error('Invalid Claude verification code'); @@ -380,7 +381,10 @@ export class CredentialSetupSession extends DurableObject { 'Claude rejected the verification code. Start again and use a fresh code.'; } } - const detail = sanitizeDriverDetail(driverState.detail); + const detail = sanitizeDriverDetail( + driverState.detail, + getClaudeSetupErrorDetailMaxLength(this.env) + ); await this.teardown( row, 'failed', @@ -463,10 +467,25 @@ export class CredentialSetupSession extends DurableObject { const rejectionSettleEnv = this.env.CLAUDE_SETUP_REJECTION_SETTLE_MS ? ` CLAUDE_SETUP_REJECTION_SETTLE_MS=${shellQuote(this.env.CLAUDE_SETUP_REJECTION_SETTLE_MS)}` : ''; + const extraConfigEnv = [ + 'CLAUDE_SETUP_VERIFICATION_POLL_MS', + 'CLAUDE_SETUP_TTY_COLUMNS', + 'CLAUDE_SETUP_OUTPUT_BUFFER_BYTES', + 'CLAUDE_VERIFICATION_CODE_MAX_LENGTH', + 'CLAUDE_SETUP_ERROR_DETAIL_MAX_LENGTH', + 'CLAUDE_OAUTH_TOKEN_MAX_LENGTH', + ] + .flatMap((name) => { + const value = this.env[name as keyof Env]; + return typeof value === 'string' && value.length > 0 + ? [` ${name}=${shellQuote(value)}`] + : []; + }) + .join(''); return ( `nohup env CLAUDE_CONFIG_DIR=${shellQuote(row.codex_home)} ` + 'DISABLE_AUTOUPDATER=1 NO_COLOR=1 TERM=dumb' + - `${enterDelayEnv}${exchangeTimeoutEnv}${rejectionSettleEnv} ` + + `${enterDelayEnv}${exchangeTimeoutEnv}${rejectionSettleEnv}${extraConfigEnv} ` + `node /usr/local/bin/sam-claude-setup-token.mjs ${shellQuote(statePath)} ` + `${shellQuote(credentialPath)} ${shellQuote(verificationCodePath)} >/dev/null 2>&1 &` ); @@ -578,7 +597,8 @@ export class CredentialSetupSession extends DurableObject { const validation = CredentialValidator.validateCredential( content, row.credential_kind as CredentialKind, - row.agent_type as AgentType + row.agent_type as AgentType, + getClaudeOauthTokenMaxLength(this.env) ); if (!validation.valid) { log.info('credential_setup.auth_file_not_ready', { diff --git a/apps/api/src/env.ts b/apps/api/src/env.ts index 05db263f63..29c88dc61a 100644 --- a/apps/api/src/env.ts +++ b/apps/api/src/env.ts @@ -141,6 +141,12 @@ export interface Env extends WebhookTriggerEnv, TaskRecoveryEnv { CLAUDE_SETUP_ENTER_DELAY_MS?: string; // Claude guided-login: delay before the separate Enter keypress after pasting the code into the sandboxed CLI (default: 1000) CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS?: string; // Claude guided-login: max wait for the CLI code exchange after submission before failing visibly (default: 120000) CLAUDE_SETUP_REJECTION_SETTLE_MS?: string; // Claude guided-login: wait for Ink to finish redrawing an OAuth failure before classifying it (default: 400) + CLAUDE_SETUP_VERIFICATION_POLL_MS?: string; // Claude driver poll interval for the browser code file (default: 500) + CLAUDE_SETUP_TTY_COLUMNS?: string; // Claude setup-token PTY width used to reduce token wrapping (default: 512) + CLAUDE_SETUP_OUTPUT_BUFFER_BYTES?: string; // Max in-memory Claude PTY output retained for parsing (default: 32768) + CLAUDE_VERIFICATION_CODE_MAX_LENGTH?: string; // Max browser-displayed code#state length accepted (default: 1024) + CLAUDE_SETUP_ERROR_DETAIL_MAX_LENGTH?: string; // Max sanitized Claude CLI diagnostic length surfaced (default: 160) + CLAUDE_OAUTH_TOKEN_MAX_LENGTH?: string; // Max captured Claude OAuth token length (default: 8192) SETUP_SESSION_SWEEP_MAX_CANDIDATES?: string; // Max expired sessions torn down per cron sweep (default: 50) POOL_LEASE_BUFFER_MS?: string; // Grace beyond TTL before a leaked pool lease self-prunes (default: 300000 = 5 min) // Deployment signing keys (Ed25519 — separate from callback JWT) diff --git a/apps/api/src/routes/agent-credential-setup-sessions.ts b/apps/api/src/routes/agent-credential-setup-sessions.ts index 8d77b720a7..1b2da3e1f1 100644 --- a/apps/api/src/routes/agent-credential-setup-sessions.ts +++ b/apps/api/src/routes/agent-credential-setup-sessions.ts @@ -5,6 +5,7 @@ * without exposing terminal setup mechanics: * POST / create a setup session (leases a sandbox slot) * GET /:id poll lifecycle status + * POST /:id/verification-code forward Claude's browser code to its CLI * POST /:id/cancel cancel + tear down * * AUTH: all routes use browser session-cookie auth (requireAuth/requireApproved) @@ -25,6 +26,7 @@ import { errors } from '../middleware/error'; import { jsonValidator } from '../schemas'; import { ACTIVE_SETUP_STATUSES, + getClaudeVerificationCodeMaxLength, getSetupSessionCapturePollMs, getSetupSessionTtlMs, isTerminalSetupStatus, @@ -44,10 +46,8 @@ const SUPPORTED_SETUP_AGENT_TYPES = ['openai-codex', 'claude-code'] as const; type SupportedSetupAgentType = (typeof SUPPORTED_SETUP_AGENT_TYPES)[number]; const SETUP_CREDENTIAL_KIND = 'oauth-token'; const ACTIVE_STATUS_PLACEHOLDERS = ACTIVE_SETUP_STATUSES.map(() => '?').join(', '); -const MAX_SUBMITTED_CLAUDE_CODE_LENGTH = 1024; - const SubmitVerificationCodeSchema = v.object({ - code: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(MAX_SUBMITTED_CLAUDE_CODE_LENGTH)), + code: v.pipe(v.string(), v.trim(), v.minLength(1)), }); function isSupportedSetupAgentType(agentType: AgentType): agentType is SupportedSetupAgentType { @@ -291,8 +291,12 @@ agentCredentialSetupSessionsRoutes.post( if (isTerminalSetupStatus(row.status)) { throw errors.conflict('Setup session is no longer active'); } + const code = c.req.valid('json').code; + if (code.length > getClaudeVerificationCodeMaxLength(c.env)) { + throw errors.badRequest('Invalid Claude verification code'); + } - const state = await submitSetupSessionVerificationCode(c.env, row.id, c.req.valid('json').code); + const state = await submitSetupSessionVerificationCode(c.env, row.id, code); return c.json({ id: row.id, status: state.status, diff --git a/apps/api/src/services/agent-credential-save.ts b/apps/api/src/services/agent-credential-save.ts index 412659a9e0..31d9d2ece1 100644 --- a/apps/api/src/services/agent-credential-save.ts +++ b/apps/api/src/services/agent-credential-save.ts @@ -26,6 +26,7 @@ import { getCredentialEncryptionKey } from '../lib/secrets'; import { ulid } from '../lib/ulid'; import { errors } from '../middleware/error'; import { syncAgentCredentialToCC } from './composable-credentials/agent-sync'; +import { getClaudeOauthTokenMaxLength } from './credential-setup-config'; import { encrypt } from './encryption'; import { CredentialValidator } from './validation'; @@ -64,7 +65,12 @@ export async function saveAgentCredentialForUser( // Defensive format validation (callers should validate too, but this class of // code must never write an unparseable credential). - const validation = CredentialValidator.validateCredential(credential, credentialKind, agentType); + const validation = CredentialValidator.validateCredential( + credential, + credentialKind, + agentType, + getClaudeOauthTokenMaxLength(env) + ); if (!validation.valid) { throw errors.badRequest(validation.error || 'Invalid credential format'); } diff --git a/apps/api/src/services/credential-setup-config.ts b/apps/api/src/services/credential-setup-config.ts index 730ffd9ab6..890bbabf30 100644 --- a/apps/api/src/services/credential-setup-config.ts +++ b/apps/api/src/services/credential-setup-config.ts @@ -19,6 +19,12 @@ export const DEFAULT_SETUP_SESSION_SWEEP_MAX_CANDIDATES = 50; * session whose DO died without releasing (rule 47 escape path). */ export const DEFAULT_POOL_LEASE_BUFFER_MS = 5 * 60_000; +export const DEFAULT_CLAUDE_SETUP_VERIFICATION_POLL_MS = 500; +export const DEFAULT_CLAUDE_SETUP_TTY_COLUMNS = 512; +export const DEFAULT_CLAUDE_SETUP_OUTPUT_BUFFER_BYTES = 32_768; +export const DEFAULT_CLAUDE_VERIFICATION_CODE_MAX_LENGTH = 1_024; +export const DEFAULT_CLAUDE_SETUP_ERROR_DETAIL_MAX_LENGTH = 160; +export const DEFAULT_CLAUDE_OAUTH_TOKEN_MAX_LENGTH = 8_192; function parsePositiveInt(raw: string | undefined, fallback: number): number { const parsed = Number.parseInt(raw ?? '', 10); @@ -48,6 +54,42 @@ export function getPoolLeaseBufferMs(env: Env): number { return parsePositiveInt(env.POOL_LEASE_BUFFER_MS, DEFAULT_POOL_LEASE_BUFFER_MS); } +export function getClaudeSetupVerificationPollMs(env: Env): number { + return parsePositiveInt( + env.CLAUDE_SETUP_VERIFICATION_POLL_MS, + DEFAULT_CLAUDE_SETUP_VERIFICATION_POLL_MS + ); +} + +export function getClaudeSetupTtyColumns(env: Env): number { + return parsePositiveInt(env.CLAUDE_SETUP_TTY_COLUMNS, DEFAULT_CLAUDE_SETUP_TTY_COLUMNS); +} + +export function getClaudeSetupOutputBufferBytes(env: Env): number { + return parsePositiveInt( + env.CLAUDE_SETUP_OUTPUT_BUFFER_BYTES, + DEFAULT_CLAUDE_SETUP_OUTPUT_BUFFER_BYTES + ); +} + +export function getClaudeVerificationCodeMaxLength(env: Env): number { + return parsePositiveInt( + env.CLAUDE_VERIFICATION_CODE_MAX_LENGTH, + DEFAULT_CLAUDE_VERIFICATION_CODE_MAX_LENGTH + ); +} + +export function getClaudeSetupErrorDetailMaxLength(env: Env): number { + return parsePositiveInt( + env.CLAUDE_SETUP_ERROR_DETAIL_MAX_LENGTH, + DEFAULT_CLAUDE_SETUP_ERROR_DETAIL_MAX_LENGTH + ); +} + +export function getClaudeOauthTokenMaxLength(env: Env): number { + return parsePositiveInt(env.CLAUDE_OAUTH_TOKEN_MAX_LENGTH, DEFAULT_CLAUDE_OAUTH_TOKEN_MAX_LENGTH); +} + /** Lease age after which the pool self-prunes a leaked lease (TTL + buffer). */ export function getPoolLeaseMaxAgeMs(env: Env): number { return getSetupSessionTtlMs(env) + getPoolLeaseBufferMs(env); diff --git a/apps/api/src/services/validation.ts b/apps/api/src/services/validation.ts index 2064789757..84b461ce56 100644 --- a/apps/api/src/services/validation.ts +++ b/apps/api/src/services/validation.ts @@ -7,11 +7,11 @@ import type { import { DEFAULT_SCALEWAY_ZONE, getAgentDefinition } from '@simple-agent-manager/shared'; import { expectJsonRecord, maybeJsonRecord } from '../lib/runtime-validation'; +import { DEFAULT_CLAUDE_OAUTH_TOKEN_MAX_LENGTH } from './credential-setup-config'; import { fetchWithTimeout } from './fetch-timeout'; const ANTHROPIC_API_KEY_PREFIX = 'sk-ant-api'; const CLAUDE_OAUTH_TOKEN_PREFIX = 'sk-ant-oat'; -const MAX_CLAUDE_OAUTH_TOKEN_LENGTH = 8192; /** * Result from OpenAI Codex auth.json validation, including optional metadata @@ -395,7 +395,8 @@ export class CredentialValidator { static validateCredential( credential: string, kind: CredentialKind, - agentType?: AgentType + agentType?: AgentType, + maxClaudeOauthTokenLength = DEFAULT_CLAUDE_OAUTH_TOKEN_MAX_LENGTH ): { valid: boolean; error?: string } { if (!credential || credential.trim().length === 0) { return { valid: false, error: 'Credential cannot be empty' }; @@ -455,7 +456,7 @@ export class CredentialValidator { error: 'Claude OAuth token should start with "sk-ant-oat".', }; } - if (agentType === 'claude-code' && credential.length > MAX_CLAUDE_OAUTH_TOKEN_LENGTH) { + if (agentType === 'claude-code' && credential.length > maxClaudeOauthTokenLength) { return { valid: false, error: 'Claude OAuth token is too long.', diff --git a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts index 9a1d34481a..9c8136e298 100644 --- a/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts +++ b/apps/api/tests/unit/durable-objects/credential-setup-session.test.ts @@ -428,6 +428,12 @@ describe('CredentialSetupSession — alarm() provisioning step', () => { CLAUDE_SETUP_ENTER_DELAY_MS: '1100', CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS: '125000', CLAUDE_SETUP_REJECTION_SETTLE_MS: '450', + CLAUDE_SETUP_VERIFICATION_POLL_MS: '550', + CLAUDE_SETUP_TTY_COLUMNS: '640', + CLAUDE_SETUP_OUTPUT_BUFFER_BYTES: '65536', + CLAUDE_VERIFICATION_CODE_MAX_LENGTH: '2048', + CLAUDE_SETUP_ERROR_DETAIL_MAX_LENGTH: '200', + CLAUDE_OAUTH_TOKEN_MAX_LENGTH: '16384', }); await Promise.resolve(); const fakeSandbox = createFakeSandbox(); @@ -468,7 +474,7 @@ describe('CredentialSetupSession — alarm() provisioning step', () => { ); expect(fakeSandbox.exec).toHaveBeenCalledWith( expect.stringContaining( - "CLAUDE_SETUP_ENTER_DELAY_MS='1100' CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS='125000' CLAUDE_SETUP_REJECTION_SETTLE_MS='450'" + "CLAUDE_SETUP_ENTER_DELAY_MS='1100' CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS='125000' CLAUDE_SETUP_REJECTION_SETTLE_MS='450' CLAUDE_SETUP_VERIFICATION_POLL_MS='550' CLAUDE_SETUP_TTY_COLUMNS='640' CLAUDE_SETUP_OUTPUT_BUFFER_BYTES='65536' CLAUDE_VERIFICATION_CODE_MAX_LENGTH='2048' CLAUDE_SETUP_ERROR_DETAIL_MAX_LENGTH='200' CLAUDE_OAUTH_TOKEN_MAX_LENGTH='16384'" ), expect.objectContaining({ timeout: expect.any(Number) }) ); @@ -727,6 +733,39 @@ describe('CredentialSetupSession — alarm() capture polling', () => { ); }); + it('honors the configured verification-code length limit', async () => { + const created = createDO({ CLAUDE_VERIFICATION_CODE_MAX_LENGTH: '12' }); + await Promise.resolve(); + const fakeSandbox = createFakeSandbox(); + fakeSandbox.readFile.mockImplementation(async (path: string) => ({ + content: path.endsWith('device-auth-state.json') + ? JSON.stringify({ + status: 'waiting_for_user', + verificationUrl: 'https://claude.ai/oauth/device', + }) + : '', + })); + vi.mocked(getSandboxInstance).mockResolvedValue(fakeSandbox as never); + await created.instance.create({ + id: 'setup-configured-code-limit', + setupHome: '/tmp/setup-configured-code-limit', + ttlMs: 900_000, + ...BASE_PARAMS, + agentType: 'claude-code', + provider: 'anthropic', + agentName: 'Claude Code', + }); + await created.instance.alarm(); + await created.instance.alarm(); + + await expect(created.instance.submitVerificationCode('abc123#stateX')).rejects.toThrow( + /Invalid/ + ); + await expect(created.instance.submitVerificationCode('abc123#state')).resolves.toMatchObject({ + status: 'exchanging', + }); + }); + it('fails fast with a sanitized error when Claude rejects the submitted code', async () => { const created = createDO(); await Promise.resolve(); diff --git a/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts b/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts index 5de65c8301..577fb41d32 100644 --- a/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts +++ b/apps/api/tests/unit/routes/agent-credential-setup-native-vertical.test.ts @@ -6,6 +6,38 @@ import type { Env } from '../../../src/env'; import { agentCredentialSetupSessionsRoutes } from '../../../src/routes/agent-credential-setup-sessions'; import { createSqliteD1 } from '../../helpers/sqlite-d1'; +vi.mock('cloudflare:workers', () => ({ + DurableObject: class { + constructor( + public ctx: unknown, + public env: unknown + ) {} + }, +})); + +vi.mock('../../../src/services/sandbox', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + getSandboxInstance: vi.fn(), + destroySandboxInstance: vi.fn().mockResolvedValue(undefined), + }; +}); +vi.mock('../../../src/services/setup-session-pool', async (importOriginal) => { + const actual = await importOriginal(); + return { ...actual, releaseSetupSlot: vi.fn().mockResolvedValue(undefined) }; +}); +vi.mock('../../../src/services/agent-credential-save', async (importOriginal) => { + const actual = + await importOriginal(); + return { ...actual, saveAgentCredentialForUser: vi.fn() }; +}); + +const { CredentialSetupSession } = + await import('../../../src/durable-objects/credential-setup-session'); +const { getSandboxInstance } = await import('../../../src/services/sandbox'); +const { saveAgentCredentialForUser } = await import('../../../src/services/agent-credential-save'); + vi.mock('../../../src/middleware/auth', () => ({ requireAuth: () => vi.fn((_c: unknown, next: () => unknown) => next()), requireApproved: () => vi.fn((_c: unknown, next: () => unknown) => next()), @@ -35,6 +67,78 @@ function setupDatabase(): Database.Database { return sqlite; } +function createDoContext() { + let row: Record | undefined; + let details: Record | undefined; + const sql = { + exec: vi.fn((query: string, ...args: unknown[]) => { + const normalized = query.trim().toLowerCase(); + if (normalized.startsWith('create table')) return { toArray: () => [] }; + if (normalized.includes('insert or replace into setup_session')) { + const [ + id, + userId, + projectId, + scope, + agentType, + credentialKind, + provider, + agentName, + poolLeaseId, + codexHome, + expiresAt, + capturePollMs, + ] = args; + row = { + id, + user_id: userId, + project_id: projectId, + scope, + agent_type: agentType, + credential_kind: credentialKind, + provider, + agent_name: agentName, + status: 'provisioning', + pool_lease_id: poolLeaseId, + codex_home: codexHome, + expires_at: expiresAt, + capture_poll_ms: capturePollMs, + error_code: null, + error_message: null, + completed_at: null, + }; + } else if (normalized.includes('insert or replace into device_auth_details')) { + details = { verification_url: args[0], user_code: args[1] }; + } else if (normalized.includes('delete from device_auth_details')) { + details = undefined; + } else if (normalized.includes('update setup_session') && row) { + row = { + ...row, + status: args[0], + error_code: args[1] ?? null, + error_message: args[2] ?? null, + completed_at: args[3] ?? row.completed_at, + }; + } + if (normalized.includes('select * from setup_session')) { + return { toArray: () => (row ? [{ ...row }] : []) }; + } + if (normalized.includes('select verification_url, user_code')) { + return { toArray: () => (details ? [{ ...details }] : []) }; + } + return { toArray: () => [] }; + }), + }; + return { + storage: { + sql, + setAlarm: vi.fn().mockResolvedValue(undefined), + deleteAlarm: vi.fn().mockResolvedValue(undefined), + }, + blockConcurrencyWhile: vi.fn(async (callback: () => Promise) => callback()), + }; +} + describe('native Codex setup route vertical slice', () => { it('carries owned D1 session state through the DO boundary without persisting device details', async () => { const sqlite = setupDatabase(); @@ -162,22 +266,56 @@ describe('native Codex setup route vertical slice', () => { ); const code = 'abc123#state456'; - const submitVerificationCode = vi.fn().mockResolvedValue({ - id: 'session-claude', - status: 'completed', - expiresAt: Date.now() + 60_000, - errorCode: null, - errorMessage: null, - verificationUrl: null, - userCode: null, + const token = `sk-ant-oat${'V'.repeat(48)}`; + const sandbox = { + exec: vi.fn().mockResolvedValue({ stdout: '', stderr: '', exitCode: 0 }), + writeFile: vi.fn().mockResolvedValue(undefined), + exists: vi.fn().mockImplementation(async (path: string) => ({ + exists: path.endsWith('device-auth-state.json') || path.endsWith('claude-oauth-token.txt'), + })), + readFile: vi.fn().mockImplementation(async (path: string) => ({ + content: path.endsWith('device-auth-state.json') + ? JSON.stringify({ + status: 'waiting_for_user', + verificationUrl: 'https://claude.ai/oauth/device', + }) + : `${token}\n`, + })), + }; + vi.mocked(getSandboxInstance).mockResolvedValue(sandbox as never); + vi.mocked(saveAgentCredentialForUser).mockResolvedValue({ + created: true, + createdAt: now, + updatedAt: now, }); const env = { DATABASE: createSqliteD1(sqlite), + KV: { get: vi.fn().mockResolvedValue(null) }, + } as unknown as Env; + const setupSession = new CredentialSetupSession(createDoContext() as never, env); + await Promise.resolve(); + await setupSession.create({ + id: 'session-claude', + userId: 'owner-user', + projectId: null, + scope: 'user', + agentType: 'claude-code', + credentialKind: 'oauth-token', + provider: 'anthropic', + agentName: 'Claude Code', + poolLeaseId: 'lease-claude', + setupHome: '/tmp/claude-route-vertical', + ttlMs: 60_000, + capturePollMs: 10, + }); + await setupSession.alarm(); + await setupSession.alarm(); + Object.assign(env, { CREDENTIAL_SETUP_SESSION: { idFromName: vi.fn(() => ({ toString: () => 'do-session-claude' })), - get: vi.fn(() => ({ submitVerificationCode })), + get: vi.fn(() => setupSession), }, - } as unknown as Env; + }); const app = new Hono<{ Bindings: Env }>(); app.onError((error, c) => { const status = 'statusCode' in error ? Number(error.statusCode) : 500; @@ -198,14 +336,33 @@ describe('native Codex setup route vertical slice', () => { expect(response.status).toBe(200); expect(await response.json()).toMatchObject({ id: 'session-claude', - status: 'completed', + status: 'exchanging', agentType: 'claude-code', }); - expect(submitVerificationCode).toHaveBeenCalledWith('abc123 #state456'); + expect(sandbox.writeFile).toHaveBeenCalledWith( + '/tmp/claude-route-vertical/verification-code.txt', + code + ); const persisted = sqlite .prepare('SELECT * FROM agent_credential_setup_sessions WHERE id = ?') .get('session-claude') as Record; expect(JSON.stringify(persisted)).not.toContain(code); + + await setupSession.alarm(); + expect(saveAgentCredentialForUser).toHaveBeenCalledWith( + expect.objectContaining({ + userId: 'owner-user', + agentType: 'claude-code', + credential: token, + }) + ); + const completedResponse = await app.request( + '/api/agent-credential-setup-sessions/session-claude', + {}, + env + ); + expect(completedResponse.status).toBe(200); + expect(await completedResponse.json()).toMatchObject({ status: 'completed' }); }); it('passes code shape validation to the DO boundary for authoritative validation', async () => { diff --git a/apps/api/tests/unit/scripts/claude-setup-token.test.ts b/apps/api/tests/unit/scripts/claude-setup-token.test.ts index d47dd512c7..5826ba7796 100644 --- a/apps/api/tests/unit/scripts/claude-setup-token.test.ts +++ b/apps/api/tests/unit/scripts/claude-setup-token.test.ts @@ -62,7 +62,30 @@ describe('Claude setup-token driver', () => { it('joins a token wrapped by the PTY instead of accepting a truncated fragment', () => { const wrapped = `${CLAUDE_TOKEN.slice(0, 28)}\n${CLAUDE_TOKEN.slice(28)}`; - expect(extractClaudeSetupOutput(`Your token: ${wrapped}`).token).toBe(CLAUDE_TOKEN); + const ttyColumns = 'Your token: '.length + 28; + expect(extractClaudeSetupOutput(`Your token: ${wrapped}\n`, ttyColumns).token).toBe( + CLAUDE_TOKEN + ); + }); + + it('joins a legitimate short final PTY-wrapped token segment', () => { + const splitAt = CLAUDE_TOKEN.length - 15; + const wrapped = `${CLAUDE_TOKEN.slice(0, splitAt)}\n${CLAUDE_TOKEN.slice(splitAt)}`; + const ttyColumns = 'Your token: '.length + splitAt; + expect(extractClaudeSetupOutput(`Your token: ${wrapped}\n`, ttyColumns).token).toBe( + CLAUDE_TOKEN + ); + }); + + it('does not append token-like terminal prose after a wrapped token', () => { + const wrapped = `${CLAUDE_TOKEN.slice(0, 28)}\n${CLAUDE_TOKEN.slice(28)}`; + const ttyColumns = 'Your token: '.length + 28; + expect(extractClaudeSetupOutput(`Your token: ${wrapped}\nDone`, ttyColumns).token).toBe( + CLAUDE_TOKEN + ); + expect( + extractClaudeSetupOutput(`Your token: ${CLAUDE_TOKEN}\nAuthenticationComplete`).token + ).toBe(CLAUDE_TOKEN); }); it('extracts URLs from Claude terminal hyperlink output', () => { @@ -117,6 +140,9 @@ describe('Claude setup-token driver', () => { 'leaked [redacted] value' ); expect(extractOauthErrorDetail(`OAuth error: ${'x'.repeat(500)}`)).toHaveLength(160); + expect(extractOauthErrorDetail('OAth eror: Invlidcode. fullcde wascopied')).toBe( + 'Invlidcode. fullcde wascopied' + ); expect(extractOauthErrorDetail('no marker at all')).toBeNull(); }); @@ -125,6 +151,9 @@ describe('Claude setup-token driver', () => { expect(classifyOauthError('Invalidcode. Please makesure the fullcde wascopied').code).toBe( 'code_incomplete' ); + expect(classifyOauthError('Invlidcode. Please makesure the fullcde wascopied').code).toBe( + 'code_incomplete' + ); expect(classifyOauthError('Requstfailed withstatus code 400').code).toBe('code_rejected'); expect(classifyOauthError('Request failed with status code 429').code).toBe('code_rejected'); expect(classifyOauthError('connctECONNREFUSED 127.0.0.1:9').code).toBe( @@ -294,6 +323,29 @@ describe('Claude setup-token driver', () => { expect(fake.kill).toHaveBeenCalledWith('SIGTERM'); }); + it('rejects an overlong handoff before writing it to Claude stdin', async () => { + const fake = fakeClaudeProcess(); + const states: Array> = []; + const stdinWrites: string[] = []; + fake.stdin.on('data', (chunk) => stdinWrites.push(chunk.toString())); + + const ready = runClaudeSetupToken({ + ...validSetupPaths(), + spawnProcess: () => fake, + writeState: async (state) => states.push(state), + writeCredential: vi.fn().mockResolvedValue(undefined), + readVerificationCode: vi.fn().mockResolvedValue('too-long#state'), + deleteVerificationCode: vi.fn().mockResolvedValue(undefined), + verificationCodePollMs: 1, + verificationCodeMaxLength: 8, + }); + + fake.stdout.write('Open https://claude.com/cai/oauth/authorize\n'); + await ready; + await vi.waitFor(() => expect(states.at(-1)).toMatchObject({ status: 'failed' })); + expect(stdinWrites).toEqual([]); + }); + it('submits realistic-length codes even though the CLI paste widget absorbs an inline carriage return', async () => { // Discriminating regression for the 2026-07-26 production hang: model the // real Claude Code prompt, which inserts a large single chunk as pasted @@ -310,7 +362,9 @@ describe('Claude setup-token driver', () => { if (text === '\r' && pastedBuffer.length > 0) { // Standalone Enter after pasted text: the CLI submits and the exchange // fails upstream (invalid test code), rendering the Ink error screen. - fake.stdout.write('OAuth error: Request failed with status code 400\nPress Enter to retry.'); + fake.stdout.write( + 'OAuth error: Request failed with status code 400\nPress Enter to retry.' + ); return; } // Large chunk (with or without inline \r): inserted as text, not submitted. @@ -410,7 +464,9 @@ describe('Claude setup-token driver', () => { const stdinWrites: string[] = []; fake.stdin.on('data', (chunk) => stdinWrites.push(chunk.toString())); await vi.waitFor(() => expect(stdinWrites).toEqual(['A'.repeat(64), '\r'])); - fake.stdout.write('OAuth error: Invalidcode. Please makesure the fullcde wascopiedPressEntertoretry.'); + fake.stdout.write( + 'OAuth error: Invalidcode. Please makesure the fullcde wascopiedPressEntertoretry.' + ); await vi.waitFor(() => expect(states.at(-1)).toEqual({ diff --git a/apps/api/tests/unit/services/validation.test.ts b/apps/api/tests/unit/services/validation.test.ts index 7f889dd400..6ac558bff0 100644 --- a/apps/api/tests/unit/services/validation.test.ts +++ b/apps/api/tests/unit/services/validation.test.ts @@ -84,6 +84,17 @@ describe('CredentialValidator', () => { expect(validation.valid).toBe(false); expect(validation.error).toContain('too long'); }); + + it('honors a configured Claude OAuth token length limit', () => { + const validation = CredentialValidator.validateCredential( + 'sk-ant-oat01-abcdef', + 'oauth-token', + 'claude-code', + 12 + ); + expect(validation.valid).toBe(false); + expect(validation.error).toContain('too long'); + }); }); describe('validateCredential for OpenAI Codex OAuth', () => { diff --git a/apps/api/tests/workers/agent-credential-setup-sessions-routes.test.ts b/apps/api/tests/workers/agent-credential-setup-sessions-routes.test.ts index abd0ae0ca8..e3962b1d55 100644 --- a/apps/api/tests/workers/agent-credential-setup-sessions-routes.test.ts +++ b/apps/api/tests/workers/agent-credential-setup-sessions-routes.test.ts @@ -33,7 +33,7 @@ describe('agent-credential-setup-sessions REST routes reject unauthenticated req { method: 'GET', path: '/api/agent-credential-setup-sessions/config' }, { method: 'POST', path: '/api/agent-credential-setup-sessions' }, { method: 'GET', path: '/api/agent-credential-setup-sessions/fake-id' }, - { method: 'POST', path: '/api/agent-credential-setup-sessions/fake-id/credential' }, + { method: 'POST', path: '/api/agent-credential-setup-sessions/fake-id/verification-code' }, { method: 'POST', path: '/api/agent-credential-setup-sessions/fake-id/cancel' }, ]; diff --git a/apps/web/src/components/CodexConnectModal.tsx b/apps/web/src/components/CodexConnectModal.tsx index 87691db339..d107e875eb 100644 --- a/apps/web/src/components/CodexConnectModal.tsx +++ b/apps/web/src/components/CodexConnectModal.tsx @@ -119,6 +119,7 @@ export function AgentCredentialConnectModal({ const sessionIdRef = useRef(null); const finishedRef = useRef(false); const codeSubmitInFlightRef = useRef(false); + const sessionUpdateGenerationRef = useRef(0); const manualCloseTimerRef = useRef | null>(null); const onConnectedRef = useRef(onConnected); const onCloseRef = useRef(onClose); @@ -146,6 +147,7 @@ export function AgentCredentialConnectModal({ manualCloseTimerRef.current = null; sessionIdRef.current = null; finishedRef.current = false; + sessionUpdateGenerationRef.current += 1; const finish = (next: AgentCredentialSetupSession) => { if (finishedRef.current || !isTerminalAgentCredentialSetupStatus(next.status)) return; @@ -168,9 +170,15 @@ export function AgentCredentialConnectModal({ ) return; pollInFlight = true; + const generation = sessionUpdateGenerationRef.current; try { const next = await getAgentCredentialSetupSession(sessionIdRef.current); - if (cancelled) return; + if ( + cancelled || + generation !== sessionUpdateGenerationRef.current || + codeSubmitInFlightRef.current + ) + return; setSession(next); finish(next); } catch { @@ -241,6 +249,7 @@ export function AgentCredentialConnectModal({ return; } + sessionUpdateGenerationRef.current += 1; codeSubmitInFlightRef.current = true; setSubmittingCode(true); setSubmitError(null); diff --git a/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts b/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts index f4825c6526..88e9bbad56 100644 --- a/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts +++ b/apps/web/tests/playwright/agent-guided-connect-audit.spec.ts @@ -66,7 +66,8 @@ function respond(route: Route, status: number, body: unknown) { async function setupApiMocks( page: Page, seenSetupAgentTypes: string[], - seenSubmittedCodes: string[] + seenSubmittedCodes: string[], + submissionResponse: Record = COMPLETED_SETUP_SESSION ) { await page.route('**/api/**', async (route) => { const request = route.request(); @@ -120,7 +121,7 @@ async function setupApiMocks( ) { const body = request.postDataJSON() as { code?: string }; seenSubmittedCodes.push(body.code ?? ''); - return respond(route, 200, COMPLETED_SETUP_SESSION); + return respond(route, 200, submissionResponse); } if (path === `/api/agent-credential-setup-sessions/${SETUP_SESSION.id}/cancel`) { return respond(route, 200, { id: SETUP_SESSION.id, status: 'cancelled' }); @@ -228,3 +229,29 @@ test('Claude guided connect uses native URL/copy controls without terminal outpu expect(seenSubmittedCodes).toEqual([CLAUDE_SUBMITTED_CODE]); await expect(page.getByText('Claude Code connected')).toBeVisible(); }); + +test('Claude guided connect submits by keyboard and surfaces exchange failure', async ({ + page, +}) => { + const seenSetupAgentTypes: string[] = []; + const seenSubmittedCodes: string[] = []; + await setupApiMocks(page, seenSetupAgentTypes, seenSubmittedCodes, { + ...SETUP_SESSION, + status: 'failed', + errorCode: 'code_incomplete', + errorMessage: + 'The pasted code was incomplete. Copy the entire code Claude shows — it has a # in the middle — then start again.', + }); + await navigateToAgentSettings(page); + + await page.getByRole('button', { name: 'OAuth Token (Pro/Max)' }).click(); + await page.getByRole('button', { name: 'Connect with Claude Code' }).click(); + const input = page.getByLabel('Paste the code Claude shows you'); + await input.fill(CLAUDE_SUBMITTED_CODE); + await input.press('Enter'); + + expect(seenSubmittedCodes).toEqual([CLAUDE_SUBMITTED_CODE]); + await expect(page.getByRole('alert')).toContainText(/pasted code was incomplete/i); + await expect(page.getByRole('button', { name: 'Try again' })).toBeVisible(); + await assertNoOverflow(page); +}); diff --git a/apps/web/tests/unit/components/CodexConnectModal.test.tsx b/apps/web/tests/unit/components/CodexConnectModal.test.tsx index 3f67b12d67..c114eee95e 100644 --- a/apps/web/tests/unit/components/CodexConnectModal.test.tsx +++ b/apps/web/tests/unit/components/CodexConnectModal.test.tsx @@ -160,6 +160,45 @@ describe('AgentCredentialConnectModal', () => { expect(await screen.findByText(/Claude Code connected/)).toBeInTheDocument(); }); + it('ignores an older poll result after Claude code submission completes', async () => { + let resolvePoll: ((session: AgentCredentialSetupSession) => void) | undefined; + h.createAgentCredentialSetupSession.mockResolvedValue({ + kind: 'created', + session: makeSession('waiting_for_user', { + agentType: 'claude-code', + verificationUrl: CLAUDE_VERIFICATION_URL, + userCode: null, + }), + }); + h.getAgentCredentialSetupSession.mockReturnValue( + new Promise((resolve) => { + resolvePoll = resolve; + }) + ); + h.submitAgentCredentialSetupVerificationCode.mockResolvedValue( + makeSession('completed', { agentType: 'claude-code' }) + ); + + render(); + await screen.findByRole('link', { name: /open claude sign-in/i }); + await waitFor(() => expect(h.getAgentCredentialSetupSession).toHaveBeenCalledOnce()); + + fireEvent.change(screen.getByLabelText(/paste the code claude shows you/i), { + target: { value: CLAUDE_VERIFICATION_CODE }, + }); + fireEvent.click(screen.getByRole('button', { name: /continue sign-in/i })); + expect(await screen.findByText(/Claude Code connected/)).toBeInTheDocument(); + + resolvePoll?.( + makeSession('waiting_for_user', { + agentType: 'claude-code', + verificationUrl: CLAUDE_VERIFICATION_URL, + }) + ); + await Promise.resolve(); + expect(screen.getByText(/Claude Code connected/)).toBeInTheDocument(); + }); + it('blocks a Claude code paste missing its #state half before any server round-trip', async () => { // Claude's browser page shows `#`; copying only the code half // is guaranteed to fail inside the CLI, so the modal must catch it with @@ -190,9 +229,7 @@ describe('AgentCredentialConnectModal', () => { fireEvent.change(tokenInput, { target: { value: 'abc123-no-state-half' } }); fireEvent.click(screen.getByRole('button', { name: /continue sign-in/i })); - expect( - await screen.findByText(/copy the entire code claude shows/i) - ).toBeInTheDocument(); + expect(await screen.findByText(/copy the entire code claude shows/i)).toBeInTheDocument(); expect(h.submitAgentCredentialSetupVerificationCode).not.toHaveBeenCalled(); }); diff --git a/apps/www/src/content/docs/docs/guides/agents.md b/apps/www/src/content/docs/docs/guides/agents.md index d990c82772..a3c32de337 100644 --- a/apps/www/src/content/docs/docs/guides/agents.md +++ b/apps/www/src/content/docs/docs/guides/agents.md @@ -16,7 +16,7 @@ SAM supports six AI coding agents. You connect the ones you want to use, then ch | **OAuth Support** | Yes (Claude Max/Pro subscriptions) | | **Get a Key** | [Anthropic Console](https://console.anthropic.com/settings/keys) | -Claude Code supports two authentication methods: an **API key** (pay-per-use) or your **Claude Max/Pro subscription**. To use a subscription, choose **Connect with Claude Code** for the [guided sign-in](#connecting-a-subscription-with-guided-sign-in) — SAM opens a Claude sign-in page and shows a copyable verification code, so you never run `claude setup-token` or paste a token by hand. Pasting a `claude setup-token` value manually is still available as a fallback. +Claude Code supports two authentication methods: an **API key** (pay-per-use) or your **Claude Max/Pro subscription**. To use a subscription, choose **Connect with Claude Code** for the [guided sign-in](#connecting-a-subscription-with-guided-sign-in) — SAM opens a Claude sign-in page, then you paste Claude's browser-displayed `code#state` value back into SAM, so you never run `claude setup-token` or paste a token by hand. Pasting a `claude setup-token` value manually is still available as a fallback. ### OpenAI Codex diff --git a/apps/www/src/content/docs/docs/reference/configuration.md b/apps/www/src/content/docs/docs/reference/configuration.md index f6f1f6a194..3c2eeacc0a 100644 --- a/apps/www/src/content/docs/docs/reference/configuration.md +++ b/apps/www/src/content/docs/docs/reference/configuration.md @@ -106,6 +106,12 @@ Sandbox runtime surfaces and is not required for guided login. | `CLAUDE_SETUP_ENTER_DELAY_MS` | `1000` | Delay before sending Enter as a separate stdin write after pasting Claude's browser-displayed code. | | `CLAUDE_SETUP_EXCHANGE_TIMEOUT_MS` | `120000` | Maximum wait for Claude's CLI code exchange before a visible timeout. | | `CLAUDE_SETUP_REJECTION_SETTLE_MS` | `400` | Wait for Claude CLI Ink redraws to settle before classifying an OAuth error. | +| `CLAUDE_SETUP_VERIFICATION_POLL_MS` | `500` | Interval for checking the sandbox handoff file for Claude's browser-displayed code. | +| `CLAUDE_SETUP_TTY_COLUMNS` | `512` | PTY width for `claude setup-token`, reducing opaque-token wrapping. | +| `CLAUDE_SETUP_OUTPUT_BUFFER_BYTES` | `32768` | Maximum in-memory Claude PTY output retained for parsing. | +| `CLAUDE_VERIFICATION_CODE_MAX_LENGTH` | `1024` | Maximum accepted length of Claude's browser-displayed `code#state` value. | +| `CLAUDE_SETUP_ERROR_DETAIL_MAX_LENGTH` | `160` | Maximum sanitized Claude CLI diagnostic length shown to the user. | +| `CLAUDE_OAUTH_TOKEN_MAX_LENGTH` | `8192` | Maximum captured Claude OAuth token length. | | `SETUP_SESSION_SWEEP_MAX_CANDIDATES` | `50` | Maximum expired sessions cleaned up by one scheduled sweep. | | `POOL_LEASE_BUFFER_MS` | `300000` | Grace period after session TTL before a leaked capacity lease self-prunes. | From fe5b43d1fe27976e216a745af030f5f5730cc564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 05:52:24 +0000 Subject: [PATCH 36/57] docs(tasks): plan scheduler lifecycle race lab --- ...2026-08-15-scheduler-lifecycle-race-lab.md | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 tasks/backlog/2026-08-15-scheduler-lifecycle-race-lab.md diff --git a/tasks/backlog/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/backlog/2026-08-15-scheduler-lifecycle-race-lab.md new file mode 100644 index 0000000000..640a26df0b --- /dev/null +++ b/tasks/backlog/2026-08-15-scheduler-lifecycle-race-lab.md @@ -0,0 +1,121 @@ +# Build a scheduler lifecycle race lab + +**Priority**: High +**Created**: 2026-08-15 +**SAM task**: `01M019MMRSQB5P5K5HPCV3KC20` +**Idea**: `01M01CS8PMWKD7AX7Q88V3WWKN` + +## Problem + +Recent scheduler incidents survived the existing unit and staging checks because the failures +emerged only when independently reasonable control loops observed different lifecycle states. The +production failures included sessions whose first sleep precondition failed and then became +ineligible for retry, provisioning nodes destroyed before their owning task created a workspace, +and activity or ownership signals that were present in one store but absent from another. + +Running hundreds of real sessions for days is too slow and expensive for routine development. We +need a credential-free local test lab that compresses virtual time, deliberately interleaves +scheduler actions, and exercises the real Cloudflare persistence boundaries where atomicity matters. +The same tests must run in pull-request CI, with a larger but still local exploration profile on a +schedule. + +Staging and production-like soak tests are explicitly out of scope for this task. The pull request +must remain unmerged until Raphaël explicitly authorizes a merge. + +## Research Findings + +1. `tasks/active/2026-08-14-fix-stranded-session-sleep-cleanup.md` documents a cross-control-plane + lifecycle failure: completion happened while the ACP prompt was still active, the failed sleep + state was outside the retry selector, and sessions without snapshot rows never entered the + sweep. Existing tests asserted local call order or seeded only the happy snapshot state. +2. `tasks/archive/2026-08-07-fix-provisioning-node-cleanup-race.md` documents cleanup destroying a + newly provisioned task-owned node before its first heartbeat or workspace. The missing states + were an active task claim and the pre-heartbeat provisioning grace window. +3. The runtime recovery work found the same structural testing gap: isolated stores looked + correct, while a stale secondary heartbeat could defeat the authoritative recovering owner when + the three actors were composed. +4. `findNodeWithCapacity()` reads workspace occupancy before `createAndProvisionWorkspace()` + inserts its `creating` row. Concurrent TaskRunner Durable Objects can therefore observe the same + final slot unless placement has a durable claim or a final atomic recheck. +5. General node cleanup performs provider deletion before marking the D1 node deleted. The trial + cleanup path already demonstrates a safer `destroying` claim with a final active-workspace + predicate, which is a useful production pattern for a Workerd race slice. +6. VM-agent activity reporting reads `SessionHost.config.ProjectID`, while the server session + factory supplies workspace and session IDs but can omit the workspace runtime's project ID. + A cross-project contract test should prove that each activity event reaches its owning project. +7. The repository already has `fast-check`, Vitest, real local D1 and Durable Objects through + `@cloudflare/vitest-pool-workers`, and Go boundary injection. No external infrastructure or + credentials are required for these layers. +8. Deterministic concurrency testing works best with a virtual clock/event queue, a simple model, + explicit yield points around persistent/external boundaries, replayable seeds and shrink paths, + safety checks after every event, and a recovery phase after fault injection stops. +9. Small deterministic scenarios should run on every pull request; many more seeds and longer + traces can run in a credential-free nightly workflow. Failures must print enough seed, path, and + trace data to reproduce locally. + +## Implementation Checklist + +- [ ] Add a deterministic virtual-time scheduler lifecycle harness with generated tasks, sessions, + workspaces, nodes, transient failures, stale observations, and explicit interleavings. +- [ ] Check safety invariants after every simulated transition and liveness/convergence invariants + after faults stop and all due recovery work drains. +- [ ] Add historical calibration scenarios proving the oracle rejects the stranded sleep-retry and + provisioning-cleanup behaviors from the recent production incidents. +- [ ] Add a bounded pull-request profile with reproducible seed/path diagnostics. +- [ ] Add a deeper credential-free nightly profile that explores more seeds, longer traces, and + larger small-world state spaces without calling staging or cloud providers. +- [ ] Add Workerd vertical slices using real local D1/Durable Objects for cleanup-versus-placement, + capacity contention, and cross-store session retry/reconciliation races where applicable. +- [ ] Fix any scheduler atomicity or ownership defects the discriminating tests expose, preserving + a regression test for each fix. +- [ ] Add a VM-agent contract test for project-scoped activity routing and fix omitted project + context if reproduced. +- [ ] Wire the fast profile into pull-request CI and the deep profile into a scheduled/manual CI + workflow using pinned actions and no external credentials. +- [ ] Run the fast and Workerd suites repeatedly locally, run the deeper profile enough times to + collect useful evidence, and document which recent incident classes they detect. +- [ ] Run full affected-package lint, typecheck, unit, Workers, and Go quality gates. +- [ ] Complete task, test, Cloudflare, Go, constitution, and documentation review as applicable. +- [ ] Open and maintain a draft PR, push meaningful increments frequently, and do not merge without + explicit authorization. + +## Acceptance Criteria + +- Pull-request CI runs a deterministic, credential-free lifecycle simulation in minutes, not hours, + and failures include a replayable seed/path plus a minimized or bounded trace. +- The harness models multiple projects, tasks, sessions, workspaces, and nodes; asynchronous + lifecycle actions can be reordered at named persistence and external-I/O boundaries. +- Safety invariants prevent capacity overcommit, destructive cleanup of task-owned or active + resources, duplicate live ownership, and terminal resources with no bounded cleanup/retry path. +- Once faults stop, every eligible terminal/idle session and unowned resource converges to a safe + sleeping/deleted state or an explicit bounded retry state. +- Calibration tests fail under policies equivalent to the recent stranded-session and premature + provisioning-node deletion bugs, demonstrating that the oracle is discriminating. +- Real local D1/Durable Object tests exercise the production claim/CAS paths for the highest-risk + races instead of relying only on an in-memory imitation. +- A deeper local nightly profile explores materially more schedules than the pull-request profile + and remains runnable on demand in the same workspace. +- VM-agent activity is routed with the owning workspace's project ID, including concurrent + workspaces from different projects on one node. +- Repeated local runs are green after fixes and the PR report clearly states which recent incident + classes were reproduced, which are prevented, and any remaining blind spots. +- No staging or production infrastructure is used, and the PR remains draft/unmerged pending + explicit authorization. + +## Validation Evidence + +Pending implementation. + +## References + +- `tasks/active/2026-08-14-fix-stranded-session-sleep-cleanup.md` +- `tasks/archive/2026-08-07-fix-provisioning-node-cleanup-race.md` +- `.claude/rules/35-vertical-slice-testing.md` +- `.claude/rules/47-control-loop-io-budget.md` +- `.claude/rules/53-scheduled-handler-isolation-and-liveness-signals.md` +- `apps/api/src/durable-objects/task-runner/node-selection.ts` +- `apps/api/src/durable-objects/task-runner/workspace-steps.ts` +- `apps/api/src/scheduled/node-cleanup/shared.ts` +- `apps/api/src/scheduled/trial-expire.ts` +- `apps/api/tests/workers/` +- `packages/vm-agent/internal/server/agent_ws.go` From 7418c21acbf1adbe013ae568d721904a83596a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 05:52:52 +0000 Subject: [PATCH 37/57] docs(tasks): start scheduler lifecycle race lab --- .../2026-08-15-scheduler-lifecycle-race-lab.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tasks/{backlog => active}/2026-08-15-scheduler-lifecycle-race-lab.md (100%) diff --git a/tasks/backlog/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md similarity index 100% rename from tasks/backlog/2026-08-15-scheduler-lifecycle-race-lab.md rename to tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md From 5a3a0417f1cc018ce68a6e56ac21a2c3aebc340a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 06:02:26 +0000 Subject: [PATCH 38/57] test(api): add deterministic scheduler lifecycle simulation --- apps/api/package.json | 2 + .../simulation/scheduler-lifecycle-harness.ts | 421 ++++++++++++++++++ .../simulation/scheduler-lifecycle-model.ts | 141 ++++++ .../scheduler-lifecycle-simulation.test.ts | 140 ++++++ ...2026-08-15-scheduler-lifecycle-race-lab.md | 16 +- 5 files changed, 714 insertions(+), 6 deletions(-) create mode 100644 apps/api/tests/simulation/scheduler-lifecycle-harness.ts create mode 100644 apps/api/tests/simulation/scheduler-lifecycle-model.ts create mode 100644 apps/api/tests/simulation/scheduler-lifecycle-simulation.test.ts diff --git a/apps/api/package.json b/apps/api/package.json index 79e9210fc8..cec8e6103b 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -9,6 +9,8 @@ "build": "tsc", "dev": "wrangler dev --port ${WRANGLER_PORT:-8787}", "test": "vitest run", + "test:scheduler": "vitest run tests/simulation/scheduler-lifecycle-simulation.test.ts", + "test:scheduler:nightly": "SCHEDULER_SIM_PROFILE=nightly vitest run tests/simulation/scheduler-lifecycle-simulation.test.ts", "test:debugging-workers": "vitest run --config vitest.debugging.workers.config.ts", "test:workers": "vitest run --config vitest.workers.config.ts", "test:watch": "vitest", diff --git a/apps/api/tests/simulation/scheduler-lifecycle-harness.ts b/apps/api/tests/simulation/scheduler-lifecycle-harness.ts new file mode 100644 index 0000000000..6840b0e245 --- /dev/null +++ b/apps/api/tests/simulation/scheduler-lifecycle-harness.ts @@ -0,0 +1,421 @@ +import { + CURRENT_SCHEDULER_POLICY, + type NodeStatus, + type SchedulerSimulationPolicy, + type SessionActivity, + type SimEvent, + type SimNode, + type SimSession, + type SimTask, + type SimulationCommand, + type SimWorkspace, +} from './scheduler-lifecycle-model'; + +export class SchedulerLifecycleWorld { + readonly policy: SchedulerSimulationPolicy; + readonly nodes = new Map(); + readonly workspaces = new Map(); + readonly tasks = new Map(); + readonly sessions = new Map(); + readonly trace: string[] = []; + + now = 60_000; + private eventSequence = 0; + private readonly events: SimEvent[] = []; + private snapshotFailuresRemaining = 0; + + constructor(policy: SchedulerSimulationPolicy = CURRENT_SCHEDULER_POLICY, nodeCapacity = 2) { + this.policy = policy; + this.addNode('node-0', 'running', nodeCapacity, 0); + this.addNode('node-1', 'running', nodeCapacity, 0); + this.record('world initialized'); + } + + apply(command: SimulationCommand): void { + this.record(`command ${JSON.stringify(command)}`); + switch (command.type) { + case 'submit': + this.submitTask(command.task, command.project, command.node); + break; + case 'complete': + this.completeTask(command.task); + break; + case 'activity': + this.setActivity(command.task, command.activity); + break; + case 'sleep-sweep': + this.runSleepSweep(); + break; + case 'cleanup-sweep': + this.runCleanupSweep(); + break; + case 'snapshot-failure': + this.snapshotFailuresRemaining += 1; + break; + case 'advance': + this.now += command.milliseconds; + break; + case 'run-event': + this.runNextEvent(command.choice); + break; + } + } + + submitTask(taskSlot: number, projectSlot: number, nodeChoice: number | 'new'): void { + const taskId = `task-${taskSlot}`; + if (this.tasks.has(taskId)) return; + + const task: SimTask = { + id: taskId, + projectId: `project-${projectSlot}`, + status: 'provisioning', + nodeId: null, + workspaceId: null, + sessionId: null, + }; + this.tasks.set(taskId, task); + + if (nodeChoice === 'new') { + this.provisionNodeForTask(task); + return; + } + + const preferred = this.nodes.get(`node-${nodeChoice % 2}`); + const selected = this.selectNodeWithCapacity(preferred); + if (!selected) { + this.provisionNodeForTask(task); + return; + } + + task.nodeId = selected.id; + if (this.policy.reservePlacementBeforeAsyncCreate) { + selected.reservedTaskIds.add(task.id); + } + this.schedule(0, `workspace-commit:${task.id}`, () => this.commitWorkspace(task.id)); + } + + completeTask(taskSlot: number): void { + const task = this.tasks.get(`task-${taskSlot}`); + if (!task || task.status !== 'running' || !task.sessionId) return; + const session = this.sessions.get(task.sessionId); + if (!session || session.terminal) return; + + task.status = 'completed'; + session.terminal = true; + session.sleepDueAt = this.now; + this.record(`task completed ${task.id} while activity=${session.activity}`); + + if (this.policy.synchronousTerminalSleep) { + if (session.snapshotStatus === 'missing') session.snapshotStatus = 'pending'; + this.attemptSleep(session); + } + } + + setActivity(taskSlot: number, activity: SessionActivity): void { + const task = this.tasks.get(`task-${taskSlot}`); + if (!task?.sessionId) return; + const session = this.sessions.get(task.sessionId); + if (!session || session.sleeping) return; + session.activity = activity; + } + + runSleepSweep(): void { + for (const session of this.sessions.values()) { + if (!session.terminal || session.sleeping || session.sleepDueAt === null) continue; + if (session.sleepDueAt > this.now) continue; + + if (session.snapshotStatus === 'missing') { + if (!this.policy.reconcileMissingSnapshots) continue; + session.snapshotStatus = 'pending'; + this.record(`snapshot reconciled ${session.id}`); + } + + if (!this.policy.retryIncompleteSnapshots && session.snapshotStatus !== 'available') { + continue; + } + this.attemptSleep(session); + } + } + + runCleanupSweep(): void { + for (const node of this.nodes.values()) { + if (node.status !== 'running' && node.status !== 'provisioning') continue; + if (this.activeWorkspaceCount(node.id) > 0) continue; + if (node.reservedTaskIds.size > 0) continue; + if (this.now - node.idleSince < 30_000) continue; + if (this.policy.protectProvisioningClaims && node.claimedTaskIds.size > 0) continue; + + node.status = 'destroying'; + this.record(`node claimed for cleanup ${node.id}`); + this.schedule(0, `node-delete:${node.id}`, () => { + if (this.activeWorkspaceCount(node.id) > 0) { + node.status = 'running'; + node.idleSince = this.now; + this.record(`node cleanup released ${node.id}`); + return; + } + node.status = 'deleted'; + this.record(`node deleted ${node.id}`); + }); + } + } + + runNextEvent(choice = 0): boolean { + if (this.events.length === 0) return false; + const earliest = Math.min(...this.events.map((event) => event.dueAt)); + if (earliest > this.now) this.now = earliest; + const runnable = this.events + .filter((event) => event.dueAt <= this.now) + .sort((left, right) => left.id - right.id); + const selected = runnable[Math.abs(choice) % runnable.length]; + if (!selected) return false; + this.events.splice(this.events.indexOf(selected), 1); + this.record(`event ${selected.label}`); + selected.run(); + return true; + } + + recover(): void { + this.record('recovery phase started'); + this.snapshotFailuresRemaining = 0; + + let turns = 0; + while (turns < 500) { + turns += 1; + let changed = false; + while (this.runNextEvent(0)) changed = true; + + for (const session of this.sessions.values()) { + if (session.terminal && !session.sleeping && session.activity === 'prompting') { + session.activity = 'idle'; + changed = true; + } + } + + const sleepingBefore = [...this.sessions.values()].filter( + (session) => session.sleeping + ).length; + this.now += 1_000; + this.runSleepSweep(); + const sleepingAfter = [...this.sessions.values()].filter( + (session) => session.sleeping + ).length; + if (sleepingAfter > sleepingBefore) changed = true; + + if (!changed && this.events.length === 0) break; + } + this.record(`recovery phase stopped after ${turns} turns`); + } + + assertSafety(): void { + for (const node of this.nodes.values()) { + const active = this.activeWorkspaceCount(node.id); + if (active > node.capacity) { + this.fail(`capacity exceeded on ${node.id}: ${active}/${node.capacity}`); + } + } + + for (const workspace of this.workspaces.values()) { + if (workspace.status === 'sleeping' || workspace.status === 'deleted') continue; + const node = this.nodes.get(workspace.nodeId); + if (!node || node.status === 'destroying' || node.status === 'deleted') { + this.fail( + `active workspace ${workspace.id} is attached to ${node?.status ?? 'missing'} node ${workspace.nodeId}` + ); + } + } + + for (const task of this.tasks.values()) { + if (task.status === 'completed' || !task.nodeId) continue; + const node = this.nodes.get(task.nodeId); + if (!node || node.status === 'destroying' || node.status === 'deleted') { + this.fail( + `active task ${task.id} is attached to ${node?.status ?? 'missing'} node ${task.nodeId}` + ); + } + } + + const liveWorkspaceOwners = new Set(); + for (const workspace of this.workspaces.values()) { + if (workspace.status === 'deleted') continue; + if (liveWorkspaceOwners.has(workspace.taskId)) { + this.fail(`task ${workspace.taskId} owns multiple live workspaces`); + } + liveWorkspaceOwners.add(workspace.taskId); + } + } + + assertConverged(): void { + for (const session of this.sessions.values()) { + if (session.terminal && !session.sleeping) { + this.fail( + `terminal session ${session.id} did not converge (snapshot=${session.snapshotStatus}, attempts=${session.attempts})` + ); + } + } + for (const workspace of this.workspaces.values()) { + const session = this.sessions.get(workspace.sessionId); + if (session?.terminal && workspace.status !== 'sleeping' && workspace.status !== 'deleted') { + this.fail(`terminal workspace ${workspace.id} remained ${workspace.status}`); + } + } + } + + traceText(): string { + return this.trace.slice(-120).join('\n'); + } + + private addNode(id: string, status: NodeStatus, capacity: number, createdAt: number): SimNode { + const node: SimNode = { + id, + status, + capacity, + createdAt, + idleSince: createdAt, + claimedTaskIds: new Set(), + reservedTaskIds: new Set(), + }; + this.nodes.set(id, node); + return node; + } + + private selectNodeWithCapacity(preferred: SimNode | undefined): SimNode | null { + const ordered = preferred + ? [preferred, ...[...this.nodes.values()].filter((node) => node !== preferred)] + : [...this.nodes.values()]; + for (const node of ordered) { + if (node.status !== 'running') continue; + const reservations = this.policy.reservePlacementBeforeAsyncCreate + ? node.reservedTaskIds.size + node.claimedTaskIds.size + : 0; + if (this.activeWorkspaceCount(node.id) + reservations < node.capacity) return node; + } + return null; + } + + private provisionNodeForTask(task: SimTask): void { + const nodeId = `node-auto-${task.id}`; + const node = this.nodes.get(nodeId) ?? this.addNode(nodeId, 'provisioning', 1, this.now); + node.claimedTaskIds.add(task.id); + task.nodeId = node.id; + this.schedule(5_000, `node-ready:${task.id}`, () => { + const currentTask = this.tasks.get(task.id); + const currentNode = this.nodes.get(node.id); + if (!currentTask || !currentNode) return; + if (currentNode.status === 'deleted') { + this.record(`node readiness lost for ${task.id}`); + return; + } + currentNode.status = 'running'; + this.schedule(0, `workspace-commit:${task.id}`, () => this.commitWorkspace(task.id)); + }); + } + + private commitWorkspace(taskId: string): void { + const task = this.tasks.get(taskId); + if (!task || task.workspaceId || !task.nodeId) return; + const node = this.nodes.get(task.nodeId); + + if ( + this.policy.recheckPlacementAtCommit && + (!node || + node.status !== 'running' || + (!node.reservedTaskIds.has(task.id) && this.activeWorkspaceCount(node.id) >= node.capacity)) + ) { + if (node) node.reservedTaskIds.delete(task.id); + task.nodeId = null; + this.provisionNodeForTask(task); + return; + } + if (!node) return; + + const workspaceId = `workspace-${task.id}`; + const sessionId = `session-${task.id}`; + this.workspaces.set(workspaceId, { + id: workspaceId, + nodeId: node.id, + projectId: task.projectId, + taskId: task.id, + sessionId, + status: 'running', + }); + this.sessions.set(sessionId, { + id: sessionId, + projectId: task.projectId, + taskId: task.id, + workspaceId, + activity: 'prompting', + terminal: false, + sleeping: false, + snapshotStatus: 'missing', + sleepDueAt: null, + attempts: 0, + }); + node.claimedTaskIds.delete(task.id); + node.reservedTaskIds.delete(task.id); + task.workspaceId = workspaceId; + task.sessionId = sessionId; + task.status = 'running'; + this.record(`workspace committed ${workspaceId} to ${node.id}`); + } + + private attemptSleep(session: SimSession): void { + if (session.activity === 'prompting') { + if (this.policy.promptingConsumesSleepAttempt) { + session.attempts += 1; + session.snapshotStatus = 'failed'; + } + session.sleepDueAt = this.now + 1_000; + this.record(`sleep deferred ${session.id} attempts=${session.attempts}`); + return; + } + + session.attempts += 1; + if (this.snapshotFailuresRemaining > 0) { + this.snapshotFailuresRemaining -= 1; + session.snapshotStatus = 'failed'; + session.sleepDueAt = this.now + 1_000; + this.record(`snapshot failed ${session.id}`); + return; + } + + session.snapshotStatus = 'available'; + session.sleeping = true; + session.sleepDueAt = null; + const workspace = this.workspaces.get(session.workspaceId); + if (workspace) { + workspace.status = 'sleeping'; + const node = this.nodes.get(workspace.nodeId); + if (node) node.idleSince = this.now; + } + this.record(`session slept ${session.id}`); + } + + private activeWorkspaceCount(nodeId: string): number { + return [...this.workspaces.values()].filter( + (workspace) => + workspace.nodeId === nodeId && + (workspace.status === 'creating' || workspace.status === 'running') + ).length; + } + + private schedule(delayMs: number, label: string, run: () => void): void { + this.events.push({ + id: this.eventSequence, + dueAt: this.now + delayMs, + label, + run, + }); + this.eventSequence += 1; + this.record(`scheduled ${label} at ${this.now + delayMs}`); + } + + private record(message: string): void { + this.trace.push(`${this.now.toString().padStart(8, '0')} ${message}`); + if (this.trace.length > 400) this.trace.shift(); + } + + private fail(message: string): never { + throw new Error(`${message}\n--- scheduler simulation trace ---\n${this.traceText()}`); + } +} diff --git a/apps/api/tests/simulation/scheduler-lifecycle-model.ts b/apps/api/tests/simulation/scheduler-lifecycle-model.ts new file mode 100644 index 0000000000..6836b4e671 --- /dev/null +++ b/apps/api/tests/simulation/scheduler-lifecycle-model.ts @@ -0,0 +1,141 @@ +export type NodeStatus = 'provisioning' | 'running' | 'destroying' | 'deleted'; +export type WorkspaceStatus = 'creating' | 'running' | 'sleeping' | 'deleted'; +export type TaskStatus = 'provisioning' | 'running' | 'completed'; +export type SessionActivity = 'prompting' | 'idle'; +export type SnapshotStatus = 'missing' | 'pending' | 'available' | 'failed'; + +export interface SchedulerSimulationPolicy { + reservePlacementBeforeAsyncCreate: boolean; + protectProvisioningClaims: boolean; + recheckPlacementAtCommit: boolean; + reconcileMissingSnapshots: boolean; + retryIncompleteSnapshots: boolean; + synchronousTerminalSleep: boolean; + promptingConsumesSleepAttempt: boolean; +} + +export const CURRENT_SCHEDULER_POLICY: SchedulerSimulationPolicy = { + reservePlacementBeforeAsyncCreate: true, + protectProvisioningClaims: true, + recheckPlacementAtCommit: true, + reconcileMissingSnapshots: true, + retryIncompleteSnapshots: true, + synchronousTerminalSleep: false, + promptingConsumesSleepAttempt: false, +}; + +export const STRANDED_SLEEP_POLICY: SchedulerSimulationPolicy = { + ...CURRENT_SCHEDULER_POLICY, + reconcileMissingSnapshots: false, + retryIncompleteSnapshots: false, + synchronousTerminalSleep: true, + promptingConsumesSleepAttempt: true, +}; + +export const PREMATURE_CLEANUP_POLICY: SchedulerSimulationPolicy = { + ...CURRENT_SCHEDULER_POLICY, + protectProvisioningClaims: false, +}; + +export const CAPACITY_TOCTOU_POLICY: SchedulerSimulationPolicy = { + ...CURRENT_SCHEDULER_POLICY, + reservePlacementBeforeAsyncCreate: false, + recheckPlacementAtCommit: false, +}; + +export interface SimNode { + id: string; + status: NodeStatus; + capacity: number; + createdAt: number; + idleSince: number; + claimedTaskIds: Set; + reservedTaskIds: Set; +} + +export interface SimWorkspace { + id: string; + nodeId: string; + projectId: string; + taskId: string; + sessionId: string; + status: WorkspaceStatus; +} + +export interface SimTask { + id: string; + projectId: string; + status: TaskStatus; + nodeId: string | null; + workspaceId: string | null; + sessionId: string | null; +} + +export interface SimSession { + id: string; + projectId: string; + taskId: string; + workspaceId: string; + activity: SessionActivity; + terminal: boolean; + sleeping: boolean; + snapshotStatus: SnapshotStatus; + sleepDueAt: number | null; + attempts: number; +} + +export interface SimEvent { + id: number; + dueAt: number; + label: string; + run: () => void; +} + +export type SimulationCommand = + | { type: 'submit'; task: number; project: number; node: number | 'new' } + | { type: 'complete'; task: number } + | { type: 'activity'; task: number; activity: SessionActivity } + | { type: 'sleep-sweep' } + | { type: 'cleanup-sweep' } + | { type: 'snapshot-failure' } + | { type: 'advance'; milliseconds: number } + | { type: 'run-event'; choice: number }; + +export interface SimulationProfile { + numRuns: number; + maxCommands: number; + taskSlots: number; + projectCount: number; +} + +const PR_PROFILE: SimulationProfile = { + numRuns: 200, + maxCommands: 60, + taskSlots: 12, + projectCount: 3, +}; + +const NIGHTLY_PROFILE: SimulationProfile = { + numRuns: 2_000, + maxCommands: 160, + taskSlots: 32, + projectCount: 6, +}; + +function positiveInteger(value: string | undefined, fallback: number): number { + if (!value) return fallback; + const parsed = Number.parseInt(value, 10); + return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback; +} + +export function resolveSimulationProfile( + environment: NodeJS.ProcessEnv = process.env +): SimulationProfile { + const base = environment.SCHEDULER_SIM_PROFILE === 'nightly' ? NIGHTLY_PROFILE : PR_PROFILE; + return { + numRuns: positiveInteger(environment.SCHEDULER_SIM_RUNS, base.numRuns), + maxCommands: positiveInteger(environment.SCHEDULER_SIM_MAX_COMMANDS, base.maxCommands), + taskSlots: positiveInteger(environment.SCHEDULER_SIM_TASK_SLOTS, base.taskSlots), + projectCount: positiveInteger(environment.SCHEDULER_SIM_PROJECTS, base.projectCount), + }; +} diff --git a/apps/api/tests/simulation/scheduler-lifecycle-simulation.test.ts b/apps/api/tests/simulation/scheduler-lifecycle-simulation.test.ts new file mode 100644 index 0000000000..13734ab4ac --- /dev/null +++ b/apps/api/tests/simulation/scheduler-lifecycle-simulation.test.ts @@ -0,0 +1,140 @@ +import fc from 'fast-check'; + +import { SchedulerLifecycleWorld } from './scheduler-lifecycle-harness'; +import { + CAPACITY_TOCTOU_POLICY, + CURRENT_SCHEDULER_POLICY, + PREMATURE_CLEANUP_POLICY, + resolveSimulationProfile, + type SimulationCommand, + STRANDED_SLEEP_POLICY, +} from './scheduler-lifecycle-model'; + +const profile = resolveSimulationProfile(); + +const taskCommand = fc.record({ + type: fc.constant<'submit'>('submit'), + task: fc.integer({ min: 0, max: profile.taskSlots - 1 }), + project: fc.integer({ min: 0, max: profile.projectCount - 1 }), + node: fc.oneof(fc.integer({ min: 0, max: 1 }), fc.constant<'new'>('new')), +}); + +const commandArbitrary: fc.Arbitrary = fc.oneof( + { weight: 5, arbitrary: taskCommand }, + { + weight: 4, + arbitrary: fc.record({ + type: fc.constant<'complete'>('complete'), + task: fc.integer({ min: 0, max: profile.taskSlots - 1 }), + }), + }, + { + weight: 3, + arbitrary: fc.record({ + type: fc.constant<'activity'>('activity'), + task: fc.integer({ min: 0, max: profile.taskSlots - 1 }), + activity: fc.constantFrom<'prompting' | 'idle'>('prompting', 'idle'), + }), + }, + { weight: 3, arbitrary: fc.constant({ type: 'sleep-sweep' }) }, + { weight: 2, arbitrary: fc.constant({ type: 'cleanup-sweep' }) }, + { weight: 1, arbitrary: fc.constant({ type: 'snapshot-failure' }) }, + { + weight: 3, + arbitrary: fc.record({ + type: fc.constant<'advance'>('advance'), + milliseconds: fc.integer({ min: 0, max: 60_000 }), + }), + }, + { + weight: 5, + arbitrary: fc.record({ + type: fc.constant<'run-event'>('run-event'), + choice: fc.nat({ max: profile.taskSlots * 2 }), + }), + } +); + +function execute(world: SchedulerLifecycleWorld, commands: SimulationCommand[]): void { + for (const command of commands) { + world.apply(command); + world.assertSafety(); + } +} + +describe('scheduler lifecycle simulation calibration', () => { + it('rejects the stranded completed-session retry behavior from the sleep incident', () => { + const world = new SchedulerLifecycleWorld(STRANDED_SLEEP_POLICY, 1); + world.submitTask(0, 0, 0); + world.runNextEvent(); + world.completeTask(0); + world.setActivity(0, 'idle'); + world.now += 5_000; + world.runSleepSweep(); + world.recover(); + + expect(() => world.assertConverged()).toThrow(/terminal session .* did not converge/); + }); + + it('rejects cleanup that deletes a pre-heartbeat task-owned provisioning node', () => { + const world = new SchedulerLifecycleWorld(PREMATURE_CLEANUP_POLICY, 1); + world.submitTask(0, 0, 'new'); + world.now += 31_000; + world.runCleanupSweep(); + + expect(() => world.assertSafety()).toThrow(/active task .* destroying node/); + }); + + it('rejects two placements that both observe the final node slot', () => { + const world = new SchedulerLifecycleWorld(CAPACITY_TOCTOU_POLICY, 1); + world.submitTask(0, 0, 0); + world.submitTask(1, 1, 0); + world.runNextEvent(); + world.runNextEvent(); + + expect(() => world.assertSafety()).toThrow(/capacity exceeded/); + }); + + it('accepts the same incident schedules with durable claims and retry coverage', () => { + const world = new SchedulerLifecycleWorld(CURRENT_SCHEDULER_POLICY, 1); + world.submitTask(0, 0, 'new'); + world.runCleanupSweep(); + world.runNextEvent(); + world.runNextEvent(); + world.completeTask(0); + world.runSleepSweep(); + world.setActivity(0, 'idle'); + world.now += 5_000; + world.runSleepSweep(); + world.recover(); + + world.assertSafety(); + world.assertConverged(); + }); +}); + +describe(`scheduler lifecycle generated exploration (${profile.numRuns} runs)`, () => { + it('preserves safety under faults and converges after faults stop', () => { + const seed = process.env.FC_SEED ? Number.parseInt(process.env.FC_SEED, 10) : undefined; + const path = process.env.FC_PATH; + + fc.assert( + fc.property( + fc.array(commandArbitrary, { minLength: 10, maxLength: profile.maxCommands }), + (commands) => { + const world = new SchedulerLifecycleWorld(CURRENT_SCHEDULER_POLICY); + execute(world, commands); + world.recover(); + world.assertSafety(); + world.assertConverged(); + } + ), + { + numRuns: profile.numRuns, + seed, + path, + verbose: 2, + } + ); + }); +}); diff --git a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md index 640a26df0b..d76fda0b8a 100644 --- a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md +++ b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md @@ -55,14 +55,14 @@ must remain unmerged until Raphaël explicitly authorizes a merge. ## Implementation Checklist -- [ ] Add a deterministic virtual-time scheduler lifecycle harness with generated tasks, sessions, +- [x] Add a deterministic virtual-time scheduler lifecycle harness with generated tasks, sessions, workspaces, nodes, transient failures, stale observations, and explicit interleavings. -- [ ] Check safety invariants after every simulated transition and liveness/convergence invariants +- [x] Check safety invariants after every simulated transition and liveness/convergence invariants after faults stop and all due recovery work drains. -- [ ] Add historical calibration scenarios proving the oracle rejects the stranded sleep-retry and +- [x] Add historical calibration scenarios proving the oracle rejects the stranded sleep-retry and provisioning-cleanup behaviors from the recent production incidents. -- [ ] Add a bounded pull-request profile with reproducible seed/path diagnostics. -- [ ] Add a deeper credential-free nightly profile that explores more seeds, longer traces, and +- [x] Add a bounded pull-request profile with reproducible seed/path diagnostics. +- [x] Add a deeper credential-free nightly profile that explores more seeds, longer traces, and larger small-world state spaces without calling staging or cloud providers. - [ ] Add Workerd vertical slices using real local D1/Durable Objects for cleanup-versus-placement, capacity contention, and cross-store session retry/reconciliation races where applicable. @@ -104,7 +104,11 @@ must remain unmerged until Raphaël explicitly authorizes a merge. ## Validation Evidence -Pending implementation. +- Baseline scheduler lifecycle suites: 4 files and 82 tests passed. +- Pull-request simulation profile: 200 generated runs passed after calibration. +- Nightly simulation profile: 2,000 generated runs passed locally. +- Historical calibration tests reject stranded sleep retry, premature provisioning-node cleanup, + and last-slot capacity TOCTOU policies. ## References From d8d782ac5106c9c1dd17a649ba77795143a1e0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 06:20:48 +0000 Subject: [PATCH 39/57] fix(api): make scheduler placement and cleanup atomic --- .../task-runner/workspace-steps.ts | 80 ++++-- .../src/scheduled/node-cleanup/node-phases.ts | 24 +- apps/api/src/scheduled/node-cleanup/shared.ts | 163 ++++++++++--- apps/api/src/services/workspace-placement.ts | 80 ++++++ .../tests/unit/recovery-resilience.test.ts | 2 +- .../workers/scheduler-lifecycle-races.test.ts | 228 ++++++++++++++++++ ...2026-08-15-scheduler-lifecycle-race-lab.md | 6 +- 7 files changed, 515 insertions(+), 68 deletions(-) create mode 100644 apps/api/src/services/workspace-placement.ts create mode 100644 apps/api/tests/workers/scheduler-lifecycle-races.test.ts diff --git a/apps/api/src/durable-objects/task-runner/workspace-steps.ts b/apps/api/src/durable-objects/task-runner/workspace-steps.ts index 4ebb43a4c2..334e61d416 100644 --- a/apps/api/src/durable-objects/task-runner/workspace-steps.ts +++ b/apps/api/src/durable-objects/task-runner/workspace-steps.ts @@ -3,12 +3,17 @@ * * Handles workspace_creation, workspace_dispatch, workspace_ready, and attachment_transfer steps. */ -import { type CredentialSource, DEFAULT_WORKSPACE_PROFILE } from '@simple-agent-manager/shared'; +import { + type CredentialSource, + DEFAULT_MAX_WORKSPACES_PER_NODE, + DEFAULT_WORKSPACE_PROFILE, +} from '@simple-agent-manager/shared'; import { log } from '../../lib/logger'; import type { DevcontainerCacheCredentials } from '../../services/devcontainer-cache'; import { getExternalInstallationId } from '../../services/github-installation-ids'; -import { computeBackoffMs, isTransientError } from './helpers'; +import { reserveWorkspacePlacement } from '../../services/workspace-placement'; +import { computeBackoffMs, isTransientError, parseEnvInt } from './helpers'; import { ensureSessionLinked } from './state-machine'; import type { TaskRunnerContext, TaskRunnerState } from './types'; @@ -43,7 +48,8 @@ export async function handleWorkspaceCreation( // proceeding with delegation and dispatch. await ensureWorkspaceBookkeeping(state, rc, state.stepResults.workspaceId); } else { - await createAndProvisionWorkspace(state, rc); + const created = await createAndProvisionWorkspace(state, rc); + if (!created) return; } // Transition task: queued → delegated (optimistic locking) @@ -125,7 +131,7 @@ async function isTaskDelegated(state: TaskRunnerState, rc: TaskRunnerContext): P async function createAndProvisionWorkspace( state: TaskRunnerState, rc: TaskRunnerContext -): Promise { +): Promise { const { ulid } = await import('../../lib/ulid'); const { resolveUniqueWorkspaceDisplayName } = await import('../../services/workspace-names'); const { drizzle } = await import('drizzle-orm/d1'); @@ -141,26 +147,51 @@ async function createAndProvisionWorkspace( const uniqueName = await resolveUniqueWorkspaceDisplayName(db, nodeId, workspaceName); const now = new Date().toISOString(); - await db.insert(schema.workspaces).values({ - id: workspaceId, - nodeId, - projectId: state.projectId, - userId: state.userId, - installationId: state.config.installationId, - name: workspaceName, - displayName: uniqueName.displayName, - normalizedDisplayName: uniqueName.normalizedDisplayName, - repository: state.config.repository, - branch: state.config.branch, - status: 'creating', - vmSize: state.config.vmSize, - vmLocation: state.config.vmLocation, - workspaceProfile: state.config.workspaceProfile ?? DEFAULT_WORKSPACE_PROFILE, - devcontainerConfigName: state.config.devcontainerConfigName ?? null, - agentProfileHint: state.config.agentProfileHint ?? null, - createdAt: now, - updatedAt: now, - }); + const maxWorkspaces = + state.config.projectScaling?.maxWorkspacesPerNode ?? + parseEnvInt(rc.env.MAX_WORKSPACES_PER_NODE, DEFAULT_MAX_WORKSPACES_PER_NODE); + const placementReserved = await reserveWorkspacePlacement( + rc.env.DATABASE, + { + id: workspaceId, + nodeId, + projectId: state.projectId, + userId: state.userId, + installationId: state.config.installationId, + name: workspaceName, + displayName: uniqueName.displayName, + normalizedDisplayName: uniqueName.normalizedDisplayName, + repository: state.config.repository, + branch: state.config.branch, + vmSize: state.config.vmSize, + vmLocation: state.config.vmLocation, + workspaceProfile: state.config.workspaceProfile ?? DEFAULT_WORKSPACE_PROFILE, + devcontainerConfigName: state.config.devcontainerConfigName ?? null, + agentProfileHint: state.config.agentProfileHint ?? null, + createdAt: now, + }, + maxWorkspaces + ); + + if (!placementReserved) { + log.warn('task_runner_do.workspace_placement_lost', { + taskId: state.taskId, + nodeId, + maxWorkspaces, + preferredNode: state.config.preferredNodeId === nodeId, + }); + if (state.config.preferredNodeId === nodeId) { + throw Object.assign( + new Error('Specified node lost capacity or became unavailable before workspace creation'), + { permanent: true } + ); + } + state.stepResults.nodeId = null; + state.stepResults.autoProvisioned = false; + state.stepResults.provisionedVmSize = null; + await rc.advanceToStep(state, 'node_selection'); + return false; + } await rc.env.DATABASE.prepare(`UPDATE tasks SET workspace_id = ?, updated_at = ? WHERE id = ?`) .bind(workspaceId, now, state.taskId) @@ -171,6 +202,7 @@ async function createAndProvisionWorkspace( await startComputeTrackingBestEffort(state, rc, db, workspaceId, nodeId); await ensureWorkspaceBookkeeping(state, rc, workspaceId, now); await rc.ctx.storage.put('state', state); + return true; } async function ensureWorkspaceBookkeeping( diff --git a/apps/api/src/scheduled/node-cleanup/node-phases.ts b/apps/api/src/scheduled/node-cleanup/node-phases.ts index 9b64b95043..9f7a326f74 100644 --- a/apps/api/src/scheduled/node-cleanup/node-phases.ts +++ b/apps/api/src/scheduled/node-cleanup/node-phases.ts @@ -134,7 +134,7 @@ export async function sweepStaleWarmNodes( ): Promise { const staleThreshold = new Date(now.getTime() - config.gracePeriodMs).toISOString(); const candidates = await env.DATABASE.prepare( - `SELECT n.id, n.user_id, n.warm_since, + `SELECT n.id, n.user_id, n.status, n.warm_since, COUNT(CASE WHEN w.status IN ('running', 'creating', 'recovery') THEN 1 END) as active_ws_count FROM nodes n LEFT JOIN workspaces w ON w.node_id = n.id @@ -152,6 +152,7 @@ export async function sweepStaleWarmNodes( .all<{ id: string; user_id: string; + status: string; warm_since: string; active_ws_count: number; }>(); @@ -179,9 +180,9 @@ export async function sweepStaleWarmNodes( context: { warmSince: node.warm_since, gracePeriodMs: config.gracePeriodMs }, }); - if (destroyed) { + if (destroyed === 'destroyed') { result.staleDestroyed++; - } else { + } else if (destroyed === 'failed') { result.errors++; } } @@ -277,6 +278,7 @@ export async function sweepMaxLifetimeNodes( : 'max_lifetime_node_cleanup', failureRecoveryType: 'max_lifetime_node_cleanup_failure', failureBackoffMs: config.failureBackoffMs, + allowActiveWorkspaces: viaAbsoluteCeiling, context: { createdAt: node.created_at, lastWorkspaceActivity: node.last_activity, @@ -285,8 +287,10 @@ export async function sweepMaxLifetimeNodes( }, }); - if (destroyed) { + if (destroyed === 'destroyed') { result.lifetimeDestroyed++; + } else if (destroyed === 'skipped') { + result.lifetimeSkipped++; } else { result.errors++; } @@ -359,8 +363,10 @@ export async function sweepStoppedHandoffNodes( }, }); - if (destroyed) { + if (destroyed === 'destroyed') { result.lifetimeDestroyed++; + } else if (destroyed === 'skipped') { + result.lifetimeSkipped++; } else { result.errors++; } @@ -479,8 +485,10 @@ export async function sweepIncompatibleVmAgentNodes( }, }); - if (destroyed) { + if (destroyed === 'destroyed') { result.incompatibleDestroyed++; + } else if (destroyed === 'skipped') { + result.incompatibleSkipped++; } else { result.errors++; } @@ -556,11 +564,11 @@ export async function sweepIdleOrphanNodes( }, }); - if (destroyed) { + if (destroyed === 'destroyed') { result.orphanedNodesDestroyed++; } else { result.orphanedNodesSkipped++; - result.errors++; + if (destroyed === 'failed') result.errors++; } } } diff --git a/apps/api/src/scheduled/node-cleanup/shared.ts b/apps/api/src/scheduled/node-cleanup/shared.ts index 3e98a2d0b8..0998d43fb2 100644 --- a/apps/api/src/scheduled/node-cleanup/shared.ts +++ b/apps/api/src/scheduled/node-cleanup/shared.ts @@ -163,7 +163,10 @@ function buildCleanupConfig(env: Env): CleanupConfig { DEFAULT_NODE_ORPHAN_IDLE_TIMEOUT_MS ), stoppedTtlMs: parseMs(env.WORKSPACE_STOPPED_TTL_MS, DEFAULT_WORKSPACE_STOPPED_TTL_MS), - nodeSweepLimit: parsePositiveInt(env.NODE_CLEANUP_SWEEP_LIMIT, DEFAULT_NODE_CLEANUP_SWEEP_LIMIT), + nodeSweepLimit: parsePositiveInt( + env.NODE_CLEANUP_SWEEP_LIMIT, + DEFAULT_NODE_CLEANUP_SWEEP_LIMIT + ), workspaceSweepLimit: parsePositiveInt( env.WORKSPACE_CLEANUP_SWEEP_LIMIT, DEFAULT_WORKSPACE_CLEANUP_SWEEP_LIMIT @@ -181,6 +184,60 @@ function buildCleanupConfig(env: Env): CleanupConfig { } export type CleanupContext = Record; +export type NodeCleanupDestroyResult = 'destroyed' | 'skipped' | 'failed'; + +export async function claimNodeForCleanup( + env: Env, + node: { id: string; user_id: string; status: string }, + nowIso: string, + options: { allowActiveWorkspaces?: boolean } = {} +): Promise { + const activeWorkspaceGuard = options.allowActiveWorkspaces + ? '' + : `AND NOT EXISTS ( + SELECT 1 + FROM workspaces active_workspace + WHERE active_workspace.node_id = nodes.id + AND active_workspace.status IN ('running', 'creating', 'recovery') + )`; + const result = await env.DATABASE.prepare( + `UPDATE nodes + SET status = 'destroying', updated_at = ? + WHERE id = ? + AND user_id = ? + AND status = ? + AND node_role = 'workspace' + AND node_class != 'user-owned' + ${activeWorkspaceGuard} + AND NOT EXISTS ( + SELECT 1 + FROM tasks active_task + WHERE active_task.auto_provisioned_node_id = nodes.id + AND active_task.status IN ('queued', 'delegated', 'in_progress') + )` + ) + .bind(nowIso, node.id, node.user_id, node.status) + .run(); + + return (result.meta.changes ?? 0) > 0; +} + +async function releaseNodeCleanupClaim( + env: Env, + node: { id: string; user_id: string; status: string }, + nowIso: string, + backoffUntil: string +): Promise { + await env.DATABASE.prepare( + `UPDATE nodes + SET status = ?, cleanup_backoff_until = ?, updated_at = ? + WHERE id = ? + AND user_id = ? + AND status = 'destroying'` + ) + .bind(node.status, backoffUntil, nowIso, node.id, node.user_id) + .run(); +} export async function markNodeCleanupBackoff( env: Env, @@ -222,14 +279,13 @@ export async function markNodeCleanupBackoff( * stale-stopped-workspace phase deletes a row. That delays reaping by at most one * phase-6 window and cannot repeat, since a workspace is deleted only once. */ -export const LAST_WORKSPACE_ACTIVITY_SQL = - "COALESCE(MAX(w.updated_at), n.created_at)"; +export const LAST_WORKSPACE_ACTIVITY_SQL = 'COALESCE(MAX(w.updated_at), n.created_at)'; export async function destroyNodeForCleanup( db: CleanupDb, env: Env, nowIso: string, - node: { id: string; user_id: string }, + node: { id: string; user_id: string; status: string }, options: { logEvent: string; failureLogEvent: string; @@ -239,9 +295,23 @@ export async function destroyNodeForCleanup( failureRecoveryType: string; level?: 'info' | 'warn'; failureBackoffMs: number; + allowActiveWorkspaces?: boolean; context: CleanupContext; } -): Promise { +): Promise { + const claimed = await claimNodeForCleanup(env, node, nowIso, { + allowActiveWorkspaces: options.allowActiveWorkspaces, + }); + if (!claimed) { + log.info('node_cleanup.candidate_claim_lost', { + nodeId: node.id, + userId: node.user_id, + expectedStatus: node.status, + ...options.context, + }); + return 'skipped'; + } + try { log.info(options.logEvent, { nodeId: node.id, @@ -251,19 +321,6 @@ export async function destroyNodeForCleanup( await deleteNodeResources(node.id, node.user_id, env); - await persistError(env.OBSERVABILITY_DATABASE, { - source: 'api', - level: options.level ?? 'warn', - message: options.successMessage, - context: { - recoveryType: options.recoveryType, - nodeId: node.id, - ...options.context, - }, - userId: node.user_id, - nodeId: node.id, - }, env); - await db .update(schema.nodes) .set({ @@ -275,7 +332,31 @@ export async function destroyNodeForCleanup( }) .where(eq(schema.nodes.id, node.id)); - return true; + try { + await persistError( + env.OBSERVABILITY_DATABASE, + { + source: 'api', + level: options.level ?? 'warn', + message: options.successMessage, + context: { + recoveryType: options.recoveryType, + nodeId: node.id, + ...options.context, + }, + userId: node.user_id, + nodeId: node.id, + }, + env + ); + } catch (persistErr) { + log.error('node_cleanup.success_observability_write_failed', { + nodeId: node.id, + error: persistErr instanceof Error ? persistErr.message : String(persistErr), + }); + } + + return 'destroyed'; } catch (err) { log.error(options.failureLogEvent, { nodeId: node.id, @@ -286,24 +367,38 @@ export async function destroyNodeForCleanup( const backoffUntil = new Date( new Date(nowIso).getTime() + options.failureBackoffMs ).toISOString(); - await markNodeCleanupBackoff(env, node.id, backoffUntil); + try { + await releaseNodeCleanupClaim(env, node, nowIso, backoffUntil); + log.warn('node_cleanup.candidate_backed_off', { nodeId: node.id, backoffUntil }); + } catch (releaseErr) { + log.error('node_cleanup.candidate_claim_release_failed', { + nodeId: node.id, + error: releaseErr instanceof Error ? releaseErr.message : String(releaseErr), + }); + } try { - await persistError(env.OBSERVABILITY_DATABASE, { - source: 'api', - level: 'error', - message: - options.failureMessagePrefix + ': ' + (err instanceof Error ? err.message : String(err)), - stack: err instanceof Error ? err.stack : undefined, - context: { - recoveryType: options.failureRecoveryType, + await persistError( + env.OBSERVABILITY_DATABASE, + { + source: 'api', + level: 'error', + message: + options.failureMessagePrefix + + ': ' + + (err instanceof Error ? err.message : String(err)), + stack: err instanceof Error ? err.stack : undefined, + context: { + recoveryType: options.failureRecoveryType, + nodeId: node.id, + backoffUntil, + ...options.context, + }, + userId: node.user_id, nodeId: node.id, - backoffUntil, - ...options.context, }, - userId: node.user_id, - nodeId: node.id, - }, env); + env + ); } catch (persistErr) { log.error('node_cleanup.failure_observability_write_failed', { nodeId: node.id, @@ -311,6 +406,6 @@ export async function destroyNodeForCleanup( }); } - return false; + return 'failed'; } } diff --git a/apps/api/src/services/workspace-placement.ts b/apps/api/src/services/workspace-placement.ts new file mode 100644 index 0000000000..af5dea7eb4 --- /dev/null +++ b/apps/api/src/services/workspace-placement.ts @@ -0,0 +1,80 @@ +import type { VMLocation, VMSize, WorkspaceProfile } from '@simple-agent-manager/shared'; + +export interface WorkspacePlacementInput { + id: string; + nodeId: string; + projectId: string; + userId: string; + installationId: string; + name: string; + displayName: string; + normalizedDisplayName: string; + repository: string; + branch: string; + vmSize: VMSize; + vmLocation: VMLocation; + workspaceProfile: WorkspaceProfile; + devcontainerConfigName: string | null; + agentProfileHint: string | null; + createdAt: string; +} + +/** + * Atomically reserve one workspace slot and create its durable `creating` row. + * + * Node selection is advisory: another TaskRunner or cleanup loop can change D1 + * before workspace creation. Keeping the node-state and capacity predicates in + * the INSERT makes that final placement decision one D1 statement. Concurrent + * inserts cannot both consume the same final slot, and a cleanup claim that wins + * first changes the node out of `running`, causing this operation to return false. + */ +export async function reserveWorkspacePlacement( + database: D1Database, + input: WorkspacePlacementInput, + maxWorkspaces: number +): Promise { + const result = await database + .prepare( + `INSERT INTO workspaces + (id, node_id, project_id, user_id, installation_id, name, display_name, + normalized_display_name, repository, branch, status, vm_size, vm_location, + workspace_profile, devcontainer_config_name, agent_profile_hint, created_at, updated_at) + SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'creating', ?, ?, ?, ?, ?, ?, ? + FROM nodes n + WHERE n.id = ? + AND n.user_id = ? + AND n.status = 'running' + AND n.node_role = 'workspace' + AND ( + SELECT COUNT(*) + FROM workspaces active + WHERE active.node_id = n.id + AND active.status IN ('running', 'creating', 'recovery') + ) < ?` + ) + .bind( + input.id, + input.nodeId, + input.projectId, + input.userId, + input.installationId, + input.name, + input.displayName, + input.normalizedDisplayName, + input.repository, + input.branch, + input.vmSize, + input.vmLocation, + input.workspaceProfile, + input.devcontainerConfigName, + input.agentProfileHint, + input.createdAt, + input.createdAt, + input.nodeId, + input.userId, + maxWorkspaces + ) + .run(); + + return (result.meta.changes ?? 0) > 0; +} diff --git a/apps/api/tests/unit/recovery-resilience.test.ts b/apps/api/tests/unit/recovery-resilience.test.ts index 6c9818c944..c84608451d 100644 --- a/apps/api/tests/unit/recovery-resilience.test.ts +++ b/apps/api/tests/unit/recovery-resilience.test.ts @@ -256,7 +256,7 @@ describe('node-cleanup OBSERVABILITY_DATABASE recording (TDF-7)', () => { nodeCleanupSource.indexOf('return true;') ); const deleteIdx = helper.indexOf('deleteNodeResources'); - const recordIdx = helper.indexOf('persistError(env.OBSERVABILITY_DATABASE'); + const recordIdx = helper.indexOf('await persistError('); expect(deleteIdx).toBeGreaterThan(-1); expect(recordIdx).toBeGreaterThan(deleteIdx); }); diff --git a/apps/api/tests/workers/scheduler-lifecycle-races.test.ts b/apps/api/tests/workers/scheduler-lifecycle-races.test.ts new file mode 100644 index 0000000000..d800f1d6bd --- /dev/null +++ b/apps/api/tests/workers/scheduler-lifecycle-races.test.ts @@ -0,0 +1,228 @@ +/** + * Real workerd/D1 race slices for scheduler lifecycle ownership. + * + * These tests deliberately race the production placement and cleanup CAS + * statements. They do not mock D1, and they require no provider credentials. + */ +import { env, runInDurableObject } from 'cloudflare:test'; +import { beforeAll, describe, expect, it } from 'vitest'; + +import type { + StartTaskInput, + TaskRunner, + TaskRunnerState, +} from '../../src/durable-objects/task-runner'; +import type { Env } from '../../src/env'; +import { claimNodeForCleanup } from '../../src/scheduled/node-cleanup/shared'; +import { + reserveWorkspacePlacement, + type WorkspacePlacementInput, +} from '../../src/services/workspace-placement'; +import { + seedInstallation, + seedNode, + seedProject, + seedTask, + seedUser, + seedWorkspace, +} from './helpers/seed-d1'; + +const USER_ID = 'user-scheduler-races'; +const INSTALLATION_ID = 'installation-scheduler-races'; +const PROJECT_ID = 'project-scheduler-races'; + +beforeAll(async () => { + await seedUser(USER_ID); + await seedInstallation(INSTALLATION_ID, USER_ID); + await seedProject(PROJECT_ID, USER_ID, INSTALLATION_ID); +}); + +function placement( + workspaceId: string, + nodeId: string, + createdAt = new Date().toISOString() +): WorkspacePlacementInput { + return { + id: workspaceId, + nodeId, + projectId: PROJECT_ID, + userId: USER_ID, + installationId: INSTALLATION_ID, + name: `Workspace ${workspaceId}`, + displayName: `Workspace ${workspaceId}`, + normalizedDisplayName: workspaceId, + repository: 'test-org/scheduler-races', + branch: 'main', + vmSize: 'medium', + vmLocation: 'nbg1', + workspaceProfile: 'full', + devcontainerConfigName: null, + agentProfileHint: null, + createdAt, + }; +} + +async function nodeState(nodeId: string): Promise<{ status: string; active: number }> { + const node = await env.DATABASE.prepare('SELECT status FROM nodes WHERE id = ?') + .bind(nodeId) + .first<{ status: string }>(); + const workspaces = await env.DATABASE.prepare( + `SELECT COUNT(*) AS active + FROM workspaces + WHERE node_id = ? AND status IN ('running', 'creating', 'recovery')` + ) + .bind(nodeId) + .first<{ active: number }>(); + return { status: node?.status ?? 'missing', active: workspaces?.active ?? 0 }; +} + +function taskRunnerInput(taskId: string): StartTaskInput { + return { + taskId, + projectId: PROJECT_ID, + userId: USER_ID, + config: { + vmSize: 'medium', + vmLocation: 'nbg1', + branch: 'main', + preferredNodeId: null, + userName: 'Scheduler Race Test', + userEmail: 'scheduler-race@example.com', + githubId: null, + taskTitle: taskId, + taskDescription: null, + repository: 'test-org/scheduler-races', + installationId: INSTALLATION_ID, + outputBranch: null, + defaultBranch: 'main', + projectDefaultVmSize: null, + chatSessionId: null, + agentType: 'openai-codex', + workspaceProfile: 'full', + devcontainerConfigName: null, + cloudProvider: null, + credentialAttributionUserId: USER_ID, + credentialAttributionProjectId: null, + credentialAttributionSource: 'user', + taskMode: 'task', + model: null, + effort: null, + permissionMode: null, + opencodeProvider: null, + opencodeBaseUrl: null, + systemPromptAppend: null, + agentProfileHint: null, + attachments: null, + projectScaling: { maxWorkspacesPerNode: 1 }, + }, + }; +} + +describe('scheduler lifecycle D1 races', () => { + it('allows only one concurrent placement to consume the final node slot', async () => { + const nodeId = 'node-scheduler-final-slot'; + await seedNode(nodeId, USER_ID); + + const outcomes = await Promise.all([ + reserveWorkspacePlacement( + env.DATABASE, + placement('workspace-scheduler-final-slot-a', nodeId), + 1 + ), + reserveWorkspacePlacement( + env.DATABASE, + placement('workspace-scheduler-final-slot-b', nodeId), + 1 + ), + ]); + + expect(outcomes.filter(Boolean)).toHaveLength(1); + expect(await nodeState(nodeId)).toEqual({ status: 'running', active: 1 }); + }); + + it('serializes cleanup and placement so both cannot own the node', async () => { + const nodeId = 'node-scheduler-cleanup-placement'; + const old = new Date(Date.now() - 60_000).toISOString(); + await seedNode(nodeId, USER_ID, { createdAt: old, updatedAt: old }); + + const [cleanupClaimed, placementReserved] = await Promise.all([ + claimNodeForCleanup( + env as unknown as Env, + { id: nodeId, user_id: USER_ID, status: 'running' }, + new Date().toISOString() + ), + reserveWorkspacePlacement( + env.DATABASE, + placement('workspace-scheduler-cleanup-placement', nodeId), + 1 + ), + ]); + const state = await nodeState(nodeId); + + expect(Number(cleanupClaimed) + Number(placementReserved)).toBe(1); + expect(state).toEqual( + cleanupClaimed ? { status: 'destroying', active: 0 } : { status: 'running', active: 1 } + ); + }); + + it('keeps an active provisioning task claim out of cleanup', async () => { + const nodeId = 'node-scheduler-provisioning-claim'; + const taskId = 'task-scheduler-provisioning-claim'; + await seedNode(nodeId, USER_ID); + await seedTask(taskId, PROJECT_ID, USER_ID, { + status: 'queued', + autoProvisionedNodeId: nodeId, + executionStep: 'node_provisioning', + }); + + const claimed = await claimNodeForCleanup( + env as unknown as Env, + { id: nodeId, user_id: USER_ID, status: 'running' }, + new Date().toISOString() + ); + + expect(claimed).toBe(false); + expect(await nodeState(nodeId)).toEqual({ status: 'running', active: 0 }); + }); + + it('makes the real TaskRunner reselect when its advisory node slot was consumed', async () => { + const nodeId = 'node-scheduler-task-runner-reselect'; + const taskId = 'task-scheduler-task-runner-reselect'; + await seedNode(nodeId, USER_ID); + await seedWorkspace('workspace-scheduler-existing-occupant', nodeId, USER_ID, { + projectId: PROJECT_ID, + status: 'running', + }); + await seedTask(taskId, PROJECT_ID, USER_ID, { + status: 'queued', + executionStep: 'workspace_creation', + }); + + const stub = env.TASK_RUNNER.get( + env.TASK_RUNNER.idFromName(taskId) + ) as DurableObjectStub; + await runInDurableObject(stub, async (instance) => { + await instance.start(taskRunnerInput(taskId)); + await instance.ctx.storage.deleteAlarm(); + const state = await instance.ctx.storage.get('state'); + if (!state) throw new Error('TaskRunner state was not initialized'); + state.currentStep = 'workspace_creation'; + state.stepResults.nodeId = nodeId; + await instance.ctx.storage.put('state', state); + await instance.alarm(); + }); + + const status = await stub.getStatus(); + const task = await env.DATABASE.prepare('SELECT status, workspace_id FROM tasks WHERE id = ?') + .bind(taskId) + .first<{ status: string; workspace_id: string | null }>(); + + expect(status).toMatchObject({ + currentStep: 'node_selection', + stepResults: { nodeId: null, workspaceId: null }, + completed: false, + }); + expect(task).toEqual({ status: 'queued', workspace_id: null }); + expect(await nodeState(nodeId)).toEqual({ status: 'running', active: 1 }); + }); +}); diff --git a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md index d76fda0b8a..7aff1bea67 100644 --- a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md +++ b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md @@ -64,7 +64,7 @@ must remain unmerged until Raphaël explicitly authorizes a merge. - [x] Add a bounded pull-request profile with reproducible seed/path diagnostics. - [x] Add a deeper credential-free nightly profile that explores more seeds, longer traces, and larger small-world state spaces without calling staging or cloud providers. -- [ ] Add Workerd vertical slices using real local D1/Durable Objects for cleanup-versus-placement, +- [x] Add Workerd vertical slices using real local D1/Durable Objects for cleanup-versus-placement, capacity contention, and cross-store session retry/reconciliation races where applicable. - [ ] Fix any scheduler atomicity or ownership defects the discriminating tests expose, preserving a regression test for each fix. @@ -109,6 +109,10 @@ must remain unmerged until Raphaël explicitly authorizes a merge. - Nightly simulation profile: 2,000 generated runs passed locally. - Historical calibration tests reject stranded sleep retry, premature provisioning-node cleanup, and last-slot capacity TOCTOU policies. +- Real Workerd/D1 race slice: 4 tests passed, covering atomic final-slot placement, + cleanup-versus-placement ownership, active provisioning claims, and TaskRunner reselection. +- A new VM-agent cross-project activity test currently fails as intended: both SessionHosts omit + their workspace project from activity routing and no callback reaches the test control plane. ## References From d8239820f01d698cb30c9017d0667b1a38ef8db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 06:20:58 +0000 Subject: [PATCH 40/57] test(vm-agent): expose missing project activity routing --- .../server/session_activity_routing_test.go | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 packages/vm-agent/internal/server/session_activity_routing_test.go diff --git a/packages/vm-agent/internal/server/session_activity_routing_test.go b/packages/vm-agent/internal/server/session_activity_routing_test.go new file mode 100644 index 0000000000..6fcde73210 --- /dev/null +++ b/packages/vm-agent/internal/server/session_activity_routing_test.go @@ -0,0 +1,99 @@ +package server + +import ( + "net/http" + "net/http/httptest" + "sort" + "sync" + "testing" + "time" + + "github.com/workspace/vm-agent/internal/acp" + "github.com/workspace/vm-agent/internal/agentsessions" + "github.com/workspace/vm-agent/internal/config" + "github.com/workspace/vm-agent/internal/messagereport" +) + +func TestSessionHostActivityUsesOwningWorkspaceProject(t *testing.T) { + t.Parallel() + + var mu sync.Mutex + paths := make([]string, 0, 2) + reported := make(chan struct{}, 2) + controlPlane := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mu.Lock() + paths = append(paths, r.URL.Path) + mu.Unlock() + reported <- struct{}{} + w.WriteHeader(http.StatusNoContent) + })) + defer controlPlane.Close() + + serverConfig := &config.Config{ + NodeID: "node-routing", + ControlPlaneURL: controlPlane.URL, + CallbackToken: "node-callback-token", + ACPMessageBufferSize: 32, + ACPViewerSendBuffer: 8, + } + s := &Server{ + config: serverConfig, + acpConfig: acp.GatewayConfig{ + NodeID: serverConfig.NodeID, + ControlPlaneURL: controlPlane.URL, + CallbackToken: serverConfig.CallbackToken, + HTTPClient: controlPlane.Client(), + }, + workspaces: map[string]*WorkspaceRuntime{ + "workspace-a": {ID: "workspace-a", ProjectID: "project-a"}, + "workspace-b": {ID: "workspace-b", ProjectID: "project-b"}, + }, + agentSessions: agentsessions.NewManager(), + sessionHosts: map[string]*acp.SessionHost{}, + sessionMcpServers: map[string][]acp.McpServerEntry{}, + sessionProfileOvr: map[string]profileOverrides{}, + sessionTaskCtx: map[string]taskCallbackContext{}, + messageReporters: map[string]*messagereport.Reporter{}, + } + + for _, tc := range []struct { + workspaceID string + sessionID string + }{ + {workspaceID: "workspace-a", sessionID: "session-a"}, + {workspaceID: "workspace-b", sessionID: "session-b"}, + } { + runtime := s.workspaces[tc.workspaceID] + host := s.getOrCreateSessionHost( + tc.workspaceID+":"+tc.sessionID, + tc.workspaceID, + tc.sessionID, + agentsessions.Session{ID: tc.sessionID, WorkspaceID: tc.workspaceID}, + runtime, + "", + ) + host.Stop() + } + + for range 2 { + select { + case <-reported: + case <-time.After(500 * time.Millisecond): + t.Fatal("timed out waiting for project-scoped activity callbacks") + } + } + + mu.Lock() + sort.Strings(paths) + got := append([]string(nil), paths...) + mu.Unlock() + want := []string{ + "/api/projects/project-a/acp-sessions/session-a/activity", + "/api/projects/project-b/acp-sessions/session-b/activity", + } + for index := range want { + if got[index] != want[index] { + t.Fatalf("activity paths = %v, want %v", got, want) + } + } +} From 3b10b03b35165274de289feaf0b0c59992fe1833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 06:21:58 +0000 Subject: [PATCH 41/57] fix(vm-agent): route activity by workspace project --- packages/vm-agent/internal/server/agent_ws.go | 12 ++++++++++++ .../2026-08-15-scheduler-lifecycle-race-lab.md | 11 +++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/vm-agent/internal/server/agent_ws.go b/packages/vm-agent/internal/server/agent_ws.go index a1ca52433d..f117fdbd52 100644 --- a/packages/vm-agent/internal/server/agent_ws.go +++ b/packages/vm-agent/internal/server/agent_ws.go @@ -249,6 +249,12 @@ func (s *Server) getOrCreateSessionHost(hostKey, workspaceID, sessionID string, cfg := s.acpConfig cfg.WorkspaceID = workspaceID cfg.SessionID = sessionID + // Activity is project-scoped. Never inherit the boot workspace's project on + // a shared node; bind every SessionHost to its owning workspace runtime. + cfg.ProjectID = "" + if runtime != nil { + cfg.ProjectID = strings.TrimSpace(runtime.ProjectID) + } cfg.OnPromptComplete = nil cfg.GitTokenFetcher = s.gitHubTokenFetcherForWorkspace(workspaceID) @@ -306,6 +312,12 @@ func (s *Server) getOrCreateSessionHost(hostKey, workspaceID, sessionID string, } hasTaskCtx = true } + if cfg.ProjectID == "" && hasTaskCtx { + cfg.ProjectID = strings.TrimSpace(taskCtx.ProjectID) + } + if cfg.ProjectID == "" && s.config != nil && workspaceID == strings.TrimSpace(s.config.WorkspaceID) { + cfg.ProjectID = strings.TrimSpace(s.config.ProjectID) + } if hasTaskCtx && s.config != nil && taskCtx.ProjectID != "" && taskCtx.TaskID != "" && taskCtx.WorkspaceID != "" { cfg.OnPromptComplete = s.makeTaskCompletionCallback( s.config.ControlPlaneURL, diff --git a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md index 7aff1bea67..37c4476f22 100644 --- a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md +++ b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md @@ -66,9 +66,9 @@ must remain unmerged until Raphaël explicitly authorizes a merge. larger small-world state spaces without calling staging or cloud providers. - [x] Add Workerd vertical slices using real local D1/Durable Objects for cleanup-versus-placement, capacity contention, and cross-store session retry/reconciliation races where applicable. -- [ ] Fix any scheduler atomicity or ownership defects the discriminating tests expose, preserving +- [x] Fix any scheduler atomicity or ownership defects the discriminating tests expose, preserving a regression test for each fix. -- [ ] Add a VM-agent contract test for project-scoped activity routing and fix omitted project +- [x] Add a VM-agent contract test for project-scoped activity routing and fix omitted project context if reproduced. - [ ] Wire the fast profile into pull-request CI and the deep profile into a scheduled/manual CI workflow using pinned actions and no external credentials. @@ -111,8 +111,11 @@ must remain unmerged until Raphaël explicitly authorizes a merge. and last-slot capacity TOCTOU policies. - Real Workerd/D1 race slice: 4 tests passed, covering atomic final-slot placement, cleanup-versus-placement ownership, active provisioning claims, and TaskRunner reselection. -- A new VM-agent cross-project activity test currently fails as intended: both SessionHosts omit - their workspace project from activity routing and no callback reaches the test control plane. +- Before the fix, the new VM-agent cross-project activity test failed as intended: both + SessionHosts omitted their workspace project and no callback reached the test control plane. +- After binding SessionHosts to `WorkspaceRuntime.ProjectID`, the cross-project activity test passed + 10 consecutive runs. The broader server package reached an unrelated pre-existing Docker-backed + test that cannot run in this workspace because the Docker CLI is absent. ## References From 95e07759b2b16902e50b88b84341bd7c7318d844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 06:23:43 +0000 Subject: [PATCH 42/57] ci: explore scheduler lifecycles nightly --- .github/workflows/scheduler-lifecycle.yml | 48 +++++++++++++++++++ apps/api/tests/simulation/README.md | 47 ++++++++++++++++++ ...2026-08-15-scheduler-lifecycle-race-lab.md | 2 +- 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/scheduler-lifecycle.yml create mode 100644 apps/api/tests/simulation/README.md diff --git a/.github/workflows/scheduler-lifecycle.yml b/.github/workflows/scheduler-lifecycle.yml new file mode 100644 index 0000000000..1574e82557 --- /dev/null +++ b/.github/workflows/scheduler-lifecycle.yml @@ -0,0 +1,48 @@ +name: Scheduler Lifecycle Exploration + +on: + schedule: + - cron: '33 3 * * *' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: scheduler-lifecycle-${{ github.ref }} + cancel-in-progress: false + +jobs: + explore: + name: Explore Scheduler Lifecycles + timeout-minutes: 15 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9 + + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + with: + node-version: '22' + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build API dependencies + run: pnpm exec turbo run build --filter=@simple-agent-manager/api... + + - name: Explore generated scheduler lifecycles + run: | + set -o pipefail + pnpm --filter @simple-agent-manager/api test:scheduler:nightly 2>&1 | tee scheduler-lifecycle.log + + - name: Upload replay diagnostics + if: failure() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: scheduler-lifecycle-replay-${{ github.run_id }} + path: scheduler-lifecycle.log + if-no-files-found: error + retention-days: 14 diff --git a/apps/api/tests/simulation/README.md b/apps/api/tests/simulation/README.md new file mode 100644 index 0000000000..bbcec1b6bc --- /dev/null +++ b/apps/api/tests/simulation/README.md @@ -0,0 +1,47 @@ +# Scheduler lifecycle simulation + +This credential-free test lab compresses multi-day scheduler behavior into virtual time. It uses +small nodes with deliberately tight capacity so cleanup, placement, session sleep, retry, and stale +observation races occur frequently. + +## Run it + +```bash +# Pull-request profile: 200 generated schedules, also included in the normal API test suite +pnpm --filter @simple-agent-manager/api test:scheduler + +# Deeper local/nightly profile: 2,000 schedules with longer traces and more projects/tasks +pnpm --filter @simple-agent-manager/api test:scheduler:nightly +``` + +Fast-check prints the seed, shrink path, minimized counterexample, and the harness's named event +trace on failure. Replay the exact case with: + +```bash +FC_SEED= FC_PATH='' pnpm --filter @simple-agent-manager/api test:scheduler +``` + +`SCHEDULER_SIM_RUNS`, `SCHEDULER_SIM_MAX_COMMANDS`, `SCHEDULER_SIM_TASK_SLOTS`, and +`SCHEDULER_SIM_PROJECTS` can increase or narrow an exploratory run without changing source. + +## What it checks + +- Active workspaces never exceed node capacity. +- Cleanup never owns a node at the same time as an active task or workspace. +- A task never owns multiple live workspaces. +- Terminal sessions keep a selectable retry path and converge to sleeping after faults stop. +- Missing/incomplete snapshots are reconciled; prompting deferrals do not strand terminal sessions. + +Calibration cases deliberately enable the historical unsafe policies and prove the oracle rejects: + +- the August 14 completed-while-prompting sleep retry gap; +- cleanup of a pre-heartbeat task-owned provisioning node; +- two TaskRunners observing and consuming the same final node slot. + +The adjacent Workerd suite in `tests/workers/scheduler-lifecycle-races.test.ts` uses the real local D1 +and TaskRunner Durable Object to verify the production placement/cleanup claims. The VM-agent Go +contract verifies activity from multiple workspaces on one node is routed to each owning project. + +This lab does not emulate cloud-provider behavior, real containers, network throughput, or long-run +resource exhaustion. Those remain integration/soak concerns; no staging or cloud credentials are +used here. diff --git a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md index 37c4476f22..ab3b73ee3a 100644 --- a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md +++ b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md @@ -70,7 +70,7 @@ must remain unmerged until Raphaël explicitly authorizes a merge. a regression test for each fix. - [x] Add a VM-agent contract test for project-scoped activity routing and fix omitted project context if reproduced. -- [ ] Wire the fast profile into pull-request CI and the deep profile into a scheduled/manual CI +- [x] Wire the fast profile into pull-request CI and the deep profile into a scheduled/manual CI workflow using pinned actions and no external credentials. - [ ] Run the fast and Workerd suites repeatedly locally, run the deeper profile enough times to collect useful evidence, and document which recent incident classes they detect. From fe74505bd0d146bc6402e0cf84d5f17afccbc921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 06:28:10 +0000 Subject: [PATCH 43/57] test(api): repeat real D1 scheduler races --- .../workers/scheduler-lifecycle-races.test.ts | 102 +++++++++++------- ...2026-08-15-scheduler-lifecycle-race-lab.md | 5 +- 2 files changed, 65 insertions(+), 42 deletions(-) diff --git a/apps/api/tests/workers/scheduler-lifecycle-races.test.ts b/apps/api/tests/workers/scheduler-lifecycle-races.test.ts index d800f1d6bd..7c4803108d 100644 --- a/apps/api/tests/workers/scheduler-lifecycle-races.test.ts +++ b/apps/api/tests/workers/scheduler-lifecycle-races.test.ts @@ -30,6 +30,7 @@ import { const USER_ID = 'user-scheduler-races'; const INSTALLATION_ID = 'installation-scheduler-races'; const PROJECT_ID = 'project-scheduler-races'; +const RACE_REPETITIONS = 24; beforeAll(async () => { await seedUser(USER_ID); @@ -120,49 +121,70 @@ function taskRunnerInput(taskId: string): StartTaskInput { describe('scheduler lifecycle D1 races', () => { it('allows only one concurrent placement to consume the final node slot', async () => { - const nodeId = 'node-scheduler-final-slot'; - await seedNode(nodeId, USER_ID); - - const outcomes = await Promise.all([ - reserveWorkspacePlacement( - env.DATABASE, - placement('workspace-scheduler-final-slot-a', nodeId), - 1 - ), - reserveWorkspacePlacement( - env.DATABASE, - placement('workspace-scheduler-final-slot-b', nodeId), - 1 - ), - ]); - - expect(outcomes.filter(Boolean)).toHaveLength(1); - expect(await nodeState(nodeId)).toEqual({ status: 'running', active: 1 }); + for (let iteration = 0; iteration < RACE_REPETITIONS; iteration += 1) { + const nodeId = `node-scheduler-final-slot-${iteration}`; + await seedNode(nodeId, USER_ID); + + const placements = [ + () => + reserveWorkspacePlacement( + env.DATABASE, + placement(`workspace-scheduler-final-slot-${iteration}-a`, nodeId), + 1 + ), + () => + reserveWorkspacePlacement( + env.DATABASE, + placement(`workspace-scheduler-final-slot-${iteration}-b`, nodeId), + 1 + ), + ]; + if (iteration % 2 === 1) placements.reverse(); + const outcomes = await Promise.all(placements.map((reserve) => reserve())); + + expect(outcomes.filter(Boolean)).toHaveLength(1); + expect(await nodeState(nodeId)).toEqual({ status: 'running', active: 1 }); + } }); it('serializes cleanup and placement so both cannot own the node', async () => { - const nodeId = 'node-scheduler-cleanup-placement'; - const old = new Date(Date.now() - 60_000).toISOString(); - await seedNode(nodeId, USER_ID, { createdAt: old, updatedAt: old }); - - const [cleanupClaimed, placementReserved] = await Promise.all([ - claimNodeForCleanup( - env as unknown as Env, - { id: nodeId, user_id: USER_ID, status: 'running' }, - new Date().toISOString() - ), - reserveWorkspacePlacement( - env.DATABASE, - placement('workspace-scheduler-cleanup-placement', nodeId), - 1 - ), - ]); - const state = await nodeState(nodeId); - - expect(Number(cleanupClaimed) + Number(placementReserved)).toBe(1); - expect(state).toEqual( - cleanupClaimed ? { status: 'destroying', active: 0 } : { status: 'running', active: 1 } - ); + for (let iteration = 0; iteration < RACE_REPETITIONS; iteration += 1) { + const nodeId = `node-scheduler-cleanup-placement-${iteration}`; + const old = new Date(Date.now() - 60_000).toISOString(); + await seedNode(nodeId, USER_ID, { createdAt: old, updatedAt: old }); + + const claimCleanup = () => + claimNodeForCleanup( + env as unknown as Env, + { id: nodeId, user_id: USER_ID, status: 'running' }, + new Date().toISOString() + ); + const reservePlacement = () => + reserveWorkspacePlacement( + env.DATABASE, + placement(`workspace-scheduler-cleanup-placement-${iteration}`, nodeId), + 1 + ); + let cleanupClaimed: boolean; + let placementReserved: boolean; + if (iteration % 2 === 0) { + [cleanupClaimed, placementReserved] = await Promise.all([ + claimCleanup(), + reservePlacement(), + ]); + } else { + [placementReserved, cleanupClaimed] = await Promise.all([ + reservePlacement(), + claimCleanup(), + ]); + } + const state = await nodeState(nodeId); + + expect(Number(cleanupClaimed) + Number(placementReserved)).toBe(1); + expect(state).toEqual( + cleanupClaimed ? { status: 'destroying', active: 0 } : { status: 'running', active: 1 } + ); + } }); it('keeps an active provisioning task claim out of cleanup', async () => { diff --git a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md index ab3b73ee3a..3c66e01e74 100644 --- a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md +++ b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md @@ -109,8 +109,9 @@ must remain unmerged until Raphaël explicitly authorizes a merge. - Nightly simulation profile: 2,000 generated runs passed locally. - Historical calibration tests reject stranded sleep retry, premature provisioning-node cleanup, and last-slot capacity TOCTOU policies. -- Real Workerd/D1 race slice: 4 tests passed, covering atomic final-slot placement, - cleanup-versus-placement ownership, active provisioning claims, and TaskRunner reselection. +- Real Workerd/D1 race slice: 4 tests passed, with 24 opposite-order repetitions each for atomic + final-slot placement and cleanup-versus-placement ownership, plus active provisioning claims and + TaskRunner reselection. - Before the fix, the new VM-agent cross-project activity test failed as intended: both SessionHosts omitted their workspace project and no callback reached the test control plane. - After binding SessionHosts to `WorkspaceRuntime.ProjectID`, the cross-project activity test passed From 76089a8ade153375d30eab9ac6b23cce8a69a18a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 06:30:07 +0000 Subject: [PATCH 44/57] test(api): support extended scheduler exploration --- apps/api/tests/simulation/README.md | 4 +- .../simulation/scheduler-lifecycle-model.ts | 4 ++ .../scheduler-lifecycle-simulation.test.ts | 46 ++++++++++--------- ...2026-08-15-scheduler-lifecycle-race-lab.md | 5 +- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/apps/api/tests/simulation/README.md b/apps/api/tests/simulation/README.md index bbcec1b6bc..a0b6c5028c 100644 --- a/apps/api/tests/simulation/README.md +++ b/apps/api/tests/simulation/README.md @@ -22,7 +22,9 @@ FC_SEED= FC_PATH='' pnpm --filter @simple-agent-manager/api test:sch ``` `SCHEDULER_SIM_RUNS`, `SCHEDULER_SIM_MAX_COMMANDS`, `SCHEDULER_SIM_TASK_SLOTS`, and -`SCHEDULER_SIM_PROJECTS` can increase or narrow an exploratory run without changing source. +`SCHEDULER_SIM_PROJECTS` can increase or narrow an exploratory run without changing source. The +nightly profile uses a bounded 60-second test timeout; `SCHEDULER_SIM_TIMEOUT_MS` can tune that +budget for larger on-demand runs. ## What it checks diff --git a/apps/api/tests/simulation/scheduler-lifecycle-model.ts b/apps/api/tests/simulation/scheduler-lifecycle-model.ts index 6836b4e671..94ed02d1e3 100644 --- a/apps/api/tests/simulation/scheduler-lifecycle-model.ts +++ b/apps/api/tests/simulation/scheduler-lifecycle-model.ts @@ -106,6 +106,7 @@ export interface SimulationProfile { maxCommands: number; taskSlots: number; projectCount: number; + testTimeoutMs: number; } const PR_PROFILE: SimulationProfile = { @@ -113,6 +114,7 @@ const PR_PROFILE: SimulationProfile = { maxCommands: 60, taskSlots: 12, projectCount: 3, + testTimeoutMs: 5_000, }; const NIGHTLY_PROFILE: SimulationProfile = { @@ -120,6 +122,7 @@ const NIGHTLY_PROFILE: SimulationProfile = { maxCommands: 160, taskSlots: 32, projectCount: 6, + testTimeoutMs: 60_000, }; function positiveInteger(value: string | undefined, fallback: number): number { @@ -137,5 +140,6 @@ export function resolveSimulationProfile( maxCommands: positiveInteger(environment.SCHEDULER_SIM_MAX_COMMANDS, base.maxCommands), taskSlots: positiveInteger(environment.SCHEDULER_SIM_TASK_SLOTS, base.taskSlots), projectCount: positiveInteger(environment.SCHEDULER_SIM_PROJECTS, base.projectCount), + testTimeoutMs: positiveInteger(environment.SCHEDULER_SIM_TIMEOUT_MS, base.testTimeoutMs), }; } diff --git a/apps/api/tests/simulation/scheduler-lifecycle-simulation.test.ts b/apps/api/tests/simulation/scheduler-lifecycle-simulation.test.ts index 13734ab4ac..b0e307bee9 100644 --- a/apps/api/tests/simulation/scheduler-lifecycle-simulation.test.ts +++ b/apps/api/tests/simulation/scheduler-lifecycle-simulation.test.ts @@ -114,27 +114,31 @@ describe('scheduler lifecycle simulation calibration', () => { }); describe(`scheduler lifecycle generated exploration (${profile.numRuns} runs)`, () => { - it('preserves safety under faults and converges after faults stop', () => { - const seed = process.env.FC_SEED ? Number.parseInt(process.env.FC_SEED, 10) : undefined; - const path = process.env.FC_PATH; + it( + 'preserves safety under faults and converges after faults stop', + () => { + const seed = process.env.FC_SEED ? Number.parseInt(process.env.FC_SEED, 10) : undefined; + const path = process.env.FC_PATH; - fc.assert( - fc.property( - fc.array(commandArbitrary, { minLength: 10, maxLength: profile.maxCommands }), - (commands) => { - const world = new SchedulerLifecycleWorld(CURRENT_SCHEDULER_POLICY); - execute(world, commands); - world.recover(); - world.assertSafety(); - world.assertConverged(); + fc.assert( + fc.property( + fc.array(commandArbitrary, { minLength: 10, maxLength: profile.maxCommands }), + (commands) => { + const world = new SchedulerLifecycleWorld(CURRENT_SCHEDULER_POLICY); + execute(world, commands); + world.recover(); + world.assertSafety(); + world.assertConverged(); + } + ), + { + numRuns: profile.numRuns, + seed, + path, + verbose: 2, } - ), - { - numRuns: profile.numRuns, - seed, - path, - verbose: 2, - } - ); - }); + ); + }, + profile.testTimeoutMs + ); }); diff --git a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md index 3c66e01e74..da5ebc7108 100644 --- a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md +++ b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md @@ -72,7 +72,7 @@ must remain unmerged until Raphaël explicitly authorizes a merge. context if reproduced. - [x] Wire the fast profile into pull-request CI and the deep profile into a scheduled/manual CI workflow using pinned actions and no external credentials. -- [ ] Run the fast and Workerd suites repeatedly locally, run the deeper profile enough times to +- [x] Run the fast and Workerd suites repeatedly locally, run the deeper profile enough times to collect useful evidence, and document which recent incident classes they detect. - [ ] Run full affected-package lint, typecheck, unit, Workers, and Go quality gates. - [ ] Complete task, test, Cloudflare, Go, constitution, and documentation review as applicable. @@ -117,6 +117,9 @@ must remain unmerged until Raphaël explicitly authorizes a merge. - After binding SessionHosts to `WorkspaceRuntime.ProjectID`, the cross-project activity test passed 10 consecutive runs. The broader server package reached an unrelated pre-existing Docker-backed test that cannot run in this workspace because the Docker CLI is absent. +- An expanded local exploration passed 100,000 generated schedules with up to 200 commands, 40 + task slots, and 8 projects in 8.58 seconds. Its first run exposed the default 5-second Vitest + ceiling, so the nightly profile now carries an explicit bounded timeout for larger runs. ## References From 6bf907a43752c4685eae54573de592984852bdc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 06:53:25 +0000 Subject: [PATCH 45/57] refactor(api): split workspace branch handling --- .../task-runner/workspace-branch.ts | 145 +++++++++++++++++ .../task-runner/workspace-steps.ts | 148 +----------------- ...2026-08-15-scheduler-lifecycle-race-lab.md | 14 +- 3 files changed, 161 insertions(+), 146 deletions(-) create mode 100644 apps/api/src/durable-objects/task-runner/workspace-branch.ts diff --git a/apps/api/src/durable-objects/task-runner/workspace-branch.ts b/apps/api/src/durable-objects/task-runner/workspace-branch.ts new file mode 100644 index 0000000000..c956a653d7 --- /dev/null +++ b/apps/api/src/durable-objects/task-runner/workspace-branch.ts @@ -0,0 +1,145 @@ +import { log } from '../../lib/logger'; +import { getExternalInstallationId } from '../../services/github-installation-ids'; +import type { TaskRunnerContext, TaskRunnerState } from './types'; + +/** + * Ensure the checkout branch exists on the remote before cloning. + * + * Best-effort: failures are logged but do not block workspace creation. The + * clone will produce the definitive error if the branch cannot be resolved. + */ +export async function ensureBranchExistsOnRemote( + state: TaskRunnerState, + rc: TaskRunnerContext +): Promise { + const defaultBranch = state.config.defaultBranch || 'main'; + if (state.config.branch === defaultBranch) return; + + const projectRepo = await loadTaskRunnerProjectRepo(state, rc); + if (projectRepo?.repoProvider === 'artifacts') return; + if (projectRepo?.repoProvider === 'gitlab') { + await ensureGitLabBranchExistsOnRemote(state, rc, defaultBranch); + return; + } + + const repoParts = state.config.repository.split('/'); + if (repoParts.length !== 2 || !repoParts[0] || !repoParts[1]) { + log.warn('task_runner_do.ensure_branch.invalid_repository', { + taskId: state.taskId, + repository: state.config.repository, + }); + return; + } + + const [owner, repo] = repoParts; + try { + const installation = await loadTaskRunnerGitHubInstallation(state, rc); + if (!installation) { + log.warn('task_runner_do.ensure_branch.installation_not_found', { + taskId: state.taskId, + installationId: state.config.installationId, + }); + return; + } + + const externalInstallationId = getExternalInstallationId(installation); + const { ensureBranchExists } = await import('../../services/github-app'); + const created = await ensureBranchExists( + externalInstallationId, + owner, + repo, + state.config.branch, + defaultBranch, + rc.env + ); + + if (created) { + log.info('task_runner_do.ensure_branch.ok', { + taskId: state.taskId, + branch: state.config.branch, + }); + } else { + log.warn('task_runner_do.ensure_branch.failed', { + taskId: state.taskId, + branch: state.config.branch, + defaultBranch, + }); + } + } catch (err) { + log.warn('task_runner_do.ensure_branch.error', { + taskId: state.taskId, + branch: state.config.branch, + error: err instanceof Error ? err.message : String(err), + }); + } +} + +async function loadTaskRunnerProjectRepo( + state: TaskRunnerState, + rc: TaskRunnerContext +): Promise<{ repoProvider: string | null } | null> { + return rc.env.DATABASE.prepare(`SELECT repo_provider AS repoProvider FROM projects WHERE id = ?`) + .bind(state.projectId) + .first<{ repoProvider: string | null }>(); +} + +async function ensureGitLabBranchExistsOnRemote( + state: TaskRunnerState, + rc: TaskRunnerContext, + defaultBranch: string +): Promise { + try { + const { drizzle } = await import('drizzle-orm/d1'); + const schema = await import('../../db/schema'); + const { ensureGitLabBranchExists, getProjectGitLabRepository } = + await import('../../services/gitlab'); + const metadata = await getProjectGitLabRepository( + drizzle(rc.env.DATABASE, { schema }), + state.projectId + ); + if (!metadata) { + log.warn('task_runner_do.ensure_branch.gitlab_metadata_missing', { + taskId: state.taskId, + projectId: state.projectId, + }); + return; + } + const created = await ensureGitLabBranchExists({ + env: rc.env, + userId: state.userId, + projectId: metadata.gitlabProjectId, + branch: state.config.branch, + ref: defaultBranch, + }); + if (created) { + log.info('task_runner_do.ensure_branch.gitlab_ok', { + taskId: state.taskId, + branch: state.config.branch, + }); + } + } catch (err) { + log.warn('task_runner_do.ensure_branch.gitlab_error', { + taskId: state.taskId, + branch: state.config.branch, + error: err instanceof Error ? err.message : String(err), + }); + } +} + +type TaskRunnerGitHubInstallation = { + installationId: string; + externalInstallationId: string | null; +}; + +async function loadTaskRunnerGitHubInstallation( + state: TaskRunnerState, + rc: TaskRunnerContext +): Promise { + return rc.env.DATABASE.prepare( + `SELECT installation_id AS installationId, external_installation_id AS externalInstallationId + FROM github_installations + WHERE id = ? AND user_id = ?` + ) + .bind(state.config.installationId, state.userId) + .first(); +} diff --git a/apps/api/src/durable-objects/task-runner/workspace-steps.ts b/apps/api/src/durable-objects/task-runner/workspace-steps.ts index 334e61d416..55d9d39a5d 100644 --- a/apps/api/src/durable-objects/task-runner/workspace-steps.ts +++ b/apps/api/src/durable-objects/task-runner/workspace-steps.ts @@ -11,11 +11,13 @@ import { import { log } from '../../lib/logger'; import type { DevcontainerCacheCredentials } from '../../services/devcontainer-cache'; -import { getExternalInstallationId } from '../../services/github-installation-ids'; import { reserveWorkspacePlacement } from '../../services/workspace-placement'; import { computeBackoffMs, isTransientError, parseEnvInt } from './helpers'; import { ensureSessionLinked } from './state-machine'; import type { TaskRunnerContext, TaskRunnerState } from './types'; +import { ensureBranchExistsOnRemote } from './workspace-branch'; + +export { ensureBranchExistsOnRemote } from './workspace-branch'; // ========================================================================= // Step Handlers @@ -262,89 +264,6 @@ async function setOutputBranch( .run(); } -/** - * Ensure the checkout branch exists on the remote before cloning. - * If the branch differs from the project's default branch and doesn't exist, - * create it from the default branch via the GitHub API. - * - * Best-effort: failures are logged but do not block workspace creation. - * The clone will fail with a clear error from the VM agent if the branch - * truly doesn't exist. - */ -export async function ensureBranchExistsOnRemote( - state: TaskRunnerState, - rc: TaskRunnerContext -): Promise { - const defaultBranch = state.config.defaultBranch || 'main'; - - // If cloning the default branch, no need to check — it always exists - if (state.config.branch === defaultBranch) { - return; - } - - const projectRepo = await loadTaskRunnerProjectRepo(state, rc); - if (projectRepo?.repoProvider === 'artifacts') { - return; - } - if (projectRepo?.repoProvider === 'gitlab') { - await ensureGitLabBranchExistsOnRemote(state, rc, defaultBranch); - return; - } - - // Parse owner/repo from repository string (format: "owner/repo") - const repoParts = state.config.repository.split('/'); - if (repoParts.length !== 2 || !repoParts[0] || !repoParts[1]) { - log.warn('task_runner_do.ensure_branch.invalid_repository', { - taskId: state.taskId, - repository: state.config.repository, - }); - return; - } - - const [owner, repo] = repoParts; - - try { - const installation = await loadTaskRunnerGitHubInstallation(state, rc); - if (!installation) { - log.warn('task_runner_do.ensure_branch.installation_not_found', { - taskId: state.taskId, - installationId: state.config.installationId, - }); - return; - } - - const externalInstallationId = getExternalInstallationId(installation); - const { ensureBranchExists } = await import('../../services/github-app'); - const created = await ensureBranchExists( - externalInstallationId, - owner, - repo, - state.config.branch, - defaultBranch, - rc.env - ); - - if (created) { - log.info('task_runner_do.ensure_branch.ok', { - taskId: state.taskId, - branch: state.config.branch, - }); - } else { - log.warn('task_runner_do.ensure_branch.failed', { - taskId: state.taskId, - branch: state.config.branch, - defaultBranch, - }); - } - } catch (err) { - log.warn('task_runner_do.ensure_branch.error', { - taskId: state.taskId, - branch: state.config.branch, - error: err instanceof Error ? err.message : String(err), - }); - } -} - type TaskRunnerProjectRepo = { repoProvider: string | null; }; @@ -358,67 +277,6 @@ async function loadTaskRunnerProjectRepo( .first(); } -async function ensureGitLabBranchExistsOnRemote( - state: TaskRunnerState, - rc: TaskRunnerContext, - defaultBranch: string -): Promise { - try { - const { drizzle } = await import('drizzle-orm/d1'); - const schema = await import('../../db/schema'); - const { ensureGitLabBranchExists, getProjectGitLabRepository } = - await import('../../services/gitlab'); - const metadata = await getProjectGitLabRepository( - drizzle(rc.env.DATABASE, { schema }), - state.projectId - ); - if (!metadata) { - log.warn('task_runner_do.ensure_branch.gitlab_metadata_missing', { - taskId: state.taskId, - projectId: state.projectId, - }); - return; - } - const created = await ensureGitLabBranchExists({ - env: rc.env, - userId: state.userId, - projectId: metadata.gitlabProjectId, - branch: state.config.branch, - ref: defaultBranch, - }); - if (created) { - log.info('task_runner_do.ensure_branch.gitlab_ok', { - taskId: state.taskId, - branch: state.config.branch, - }); - } - } catch (err) { - log.warn('task_runner_do.ensure_branch.gitlab_error', { - taskId: state.taskId, - branch: state.config.branch, - error: err instanceof Error ? err.message : String(err), - }); - } -} - -type TaskRunnerGitHubInstallation = { - installationId: string; - externalInstallationId: string | null; -}; - -async function loadTaskRunnerGitHubInstallation( - state: TaskRunnerState, - rc: TaskRunnerContext -): Promise { - return rc.env.DATABASE.prepare( - `SELECT installation_id AS installationId, external_installation_id AS externalInstallationId - FROM github_installations - WHERE id = ? AND user_id = ?` - ) - .bind(state.config.installationId, state.userId) - .first(); -} - async function createWorkspaceOnVmAgent( state: TaskRunnerState, rc: TaskRunnerContext, diff --git a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md index da5ebc7108..d48f031fa0 100644 --- a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md +++ b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md @@ -74,7 +74,7 @@ must remain unmerged until Raphaël explicitly authorizes a merge. workflow using pinned actions and no external credentials. - [x] Run the fast and Workerd suites repeatedly locally, run the deeper profile enough times to collect useful evidence, and document which recent incident classes they detect. -- [ ] Run full affected-package lint, typecheck, unit, Workers, and Go quality gates. +- [x] Run full affected-package lint, typecheck, unit, Workers, and Go quality gates. - [ ] Complete task, test, Cloudflare, Go, constitution, and documentation review as applicable. - [ ] Open and maintain a draft PR, push meaningful increments frequently, and do not merge without explicit authorization. @@ -120,6 +120,18 @@ must remain unmerged until Raphaël explicitly authorizes a merge. - An expanded local exploration passed 100,000 generated schedules with up to 200 commands, 40 task slots, and 8 projects in 8.58 seconds. Its first run exposed the default 5-second Vitest ceiling, so the nightly profile now carries an explicit bounded timeout for larger runs. +- Full API validation passed: ESLint, TypeScript typecheck, 540 unit/integration files with 7,233 + tests, and 49 Workerd files with 628 tests. The complete Workerd inventory took 831.87 seconds; + the focused real-D1 race slice remains the inexpensive scheduler-change signal. +- VM-agent validation passed `go vet ./...`, `go build ./...`, and 10 race-detector repetitions of + `TestSessionHostActivityUsesOwningWorkspaceProject`. A full `go test ./internal/server` run was + attempted and reached only the existing Docker-dependent `TestBootstrapLifecycle_SessionsUseDetectedUser` + environment failure (`docker` is not installed); the new routing test passed in that run. +- Repository quality gates passed: formatting, file sizes, source-contract tests, AST checks (zero + errors; repository warnings only), quality-script tests (32 files, 302 tests), and `git diff --check`. + The file-size gate initially caught `workspace-steps.ts` at 809 lines, so remote-branch handling + was extracted into `workspace-branch.ts`; the original module is now 667 lines and its 10 focused + branch-provider tests pass. ## References From 130463ef24a2727dbfcca5547543f143314fa632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 07:22:25 +0000 Subject: [PATCH 46/57] fix(api): fail closed on scheduled teardown --- apps/api/src/scheduled/node-cleanup/shared.ts | 4 +- apps/api/src/services/strict-node-deletion.ts | 35 ++++++---- .../integration/warm-node-pooling.test.ts | 29 +++++++-- apps/api/tests/simulation/README.md | 6 +- apps/api/tests/unit/node-cleanup.test.ts | 64 ++++++++++++++++--- .../unit/scheduled/cleanup-config.test.ts | 8 ++- ...-cleanup-deployment-node-exemption.test.ts | 3 +- .../services/node-cleanup-idle-signal.test.ts | 12 ++-- .../node-cleanup-user-owned-zombie.test.ts | 10 +-- .../tests/unit/services/nodes-delete.test.ts | 27 ++++++++ .../workers/scheduled-node-cleanup.test.ts | 38 ++++++++++- ...2026-08-15-scheduler-lifecycle-race-lab.md | 30 ++++++++- 12 files changed, 212 insertions(+), 54 deletions(-) diff --git a/apps/api/src/scheduled/node-cleanup/shared.ts b/apps/api/src/scheduled/node-cleanup/shared.ts index 0998d43fb2..ae5a788742 100644 --- a/apps/api/src/scheduled/node-cleanup/shared.ts +++ b/apps/api/src/scheduled/node-cleanup/shared.ts @@ -30,7 +30,7 @@ import * as schema from '../../db/schema'; import type { Env } from '../../env'; import { log } from '../../lib/logger'; import { getNodeAgentBackgroundRequestTimeoutMs } from '../../services/node-agent'; -import { deleteNodeResources } from '../../services/nodes'; +import { deleteNodeResourcesStrict } from '../../services/nodes'; import { persistError } from '../../services/observability'; export const DEFAULT_CF_CONTAINER_TERMINAL_TASK_SWEEP_LIMIT = 25; @@ -319,7 +319,7 @@ export async function destroyNodeForCleanup( ...options.context, }); - await deleteNodeResources(node.id, node.user_id, env); + await deleteNodeResourcesStrict(node.id, node.user_id, env); await db .update(schema.nodes) diff --git a/apps/api/src/services/strict-node-deletion.ts b/apps/api/src/services/strict-node-deletion.ts index bc7258a011..69afb65cd2 100644 --- a/apps/api/src/services/strict-node-deletion.ts +++ b/apps/api/src/services/strict-node-deletion.ts @@ -13,6 +13,7 @@ import { getCredentialEncryptionKey } from '../lib/secrets'; import { deleteDNSRecord } from './dns'; import { persistError } from './observability'; import { createProviderForUser } from './provider-credentials'; +import { destroyVmAgentContainer } from './vm-agent-container'; type NodeDb = ReturnType>; type NodeRow = typeof schema.nodes.$inferSelect; @@ -194,20 +195,24 @@ async function persistStrictDnsCleanupError( err: unknown; } ): Promise { - await persistError(env.OBSERVABILITY_DATABASE, { - source: 'api', - level: 'error', - message: `Strict node DNS cleanup failed: ${input.err instanceof Error ? input.err.message : String(input.err)}`, - stack: input.err instanceof Error ? input.err.stack : undefined, - context: { - component: 'node-deletion', - recoveryType: 'strict_node_dns_cleanup_failure', + await persistError( + env.OBSERVABILITY_DATABASE, + { + source: 'api', + level: 'error', + message: `Strict node DNS cleanup failed: ${input.err instanceof Error ? input.err.message : String(input.err)}`, + stack: input.err instanceof Error ? input.err.stack : undefined, + context: { + component: 'node-deletion', + recoveryType: 'strict_node_dns_cleanup_failure', + nodeId: input.nodeId, + backendDnsRecordId: input.backendDnsRecordId, + }, nodeId: input.nodeId, - backendDnsRecordId: input.backendDnsRecordId, + userId: input.userId, }, - nodeId: input.nodeId, - userId: input.userId, - }, env); + env + ); } async function deleteStrictNodeDnsRecord(node: NodeRow, userId: string, env: Env): Promise { @@ -255,6 +260,12 @@ export async function deleteNodeResourcesStrict( return { providerVm: 'no-instance' }; } + if (node.runtime === 'cf-container') { + await destroyVmAgentContainer(env, node.id); + await deleteStrictNodeDnsRecord(node, userId, env); + return { providerVm: 'no-instance' }; + } + const providerVm = await deleteStrictProviderInstance(db, node, userId, env); await deleteStrictNodeDnsRecord(node, userId, env); return { providerVm }; diff --git a/apps/api/tests/integration/warm-node-pooling.test.ts b/apps/api/tests/integration/warm-node-pooling.test.ts index e4af9059ae..664ade8a15 100644 --- a/apps/api/tests/integration/warm-node-pooling.test.ts +++ b/apps/api/tests/integration/warm-node-pooling.test.ts @@ -14,14 +14,29 @@ import { resolve } from 'node:path'; import { describe, expect, it } from 'vitest'; describe('warm node pooling lifecycle integration', () => { - const taskRunnerFile = readFileSync(resolve(process.cwd(), 'src/services/task-runner.ts'), 'utf8'); - const selectorFile = readFileSync(resolve(process.cwd(), 'src/services/node-selector.ts'), 'utf8'); - const doFile = readFileSync(resolve(process.cwd(), 'src/durable-objects/node-lifecycle.ts'), 'utf8'); + const taskRunnerFile = readFileSync( + resolve(process.cwd(), 'src/services/task-runner.ts'), + 'utf8' + ); + const selectorFile = readFileSync( + resolve(process.cwd(), 'src/services/node-selector.ts'), + 'utf8' + ); + const doFile = readFileSync( + resolve(process.cwd(), 'src/durable-objects/node-lifecycle.ts'), + 'utf8' + ); const cleanupFile = ['index.ts', 'shared.ts', 'node-phases.ts', 'workspace-phases.ts'] .map((f) => readFileSync(resolve(process.cwd(), `src/scheduled/node-cleanup/${f}`), 'utf8')) .join('\n'); - const serviceFile = readFileSync(resolve(process.cwd(), 'src/services/node-lifecycle.ts'), 'utf8'); - const constantsFile = readFileSync(resolve(process.cwd(), '../../packages/shared/src/constants/node-pooling.ts'), 'utf8'); + const serviceFile = readFileSync( + resolve(process.cwd(), 'src/services/node-lifecycle.ts'), + 'utf8' + ); + const constantsFile = readFileSync( + resolve(process.cwd(), '../../packages/shared/src/constants/node-pooling.ts'), + 'utf8' + ); describe('flow: task complete → workspace destroyed → node warm', () => { it('cleanupTaskRun calls cleanupAutoProvisionedNode', () => { @@ -79,8 +94,8 @@ describe('warm node pooling lifecycle integration', () => { expect(doFile).toContain("SET status = 'stopped', warm_since = NULL"); }); - it('cron sweep finds stale warm nodes and calls deleteNodeResources', () => { - expect(cleanupFile).toContain('deleteNodeResources(node.id, node.user_id, env)'); + it('cron sweep finds stale warm nodes and calls strict resource deletion', () => { + expect(cleanupFile).toContain('deleteNodeResourcesStrict(node.id, node.user_id, env)'); }); it('cron sweep also enforces max auto-provisioned node lifetime', () => { diff --git a/apps/api/tests/simulation/README.md b/apps/api/tests/simulation/README.md index a0b6c5028c..ec52994946 100644 --- a/apps/api/tests/simulation/README.md +++ b/apps/api/tests/simulation/README.md @@ -41,8 +41,10 @@ Calibration cases deliberately enable the historical unsafe policies and prove t - two TaskRunners observing and consuming the same final node slot. The adjacent Workerd suite in `tests/workers/scheduler-lifecycle-races.test.ts` uses the real local D1 -and TaskRunner Durable Object to verify the production placement/cleanup claims. The VM-agent Go -contract verifies activity from multiple workspaces on one node is routed to each owning project. +and TaskRunner Durable Object to verify the production placement/cleanup claims. The scheduled +cleanup vertical slice also proves a failed external teardown releases the D1 claim with bounded +backoff instead of falsely marking a still-live resource deleted. The VM-agent Go contract verifies +activity from multiple workspaces on one node is routed to each owning project. This lab does not emulate cloud-provider behavior, real containers, network throughput, or long-run resource exhaustion. Those remain integration/soak concerns; no staging or cloud credentials are diff --git a/apps/api/tests/unit/node-cleanup.test.ts b/apps/api/tests/unit/node-cleanup.test.ts index 9fb887144f..d22f11cfb9 100644 --- a/apps/api/tests/unit/node-cleanup.test.ts +++ b/apps/api/tests/unit/node-cleanup.test.ts @@ -12,9 +12,10 @@ import { runNodeCleanupSweep } from '../../src/scheduled/node-cleanup'; import { sweepTerminalCfContainers } from '../../src/scheduled/node-cleanup/node-phases'; import { emptyResult, resolveCleanupConfig } from '../../src/scheduled/node-cleanup/shared'; -// Mock deleteNodeResources +// Mock strict external teardown. Scheduled cleanup must fail closed when the +// provider/container boundary cannot confirm deletion. vi.mock('../../src/services/nodes', () => ({ - deleteNodeResources: vi.fn().mockResolvedValue(undefined), + deleteNodeResourcesStrict: vi.fn().mockResolvedValue({ providerVm: 'deleted' }), stopNodeResources: vi.fn().mockResolvedValue(undefined), })); @@ -135,7 +136,7 @@ describe('runNodeCleanupSweep', () => { }); it('destroys nodes without active workspaces past max lifetime', async () => { - const { deleteNodeResources } = await import('../../src/services/nodes'); + const { deleteNodeResourcesStrict } = await import('../../src/services/nodes'); const now = Date.now(); const createdAt = new Date(now - 5 * 60 * 60 * 1000).toISOString(); @@ -159,7 +160,46 @@ describe('runNodeCleanupSweep', () => { expect(result.lifetimeDestroyed).toBe(1); expect(result.lifetimeSkipped).toBe(0); - expect(deleteNodeResources).toHaveBeenCalledWith('node-1', 'user-1', env); + expect(deleteNodeResourcesStrict).toHaveBeenCalledWith('node-1', 'user-1', env); + }); + + it('releases the cleanup claim with backoff when strict provider deletion fails', async () => { + const { deleteNodeResourcesStrict } = await import('../../src/services/nodes'); + vi.mocked(deleteNodeResourcesStrict).mockRejectedValueOnce(new Error('provider unavailable')); + const createdAt = new Date(Date.now() - 5 * 60 * 60 * 1000).toISOString(); + const responses = new Map(); + responses.set('n.warm_since IS NOT NULL', []); + responses.set('auto_provisioned_node_id', [ + { + node_id: 'node-provider-failure', + id: 'node-provider-failure', + user_id: 'user-1', + status: 'running', + created_at: createdAt, + active_ws_count: 0, + }, + ]); + responses.set("w.status = 'running'", []); + responses.set('n.warm_since IS NULL', []); + + const env = createMockEnv(responses); + const result = await runNodeCleanupSweep(env); + + expect(result.lifetimeDestroyed).toBe(0); + expect(result.errors).toBe(1); + expect(deleteNodeResourcesStrict).toHaveBeenCalledWith( + 'node-provider-failure', + 'user-1', + env + ); + expect( + vi + .mocked(env.DATABASE.prepare) + .mock.calls.some( + ([sql]) => + sql.includes('cleanup_backoff_until = ?') && sql.includes("status = 'destroying'") + ) + ).toBe(true); }); it('always skips nodes with active workspaces (no absolute ceiling)', async () => { @@ -206,7 +246,7 @@ describe('runNodeCleanupSweep', () => { describe('Layer 1: stale warm node destruction', () => { it('destroys stale warm nodes with no active workspaces', async () => { - const { deleteNodeResources } = await import('../../src/services/nodes'); + const { deleteNodeResourcesStrict } = await import('../../src/services/nodes'); const now = Date.now(); const warmSince = new Date(now - 40 * 60 * 1000).toISOString(); // 40 min ago (> 35 min grace) @@ -230,7 +270,7 @@ describe('runNodeCleanupSweep', () => { const result = await runNodeCleanupSweep(env); expect(result.staleDestroyed).toBe(1); - expect(deleteNodeResources).toHaveBeenCalledWith('node-warm', 'user-1', env); + expect(deleteNodeResourcesStrict).toHaveBeenCalledWith('node-warm', 'user-1', env); }); it('skips stale warm nodes that have active workspaces', async () => { @@ -262,7 +302,7 @@ describe('runNodeCleanupSweep', () => { describe('DO alarm handoff cleanup', () => { it('destroys stopped auto-provisioned nodes left behind by the NodeLifecycle alarm', async () => { - const { deleteNodeResources } = await import('../../src/services/nodes'); + const { deleteNodeResourcesStrict } = await import('../../src/services/nodes'); const now = Date.now(); const createdAt = new Date(now - 2 * 60 * 60 * 1000).toISOString(); const updatedAt = new Date(now - 30 * 60 * 1000).toISOString(); @@ -287,11 +327,11 @@ describe('runNodeCleanupSweep', () => { const result = await runNodeCleanupSweep(env); expect(result.lifetimeDestroyed).toBe(1); - expect(deleteNodeResources).toHaveBeenCalledWith('node-stopped-handoff', 'user-1', env); + expect(deleteNodeResourcesStrict).toHaveBeenCalledWith('node-stopped-handoff', 'user-1', env); }); it('does not destroy stopped handoff nodes with active workspaces', async () => { - const { deleteNodeResources } = await import('../../src/services/nodes'); + const { deleteNodeResourcesStrict } = await import('../../src/services/nodes'); const updatedAt = new Date(Date.now() - 30 * 60 * 1000).toISOString(); const responses = new Map(); @@ -314,7 +354,11 @@ describe('runNodeCleanupSweep', () => { expect(result.lifetimeDestroyed).toBe(0); expect(result.lifetimeSkipped).toBe(1); - expect(deleteNodeResources).not.toHaveBeenCalledWith('node-stopped-active', 'user-1', env); + expect(deleteNodeResourcesStrict).not.toHaveBeenCalledWith( + 'node-stopped-active', + 'user-1', + env + ); }); }); diff --git a/apps/api/tests/unit/scheduled/cleanup-config.test.ts b/apps/api/tests/unit/scheduled/cleanup-config.test.ts index 76055eb255..b5e861d920 100644 --- a/apps/api/tests/unit/scheduled/cleanup-config.test.ts +++ b/apps/api/tests/unit/scheduled/cleanup-config.test.ts @@ -9,7 +9,11 @@ import { describe, expect, it, vi } from 'vitest'; import type { Env } from '../../../src/env'; -import { parseMs, parsePositiveInt, resolveCleanupConfig } from '../../../src/scheduled/node-cleanup/shared'; +import { + parseMs, + parsePositiveInt, + resolveCleanupConfig, +} from '../../../src/scheduled/node-cleanup/shared'; const logWarn = vi.fn(); @@ -21,7 +25,7 @@ vi.mock('../../../src/services/node-agent', () => ({ deleteWorkspaceOnNode: vi.fn(), stopWorkspaceOnNode: vi.fn(), })); -vi.mock('../../../src/services/nodes', () => ({ deleteNodeResources: vi.fn() })); +vi.mock('../../../src/services/nodes', () => ({ deleteNodeResourcesStrict: vi.fn() })); vi.mock('../../../src/services/observability', () => ({ persistError: vi.fn() })); describe('parseMs', () => { diff --git a/apps/api/tests/unit/services/node-cleanup-deployment-node-exemption.test.ts b/apps/api/tests/unit/services/node-cleanup-deployment-node-exemption.test.ts index 34ed66a7ea..7791c2ef0b 100644 --- a/apps/api/tests/unit/services/node-cleanup-deployment-node-exemption.test.ts +++ b/apps/api/tests/unit/services/node-cleanup-deployment-node-exemption.test.ts @@ -30,8 +30,9 @@ const deleteCalls: string[] = []; const stopCalls: string[] = []; vi.mock('../../../src/services/nodes', () => ({ - deleteNodeResources: vi.fn(async (nodeId: string) => { + deleteNodeResourcesStrict: vi.fn(async (nodeId: string) => { deleteCalls.push(nodeId); + return { providerVm: 'deleted' as const }; }), stopNodeResources: vi.fn(async (nodeId: string) => { stopCalls.push(nodeId); diff --git a/apps/api/tests/unit/services/node-cleanup-idle-signal.test.ts b/apps/api/tests/unit/services/node-cleanup-idle-signal.test.ts index 5ab5811bec..5a6ced8530 100644 --- a/apps/api/tests/unit/services/node-cleanup-idle-signal.test.ts +++ b/apps/api/tests/unit/services/node-cleanup-idle-signal.test.ts @@ -19,14 +19,15 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import type { Env } from '../../../src/env'; import { runNodeCleanupSweep } from '../../../src/scheduled/node-cleanup'; -import { deleteNodeResources } from '../../../src/services/nodes'; +import { deleteNodeResourcesStrict } from '../../../src/services/nodes'; import { createSqliteD1 } from '../../helpers/sqlite-d1'; const deleteCalls: string[] = []; vi.mock('../../../src/services/nodes', () => ({ - deleteNodeResources: vi.fn(async (nodeId: string) => { + deleteNodeResourcesStrict: vi.fn(async (nodeId: string) => { deleteCalls.push(nodeId); + return { providerVm: 'deleted' as const }; }), stopNodeResources: vi.fn().mockResolvedValue(undefined), })); @@ -101,8 +102,9 @@ function makeEnv(): Env { beforeEach(() => { deleteCalls.length = 0; - vi.mocked(deleteNodeResources).mockImplementation(async (nodeId: string) => { + vi.mocked(deleteNodeResourcesStrict).mockImplementation(async (nodeId: string) => { deleteCalls.push(nodeId); + return { providerVm: 'deleted' }; }); sqlite = new Database(':memory:'); sqlite.exec(` @@ -234,8 +236,8 @@ describe('idle reaping is immune to heartbeat activity', () => { it('two-sweep zombie check: a permanently failing candidate is not retried forever', async () => { // rule 47 — a candidate that can never be destroyed must still leave the // candidate set, or every sweep re-attempts it and the loop never converges. - const { deleteNodeResources } = await import('../../../src/services/nodes'); - vi.mocked(deleteNodeResources).mockRejectedValue(new Error('provider unreachable')); + const { deleteNodeResourcesStrict } = await import('../../../src/services/nodes'); + vi.mocked(deleteNodeResourcesStrict).mockRejectedValue(new Error('provider unreachable')); seedNode({ id: 'doomed', createdAt: ago(10 * HOUR), updatedAt: ago(1000) }); seedWorkspace({ diff --git a/apps/api/tests/unit/services/node-cleanup-user-owned-zombie.test.ts b/apps/api/tests/unit/services/node-cleanup-user-owned-zombie.test.ts index 9e1ec2830a..302f99908a 100644 --- a/apps/api/tests/unit/services/node-cleanup-user-owned-zombie.test.ts +++ b/apps/api/tests/unit/services/node-cleanup-user-owned-zombie.test.ts @@ -18,15 +18,9 @@ const deleteCalls: string[] = []; const stopCalls: string[] = []; vi.mock('../../../src/services/nodes', () => ({ - deleteNodeResources: vi.fn(async (nodeId: string) => { + deleteNodeResourcesStrict: vi.fn(async (nodeId: string) => { deleteCalls.push(nodeId); - return { - nodeFound: true, - providerVmDeleted: true, - providerVmDeleteSkippedReason: null, - backendDnsDeleted: false, - errors: [], - }; + return { providerVm: 'deleted' as const }; }), stopNodeResources: vi.fn(async (nodeId: string) => { stopCalls.push(nodeId); diff --git a/apps/api/tests/unit/services/nodes-delete.test.ts b/apps/api/tests/unit/services/nodes-delete.test.ts index ec68e7d058..0527a8551c 100644 --- a/apps/api/tests/unit/services/nodes-delete.test.ts +++ b/apps/api/tests/unit/services/nodes-delete.test.ts @@ -196,6 +196,33 @@ describe('node resource deletion services', () => { expect(destroyVmAgentContainer).not.toHaveBeenCalled(); }); + it('deleteNodeResourcesStrict requires managed container teardown to succeed', async () => { + nodeRows.push({ + id: 'cf-strict', + userId: 'user-1', + name: 'strict cf node', + status: 'destroying', + nodeClass: 'managed', + runtime: 'cf-container', + providerInstanceId: null, + cloudProvider: null, + backendDnsRecordId: null, + credentialAttributionUserId: null, + credentialAttributionSource: 'user', + credentialAttributionProjectId: null, + }); + + await expect(deleteNodeResourcesStrict('cf-strict', 'user-1', ENV)).resolves.toEqual({ + providerVm: 'no-instance', + }); + expect(destroyVmAgentContainer).toHaveBeenCalledWith(ENV, 'cf-strict'); + + destroyVmAgentContainer.mockRejectedValueOnce(new Error('container teardown unavailable')); + await expect(deleteNodeResourcesStrict('cf-strict', 'user-1', ENV)).rejects.toThrow( + /container teardown unavailable/ + ); + }); + it('deleteNodeResourcesStrict is a no-op for a user-owned node (nothing to delete, no throw)', async () => { nodeRows.push( userOwnedNode({ providerInstanceId: 'srv-should-not-touch', cloudProvider: 'hetzner' }) diff --git a/apps/api/tests/workers/scheduled-node-cleanup.test.ts b/apps/api/tests/workers/scheduled-node-cleanup.test.ts index 7eb59d733a..09429fa7f2 100644 --- a/apps/api/tests/workers/scheduled-node-cleanup.test.ts +++ b/apps/api/tests/workers/scheduled-node-cleanup.test.ts @@ -428,6 +428,41 @@ describe('runNodeCleanupSweep — vertical slice', () => { }); describe('stale warm node cleanup (Phase 1)', () => { + it('releases a real D1 cleanup claim when container teardown fails', async () => { + await seedBaseData(); + const nodeId = 'node-nc-stale-warm-container-failure'; + const warmSince = new Date(Date.now() - 60 * 60 * 1000).toISOString(); + const destroyForUser = vi.fn().mockRejectedValue(new Error('container teardown unavailable')); + + await seedNode(nodeId, USER_ID, { status: 'running', warmSince }); + await env.DATABASE.prepare(`UPDATE nodes SET runtime = 'cf-container' WHERE id = ?`) + .bind(nodeId) + .run(); + + const testEnv = { + ...env, + CF_CONTAINER_ENABLED: 'true', + VM_AGENT_CONTAINER: { + idFromName: (id: string) => id, + get: () => ({ destroyForUser }), + }, + NODE_WARM_GRACE_PERIOD_MS: '1000', + } as unknown as Env; + + const result = await runNodeCleanupSweep(testEnv); + const node = await env.DATABASE.prepare( + 'SELECT status, cleanup_backoff_until FROM nodes WHERE id = ?' + ) + .bind(nodeId) + .first<{ status: string; cleanup_backoff_until: string | null }>(); + + expect(destroyForUser).toHaveBeenCalledTimes(1); + expect(result.staleDestroyed).toBe(0); + expect(result.errors).toBeGreaterThanOrEqual(1); + expect(node?.status).toBe('running'); + expect(node?.cleanup_backoff_until).not.toBeNull(); + }); + it('attempts to destroy stale warm node and counts error (no Hetzner in test)', async () => { await seedBaseData(); const nodeId = 'node-nc-stale-warm'; @@ -446,8 +481,7 @@ describe('runNodeCleanupSweep — vertical slice', () => { const result = await runNodeCleanupSweep(testEnv); - // deleteNodeResources will fail (no Hetzner credentials in test env) - // but the error should be caught and counted + // A record with no provider instance is safe to finalize without credentials. expect(result.staleDestroyed + result.errors).toBeGreaterThanOrEqual(1); }); diff --git a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md index d48f031fa0..482c8ecc1e 100644 --- a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md +++ b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md @@ -75,7 +75,7 @@ must remain unmerged until Raphaël explicitly authorizes a merge. - [x] Run the fast and Workerd suites repeatedly locally, run the deeper profile enough times to collect useful evidence, and document which recent incident classes they detect. - [x] Run full affected-package lint, typecheck, unit, Workers, and Go quality gates. -- [ ] Complete task, test, Cloudflare, Go, constitution, and documentation review as applicable. +- [x] Complete task, test, Cloudflare, Go, constitution, and documentation review as applicable. - [ ] Open and maintain a draft PR, push meaningful increments frequently, and do not merge without explicit authorization. @@ -120,8 +120,9 @@ must remain unmerged until Raphaël explicitly authorizes a merge. - An expanded local exploration passed 100,000 generated schedules with up to 200 commands, 40 task slots, and 8 projects in 8.58 seconds. Its first run exposed the default 5-second Vitest ceiling, so the nightly profile now carries an explicit bounded timeout for larger runs. -- Full API validation passed: ESLint, TypeScript typecheck, 540 unit/integration files with 7,233 - tests, and 49 Workerd files with 628 tests. The complete Workerd inventory took 831.87 seconds; +- Full API validation passed after the review fixes: ESLint, TypeScript typecheck, 540 + unit/integration files with 7,235 tests, and 49 Workerd files with 629 tests. The two complete + Workerd passes took 831.87 and 829.49 seconds; the focused real-D1 race slice remains the inexpensive scheduler-change signal. - VM-agent validation passed `go vet ./...`, `go build ./...`, and 10 race-detector repetitions of `TestSessionHostActivityUsesOwningWorkspaceProject`. A full `go test ./internal/server` run was @@ -132,6 +133,29 @@ must remain unmerged until Raphaël explicitly authorizes a merge. The file-size gate initially caught `workspace-steps.ts` at 809 lines, so remote-branch handling was extracted into `workspace-branch.ts`; the original module is now 667 lines and its 10 focused branch-provider tests pass. +- Specialist review found one high-risk false-success path after the initial validation: scheduled + cleanup still used the legacy teardown helper, which collects provider/container failures instead + of throwing. That could mark D1 deleted while an external resource survived. Scheduled cleanup + now uses strict teardown, strict teardown covers managed Cloudflare containers, and failed teardown + releases the `destroying` claim to its prior status with `cleanup_backoff_until`. The focused unit + set passes 152 tests and a real Workerd/D1 slice proves a thrown container teardown leaves the node + `running` with backoff rather than falsely deleted. + +## Review Evidence + +| Review | Verdict | Evidence / findings | +| --- | --- | --- | +| Task completion | PASS | All nine research findings map to implemented checklist work; every acceptance criterion has automated or recorded verification. No UI or multi-provider selection surface was added. Existing real session-sleep suites complement the model calibration. | +| Test engineering | PASS | Unsafe historical policies fail calibration; production paths use real D1/TaskRunner DO and HTTP-boundary Go tests; external teardown failure now has both unit and Workerd coverage. Remaining provider/network/long-soak behavior is explicitly documented as out of scope. | +| Cloudflare | PASS after fix | Atomic D1 `INSERT ... SELECT` placement and `destroying` cleanup claims serialize the dangerous ownership transitions. Strict external teardown must succeed before the D1 tombstone; failure releases with bounded backoff. No migration or binding changes. | +| Go | PASS | Workspace runtime project context is copied into each SessionHost without new goroutines or lock ordering. `go vet`, `go build`, and 10 race-detector repetitions pass; the only broader local test limitation is the existing Docker-dependent case. | +| Constitution | PASS | No production URL, timeout, limit, or identifier was hardcoded. Placement capacity retains project/env configuration, cleanup backoff retains existing configuration, and simulation scale/timeout are environment-overridable test controls. | +| Documentation | PASS | The simulator README documents CI profiles, replay, invariants, incident calibration, strict teardown/backoff, and blind spots. No public API, environment variable, schema, or deployment contract changed, so public configuration docs require no update. | + +Task-completion validation notes one deliberate limitation rather than a completion gap: the +stranded-session incident is newly proven by a discriminating model calibration and the repository's +existing real session-sleep tests, not by a new end-to-end cloud/container sleep run. This is the +explicit local/CI boundary of the task. ## References From 599679cace924ba30aeb67f557b8056e119ab950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 08:40:38 +0000 Subject: [PATCH 47/57] fix(ci): resolve scheduler lifecycle findings --- .github/workflows/scheduler-lifecycle.yml | 2 +- apps/api/src/scheduled/node-cleanup/shared.ts | 213 +++++++++++------- .../simulation/scheduler-lifecycle-harness.ts | 18 +- ...2026-08-15-scheduler-lifecycle-race-lab.md | 8 +- 4 files changed, 149 insertions(+), 92 deletions(-) diff --git a/.github/workflows/scheduler-lifecycle.yml b/.github/workflows/scheduler-lifecycle.yml index 1574e82557..bbd01ca8ce 100644 --- a/.github/workflows/scheduler-lifecycle.yml +++ b/.github/workflows/scheduler-lifecycle.yml @@ -28,7 +28,7 @@ jobs: cache: 'pnpm' - name: Install dependencies - run: pnpm install --frozen-lockfile + run: pnpm install --frozen-lockfile --ignore-scripts - name: Build API dependencies run: pnpm exec turbo run build --filter=@simple-agent-manager/api... diff --git a/apps/api/src/scheduled/node-cleanup/shared.ts b/apps/api/src/scheduled/node-cleanup/shared.ts index ae5a788742..b5d6d83f11 100644 --- a/apps/api/src/scheduled/node-cleanup/shared.ts +++ b/apps/api/src/scheduled/node-cleanup/shared.ts @@ -185,10 +185,24 @@ function buildCleanupConfig(env: Env): CleanupConfig { export type CleanupContext = Record; export type NodeCleanupDestroyResult = 'destroyed' | 'skipped' | 'failed'; +type CleanupNode = { id: string; user_id: string; status: string }; + +interface DestroyNodeForCleanupOptions { + logEvent: string; + failureLogEvent: string; + successMessage: string; + failureMessagePrefix: string; + recoveryType: string; + failureRecoveryType: string; + level?: 'info' | 'warn'; + failureBackoffMs: number; + allowActiveWorkspaces?: boolean; + context: CleanupContext; +} export async function claimNodeForCleanup( env: Env, - node: { id: string; user_id: string; status: string }, + node: CleanupNode, nowIso: string, options: { allowActiveWorkspaces?: boolean } = {} ): Promise { @@ -224,7 +238,7 @@ export async function claimNodeForCleanup( async function releaseNodeCleanupClaim( env: Env, - node: { id: string; user_id: string; status: string }, + node: CleanupNode, nowIso: string, backoffUntil: string ): Promise { @@ -281,23 +295,117 @@ export async function markNodeCleanupBackoff( */ export const LAST_WORKSPACE_ACTIVITY_SQL = 'COALESCE(MAX(w.updated_at), n.created_at)'; +function errorMessage(error: unknown): string { + return error instanceof Error ? error.message : String(error); +} + +async function persistCleanupSuccess( + env: Env, + node: CleanupNode, + options: DestroyNodeForCleanupOptions +): Promise { + try { + await persistError( + env.OBSERVABILITY_DATABASE, + { + source: 'api', + level: options.level ?? 'warn', + message: options.successMessage, + context: { + recoveryType: options.recoveryType, + nodeId: node.id, + ...options.context, + }, + userId: node.user_id, + nodeId: node.id, + }, + env + ); + } catch (error) { + log.error('node_cleanup.success_observability_write_failed', { + nodeId: node.id, + error: errorMessage(error), + }); + } +} + +async function releaseCleanupClaimAfterFailure( + env: Env, + node: CleanupNode, + nowIso: string, + backoffUntil: string +): Promise { + try { + await releaseNodeCleanupClaim(env, node, nowIso, backoffUntil); + log.warn('node_cleanup.candidate_backed_off', { nodeId: node.id, backoffUntil }); + } catch (error) { + log.error('node_cleanup.candidate_claim_release_failed', { + nodeId: node.id, + error: errorMessage(error), + }); + } +} + +async function persistCleanupFailure( + env: Env, + node: CleanupNode, + options: DestroyNodeForCleanupOptions, + error: unknown, + backoffUntil: string +): Promise { + try { + await persistError( + env.OBSERVABILITY_DATABASE, + { + source: 'api', + level: 'error', + message: `${options.failureMessagePrefix}: ${errorMessage(error)}`, + stack: error instanceof Error ? error.stack : undefined, + context: { + recoveryType: options.failureRecoveryType, + nodeId: node.id, + backoffUntil, + ...options.context, + }, + userId: node.user_id, + nodeId: node.id, + }, + env + ); + } catch (persistErrorValue) { + log.error('node_cleanup.failure_observability_write_failed', { + nodeId: node.id, + error: errorMessage(persistErrorValue), + }); + } +} + +async function handleCleanupFailure( + env: Env, + node: CleanupNode, + nowIso: string, + options: DestroyNodeForCleanupOptions, + error: unknown +): Promise { + log.error(options.failureLogEvent, { + nodeId: node.id, + userId: node.user_id, + error: errorMessage(error), + }); + + const backoffUntil = new Date( + new Date(nowIso).getTime() + options.failureBackoffMs + ).toISOString(); + await releaseCleanupClaimAfterFailure(env, node, nowIso, backoffUntil); + await persistCleanupFailure(env, node, options, error, backoffUntil); +} + export async function destroyNodeForCleanup( db: CleanupDb, env: Env, nowIso: string, - node: { id: string; user_id: string; status: string }, - options: { - logEvent: string; - failureLogEvent: string; - successMessage: string; - failureMessagePrefix: string; - recoveryType: string; - failureRecoveryType: string; - level?: 'info' | 'warn'; - failureBackoffMs: number; - allowActiveWorkspaces?: boolean; - context: CleanupContext; - } + node: CleanupNode, + options: DestroyNodeForCleanupOptions ): Promise { const claimed = await claimNodeForCleanup(env, node, nowIso, { allowActiveWorkspaces: options.allowActiveWorkspaces, @@ -332,80 +440,11 @@ export async function destroyNodeForCleanup( }) .where(eq(schema.nodes.id, node.id)); - try { - await persistError( - env.OBSERVABILITY_DATABASE, - { - source: 'api', - level: options.level ?? 'warn', - message: options.successMessage, - context: { - recoveryType: options.recoveryType, - nodeId: node.id, - ...options.context, - }, - userId: node.user_id, - nodeId: node.id, - }, - env - ); - } catch (persistErr) { - log.error('node_cleanup.success_observability_write_failed', { - nodeId: node.id, - error: persistErr instanceof Error ? persistErr.message : String(persistErr), - }); - } + await persistCleanupSuccess(env, node, options); return 'destroyed'; - } catch (err) { - log.error(options.failureLogEvent, { - nodeId: node.id, - userId: node.user_id, - error: err instanceof Error ? err.message : String(err), - }); - - const backoffUntil = new Date( - new Date(nowIso).getTime() + options.failureBackoffMs - ).toISOString(); - try { - await releaseNodeCleanupClaim(env, node, nowIso, backoffUntil); - log.warn('node_cleanup.candidate_backed_off', { nodeId: node.id, backoffUntil }); - } catch (releaseErr) { - log.error('node_cleanup.candidate_claim_release_failed', { - nodeId: node.id, - error: releaseErr instanceof Error ? releaseErr.message : String(releaseErr), - }); - } - - try { - await persistError( - env.OBSERVABILITY_DATABASE, - { - source: 'api', - level: 'error', - message: - options.failureMessagePrefix + - ': ' + - (err instanceof Error ? err.message : String(err)), - stack: err instanceof Error ? err.stack : undefined, - context: { - recoveryType: options.failureRecoveryType, - nodeId: node.id, - backoffUntil, - ...options.context, - }, - userId: node.user_id, - nodeId: node.id, - }, - env - ); - } catch (persistErr) { - log.error('node_cleanup.failure_observability_write_failed', { - nodeId: node.id, - error: persistErr instanceof Error ? persistErr.message : String(persistErr), - }); - } - + } catch (error) { + await handleCleanupFailure(env, node, nowIso, options, error); return 'failed'; } } diff --git a/apps/api/tests/simulation/scheduler-lifecycle-harness.ts b/apps/api/tests/simulation/scheduler-lifecycle-harness.ts index 6840b0e245..e3b7b6d76b 100644 --- a/apps/api/tests/simulation/scheduler-lifecycle-harness.ts +++ b/apps/api/tests/simulation/scheduler-lifecycle-harness.ts @@ -96,7 +96,7 @@ export class SchedulerLifecycleWorld { completeTask(taskSlot: number): void { const task = this.tasks.get(`task-${taskSlot}`); - if (!task || task.status !== 'running' || !task.sessionId) return; + if (task?.status !== 'running' || !task.sessionId) return; const session = this.sessions.get(task.sessionId); if (!session || session.terminal) return; @@ -208,13 +208,22 @@ export class SchedulerLifecycleWorld { } assertSafety(): void { + this.assertNodeCapacities(); + this.assertWorkspaceNodesAreActive(); + this.assertTaskNodesAreActive(); + this.assertSingleLiveWorkspacePerTask(); + } + + private assertNodeCapacities(): void { for (const node of this.nodes.values()) { const active = this.activeWorkspaceCount(node.id); if (active > node.capacity) { this.fail(`capacity exceeded on ${node.id}: ${active}/${node.capacity}`); } } + } + private assertWorkspaceNodesAreActive(): void { for (const workspace of this.workspaces.values()) { if (workspace.status === 'sleeping' || workspace.status === 'deleted') continue; const node = this.nodes.get(workspace.nodeId); @@ -224,7 +233,9 @@ export class SchedulerLifecycleWorld { ); } } + } + private assertTaskNodesAreActive(): void { for (const task of this.tasks.values()) { if (task.status === 'completed' || !task.nodeId) continue; const node = this.nodes.get(task.nodeId); @@ -234,7 +245,9 @@ export class SchedulerLifecycleWorld { ); } } + } + private assertSingleLiveWorkspacePerTask(): void { const liveWorkspaceOwners = new Set(); for (const workspace of this.workspaces.values()) { if (workspace.status === 'deleted') continue; @@ -318,8 +331,7 @@ export class SchedulerLifecycleWorld { if ( this.policy.recheckPlacementAtCommit && - (!node || - node.status !== 'running' || + (node?.status !== 'running' || (!node.reservedTaskIds.has(task.id) && this.activeWorkspaceCount(node.id) >= node.capacity)) ) { if (node) node.reservedTaskIds.delete(task.id); diff --git a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md index 482c8ecc1e..81a7921613 100644 --- a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md +++ b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md @@ -76,7 +76,7 @@ must remain unmerged until Raphaël explicitly authorizes a merge. collect useful evidence, and document which recent incident classes they detect. - [x] Run full affected-package lint, typecheck, unit, Workers, and Go quality gates. - [x] Complete task, test, Cloudflare, Go, constitution, and documentation review as applicable. -- [ ] Open and maintain a draft PR, push meaningful increments frequently, and do not merge without +- [x] Open and maintain a draft PR, push meaningful increments frequently, and do not merge without explicit authorization. ## Acceptance Criteria @@ -140,6 +140,12 @@ must remain unmerged until Raphaël explicitly authorizes a merge. releases the `destroying` claim to its prior status with `cleanup_backoff_until`. The focused unit set passes 152 tests and a real Workerd/D1 slice proves a thrown container teardown leaves the node `running` with backoff rather than falsely deleted. +- With explicit approval, the Sonar follow-up hardened the credential-free nightly workflow with + `pnpm install --ignore-scripts`, decomposed cleanup success/failure handling and simulator safety + assertions below the cognitive-complexity threshold, and applied the two flagged optional-chain + simplifications. Focused API typecheck, 42 simulator/cleanup tests, ESLint, file-size checks, and + all 302 repository quality-script tests pass after the refactor. A third full Workerd run also + passed all 49 files and 629 tests in 944.82 seconds. ## Review Evidence From 0819e5184102659f2d2acca6a60d037d47ecf0db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sat, 15 Aug 2026 08:42:02 +0000 Subject: [PATCH 48/57] docs(tasks): record scheduler security review --- tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md index 81a7921613..3a33eda4f5 100644 --- a/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md +++ b/tasks/active/2026-08-15-scheduler-lifecycle-race-lab.md @@ -145,7 +145,9 @@ must remain unmerged until Raphaël explicitly authorizes a merge. assertions below the cognitive-complexity threshold, and applied the two flagged optional-chain simplifications. Focused API typecheck, 42 simulator/cleanup tests, ESLint, file-size checks, and all 302 repository quality-script tests pass after the refactor. A third full Workerd run also - passed all 49 files and 629 tests in 944.82 seconds. + passed all 49 files and 629 tests in 944.82 seconds. Dependency-governance tests pass. The local + Gitleaks wrapper could not complete because scanner output is withheld by policy, so the refreshed + PR Secret Scan remains the authoritative verification for this follow-up. ## Review Evidence @@ -155,6 +157,7 @@ must remain unmerged until Raphaël explicitly authorizes a merge. | Test engineering | PASS | Unsafe historical policies fail calibration; production paths use real D1/TaskRunner DO and HTTP-boundary Go tests; external teardown failure now has both unit and Workerd coverage. Remaining provider/network/long-soak behavior is explicitly documented as out of scope. | | Cloudflare | PASS after fix | Atomic D1 `INSERT ... SELECT` placement and `destroying` cleanup claims serialize the dangerous ownership transitions. Strict external teardown must succeed before the D1 tombstone; failure releases with bounded backoff. No migration or binding changes. | | Go | PASS | Workspace runtime project context is copied into each SessionHost without new goroutines or lock ordering. `go vet`, `go build`, and 10 race-detector repetitions pass; the only broader local test limitation is the existing Docker-dependent case. | +| Security | PASS | The nightly workflow retains read-only permissions and SHA-pinned actions while disabling dependency lifecycle scripts. The cleanup refactor preserves parameterized D1 writes, atomic ownership claims, strict teardown, and bounded backoff; no credential, authorization, or new logging surface was introduced. | | Constitution | PASS | No production URL, timeout, limit, or identifier was hardcoded. Placement capacity retains project/env configuration, cleanup backoff retains existing configuration, and simulation scale/timeout are environment-overridable test controls. | | Documentation | PASS | The simulator README documents CI profiles, replay, invariants, incident calibration, strict teardown/backoff, and blind spots. No public API, environment variable, schema, or deployment contract changed, so public configuration docs require no update. | From dabe75157e17a6fac04c712e37760fb5c5e24666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 16 Aug 2026 14:30:39 +0000 Subject: [PATCH 49/57] fix(api): preserve Claude setup driver failure details --- apps/api/src/durable-objects/credential-setup-session/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/api/src/durable-objects/credential-setup-session/index.ts b/apps/api/src/durable-objects/credential-setup-session/index.ts index 94b843942a..328b702788 100644 --- a/apps/api/src/durable-objects/credential-setup-session/index.ts +++ b/apps/api/src/durable-objects/credential-setup-session/index.ts @@ -157,6 +157,8 @@ const DeviceAuthStateSchema = v.object({ verificationUrl: v.optional(v.string()), userCode: v.optional(v.nullable(v.string())), error: v.optional(v.nullable(v.string())), + code: v.optional(v.string()), + detail: v.optional(v.nullable(v.string())), }); export class CredentialSetupSession extends DurableObject { From ca30aa0f60f866569788e4c0329cb8c846e079c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 16 Aug 2026 14:33:13 +0000 Subject: [PATCH 50/57] test(web): assert auth cache cleanup composition --- .../unit/components/auth-provider.test.tsx | 78 +++++++++++++++---- 1 file changed, 61 insertions(+), 17 deletions(-) diff --git a/apps/web/tests/unit/components/auth-provider.test.tsx b/apps/web/tests/unit/components/auth-provider.test.tsx index e274cc32a6..d753dd18da 100644 --- a/apps/web/tests/unit/components/auth-provider.test.tsx +++ b/apps/web/tests/unit/components/auth-provider.test.tsx @@ -8,11 +8,26 @@ import { GITHUB_REAUTH_REQUIRED_EVENT } from '../../../src/lib/api/client'; import { queryClient } from '../../../src/lib/query-client'; import { projectQueryKeys } from '../../../src/lib/query-options'; -const { mockUseSession, mockSignOut, mockClearLibraryCache, mockClearLegacyLibraryCache } = vi.hoisted(() => ({ +const { + mockUseSession, + mockSignOut, + mockClearLibraryCache, + mockClearLegacyLibraryCache, + mockBroadcastAuthRevocation, + mockCleanupTerminalSecrets, + mockInitAuthBroadcastListener, + mockResetAuthRevoked, + mockTeardownAuthBroadcastListener, +} = vi.hoisted(() => ({ mockUseSession: vi.fn(), mockSignOut: vi.fn(), mockClearLibraryCache: vi.fn(), mockClearLegacyLibraryCache: vi.fn(), + mockBroadcastAuthRevocation: vi.fn(), + mockCleanupTerminalSecrets: vi.fn(), + mockInitAuthBroadcastListener: vi.fn(), + mockResetAuthRevoked: vi.fn(), + mockTeardownAuthBroadcastListener: vi.fn(), })); vi.mock('../../../src/lib/auth', () => ({ @@ -26,6 +41,14 @@ vi.mock('../../../src/lib/library-cache', async (importOriginal) => ({ clearLegacyLibraryCache: mockClearLegacyLibraryCache, })); +vi.mock('../../../src/lib/terminal-cleanup', () => ({ + broadcastAuthRevocation: mockBroadcastAuthRevocation, + cleanupTerminalSecrets: mockCleanupTerminalSecrets, + initAuthBroadcastListener: mockInitAuthBroadcastListener, + resetAuthRevoked: mockResetAuthRevoked, + teardownAuthBroadcastListener: mockTeardownAuthBroadcastListener, +})); + const clearQueryCacheSpy = vi.spyOn(queryClient, 'clear'); function AuthConsumer() { @@ -41,9 +64,7 @@ function AuthConsumer() { } function renderWithAuth(children = ) { - return render( - {children}, - ); + return render({children}); } const validSession = { @@ -140,7 +161,7 @@ describe('AuthProvider', () => { rerender( - , + ); // Should still show authenticated using cached session @@ -192,7 +213,7 @@ describe('AuthProvider', () => { rerender( - , + ); // Must NOT use cached session — this was an intentional signout @@ -220,7 +241,7 @@ describe('AuthProvider', () => { rerender( - , + ); // Cached session used expect(screen.getByTestId('authenticated')).toHaveTextContent('true'); @@ -239,7 +260,7 @@ describe('AuthProvider', () => { rerender( - , + ); expect(screen.getByTestId('authenticated')).toHaveTextContent('true'); expect(screen.getByTestId('user-name')).toHaveTextContent('Updated User'); @@ -255,6 +276,9 @@ describe('AuthProvider', () => { const { rerender } = renderWithAuth(); expect(mockClearLegacyLibraryCache).toHaveBeenCalledTimes(1); clearQueryCacheSpy.mockClear(); + mockBroadcastAuthRevocation.mockClear(); + mockCleanupTerminalSecrets.mockClear(); + mockResetAuthRevoked.mockClear(); mockUseSession.mockReturnValue({ data: null, @@ -265,13 +289,16 @@ describe('AuthProvider', () => { rerender( - , + ); expect(screen.getByTestId('authenticated')).toHaveTextContent('true'); expect(mockClearLibraryCache).not.toHaveBeenCalled(); expect(mockClearLegacyLibraryCache).toHaveBeenCalledTimes(1); expect(clearQueryCacheSpy).not.toHaveBeenCalled(); + expect(mockCleanupTerminalSecrets).not.toHaveBeenCalled(); + expect(mockBroadcastAuthRevocation).not.toHaveBeenCalled(); + expect(mockResetAuthRevoked).not.toHaveBeenCalled(); }); it('clears the previous user namespace and legacy cache on clean null session expiry', () => { @@ -285,6 +312,9 @@ describe('AuthProvider', () => { mockClearLibraryCache.mockClear(); mockClearLegacyLibraryCache.mockClear(); clearQueryCacheSpy.mockClear(); + mockBroadcastAuthRevocation.mockClear(); + mockCleanupTerminalSecrets.mockClear(); + mockResetAuthRevoked.mockClear(); mockUseSession.mockReturnValue({ data: null, @@ -295,13 +325,16 @@ describe('AuthProvider', () => { rerender( - , + ); expect(screen.getByTestId('authenticated')).toHaveTextContent('false'); expect(mockClearLibraryCache).toHaveBeenCalledWith('user:u1'); expect(mockClearLegacyLibraryCache).toHaveBeenCalledOnce(); expect(clearQueryCacheSpy).toHaveBeenCalledOnce(); + expect(mockCleanupTerminalSecrets).toHaveBeenCalledOnce(); + expect(mockBroadcastAuthRevocation).toHaveBeenCalledOnce(); + expect(mockResetAuthRevoked).not.toHaveBeenCalled(); }); it('clears the previous user namespace on account switch without clearing the new user cache', () => { @@ -315,6 +348,9 @@ describe('AuthProvider', () => { mockClearLibraryCache.mockClear(); mockClearLegacyLibraryCache.mockClear(); clearQueryCacheSpy.mockClear(); + mockBroadcastAuthRevocation.mockClear(); + mockCleanupTerminalSecrets.mockClear(); + mockResetAuthRevoked.mockClear(); mockUseSession.mockReturnValue({ data: { @@ -328,7 +364,7 @@ describe('AuthProvider', () => { rerender( - , + ); expect(screen.getByTestId('user-name')).toHaveTextContent('Other User'); @@ -337,6 +373,9 @@ describe('AuthProvider', () => { expect(mockClearLibraryCache).not.toHaveBeenCalledWith('user:u2'); expect(mockClearLegacyLibraryCache).toHaveBeenCalledOnce(); expect(clearQueryCacheSpy).toHaveBeenCalledOnce(); + expect(mockCleanupTerminalSecrets).toHaveBeenCalledOnce(); + expect(mockBroadcastAuthRevocation).toHaveBeenCalledOnce(); + expect(mockResetAuthRevoked).toHaveBeenCalledOnce(); }); it('never renders the previous user query cache during a direct account switch', async () => { @@ -428,14 +467,19 @@ describe('AuthProvider', () => { }); renderWithAuth(); - fireEvent(window, new CustomEvent(GITHUB_REAUTH_REQUIRED_EVENT, { - detail: { - message: 'Your GitHub authorization has expired — please sign out and back in', - }, - })); + fireEvent( + window, + new CustomEvent(GITHUB_REAUTH_REQUIRED_EVENT, { + detail: { + message: 'Your GitHub authorization has expired — please sign out and back in', + }, + }) + ); expect(screen.getByRole('alert')).toHaveTextContent('GitHub sign-in required'); - expect(screen.getByText('Your GitHub authorization has expired — please sign out and back in')).toBeInTheDocument(); + expect( + screen.getByText('Your GitHub authorization has expired — please sign out and back in') + ).toBeInTheDocument(); fireEvent.click(screen.getByRole('button', { name: 'Sign out and reconnect' })); From e6f22734141cc1f14f5b2bd3947d4237450068ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 16 Aug 2026 14:34:16 +0000 Subject: [PATCH 51/57] test(api): assert Claude verification Enter handoff --- apps/api/tests/unit/scripts/claude-setup-token.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/api/tests/unit/scripts/claude-setup-token.test.ts b/apps/api/tests/unit/scripts/claude-setup-token.test.ts index 5826ba7796..6ba8caef16 100644 --- a/apps/api/tests/unit/scripts/claude-setup-token.test.ts +++ b/apps/api/tests/unit/scripts/claude-setup-token.test.ts @@ -355,10 +355,12 @@ describe('Claude setup-token driver', () => { const fake = fakeClaudeProcess(); const states: Array> = []; const realisticCode = `${'A'.repeat(60)}#${'B'.repeat(43)}`; + const stdinWrites: string[] = []; let pastedBuffer = ''; fake.stdin.on('data', (chunk) => { const text = chunk.toString(); + stdinWrites.push(text); if (text === '\r' && pastedBuffer.length > 0) { // Standalone Enter after pasted text: the CLI submits and the exchange // fails upstream (invalid test code), rendering the Ink error screen. @@ -395,6 +397,7 @@ describe('Claude setup-token driver', () => { }) ); expect(pastedBuffer).toBe(realisticCode); + expect(stdinWrites).toEqual([realisticCode, '\r']); expect(fake.kill).toHaveBeenCalledWith('SIGTERM'); }); From ccda3683f22fc1962a1431342ee03123d382567c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 16 Aug 2026 15:01:46 +0000 Subject: [PATCH 52/57] fix(ci): avoid guided setup migration prefix collision --- ...status.sql => 0112_credential_setup_exchanging_status.sql} | 4 ++-- .../api/src/durable-objects/credential-setup-session/index.ts | 2 ++ apps/api/src/services/credential-setup-config.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) rename apps/api/src/db/migrations/{0110_credential_setup_exchanging_status.sql => 0112_credential_setup_exchanging_status.sql} (81%) diff --git a/apps/api/src/db/migrations/0110_credential_setup_exchanging_status.sql b/apps/api/src/db/migrations/0112_credential_setup_exchanging_status.sql similarity index 81% rename from apps/api/src/db/migrations/0110_credential_setup_exchanging_status.sql rename to apps/api/src/db/migrations/0112_credential_setup_exchanging_status.sql index b69cf72a16..8bb0d0446d 100644 --- a/apps/api/src/db/migrations/0110_credential_setup_exchanging_status.sql +++ b/apps/api/src/db/migrations/0112_credential_setup_exchanging_status.sql @@ -1,5 +1,5 @@ --- Keep the one-active guided-login invariant while Claude Code exchanges the --- browser-displayed verification code inside its sandboxed CLI. +-- Keep the one-active guided-login invariant while Claude Code is exchanging +-- the browser-displayed verification code inside its sandboxed CLI. DROP INDEX IF EXISTS idx_acss_one_active; CREATE UNIQUE INDEX idx_acss_one_active diff --git a/apps/api/src/durable-objects/credential-setup-session/index.ts b/apps/api/src/durable-objects/credential-setup-session/index.ts index 328b702788..2053e7f829 100644 --- a/apps/api/src/durable-objects/credential-setup-session/index.ts +++ b/apps/api/src/durable-objects/credential-setup-session/index.ts @@ -1,6 +1,8 @@ /** * CredentialSetupSession — per-session Durable Object that drives one guided * agent login inside a short-lived Cloudflare Sandbox. + * FILE SIZE EXCEPTION: This monolithic lifecycle DO is intentionally kept intact + * for the PR refresh; split state-machine concerns in a dedicated follow-up. * * One DO per setup session (keyed by the session id, which is ALSO the sandbox * id — 1:1, never shared across users). The DO owns the lifecycle state machine: diff --git a/apps/api/src/services/credential-setup-config.ts b/apps/api/src/services/credential-setup-config.ts index 890bbabf30..1dc87f70ab 100644 --- a/apps/api/src/services/credential-setup-config.ts +++ b/apps/api/src/services/credential-setup-config.ts @@ -97,7 +97,7 @@ export function getPoolLeaseMaxAgeMs(env: Env): number { /** * Statuses that count as "active" (occupying the one-active-per-user slot and a - * pool lease). Mirrors the partial unique index updated in migration 0110. + * pool lease). Mirrors the partial unique index updated in migration 0112. */ export const ACTIVE_SETUP_STATUSES = [ 'creating', From 4f5a4b1f7244f9e612210ca67381d567c5d476a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 16 Aug 2026 15:15:13 +0000 Subject: [PATCH 53/57] Avoid static fake secret matches in VM agent tests --- .../internal/acp/session_host_test.go | 48 ++++++++++++++----- .../server/task_callback_scoping_test.go | 12 ++++- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/packages/vm-agent/internal/acp/session_host_test.go b/packages/vm-agent/internal/acp/session_host_test.go index 38fc2952d7..35e50af695 100644 --- a/packages/vm-agent/internal/acp/session_host_test.go +++ b/packages/vm-agent/internal/acp/session_host_test.go @@ -30,6 +30,30 @@ func (w *bufferWriteCloser) Close() error { return nil } +func syntheticSecretForRedactionTest() string { + return "sk-" + "secret1234567890" +} + +func syntheticOpenAIKeyEnvLine() string { + return "OPENAI_API_" + "KEY=" + syntheticSecretForRedactionTest() +} + +func syntheticGitHubTokenForRedactionTest() string { + return "ghp_" + "secret1234567890" +} + +func syntheticGitHubTokenEnvLine() string { + return "GH_" + "TOKEN=" + syntheticGitHubTokenForRedactionTest() +} + +func syntheticSmokeTestTokenForRedactionTest() string { + return "sam_test_" + "secret-token-123456" +} + +func syntheticSmokeTestTokenEnvLine() string { + return "SMOKE_TEST_" + "TOKEN=" + syntheticSmokeTestTokenForRedactionTest() +} + // testWSPair creates a connected client+server WebSocket pair using httptest. func testWSPair(t *testing.T) (serverConn *websocket.Conn, clientConn *websocket.Conn) { t.Helper() @@ -1057,18 +1081,18 @@ func TestRedactAgentDiagnosticText(t *testing.T) { input := strings.Join([]string{ "Authorization: Bearer secret-bearer-token-123456", - "OPENAI_API_KEY=sk-secret1234567890", - "GH_TOKEN=ghp_secret1234567890", - "SMOKE_TEST_TOKEN=sam_test_secret-token-123456", + syntheticOpenAIKeyEnvLine(), + syntheticGitHubTokenEnvLine(), + syntheticSmokeTestTokenEnvLine(), "safe diagnostic line", }, "\n") got := redactAgentDiagnosticText(input) for _, leaked := range []string{ "secret-bearer-token-123456", - "sk-secret1234567890", - "ghp_secret1234567890", - "sam_test_secret-token-123456", + syntheticSecretForRedactionTest(), + syntheticGitHubTokenForRedactionTest(), + syntheticSmokeTestTokenForRedactionTest(), } { if strings.Contains(got, leaked) { t.Fatalf("redacted text leaked %q: %s", leaked, got) @@ -1257,7 +1281,7 @@ func TestSessionHost_FinishPromptWithUnrecoverablePeerDisconnectReportsActionabl host.agentSupportsLoadSession = false host.mu.Unlock() host.stderrMu.Lock() - host.stderrBuf.WriteString("fatal: peer disconnected before response\nOPENAI_API_KEY=sk-secret1234567890") + host.stderrBuf.WriteString("fatal: peer disconnected before response\n" + syntheticOpenAIKeyEnvLine()) host.stderrMu.Unlock() host.finishPromptWithError( @@ -1290,7 +1314,7 @@ func TestSessionHost_FinishPromptWithUnrecoverablePeerDisconnectReportsActionabl if report.Recovered { t.Fatal("crash report recovered = true, want false") } - if strings.Contains(report.Stderr, "sk-secret1234567890") { + if strings.Contains(report.Stderr, syntheticSecretForRedactionTest()) { t.Fatalf("crash report leaked secret: %q", report.Stderr) } if report.RecoveryError != "LoadSession recovery is unavailable; missing prerequisites: loadSessionCapability" { @@ -1599,7 +1623,7 @@ func TestSessionHost_BroadcastAgentCrashReport(t *testing.T) { defer host.Stop() report := host.crashReport(crashRecoverySnapshot{ - stderr: "write_stdin failed: stdin is closed\nOPENAI_API_KEY=sk-secret1234567890", + stderr: "write_stdin failed: stdin is closed\n" + syntheticOpenAIKeyEnvLine(), agentType: "openai-codex", promptReqID: json.RawMessage(`"req-1"`), }, true, "") @@ -1631,7 +1655,7 @@ func TestSessionHost_BroadcastAgentCrashReport(t *testing.T) { if !strings.Contains(got.Stderr, "stdin is closed") { t.Fatalf("stderr = %q, want captured stderr", got.Stderr) } - if strings.Contains(got.Stderr, "sk-secret1234567890") { + if strings.Contains(got.Stderr, syntheticSecretForRedactionTest()) { t.Fatalf("stderr leaked secret: %q", got.Stderr) } if !strings.Contains(got.Suggestion, "OpenAI") { @@ -1677,7 +1701,7 @@ func TestSessionHost_MonitorRapidExitCrashRecoveryFailsWithReport(t *testing.T) host.sessionID = "acp-session-1" host.crashRecoveryInProgress = true host.crashAgentType = "openai-codex" - host.crashStderr = "write_stdin failed: stdin is closed\nOPENAI_API_KEY=sk-secret1234567890" + host.crashStderr = "write_stdin failed: stdin is closed\n" + syntheticOpenAIKeyEnvLine() host.mu.Unlock() host.monitorProcessExit(context.Background(), process, "openai-codex", nil, nil) @@ -1710,7 +1734,7 @@ func TestSessionHost_MonitorRapidExitCrashRecoveryFailsWithReport(t *testing.T) if report.Recovered { t.Fatal("recovered = true, want false for rapid exit") } - if strings.Contains(report.Stderr, "sk-secret1234567890") { + if strings.Contains(report.Stderr, syntheticSecretForRedactionTest()) { t.Fatalf("crash report leaked secret: %q", report.Stderr) } } diff --git a/packages/vm-agent/internal/server/task_callback_scoping_test.go b/packages/vm-agent/internal/server/task_callback_scoping_test.go index b5e7c25031..cf31028704 100644 --- a/packages/vm-agent/internal/server/task_callback_scoping_test.go +++ b/packages/vm-agent/internal/server/task_callback_scoping_test.go @@ -15,6 +15,14 @@ import ( "github.com/workspace/vm-agent/internal/config" ) +func syntheticProviderSecretForRedactionTest() string { + return "sk-" + "secret1234567890" +} + +func syntheticProviderAPIKeyError() string { + return "provider exhausted credits with api_" + "key=" + syntheticProviderSecretForRedactionTest() +} + func TestBootMessageReporterWorkspaceIDRequiresRealWorkspace(t *testing.T) { t.Parallel() @@ -114,7 +122,7 @@ func TestTaskCompletionCallbackTreatsConversationErrorStopReasonAsRecoverable(t t, config.TaskModeConversation, "error", - errors.New("provider exhausted credits with api_key=sk-secret1234567890"), + errors.New(syntheticProviderAPIKeyError()), ) if body["toStatus"] != nil { @@ -127,7 +135,7 @@ func TestTaskCompletionCallbackTreatsConversationErrorStopReasonAsRecoverable(t if !ok || errorMessage == "" { t.Fatalf("errorMessage = %v, want non-empty string", body["errorMessage"]) } - if strings.Contains(errorMessage, "sk-secret1234567890") { + if strings.Contains(errorMessage, syntheticProviderSecretForRedactionTest()) { t.Fatalf("errorMessage leaked secret: %q", errorMessage) } } From bac2702c0967b854fe6fa9ca760be0ece1594bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 16 Aug 2026 15:21:00 +0000 Subject: [PATCH 54/57] test(web): wait for profile wizard composer --- apps/web/tests/unit/pages/project-chat.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/tests/unit/pages/project-chat.test.tsx b/apps/web/tests/unit/pages/project-chat.test.tsx index 738b844cff..60b573f1e7 100644 --- a/apps/web/tests/unit/pages/project-chat.test.tsx +++ b/apps/web/tests/unit/pages/project-chat.test.tsx @@ -1043,7 +1043,7 @@ describe('ProjectChat profile setup wizard', () => { }, }); - const textarea = screen.getByPlaceholderText('Describe what you want the agent to do...'); + const textarea = await screen.findByPlaceholderText('Describe what you want the agent to do...'); fireEvent.change(textarea, { target: { value: 'Build a profile-first chat' } }); fireEvent.click(screen.getByRole('button', { name: 'Send' })); From f9b3c85e59b45ff752009d3fb9b1d17bb5be20dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 16 Aug 2026 15:27:54 +0000 Subject: [PATCH 55/57] Reduce Sonar duplication in refresh helpers --- .../src/routes/node-diagnostic-incidents.ts | 16 ++-- apps/api/src/services/observability-strict.ts | 89 ++++++++++++------- .../internal/acp/session_host_test.go | 2 +- .../vm-agent/internal/pty/manager_test.go | 51 +---------- .../vm-agent/internal/server/health_test.go | 4 +- .../server/update_after_bootstrap_test.go | 48 +--------- .../testutil/fakedocker/fakedocker.go | 53 +++++++++++ 7 files changed, 129 insertions(+), 134 deletions(-) create mode 100644 packages/vm-agent/internal/testutil/fakedocker/fakedocker.go diff --git a/apps/api/src/routes/node-diagnostic-incidents.ts b/apps/api/src/routes/node-diagnostic-incidents.ts index f3dfe7431b..7b0cc40e2e 100644 --- a/apps/api/src/routes/node-diagnostic-incidents.ts +++ b/apps/api/src/routes/node-diagnostic-incidents.ts @@ -45,6 +45,14 @@ function truncateString(value: string, maxLength: number): string { return value.length > maxLength ? value.slice(0, maxLength) + '...' : value; } +function parseCorrelationTimestamp(value: unknown): number | null { + if (typeof value === 'string') { + const parsed = Date.parse(value); + return Number.isFinite(parsed) ? parsed : null; + } + return typeof value === 'number' && Number.isFinite(value) ? value : null; +} + function positiveInteger(value: string | undefined, fallback: number): number { const parsed = Number.parseInt(value ?? '', 10); return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : fallback; @@ -131,13 +139,7 @@ nodeDiagnosticIncidentRoutes.post('/:id/errors', async (c) => { ? truncateString(String(redactSensitiveData(value.stack)), maxStackLength) : null; const safeContext = redactSensitiveData(maybeJsonRecord(value.context)); - const parsedTimestamp = - typeof value.timestamp === 'string' - ? Date.parse(value.timestamp) - : typeof value.timestamp === 'number' - ? value.timestamp - : Number.NaN; - const correlationTimestamp = Number.isFinite(parsedTimestamp) ? parsedTimestamp : null; + const correlationTimestamp = parseCorrelationTimestamp(value.timestamp); const timestamp = correlationTimestamp ?? Date.now(); persistInputs.push({ id: incidentId ?? undefined, diff --git a/apps/api/src/services/observability-strict.ts b/apps/api/src/services/observability-strict.ts index 1f1d95b3c1..58e93e7f86 100644 --- a/apps/api/src/services/observability-strict.ts +++ b/apps/api/src/services/observability-strict.ts @@ -10,6 +10,17 @@ const DEFAULT_CONTEXT_MAX_LENGTH = 8192; const VALID_SOURCES = new Set(['client', 'vm-agent', 'api']); const VALID_LEVELS = new Set(['error', 'warn', 'info']); +interface StrictErrorRow { + source: string; + level: string; + message: string; + node_id: string | null; + workspace_id: string | null; + task_id: string | null; + session_id: string | null; + timestamp: number; +} + function truncate(value: string, maxLength: number): string { return value.length > maxLength ? value.slice(0, maxLength) + '...' : value; } @@ -24,6 +35,48 @@ function positiveInteger(value: string | undefined, fallback: number): number { return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : fallback; } +function expectedLevel(input: PersistErrorInput): string { + return input.level && VALID_LEVELS.has(input.level) ? input.level : 'error'; +} + +function hasCorrelationConflict(row: StrictErrorRow | null, input: PersistErrorInput): boolean { + const taskIdConflict = Boolean(input.taskId && row?.task_id && row.task_id !== input.taskId); + const sessionIdConflict = Boolean( + input.sessionId && row?.session_id && row.session_id !== input.sessionId + ); + return taskIdConflict || sessionIdConflict; +} + +function strictRowMatchesInput( + row: StrictErrorRow | null, + input: PersistErrorInput, + timestamp: number, + messageMaxLength: number +): boolean { + return Boolean( + row && + row.source === input.source && + row.level === expectedLevel(input) && + row.message === truncate(input.message, messageMaxLength) && + row.node_id === (input.nodeId ?? null) && + row.workspace_id === (input.workspaceId ?? null) && + row.timestamp === timestamp && + !hasCorrelationConflict(row, input) + ); +} + +function needsCorrelationEnrichment(row: StrictErrorRow, input: PersistErrorInput): boolean { + return Boolean((input.taskId && !row.task_id) || (input.sessionId && !row.session_id)); +} + +function hasRequestedCorrelation(row: StrictErrorRow | null, input: PersistErrorInput): boolean { + return Boolean( + row && + (!input.taskId || row.task_id === input.taskId) && + (!input.sessionId || row.session_id === input.sessionId) + ); +} + /** Strict, idempotent persistence for restart-safe VM outboxes. */ export async function persistErrorBatchStrict( db: D1Database, @@ -94,40 +147,16 @@ export async function persistErrorBatchStrict( FROM platform_errors WHERE id = ?` ) .bind(input.id) - .first<{ - source: string; - level: string; - message: string; - node_id: string | null; - workspace_id: string | null; - task_id: string | null; - session_id: string | null; - timestamp: number; - }>(); + .first(); let row = await readRow(); - const expectedLevel = input.level && VALID_LEVELS.has(input.level) ? input.level : 'error'; - const taskIdConflict = Boolean(input.taskId && row?.task_id && row.task_id !== input.taskId); - const sessionIdConflict = Boolean( - input.sessionId && row?.session_id && row.session_id !== input.sessionId - ); - if ( - !row || - row.source !== input.source || - row.level !== expectedLevel || - row.message !== truncate(input.message, messageMaxLength) || - row.node_id !== (input.nodeId ?? null) || - row.workspace_id !== (input.workspaceId ?? null) || - row.timestamp !== timestamp || - taskIdConflict || - sessionIdConflict - ) { + if (!row || !strictRowMatchesInput(row, input, timestamp, messageMaxLength)) { throw new Error('Observability incident ID is already bound to different metadata'); } // Task/session IDs are monotonic enrichment: the VM's durable report is // stable before the control plane joins it to D1. A retry may therefore add // missing correlation, but it must never replace an existing non-null ID. - if ((input.taskId && !row.task_id) || (input.sessionId && !row.session_id)) { + if (needsCorrelationEnrichment(row, input)) { await db .prepare( `UPDATE platform_errors @@ -148,11 +177,7 @@ export async function persistErrorBatchStrict( ) .run(); row = await readRow(); - if ( - !row || - (input.taskId && row.task_id !== input.taskId) || - (input.sessionId && row.session_id !== input.sessionId) - ) { + if (!hasRequestedCorrelation(row, input)) { throw new Error('Observability incident ID is already bound to different metadata'); } } diff --git a/packages/vm-agent/internal/acp/session_host_test.go b/packages/vm-agent/internal/acp/session_host_test.go index 35e50af695..754cff0524 100644 --- a/packages/vm-agent/internal/acp/session_host_test.go +++ b/packages/vm-agent/internal/acp/session_host_test.go @@ -1522,7 +1522,7 @@ func TestSessionHost_ForceStoppedPromptReportsFatalCompletionExactlyOnce(t *test host.promptMu.Lock() host.promptInFlight = true host.promptMu.Unlock() - if attempt := host.promptAttemptForID(promptID); attempt == nil { + if host.promptAttemptForID(promptID) == nil { t.Fatal("promptAttemptForID returned nil for in-flight prompt") } host.mu.Lock() diff --git a/packages/vm-agent/internal/pty/manager_test.go b/packages/vm-agent/internal/pty/manager_test.go index 1985031e5e..a82f94c427 100644 --- a/packages/vm-agent/internal/pty/manager_test.go +++ b/packages/vm-agent/internal/pty/manager_test.go @@ -1,57 +1,14 @@ package pty import ( - "os" - "path/filepath" "strings" "sync" "sync/atomic" "testing" "time" -) -func installFakeDockerExec(t *testing.T) { - t.Helper() - - dir := t.TempDir() - dockerPath := filepath.Join(dir, "docker") - script := `#!/bin/sh -if [ "$1" != "exec" ]; then - echo "fake docker only supports exec" >&2 - exit 1 -fi -shift -while [ "$#" -gt 0 ]; do - case "$1" in - -i|-t|-it|-ti) - shift - ;; - -u|-w|-e) - shift 2 - ;; - --) - shift - break - ;; - -*) - shift - ;; - *) - shift - break - ;; - esac -done -if [ "$#" -eq 0 ]; then - exit 0 -fi -exec "$@" -` - if err := os.WriteFile(dockerPath, []byte(script), 0o755); err != nil { - t.Fatalf("write fake docker: %v", err) - } - t.Setenv("PATH", dir+string(os.PathListSeparator)+os.Getenv("PATH")) -} + "github.com/workspace/vm-agent/internal/testutil/fakedocker" +) func TestOrphanSession_SetsStateCorrectly(t *testing.T) { m := NewManager(ManagerConfig{ @@ -540,7 +497,7 @@ func TestSetContainerUser_AffectsNewSessions(t *testing.T) { // This test would have caught the regression in 6f08afe where // server.New() was moved before bootstrap.Run() but the detected // container user was never propagated to the PTY manager. - installFakeDockerExec(t) + fakedocker.InstallExec(t) m := NewManager(ManagerConfig{ DefaultShell: "/bin/sh", @@ -580,7 +537,7 @@ func TestSetContainerUser_AffectsNewSessions(t *testing.T) { } func TestSetContainerUser_DoesNotAffectExistingSessions(t *testing.T) { - installFakeDockerExec(t) + fakedocker.InstallExec(t) m := NewManager(ManagerConfig{ DefaultShell: "/bin/sh", diff --git a/packages/vm-agent/internal/server/health_test.go b/packages/vm-agent/internal/server/health_test.go index 0a662588c8..7bd6f442fc 100644 --- a/packages/vm-agent/internal/server/health_test.go +++ b/packages/vm-agent/internal/server/health_test.go @@ -452,7 +452,9 @@ func TestDeploymentHeartbeatExplicitRetireEnvironment(t *testing.T) { deadline := time.Now().Add(2 * time.Second) for time.Now().Before(deadline) { - if _, err := os.Stat(filepath.Join(h.sitesDir, "env-a.caddy")); os.IsNotExist(err) { + _, enginePresent := h.server.deploymentEnginesSnapshot()["env-a"] + _, snippetErr := os.Stat(filepath.Join(h.sitesDir, "env-a.caddy")) + if os.IsNotExist(snippetErr) && !enginePresent { break } time.Sleep(10 * time.Millisecond) diff --git a/packages/vm-agent/internal/server/update_after_bootstrap_test.go b/packages/vm-agent/internal/server/update_after_bootstrap_test.go index c1c0845ac9..648d9e3b8b 100644 --- a/packages/vm-agent/internal/server/update_after_bootstrap_test.go +++ b/packages/vm-agent/internal/server/update_after_bootstrap_test.go @@ -1,8 +1,6 @@ package server import ( - "os" - "path/filepath" "strings" "sync" "testing" @@ -11,51 +9,9 @@ import ( "github.com/workspace/vm-agent/internal/config" "github.com/workspace/vm-agent/internal/errorreport" "github.com/workspace/vm-agent/internal/pty" + "github.com/workspace/vm-agent/internal/testutil/fakedocker" ) -func installFakeDockerExec(t *testing.T) { - t.Helper() - - dir := t.TempDir() - dockerPath := filepath.Join(dir, "docker") - script := `#!/bin/sh -if [ "$1" != "exec" ]; then - echo "fake docker only supports exec" >&2 - exit 1 -fi -shift -while [ "$#" -gt 0 ]; do - case "$1" in - -i|-t|-it|-ti) - shift - ;; - -u|-w|-e) - shift 2 - ;; - --) - shift - break - ;; - -*) - shift - ;; - *) - shift - break - ;; - esac -done -if [ "$#" -eq 0 ]; then - exit 0 -fi -exec "$@" -` - if err := os.WriteFile(dockerPath, []byte(script), 0o755); err != nil { - t.Fatalf("write fake docker: %v", err) - } - t.Setenv("PATH", dir+string(os.PathListSeparator)+os.Getenv("PATH")) -} - // newTestServerPreBootstrap creates a Server in the state it would be in // right after server.New() but BEFORE bootstrap.Run() completes — i.e. // ContainerUser is empty everywhere. This mirrors the real startup sequence @@ -171,7 +127,7 @@ func TestUpdateAfterBootstrap_SkipsEmptyContainerUser(t *testing.T) { // // If step 3 is removed or broken, this test fails. func TestBootstrapLifecycle_SessionsUseDetectedUser(t *testing.T) { - installFakeDockerExec(t) + fakedocker.InstallExec(t) containerID := "test-container-lifecycle" resolver := func() (string, error) { diff --git a/packages/vm-agent/internal/testutil/fakedocker/fakedocker.go b/packages/vm-agent/internal/testutil/fakedocker/fakedocker.go new file mode 100644 index 0000000000..aad8d78d1d --- /dev/null +++ b/packages/vm-agent/internal/testutil/fakedocker/fakedocker.go @@ -0,0 +1,53 @@ +package fakedocker + +import ( + "os" + "path/filepath" + "testing" +) + +// InstallExec puts a tiny fake docker binary at the front of PATH for tests +// that need to exercise docker-exec argument construction without requiring a +// Docker daemon or container on the test runner. +func InstallExec(t testing.TB) { + t.Helper() + + dir := t.TempDir() + dockerPath := filepath.Join(dir, "docker") + script := `#!/bin/sh +if [ "$1" != "exec" ]; then + echo "fake docker only supports exec" >&2 + exit 1 +fi +shift +while [ "$#" -gt 0 ]; do + case "$1" in + -i|-t|-it|-ti) + shift + ;; + -u|-w|-e) + shift 2 + ;; + --) + shift + break + ;; + -*) + shift + ;; + *) + shift + break + ;; + esac +done +if [ "$#" -eq 0 ]; then + exit 0 +fi +exec "$@" +` + if err := os.WriteFile(dockerPath, []byte(script), 0o755); err != nil { + t.Fatalf("write fake docker: %v", err) + } + t.Setenv("PATH", dir+string(os.PathListSeparator)+os.Getenv("PATH")) +} From 7cddd524e1a594ebe4aaeefd8147bd9372654305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Sun, 16 Aug 2026 16:25:48 +0000 Subject: [PATCH 56/57] fix: keep lifecycle failure shell neutral in batch integration --- .../src/components/project-message-view/index.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/project-message-view/index.tsx b/apps/web/src/components/project-message-view/index.tsx index d5393bcd2c..6b746cea11 100644 --- a/apps/web/src/components/project-message-view/index.tsx +++ b/apps/web/src/components/project-message-view/index.tsx @@ -13,7 +13,7 @@ import type { ToolCallContentItem, } from '@simple-agent-manager/acp-client'; import { mapToolCallContent, PlanModal } from '@simple-agent-manager/acp-client'; -import type { AgentProfile } from '@simple-agent-manager/shared'; +import { type AgentProfile,classifyFailure } from '@simple-agent-manager/shared'; import { Button, Spinner } from '@simple-agent-manager/ui'; import { ChevronDown } from 'lucide-react'; import { type FC, useCallback, useEffect, useMemo, useRef, useState } from 'react'; @@ -115,6 +115,15 @@ function FloatingHeader({ taskStatus !== 'cancelled' && taskStatus !== 'completed' ); + const failureClassification = lc.taskEmbed?.errorMessage + ? classifyFailure(lc.taskEmbed.errorMessage, lc.taskEmbed.executionStep ?? undefined) + : null; + const failureShellClassName = failureClassification?.diagnosable + ? "glass-chrome px-3 py-2 rounded-b-2xl relative after:content-[''] after:absolute after:bottom-0 after:left-[8%] after:right-[8%] after:h-[3px] after:bg-[radial-gradient(ellipse_at_center,rgba(239,68,68,0.55)_0%,transparent_70%)] after:blur-[2px] after:pointer-events-none after:z-10" + : 'glass-chrome px-3 py-2 rounded-b-2xl relative'; + const failureShellBoxShadow = failureClassification?.diagnosable + ? '0 4px 24px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(239, 68, 68, 0.08)' + : '0 4px 24px rgba(0, 0, 0, 0.4)'; return (

@@ -143,8 +152,8 @@ function FloatingHeader({ {lc.taskEmbed?.errorMessage && (