{"record":{"id":"e8f656c281eab10f","repo":"slopus/happy","slug":"no-happy-session-found-matching-trimmed","errorCode":null,"errorMessage":"No Happy session found matching \"${trimmed}\"","messagePattern":"No Happy session found matching \"(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/happy-cli/src/resume/resolveHappySession.ts","lineNumber":67,"sourceCode":"};\n\nexport type ReconnectableHappySession = ResumableHappySession & {\n    seq: number;\n    metadataVersion: number;\n    agentStateVersion: number;\n    encryptionKey: Uint8Array;\n    encryptionVariant: 'legacy' | 'dataKey';\n};\n\nexport function resolveSessionRecordByPrefix<T extends { id: string }>(records: T[], sessionId: string): T {\n    const trimmed = sessionId.trim();\n    if (!trimmed) {\n        throw new Error('Happy session ID is required: happy resume <session-id>');\n    }\n\n    const matches = records.filter((record) => record.id.startsWith(trimmed));\n    if (matches.length === 0) {\n        throw new Error(`No Happy session found matching \"${trimmed}\"`);\n    }\n    if (matches.length > 1) {\n        throw new Error(`Ambiguous Happy session \"${trimmed}\" matches ${matches.length} sessions. Be more specific.`);\n    }\n    return matches[0];\n}\n\nfunction decryptBoxBundle(bundle: Uint8Array, recipientSecretKey: Uint8Array): Uint8Array | null {\n    if (bundle.length < 56) {\n        return null;\n    }\n\n    const ephemeralPublicKey = bundle.slice(0, 32);\n    const nonce = bundle.slice(32, 56);\n    const ciphertext = bundle.slice(56);\n    const decrypted = tweetnacl.box.open(ciphertext, nonce, ephemeralPublicKey, recipientSecretKey);\n\n    return decrypted ? new Uint8Array(decrypted) : null;","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/resume/resolveHappySession.ts#L49-L85","documentation":"After trimming, resolveSessionRecordByPrefix filters the supplied records for IDs starting with the given prefix. If zero records match, it throws this error: the prefix is well-formed but no known Happy session starts with it. The library throws instead of returning null so the CLI can surface a clear lookup failure.","triggerScenarios":"Calling resolveSessionRecordByPrefix(records, \"abc123\") where no record.id in the passed array starts with \"abc123\" — typically because the session was deleted, the prefix is mistyped, or the records array was fetched from the wrong account.","commonSituations":"Typos or truncated copy-paste of a session ID; resuming a session created under a different account/machine; the session expired or was purged server-side; stale local cache of sessions.","solutions":["Re-run `happy` to list current sessions and copy the exact ID, then resume with the correct prefix.","Use a longer/complete session ID to rule out partial-copy mistakes.","Verify you are authenticated as the account that owns the session (re-authenticate if needed).","Confirm the session still exists — if it was deleted or rotated, start a new session instead."],"exampleFix":"// before\nconst session = await resolveHappySession('abc12'); // mistyped prefix\n// after\nconst session = await resolveHappySession('a1b2c3d4-e5f6-7890-abcd-ef1234567890'); // full ID copied from session list","handlingStrategy":"try-catch","validationCode":"// Optional pre-check when you already hold the record list:\nconst exists = records.some(r => r.id.startsWith(prefix));\nif (!exists) console.error('No session matches that prefix — list sessions first');","typeGuard":null,"tryCatchPattern":"try {\n  const session = await resolveHappySession(prefix);\n} catch (err) {\n  if ((err as Error).message.includes('No Happy session found matching')) {\n    // print available sessions and re-prompt for the ID\n  } else throw err;\n}","preventionTips":["Copy full session IDs rather than retyping prefixes from memory.","List sessions programmatically before resuming to pick a valid ID.","Ensure you're authenticated as the account that owns the session."],"tags":["cli","session-lookup","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}