Expand description
Request ledger of a serving process: counters, oldest pending request and last completions for doctor and health (#2197). Request ledger of a serving process (#2197).
A worker that stops answering looks the same from outside whether it is
idle, saturated, or stuck in one handler. The ledger tells them apart
without touching the request queue: it counts every admitted request and
exactly one outcome per request, keeps the oldest pending request’s method
and stage, and remembers the last tools/call completion separately from
the last initialize.
Privacy: only method names (tools/call:ctx_read, never arguments, paths
or content) are kept, truncated, and the pending set is bounded.
A serving process publishes its snapshot to <data_dir>/requests/<pid>.json
from a dedicated thread, so lean-ctx doctor can read it even when every
request worker is busy. In-process, the HTTP /v1/health route serves the
same snapshot.
Structs§
- Completion
Record - Pending
Request - Phase
Record - Request
Guard - Request
Ledger Snapshot - One point-in-time view of the ledger.
Nonefields are unknown or did not happen yet; renderers spell them out instead of guessing.
Enums§
- Outcome
- How a request ended. Each admitted request ends exactly once.
- Stage
- Where a pending request is.
Constants§
- HEARTBEAT
- A live publisher rewrites its snapshot at least this often, so a reader can tell a running process from a file a dead one left behind.
- STALE_
AFTER - Snapshots older than this belong to a process that is gone.
Functions§
- begin
- Admit one request. The returned guard records exactly one outcome: the
one passed to
RequestGuard::finish, orAbandonedwhen it is dropped unfinished (the request future was cancelled or the client went away). - epoch_
ms - Milliseconds since the Unix epoch, the clock snapshots are stamped with.
- finish_
serving - Shutdown of a serving process: persist the observations still queued for
the detached writer (bounded by
timeout) and withdraw this process’s published snapshot, solean-ctx doctordoes not list a stopped server. Runs once; later calls return at once. Blocking — call it from a plain thread orspawn_blocking, never directly on an async worker. - published_
snapshots - Snapshots published by serving processes that are still running, by pid.
- refused
- Count a request turned away before admission (rate or concurrency limit).
- serving
- snapshot
- The ledger now, without ages (a snapshot is a cacheable fact; ages are
the reader’s arithmetic, see
RequestLedgerSnapshot::with_ages). - start_
serving - Mark this process as serving requests of
kind: observations no longer block dispatch (#2196) and the snapshot publisher starts. Idempotent.