@sema-agent/core 7.68.3 → 7.68.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/dist/agents/peer-held-queue.d.ts +6 -1
- package/dist/agents/peer-held-queue.js +10 -1
- package/dist/agents/peer-idle.d.ts +3 -1
- package/dist/agents/peer-idle.js +4 -4
- package/dist/agents/peer-session-drain.d.ts +9 -1
- package/dist/agents/peer-session-drain.js +184 -115
- package/dist/core/engine-notice.d.ts +5 -0
- package/dist/core/governance-codes.d.ts +3 -1
- package/dist/core/governance-codes.js +3 -0
- package/dist/core/mods/message-display.d.ts +3 -0
- package/dist/core/mods/message-display.js +2 -2
- package/dist/core/process-identity.d.ts +14 -2
- package/dist/core/process-identity.js +5 -3
- package/dist/core/runner/caller-stop-gate.d.ts +3 -3
- package/dist/core/runner/contracts.d.ts +2 -2
- package/dist/core/runner/end-of-run.d.ts +42 -0
- package/dist/core/runner/end-of-run.js +53 -0
- package/dist/core/runner/prepare-task.d.ts +4 -1
- package/dist/core/runner/prepare-task.js +4 -4
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
- package/dist/core/runner/prepare-wiring-manifest.js +2 -2
- package/dist/core/runner/run-notification-lane.d.ts +2 -0
- package/dist/core/runner/run-notification-lane.js +2 -2
- package/dist/core/runner/runtask.js +7 -2
- package/dist/core/task-spec.d.ts +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/stores/file/data-root-declaration.d.ts +32 -0
- package/dist/stores/file/data-root-declaration.js +19 -0
- package/dist/stores/file/fs-atomic.d.ts +22 -2
- package/dist/stores/file/fs-atomic.js +63 -10
- package/dist/stores/file/index.d.ts +1 -0
- package/dist/stores/file/index.js +1 -0
- package/dist/stores/file/permission-rule-adopt.js +3 -3
- package/dist/stores/file/permission-rule-store.js +2 -2
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +5 -1
- package/wire-changes/core-stores-sql@7.68.4.json +39 -0
- package/wire-changes/core-stores-sql@7.68.5.json +39 -0
- package/wire-changes/core@7.68.4.json +187 -0
- package/wire-changes/core@7.68.5.json +141 -0
- package/wire-changes/mods-kernel@7.68.4.json +39 -0
- package/wire-changes/mods-kernel@7.68.5.json +39 -0
- package/wire-changes/primitives@7.68.4.json +39 -0
- package/wire-changes/primitives@7.68.5.json +39 -0
- package/wire-changes/wiki-gate@7.68.4.json +39 -0
- package/wire-changes/wiki-gate@7.68.5.json +39 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
+
## 7.68.5 — 2026-11-16
|
|
2
|
+
|
|
3
|
+
### A finished run lets go of what it handed its session's process-level seats: a long-lived host with a mailbox store no longer keeps each session's last leg for the life of the process (#4672; fix; behavior change: one, below, open to veto; narrowing: none; widening: none; hard-breaking: none; closed sets: none; exports: none; wire: none)
|
|
4
|
+
|
|
5
|
+
- **Before.** Since 7.4.0, on a deployment whose sessions have a session box (a mailbox store safe across processes over a session store that reads a row by id), every top-level leg mounts the box drain, which opens its session's idle machine and the held queue of each box it drains — process-level seats, one per session address. The drain bound them sinks built inside the leg; at the leg's loop end only the held queue's injector was detached, and every other sink still closed over the leg. A timer a seat armed for the leg (an idle ask's 12 h, a held card's deadline) also kept the async context of the run that armed it. So each session's last leg — its prepared state, tool table, guard rows, harness and conversation — stayed reachable for as long as the process lived. Measured on the engine alone (one Runner on the file backend, a new session per run, 50 caller tools, the session deleted through the store after each run, 300 runs, base and fix alternated twice): 771,232 and 771,686 bytes of heap and one whole leg (its harness, its session object, its 50 tools) kept per run on 7.68.4; 11,812 and 11,895 bytes and no leg with this fix (what is left is the "Not fixed" paragraph below).
|
|
6
|
+
- **Affected.** Long-lived hosts that wire a mailbox store: every session they ever ran keeps its last leg. A host that runs each request in a new session grows by one leg per request (about 770 KB in the measurement above; more with a longer conversation or a larger tool table) until the heap runs out.
|
|
7
|
+
- **Now.** What a leg binds its session's seats is handed through the run's end — the one end that already takes back the listeners a run hangs on a signal it does not own — and taken back once the run has settled, whatever way it ended: each seat is re-bound to the session's facts as the leg ended with them (its mode class, its name, its last turn's text) and to the deployment's own seats, nothing of the leg. A seat is re-bound only while it still holds this leg's binding: when two legs of one session are bound at once (two Runners in one process on one session id), the run's end of the one that ends first leaves the other's binding — its injector, its live readings — in place (that leg's loop end can still take the other's injector off the held queue until the other's next pass, as on every released version). A seat (a held queue, either idle half) arms its timers outside any run, on whatever clock it was given. Each seat is taken back on its own: if re-binding one throws, the others are still re-bound, and the fault reaches `RunnerDeps.onError` (`phase: "degraded"`, `classification: "run-end-take-back"`), never the process as an unhandled rejection; the run's result is unchanged. A Runner with no `onError` hears nothing of it, as with its other degraded arms.
|
|
8
|
+
- **Not changed.** Between legs the seats stand and work as before: a subscription recorded in one leg is fired at the end of a later one; a subscription fired after the leg ended reaches its requester, authored as before; a session's own idle ask answers it `expired` at 12 h; a held card expires at its deadline with its receipt, and an approval between legs answers `released_pending`. The host face (`peerIdleMachineIfAny`, `peerHeldQueueIfAny`, `listPeerHeldQueues`) reads them as before. Deleting a session does to its seats what it did before (nothing; a new occupant of the id replaces them). `realPeerClock` is a plain clock as before (a timer armed on it directly keeps its caller's async context).
|
|
9
|
+
- **Not fixed (as in every released version).** Each session whose legs mounted the drain keeps its idle machine and its held queue in this process until the process ends or a new occupant of the id replaces them — now without the leg: about 7.6 KB per session (measured: a host-owned session store, each session's box dropped, 2,400 sessions per pass, the heap slope with the seats kept less the slope with them cleared each round: 7,619 and 7,637 bytes in two passes). A host that calls the root `runTask(spec, deps)` once per request (a new Runner each call) keeps more: each session also keeps one Runner — about 22 KB per session in one measurement (an in-memory session store, 20 caller tools, one shared file mailbox; about 361 KB before the fix); what holds it is, by reading the code and not traced, the seats' resting form reaching that call's Runner through its error sink. A seat whose re-bind throws at the run's end keeps the leg it was bound (the fault reaches the error sink; no take-back is known to throw today). Deleting the session, through the engine's store or the host's own, does not remove them, and `listPeerHeldQueues()` keeps listing each ended session's empty queue. On the file backend, a host that does not drop a deleted session's box also keeps the box's open log in the mailbox store until the store closes: about 850 bytes (866 and 834 in the same two passes) and one open log per session, so one file descriptor each by reading the code (the descriptors were not counted). The drop is the deletion cascade's mailbox leg, `mailboxStore.drop`, at the scope the session's legs drained it in — the leg's `isolationScope`, else its `principal`, else `"default"`; the file mailbox keys a box by a digest of the scope's bytes, so another spelling drops another box.
|
|
10
|
+
- **Behavior change, an exit (open to veto).** `PeerIdleTarget.configure` no longer clears an exit the host declared (`exited`); `busy` (the session starts working) does. For a Runner's leg that begins it is the same moment as before (the leg binds and then begins). Two forms differ: a leg refused after the drain mounted and before it begins no longer clears the exit (measured: after `exited` and one such refused leg, a subscription was recorded on 7.68.4 and is answered `full` now; after the next leg that runs it is recorded on both), and between a leg's bind and its first turn a subscription is answered `full` where it was recorded (by reading the code, not measured); the run's end re-binding the seats no longer revives a target the host declared exited. A host that drives `createPeerIdleTarget` directly and re-binds it after `exited` sees subscriptions refused until it calls `busy`.
|
|
11
|
+
- **Rules.** The run's end gains one verb (`lend`: hand something over and name how it is taken back); listening to a signal is one use of it; the stream leg ends the run through one call that hands a take-back's fault to the error sink. The leg's seat logic (judgment, route, receipt, disclosure, the three sinks) has one spelling, read by the bound and the resting form; every bind of a seat goes through one function that records which leg's bind landed, and a leg whose run ended re-binds only a seat still its own (or one a failed bind left with no known holder). A seat's timers are armed outside any run (one clock wrapper, read by the three seat factories).
|
|
12
|
+
- **Pins.** `test/backlog4672-session-machine-lets-go-of-the-leg.test.ts` — R (an in-memory session store and the file backend; nothing after the run / the session deleted; a prepare that refuses after the drain mounted; the no-mailbox control), B1–B4 (each with the leg collected first: a subscriber told after the leg; a subscription across two legs; a session's own 12 h ask; a held card's deadline and an approval between legs), F1 (a real Runner whose seat throws when the run's end re-binds it: no unhandled rejection, one `run-end-take-back` error, every other take-back ran, the result unchanged), F2 (the first seat's re-bind throws: the others are still re-bound), O1 (two legs of one session bound at once: the first to end re-binds nothing the other bound), O2 (a bind that throws leaves no known holder: the earlier leg still takes the seat back), E1–E3, E5–E7 (a getter that throws at the run's end keeps nothing of the leg; a pass after the end binds the resting form; an exit stands across the take-back; with the real clock, and with a clock the host supplies, a leg whose idle ask is outstanding is collected; `realPeerClock` itself unchanged).
|
|
13
|
+
- **Consumers.** Nothing to change to get the fix. What a long-lived host still keeps per ended session is the "Not fixed" paragraph above: a host on the file backend that deletes sessions should drop each session's box at that exact scope; a host that shows `listPeerHeldQueues()` to people sees ended sessions' empty queues. A host whose `onError` sink sorts by `classification` has one more word, `run-end-take-back`.
|
|
14
|
+
|
|
15
|
+
## 7.68.4 — 2026-11-16
|
|
16
|
+
|
|
17
|
+
### A host can declare that every process opening a file data root runs in this one process table, and the directory locks under that root then judge a lock written by an engine before 7.67.0 by its pid; without the declaration nothing changes but the refusal's sentence and one re-read under the reclaim gate, below (#4667; ruled C-R2243; new host declaration; default unchanged; narrowing: none; widening: one, below, open to veto @server @cli; hard-breaking: none; closed sets: one, `EngineNoticeCode` +1; exports: two, `declareDataRoot`, `DataRootDeclaration`, and one optional member on the exported class `FileStoreLockError`, `ownerFingerprintUnread`; wire: none)
|
|
18
|
+
|
|
19
|
+
- **Before.** On a host that names its pid namespace (Linux), a file store's directory lock whose record names no namespace was never judged: it may come from another process table under the same host name, so it was refused `store.dir_in_use` (`ownerUncheckable: "pid_namespace_unrecorded"`) until removed by hand — 7.67.0's narrowing (its CHANGELOG, "a Linux deployment upgrading over claims and locks written before it reads them live until they are removed"). Every engine before 7.67.0 wrote its locks that way (`v / pid / startedAtMs / startedSinceBootMs / host`), and a host that leaves one behind at a normal stop (a second store over the same root that is never closed) or at a kill leaves it for the upgraded engine: one refusal per start, one lock named per refusal. Its sentence also said "this host has more than one" pid namespace, which the judgment never measured. Measured on 7.68.3 (the pin file run against 7.68.3's sources, macOS with the namespace link seamed: 29 of the 30 cells that ran are red, most of them because the declaration does not exist there; the green one, A1, only checks which namespace the column reads).
|
|
20
|
+
- **Now.** `declareDataRoot(root, { singleProcessTable: true })` states that every process opening `root` runs in this process table (no other container or host mounts it). A lock at or under a declared root whose record names no namespace is then judged by the one judgment every lock gets — the pid signalled, gone ⇒ reclaimed; a pid that exists is reclaimed only when both recorded start times are falsified by its current holder, refused as a live owner otherwise — and the reclaim is said once, `store.lock_reclaimed_on_declaration` (operator; `detail: { path, pid, root }`); the lock is rewritten naming this namespace. One seat per root: every directory lock under it reads the declaration (the data root's `LOCK`, the background-agent, checkpoint and workflow-run ledgers, the permission-rule writer lock, the artifact stub's ledger, an adoption's two locks), whichever store or door opened it. Only the literal `true` is taken; any other value, a stray or missing member and a root that is no path are refused `config.invalid_argument`. The root is resolved as `FileStorageBackend` resolves its own (`resolveDataRoot`: created if absent, then its physical path), so a `..` after a symlink names the directory the stores open, never its lexical twin.
|
|
21
|
+
- **Widening (open to veto).** Under the declaration a lock that names no namespace and whose process is gone from this table is reclaimed where it was refused. It is the deployment's statement, not the engine's observation: a deployment that declares it while a second container or host has the root mounted (replicas over one volume, two generations of a pod during a rolling upgrade) can have a live writer's lock reclaimed. `docs/INTEGRATION-CORE.md` §5.15a lists who may and who may not declare it.
|
|
22
|
+
- **One change without the declaration.** A reclaim re-reads the lock under its gate and removes only the record it judged. A bare-pid record (the form before 7.6.1) replaced in that window by a record of the same pid that this engine reads only for its pid (below) is no longer taken for it: the reclaim does not remove it, and the next pass judges it on its own reading. Without the declaration this reaches only a host that names no pid namespace (macOS), where that next pass judges it by its pid as before (by code: `sameOwner` in `src/stores/file/fs-atomic.ts` also compares whether the record's fingerprint was read); under the declaration such a record is refused and stays (pin C6).
|
|
23
|
+
- **Not changed.** Without the declaration: every verdict, code and lock as before, but for the re-read above; the refusal of a record that names no namespace drops the unmeasured half-sentence and names the way out (the declaration, what it asserts, and "if no process uses it, remove …"), one sentence. With it: a record naming another namespace (`another_pid_namespace`) or another host (`another_host`) is refused word for word as without it (pin C1); a lock whose writer still runs is refused as before (B1); where this host names no namespace (macOS) nothing changes and nothing is said (G1). A record this engine reads only the pid of — a later engine version's, or a JSON record with no version, which no engine wrote — had its host and namespace not read, which is not the same as not written: it is refused with and without the declaration, word for word, untouched and unannounced, and its refusal does not offer the declaration; its reason stays `pid_namespace_unrecorded`, whose sentence says the record was "written without naming its pid namespace" — not true of such a record (its namespace was not read, not shown to be unwritten); it is met where a later engine's lock is found, after a downgrade (C5 each shape; `FileStoreLockError` carries `ownerFingerprintUnread: true` for it, and a store that says a lock refusal again in its own words keeps it, C7); a record of this version that left the namespace out is still judged under it (C5-control). A `singleProcessTable` only a prototype supplies is no member (F2). Still refused, still removed by hand: a current-form record met after a container restart or a pod rebuild (KNOWN-LIMITS KL-4667-a). Not reached by the declaration: a memory writer's session account (its holder and its namespace were introduced together in 7.67.0, so no earlier engine wrote one without it); the root export `isProcessLive` called by a host on its own records (a host's own run claims are judged as on 7.68.3); and a directory lock outside every declared root — a permission-rule or artifact directory a host places outside the data root reads no declaration until that tree is declared too (C2).
|
|
24
|
+
- **Rules.** +1 input to the comparability step (`processCensus({ singleProcessTable: true })` reads a missing namespace as this one), read only after the default verdict already said `pid_namespace_unrecorded`, only for a record whose fingerprint was read, and only for a lock under a declared root; no new judgment, no new refusal code, no new `ProcessUncheckable` member. +1 notice code. +1 optional member on `FileStoreLockError` (`ownerFingerprintUnread`).
|
|
25
|
+
- **Pins.** `test/backlog4667-legacy-lock-host-declaration.test.ts` — A1–A4 (the record refused and reclaimed; the bare pid), B1–B2 (the live writer refused, a reused pid reclaimed), C1–C7 (the other namespace and the other host word for word; a lock outside the declared root; a `..` after a symlink; a root declared before it exists; each record read only for its pid, refused with and without, and the control; such a record swapped in under the reclaim gate is not the one the reclaim came to remove; each store that says the refusal again), D (every lock seat, refused without and opened with), E1 (the server's shape through the root export: the backend, a second background-agent store and the workflow-run store over a root left with four such locks start once), F1–F2 (bad values; a member only a prototype supplies), G1 (macOS), R0; each cell in a seam column and, where the kernel serves `/proc/self/ns/pid`, a real column. `test/fs-atomic-bootlock-fingerprint.test.ts` unchanged and green.
|
|
26
|
+
- **Consumers.** @server / @cli: a local deployment that alone opens its data root can call `declareDataRoot(root, { singleProcessTable: true })` before it opens the stores; a deployment that does not call it behaves exactly as on 7.68.3. A consumer that pins `EngineNoticeCode` as a closed set has one more word.
|
|
27
|
+
|
|
28
|
+
### A run given a `TaskSpec.signal` that is never aborted is let go when it ends: every listener the run hung on that signal, or on the caller-stop gate composed from it, comes off at the run's end (#4668; fix)
|
|
29
|
+
|
|
30
|
+
- **Before.** Since 7.67.0 a top-level leg's message display (the `classic.MessageDisplay` station, opened on every top-level leg whether or not a handler hangs it) hung an abort listener on the caller-stop gate — the signal composed from the host's `signal` with `AbortSignal.any` — and never took it off. The runtime holds a composed signal that carries an abort listener until it aborts, so everything the listener closes over (the leg's prepared state, its conversation, its image bytes) stayed reachable after the run, one copy per run, whether the host kept its controller or dropped it. Measured on 7.68.3: seven live signals per run, and a fresh Runner's brain, runner and spec reachable after every run; a host that gave no signal, or aborted it after the run, did not leak. A second path: a prepare that refused after hanging its listener on the host's own signal (for example, `spec.tools` changed after the call) left that listener on a kept signal, holding the leg's controller and harness.
|
|
31
|
+
- **Affected.** Hosts that pass `TaskSpec.signal` to `runTask` / `runTaskStream` — directly, or through an entry that hands it to its legs (`runWithVerification`, a delegated child given its parent's tool signal) — and do not abort it after the run. The display path since 7.67.0; the prepare path is older (by reading the code; not measured on earlier releases).
|
|
32
|
+
- **Now.** One rule: a run listens to a signal it does not own only through the run's end, minted by the stream leg when the run starts and ended once the run has settled — its result published by the run body, or by the failure backstop after a throw. Both listeners go through it; the leg's forwarding listener still comes off at the loop's end as before. A host need not abort its signal after the run (now stated on `TaskSpec.signal` and in the integration guide).
|
|
33
|
+
- **Not changed.** A host abort while the run is live stops it as before, and the display still drops the message it was showing (nothing more of it reaches the stream, nothing is said of it). The caller-stop gate keeps answering after the run's end. An abort after the run ended adds no frame, notice or error.
|
|
34
|
+
- **Rules.** +1 (the run listens to a signal it does not own only through its end) for −2 per-site releases: the display had none, and prepare's own release was reached only by a prepare that returned. The release is an explicit `removeEventListener`; the `{ signal }` listener option was not used, because the runtime keeps the latest listener hung with it reachable through its target for as long as the target lives (measured: with it, the last run stayed reachable on a kept signal).
|
|
35
|
+
- **Pins.** `test/backlog4668-run-end-releases-caller-signal.test.ts` — R (five shapes: `runTask`, `runTaskStream` with an image and a tool turn, `runWithVerification`, a delegated child, a prepare that refuses; × kept / dropped / no signal / aborted after the end), N (a nested run on a parent tool's signal is collected while the parent still runs), L (no listener a run added stays attached, five shapes), C (40 runs on one Runner and one kept controller: live signals flat; 70 → 280 on 7.68.3), B (a mid-run abort still stops the loop and still drops the message on display; the display's listener comes off only after the result is published; an abort after the end adds nothing). 17 of its 31 cells are red against 7.68.3's sources (B3 among them: there the display's listener never comes off).
|
|
36
|
+
- **Measured after, and what is left.** The implementation car's long run (the engine alone, no network, 300 small runs given a signal that is never aborted, the heap after a forced collection, the least-squares slope per run, three alternations): about 272–282 KB kept per run before, in each of the three shapes; after, about 1.2 KB per run with a fresh Runner each run and about 8.6 KB per run on one Runner whose sessions are released (about 9.9 KB with the sessions left in the store, which holds them by design). That remainder still grows linearly and does not level off: the runtime keeps one entry for every signal composed from a long-lived source until the source dies (three compositions per run from the host's signal, about 0.5 KB), and per-session state outlives a released session (sampled, not traced) — tracked as #4671, not changed here.
|
|
37
|
+
- **Consumers.** No change needed. A host that aborts its controller after every run only to avoid this can stop.
|
|
38
|
+
|
|
39
|
+
no-notes: #4545(repository tooling only: `scripts/verify-clearance.mjs` and its pins count the clearance gate off the ledger; nothing in the package changes), #4546(named only by the car-tools-4545 merge header, as the commit held back; nothing for it lands here), #4547(repository tooling only: `scripts/merge-queue-audit.mjs` and its pins; nothing in the package changes), #4563(repository tooling only: `scripts/remote-gate.sh` ships a tree to the test host by difference; nothing in the package changes)
|
|
40
|
+
|
|
1
41
|
## 7.68.3 — 2026-11-14
|
|
2
42
|
|
|
3
43
|
### A composition's later legs continue the session its first leg entered and never enter it again: a file rewind, a branch point and the other operations a run performs on entering a session now act once, on the leg that enters (#4510; behavior change; narrowing: one, below, open to veto @server; widening: none; two further changes of reading, below (a goal handed an empty `sessionId`; a session deleted between two legs); hard-breaking: none; closed sets: none; exports: none; wire: none)
|
|
@@ -44,10 +44,15 @@ export interface PeerClock {
|
|
|
44
44
|
clearTimeout(handle: unknown): void;
|
|
45
45
|
}
|
|
46
46
|
export declare const realPeerClock: PeerClock;
|
|
47
|
+
/** The clock a seat (a held queue, an idle half) arms its timers on: `clock`, with every timer armed outside any run. A timer
|
|
48
|
+
* keeps the async context it was armed in until it fires or is cleared, and with it the stores of the run whose code armed it
|
|
49
|
+
* (the run's whole state); a seat outlives every run (an idle ask waits 12 h), so its timers are armed, and fire, outside any. */
|
|
50
|
+
export declare function peerSeatClock(clock?: PeerClock): PeerClock;
|
|
47
51
|
/** The live seats a bound run gives the queue. `inject` is the ONLY member that is run-scoped (a run's
|
|
48
52
|
* own injection lane); the others survive the run (the receipt route rides the mailbox, the judge
|
|
49
53
|
* reads the deployment's settings getter, the decision seat is the store) and are what a headless
|
|
50
|
-
* deadline settles through
|
|
54
|
+
* deadline settles through — so what the queue keeps after the run closes over nothing of it (the
|
|
55
|
+
* queue is process-lived: the session-box drain hands its sinks through the run's end). */
|
|
51
56
|
export interface PeerHeldQueueSink {
|
|
52
57
|
/** Re-judge an entry against the recipient's CURRENT settings and mode class (CC `M`). */
|
|
53
58
|
judge: (entry: PeerHeldEntry) => CrossSessionInboundVerdict;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AsyncResource } from "node:async_hooks";
|
|
1
2
|
import { isMailboxDecisionDeliverable, isMailboxDecisionFinal } from "../core/mailbox-store.js";
|
|
2
3
|
import { sameOccupant } from "../engine/session/repo-utils.js";
|
|
3
4
|
import { PEER_HELD_QUEUE_CAP, PEER_HELD_REVIEW_CAUSES, peerHeldReceiptStateOf } from "./peer-notices.js";
|
|
@@ -18,10 +19,18 @@ export const realPeerClock = {
|
|
|
18
19
|
},
|
|
19
20
|
clearTimeout: (h) => clearTimeout(h),
|
|
20
21
|
};
|
|
22
|
+
const outsideAnyRun = AsyncResource.bind((arm) => arm());
|
|
23
|
+
export function peerSeatClock(clock = realPeerClock) {
|
|
24
|
+
return {
|
|
25
|
+
now: () => clock.now(),
|
|
26
|
+
setTimeout: (fn, ms) => outsideAnyRun(() => clock.setTimeout(fn, ms)),
|
|
27
|
+
clearTimeout: (h) => clock.clearTimeout(h),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
21
30
|
const crashHandlers = new WeakMap();
|
|
22
31
|
export function createPeerHeldQueue(key, opts = {}) {
|
|
23
32
|
const cap = opts.cap ?? PEER_HELD_QUEUE_CAP;
|
|
24
|
-
const clock = opts.clock
|
|
33
|
+
const clock = peerSeatClock(opts.clock);
|
|
25
34
|
const entries = [];
|
|
26
35
|
const deadlines = new Map();
|
|
27
36
|
const releasedBy = new WeakMap();
|
|
@@ -36,6 +36,8 @@ export interface PeerIdleTargetSink {
|
|
|
36
36
|
}
|
|
37
37
|
export type PeerIdleSubscribeOutcome = "recorded" | "refreshed" | "full";
|
|
38
38
|
export interface PeerIdleTarget {
|
|
39
|
+
/** Bind the sink the machine routes through (a leg's, then the session's resting one). Binding is not working: an exit stands
|
|
40
|
+
* until the session works again ({@link busy}). */
|
|
39
41
|
configure(sink: PeerIdleTargetSink): void;
|
|
40
42
|
configured(): boolean;
|
|
41
43
|
/** CC `tYt` (sans pid classes): same requester ⇒ refresh; table full ⇒ `"full"` (the caller answers
|
|
@@ -43,7 +45,7 @@ export interface PeerIdleTarget {
|
|
|
43
45
|
subscribe(sub: PeerIdleSubscriber): PeerIdleSubscribeOutcome;
|
|
44
46
|
/** CC `A`: drop subscribers older than the TTL, silently. Returns how many. */
|
|
45
47
|
sweep(now?: number): number;
|
|
46
|
-
/** The session started working (a run began): cancel a pending fire. */
|
|
48
|
+
/** The session started working (a run began): cancel a pending fire; an earlier exit no longer stands (subscriptions are taken again). */
|
|
47
49
|
busy(): void;
|
|
48
50
|
/** The session's run ended with nothing queued: schedule the one-shot `idle` fire (debounced; parked
|
|
49
51
|
* while the held buffer is non-empty and re-checked). `finishedAt` = when the turn ended. */
|
package/dist/agents/peer-idle.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { sameOccupant } from "../engine/session/repo-utils.js";
|
|
2
2
|
import { PEER_IDLE_FIRE_DEBOUNCE_MS, PEER_IDLE_HELD_BACKOFF_MS, PEER_IDLE_OUTSTANDING_CAP, PEER_IDLE_PRIORS_KEPT, PEER_IDLE_SUBSCRIBER_TABLE_CAP, PEER_IDLE_SUBSCRIPTION_TTL_MS } from "./peer-notices.js";
|
|
3
|
-
import {
|
|
3
|
+
import { peerSeatClock } from "./peer-held-queue.js";
|
|
4
4
|
import { peerSessionBoxHandle } from "./peer-directory.js";
|
|
5
5
|
export function createPeerIdleTarget(opts = {}) {
|
|
6
|
-
const clock = opts.clock
|
|
6
|
+
const clock = peerSeatClock(opts.clock);
|
|
7
7
|
const cap = opts.tableCap ?? PEER_IDLE_SUBSCRIBER_TABLE_CAP;
|
|
8
8
|
const ttl = opts.ttlMs ?? PEER_IDLE_SUBSCRIPTION_TTL_MS;
|
|
9
9
|
const subs = [];
|
|
@@ -87,7 +87,6 @@ export function createPeerIdleTarget(opts = {}) {
|
|
|
87
87
|
return {
|
|
88
88
|
configure(next) {
|
|
89
89
|
sink = next;
|
|
90
|
-
exitedFlag = false;
|
|
91
90
|
},
|
|
92
91
|
configured: () => sink !== undefined,
|
|
93
92
|
subscribe(sub) {
|
|
@@ -115,6 +114,7 @@ export function createPeerIdleTarget(opts = {}) {
|
|
|
115
114
|
sweep,
|
|
116
115
|
busy() {
|
|
117
116
|
idleState = undefined;
|
|
117
|
+
exitedFlag = false;
|
|
118
118
|
cancelPending();
|
|
119
119
|
},
|
|
120
120
|
idle(finishedAt) {
|
|
@@ -143,7 +143,7 @@ export function createPeerIdleTarget(opts = {}) {
|
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
export function createPeerIdleRequester(opts = {}) {
|
|
146
|
-
const clock = opts.clock
|
|
146
|
+
const clock = peerSeatClock(opts.clock);
|
|
147
147
|
const cap = opts.cap ?? PEER_IDLE_OUTSTANDING_CAP;
|
|
148
148
|
const priorsKept = opts.priorsKept ?? PEER_IDLE_PRIORS_KEPT;
|
|
149
149
|
const ttl = opts.ttlMs ?? PEER_IDLE_SUBSCRIPTION_TTL_MS;
|
|
@@ -15,6 +15,7 @@ import type { SendMessageToolOptions } from "./send-message-tool.js";
|
|
|
15
15
|
import type { PeerChannel } from "../core/peer-channel.js";
|
|
16
16
|
import { type PeerClock, type PeerHeldQueue } from "./peer-held-queue.js";
|
|
17
17
|
import { type PeerIdleMachine } from "./peer-idle.js";
|
|
18
|
+
import type { RunEnd } from "../core/runner/end-of-run.js";
|
|
18
19
|
/** design/385 §1.2④ — the drain lease TTL. Same sizing law as the tier-3 revive lease: well under the
|
|
19
20
|
* store's stale-row floor, long enough to cover one turn (a longer turn renews on the same owner at
|
|
20
21
|
* its next boundary; an expired lease re-serves the batch — at-least-once). */
|
|
@@ -217,7 +218,8 @@ export interface PeerSessionDrainOptions {
|
|
|
217
218
|
lane?: Partial<PeerLaneConfig>;
|
|
218
219
|
/** The recipient's self-token set for the hop check, read live (the run's peer identity ref). */
|
|
219
220
|
ownTokens: () => readonly string[];
|
|
220
|
-
/** The recipient's `crossSessionInbound` layers, read at every drain
|
|
221
|
+
/** The recipient's `crossSessionInbound` layers, read at every drain — and by the session's seats after the leg (a held card's
|
|
222
|
+
* deadline or approval, an idle notice's detail), so it reads the deployment's seat and closes over nothing of the leg. */
|
|
221
223
|
settingLayers: () => CrossSessionInboundSettingLayers | undefined;
|
|
222
224
|
/** The recipient's own permission-mode class, read at every drain (the manifest's ask fold). */
|
|
223
225
|
selfModeClass: () => PermissionModeClass | "unknown";
|
|
@@ -251,6 +253,10 @@ export interface PeerSessionDrainOptions {
|
|
|
251
253
|
leaseTtlMs?: number;
|
|
252
254
|
/** Tests: a virtual clock for the held deadlines and idle timers (honored when this process first sees the session). */
|
|
253
255
|
clock?: PeerClock;
|
|
256
|
+
/** The run's end (end-of-run.ts): what this leg binds the session's process-level seats is handed through it, and taken back
|
|
257
|
+
* there — the seats then read the session's facts as the leg ended with them. Absent outside a Runner's stream: the leg's
|
|
258
|
+
* binding stays until the session's next leg binds its own. */
|
|
259
|
+
runEnd?: Pick<RunEnd, "lend">;
|
|
254
260
|
}
|
|
255
261
|
export interface PeerSessionDrain {
|
|
256
262
|
/**
|
|
@@ -447,5 +453,7 @@ export declare function bindPeerLaneDrain(harness: PeerDrainHarness, args: {
|
|
|
447
453
|
/** The assistant seat the host handed the leg (`RunInternals.principalInboxAssistant`, as handed): its letter observer rides the
|
|
448
454
|
* `pullOnly` lane that seat made ({@link PeerSessionDrainOptions.onLetters}). */
|
|
449
455
|
assistantSeat?: unknown;
|
|
456
|
+
/** The run's end ({@link PeerSessionDrainOptions.runEnd}). */
|
|
457
|
+
runEnd?: Pick<RunEnd, "lend">;
|
|
450
458
|
}): PeerSessionDrain;
|
|
451
459
|
export {};
|
|
@@ -137,6 +137,133 @@ export function sessionBoxVerdictOf(deps, at) {
|
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
139
|
export const PEER_RESUPPLY_CAP = 1;
|
|
140
|
+
function readOnce(read) {
|
|
141
|
+
let read1;
|
|
142
|
+
try {
|
|
143
|
+
read1 = { value: read() };
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
read1 = { fault: thrownText(e) };
|
|
147
|
+
}
|
|
148
|
+
if ("fault" in read1) {
|
|
149
|
+
const { fault } = read1;
|
|
150
|
+
return () => {
|
|
151
|
+
throw new Error(fault);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
const { value } = read1;
|
|
155
|
+
return () => value;
|
|
156
|
+
}
|
|
157
|
+
function restingSeatFacts(live) {
|
|
158
|
+
const { mailbox, scope, sessionId, occupant, runId, settingLayers, onNotice, onError } = live;
|
|
159
|
+
return { mailbox, scope, sessionId, occupant, runId, settingLayers, onNotice, onError, selfModeClass: readOnce(live.selfModeClass), selfName: readOnce(live.selfName), lastTurnText: live.lastTurnText === undefined ? undefined : readOnce(live.lastTurnText) };
|
|
160
|
+
}
|
|
161
|
+
function readSeatJudgment(f) {
|
|
162
|
+
const layers = f.settingLayers() ?? {};
|
|
163
|
+
return { setting: resolveCrossSessionInboundSetting(layers), principalSetting: resolveCrossSessionInboundSetting(principalInboundLayers(layers)), selfModeClass: f.selfModeClass() };
|
|
164
|
+
}
|
|
165
|
+
function judgeSeatMeta(sessionId, facts, meta) {
|
|
166
|
+
return meta?.fromScope !== undefined
|
|
167
|
+
? judgeCrossSessionInbound({ setting: facts.principalSetting, selfModeClass: facts.selfModeClass, sender: { fromScope: meta.fromScope } })
|
|
168
|
+
: judgeCrossSessionInbound({ setting: facts.setting, selfModeClass: facts.selfModeClass, sender: { ...(meta?.fromMode !== undefined ? { fromMode: meta.fromMode } : {}), selfSent: meta?.fromSession !== undefined && meta.fromSession.toLowerCase() === sessionId.toLowerCase() } });
|
|
169
|
+
}
|
|
170
|
+
function seatRoute(f) {
|
|
171
|
+
return {
|
|
172
|
+
mailbox: f.mailbox,
|
|
173
|
+
scope: f.scope,
|
|
174
|
+
self: { sessionId: f.sessionId, ...(f.selfName() !== undefined ? { name: f.selfName() } : {}), ...(f.occupant !== undefined ? { occupant: f.occupant } : {}), modeClass: f.selfModeClass },
|
|
175
|
+
...(f.onError !== undefined ? { onError: f.onError } : {}),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function seatReceiptAddress(kind, entry) {
|
|
179
|
+
const from = kind === "session" ? entry.peerMeta?.fromSession : undefined;
|
|
180
|
+
return from === undefined ? undefined : { sessionId: from, occupant: entry.peerMeta?.fromOccupant };
|
|
181
|
+
}
|
|
182
|
+
function seatReceipt(f, kind) {
|
|
183
|
+
return async (entry, state, releasedBy) => {
|
|
184
|
+
const to = seatReceiptAddress(kind, entry);
|
|
185
|
+
if (to === undefined)
|
|
186
|
+
return;
|
|
187
|
+
const faults = [];
|
|
188
|
+
const via = {
|
|
189
|
+
...seatRoute(f),
|
|
190
|
+
onError: (error, ctx) => {
|
|
191
|
+
faults.push(error);
|
|
192
|
+
f.onError?.(error, ctx);
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
if (state === "dropped")
|
|
196
|
+
await routePeerDroppedReceipt(via, to, entry.seq);
|
|
197
|
+
else
|
|
198
|
+
await routePeerDeliveryReceipt(via, to, state, entry.seq, releasedBy);
|
|
199
|
+
if (faults.length > 0)
|
|
200
|
+
throw faults[0];
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function discloseSeatDisposition(f, lane, disposition, cause, m, heldNote) {
|
|
204
|
+
deliverEngineNotice(f.onNotice, {
|
|
205
|
+
code: "peer.inbound_disposition",
|
|
206
|
+
message: `cross-session message seq ${m.seq} in ${lane.label} was ${disposition === "held"
|
|
207
|
+
? `HELD${heldNote !== undefined ? ` (${heldNote})` : lane.kind === "session" ? ` (it entered this session's held queue and STAYS IN THE BOX — the box is that queue's durable seat, so it is not acked until it settles; it is re-judged at every boundary, released or refused with a receipt to the sender, ${isCrossSessionHoldCause(cause) && peerHeldReceiptStateOf(cause) === "held" ? "and expires with a receipt under dialogExpiry" : "and has no expiry deadline: its cause is this session's own settings or state, not a review"})` : " (it entered this session's held queue for the principal inbox and STAYS IN THE BOX until it settles; it is re-judged at every boundary. The sender is another principal: no receipt reaches it from here — the delivery gate's receipt is its record)"}`
|
|
208
|
+
: disposition === "refused"
|
|
209
|
+
? "refused by this session's crossSessionInbound setting"
|
|
210
|
+
: disposition === "resupply_exhausted"
|
|
211
|
+
? "settled WITHOUT being read: its frame was summarized away by a compaction, re-supplied once, and summarized away again — the engine has stopped handing it over. The sender was not told; reply-worthy content is GONE from this session's context"
|
|
212
|
+
: disposition === "notice_unrouted"
|
|
213
|
+
? "settled WITHOUT delivery (a notice-kind record the notice face cannot render)"
|
|
214
|
+
: disposition === "notice_user_only"
|
|
215
|
+
? "surfaced to the user only (a notice whose sender this session's parity would hold; the model did not read it)"
|
|
216
|
+
: "refused by the inbound admission gate"}: ${cause}`,
|
|
217
|
+
detail: { disposition, cause, seq: m.seq, box: lane.boxHandle, ...(m.peerMeta?.fromSession !== undefined ? { fromSession: m.peerMeta.fromSession } : {}), sessionId: f.sessionId, runId: f.runId },
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function idleTargetSink(f, queues) {
|
|
221
|
+
return {
|
|
222
|
+
notify: (sub, notice) => void routePeerIdleNotice(seatRoute(f), { sessionId: sub.requester, occupant: sub.requesterOccupant }, notice),
|
|
223
|
+
judge: (sub) => judgeSeatMeta(f.sessionId, readSeatJudgment(f), { ...(sub.fromMode !== undefined ? { fromMode: sub.fromMode } : {}), ...(sub.selfSent ? { fromSession: f.sessionId } : {}) }),
|
|
224
|
+
heldCount: () => queues.reduce((n, queue) => n + queue.size(), 0),
|
|
225
|
+
...(f.lastTurnText !== undefined ? { lastTurnText: f.lastTurnText } : {}),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function idleRequesterSink(f) {
|
|
229
|
+
return { expired: (o) => void routePeerIdleNotice(seatRoute(f), { sessionId: f.sessionId, occupant: f.occupant }, { kind: "expired", label: o.label }) };
|
|
230
|
+
}
|
|
231
|
+
const seatBinders = new WeakMap();
|
|
232
|
+
function bindPeerSeat(seat, binder, legEnded, config) {
|
|
233
|
+
const holder = seatBinders.get(seat);
|
|
234
|
+
if (legEnded && holder !== undefined && holder !== binder)
|
|
235
|
+
return;
|
|
236
|
+
seatBinders.delete(seat);
|
|
237
|
+
seat.configure(config());
|
|
238
|
+
seatBinders.set(seat, binder);
|
|
239
|
+
}
|
|
240
|
+
function heldQueueSink(f, lane, drainOwner, leg) {
|
|
241
|
+
return {
|
|
242
|
+
judge: (entry) => judgeSeatMeta(f.sessionId, readSeatJudgment(f), entry.peerMeta),
|
|
243
|
+
...(leg !== undefined ? { inject: leg.inject, canInject: leg.canInject } : {}),
|
|
244
|
+
receipt: seatReceipt(f, lane.kind),
|
|
245
|
+
tellsSender: (entry) => seatReceiptAddress(lane.kind, entry) !== undefined,
|
|
246
|
+
decide: (entry, expect, next) => moveMailboxDecision(f.mailbox, f.scope, lane.boxHandle, entry.seq, expect, next, drainOwner),
|
|
247
|
+
onFault: (entry, e) => f.onError?.(e, { phase: "degraded", sessionId: f.sessionId, classification: `peer-decision-move:${entry.box}#${entry.seq}` }),
|
|
248
|
+
onHeld: (entry, count, cause, reannounce) => {
|
|
249
|
+
if (!reannounce && leg?.disclosedHeld.has(entry.seq) === true)
|
|
250
|
+
return;
|
|
251
|
+
leg?.disclosedHeld.add(entry.seq);
|
|
252
|
+
discloseSeatDisposition(f, lane, "held", cause, entry, reannounce ? `still held; its cause moved to ${cause} (${count} held)` : undefined);
|
|
253
|
+
},
|
|
254
|
+
onSettled: (entry, settlement, reason, count) => {
|
|
255
|
+
if (leg !== undefined && entry.box === lane.boxHandle && settlement !== "delivered" && settlement !== "retired")
|
|
256
|
+
leg.settled(entry.seq, settlement);
|
|
257
|
+
const replyTo = seatReceiptAddress(lane.kind, entry);
|
|
258
|
+
const told = reason !== "decided_elsewhere" && settlement !== "retired" && replyTo !== undefined;
|
|
259
|
+
deliverEngineNotice(f.onNotice, {
|
|
260
|
+
code: "peer.held_settled",
|
|
261
|
+
message: `held cross-session message seq ${entry.seq} left this session's held queue: ${settlement} (${reason}); ${count} still held${settlement === "expired" && reason === "evicted" ? " — the held queue was full, so the oldest entry was expired to make room" : ""}${settlement === "retired" ? (reason === "superseded" ? " — its record is no longer in the box (another consumer settled it); nothing was decided here" : " — no decision was taken: it stays held in the box, and the next drain presents it again") : ""}${reason === "decided_elsewhere" ? " — another consumer of the box decided it first" : ""}. The sender ${told ? "was sent a receipt" : replyTo !== undefined ? "was not sent a receipt from here" : "has no reply address and was not told"}.`,
|
|
262
|
+
detail: { settlement, reason, seq: entry.seq, box: lane.boxHandle, ...(entry.peerMeta?.fromSession !== undefined ? { fromSession: entry.peerMeta.fromSession } : {}), heldCount: count, sessionId: f.sessionId, runId: f.runId },
|
|
263
|
+
});
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
}
|
|
140
267
|
export function createPeerSessionDrain(opts) {
|
|
141
268
|
const { mailbox, sessionId, runId, scope } = opts;
|
|
142
269
|
const storedSessionAddress = (fromSession) => fromSession !== undefined && isPeerSessionId(fromSession) ? peerSessionBoxHandle(fromSession) : undefined;
|
|
@@ -171,34 +298,11 @@ export function createPeerSessionDrain(opts) {
|
|
|
171
298
|
let noticeRound = 0;
|
|
172
299
|
let currentRound;
|
|
173
300
|
const idleMachine = peerIdleMachineFor(scope, sessionId, { ...clockOpt, ...occupantOpt });
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
? "refused by this session's crossSessionInbound setting"
|
|
180
|
-
: disposition === "resupply_exhausted"
|
|
181
|
-
? "settled WITHOUT being read: its frame was summarized away by a compaction, re-supplied once, and summarized away again \u2014 the engine has stopped handing it over. The sender was not told; reply-worthy content is GONE from this session's context"
|
|
182
|
-
: disposition === "notice_unrouted"
|
|
183
|
-
? "settled WITHOUT delivery (a notice-kind record the notice face cannot render)"
|
|
184
|
-
: disposition === "notice_user_only"
|
|
185
|
-
? "surfaced to the user only (a notice whose sender this session's parity would hold; the model did not read it)"
|
|
186
|
-
: "refused by the inbound admission gate"}: ${cause}`,
|
|
187
|
-
detail: { disposition, cause, seq: m.seq, box: lane.boxHandle, ...(m.peerMeta?.fromSession !== undefined ? { fromSession: m.peerMeta.fromSession } : {}), sessionId, runId },
|
|
188
|
-
});
|
|
189
|
-
const readFacts = () => {
|
|
190
|
-
const layers = opts.settingLayers() ?? {};
|
|
191
|
-
return { setting: resolveCrossSessionInboundSetting(layers), principalSetting: resolveCrossSessionInboundSetting(principalInboundLayers(layers)), selfModeClass: opts.selfModeClass() };
|
|
192
|
-
};
|
|
193
|
-
const judgeMeta = (facts, meta) => meta?.fromScope !== undefined
|
|
194
|
-
? judgeCrossSessionInbound({ setting: facts.principalSetting, selfModeClass: facts.selfModeClass, sender: { fromScope: meta.fromScope } })
|
|
195
|
-
: judgeCrossSessionInbound({ setting: facts.setting, selfModeClass: facts.selfModeClass, sender: { ...(meta?.fromMode !== undefined ? { fromMode: meta.fromMode } : {}), selfSent: meta?.fromSession !== undefined && meta.fromSession.toLowerCase() === sessionId.toLowerCase() } });
|
|
196
|
-
const route = () => ({
|
|
197
|
-
mailbox,
|
|
198
|
-
scope,
|
|
199
|
-
self: { sessionId, ...(opts.selfName?.() !== undefined ? { name: opts.selfName() } : {}), ...occupantOpt, modeClass: opts.selfModeClass },
|
|
200
|
-
...(opts.onError !== undefined ? { onError: opts.onError } : {}),
|
|
201
|
-
});
|
|
301
|
+
const seat = { mailbox, scope, sessionId, occupant: opts.occupant, runId, settingLayers: opts.settingLayers, selfModeClass: opts.selfModeClass, selfName: () => opts.selfName?.(), lastTurnText: opts.lastTurnText, onNotice: opts.onNotice, onError: opts.onError };
|
|
302
|
+
const disclose = (lane, disposition, cause, m, heldNote) => discloseSeatDisposition(seat, lane, disposition, cause, m, heldNote);
|
|
303
|
+
const readFacts = () => readSeatJudgment(seat);
|
|
304
|
+
const judgeMeta = (facts, meta) => judgeSeatMeta(sessionId, facts, meta);
|
|
305
|
+
const route = () => seatRoute(seat);
|
|
202
306
|
const buildPeerMessagePayload = (lane, m) => {
|
|
203
307
|
const { boxHandle } = lane;
|
|
204
308
|
const meta = m.peerMeta;
|
|
@@ -232,29 +336,7 @@ export function createPeerSessionDrain(opts) {
|
|
|
232
336
|
crossSessionNotice: { kind, text },
|
|
233
337
|
_sema_provenance: { kind: "cross_session_notice", from: encodePeerAddress(storedSessionAddress(m.peerMeta?.fromSession) ?? (m.from ?? "unknown")), taskId: boxHandle, seq: m.seq, ...(m.peerMeta !== undefined ? { peerMeta: { ...m.peerMeta } } : {}) },
|
|
234
338
|
});
|
|
235
|
-
const receiptAddress = (lane, entry) =>
|
|
236
|
-
const from = lane.kind === "session" ? entry.peerMeta?.fromSession : undefined;
|
|
237
|
-
return from === undefined ? undefined : { sessionId: from, occupant: entry.peerMeta?.fromOccupant };
|
|
238
|
-
};
|
|
239
|
-
const receipt = (lane) => async (entry, state, releasedBy) => {
|
|
240
|
-
const to = receiptAddress(lane, entry);
|
|
241
|
-
if (to === undefined)
|
|
242
|
-
return;
|
|
243
|
-
const faults = [];
|
|
244
|
-
const via = {
|
|
245
|
-
...route(),
|
|
246
|
-
onError: (error, ctx) => {
|
|
247
|
-
faults.push(error);
|
|
248
|
-
opts.onError?.(error, ctx);
|
|
249
|
-
},
|
|
250
|
-
};
|
|
251
|
-
if (state === "dropped")
|
|
252
|
-
await routePeerDroppedReceipt(via, to, entry.seq);
|
|
253
|
-
else
|
|
254
|
-
await routePeerDeliveryReceipt(via, to, state, entry.seq, releasedBy);
|
|
255
|
-
if (faults.length > 0)
|
|
256
|
-
throw faults[0];
|
|
257
|
-
};
|
|
339
|
+
const receiptAddress = (lane, entry) => seatReceiptAddress(lane.kind, entry);
|
|
258
340
|
const settleConsumed = (lane, seq, payload, by, reason) => {
|
|
259
341
|
lane.ledger.set(seq, { kind: "terminal", why: "consumed" });
|
|
260
342
|
const peerMeta = payload._sema_provenance?.kind === "cross_session_message" ? payload._sema_provenance.peerMeta : undefined;
|
|
@@ -262,63 +344,43 @@ export function createPeerSessionDrain(opts) {
|
|
|
262
344
|
if (to !== undefined)
|
|
263
345
|
void routePeerDeliveryReceipt(route(), to, "refused", seq, by === "engine" ? "the receiving engine (it could not judge the message)" : `extension ${by} of that session: ${reason}`);
|
|
264
346
|
};
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (currentRound.out !== undefined && opts.receive?.listens() === true) {
|
|
274
|
-
currentRound.batch.push({ lane, payload, priority: "next", urgent: false, seq: entry.seq, attempt: 1, source: entry });
|
|
275
|
-
return undefined;
|
|
276
|
-
}
|
|
277
|
-
if (currentRound.out === undefined && payload._sema_provenance?.peerMeta?.fromScope !== undefined && opts.markExternalContent !== undefined) {
|
|
278
|
-
const round = currentRound;
|
|
279
|
-
try {
|
|
280
|
-
await opts.markExternalContent(`a letter from another principal (cross-principal message seq ${entry.seq} in ${lane.boxHandle}) was delivered into this session`);
|
|
281
|
-
}
|
|
282
|
-
catch (e) {
|
|
283
|
-
opts.onError?.(e, { phase: "degraded", sessionId, classification: "peer-external-mark" });
|
|
284
|
-
return "deferred";
|
|
285
|
-
}
|
|
286
|
-
if (currentRound !== round || !round.holds(lane))
|
|
287
|
-
return "deferred";
|
|
288
|
-
}
|
|
289
|
-
if (currentRound.deliver(payload, "next") === "deferred")
|
|
290
|
-
return "deferred";
|
|
291
|
-
noteDelivered(lane, entry.seq, 1, payload, entry, currentRound.carrier);
|
|
292
|
-
return undefined;
|
|
293
|
-
},
|
|
294
|
-
canInject: () => currentRound !== undefined && currentRound.holds(lane) && !currentRound.spent,
|
|
347
|
+
const heldLegSeats = (lane) => ({
|
|
348
|
+
inject: async (entry) => {
|
|
349
|
+
if (currentRound === undefined || !currentRound.holds(lane))
|
|
350
|
+
return "deferred";
|
|
351
|
+
const payload = buildPeerMessagePayload(lane, entry);
|
|
352
|
+
if (currentRound.out !== undefined && opts.receive?.listens() === true) {
|
|
353
|
+
currentRound.batch.push({ lane, payload, priority: "next", urgent: false, seq: entry.seq, attempt: 1, source: entry });
|
|
354
|
+
return undefined;
|
|
295
355
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
356
|
+
if (currentRound.out === undefined && payload._sema_provenance?.peerMeta?.fromScope !== undefined && opts.markExternalContent !== undefined) {
|
|
357
|
+
const round = currentRound;
|
|
358
|
+
try {
|
|
359
|
+
await opts.markExternalContent(`a letter from another principal (cross-principal message seq ${entry.seq} in ${lane.boxHandle}) was delivered into this session`);
|
|
360
|
+
}
|
|
361
|
+
catch (e) {
|
|
362
|
+
opts.onError?.(e, { phase: "degraded", sessionId, classification: "peer-external-mark" });
|
|
363
|
+
return "deferred";
|
|
364
|
+
}
|
|
365
|
+
if (currentRound !== round || !round.holds(lane))
|
|
366
|
+
return "deferred";
|
|
367
|
+
}
|
|
368
|
+
if (currentRound.deliver(payload, "next") === "deferred")
|
|
369
|
+
return "deferred";
|
|
370
|
+
noteDelivered(lane, entry.seq, 1, payload, entry, currentRound.carrier);
|
|
371
|
+
return undefined;
|
|
306
372
|
},
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const replyTo = receiptAddress(lane, entry);
|
|
311
|
-
const told = reason !== "decided_elsewhere" && settlement !== "retired" && replyTo !== undefined;
|
|
312
|
-
deliverEngineNotice(opts.onNotice, {
|
|
313
|
-
code: "peer.held_settled",
|
|
314
|
-
message: `held cross-session message seq ${entry.seq} left this session's held queue: ${settlement} (${reason}); ${count} still held${settlement === "expired" && reason === "evicted" ? " — the held queue was full, so the oldest entry was expired to make room" : ""}${settlement === "retired" ? (reason === "superseded" ? " — its record is no longer in the box (another consumer settled it); nothing was decided here" : " — no decision was taken: it stays held in the box, and the next drain presents it again") : ""}${reason === "decided_elsewhere" ? " — another consumer of the box decided it first" : ""}. The sender ${told ? "was sent a receipt" : replyTo !== undefined ? "was not sent a receipt from here" : "has no reply address and was not told"}.`,
|
|
315
|
-
detail: { settlement, reason, seq: entry.seq, box: lane.boxHandle, ...(entry.peerMeta?.fromSession !== undefined ? { fromSession: entry.peerMeta.fromSession } : {}), heldCount: count, sessionId, runId },
|
|
316
|
-
});
|
|
373
|
+
canInject: () => currentRound !== undefined && currentRound.holds(lane) && !currentRound.spent,
|
|
374
|
+
settled: (seq, settlement) => {
|
|
375
|
+
lane.ledger.set(seq, { kind: "terminal", why: `held_${settlement}` });
|
|
317
376
|
},
|
|
377
|
+
disclosedHeld: lane.disclosedHeld,
|
|
318
378
|
});
|
|
319
379
|
let dialogExpiryMs = resolveCrossSessionDialogExpiry(undefined).ms;
|
|
320
380
|
let dialogExpiryAnnounced = false;
|
|
321
|
-
const
|
|
381
|
+
const binder = Symbol("peer-seat-binder");
|
|
382
|
+
let resting;
|
|
383
|
+
const bindHeld = (lane) => {
|
|
322
384
|
try {
|
|
323
385
|
const resolved = resolveCrossSessionDialogExpiry(opts.dialogExpiry?.());
|
|
324
386
|
dialogExpiryMs = resolved.ms;
|
|
@@ -330,19 +392,22 @@ export function createPeerSessionDrain(opts) {
|
|
|
330
392
|
catch (e) {
|
|
331
393
|
opts.onError?.(e, { phase: "degraded", sessionId, classification: "peer-dialog-expiry" });
|
|
332
394
|
}
|
|
333
|
-
lane.held
|
|
395
|
+
bindPeerSeat(lane.held, binder, resting !== undefined, () => ({ sink: heldSinkOf(lane), dialogExpiryMs }));
|
|
334
396
|
};
|
|
397
|
+
const heldSinkOf = (lane) => (resting === undefined ? heldQueueSink(seat, lane, drainOwner, heldLegSeats(lane)) : heldQueueSink(resting, { kind: lane.kind, boxHandle: lane.boxHandle, label: lane.label }, drainOwner));
|
|
335
398
|
for (const lane of lanes)
|
|
336
|
-
bindHeld(lane
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
})
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
399
|
+
bindHeld(lane);
|
|
400
|
+
const heldQueues = lanes.map((lane) => lane.held);
|
|
401
|
+
const bindTarget = () => bindPeerSeat(idleMachine.target, binder, resting !== undefined, () => idleTargetSink(resting ?? seat, heldQueues));
|
|
402
|
+
const bindRequester = () => bindPeerSeat(idleMachine.requester, binder, resting !== undefined, () => idleRequesterSink(resting ?? seat));
|
|
403
|
+
bindTarget();
|
|
404
|
+
bindRequester();
|
|
405
|
+
for (const bind of [bindTarget, bindRequester, ...lanes.map((lane) => () => bindPeerSeat(lane.held, binder, true, () => ({ sink: heldSinkOf(lane), dialogExpiryMs })))]) {
|
|
406
|
+
opts.runEnd?.lend(() => {
|
|
407
|
+
resting ??= restingSeatFacts(seat);
|
|
408
|
+
bind();
|
|
409
|
+
});
|
|
410
|
+
}
|
|
346
411
|
const reconcileHeld = async (lane, lease) => {
|
|
347
412
|
const live = lease.messages.filter((m) => lane.ackedUpTo === undefined || m.seq > lane.ackedUpTo);
|
|
348
413
|
lane.held.reconcile(new Map(live.map((m) => [m.seq, m.decision])));
|
|
@@ -735,7 +800,7 @@ export function createPeerSessionDrain(opts) {
|
|
|
735
800
|
return { pending: 0, urgent: 0 };
|
|
736
801
|
round.lease(leased.map((c) => c.lane));
|
|
737
802
|
for (const { lane, lease } of leased) {
|
|
738
|
-
bindHeld(lane
|
|
803
|
+
bindHeld(lane);
|
|
739
804
|
await reconcileHeld(lane, lease);
|
|
740
805
|
await lane.held.rejudge();
|
|
741
806
|
}
|
|
@@ -1090,6 +1155,9 @@ export function mountListAgents(args) {
|
|
|
1090
1155
|
...(args.readSeats ?? {}),
|
|
1091
1156
|
});
|
|
1092
1157
|
}
|
|
1158
|
+
function crossSessionInboundOf(deps) {
|
|
1159
|
+
return () => (typeof deps.crossSessionInbound === "function" ? deps.crossSessionInbound() : deps.crossSessionInbound);
|
|
1160
|
+
}
|
|
1093
1161
|
export function bindPeerSessionDrain(harness, opts) {
|
|
1094
1162
|
const drain = createPeerSessionDrain(opts);
|
|
1095
1163
|
const round = async () => {
|
|
@@ -1148,8 +1216,9 @@ export function bindPeerLaneDrain(harness, args) {
|
|
|
1148
1216
|
inject: args.inject,
|
|
1149
1217
|
...(deps.peerLane !== undefined ? { lane: deps.peerLane } : {}),
|
|
1150
1218
|
ownTokens: args.ownTokens,
|
|
1151
|
-
settingLayers: (
|
|
1219
|
+
settingLayers: crossSessionInboundOf(deps),
|
|
1152
1220
|
selfModeClass: () => peerModeClassOf(args.refs),
|
|
1221
|
+
...(args.runEnd !== undefined ? { runEnd: args.runEnd } : {}),
|
|
1153
1222
|
dialogExpiry: () => (typeof deps.crossSessionDialogExpiry === "function" ? deps.crossSessionDialogExpiry() : deps.crossSessionDialogExpiry),
|
|
1154
1223
|
selfName: () => rowName ?? args.selfName?.(),
|
|
1155
1224
|
warmup: lookupRowName,
|
|
@@ -229,6 +229,11 @@ export interface EngineNotice {
|
|
|
229
229
|
* name this pid: `detail: { lock, path, pid }`, `lock` one of `"directory_fence"`, `"boot"` (a file
|
|
230
230
|
* store's data root) or `"mailbox"` (a box lock, unreadable at release or not removable). Said on the
|
|
231
231
|
* default seat; audience `operator`; once per failed release.
|
|
232
|
+
* - `"store.lock_reclaimed_on_declaration"` — a file store's directory lock whose record names no pid
|
|
233
|
+
* namespace was removed because the host declared, with `declareDataRoot(root, { singleProcessTable:
|
|
234
|
+
* true })`, that every process opening that data root runs in this process table, and the process the
|
|
235
|
+
* record names is gone from it. `detail: { path, pid, root }` — the lock, the pid it named, the declared
|
|
236
|
+
* root that covers it. Said on the default seat; audience `operator`; once per lock removed.
|
|
232
237
|
* - `"memory.notice_unscoped"` — a memory notice (the engine's, or a file store's) named no single
|
|
233
238
|
* scope, so it was kept off every session's memory notices; said here only when the memory engine has
|
|
234
239
|
* no incident sink (with one, the sink is told `memory.announcement_withheld`). `detail: { stage }`.
|