{"record":{"id":"add907f30ea3d65c","repo":"different-ai/openwork","slug":"app-error-compact-no-session-id","errorCode":null,"errorMessage":"app.error_compact_no_session_id","messagePattern":"app\\.error_compact_no_session_id","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/app/src/react-app/domains/session/sync/actions-store.ts","lineNumber":647,"sourceCode":"    const text = lastPromptSent().trim();\n    if (!text) return;\n    void sendPrompt({\n      mode: \"prompt\",\n      text,\n      parts: [{ type: \"text\", text }],\n      attachments: [],\n    });\n  }\n\n  async function compactCurrentSession(sessionIdOverride?: string) {\n    const c = options.client();\n    if (!c) {\n      throw new Error(t(\"app.error_not_connected\"));\n    }\n\n    const sessionID = (sessionIdOverride ?? options.selectedSessionId() ?? \"\").trim();\n    if (!sessionID) {\n      throw new Error(t(\"app.error_compact_no_session_id\"));\n    }\n\n    const visible = options.messages();\n    if (!visible.length) {\n      throw new Error(t(\"app.error_compact_empty\"));\n    }\n\n    const model = options.selectedSessionModel();\n    const startedAt = perfNow();\n    const modelLabel = `${model.providerID}/${model.modelID}`;\n    recordPerfLog(options.developerMode(), \"session.compact\", \"start\", {\n      sessionID,\n      messageCount: visible.length,\n      model: modelLabel,\n      variant: options.sanitizeModelVariantForRef(model, options.modelVariant()) ?? null,\n    });\n\n    try {","sourceCodeStart":629,"sourceCodeEnd":665,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/react-app/domains/session/sync/actions-store.ts#L629-L665","documentation":"After confirming a client exists, compactCurrentSession resolves the session ID from the override argument or the currently selected session; if the trimmed result is empty it throws the localized 'app.error_compact_no_session_id'. The compact API needs an explicit session identifier and the UI cannot determine one.","triggerScenarios":"Calling compactCurrentSession() with no sessionIdOverride while options.selectedSessionId() returns null/undefined/whitespace — e.g. no session is selected, the session list hasn't loaded, or the selected session was deleted.","commonSituations":"Invoking compact programmatically or via a shortcut before any session is selected; stale UI after a session deletion; session ID lost after a reconnect that reset selection.","solutions":["Select a session in the UI (or pass a sessionIdOverride) before compacting.","Gate the compact action on a non-empty selectedSessionId so it's disabled when nothing is selected.","If a session is visually selected but the ID is empty, check selection state restoration after reconnect/delete."],"exampleFix":"// before\nawait compactCurrentSession(); // no override, nothing selected\n// after\nconst sid = selectedSessionId();\nif (!sid) { showToast(\"Select a session first\"); return; }\nawait compactCurrentSession(sid);","handlingStrategy":"validation","validationCode":"const sid = (selectedSessionId() ?? \"\").trim();\nif (!sid) {\n  showToast(\"Select a session before compacting\");\n  return;\n}\nawait compactCurrentSession(sid);","typeGuard":"function hasSessionId(s: { selectedSessionId?: string | null }): s is { selectedSessionId: string } {\n  return typeof s.selectedSessionId === \"string\" && s.selectedSessionId.trim().length > 0;\n}","tryCatchPattern":"try {\n  await compactCurrentSession();\n} catch (e) {\n  if (e instanceof Error && e.message === \"app.error_compact_no_session_id\") {\n    openSessionPicker();\n    return;\n  }\n  throw e;\n}","preventionTips":["Disable the compact action when no session is selected.","Clear or refresh selection state after session deletion/reconnect so stale IDs never mask as valid.","Pass an explicit sessionIdOverride in scripts/automation instead of relying on UI selection."],"tags":["session","compact","missing-argument"],"backgroundTag":"missing-session-id","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}