{"record":{"id":"e15672ff62fa21ba","repo":"coleam00/Archon","slug":"isolation-resolution-stuck-in-stale-cleaned-loop-f","errorCode":null,"errorMessage":"Isolation resolution stuck in stale_cleaned loop for conversation ${conversation.id}","messagePattern":"Isolation resolution stuck in stale_cleaned loop for conversation (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/orchestrator/orchestrator.ts","lineNumber":245,"sourceCode":"      // Clear stale reference\n      await db.updateConversation(conversation.id, { isolation_env_id: null }).catch(e => {\n        if (!(toError(e) instanceof ConversationNotFoundError)) {\n          getLog().error(\n            { err: toError(e), conversationId: conversation.id },\n            'stale_isolation_clear_failed'\n          );\n        }\n      });\n      const staleMsg = codebase\n        ? 'Detected a stale isolated workspace reference and cleared it. Creating a new isolated workspace now.'\n        : 'Detected a stale isolated workspace reference and cleared it. Continuing without an isolated workspace.';\n      await platform.sendMessage(conversationId, staleMsg).catch(e => {\n        getLog().error({ err: toError(e), conversationId }, 'stale_isolation_notice_failed');\n      });\n      // Retry without existing env (guard against infinite recursion)\n      if (!codebase) return { status: 'none', cwd: conversation.cwd ?? '/workspace', env: null };\n      if (_isRetry) {\n        throw new Error(\n          `Isolation resolution stuck in stale_cleaned loop for conversation ${conversation.id}`\n        );\n      }\n      return validateAndResolveIsolation(\n        { ...conversation, isolation_env_id: null },\n        codebase,\n        platform,\n        conversationId,\n        hints,\n        true,\n        userId\n      );\n    }\n\n    case 'none':\n      return { status: 'none', cwd: result.cwd, env: null };\n\n    case 'blocked':","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/orchestrator/orchestrator.ts#L227-L263","documentation":"validateAndResolveIsolation detects that retrying isolation resolution after a stale_cleaned environment still produced a stale-cleaned state, meaning the loop guard fired. The engine retried once with a cleared isolation_env_id and still could not obtain a valid isolation environment, so it throws rather than recursing forever.","triggerScenarios":"A conversation carries an isolation_env_id whose environment is reported stale/cleaned; the retry path clears the id and re-resolves, but validation still fails with stale_cleaned and _isRetry is true — e.g. the environment store keeps returning a stale status for the freshly resolved env.","commonSituations":"A stale environment record that the store fails to purge or replace; a misbehaving isolation provider marking new envs as cleaned; concurrent cleanup jobs racing with resolution; corrupted isolation env state in the database.","solutions":["Inspect the isolation environment store/records for conversation ${conversation.id} and purge stale entries manually.","Check for concurrent cleanup jobs racing with run dispatch and pause them.","Clear the conversation's isolation_env_id and retry the dispatch fresh.","Verify the isolation provider is healthy and returns non-stale environments."],"exampleFix":"// before (persistence)\nconversation.isolation_env_id = \"env-stale-123\"; // repeatedly resolves to stale_cleaned\n// after (repair)\nawait db.updateConversation(conversation.id, { isolation_env_id: null });\n// then re-dispatch","handlingStrategy":"retry","validationCode":"const env = await getIsolationEnv(conversation.isolation_env_id);\nif (env?.status === 'stale_cleaned') await clearIsolationEnvId(conversation.id);","typeGuard":null,"tryCatchPattern":"try {\n  await dispatch(conversationId);\n} catch (e) {\n  if (e.message.includes('stale_cleaned loop')) {\n    await purgeStaleIsolationRecords(conversationId);\n    await clearIsolationEnvId(conversationId);\n    await dispatch(conversationId); // one manual retry after repair\n  } else throw e;\n}","preventionTips":["Purge stale isolation env records instead of leaving them attached to conversations.","Avoid running cleanup jobs concurrently with run dispatch.","Monitor the isolation provider health so stale statuses are caught early."],"tags":["isolation","state","retry","orchestrator"],"backgroundTag":"stale-isolation-environment","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}