{"record":{"id":"fbf3a71933fac3a2","repo":"different-ai/openwork","slug":"file-not-found-in-this-workspace","errorCode":null,"errorMessage":"File not found in this workspace.","messagePattern":"File not found in this workspace\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/app/src/react-app/domains/session/artifacts/artifact-panel.tsx","lineNumber":131,"sourceCode":"    const nextTarget = openTargetFromWorkspaceFile(entry.path, { size: entry.size, updatedAt: entry.mtimeMs });\n    if (!nextTarget) return;\n    usePanelTabStore.getState().openTab(sessionId, {\n      id: nextTarget.id,\n      type: \"artifact\",\n      label: nextTarget.name,\n      preview: nextTarget.preview,\n      target: nextTarget,\n    });\n  };\n\n  const { data, error, isError, isLoading } = useQuery<ArtifactQueryState>({\n    queryKey: [\"artifact-panel\", workspaceId, target.id, target.updatedAt ?? null] as const,\n    queryFn: async () => {\n      if (target.kind === \"url\") {\n        throw new Error(\"URLs open in browser tabs.\");\n      }\n      else if (target.exists === false) {\n        throw new Error(\"File not found in this workspace.\");\n      }\n\n      if (isTextContent(target)) {\n        const result = await client.readWorkspaceFile(workspaceId, target.value);\n\n        return { kind: \"text\", data: result.content, updatedAt: result.updatedAt ?? null };\n      }\n\n      const result = await client.downloadWorkspaceFile(workspaceId, target.value);\n\n      return { kind: \"binary\", data: result.data, contentType: result.contentType, updatedAt: target.updatedAt ?? null };\n    },\n    refetchOnReconnect: false,\n    refetchOnWindowFocus: false,\n    staleTime: Infinity,\n    gcTime: 0,\n  });\n","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/react-app/domains/session/artifacts/artifact-panel.tsx#L113-L149","documentation":"When the artifact target is flagged as nonexistent (target.exists === false), the panel's query function throws 'File not found in this workspace.' so React Query shows an error state. This reflects that the workspace no longer (or never did) contain the file at target.value.","triggerScenarios":"ArtifactPanelView's useQuery queryFn runs with target.exists === false — the workspace metadata says the file for this artifact is missing.","commonSituations":"File deleted or moved after the artifact entry was created; stale artifact list cached with an outdated updatedAt; workspace switched or re-provisioned so the referenced file path no longer exists; session resumed on a fresh workspace.","solutions":["Refresh the session artifact list so deleted/moved files drop out of the panel.","Verify the workspaceId and target.value path still correspond to an existing file.","Restore the file or re-run the agent step that produced the artifact.","Handle the isError state in the panel with a 'file no longer available' message instead of a raw error."],"exampleFix":"// before: stale artifact opened directly\nopenArtifactPanel({ id, value: \"reports/old.md\", exists: false });\n// after: refetch artifacts and open only existing ones\nconst artifacts = await refetchArtifacts();\nconst target = artifacts.find((a) => a.id === id && a.exists !== false);\nif (target) openArtifactPanel(target);","handlingStrategy":"fallback","validationCode":"if (target.exists === false) {\n  return <EmptyState message=\"File not found in this workspace.\" />;\n}","typeGuard":"function fileExists(target: ArtifactTarget): boolean {\n  return target.kind === \"file\" && target.exists !== false;\n}","tryCatchPattern":"const { data, isError, error } = useQuery({ queryKey: [...], queryFn });\nif (isError && error.message === \"File not found in this workspace.\") {\n  return <EmptyState message=\"This file is no longer available.\" onRefresh={refetchArtifacts} />;\n}","preventionTips":["Refresh the artifact list after any file mutation in the workspace.","Key the query on workspaceId + updatedAt so stale entries refetch.","Show a friendly empty state instead of a raw error for missing files.","Clean up artifact records when their backing files are deleted."],"tags":["react-query","artifacts","missing-file","workspace"],"backgroundTag":"file-not-found","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}