export interface PersistedAsyncTriggerResult { status: 'pending' | 'completed' | 'failed'; createdAt: number; completedAt?: number; content?: string; /** Set only when status==='failed'. `dispatch_unknown` is the at-most-once * ambiguous-crash outcome written by the idempotency reconcile/barrier; * `turn_terminal` is an explicit failed/ambiguous terminal emitted by the * still-live worker. */ failedAt?: number; errorCode?: 'no_output' | 'trigger_failed'; reason?: 'dispatch_unknown' | 'turn_terminal'; /** Original structured worker terminal code retained for programmatic * callers without widening TriggerResponse.errorCode with provider values. */ terminalErrorCode?: string; /** Per-turn token usage captured at completion (codex-app). Optional — omitted * when the turn produced no coherent usage. */ usage?: { inputTokens: number; outputTokens: number; cacheReadTokens: number; cacheCreateTokens: number; }; } /** Record a freshly-armed async trigger as pending. Best-effort; a failed write * only loses the restart-recovery guarantee, never the in-memory path. * `ownerLarkAppId` is REQUIRED — it stamps the owning bot so cross-bot lookups * can be rejected fail-closed (an unstamped file would be un-attributable and * therefore un-servable). Pass '' only in tests that deliberately exercise the * legacy-unstamped path. */ export declare function recordPending(sessionId: string, triggerId: string, createdAt: number, ownerLarkAppId: string): void; /** Mark an async trigger completed with its captured final output. * `ownerLarkAppId` is REQUIRED (see recordPending). `usage` optional per-turn tokens. */ export declare function recordCompleted(sessionId: string, triggerId: string, content: string, completedAt: number, ownerLarkAppId: string, usage?: PersistedAsyncTriggerResult['usage']): void; /** * Record a durable `failed` async outcome (STRICT). This is the authoritative * terminal state the idempotency reconcile/barrier writes for a * `dispatch_unknown` turn — an at-most-once ambiguous crash that must NOT be * re-run. Unlike recordPending/recordCompleted's best-effort save, this: * - takes the per-session cross-process lock (serialized with recordCompleted), * - writes crash-durable (fsync temp + rename), and * - THROWS on any I/O error (the caller must treat a failed persist as a hard * failure — the whole point is that this evidence is authoritative). * * Completed-wins invariant: if a `completed` result is ALREADY on disk for this * triggerId, this is a no-op and returns `already_completed` (the turn finished; * the stronger proof stands). We deliberately do NOT make `failed` irreversible — * a completed arriving later still wins via recordCompleted (same lock). * * Returns a discriminated in-lock outcome so a caller that races a late completion * reacts to what ACTUALLY happened under the lock (no TOCTOU): `already_completed` * = a completed was on disk, nothing written, the caller must resolve completed; * `written_failed` = the durable failed was written (codex #818 P1-8 race). */ export type RecordFailedStrictOutcome = 'written_failed' | 'already_completed'; export declare function recordFailedStrict(sessionId: string, triggerId: string, failedAt: number, ownerLarkAppId: string, reason?: 'dispatch_unknown'): RecordFailedStrictOutcome; /** Persist an explicit failed/ambiguous worker terminal for an async trigger. * Uses the same owner-proofed, durable, completed-wins transaction as * recordFailedStrict, while retaining the structured terminal code so polling * returns an immediate provider failure rather than a generic no-output state. */ export declare function recordTerminalFailureStrict(sessionId: string, triggerId: string, failedAt: number, ownerLarkAppId: string, terminalErrorCode: string): RecordFailedStrictOutcome; /** Look up a persisted result. With no triggerId, resolves the latest recorded * one (mirrors the in-memory latestAsyncTriggerId semantics). Returns the * stamped `ownerLarkAppId` (if any) so the caller can enforce cross-bot * isolation before trusting the result. */ export declare function lookup(sessionId: string, triggerId?: string): { triggerId: string; result: PersistedAsyncTriggerResult; ownerLarkAppId?: string; } | undefined; /** STRICT variant of `lookup`: ONLY a genuinely absent file (ENOENT) or an * absent trigger id yields `undefined`. A present-but-unreadable file * (EIO/EACCES), corrupt JSON, or invalid shape THROWS. Use this wherever a * soft "no record" would be misread as "no terminal outcome" and drive a * fail-OPEN action — e.g. the codex-app recovery fence, which must NOT replay a * keyed turn just because its durable `failed(dispatch_unknown)` proof happens * to be transiently unreadable (the soft `load()` folds that into `{}` and the * accepted ledger entry would re-enter the recovery snapshot). Fail-closed: * the caller aborts the fork and retries at the next seam. */ export declare function lookupStrict(sessionId: string, triggerId?: string): { triggerId: string; result: PersistedAsyncTriggerResult; ownerLarkAppId?: string; } | undefined; /** Delete a session's persisted async results (called on session close). */ export declare function deleteResults(sessionId: string): void; //# sourceMappingURL=async-trigger-store.d.ts.map