@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
119 lines • 5.56 kB
TypeScript
import type { EventLeases } from "./compact-event-leases.ts";
import type { RecoveryRepairAdvice } from "../../../vendor/pi-protocol/index.js";
import { RecoveryCursors } from "./compact-recovery-cursor.ts";
import type { RecoveryCheckpoints } from "./compact-recovery-state.ts";
import type { RecoveryCaller, RecoveryFailure, RecoveryLease } from "./compact-recovery-types.ts";
/** B3's request fields: every one an opaque bounded id, parsed before any use. */
export interface RecoveryPageRequest {
readonly requestId: string;
readonly admissionId: string;
readonly token: string;
readonly componentRef: string;
readonly cursor?: string;
}
/** The same request naming its lease by kind (S13, RULING-65 S13-Q1 A, RULING-81 Q-C): an unknown kind is refused. */
export interface LeasePageRequest {
readonly requestId: string;
readonly admissionId: string;
readonly lease: {
readonly kind: RecoveryLease["kind"];
readonly id: string;
};
readonly componentRef: string;
readonly cursor?: string;
}
/**
* One page as the wire carries it (B3, RULING-69 (1)): `bytes` is the base64 of exactly `length` raw stored bytes at
* `offset`; `digest` is over those raw bytes, so a client verifies it after decoding. `cursor` continues the component
* or is null once `complete`.
*/
export interface RecoveryPageAnswer {
readonly repair?: RecoveryRepairAdvice;
readonly requestId: string;
readonly token: string;
readonly generation: number;
readonly componentRef: string;
readonly ordinal: number;
readonly offset: number;
readonly length: number;
readonly digest: string;
readonly bytes: string;
readonly cursor: string | null;
readonly complete: boolean;
}
/** A page under an event lease: the lease in place of the token and its generation, which an event lease never has. */
export type EventPageAnswer = Omit<RecoveryPageAnswer, "token" | "generation"> & {
readonly lease: {
readonly kind: "event";
readonly id: string;
};
};
export type RequestRefusalReason = "malformed_request" | "busy" | "request_limit" | "request_mismatch" | "invalid_cursor" | "cursor_out_of_range" | "ordinal_exhausted" | "lease_kind_unsupported";
/** What the client does next: wait for the current request, start the component over, re-admit, or send a new id. */
export type RequestRefusalHint = "retry" | "restart_from_catalog" | "release_token" | "new_request";
export interface RequestRefusal {
readonly kind: "request_refused";
readonly reason: RequestRefusalReason;
readonly hint: RequestRefusalHint;
}
export type RecoveryPageFailure = RecoveryFailure | RequestRefusal;
export type RecoveryPageOutcome = {
readonly ok: true;
readonly value: RecoveryPageAnswer;
} | {
readonly ok: false;
readonly failure: RecoveryPageFailure;
};
export interface RecoveryPageCounters {
readonly tokens: number;
readonly outstanding: number;
readonly cachedBytes: number;
readonly refused: Readonly<Partial<Record<RequestRefusalReason, number>>>;
}
type PageRequest = RecoveryPageRequest | LeasePageRequest;
type PageOutcome = {
readonly ok: true;
readonly value: RecoveryPageAnswer | EventPageAnswer;
} | {
readonly ok: false;
readonly failure: RecoveryPageFailure;
};
/**
* The page requests of one host over its checkpoint owner (S11b, RULING-62 Q1 A): one monotonically advancing ordinal
* per token, one active request per token (a second concurrent one is `busy`, taking no slot and no memory), at most
* `SOCKET_PAGE_REQUESTS_MAX` outstanding per socket, and one cached page per token so an exact retry answers identical
* bytes without a read; the cache goes when the next request advances or the token ends. Every refusal is typed and
* happens before any byte is read.
*/
export declare class RecoveryPageRequests {
private readonly checkpoints;
private readonly cursors;
private readonly events;
private readonly tokens;
private readonly outstanding;
private readonly refusals;
/** Per socket with a request in flight: its connection's lifetime, aborted when that peer's connection ends. */
private readonly lifetimes;
constructor(checkpoints: RecoveryCheckpoints, cursors?: RecoveryCursors, events?: EventLeases);
status(): RecoveryPageCounters;
/**
* A peer incarnation's connection ended (closed, errored or cut): every open still verifying for it stops, typed
* `aborted`, so its slots and its tokens are freed at the next leaf instead of when the verification ends.
*/
forgetPeer(socketEpoch: string): void;
/**
* `signal` is the request's budget: a first open's verification is charged to it and to the asking connection's
* lifetime, whichever ends first (RULING-69 (2)).
*/
request(caller: RecoveryCaller, request: RecoveryPageRequest, signal?: AbortSignal): Promise<RecoveryPageOutcome>;
request(caller: RecoveryCaller, request: PageRequest, signal?: AbortSignal): Promise<PageOutcome>;
/** A checkpoint token minted for this caller under the named admission, claimed before any request state. */
private checkpointSource;
/** An event lease of this caller (S13); its pages are the leased record's bytes, and it carries no generation. */
private eventSource;
/** Holds the token's active flag and one socket slot from before the read until the outcome is known. */
private serve;
private refuse;
}
export {};
//# sourceMappingURL=compact-recovery-requests.d.ts.map