{"record":{"id":"c7834e5ee91f0b71","repo":"paperclipai/paperclip","slug":"fake-setup-session-not-found","errorCode":null,"errorMessage":"Fake setup session not found.","messagePattern":"Fake setup session not found\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/plugins/paperclip-plugin-fake-sandbox/src/plugin.ts","lineNumber":428,"sourceCode":"        status: \"missing\",\n        connectionSummary: null,\n        connectionPayload: null,\n        metadata: {\n          provider: \"fake-plugin\",\n          found: false,\n        },\n      };\n    }\n    return presentSetupSession(state, { includeConnectionPayload: params.includeConnectionPayload === true });\n  },\n\n  async onEnvironmentCaptureTemplate(\n    params: PluginEnvironmentCaptureTemplateParams,\n  ): Promise<PluginEnvironmentCaptureTemplateResult> {\n    const config = parseConfig(params.config);\n    const state = params.providerLeaseId ? setupSessions.get(params.providerLeaseId) : undefined;\n    if (!state) {\n      throw new Error(\"Fake setup session not found.\");\n    }\n    if (state.status === \"cancelled\" || state.status === \"timed_out\" || state.status === \"failed\") {\n      throw new Error(`Fake setup session cannot be captured from status ${state.status}.`);\n    }\n\n    state.status = \"capturing\";\n    const templateRef = buildTemplateRef(state.environmentId, state.sessionId);\n    const template: FakeTemplateState = {\n      templateRef,\n      environmentId: state.environmentId,\n      sessionId: state.sessionId,\n      image: config.image,\n      sourceTemplateRef: params.sourceTemplateRef ?? state.sourceTemplateRef,\n      previousTemplateRef: params.previousTemplateRef ?? null,\n      deleted: false,\n    };\n    templates.set(templateRef, template);\n    state.status = \"promoted\";","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/packages/plugins/paperclip-plugin-fake-sandbox/src/plugin.ts#L410-L446","documentation":"Thrown by the fake sandbox plugin's onEnvironmentCaptureTemplate() when no setup session is found in the in-memory setupSessions map for the given providerLeaseId (or providerLeaseId is undefined/null). The fake sandbox is a test double that simulates an interactive environment provider; capture requires a live setup session previously created via onEnvironmentStartInteractiveSetup().","triggerScenarios":"Calling captureTemplate with a providerLeaseId that was never started, or after the session was evicted by removeLease(). Calling captureTemplate without a providerLeaseId (the lookup is skipped and state is undefined). Calling capture after the session expired and was garbage-collected by the fake provider.","commonSituations":"Test harness calling capture before start. Using a stale lease id from a previous test run in a long-lived fake sandbox instance. Race between cancel/timeout cleanup and a capture attempt.","solutions":["Ensure onEnvironmentStartInteractiveSetup() ran first and returned a providerLeaseId; pass that exact id to captureTemplate.","Re-open the setup session via onEnvironmentStartInteractiveSetup() (it is idempotent and reuses or recreates the session for the environmentId/sessionId pair).","In tests, reset the fake sandbox state between cases so lease ids from prior runs do not leak."],"exampleFix":"// before\nawait plugin.onEnvironmentCaptureTemplate({ providerLeaseId: staleOrMissingId, ... });\n// after\nconst session = await plugin.onEnvironmentStartInteractiveSetup({ environmentId, sessionId, ... });\nawait plugin.onEnvironmentCaptureTemplate({ providerLeaseId: session.providerLeaseId, ... });","handlingStrategy":"validation","validationCode":"// before capturing, ensure a session exists\nconst session = await plugin.onEnvironmentGetInteractiveSetup({ providerLeaseId });\nif (session.status === \"missing\") {\n  const started = await plugin.onEnvironmentStartInteractiveSetup({ environmentId, sessionId /* ... */ });\n  // use started.providerLeaseId\n}","typeGuard":"function hasSetupSession<T extends { status: string }>(s: T | undefined): s is T & { status: Exclude<T[\"status\"], \"missing\"> } {\n  return !!s && (s as { status: string }).status !== \"missing\";\n}","tryCatchPattern":"try {\n  await plugin.onEnvironmentCaptureTemplate({ providerLeaseId, ... });\n} catch (err) {\n  if (err instanceof Error && err.message === \"Fake setup session not found.\") {\n    // re-open setup then retry once\n  } else throw err;\n}","preventionTips":["Always start interactive setup before capture and reuse the returned providerLeaseId.","Reset fake-sandbox state between tests.","Check session existence via getInteractiveSetup before capturing."],"tags":["fake-sandbox","test-double","state","environment"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}