@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
|
@@ -154,7 +154,7 @@ export type NoticeAudience = "user" | "operator";
|
|
|
154
154
|
* the union's catalog ({@link EngineNotice.code}). The groups below say only which family a row joins,
|
|
155
155
|
* so the catalog is not written a second time here and the two cannot drift.
|
|
156
156
|
*/
|
|
157
|
-
export declare const ENGINE_NOTICE_CODES: readonly ["config.autocompact_window_clamped", "config.env_timeout_discarded", "config.materialize_env_discarded", "config.models_swapped", "config.context_settings_swapped", "config.read_face_swapped", "config.read_face_deployment_clamped", "config.write_face_swapped", "config.write_face_deployment_clamped", "config.read_deny_swapped", "config.tool_model_gate_removed", "config.tool_model_gate_unknown_class", "config.tool_model_gate_env_invalid", "config.artifact_host_invalid", "config.task_root_not_canonical", "config.write_protection_target_view_absent", "config.path_view_unresolved", "config.execution_env_capability_invalid", "config.read_deny_floor_unkept", "config.read_floor_confinement_unavailable", "config.inherit_env_declared_late", "config.command_sandbox_unavailable", "config.tool_card_undeclared", "config.tool_face_undeclared", "config.tool_face_invalid", "config.host_sink_failed", "config.seat_malformed", "config.env_knob_adjusted", "config.read_deny_home", "config.permission_rules_skipped", "config.process_start_time_unavailable", "config.durable_gate_unavailable", "config.peer_admission_out_of_range", "config.peer_lane_unmounted", "config.secret_env_scrubbed", "inherit_env.names_withheld", "config.credential_not_withheld", "config.cross_boundary_posture_undeclared", "config.cross_boundary_record_unwritten", "config.permission_mode_unavailable", "permission.ask_released_by_mode", "permission.read_deny_unapplied", "permission.rule_store_unavailable", "permission.rule_row_dropped", "config.session_rules_earlier_grammar", "config.legacy_tool_name", "config.toolpolicy.unmatched_names", "config.agent.unknown_tool", "permission.allowed_tool_not_granted", "permission.allow_rule_not_used_in_auto", "mods.registration_refused", "mods.display_withheld", "mods.stop_ended", "peer.inbound_disposition", "peer.held_settled", "peer.idle_subscription", "classifier.denial_limit", "classifier.fallback", "classifier.seat_rate_limited", "classifier.role_defaulted", "classifier.contract_broken", "classifier.unavailable", "checkpoint.execution_outcome_unrecorded", "delegation.transcript_integrity", "delegation.ask_unresolvable", "delegation.resume_lane_missing", "delegation.delivery_discarded", "delegation.settlement_external", "delegation.settlement_write_failed", "delegation.durable_row_unpersisted", "delegation.parked_card_unreadable", "mcp.injection_dropped", "protocol.revocation_probe_failed", "mcp.server_redialed", "mcp.authorization_required", "mcp.server_unavailable", "mcp.credential_echoed", "workflow.governance_key_stripped", "workflow.agent_option_ignored", "memory.session_polluted", "memory.harvest_quarantined", "memory.harvest_refused", "memory.harvest_conflict", "memory.delegation_static_mark_waived", "memory.content_class_declared", "memory.hold_opened", "memory.hold_released", "memory.hold_disposed", "memory.consolidation_recommended", "memory.consolidation_committed", "memory.consolidation_conflict", "memory.consolidation_incomplete", "memory.consolidation_refused", "memory.consolidation_withheld", "memory.restore_withheld", "memory.project_scope_absent", "memory.notice_unscoped", "route.fallback_to_primary", "route.classifier_unroutable", "route.seat_detached", "advisor.not_attached", "route.credential_origin_mismatch", "route.credential_mismatch", "route.credential_rebound", "route.response_model_mismatch", "route.tool_call_id_folded", "route.finish_reason_unknown", "route.stream_end_ignored", "route.extra_body_reserved_dropped", "model.capability_downgraded", "model.role_defaulted", "model.fallback", "context.tool_turn_repaired", "context.media_removed", "context.tool_schema_removed", "context.messages_omitted", "instructions.withheld", "instructions.family_undeclared", "task.user_steer_undrained", "task.user_followup_undrained", "task.undelivered_input_dropped", "steering.parked_input_blocked", "task.turn_interrupted", "task.halt_unconsumed", "task.late_approval", "task.interrupt_unconsumed", "task.completed_past_limit", "task.tool_turn_incomplete", "approval.read_root_granted", "approval.read_root_grant_rejected", "approval.approver_defect", "memory.capture_opted_out", "memory.capture_optout_unpersisted", "memory.mount_failed", "skills.listing_truncated", "agents.listing_truncated", "tool_result.offload_put_failed", "tool_result.media_refused", "tool_result.media_persisted", "config.image_processor_unavailable", "fs.staging_file_left", "fs.staging_file_swept", "store.tail_segment_unjudged", "store.lock_retained", "engine.debug_trace", "session.lineage_rerooted", "rewind.boundary_unrecorded", "verify.verifier_is_implementer", "memory.layer_locked_legacy", "server.model_unreachable", "permission.entry_mode_clamped", "model.context_window_assumed", "config.store_ephemeral"];
|
|
157
|
+
export declare const ENGINE_NOTICE_CODES: readonly ["config.autocompact_window_clamped", "config.env_timeout_discarded", "config.materialize_env_discarded", "config.models_swapped", "config.context_settings_swapped", "config.read_face_swapped", "config.read_face_deployment_clamped", "config.write_face_swapped", "config.write_face_deployment_clamped", "config.read_deny_swapped", "config.tool_model_gate_removed", "config.tool_model_gate_unknown_class", "config.tool_model_gate_env_invalid", "config.artifact_host_invalid", "config.task_root_not_canonical", "config.write_protection_target_view_absent", "config.path_view_unresolved", "config.execution_env_capability_invalid", "config.read_deny_floor_unkept", "config.read_floor_confinement_unavailable", "config.inherit_env_declared_late", "config.command_sandbox_unavailable", "config.tool_card_undeclared", "config.tool_face_undeclared", "config.tool_face_invalid", "config.host_sink_failed", "config.seat_malformed", "config.env_knob_adjusted", "config.read_deny_home", "config.permission_rules_skipped", "config.process_start_time_unavailable", "config.durable_gate_unavailable", "config.peer_admission_out_of_range", "config.peer_lane_unmounted", "config.secret_env_scrubbed", "inherit_env.names_withheld", "config.credential_not_withheld", "config.cross_boundary_posture_undeclared", "config.cross_boundary_record_unwritten", "config.permission_mode_unavailable", "permission.ask_released_by_mode", "permission.read_deny_unapplied", "permission.rule_store_unavailable", "permission.rule_row_dropped", "config.session_rules_earlier_grammar", "config.legacy_tool_name", "config.toolpolicy.unmatched_names", "config.agent.unknown_tool", "permission.allowed_tool_not_granted", "permission.allow_rule_not_used_in_auto", "mods.registration_refused", "mods.display_withheld", "mods.stop_ended", "peer.inbound_disposition", "peer.held_settled", "peer.idle_subscription", "classifier.denial_limit", "classifier.fallback", "classifier.seat_rate_limited", "classifier.role_defaulted", "classifier.contract_broken", "classifier.unavailable", "checkpoint.execution_outcome_unrecorded", "delegation.transcript_integrity", "delegation.ask_unresolvable", "delegation.resume_lane_missing", "delegation.delivery_discarded", "delegation.settlement_external", "delegation.settlement_write_failed", "delegation.durable_row_unpersisted", "delegation.parked_card_unreadable", "mcp.injection_dropped", "protocol.revocation_probe_failed", "mcp.server_redialed", "mcp.authorization_required", "mcp.server_unavailable", "mcp.credential_echoed", "workflow.governance_key_stripped", "workflow.agent_option_ignored", "memory.session_polluted", "memory.harvest_quarantined", "memory.harvest_refused", "memory.harvest_conflict", "memory.delegation_static_mark_waived", "memory.content_class_declared", "memory.hold_opened", "memory.hold_released", "memory.hold_disposed", "memory.consolidation_recommended", "memory.consolidation_committed", "memory.consolidation_conflict", "memory.consolidation_incomplete", "memory.consolidation_refused", "memory.consolidation_withheld", "memory.restore_withheld", "memory.project_scope_absent", "memory.notice_unscoped", "route.fallback_to_primary", "route.classifier_unroutable", "route.seat_detached", "advisor.not_attached", "route.credential_origin_mismatch", "route.credential_mismatch", "route.credential_rebound", "route.response_model_mismatch", "route.tool_call_id_folded", "route.finish_reason_unknown", "route.stream_end_ignored", "route.extra_body_reserved_dropped", "model.capability_downgraded", "model.role_defaulted", "model.fallback", "context.tool_turn_repaired", "context.media_removed", "context.tool_schema_removed", "context.messages_omitted", "instructions.withheld", "instructions.family_undeclared", "task.user_steer_undrained", "task.user_followup_undrained", "task.undelivered_input_dropped", "steering.parked_input_blocked", "task.turn_interrupted", "task.halt_unconsumed", "task.late_approval", "task.interrupt_unconsumed", "task.completed_past_limit", "task.tool_turn_incomplete", "approval.read_root_granted", "approval.read_root_grant_rejected", "approval.approver_defect", "memory.capture_opted_out", "memory.capture_optout_unpersisted", "memory.mount_failed", "skills.listing_truncated", "agents.listing_truncated", "tool_result.offload_put_failed", "tool_result.media_refused", "tool_result.media_persisted", "config.image_processor_unavailable", "fs.staging_file_left", "fs.staging_file_swept", "store.tail_segment_unjudged", "store.lock_retained", "store.lock_reclaimed_on_declaration", "engine.debug_trace", "session.lineage_rerooted", "rewind.boundary_unrecorded", "verify.verifier_is_implementer", "memory.layer_locked_legacy", "server.model_unreachable", "permission.entry_mode_clamped", "model.context_window_assumed", "config.store_ephemeral"];
|
|
158
158
|
/** A catalogued code (see {@link ENGINE_NOTICE_CODES}); {@link NOTICE_MINTER} says who mints it. NOT the type of
|
|
159
159
|
* `EngineNotice.code`, which stays `string` — a host forwarding its own notices through the same
|
|
160
160
|
* sink is a supported shape, and narrowing that field would break it. */
|
|
@@ -315,6 +315,7 @@ declare const NOTICE_AUDIENCE_TABLE: {
|
|
|
315
315
|
readonly "config.process_start_time_unavailable": "operator";
|
|
316
316
|
readonly "store.tail_segment_unjudged": "operator";
|
|
317
317
|
readonly "store.lock_retained": "operator";
|
|
318
|
+
readonly "store.lock_reclaimed_on_declaration": "operator";
|
|
318
319
|
readonly "memory.notice_unscoped": "operator";
|
|
319
320
|
readonly "delegation.settlement_external": "operator";
|
|
320
321
|
readonly "delegation.settlement_write_failed": "operator";
|
|
@@ -495,6 +496,7 @@ declare const NOTICE_MINTER_TABLE: {
|
|
|
495
496
|
readonly "fs.staging_file_swept": "engine";
|
|
496
497
|
readonly "store.tail_segment_unjudged": "engine";
|
|
497
498
|
readonly "store.lock_retained": "engine";
|
|
499
|
+
readonly "store.lock_reclaimed_on_declaration": "engine";
|
|
498
500
|
readonly "engine.debug_trace": "engine";
|
|
499
501
|
readonly "session.lineage_rerooted": "engine";
|
|
500
502
|
readonly "rewind.boundary_unrecorded": "engine";
|
|
@@ -279,6 +279,7 @@ export const ENGINE_NOTICE_CODES = Object.freeze([
|
|
|
279
279
|
"fs.staging_file_swept",
|
|
280
280
|
"store.tail_segment_unjudged",
|
|
281
281
|
"store.lock_retained",
|
|
282
|
+
"store.lock_reclaimed_on_declaration",
|
|
282
283
|
"engine.debug_trace",
|
|
283
284
|
"session.lineage_rerooted",
|
|
284
285
|
"rewind.boundary_unrecorded",
|
|
@@ -432,6 +433,7 @@ const NOTICE_AUDIENCE_TABLE = {
|
|
|
432
433
|
"config.process_start_time_unavailable": "operator",
|
|
433
434
|
"store.tail_segment_unjudged": "operator",
|
|
434
435
|
"store.lock_retained": "operator",
|
|
436
|
+
"store.lock_reclaimed_on_declaration": "operator",
|
|
435
437
|
"memory.notice_unscoped": "operator",
|
|
436
438
|
"delegation.settlement_external": "operator",
|
|
437
439
|
"delegation.settlement_write_failed": "operator",
|
|
@@ -593,6 +595,7 @@ const NOTICE_MINTER_TABLE = {
|
|
|
593
595
|
"fs.staging_file_swept": "engine",
|
|
594
596
|
"store.tail_segment_unjudged": "engine",
|
|
595
597
|
"store.lock_retained": "engine",
|
|
598
|
+
"store.lock_reclaimed_on_declaration": "engine",
|
|
596
599
|
"engine.debug_trace": "engine",
|
|
597
600
|
"session.lineage_rerooted": "engine",
|
|
598
601
|
"rewind.boundary_unrecorded": "engine",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ClassicEventBase } from "../hooks.js";
|
|
2
2
|
import { type EngineNotice } from "../engine-notice.js";
|
|
3
3
|
import type { QueueSlot } from "../push-queue.js";
|
|
4
|
+
import type { RunEnd } from "../runner/end-of-run.js";
|
|
4
5
|
import type { TaskEvent, TaskEventIdentity } from "../task-event.js";
|
|
5
6
|
import { type LegEvents, type LegModBus } from "./stations.js";
|
|
6
7
|
/** The station's pace (CC 2.1.316 `VTs`, cli316.js:288153: a raise every 100 ms, three in flight, a window's ten seconds). */
|
|
@@ -44,6 +45,8 @@ export interface MessageDisplayInput {
|
|
|
44
45
|
readonly ident: () => TaskEventIdentity;
|
|
45
46
|
/** The caller's stop: once it fires, nothing more of any message is shown (and nothing is said of what is not). */
|
|
46
47
|
readonly signal: AbortSignal;
|
|
48
|
+
/** The run's end (runner/end-of-run.ts): the station hears `signal` through it, until then — the caller's stop outlives the run. */
|
|
49
|
+
readonly runEnd: Pick<RunEnd, "listen">;
|
|
47
50
|
/** The leg's notice sink (`RunnerDeps.onNotice`): an answer that did not stand is said through the engine's one notice throat. */
|
|
48
51
|
readonly onNotice: ((notice: EngineNotice) => void) | undefined;
|
|
49
52
|
readonly sessionId: string;
|
|
@@ -71,10 +71,10 @@ export function openMessageDisplay(input) {
|
|
|
71
71
|
m.finalSlot?.fill([]);
|
|
72
72
|
m.finish();
|
|
73
73
|
};
|
|
74
|
-
input.
|
|
74
|
+
input.runEnd.listen(input.signal, () => {
|
|
75
75
|
for (const m of [...messages])
|
|
76
76
|
drop(m);
|
|
77
|
-
}
|
|
77
|
+
});
|
|
78
78
|
const open = (whole) => {
|
|
79
79
|
let resolveDone;
|
|
80
80
|
const done = new Promise((resolve) => (resolveDone = resolve));
|
|
@@ -85,6 +85,16 @@ export type ProcessVerdict = {
|
|
|
85
85
|
readonly state: "uncheckable";
|
|
86
86
|
readonly why: ProcessUncheckable;
|
|
87
87
|
};
|
|
88
|
+
/** What a census is told besides the records it judges. */
|
|
89
|
+
export interface ProcessCensusOptions {
|
|
90
|
+
/**
|
|
91
|
+
* The host has declared that every process which could have written the records this census judges runs in THIS process
|
|
92
|
+
* table — no other container and no other host opens what those records guard. A record that names NO pid namespace is
|
|
93
|
+
* then read as naming this one, and judged like any record written here. It fills in only what a record leaves unsaid: a
|
|
94
|
+
* record that names another namespace, or another host, is exactly as uncomparable as without it.
|
|
95
|
+
*/
|
|
96
|
+
readonly singleProcessTable?: true;
|
|
97
|
+
}
|
|
88
98
|
/** One question session over the process table. */
|
|
89
99
|
export interface ProcessCensus {
|
|
90
100
|
/** The verdict on one record. Within one census each pid is signalled at most once and its start time is
|
|
@@ -118,7 +128,9 @@ export declare function processFingerprint(pid?: number): ProcessFingerprint;
|
|
|
118
128
|
* one), is `uncheckable` — and the pid is never signalled: a number from another table names nothing
|
|
119
129
|
* here, and signalling it would judge whatever unrelated process happens to hold it. With no namespace
|
|
120
130
|
* on either side (macOS), the host name decides alone. A record naming no host at all (a pre-fingerprint
|
|
121
|
-
* spelling) is compared on the namespace alone.
|
|
131
|
+
* spelling) is compared on the namespace alone. A record naming no namespace is read as naming this one
|
|
132
|
+
* when the census was told so ({@link ProcessCensusOptions.singleProcessTable}) — the one input the host
|
|
133
|
+
* can supply, and only to this step.
|
|
122
134
|
* 2. EXISTS? `kill(pid, 0)`: only ESRCH is `gone`. EPERM is a process that exists; any other error is the
|
|
123
135
|
* table refusing the question — `uncheckable`, never `gone`.
|
|
124
136
|
* 3. SAME PROCESS? The record's start time against the one observed now. One-sided: whatever holds a
|
|
@@ -130,7 +142,7 @@ export declare function processFingerprint(pid?: number): ProcessFingerprint;
|
|
|
130
142
|
* this host's own uptime names a boot that is over. A record and an observation sharing no measure at all
|
|
131
143
|
* are `uncheckable` (`start_time_unknown`); otherwise the process is `running`.
|
|
132
144
|
*/
|
|
133
|
-
export declare function processCensus(): ProcessCensus;
|
|
145
|
+
export declare function processCensus(options?: ProcessCensusOptions): ProcessCensus;
|
|
134
146
|
/**
|
|
135
147
|
* Is the process a record names possibly still the one that wrote it? `false` ONLY when it is proven gone
|
|
136
148
|
* (see {@link processCensus}): a record from another process table, a pid the table will not answer about,
|
|
@@ -7,7 +7,7 @@ import { deliverEngineNotice } from "./engine-notice.js";
|
|
|
7
7
|
const UNCHECKABLE_TEXT = Object.freeze({
|
|
8
8
|
another_host: "it was written on another host",
|
|
9
9
|
another_pid_namespace: "it was written in another pid namespace (another container, or one this process cannot name)",
|
|
10
|
-
pid_namespace_unrecorded: "it was written without naming its pid namespace (by an engine before this one, or by a process that could not read it),
|
|
10
|
+
pid_namespace_unrecorded: "it was written without naming its pid namespace (by an engine before this one, or by a process that could not read it), so another process table under this host name may have written it",
|
|
11
11
|
start_time_unknown: "no start time could be compared, so a process now holding that pid cannot be told apart from the one that wrote it",
|
|
12
12
|
probe_refused: "the process table refused the question",
|
|
13
13
|
});
|
|
@@ -165,7 +165,8 @@ const RUNNING = Object.freeze({ state: "running" });
|
|
|
165
165
|
function uncheckable(why) {
|
|
166
166
|
return { state: "uncheckable", why };
|
|
167
167
|
}
|
|
168
|
-
export function processCensus() {
|
|
168
|
+
export function processCensus(options) {
|
|
169
|
+
const singleProcessTable = options?.singleProcessTable === true;
|
|
169
170
|
const signalled = new Map();
|
|
170
171
|
const observed = new Map();
|
|
171
172
|
const signal = (pid) => {
|
|
@@ -188,7 +189,8 @@ export function processCensus() {
|
|
|
188
189
|
verdict(record) {
|
|
189
190
|
if (typeof record.host === "string" && record.host !== "" && record.host !== thisHost())
|
|
190
191
|
return uncheckable("another_host");
|
|
191
|
-
const
|
|
192
|
+
const recorded = typeof record.pidNs === "string" && record.pidNs !== "" ? record.pidNs : null;
|
|
193
|
+
const theirs = recorded ?? (singleProcessTable ? ownPidNamespace() : null);
|
|
192
194
|
if (theirs !== ownPidNamespace())
|
|
193
195
|
return uncheckable(theirs === null ? "pid_namespace_unrecorded" : "another_pid_namespace");
|
|
194
196
|
const answer = signal(record.pid);
|
|
@@ -18,8 +18,8 @@ export interface CallerStopGate {
|
|
|
18
18
|
readonly signal: AbortSignal;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* The caller's own signal is COMPOSED into the read face, not listened to
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* The caller's own signal is COMPOSED into the read face, not listened to, so the gate keeps answering after the leg
|
|
22
|
+
* dropped its own listener on that signal — which is exactly when the end-of-task pass runs. A listener hung ON the read
|
|
23
|
+
* face outlives the run with it (a composed signal that carries one is held until it aborts): listen through the run's end.
|
|
24
24
|
*/
|
|
25
25
|
export declare function mintCallerStopGate(callerSignal: AbortSignal | undefined): CallerStopGate;
|
|
@@ -544,7 +544,7 @@ export interface Prepared {
|
|
|
544
544
|
permissionRuleOrg?: {
|
|
545
545
|
adjudicate: (req: ToolCallRequest) => Promise<OrgGateVerdict>;
|
|
546
546
|
};
|
|
547
|
-
/**
|
|
547
|
+
/** Takes the `spec.signal` abort listener off once the leg's loop ended (its job is over); the run's end takes it off on every exit. */
|
|
548
548
|
releaseSignal: () => void;
|
|
549
549
|
/** The leg has stopped: its children's mode ceiling moves to the session's current leg (called once its loop settled). */
|
|
550
550
|
endModeCeiling: () => void;
|
|
@@ -3150,7 +3150,7 @@ export interface RunnerSelfSeat {
|
|
|
3150
3150
|
*/
|
|
3151
3151
|
export type PrepareTaskFn = (spec: TaskSpec, deps: RunnerDeps, sessions: SessionStore, resume?: PrepareResume, internals?: RunInternals, runnerSelf?: RunnerSelfSeat, runIdSink?: {
|
|
3152
3152
|
runId?: string;
|
|
3153
|
-
}, holdSessionLock?: (sessionId: string) => Promise<void>, legWrites?: LegWrites, noticeDestinations?: import("../task-notification.js").NoticeDestinationJudge, promptSubmitRef?: import("../input-author.js").PromptSubmitRef) => Promise<Prepared>;
|
|
3153
|
+
}, holdSessionLock?: (sessionId: string) => Promise<void>, legWrites?: LegWrites, noticeDestinations?: import("../task-notification.js").NoticeDestinationJudge, promptSubmitRef?: import("../input-author.js").PromptSubmitRef, runEnd?: import("./end-of-run.js").RunEnd) => Promise<Prepared>;
|
|
3154
3154
|
/** One leg's view of the Runner's session write ledger (`session-write-ledger.ts`): `issue` starts a write of the leg (`what` = the
|
|
3155
3155
|
* entry type, for a report) or refuses it once `close` ran — the leg's hold ended; a write still in flight is reported when it settles. */
|
|
3156
3156
|
export interface LegWrites {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run's end: one per run, and the one place a run takes back everything it handed to something that outlives it.
|
|
3
|
+
*
|
|
4
|
+
* A run reaches holders that can outlive it — the caller's `TaskSpec.signal` (a host may keep one controller for many runs, or
|
|
5
|
+
* never abort it), the caller-stop gate composed from it, a parent leg's tool signal a child run is handed, and the process-level
|
|
6
|
+
* seats of its session (the idle machine, the held queue of each box the leg drains), which live as long as the process. What the
|
|
7
|
+
* run leaves on such a holder — a listener, a sink — stays reachable for as long as the holder does, and so does everything it
|
|
8
|
+
* closes over (the run's prepared state, its conversation, its tool table, its images). A composed signal (`AbortSignal.any`) or a
|
|
9
|
+
* timeout signal that carries an abort listener is held by the runtime itself until it aborts, so dropping the signal frees nothing
|
|
10
|
+
* either.
|
|
11
|
+
*
|
|
12
|
+
* The rule: the run hands such a thing over only through its end — {@link RunEnd.listen} for a listener on a signal it does not
|
|
13
|
+
* own, {@link RunEnd.lend} for anything else, naming how it is taken back. The stream leg mints the end when the run starts and
|
|
14
|
+
* ends it once the run has settled — its result published by the run body, or by the failure backstop after a throw — so every
|
|
15
|
+
* hand-over is taken back whether or not the run reached its loop, and the host owes nothing after the run. A hand-over whose job
|
|
16
|
+
* ends sooner is taken back sooner (the release each verb returns); none outlives the run. Ending the run fires nothing and
|
|
17
|
+
* answers nothing: the caller-stop gate still answers "did the caller ask this run to stop?".
|
|
18
|
+
*
|
|
19
|
+
* A listener's release is an explicit `removeEventListener`, not the `{ signal }` listener option: the runtime keeps the latest
|
|
20
|
+
* listener hung with that option reachable through its target for as long as the target lives, so on a host's long-lived
|
|
21
|
+
* signal it would keep the last run reachable.
|
|
22
|
+
*/
|
|
23
|
+
export interface RunEnd {
|
|
24
|
+
/**
|
|
25
|
+
* Hear `signal` abort, once, until the run ends. The return takes the listener off sooner (idempotent). Hangs nothing once
|
|
26
|
+
* the run ended. A signal that already fired is the caller's to read: an abort is not replayed to a late listener.
|
|
27
|
+
*/
|
|
28
|
+
listen(signal: AbortSignal, onAbort: () => void): () => void;
|
|
29
|
+
/**
|
|
30
|
+
* Something was handed to a holder that outlives the run: `takeBack` takes it back, once — at the run's end, or sooner through
|
|
31
|
+
* the return (idempotent). Lent after the run ended, it is taken back at once. `takeBack` must not throw; the end runs every
|
|
32
|
+
* take-back before it reports one that did.
|
|
33
|
+
*/
|
|
34
|
+
lend(takeBack: () => void): () => void;
|
|
35
|
+
/** The run ended: every hand-over not yet taken back is taken back; idempotent. Throws, once every take-back ran, when one threw. */
|
|
36
|
+
end(): void;
|
|
37
|
+
}
|
|
38
|
+
/** The stream leg's end of the run: `runEnd` ends once `settled` settles, either way. A take-back that threw (reported by
|
|
39
|
+
* {@link RunEnd.end} once every other one ran) goes to `onError`, not to the process as an unhandled rejection; the run's result
|
|
40
|
+
* stands. `onError` must not throw: the stream leg hands the deployment's error sink, which the Runner guards where it takes it. */
|
|
41
|
+
export declare function endOnSettle(runEnd: RunEnd, settled: Promise<unknown>, onError: (err: unknown) => void): void;
|
|
42
|
+
export declare function mintRunEnd(): RunEnd;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export function endOnSettle(runEnd, settled, onError) {
|
|
2
|
+
const end = () => {
|
|
3
|
+
try {
|
|
4
|
+
runEnd.end();
|
|
5
|
+
}
|
|
6
|
+
catch (err) {
|
|
7
|
+
onError(err);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
void settled.then(end, end);
|
|
11
|
+
}
|
|
12
|
+
export function mintRunEnd() {
|
|
13
|
+
let lent = new Set();
|
|
14
|
+
const lend = (takeBack) => {
|
|
15
|
+
let done = false;
|
|
16
|
+
const release = () => {
|
|
17
|
+
if (done)
|
|
18
|
+
return;
|
|
19
|
+
done = true;
|
|
20
|
+
lent?.delete(release);
|
|
21
|
+
takeBack();
|
|
22
|
+
};
|
|
23
|
+
if (lent === undefined)
|
|
24
|
+
release();
|
|
25
|
+
else
|
|
26
|
+
lent.add(release);
|
|
27
|
+
return release;
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
listen(signal, onAbort) {
|
|
31
|
+
if (lent === undefined)
|
|
32
|
+
return () => undefined;
|
|
33
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
34
|
+
return lend(() => signal.removeEventListener("abort", onAbort));
|
|
35
|
+
},
|
|
36
|
+
lend,
|
|
37
|
+
end() {
|
|
38
|
+
const all = lent;
|
|
39
|
+
lent = undefined;
|
|
40
|
+
const faults = [];
|
|
41
|
+
for (const release of all ?? []) {
|
|
42
|
+
try {
|
|
43
|
+
release();
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
faults.push(e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (faults.length > 0)
|
|
50
|
+
throw faults.length === 1 ? faults[0] : new AggregateError(faults, "RunEnd.end: a take-back threw");
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SessionStore } from "../session.js";
|
|
2
2
|
export { runGuardChain, type GuardChainArgs, type GuardChainOutcome } from "./prepare-context-lane.js";
|
|
3
3
|
import type { LegWrites } from "./session-write-ledger.js";
|
|
4
|
+
import { type RunEnd } from "./end-of-run.js";
|
|
4
5
|
export { gatedCallIdOf, USAGE_WINDOW_REAP_MARGIN_MS } from "./park-commit.js";
|
|
5
6
|
export { batchContextAt } from "./prepare-park-ask.js";
|
|
6
7
|
export { compensateUnparkedPause } from "./prepare-suspend-saga.js";
|
|
@@ -126,7 +127,9 @@ legWrites?: LegWrites,
|
|
|
126
127
|
noticeDestinations?: NoticeDestinationJudge,
|
|
127
128
|
/** `$.prompt.submit`'s binding — the stream that runs this leg filled it with its own steer relay; the leg's facade entry reads
|
|
128
129
|
* it at call time. Absent when prepareTask runs outside a Runner's stream, and then every such call is dropped. */
|
|
129
|
-
promptSubmitRef?: PromptSubmitRef
|
|
130
|
+
promptSubmitRef?: PromptSubmitRef,
|
|
131
|
+
/** The run's end (end-of-run.ts): the caller's signal is listened to through it. Absent outside a Runner's stream. */
|
|
132
|
+
runEnd?: RunEnd): Promise<Prepared>;
|
|
130
133
|
/** The entry IS the contract the notification lane's seat names ({@link PrepareTaskFn}, contracts.ts):
|
|
131
134
|
* a signature change reds HERE, at the declaration, as `false` failing the `true` bound. IDENTITY, not assignability:
|
|
132
135
|
* the parameter tuple (arity, optionality, each type) and the return type must be the SAME type in both directions —
|
|
@@ -59,6 +59,7 @@ import { joinedCrossBoundaryTree, prepareCrossBoundaryLane } from "./cross-bound
|
|
|
59
59
|
import { prepareSafetyScan } from "./prepare-safety-scan.js";
|
|
60
60
|
import { prepareAcquireReconcile } from "./prepare-acquire-reconcile.js";
|
|
61
61
|
import { settleBranchWriteBack } from "./branch-writeback.js";
|
|
62
|
+
import { mintRunEnd } from "./end-of-run.js";
|
|
62
63
|
import { prepareHandsMount, resolveHandsLessReadFace } from "./prepare-hands-readface.js";
|
|
63
64
|
import { createContextRoomSeat } from "./context-room.js";
|
|
64
65
|
import { discloseUnevaluableWindow } from "./clock-and-limits.js";
|
|
@@ -324,7 +325,7 @@ function refuseRegistryScopeMismatch(spec, internals) {
|
|
|
324
325
|
function validateInputFaultNotice(onError, sessionId) {
|
|
325
326
|
return ({ toolName, toolCallId, error }) => onError?.(new Error(`tool input pre-validation (validateInput) threw for ${toolName} (call ${toolCallId}) — read as no verdict; the call proceeded to the gate: ${thrownText(error)}`), { phase: "hook", sessionId });
|
|
326
327
|
}
|
|
327
|
-
export async function prepareTask(request, deps, sessions, resume, internals, runnerSelf, runIdSink, holdSessionLock, legWrites, noticeDestinations, promptSubmitRef) {
|
|
328
|
+
export async function prepareTask(request, deps, sessions, resume, internals, runnerSelf, runIdSink, holdSessionLock, legWrites, noticeDestinations, promptSubmitRef, runEnd) {
|
|
328
329
|
const runId = uuidv7();
|
|
329
330
|
if (runIdSink !== undefined)
|
|
330
331
|
runIdSink.runId = runId;
|
|
@@ -897,8 +898,7 @@ export async function prepareTask(request, deps, sessions, resume, internals, ru
|
|
|
897
898
|
abortController.abort();
|
|
898
899
|
void harness.abort();
|
|
899
900
|
};
|
|
900
|
-
|
|
901
|
-
releaseSignal = () => sig.removeEventListener("abort", onExternalAbort);
|
|
901
|
+
releaseSignal = (runEnd ?? mintRunEnd()).listen(sig, onExternalAbort);
|
|
902
902
|
}
|
|
903
903
|
}
|
|
904
904
|
const approvalWords = approvalWordsSeat(harness, (error) => deps.onError?.(error, { phase: "degraded", sessionId }));
|
|
@@ -906,7 +906,7 @@ export async function prepareTask(request, deps, sessions, resume, internals, ru
|
|
|
906
906
|
const autoStripNotice = createAutoStripNotice({ onNotice: deps.onNotice, legNotice, runId, announced: { announcedListingsRef, frameReceipts } });
|
|
907
907
|
const { basePolicyForResumeEdit, denyNarrowingPolicy, skillGrantLane, allowEntryLanes, policyLayers, effectivePolicy, inheritedUnavailableAsks, deferredAskIdentities, inheritedAskGrants, riskAxesOf, ruleOffersOf, grantBindingOf, permissionRuleLane, permissionRuleGateLane, ruleLaneFacts, permissionRuleOrgLane, storedRuleWholeToolRefusals, sandboxAdmissionArmed, sandboxBoundaryCapable, emitSandboxAdmitted, foldAskClasses, ancestorSandboxAdmissions, ancestorArbitrations, inheritedInstallations } = await preparePolicyChain({ hostFloor: doors.hostFloor, spec, deps, sessionId, runId, hostTaskId, approvalWords, engineText, taskRootFinal, additionalRootsCanonical, writeLocation, executionEnv, lockedPreflight: installedPreflight, pathRuleAnchors: { leg: legAnchors, chainTop }, headLeads, tools, harnessTools, selector: toolFaceSnapshot.selector, toolEffects, egressTools, irreversibilityTier, axisExplicitNegatives, shellGatedTools, toolMarkSources, envHandToolNames, handsCwdRef, readDenyMatcher, personRows, questionToolMounted, runtimeCaps, approvalParkNotResumable, notResumableSays, forcedGateNotResumable, inheritedAncestorRules, ancestorSessionRulesRef, inheritedParentConstraints, seedInheritedGate, skillGrants, skillSpecs, allowedToolTables, frozenOnAsk, hookEnvSource, notifyOwnHookCrash, modBus: legMods.bus, ownModChain, autoModeDecider: () => autoModeDeciderRef.current, whileClassifying: toolOccurrences.whileClassifying, readFace: () => resolvedReadFace, permissionMode, autoStripNotice, toolRosterDeltas: rosterSeat, stopForDenialLimit, askSource, abortController, now, ownSessionRulesRef });
|
|
908
908
|
toolTableViewRef.current = createToolTableView({ policy: effectivePolicy, stored: { wholeToolRefusals: storedRuleWholeToolRefusals }, roster: rosterSeat, fpRef, turnSnapshotRef });
|
|
909
|
-
const { onAsk, preToolContexts, blockedToolCalls, batchHaltRef, blockedTracked, suspendTargetGap, durableSuspendInfraReady, suspendLaneGap, resourceSuspendEligible, usageGovernance, durableApproval, wiringManifest, writeProtection, parkLaneArmed, gateMachineryActive, hookIdentity, hookEnvFace, sessionBoxBound } = prepareWiringManifest({ spec, deps, askSeat: doors.askSeat, hostFloorPosture: doors.hostFloor?.posture, crossBoundaryStationEngaged: crossBoundary.stationEngaged, internals, resume, sessionId, runId, hostTaskId, taskScope, modBus: legMods.bus, standingModBus: legMods.standing, policyLayers, effectivePolicy, handsEnabled, taskRootFinal, legWriteGuard: advertisedWritableDirs?.planFile !== undefined ? { ...legWriteGuard, exemptFiles: [advertisedWritableDirs.planFile] } : legWriteGuard, mcp, irreversibleTools, egressTools, shellReadStationArmed: handsReadFace.shellReadStationArmed, toolEffects, ownedEnv, executionEnv, offloadStore, onceLedger, usageWindows, envLifetimeSuspendAt, runtimeCaps, resolvedInteractionPosture, durableQuestionFace, liveQuestionFace, checkpointStore, sessions, modelGateManifest, autoModeArmReason, permissionMode, lockedPreflight, peerLaneRefs, frameSettlement, receiveSeat, harness, pausedRef, liveInheritedGate, delegation, approvalParkNotResumable, forcedGateNotResumable, toolRoster, toolPlan, readDenyBuiltinTiersActive: handsReadFace.readDenyBuiltinTiersActive, lspManagerWired, lspDiagnosticsLive: lspDiagnostics !== undefined, fileHistoryFact, projectMemoryFact, sessionRulesChildrenReadLive: ownSessionRulesRef.current !== undefined, sessionBox, sessionAddress, checkpointScope, memoryPollution: () => memoryEngineSession?.pollution, advisorFact: advisor.manifest, runOrigin: doors.runOrigin, commandSandboxFact: commandSandboxRun.state === "unavailable" ? { state: "unavailable", reason: commandSandboxRun.reason } : { state: commandSandboxRun.state } });
|
|
909
|
+
const { onAsk, preToolContexts, blockedToolCalls, batchHaltRef, blockedTracked, suspendTargetGap, durableSuspendInfraReady, suspendLaneGap, resourceSuspendEligible, usageGovernance, durableApproval, wiringManifest, writeProtection, parkLaneArmed, gateMachineryActive, hookIdentity, hookEnvFace, sessionBoxBound } = prepareWiringManifest({ spec, deps, askSeat: doors.askSeat, hostFloorPosture: doors.hostFloor?.posture, crossBoundaryStationEngaged: crossBoundary.stationEngaged, internals, resume, sessionId, runId, hostTaskId, taskScope, modBus: legMods.bus, standingModBus: legMods.standing, policyLayers, effectivePolicy, handsEnabled, taskRootFinal, legWriteGuard: advertisedWritableDirs?.planFile !== undefined ? { ...legWriteGuard, exemptFiles: [advertisedWritableDirs.planFile] } : legWriteGuard, mcp, irreversibleTools, egressTools, shellReadStationArmed: handsReadFace.shellReadStationArmed, toolEffects, ownedEnv, executionEnv, offloadStore, onceLedger, usageWindows, envLifetimeSuspendAt, runtimeCaps, resolvedInteractionPosture, durableQuestionFace, liveQuestionFace, checkpointStore, sessions, modelGateManifest, autoModeArmReason, permissionMode, lockedPreflight, peerLaneRefs, frameSettlement, receiveSeat, harness, pausedRef, liveInheritedGate, delegation, approvalParkNotResumable, forcedGateNotResumable, toolRoster, toolPlan, readDenyBuiltinTiersActive: handsReadFace.readDenyBuiltinTiersActive, lspManagerWired, lspDiagnosticsLive: lspDiagnostics !== undefined, fileHistoryFact, projectMemoryFact, sessionRulesChildrenReadLive: ownSessionRulesRef.current !== undefined, sessionBox, sessionAddress, runEnd, checkpointScope, memoryPollution: () => memoryEngineSession?.pollution, advisorFact: advisor.manifest, runOrigin: doors.runOrigin, commandSandboxFact: commandSandboxRun.state === "unavailable" ? { state: "unavailable", reason: commandSandboxRun.reason } : { state: commandSandboxRun.state } });
|
|
910
910
|
refuseDisplayWithoutSentences(legMods.bus, legEventsOf(hookIdentity));
|
|
911
911
|
agentStationsRef.current = createAgentStations({ bus: legMods.bus, identity: hookIdentity, permissionMode: () => permissionMode.observed });
|
|
912
912
|
sendStationRef.current = createSessionSendStation({ bus: legMods.bus, identity: hookIdentity });
|
|
@@ -170,6 +170,7 @@ export interface PrepareWiringManifestInput {
|
|
|
170
170
|
sessionBox: SessionBoxBinding | undefined;
|
|
171
171
|
/** borrowed-readonly — the leg's own session address (`sessionAddressOf`): the box is drained for it. */
|
|
172
172
|
sessionAddress: SessionAddress;
|
|
173
|
+
/** borrowed-mutable — the run's end: the drain hands what it binds the session's process-level seats through it (absent outside a stream). */ runEnd?: import("./end-of-run.js").RunEnd | undefined;
|
|
173
174
|
/** borrowed-readonly, read late — the memory session's one-way pollution face (absent with no memory session). The drain marks
|
|
174
175
|
* it when it INJECTS a letter from another principal (the injection path; the tool path is accounted by `ReadInbox`'s class). */
|
|
175
176
|
memoryPollution?: () => Pick<NonNullable<Prepared["memoryEngineSession"]>["pollution"], "markPolluted"> | undefined;
|
|
@@ -158,7 +158,7 @@ export function durableSuspendInfraGaps(facts) {
|
|
|
158
158
|
return gaps;
|
|
159
159
|
}
|
|
160
160
|
export function prepareWiringManifest(input) {
|
|
161
|
-
const { spec, deps, internals, resume, sessionId, runId, hostTaskId, taskScope, modBus, standingModBus, checkpointScope, policyLayers, effectivePolicy, handsEnabled, taskRootFinal, legWriteGuard, mcp, irreversibleTools, egressTools, toolEffects, ownedEnv, executionEnv, offloadStore, onceLedger, usageWindows, envLifetimeSuspendAt, runtimeCaps, resolvedInteractionPosture, durableQuestionFace, liveQuestionFace, checkpointStore, sessions, modelGateManifest, autoModeArmReason, permissionMode, lockedPreflight, peerLaneRefs, frameSettlement, receiveSeat, sessionBox, sessionAddress, harness, pausedRef, askSeat, liveInheritedGate, delegation, approvalParkNotResumable, forcedGateNotResumable, toolRoster, toolPlan, readDenyBuiltinTiersActive, lspManagerWired, shellReadStationArmed, crossBoundaryStationEngaged, lspDiagnosticsLive, fileHistoryFact, projectMemoryFact, sessionRulesChildrenReadLive, memoryPollution, advisorFact, hostFloorPosture, runOrigin, commandSandboxFact } = input;
|
|
161
|
+
const { spec, deps, internals, resume, sessionId, runId, hostTaskId, taskScope, modBus, standingModBus, checkpointScope, policyLayers, effectivePolicy, handsEnabled, taskRootFinal, legWriteGuard, mcp, irreversibleTools, egressTools, toolEffects, ownedEnv, executionEnv, offloadStore, onceLedger, usageWindows, envLifetimeSuspendAt, runtimeCaps, resolvedInteractionPosture, durableQuestionFace, liveQuestionFace, checkpointStore, sessions, modelGateManifest, autoModeArmReason, permissionMode, lockedPreflight, peerLaneRefs, frameSettlement, receiveSeat, sessionBox, sessionAddress, runEnd, harness, pausedRef, askSeat, liveInheritedGate, delegation, approvalParkNotResumable, forcedGateNotResumable, toolRoster, toolPlan, readDenyBuiltinTiersActive, lspManagerWired, shellReadStationArmed, crossBoundaryStationEngaged, lspDiagnosticsLive, fileHistoryFact, projectMemoryFact, sessionRulesChildrenReadLive, memoryPollution, advisorFact, hostFloorPosture, runOrigin, commandSandboxFact } = input;
|
|
162
162
|
const onAsk = askSeat.value;
|
|
163
163
|
const handWriteTools = toolRoster.entries.filter((e) => e.mountedBy === "hands" && (e.effect === "write" || e.effect === "idempotent")).map((e) => e.name);
|
|
164
164
|
const hasEffectAwareGate = policyLayers.length > 0 || chainJudges(standingModBus);
|
|
@@ -286,7 +286,7 @@ export function prepareWiringManifest(input) {
|
|
|
286
286
|
deps, lanes: drainLanes, assistantSeat: internals.principalInboxAssistant,
|
|
287
287
|
address: sessionAddress,
|
|
288
288
|
sessions,
|
|
289
|
-
runId,
|
|
289
|
+
runId, ...(runEnd !== undefined ? { runEnd } : {}),
|
|
290
290
|
scope: taskScope,
|
|
291
291
|
inject: internals.onTaskNotification,
|
|
292
292
|
ownTokens: () => internals?.peerSelfRef?.current.ownTokens ?? [],
|
|
@@ -22,6 +22,8 @@ export interface RunNotificationLaneInput<R> {
|
|
|
22
22
|
holdSessionLock: ((sessionId: string) => Promise<void>) | undefined;
|
|
23
23
|
/** borrowed-mutable (the Runner's) — this leg's view of the session write ledger, handed to prepare; the stream layer closes it at the leg's end. */
|
|
24
24
|
legWrites: import("./session-write-ledger.js").LegWrites;
|
|
25
|
+
/** borrowed-readonly — the run's end (end-of-run.ts), handed to prepare: the caller's signal is listened to through it. */
|
|
26
|
+
runEnd: import("./end-of-run.js").RunEnd;
|
|
25
27
|
/** borrowed-readonly — `$.prompt.submit`'s binding the stream layer filled with its own relay, handed to prepare (whose facade reads
|
|
26
28
|
* it at call time); absent outside a Runner's stream. */
|
|
27
29
|
promptSubmitRef: import("../input-author.js").PromptSubmitRef | undefined;
|
|
@@ -14,7 +14,7 @@ export function runNotificationLane(input) {
|
|
|
14
14
|
return obligations.run(() => runNotificationLaneAs(input, obligations));
|
|
15
15
|
}
|
|
16
16
|
async function runNotificationLaneAs(input, obligations) {
|
|
17
|
-
const { spec, queue, resume, internals, taskIdRef, holdSessionLock, legWrites, promptSubmitRef, runner, self, sessions, sessionReadStates, sessionModeSeats, sessionMcpPools, pendingSessionNotifications, prepareTask, next } = input;
|
|
17
|
+
const { spec, queue, resume, internals, taskIdRef, holdSessionLock, legWrites, runEnd, promptSubmitRef, runner, self, sessions, sessionReadStates, sessionModeSeats, sessionMcpPools, pendingSessionNotifications, prepareTask, next } = input;
|
|
18
18
|
const prepareResume = resume
|
|
19
19
|
? {
|
|
20
20
|
leafId: resume.cp.leafId,
|
|
@@ -151,7 +151,7 @@ async function runNotificationLaneAs(input, obligations) {
|
|
|
151
151
|
sessionReadStates,
|
|
152
152
|
sessionModeSeats, sessionMcpPools,
|
|
153
153
|
onTaskNotification: laneSink,
|
|
154
|
-
}, self, taskIdRef, holdSessionLock, legWrites, (destination, delivery) => pendingSessionNotifications.discardsStaleNotice(destination, delivery), promptSubmitRef);
|
|
154
|
+
}, self, taskIdRef, holdSessionLock, legWrites, (destination, delivery) => pendingSessionNotifications.discardsStaleNotice(destination, delivery), promptSubmitRef, runEnd);
|
|
155
155
|
try {
|
|
156
156
|
pendingSessionNotifications.admit(sessionAddressOf(prepared), prepared.sessionBox);
|
|
157
157
|
const settling = pendingSessionNotifications.settleBoxDebts(sessionAddressOf(prepared), prepared.abortController.signal);
|
|
@@ -35,6 +35,7 @@ import { ToolDetachHub } from "../tool-detach.js";
|
|
|
35
35
|
import { assertContextSettingsValue, assertContextSettingsWords, contextOverlayFor } from "../context-settings.js";
|
|
36
36
|
import { createRunState } from "./initial-run-state.js";
|
|
37
37
|
import { SessionWriteLedger } from "./session-write-ledger.js";
|
|
38
|
+
import { endOnSettle, mintRunEnd } from "./end-of-run.js";
|
|
38
39
|
import { teardownLegBudget } from "./teardown-bounded.js";
|
|
39
40
|
import { emitSettled, reconciledEnd } from "./tool-end-body.js";
|
|
40
41
|
import { answerFaceForRedeemedCall } from "./decide-continuation.js";
|
|
@@ -325,6 +326,7 @@ export class Runner {
|
|
|
325
326
|
};
|
|
326
327
|
const namedSessionId = spec.sessionId;
|
|
327
328
|
const legWrites = this.sessionWrites.openLeg((err, sessionId) => this.deps.onError?.(err, { phase: "degraded", sessionId }));
|
|
329
|
+
const runEnd = mintRunEnd();
|
|
328
330
|
const receivedPeers = receivePeerDeclarations(spec, this.deps);
|
|
329
331
|
const declarationHold = this.holdDeclarations(receivedDeclarations(receivedPeers), namedSessionId);
|
|
330
332
|
const run = (async () => {
|
|
@@ -338,6 +340,7 @@ export class Runner {
|
|
|
338
340
|
queue,
|
|
339
341
|
holdSessionLock: namedSessionId ? undefined : holdSessionLock,
|
|
340
342
|
legWrites,
|
|
343
|
+
runEnd,
|
|
341
344
|
setResult: (r) => {
|
|
342
345
|
resultValue = r;
|
|
343
346
|
const pcs = internals?.inheritedGate?.parentConstraints;
|
|
@@ -405,6 +408,7 @@ export class Runner {
|
|
|
405
408
|
}).onRunRejected);
|
|
406
409
|
void settled.then(() => acceptedSteerInputs.clear(), () => acceptedSteerInputs.clear());
|
|
407
410
|
void settled.then(() => declarationHold.release(), () => declarationHold.release());
|
|
411
|
+
endOnSettle(runEnd, settled, (err) => this.deps.onError?.(err, { phase: "degraded", sessionId: taskIdRef.sessionId ?? "(pre-session)", classification: "run-end-take-back" }));
|
|
408
412
|
const { reapSuspended } = streamReap({
|
|
409
413
|
live, runner: this.depsSeat,
|
|
410
414
|
locallyClaimedTokens: this.locallyClaimedTokens, parentConstraintRegistry: this.parentConstraintRegistry, suspendedEnvReaps: this.suspendedEnvReaps,
|
|
@@ -440,9 +444,9 @@ export class Runner {
|
|
|
440
444
|
return stream;
|
|
441
445
|
}
|
|
442
446
|
runLocked(input) {
|
|
443
|
-
const { spec, queue, setResult, onSuggestions, onReady, onSuspend, manualCompactRef, taskIdRef, holdSessionLock, legWrites, resume, internals, notifyRef, promptSubmitRef, captureOptOutRef, mcpRedialRef, entryActor, entryTracer } = input;
|
|
447
|
+
const { spec, queue, setResult, onSuggestions, onReady, onSuspend, manualCompactRef, taskIdRef, holdSessionLock, legWrites, runEnd, resume, internals, notifyRef, promptSubmitRef, captureOptOutRef, mcpRedialRef, entryActor, entryTracer } = input;
|
|
444
448
|
return runNotificationLane({
|
|
445
|
-
spec, queue, resume, internals, taskIdRef, holdSessionLock, legWrites, promptSubmitRef,
|
|
449
|
+
spec, queue, resume, internals, taskIdRef, holdSessionLock, legWrites, runEnd, promptSubmitRef,
|
|
446
450
|
runner: this.depsSeat, self: this, sessions: this.sessions, sessionReadStates: this.sessionReadStates, sessionModeSeats: this.sessionModeSeats, sessionMcpPools: this.sessionMcpPools, pendingSessionNotifications: this.pendingSessionNotifications,
|
|
447
451
|
prepareTask,
|
|
448
452
|
next: ({ prepared, injectTaskNotification, deliveredAtTurnOpen, peerInboundChainRef, modelCatalog, notificationLane, unsubscribeTaskNotifications, deliveryObligations }) => {
|
|
@@ -467,6 +471,7 @@ export class Runner {
|
|
|
467
471
|
reserve: () => queue.reserve(),
|
|
468
472
|
ident,
|
|
469
473
|
signal: loopLatch.callerStop.signal,
|
|
474
|
+
runEnd,
|
|
470
475
|
onNotice: this.deps.onNotice,
|
|
471
476
|
sessionId: prepared.sessionId,
|
|
472
477
|
});
|
package/dist/core/task-spec.d.ts
CHANGED
|
@@ -1795,6 +1795,8 @@ export interface TaskSpec {
|
|
|
1795
1795
|
* External cancellation. When it aborts, the task aborts (the brain request is cancelled and any
|
|
1796
1796
|
* pending tool-policy gate releases). Pass a parent tool's `ToolExecuteContext.signal` here so a
|
|
1797
1797
|
* nested `runTask` stops the instant the parent does instead of running to its own `limits.maxWalltimeMs`.
|
|
1798
|
+
* The run holds nothing on it once it has ended: the host need not abort it after the run, and may keep one
|
|
1799
|
+
* signal for many runs.
|
|
1798
1800
|
*/
|
|
1799
1801
|
signal?: AbortSignal;
|
|
1800
1802
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -186,7 +186,7 @@ export type { FileHistoryStore, FileHistoryResult, FileHistoryTrackResult, FileH
|
|
|
186
186
|
export type { InMemoryFileHistoryStoreOptions } from "./core/file-history-store.js";
|
|
187
187
|
export { DEFAULT_FILE_HISTORY_BOUNDARY_KEEP, resolveFileHistoryRetention, fileHistoryBoundariesToKeep } from "./core/file-history-retention.js";
|
|
188
188
|
export type { FileHistoryRetentionPolicy } from "./core/file-history-retention.js";
|
|
189
|
-
export { FileStorageBackend, FileSessionRepo, FileCheckpointStore, CHECKPOINT_LEDGER_EVENT_KINDS, readCheckpointLedger, FileToolResultStore, FileSessionPolicyStore, FileFileHistoryStore, FileWorkflowJournalStore, MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult, resolveDataRoot, sanitizeScope, sanitizePathComponent, atomicWriteFile, writeThenLink, ensureDir, readJsonlRecords, AppendLog, FileStoreLockError, type FileStoreLockErrorCode, processFingerprint, isProcessLive, type ProcessFingerprint, type FileStorageBackendOptions, type FileStorageCorruptReadInfo, type FileFileHistoryStoreOptions, type FileSessionRepoOptions, type FileCheckpointStoreOptions, type CheckpointLedgerEventKind, type CheckpointLedgerReading, type ReadCheckpointLedgerOptions, } from "./stores/file/index.js";
|
|
189
|
+
export { FileStorageBackend, FileSessionRepo, FileCheckpointStore, CHECKPOINT_LEDGER_EVENT_KINDS, readCheckpointLedger, FileToolResultStore, FileSessionPolicyStore, FileFileHistoryStore, FileWorkflowJournalStore, MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult, resolveDataRoot, sanitizeScope, sanitizePathComponent, atomicWriteFile, writeThenLink, ensureDir, readJsonlRecords, AppendLog, FileStoreLockError, type FileStoreLockErrorCode, processFingerprint, isProcessLive, type ProcessFingerprint, declareDataRoot, type DataRootDeclaration, type FileStorageBackendOptions, type FileStorageCorruptReadInfo, type FileFileHistoryStoreOptions, type FileSessionRepoOptions, type FileCheckpointStoreOptions, type CheckpointLedgerEventKind, type CheckpointLedgerReading, type ReadCheckpointLedgerOptions, } from "./stores/file/index.js";
|
|
190
190
|
export { CacheBreakDetector, type CacheBreakFinding, type ToolFingerprintInput } from "./core/cache-break-detector.js";
|
|
191
191
|
export { maybeCompact, type MaybeCompactOptions, type CompactionPassStart, type CompactionWindowSafetyInfo, type CompactionRestoreAsk } from "./core/auto-compaction.js";
|
|
192
192
|
export type { MintedAttachmentFrame } from "./core/user-attachment.js";
|
package/dist/index.js
CHANGED
|
@@ -147,7 +147,7 @@ export { describeTrackKey as fileHistoryDescribeTrackKey, fileHistoryExportDiges
|
|
|
147
147
|
export { resolveTrackedFile as fileHistoryResolveTrackedFile, placeProvenDifferent as fileHistoryPlaceProvenDifferent, trackKeyForEdit as fileHistoryTrackKeyForEdit, trackKeyForAnnul as fileHistoryTrackKeyForAnnul, fileHistoryEntryTravels, fileHistoryParentIdentTravels } from "./core/file-history-store.js";
|
|
148
148
|
export { fileHistoryBlobExchangeOf } from "./core/file-history-store.js";
|
|
149
149
|
export { DEFAULT_FILE_HISTORY_BOUNDARY_KEEP, resolveFileHistoryRetention, fileHistoryBoundariesToKeep } from "./core/file-history-retention.js";
|
|
150
|
-
export { FileStorageBackend, FileSessionRepo, FileCheckpointStore, CHECKPOINT_LEDGER_EVENT_KINDS, readCheckpointLedger, FileToolResultStore, FileSessionPolicyStore, FileFileHistoryStore, FileWorkflowJournalStore, MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult, resolveDataRoot, sanitizeScope, sanitizePathComponent, atomicWriteFile, writeThenLink, ensureDir, readJsonlRecords, AppendLog, FileStoreLockError, processFingerprint, isProcessLive, } from "./stores/file/index.js";
|
|
150
|
+
export { FileStorageBackend, FileSessionRepo, FileCheckpointStore, CHECKPOINT_LEDGER_EVENT_KINDS, readCheckpointLedger, FileToolResultStore, FileSessionPolicyStore, FileFileHistoryStore, FileWorkflowJournalStore, MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult, resolveDataRoot, sanitizeScope, sanitizePathComponent, atomicWriteFile, writeThenLink, ensureDir, readJsonlRecords, AppendLog, FileStoreLockError, processFingerprint, isProcessLive, declareDataRoot, } from "./stores/file/index.js";
|
|
151
151
|
export { CacheBreakDetector } from "./core/cache-break-detector.js";
|
|
152
152
|
export { maybeCompact } from "./core/auto-compaction.js";
|
|
153
153
|
export { brainToRuntime } from "./core/runtime.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a host states about a file data root — facts about the DEPLOYMENT the engine cannot observe from inside one process.
|
|
3
|
+
*
|
|
4
|
+
* `singleProcessTable: true` states: every process that opens this data root runs in this one process table — no other
|
|
5
|
+
* container and no other host mounts it (a self-launched, single-user process over a local disk). The directory locks under
|
|
6
|
+
* the root then read a lock record that names no pid namespace (one written by an engine before the namespace was recorded)
|
|
7
|
+
* as written in this table, and judge it by its pid and start times like any lock written here. Without the declaration such
|
|
8
|
+
* a record is not comparable on a host that names its pid namespace (Linux), because a restarted container keeps its host
|
|
9
|
+
* name while its pids live in another table, and it is refused until removed by hand.
|
|
10
|
+
*
|
|
11
|
+
* It is NOT true — and must not be declared — where two containers, pods or hosts can have the root mounted at once: several
|
|
12
|
+
* replicas over one volume, or a rolling upgrade during which two generations of a pod both run.
|
|
13
|
+
*/
|
|
14
|
+
export interface DataRootDeclaration {
|
|
15
|
+
/** Every process that opens the data root runs in this one process table. Only the literal `true`. */
|
|
16
|
+
readonly singleProcessTable: true;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Declare a fact about a file data root ({@link DataRootDeclaration}). Call it before the first store over the root is
|
|
20
|
+
* opened; a lock judged before the call was judged without it. Declaring a root twice is declaring it once, and the
|
|
21
|
+
* declaration lasts for the process.
|
|
22
|
+
*
|
|
23
|
+
* The root is resolved exactly as `FileStorageBackend` resolves its own ({@link resolveDataRoot}: NFC-normalized, created
|
|
24
|
+
* if absent, then its physical path), so the declaration names the directory the stores open — and every directory lock at
|
|
25
|
+
* or under it, whichever store or door takes it, reads the declaration.
|
|
26
|
+
*
|
|
27
|
+
* Refused `config.invalid_argument`: a root that is not a non-empty string, a declaration that is not a plain record, a member
|
|
28
|
+
* the declaration does not take, and a `singleProcessTable` that is anything but the literal `true` (`"true"`, `1`, `false`
|
|
29
|
+
* included — a deployment for which the fact does not hold makes no declaration; a member only a prototype supplies is no
|
|
30
|
+
* member). A refused call declares nothing.
|
|
31
|
+
*/
|
|
32
|
+
export declare function declareDataRoot(root: string, declaration: DataRootDeclaration): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { holdSingleProcessTableRoot, resolveDataRoot } from "./fs-atomic.js";
|
|
2
|
+
import { optionKeys, receiptRefusal, receiveMembers } from "../../core/own-property-receipt.js";
|
|
3
|
+
import { describeRejectedValue } from "../../core/tool-search-setting.js";
|
|
4
|
+
const DATA_ROOT_DECLARATION_KEYS = optionKeys()({ singleProcessTable: 0 });
|
|
5
|
+
export function declareDataRoot(root, declaration) {
|
|
6
|
+
if (typeof root !== "string" || root === "") {
|
|
7
|
+
throw receiptRefusal(`declareDataRoot: the data root must be a non-empty path (got ${describeRejectedValue(root)})`);
|
|
8
|
+
}
|
|
9
|
+
if (typeof declaration !== "object" || declaration === null) {
|
|
10
|
+
throw receiptRefusal(`declareDataRoot: the declaration must be a record, { singleProcessTable: true } (got ${describeRejectedValue(declaration)})`);
|
|
11
|
+
}
|
|
12
|
+
const read = receiveMembers(declaration, { subject: "declareDataRoot declaration", unit: "member", moment: "at declareDataRoot" }, DATA_ROOT_DECLARATION_KEYS);
|
|
13
|
+
const value = Object.hasOwn(read, "singleProcessTable") ? read.singleProcessTable : undefined;
|
|
14
|
+
if (value !== true) {
|
|
15
|
+
throw receiptRefusal(`declareDataRoot: singleProcessTable must be the literal true (got ${describeRejectedValue(value)}) — it states that every process ` +
|
|
16
|
+
`opening this data root runs in this one process table; where that does not hold, declare nothing`);
|
|
17
|
+
}
|
|
18
|
+
holdSingleProcessTableRoot(resolveDataRoot(root));
|
|
19
|
+
}
|