@nylorun/harness 0.25.0-beta → 0.26.0-beta
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 +105 -0
- package/HOST_CONTRACT.md +13 -12
- package/README.md +2 -2
- package/dist/api/executors.d.ts +18 -4
- package/dist/api/harness.js +2 -2
- package/dist/api/host.d.ts +4 -0
- package/dist/api/host.js +62 -24
- package/dist/api/index.d.ts +1 -1
- package/dist/api/run.js +9 -0
- package/dist/run/durable.d.ts +1 -3
- package/dist/run/durable.js +6 -14
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,110 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.26.0-beta
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- e917bd6: **Bring your own harness: harness ids, harness-owned state, and who wrote each event (R4.1, R4.2, R4.4, R4.9).**
|
|
8
|
+
|
|
9
|
+
- **Harness ids and routing.** An Environment's `harness` takes any harness id (`^[a-z][a-z0-9-]{1,62}$`). It is no longer only `nylorun`.
|
|
10
|
+
- **The pin.** A session pins its harness when it opens: its Environment's harness, else `nylorun`. A flow always runs `nylorun`. `GET /v1/sessions/{id}` returns the pin as `harness`.
|
|
11
|
+
- **Routing.** Only a connection whose `hello.name` is that id takes the session's runs.
|
|
12
|
+
- **Our harness's name.** It now says `nylorun` in `hello`. A harness that says `@nylorun/harness` is refused with a message naming the new id, so an older harness image needs this Runtime's.
|
|
13
|
+
- **Placement.** It is keyed by the real harness id, and `"*": {hosts: []}` refuses any harness the map does not name.
|
|
14
|
+
- **Drift.** A turn on an Environment that now runs another harness is `409 harness_mismatch`; open a new session. For a pod Environment, a changed `harness` applies at the pod's next wake, like its image.
|
|
15
|
+
- **Per-harness tokens.** `nylorun-operate harness token put <id>` makes a custom harness container's own Harness API credential, bound to its id; `list` and `rm` manage them. `NYLORUN_HARNESS_TOKEN` stays ours, bound to `nylorun`.
|
|
16
|
+
- **A custom harness as a pod's image.** A pod Environment whose harness is not ours runs its `image` as the harness: the image's own entrypoint (`entrypoint: "image"` to the sandboxes service), with nothing copied in. It needs `image`.
|
|
17
|
+
- **Harness-owned state.** Core stores a harness's turn state as sent and never reads it. Our engine now aligns its state with the turn's manifest itself.
|
|
18
|
+
- **Limits for a custom harness.** Its state is at most 256 KiB, or its turn fails. It cannot pause for approvals in Harness API 2.
|
|
19
|
+
- **Native tools.** It may declare the tools it runs itself in `hello` (`capabilities.tools`). Their calls (capability `harness`) are journaled like built-ins, and the log records a real `tool.completed` instead of `tool.unavailable`.
|
|
20
|
+
- **Who wrote each event.** The writer sets an event's `source` and `evidence`; the event's type no longer decides them. Events written before this release still say `loop` or `api`.
|
|
21
|
+
- **`client`**: a command, with a new `principal` taken from its credential.
|
|
22
|
+
- **`harness`**: what a harness reported, with its harness id and `runId`. Evidence `claimed`.
|
|
23
|
+
- **`core`**: core's own logic. Evidence `observed`.
|
|
24
|
+
- **`effectId` on model calls.** `GET /v1/sessions/{id}/calls/model` returns each call's `effectId`, so a metered call joins the effect journal.
|
|
25
|
+
- **The published contract grows.** It adds `HarnessCheckpointSchema` (the checkpoint fields a harness reads), `NativeToolSchema`, the harness id helpers, `HARNESS_TOOLS_CAPABILITY`, `MAX_HARNESS_STATE_BYTES`, and the gate error codes `key_required` and `effect_not_journaled`. It also documents the effect context keys, the model request hash rule and how a turn's status maps to its output method.
|
|
26
|
+
|
|
27
|
+
- 35e29b7: **Environments replace sandboxes and vaults (protocol 11). This is a fresh start: upgrading deletes your sandboxes, their disks and every vault except the model's, and closes every open session (its history stays readable).** List what you have before upgrading; see "Environments replace sandboxes and vaults" in MIGRATION.md.
|
|
28
|
+
|
|
29
|
+
An Environment is where sessions run: one sandbox (kind `virtual`, `pod` or `none`) with a recipe that can change, and one vault of secrets for its shell, MCP servers and HTTP tools. The app decides who uses which Environment; the Runtime keeps it by id and holds its lifecycle.
|
|
30
|
+
|
|
31
|
+
- `@nylorun/core`: protocol 11 (the Host accepts 11 only; older clients get `426`), required feature `environments`. `PutEnvironmentRequestSchema`, `EnvironmentViewSchema` (`recipe`, `version`, `appliedVersion`, `ownerUserId`, `lastUsedAt`), `PutEnvironmentSecretRequestSchema`, `EnvironmentSecretViewSchema`, `ENVIRONMENT_EVENT_TYPES`, `TenantEnvironmentsConfigSchema`, `environmentGranted`. `PutSessionRequest.environment` replaces `sandbox`, `vaultIds` and `credentialSelections`; `SessionView.environment` replaces the session's sandbox and vault fields. Error codes `environment_busy`, `environment_unavailable`, `environment_lost`, `environment_not_granted`, `environment_owner_mismatch` and `session_closed` (the `sandbox_*` codes and `sandbox_expired` are gone); session events `environment.state`, `environment.exec` and `environment.attached`; scope `environments:write`. Credential coverage takes `environmentId` and answers `covered` or `missing`; the MCP preview takes `environmentId`. The vault Management schemas are removed.
|
|
32
|
+
- `@nylorun/runtime`: `/v1/environments/{id}` replaces `/v1/sandboxes/{id}`: `PUT` creates, finds or changes one (`kind` and `storage` fixed; a recipe change bumps `version`; a pod gets a new image or resources at its next start from stopped, a new allowlist within seconds), with list by label, events (`nylorun.environment-event/1`), stop, reset and delete. Each Environment owns one vault: `PUT|GET|DELETE /v1/environments/{id}/secrets/{name}` on the Runtime API, write-only, with a second credential for a host or URL refused at the write (`409 credential_conflict`). An optional owner guard (`ownerUserId`) is checked when a session opens and at every turn start. `lifecycle.deleteAfter` deletes an Environment unused that long; TTL and `onExpiry` are gone. Kind `none` holds secrets for MCP-only agents. `/v1/tenant/vaults`, user and installation vaults, the Tenant's default sandbox, inline sandboxes and `{ session }` sharing are removed. The Tenant setting is `environments.config` (`limits.environments`). Identity files grant `environments:` (an old `sandboxes:` key, or `sandboxes:write`, stops the Runtime with a message naming the new key). Migration `0020_environments`.
|
|
33
|
+
- `@nylorun/harness`: the Harness API claims `environment.state` and `environment.exec`, and its workspace fields name `environmentId`.
|
|
34
|
+
- `@nylorun/agents`: `client.environments` (`put`, `get`, `list`, `page`, `stop`, `reset`, `delete`, `events`, `secrets.put|list|get|delete`, `forSession`) replaces `client.sandboxes`; `createSession({ environment })`; `sessions.page({ environmentId })` filters by Environment. The AG-UI handler's session options take `environment`.
|
|
35
|
+
- `@nylorun/admin`: `admin.coverage({ agentId, environmentId })` replaces `admin.vaults`; `admin.mcp.preview({ url, environmentId })`.
|
|
36
|
+
- `@nylorun/studio`: Environments replace Sandboxes, with a create form, stop, reset, delete and their secrets; the Credentials forms write an Environment's secrets; New session picks an Environment and shows its coverage.
|
|
37
|
+
- `nylorun`: `nylorun sandbox ls|rm` list and delete Environments; `nylorun mcp inspect --environment <id>` replaces `--vault`; `nylo reset --environments` replaces `--sandboxes`; `nylo doctor sandbox` reports the Environment limits.
|
|
38
|
+
|
|
39
|
+
- 3013501: **Tool calls are delivered at least once, and every one is on the record (R5 step 1).** A gateway restart used to park the sessions it interrupted as `uncertain` until someone cancelled them, a harness could call tools with no record, and nothing listed a session's tool calls. Now every tool call ends in the log with its outcome, a crash sends it again with the same key, and the gateway runs only calls the effect journal recorded.
|
|
40
|
+
|
|
41
|
+
- **Every outcome in the log.** Each tool call ends in one `tool.completed` with `status` (`completed`: the tool answered; `failed`: the Runtime ended it, `tool.disabled`, `tool.unavailable` or `tool.interrupted`; `cancelled`), `kind` (`mcp`, `http`, `sandbox`, `platform`), `server`, `attempts` and `durationMs`. Refused and cancelled calls are in the log for the first time.
|
|
42
|
+
- **`GET /v1/sessions/{id}/calls/tool`** pages a session's tool calls from the effect journal, in the order they were first sent: tool, input, status, sends, error and timing. Same credentials and paging as `/calls/model`; `@nylorun/agents` adds `session.toolCalls()`. Host feature `tool-calls`.
|
|
43
|
+
- **At least once, with the same key.** An MCP or HTTP tool call that a crash, a shutdown or a lost gateway hop interrupted is sent again with its effect id as the key, up to 3 sends; then it fails to the model as `tool.interrupted` ("may have run") and the session continues. A gateway that restarts mid call runs the call again under its key instead of answering `uncertain`. HTTP tools get the key as `Idempotency-Key`, as before; MCP servers now get it in `_meta["nylorun/idempotency-key"]` on `tools/call`. A tool that honors the key acts once; `attempts` above 1 marks where one may have acted twice.
|
|
44
|
+
- **Sandbox commands are never run twice.** A sandbox or core-served call a crash interrupted has no key to dedupe on, so it fails to the model as `tool.interrupted` at once, and the model decides whether to run it again.
|
|
45
|
+
- **No tool call parks a session.** The `uncertain` state for tool calls, its cancel-only exit and R2b's read-only/idempotent `mcp.lost` exception are gone: a lost MCP answer is `mcp.lost` to the model for every tool. Model calls keep their own rules.
|
|
46
|
+
- **The gateway runs only journaled calls.** Under a run token, `/nylorun/v1/tool-calls` and `/nylorun/v1/http-calls` need the call's effect id as `Idempotency-Key` (`400 key_required`), and the effect journal must hold it running, for the run's turn, the same tool and the same input (`409 effect_not_journaled`). A harness that skips the journal gets nothing run.
|
|
47
|
+
- `@nylorun/harness`: `HarnessExecutors.resends(effect, error, run)` says a gate hop lost a call's answer; the harness then asks core again with the same intent and sends the call again.
|
|
48
|
+
- **Approval** stays in the manifest and our harness still asks for it. Only the Runtime's own harness asks: one built from the Harness API can skip it until tool policy moves to the gateway (R5 step 2).
|
|
49
|
+
|
|
50
|
+
- 6061a3a: **Tool approvals are the Tenant's tool policy (R5 step 2).** An agent's manifest used to say which tool calls wait for a person, and only the Runtime's own harness asked; a harness built from the Harness API could skip it. Now the operator sets one tool policy for every agent and every harness, and the Runtime enforces it before anything is sent.
|
|
51
|
+
|
|
52
|
+
- **`GET`/`PUT /v1/tenant/tool-policy`** (the Management API; `admin.toolPolicy.get()`/`.put({ rules })`): rules `{ effect: "allow" | "ask" | "deny", tool?, server?, kind?, agent?, when?, reason? }`. A rule matches a call when every selector it sets matches (`tool` and `server` take `*` globs; `when` tests input fields by dotted path with `equals`, `in`, `gt`, `gte`, `lt`, `lte` or `matches`). The strictest matching rule decides; a call no rule matches runs.
|
|
53
|
+
- **Enforced for every harness.** Core decides an MCP or HTTP tool call as it journals it. `deny` fails it to the model as `tool.denied`, unsent. `ask` holds the call (`held` at `/calls/tool`) and pauses the turn with one `approval` interaction per held call (`turn.paused`, with the tool, its input and the reason). `approve` sends that exact call, or fails it as `tool.denied`. The Tool Gate runs only calls the journal holds running, so a held or refused call cannot run. Nothing holds a process while it waits: an approval survives a restart. A flow's HTTP stages are decided the same way.
|
|
54
|
+
- **`approval` leaves the manifest.** `PUT /v1/agents/:id` and `saveAgent()` refuse a definition that sets `approval` on an HTTP tool, an MCP server or an MCP tool's settings; `http({ approval })` and `.mcp({ … approval })` throw; a turn manifest can no longer add one. The engine never asks for an HTTP or MCP tool's approval itself. A session pinned to a manifest saved with `approval: "always"` keeps it, as an ask.
|
|
55
|
+
- `@nylorun/studio`: a paused session shows an approval card for each held call, with its tool, why it is held and its input, and **Approve** / **Deny**.
|
|
56
|
+
- Migration: move each `approval: "always"` to an `ask` rule (see MIGRATION.md).
|
|
57
|
+
|
|
58
|
+
- 7800358: **Each turn is one OpenTelemetry trace, projected from the session log (R7).** An operator could not see what a turn did or where its time went without grepping container logs. Now every turn is a trace with a span for each model call, tool call and egress tunnel, exported over OTLP to any collector, readable per turn from the Runtime, and joined to the trace of the app that started it. No protocol change.
|
|
59
|
+
|
|
60
|
+
- **Traces from the log.** A turn's end is its root span, `invoke_agent <agent>`; each model call is a `chat <model>` span, each tool call and flow HTTP stage an `execute_tool <tool>` span, each egress-gate tunnel a `CONNECT <host>` span, and each pause and answer a marker. A model or gate tool span is the gate's own start and end; usage and cost are the gate's (`nylorun.usage.mismatch` when the harness reported other numbers). Attribute names follow the OTel GenAI conventions at one pinned commit, recorded as `nylorun.semconv.genai` on the resource. Ids are derived from the log under a key the Tenant keeps (setting `trace.key`), so every export and read of a turn gives the same ids.
|
|
61
|
+
- **OTLP export, off until you set an endpoint.** With `OTEL_EXPORTER_OTLP_ENDPOINT` (or `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`) the Runtime posts OTLP/HTTP JSON from a replication slot of its own, `nylorun_trace_export`, in batches of up to 512 spans or every 2 s; `OTEL_EXPORTER_OTLP_HEADERS`, `OTEL_SERVICE_NAME` and `OTEL_RESOURCE_ATTRIBUTES` work as usual. No turn waits for it. A collector that is down costs only its spans: after three retries a batch is dropped and logged as `trace_export_dropped`, and the slot moves on, so Postgres keeps no WAL for it. `nylorun start` passes these variables to the runtime container.
|
|
62
|
+
- **References by default.** Spans point at log events (`nylorun.event.cursor`) and carry no content unless you opt in per kind with `NYLORUN_TRACE_CONTENT` (`user`, `outputs`, `tool-results`, `errors`), or all of them with `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true`, each cut at 8 KiB. A span never carries a credential value, a prompt, a person's id, an identity header or an idempotency key.
|
|
63
|
+
- **`GET /v1/sessions/{id}/turns/{turnId}/trace`** answers a turn's spans as OTLP JSON, the same spans the exporter posts: look at a turn without a collector, or post it to one to backfill. Application keys, as the `/calls` reads. Host feature `traces`; `@nylorun/agents` adds `session.trace(turnId)`, and `@nylorun/core/contracts` `TurnTraceSchema`.
|
|
64
|
+
- **Trace context in and out.** A `traceparent` (and `tracestate`) on `POST /v1/sessions/{id}/commands`, an AG-UI run or an A2A message puts the turn in the caller's trace; `command.message` records it as `trace`. The turn hands its context on: to the harness in `TurnStart.trace`, to HTTP tools as `traceparent` beside `Idempotency-Key`, to MCP servers as `traceparent` on the call's requests, and to sandbox commands as `TRACEPARENT`.
|
|
65
|
+
- **Harness API** (additive): the `effect.intent` answer `execute` may carry the tool call's `traceparent`. `@nylorun/harness`: `HarnessExecutors.tool` takes it as a fourth argument (`ToolCallContext`).
|
|
66
|
+
|
|
67
|
+
### Patch Changes
|
|
68
|
+
|
|
69
|
+
- e917bd6: **The Harness API is a published contract (R4.5).** Everything a harness sends or reads now has a schema in `@nylorun/core/harness-api`, and the Runtime validates with those same schemas:
|
|
70
|
+
- the transport and the pod join (`HARNESS_API_PATH`, `HARNESS_API_HEADER`, `HOST_JOIN_PATH`, `HostJoinRequestSchema`, `HostJoinAnswerSchema`);
|
|
71
|
+
- the Model and Tool Gate bodies (`ModelCallBodySchema`, `ToolCallBodySchema`, `HttpCallBodySchema`, the MCP bodies, `GATE_ERROR_CODES`);
|
|
72
|
+
- the MCP snapshot (`McpSnapshotSchema`);
|
|
73
|
+
- transcript entries (`TranscriptEntrySchema`);
|
|
74
|
+
- the effect id rule (`effectIdOf`, `isEffectIdOf`).
|
|
75
|
+
|
|
76
|
+
The build also writes them as one JSON Schema document, `@nylorun/core/harness-api/schema.json`, for harnesses written in other languages.
|
|
77
|
+
|
|
78
|
+
Other changes:
|
|
79
|
+
- `TurnStart` gains an optional `trace` (W3C `traceparent`) for the turn's trace context. Nothing fills it yet.
|
|
80
|
+
- Core refuses a `hello` whose `api` is not `2`.
|
|
81
|
+
- **The fixture model answers at the Model Gate (R4.3).** With a Tenant's `fixtureModel` seeded, the gate answers model calls itself and meters each one, like any model: a `model_usage` row with provider `fixture` and cost 0, readable at `GET /v1/sessions/{id}/calls/model`. Our harness no longer answers it locally.
|
|
82
|
+
- The fixture model also answers scripted markers: `fixture:text`, `fixture:tool <name> <json>`, `fixture:budget` and `fixture:slow <seconds>`.
|
|
83
|
+
- **The sandboxes service can run a harness image (R4.4, Go).** `PUT /v1/pods/{name}` accepts `entrypoint: "image"`: the workload image's own `ENTRYPOINT` and `CMD` run, with no engine copied in and no `harnessImage`. The default, `entrypoint: "engine"`, is unchanged. The Runtime starts sending it with the harness pin in a later change.
|
|
84
|
+
|
|
85
|
+
- Pin core to the tested release.
|
|
86
|
+
- Updated dependencies [17a97e9]
|
|
87
|
+
- Updated dependencies [b6214d9]
|
|
88
|
+
- Updated dependencies [e917bd6]
|
|
89
|
+
- Updated dependencies [5165451]
|
|
90
|
+
- Updated dependencies [35e29b7]
|
|
91
|
+
- Updated dependencies [e917bd6]
|
|
92
|
+
- Updated dependencies [a0cbca1]
|
|
93
|
+
- Updated dependencies [3013501]
|
|
94
|
+
- Updated dependencies [6061a3a]
|
|
95
|
+
- Updated dependencies [7d496e4]
|
|
96
|
+
- Updated dependencies [81c783e]
|
|
97
|
+
- Updated dependencies [7800358]
|
|
98
|
+
- @nylorun/core@0.20.0-beta
|
|
99
|
+
|
|
100
|
+
## 0.25.1-beta
|
|
101
|
+
|
|
102
|
+
### Patch Changes
|
|
103
|
+
|
|
104
|
+
- Pin core to the tested release.
|
|
105
|
+
- Updated dependencies [212364b]
|
|
106
|
+
- @nylorun/core@0.19.0-beta
|
|
107
|
+
|
|
3
108
|
## 0.25.0-beta
|
|
4
109
|
|
|
5
110
|
### Major Changes
|
package/HOST_CONTRACT.md
CHANGED
|
@@ -4,7 +4,7 @@ Artifact: `@nylorun/harness@0.14.0-beta.3`. Package version is separate from pro
|
|
|
4
4
|
|
|
5
5
|
## HTTP (both hosts)
|
|
6
6
|
|
|
7
|
-
Bearer application credentials: `PUT /v1/agents/:agentId` (`PutAgentRequest`: requestId, complete manifest, implementationVersion); `PUT /v1/sessions/:sessionId` (`PutSessionRequest`: requestId, agentId, trusted ownerUserId, optional info, optional
|
|
7
|
+
Bearer application credentials: `PUT /v1/agents/:agentId` (`PutAgentRequest`: requestId, complete manifest, implementationVersion); `PUT /v1/sessions/:sessionId` (`PutSessionRequest`: requestId, agentId, trusted ownerUserId, optional info, optional `environment` — the id of an Environment (protocol 11): its sandbox (kinds `virtual` and `pod`) and its vault are the session's, with the recipe it applies pinned at open; omitted means no sandbox and no credentials; fixed for the session's life); `GET /v1/sessions/:sessionId`; `POST /v1/sessions/:sessionId/commands`; `GET /v1/sessions/:sessionId/items?cursor=...`; `GET /v1/sessions/:sessionId/events?cursor=...` (SSE, Last-Event-ID also accepted). Environments (`PUT/GET/DELETE /v1/environments/:environmentId`, `/stop`, `/reset`, `/events`, disk versions) and their secrets (`PUT/GET/DELETE /v1/environments/:environmentId/secrets/:name` and `GET .../secrets`: names, types and bindings, never a value) are Runtime API routes. Bearer management keys (the Management API, protocol 8; an application key there is `403 key_role_mismatch`): the `/v1/tenant/*` model routes below, the tool policy (`/v1/tenant/tool-policy`) and the Tenant's settings. Commands use `SessionCommandSchema`. A `message` command is exactly one of `{ content: string }` or `{ data: JsonValue }`, plus optional `manifest` (turn-only agent variant; see Turn manifests below). Application principals may call `POST /v1/sessions/:id/sandbox/:tool` for session-scoped sandbox built-ins when the session has a sandbox and no active agent turn. An Environment whose owner guard (`ownerUserId`) names another owner cannot be named by the session (the opaque `404`). `GET /v1/tenant/model` returns `{configured:false}` or the active provider, model, authType, and optional baseUrl, never the secret. `PUT /v1/tenant/model` upserts a host-scope provider credential and makes it active (idempotencyKey, requestId excluded from comparison). `PUT /v1/tenant/model/selection` switches the active provider/model among configured credentials without a new secret. `GET /v1/tenant/providers` lists configured providers with name, model, authType, lastUpdated, and active. `GET /v1/tenant/models` returns the public provider catalog. agentId, ownerUserId, info and environment stay the creation identity. GET session returns id, agentId, ownerUserId, status, activeTurnId, `environment: { id, version } | null`, the pinned `harness`, `closedReason` on a closed session, mcpSnapshot, mcpDiagnostics, plus inspectable waits/uncertainty as available. mcpSnapshot is null until the first turn discovers MCP tools; it is then pinned for the session and contains no secrets. History returns `{items: LiveEvent[], cursor: string|null}`; empty history cursor is null.
|
|
8
8
|
|
|
9
9
|
**Manifest-only agents (protocol 8, track R2).** The Runtime runs the whole agent from its manifest and its definition files, and never calls the developer's code during a session: Action endpoints, delivery tokens, background tools and held runs are gone (`/v1/endpoints` and `/v1/actions/*` answer `404`). An agent's tools are HTTP tools (`http`), remote MCP servers, agents used as tools and the Runtime's built-ins. `PUT /v1/agents/:agentId` refuses (`400`) a definition with a tool that has no `http` and no `agent` and is not a built-in, and a flow agent with a `tool` stage (`codeToolRefusal` in `/define`); a tool effect the Runtime cannot run fails with `tool.unavailable`. `tool({ run })` runs only in the local engine (`/run`).
|
|
10
10
|
|
|
@@ -14,17 +14,16 @@ route requires `Nylorun-Protocol` (client protocol integer). Missing or
|
|
|
14
14
|
unsupported protocol → `426` with
|
|
15
15
|
`{ status: "rejected", code: "protocol_unsupported", protocol }` before
|
|
16
16
|
authentication, except that a request with neither `Nylorun-Protocol` nor
|
|
17
|
-
`Authorization` gets the route's `401` challenge (protocol 9).
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
one) is the opaque `404`. A Tenant id in the query string or body is ignored. A
|
|
17
|
+
`Authorization` gets the route's `401` challenge (protocol 9). The Host serves
|
|
18
|
+
protocol 11 only. A `Nylorun-Tenant` header naming the Host's Tenant is
|
|
19
|
+
accepted, one naming another Tenant (or a malformed one) is the opaque `404`. A Tenant id in the query string or body is ignored. A
|
|
21
20
|
Tenant that could not be opened and an unknown Tenant share the opaque `404`
|
|
22
21
|
body. A missing or rejected credential is `401` (`credential_required`,
|
|
23
22
|
`credential_invalid`) with `WWW-Authenticate: Bearer` (protocol 9); on the
|
|
24
23
|
Runtime API the challenge names `/.well-known/oauth-protected-resource` when
|
|
25
24
|
the Host has trusted issuers. The Admin API is gone (protocol 8): `/v1/admin/*`
|
|
26
25
|
is no route, and the admin key is no request's credential. Vocabulary:
|
|
27
|
-
[runtime/src/CONTEXT.md](../
|
|
26
|
+
[runtime/server/src/CONTEXT.md](../server/src/CONTEXT.md).
|
|
28
27
|
|
|
29
28
|
Unauthenticated `GET /health` returns status, `service: "nylorun-runtime"`,
|
|
30
29
|
version, `hostId`, pid, and `protocol: { min, max, features }` (plus diagnostic
|
|
@@ -34,13 +33,13 @@ Tenant is open; a Tenant that cannot be opened fails it with its cause
|
|
|
34
33
|
(`schema-too-new`, `kek-missing`, `database-layout-old`, …), also reported in
|
|
35
34
|
`nylorun-operate status` inside the runtime container (`nylorun status` on a local Tenant).
|
|
36
35
|
|
|
37
|
-
All command idempotency keys bind to canonical request content within a session; requestId is transport metadata and is excluded from content comparison; exact semantic duplicates return the stored original response; changed content conflicts (409).
|
|
36
|
+
All command idempotency keys bind to canonical request content within a session; requestId is transport metadata and is excluded from content comparison; exact semantic duplicates return the stored original response; changed content conflicts (409). Tool calls are delivered at least once (R5): an MCP or HTTP call a crash, a shutdown or a lost gate hop interrupted is sent again with the same key, its effect id (`Idempotency-Key`, or `_meta["nylorun/idempotency-key"]` for MCP), up to 3 sends; then, and for a sandbox or core-served call at once, it fails to the model as `tool.interrupted` and is not run again. No tool call leaves its session `uncertain`. Results after cancellation cannot resume a turn. No hardcoded production credentials.
|
|
38
37
|
|
|
39
38
|
## Engine host
|
|
40
39
|
|
|
41
40
|
`createDurableCheckpoint({manifest,sessionId,turnId,input,state?,info?,segment?})`, `runDurable({manifest,checkpoint,host,signal?,sessionTools?})` from `/run`. `DurableHost.resolveEffect(HostEffect)` atomically creates or reads an individually identified effect and returns `{status:'completed',outcome:{value,statePatch?}}` or `{status:'pending'|'uncertain'}`. Model effect `input` is the complete ModelCall (instructions/history/tools/output schema); context contains invocationId and, for a call that summarizes history, `compaction: {trigger, tokensBefore, keptTokens}` (its invocationId starts with `compaction-`). When history no longer fits the model's window, the engine replaces the older transcript entries with one `compaction` entry and keeps the rest; hosts publish `context.compacted` for such a call instead of `message.assistant`. Its completed value is a ModelCandidate, a string, or a failure outcome `{kind:'failed', code, message, retryable, retryAfterMs?}` for a provider failure the Runtime classified (codes in `MODEL_FAILURE_CODES`); the engine fails the step with `model.<code>`. A classified failure is a known outcome, not a lost one, so it is never `uncertain`. Runtime provider code owns credentials and invocation. Tool effects have capabilityId, toolName, serialized input and context. Tool result value is a ToolOutcome or a plain tool output; statePatch contains changed session keys. Tool context includes invocationId, resume, state, info and stable idempotencyKey. Customer implementationVersion is pinned by the runtime outside durable checkpoints.
|
|
42
41
|
|
|
43
|
-
Persist checkpoint BEFORE scheduling, effect intent BEFORE provider invocation or notification, and outcome BEFORE resumption. Journaling an entire runDurable call as one replayable operation is forbidden. The durable path deterministically reconstructs a segment from its immutable starting checkpoint and individually cached effect outcomes. A waiting result returns that starting checkpoint: do not replace it with an intermediate preview. The journal is required continuation data and must be retained with the checkpoint. Stable IDs include turn/segment and deterministic invocation identity. There is no live continuation or request-held promise while waiting. Runtimes serialize work per session, check cancellation before effects and before settlement, and fence ownership. Lost provider acknowledgement becomes uncertain; do not repeat it merely because a worker restarts.
|
|
42
|
+
Persist checkpoint BEFORE scheduling, effect intent BEFORE provider invocation or notification, and outcome BEFORE resumption. Journaling an entire runDurable call as one replayable operation is forbidden. The durable path deterministically reconstructs a segment from its immutable starting checkpoint and individually cached effect outcomes. A waiting result returns that starting checkpoint: do not replace it with an intermediate preview. The journal is required continuation data and must be retained with the checkpoint. Stable IDs include turn/segment and deterministic invocation identity. There is no live continuation or request-held promise while waiting. Runtimes serialize work per session, check cancellation before effects and before settlement, and fence ownership. Lost provider acknowledgement becomes uncertain; do not repeat it merely because a worker restarts. Tool calls are the exception: they are re-sent with their key, as above.
|
|
44
43
|
|
|
45
44
|
A terminal/paused result includes `result.state`. Save it. A new message uses a new turnId with prior completed state. Approval/response resumes paused state via a new checkpoint, same turnId, `segment + 1`, with `{kind:'approve',interactionId,approved}` or `{kind:'respond',interactionId,value}`. An action result simply reruns the SAME suspended checkpoint/segment after recording the outcome. `runDurable({yieldAfter: {steps, ms}})` lets a long turn end a segment at a step boundary with status `yielded` (Model Calls §10): the result state is mid-turn (status `active`, `turn` kept); save it, write a new checkpoint for the same turnId at `segment + 1` with input `{kind:'continue'}`, and schedule it. A yielded segment emits no `turn.*` event, and its effects are never read again. Paused plan records pending interactions/deferred calls; waiting on remote action is distinct from a human wait. Cancellation is host-owned and must fence both running and pending work. Runtime supplies canonical events; execution observations are not wire events and reconstruction must not republish duplicate history.
|
|
46
45
|
|
|
@@ -48,26 +47,28 @@ Host resolveEffect must bind the effect ID to the original request and reject dr
|
|
|
48
47
|
|
|
49
48
|
Agents used as tools: a manifest tool with an `agent` body (the child manifest inlined; name equals the child id, description equals the child description, input is the standard `{task}` schema, no outputSchema, no nested agent tools, identical sandbox specs across the tree — in a session opened with a sandbox the Runtime adds the same `nylorun.sandbox` capability to the root and each inlined child) is run by the engine inside the parent's `runDurable`. Its model and tool effects carry `agent: {id, path, delegationId}` (`delegationId` is the parent tool call's invocationId), keep the root `agentId` and `manifestHash`, and use identity `<delegationId>/<inner identity>`; tool context `idempotencyKey` is prefixed the same way. Hosts resolve child effects against the child manifest (`delegateManifest`) for pinned tool schemas, sandbox and MCP routing, and include `agent` in `tool.completed` payloads. A `delegation` effect (identity `<delegationId>:started` or `<delegationId>:settled`, input `{task}` or `{status, outcome}`) must be recorded completed immediately with value null and publish `delegation.started` / `delegation.completed` exactly once; the journal makes replays silent. `DurableSessionTool.agentId` attaches discovered MCP tools to a child; MCP snapshot records and diagnostics carry `agentId`. Children share the session sandbox. `GET /v1/sessions/:id/items?agent=` filters history by `payload.agent.delegationId` or `payload.agent.path`. Existing checkpoints are unaffected; engine version stays `hosted-2`. A tool whose `agent` body is a flow agent (workflow manifest v3) is not run in-process: the engine issues one `agent` effect (identity `<delegationId>:flow`, input `{agentId, input: task, path}`, context `{role: "delegate", delegationId}`, `agent` ref set) between the `delegation` start and settle points. The host starts a linked flow session from the pinned parent manifest's inlined flow (session id `derive(parentSessionId, path, "delegate", delegationId)`), sends the task as its message, and completes the effect with the flow's output, or `{kind: "failed", code, message}`, when its turn ends. Cancelling the parent cascades to linked sessions.
|
|
50
49
|
|
|
51
|
-
**Workflows (flow engine).** Definitions with `kind: "workflow"` (workflow manifest v3) run through `createFlowCheckpoint` / `runFlowDurable` from `/run` (same `DurableResult` shape as `runDurable`) on engine `flow-3`; checkpoints pin it, and v1/v2 manifests are refused. The turn loop in `harness/src/loop/` is unchanged. A flow runs no developer code: its effects are `agent` (a leaf agent's turn) and `tool` (a workflow tool node). Each carries `path` (the leaf path: the leaf's id, `[i]` per Map item, nested flow agent ids in front), `key` (the path without Map indices) and `iterations` (enclosing Loop vector as a dotted string, or `"-"` outside Loops). Effect ids are `${turnId}:${segment}:flow:${path}:${kind}:${iterations}`. The first stage gets the flow's input and each later stage the previous output; a Switch reads it (a string, or its `route` field), a Map runs over it (an array, or its `items`), and a Loop asks a verifier (an agent, or an HTTP verifier) for a verdict (`{ pass, feedback? }`) and retries the body with the feedback, up to `max`. `agent` effect input is `{ agentId, input, path, flow?, flowInput? }`: `flow` names the nested flow agents, outermost first; `flowInput` is the flow agent's input, sent when the stage's input differs, and the host puts it in the linked message as the original request before the stage's input. Effect `context` carries `loopPath` and `n` for a Loop's turns, and `role: "verify-agent"` for its verifier, which gets a fresh session per attempt and whose verdict the host records as `loop.verified`. The host resolves the leaf from the workflow manifest's embedded `agents` (`embeddedAgent`) and gives the linked session the leaf's manifest and its hash, only through the public session contract (create linked session, message with derived idempotency key, settle on linked `turn.completed` / failed / cancelled). A `tool` effect carries `path` + `key` instead of `capabilityId` + `toolName`. A code tool node (no `http`) runs only in the local engine: the Runtime refuses a flow with one at save and fails such an effect with `tool.unavailable`. The `tool` effects of an HTTP stage (a tool node with `http`, input checked against its schema first) and of an HTTP verifier (`loop.verify: { http }`, input `{ input, output, iteration }`, `context.role: "verify-http"`, at the verify position's key) are requests the host makes through its Tool Gate as for an agent's HTTP tool, the effect id as `Idempotency-Key`, the HTTP outcome (`{ kind: "completed", output }` or `{ kind: "failed", code, message }`) as the value, and an HTTP verifier's verdict recorded as `loop.verified`; a Loop body that starts with an HTTP stage is retried with the Loop's input. A lost HTTP stage
|
|
50
|
+
**Workflows (flow engine).** Definitions with `kind: "workflow"` (workflow manifest v3) run through `createFlowCheckpoint` / `runFlowDurable` from `/run` (same `DurableResult` shape as `runDurable`) on engine `flow-3`; checkpoints pin it, and v1/v2 manifests are refused. The turn loop in `runtime/harness/src/loop/` is unchanged. A flow runs no developer code: its effects are `agent` (a leaf agent's turn) and `tool` (a workflow tool node). Each carries `path` (the leaf path: the leaf's id, `[i]` per Map item, nested flow agent ids in front), `key` (the path without Map indices) and `iterations` (enclosing Loop vector as a dotted string, or `"-"` outside Loops). Effect ids are `${turnId}:${segment}:flow:${path}:${kind}:${iterations}`. The first stage gets the flow's input and each later stage the previous output; a Switch reads it (a string, or its `route` field), a Map runs over it (an array, or its `items`), and a Loop asks a verifier (an agent, or an HTTP verifier) for a verdict (`{ pass, feedback? }`) and retries the body with the feedback, up to `max`. `agent` effect input is `{ agentId, input, path, flow?, flowInput? }`: `flow` names the nested flow agents, outermost first; `flowInput` is the flow agent's input, sent when the stage's input differs, and the host puts it in the linked message as the original request before the stage's input. Effect `context` carries `loopPath` and `n` for a Loop's turns, and `role: "verify-agent"` for its verifier, which gets a fresh session per attempt and whose verdict the host records as `loop.verified`. The host resolves the leaf from the workflow manifest's embedded `agents` (`embeddedAgent`) and gives the linked session the leaf's manifest and its hash, only through the public session contract (create linked session, message with derived idempotency key, settle on linked `turn.completed` / failed / cancelled). A `tool` effect carries `path` + `key` instead of `capabilityId` + `toolName`. A code tool node (no `http`) runs only in the local engine: the Runtime refuses a flow with one at save and fails such an effect with `tool.unavailable`. The `tool` effects of an HTTP stage (a tool node with `http`, input checked against its schema first) and of an HTTP verifier (`loop.verify: { http }`, input `{ input, output, iteration }`, `context.role: "verify-http"`, at the verify position's key) are requests the host makes through its Tool Gate as for an agent's HTTP tool, the effect id as `Idempotency-Key`, the HTTP outcome (`{ kind: "completed", output }` or `{ kind: "failed", code, message }`) as the value, and an HTTP verifier's verdict recorded as `loop.verified`; a Loop body that starts with an HTTP stage is retried with the Loop's input. A lost HTTP stage is sent again with the same key, as an agent's HTTP tool call is (R5). Parallelism comes from pending effects returned together; the Runtime caps concurrency with `RuntimeOptions.flow` / env (`maxConcurrency`, `maxMapItems`, `maxLoopIterations`).
|
|
52
51
|
|
|
53
52
|
**Turn manifests.** A `message` command may include optional `manifest`. Any app may use it (not only Loops). When present, the Runtime parses it with `AgentManifestSchema`, requires it to be a **variant** of the session's pinned manifest (id fixed; tools/skills/delegates may only shrink; MCP and sandbox must not change), hashes and stores it by hash for that turn only (it does not latch — a later message without `manifest` uses the pin), and rebases `state.manifestHash` at turn start when the prior state hash and the turn hash are both the pin or validated variants of it. Invalid variants fail closed.
|
|
54
53
|
|
|
55
54
|
**Shared sandbox.** Definitions declare no sandbox; a session is opened with one (`PutSessionRequest.sandbox`), resolved against the Tenant's limits and pinned on the session. An agent session's pinned manifest is its definition plus capability `nylorun.sandbox` (the six built-ins, the sandbox instructions and the resolved spec), so its hash differs from the definition's; a workflow session's manifest is unchanged and its sandbox is stored beside it. A tree has one sandbox, keyed by the owning session id. `sandbox: { session }` attaches another session's sandbox (same `ownerUserId`, same Tenant); a session whose definition declares none inherits the owner's spec and tools. Linked agent sessions created for agent nodes attach with `sandbox: { session: workflowSessionId }` and inherit the same way. Application principals call `POST /v1/sessions/:id/sandbox/:tool` (`bash` | `read` | `write` | `edit` | `grep` | `glob`); refused while that session has an active agent turn. `session.sandbox` on the application client mirrors the session endpoint. Registration refuses a definition that declares a sandbox; definitions stored before Sandboxes v3 keep theirs.
|
|
56
55
|
|
|
57
|
-
## Harness API
|
|
56
|
+
## Harness API 2
|
|
58
57
|
|
|
59
|
-
The Runtime runs every segment through the Harness API (blueprint D37–D42): core keeps scheduling, the record, settle and takeover; a harness runs the engine.
|
|
58
|
+
The Runtime runs every segment through the Harness API (blueprint D37–D42): core keeps scheduling, the record, settle and takeover; a harness runs the engine. Three version numbers apply: the transport (path `/nylorun/harness/v1`, header `Nylorun-Harness-Api: 1`), the messages (`HARNESS_API_VERSION = 2`; core refuses a `hello` naming another `api`) and the Runtime protocol, which only the Runtime and Management APIs carry. The whole contract is `@nylorun/core/harness-api` (R4.5): frames and messages, the transport and the pod join (`HostJoinRequestSchema`, `HostJoinAnswerSchema`), the Model and Tool Gate bodies (`ModelCallBodySchema`, `ToolCallBodySchema`, `HttpCallBodySchema`, MCP bodies, `GATE_ERROR_CODES`), the MCP snapshot (`McpSnapshotSchema`), transcript entries (`TranscriptEntrySchema`) and the effect id rule (`effectIdOf`: `<turnId>:<segment>:<kind>:<identity>`; a run gets back only its segment's outcomes), the request hash, transcript edits and the RPC channel; the Runtime validates with the same schemas, and the build writes them as one JSON Schema document (`@nylorun/core/harness-api/schema.json`). `TurnStart.trace` (optional W3C `traceparent`) is the turn's trace context when the Runtime traces. With the Tenant's fixture model on (`TurnStart.options.fixtureModel`, informational), the Model Gate answers model calls itself, metered like any model (provider `fixture`, cost 0), so a harness calls the gate as usual. Harness ids (R4.1): `hello.name` is the harness's id (ours says `nylorun`; `@nylorun/harness` is refused); a session pins its Environment's harness, else `nylorun`, and only a connection of that id takes its runs; a credential binds its id (the harness token is ours, a custom harness has its own from `nylorun-operate harness token put <id>`, a pod's host is its Environment's harness). A harness's state is its own (R4.2): core stores it unread; a custom harness's is at most 256 KiB, it cannot pause for approvals, and the tools it declares in `hello` (`capabilities.tools`, capability `harness`) are journaled like built-ins. Events carry who wrote them (R4.9): `harness` with its id, `runId` and evidence `claimed` for what a harness reported. v2 removed held runs, `TurnStart.options.holdMs` and `effect.resolved`, with track R2; the harness client is `@nylorun/harness/api` (`createHarness({channel, executors})`). A Tenant runs one harness in its own process over a memory channel, or (F6.2, `NYLORUN_HARNESS=remote`) harnesses connect to core's Harness API listener over WebSocket (`/nylorun/harness/v1`, the harness credential): `--service harness` runs one with its own MCP pool and sandboxes and no store, and serves the Tenant's workspaces (`workspace.*`). Durable checkpoint 1 is unchanged.
|
|
60
59
|
|
|
61
60
|
Frames: `{t:"req",id,m,p}`, `{t:"res",id,ok,r|e:{code,message}}`, `{t:"msg",m,p}`, `{t:"abort",id}`, `{t:"ping"}`. Error codes: `run_not_held`, `turn_cancelled`, `ownership_lost`, `effect_drift`, `invalid`, `unavailable`, `internal`; the message is today's (`Turn cancelled`, `Effect identity request drift`, …).
|
|
62
61
|
|
|
63
62
|
- **Work.** `hello` → `{api, sandbox:{backend}, renewEveryMs}`. A harness keeps one `lease` waiting; an advance that took a session's lease offers its segment, and the answer is `{run: {runId, sessionId, turnId, epoch, token?, tokenExpiresAt?}, input: TurnStart}`. A run is bound to the connection that leased it. `lease.renew` every `renewEveryMs` renews the session's ownership lease (`{ok:false}`: lost, abort with `ownership.lost`); `lease.release{reason}` gives the run back (`shutdown`, `ownership.lost`; a lost connection counts as `connection.lost`).
|
|
64
63
|
- **Input.** `TurnStart` (`type` `turn.start`, or `approval.answer` for approve/respond): `engine` (`agent` | `flow`), the turn's `manifest`, the segment's `checkpoint` with an empty transcript, `sessionTools`, the segment's completed `outcomes` (`{effectId, requestHash, outcome}`), `transcript.cursor`, `options` (`yieldAfter`, `flowLimits`, `fixtureModel`) and `routing` (root manifest, plugin roots, MCP snapshot, sandbox owner). Core aborts a run with `cancel{runId, reason, message}`, `reason` one of `cancel`, `shutdown`, `deadline`, `ownership.lost`.
|
|
65
|
-
- **Record.** `requestHash = sha256(canonical(requestIdentity(effect)))` (canonical JSON: keys by code unit, `undefined` dropped; a delegation's identity leaves out `context`). An effect in `outcomes` with the same hash resolves in the harness; another hash is drift. Any other effect is an `effect.intent{effect, requestHash}`: a model intent carries no `input`, so a prompt never crosses twice. Core journals the row with `requestHash` (a model row without `input`) and answers `completed`, `pending`, `uncertain`, or `execute` (`rejoin` for a call its gate recovers, P1.2/F4.1). The harness runs model, MCP, HTTP and sandbox calls through the executors it is given (a model call reaches its provider through the Runtime's Model Gate, never from the harness) and reports `effect.outcome{value}` or `{error}` (uncertain); after a `shutdown` a recoverable call reports nothing and stays `invoking`. Core runs flow work, linked sessions, delegation journaling and its built-in tools, and fails a tool that would run the developer's code (`tool.unavailable`). Rows written before carry their full request and are hashed on read.
|
|
64
|
+
- **Record.** `requestHash = sha256(canonical(requestIdentity(effect)))` (canonical JSON: keys by code unit, `undefined` dropped; a delegation's identity leaves out `context`). An effect in `outcomes` with the same hash resolves in the harness; another hash is drift. Any other effect is an `effect.intent{effect, requestHash}`: a model intent carries no `input`, so a prompt never crosses twice. Core journals the row with `requestHash` (a model row without `input`) and answers `completed`, `pending`, `uncertain`, or `execute` (`rejoin` for a call its gate recovers, P1.2/F4.1). The harness runs model, MCP, HTTP and sandbox calls through the executors it is given (a model call reaches its provider through the Runtime's Model Gate, never from the harness) and reports `effect.outcome{value}` or `{error}` (uncertain for a model call; a tool call's error fails it to the model as `tool.interrupted`); after a `shutdown` a recoverable call reports nothing and stays `invoking`. An intent for a tool row still `invoking` is a re-send (R5): core counts it and answers `execute` for an MCP or HTTP call under 3 sends, else the call's `tool.interrupted` outcome. A harness whose gate hop lost a call's answer asks again with the same intent. The Tool Gate runs a run's tool call only when its `Idempotency-Key` names an `invoking` row of the run's turn for the same tool and input (`400 key_required`, `409 effect_not_journaled`). Core applies the Tenant's tool policy to an MCP or HTTP tool intent (R5 step 2): one it refuses is answered `completed` with a `tool.denied` failure, and one it holds for a person is answered `pending` (the segment ends waiting; the turn pauses with an `approval` interaction whose id is the effect id, and the call is `execute`d once approved). Core runs flow work, linked sessions, delegation journaling and its built-in tools, and fails a tool that would run the developer's code (`tool.unavailable`). Rows written before carry their full request and are hashed on read.
|
|
66
65
|
- **Transcript.** The cursor is the record seq of the last `transcript.updated`, `turn.cancelled` or `turn.failed`. A harness resumes from its cached transcript at that cursor, else reads it once (`transcript.read`). Outputs carry the agent's state without its transcript plus the `TranscriptUpdate[]` from the transcript the segment started with; core records them and answers with the new cursor.
|
|
67
66
|
- **Output.** `turn.completed`, `turn.paused`, `turn.waiting{status, effectIds}`, `turn.failed{status, error}` or `{thrown}`, and `checkpoint` for a yielded segment; answered `{cursor?}` once core settled it, idempotent per run and type. Core settles them exactly as the engine's own results, classifying aborts from its own signal.
|
|
68
67
|
|
|
69
68
|
A Runtime below F6.1 compares journal rows by their full request: downgrading one with a turn in flight can fail that turn with drift.
|
|
70
69
|
|
|
70
|
+
**Build your own harness.** A harness is any program that speaks this contract; it does not need `@nylorun/harness`. [`examples/harness-minimal`](../../examples/harness-minimal/) is one, written only against `@nylorun/core/harness-api`: it runs beside the Runtime with its own token (`nylorun-operate harness token put <id>`) and takes the sessions of Environments whose `harness` is its id, or runs as a pod Environment's `image`. `runtime/server/test/harness-api/conformance.test.ts` runs it against ours and the example.
|
|
71
|
+
|
|
71
72
|
## Definitions, validation, compatibility
|
|
72
73
|
|
|
73
74
|
`/define` is execution-free and browser-bundleable; Agent has no `.run()`. Explicit local execution uses `/run` run + bindingFromAgent(agent.build()). `/contracts` never imports checkpoint internals. Tools are supported remotely. Arbitrary legacy middleware closures are rejected for durable definitions because they cannot be reconstructed from manifests. JSON schemas are reconstructed through Zod's JSON Schema importer; unsupported schemas fail closed. The original manifest document must survive reconstruction. Runtime is the only hasher: it hashes the accepted manifest and pins that digest on the session. Agents do not hash. Model configuration is host-owned. The Runtime refuses a definition whose tools would run the developer's code. It checks an HTTP tool's answer against the tool's output schema and records a mismatch as the failed outcome `tool.invalid-output`.
|
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ Prefer `input` / `output` / `run`. Legacy `inputSchema` / `execute` and tagged `
|
|
|
79
79
|
Definitions must not import `@nylorun/runtime`.
|
|
80
80
|
|
|
81
81
|
Local explicit engine execution retains middleware. Durable manifests reject middleware
|
|
82
|
-
closures: a hosted agent is its manifest, and the Runtime
|
|
82
|
+
closures: a hosted agent is its manifest, and the Runtime runs it from that alone.
|
|
83
83
|
|
|
84
84
|
## Checkpoint / durability
|
|
85
85
|
|
|
@@ -87,4 +87,4 @@ closures: a hosted agent is its manifest, and the Runtime never calls your code
|
|
|
87
87
|
|
|
88
88
|
## Client types
|
|
89
89
|
|
|
90
|
-
The authoritative session/action wire schemas live in `/contracts` and do not import durable checkpoint types. Use `@nylorun/agents` for the session client and to save agents (`saveAgent`); the Runtime runs
|
|
90
|
+
The authoritative session/action wire schemas live in `/contracts` and do not import durable checkpoint types. Use `@nylorun/agents` for the session client and to save agents (`saveAgent`); the Runtime runs agents from their manifests alone, so a tool there is an `http()` tool or a remote MCP server's. Historical root client types remain for deferred local tooling; they are not the new wire contract.
|
package/dist/api/executors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ParamsOf, ResultOf, RunGrant, TurnStart } from "@nylorun/core/harness-api";
|
|
1
|
+
import type { McpSnapshot, ParamsOf, ResultOf, RunGrant, TurnStart } from "@nylorun/core/harness-api";
|
|
2
2
|
import type { DurableSessionTool, HostEffect } from "../run/durable.js";
|
|
3
3
|
/** A run as the harness holds it: the lease, what it started from, and its signal. */
|
|
4
4
|
export interface HarnessRun {
|
|
@@ -15,8 +15,12 @@ export interface HarnessRun {
|
|
|
15
15
|
export interface HarnessExecutors {
|
|
16
16
|
/** A model call. A provider failure is a failure outcome; only an abort throws. */
|
|
17
17
|
model(effect: HostEffect, signal: AbortSignal, run: HarnessRun): Promise<unknown>;
|
|
18
|
-
/**
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* An MCP, HTTP or sandbox tool call, routed by `run.start.routing`. `call.traceparent` is the
|
|
20
|
+
* call's span context from core's `execute` answer (R7.4): a sandbox command gets it as
|
|
21
|
+
* `TRACEPARENT`.
|
|
22
|
+
*/
|
|
23
|
+
tool(effect: HostEffect, signal: AbortSignal, run: HarnessRun, call?: ToolCallContext): Promise<unknown>;
|
|
20
24
|
/**
|
|
21
25
|
* Calls that outlive this process at their gate: a shutdown leaves them running there, and
|
|
22
26
|
* the next run re-sends them (`rejoin`) instead of marking them uncertain.
|
|
@@ -28,6 +32,12 @@ export interface HarnessExecutors {
|
|
|
28
32
|
};
|
|
29
33
|
/** Stops a recoverable tool call at its gate after a user cancel. Never rejects. */
|
|
30
34
|
cancelAtGate?(effect: HostEffect, run: HarnessRun): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* True when `error` says the hop to the tool call's gate lost its answer (R5.3): sending the
|
|
37
|
+
* call again with the same key joins it, collects its answer, or runs it again. The harness
|
|
38
|
+
* then asks core first (`effect.intent`), which counts the send and stops at its cap.
|
|
39
|
+
*/
|
|
40
|
+
resends?(effect: HostEffect, error: unknown, run: HarnessRun): boolean;
|
|
31
41
|
/**
|
|
32
42
|
* Readies the session's MCP servers before an agent's segment runs (F6.2): discovers their
|
|
33
43
|
* tools the first time, reconnects them after. `record` keeps what it found in the session
|
|
@@ -36,10 +46,14 @@ export interface HarnessExecutors {
|
|
|
36
46
|
*/
|
|
37
47
|
prepare?(run: HarnessRun, record: McpRecorder): Promise<PreparedRun | undefined>;
|
|
38
48
|
}
|
|
49
|
+
/** What core's `execute` answer says of a tool call beside running it (R7.4). */
|
|
50
|
+
export interface ToolCallContext {
|
|
51
|
+
readonly traceparent?: string;
|
|
52
|
+
}
|
|
39
53
|
/** Records a session's MCP discovery in core (`session.mcp`). */
|
|
40
54
|
export type McpRecorder = (params: Omit<ParamsOf<"session.mcp">, "runId">) => Promise<ResultOf<"session.mcp">>;
|
|
41
55
|
/** The session's MCP snapshot and tools after `prepare`. */
|
|
42
56
|
export interface PreparedRun {
|
|
43
57
|
readonly sessionTools: readonly DurableSessionTool[];
|
|
44
|
-
readonly mcpSnapshot?:
|
|
58
|
+
readonly mcpSnapshot?: McpSnapshot;
|
|
45
59
|
}
|
package/dist/api/harness.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* with `ownership.lost`, and `stop()` with `shutdown`. While a run is live it renews its lease
|
|
6
6
|
* every `renewEveryMs`; renewing stops once the run is aborted.
|
|
7
7
|
*/
|
|
8
|
-
import { HARNESS_API_VERSION, } from "@nylorun/core/harness-api";
|
|
8
|
+
import { DEFAULT_HARNESS, HARNESS_API_VERSION, } from "@nylorun/core/harness-api";
|
|
9
9
|
import { ABORT_MESSAGES, RunAbort } from "./abort.js";
|
|
10
10
|
import { runTurn } from "./run.js";
|
|
11
11
|
import { TranscriptCache } from "./transcript-cache.js";
|
|
@@ -111,7 +111,7 @@ export function createHarness(options) {
|
|
|
111
111
|
async start() {
|
|
112
112
|
const hello = await channel.request("hello", {
|
|
113
113
|
api: HARNESS_API_VERSION,
|
|
114
|
-
name: options.name ??
|
|
114
|
+
name: options.name ?? DEFAULT_HARNESS,
|
|
115
115
|
version: options.version ?? "0",
|
|
116
116
|
capabilities: options.capabilities?.workspace === undefined
|
|
117
117
|
? {}
|
package/dist/api/host.d.ts
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* (same id, same request hash) resolves here; any other becomes an `effect.intent`. A model
|
|
4
4
|
* intent carries no prompt: core stores its hash. When core answers `execute`, the harness runs
|
|
5
5
|
* the call and reports its outcome.
|
|
6
|
+
*
|
|
7
|
+
* A tool call whose gate hop lost its answer (`executors.resends`) is sent again with the same
|
|
8
|
+
* key (R5.3): the harness waits a moment and asks core again with the same intent, and core
|
|
9
|
+
* counts the send, answering `execute` again or the call's outcome once it reached its cap.
|
|
6
10
|
*/
|
|
7
11
|
import { type HarnessChannel } from "@nylorun/core/harness-api";
|
|
8
12
|
import type { DurableHost } from "../run/durable.js";
|
package/dist/api/host.js
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* (same id, same request hash) resolves here; any other becomes an `effect.intent`. A model
|
|
4
4
|
* intent carries no prompt: core stores its hash. When core answers `execute`, the harness runs
|
|
5
5
|
* the call and reports its outcome.
|
|
6
|
+
*
|
|
7
|
+
* A tool call whose gate hop lost its answer (`executors.resends`) is sent again with the same
|
|
8
|
+
* key (R5.3): the harness waits a moment and asks core again with the same intent, and core
|
|
9
|
+
* counts the send, answering `execute` again or the call's outcome once it reached its cap.
|
|
6
10
|
*/
|
|
7
11
|
import { HarnessApiError, effectRequestHash, } from "@nylorun/core/harness-api";
|
|
8
12
|
import { runAbortKind } from "./abort.js";
|
|
@@ -20,30 +24,46 @@ export function apiHost(channel, executors, run) {
|
|
|
20
24
|
throw error;
|
|
21
25
|
}
|
|
22
26
|
};
|
|
23
|
-
const execute = async (effect) => {
|
|
27
|
+
const execute = async (effect, requestHash, traceparent) => {
|
|
24
28
|
const model = effect.kind === "model";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
for (let resent = 0;; resent += 1) {
|
|
30
|
+
try {
|
|
31
|
+
const value = model
|
|
32
|
+
? await executors.model(effect, signal, run)
|
|
33
|
+
: await executors.tool(effect, signal, run, traceparent ? { traceparent } : {});
|
|
34
|
+
return await ask("effect.outcome", { runId, effectId: effect.effectId, value });
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
// Another owner decides what the effect became.
|
|
38
|
+
if (error instanceof HarnessApiError && error.code === "ownership_lost")
|
|
39
|
+
throw error;
|
|
40
|
+
const recoverable = model ? executors.recovers.model : executors.recovers.tool(effect, run);
|
|
41
|
+
const kind = runAbortKind(signal);
|
|
42
|
+
// The call goes on at its gate: the next run re-sends it and collects its outcome.
|
|
43
|
+
if (recoverable && kind === "shutdown")
|
|
44
|
+
throw error;
|
|
45
|
+
// The hop lost the answer: core counts one more send, and the call goes again (R5.3).
|
|
46
|
+
if (!model && kind === undefined && executors.resends?.(effect, error, run)) {
|
|
47
|
+
await pause(RESEND_DELAYS_MS[Math.min(resent, RESEND_DELAYS_MS.length - 1)], signal);
|
|
48
|
+
const again = await ask("effect.intent", {
|
|
49
|
+
runId,
|
|
50
|
+
effect: intentOf(effect),
|
|
51
|
+
requestHash,
|
|
52
|
+
});
|
|
53
|
+
if (again.status === "execute") {
|
|
54
|
+
traceparent = again.traceparent ?? traceparent;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
return again;
|
|
58
|
+
}
|
|
59
|
+
if (recoverable && !model && kind === "cancel")
|
|
60
|
+
await executors.cancelAtGate?.(effect, run);
|
|
61
|
+
return ask("effect.outcome", {
|
|
62
|
+
runId,
|
|
63
|
+
effectId: effect.effectId,
|
|
64
|
+
error: error instanceof Error ? error.message : String(error),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
47
67
|
}
|
|
48
68
|
};
|
|
49
69
|
return {
|
|
@@ -59,11 +79,29 @@ export function apiHost(channel, executors, run) {
|
|
|
59
79
|
}
|
|
60
80
|
const answer = await ask("effect.intent", { runId, effect: intentOf(effect), requestHash });
|
|
61
81
|
if (answer.status === "execute")
|
|
62
|
-
return execute(effect);
|
|
82
|
+
return execute(effect, requestHash, answer.traceparent);
|
|
63
83
|
return answer;
|
|
64
84
|
},
|
|
65
85
|
};
|
|
66
86
|
}
|
|
87
|
+
/** How long the harness waits before it sends a call whose gate hop was lost again. */
|
|
88
|
+
const RESEND_DELAYS_MS = [1_000, 2_000, 4_000];
|
|
89
|
+
/** Waits `ms`, or throws the reason as soon as `signal` aborts. */
|
|
90
|
+
function pause(ms, signal) {
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
if (signal.aborted)
|
|
93
|
+
return reject(signal.reason);
|
|
94
|
+
const onAbort = () => {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
reject(signal.reason);
|
|
97
|
+
};
|
|
98
|
+
const timer = setTimeout(() => {
|
|
99
|
+
signal.removeEventListener("abort", onAbort);
|
|
100
|
+
resolve();
|
|
101
|
+
}, ms);
|
|
102
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
103
|
+
});
|
|
104
|
+
}
|
|
67
105
|
/** What crosses for an effect: a model call's prompt stays here. */
|
|
68
106
|
function intentOf(effect) {
|
|
69
107
|
if (effect.kind !== "model")
|
package/dist/api/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { createHarness, type Harness, type HarnessLogger, type HarnessOptions } from "./harness.js";
|
|
7
7
|
export { ABORT_MESSAGES, RunAbort, runAbortKind } from "./abort.js";
|
|
8
|
-
export type { HarnessExecutors, HarnessRun, McpRecorder, PreparedRun } from "./executors.js";
|
|
8
|
+
export type { HarnessExecutors, HarnessRun, McpRecorder, PreparedRun, ToolCallContext, } from "./executors.js";
|
|
9
9
|
export { apiHost } from "./host.js";
|
|
10
10
|
export { runTurn, type RunContext } from "./run.js";
|
|
11
11
|
export { TranscriptCache } from "./transcript-cache.js";
|
package/dist/api/run.js
CHANGED
|
@@ -45,6 +45,15 @@ export async function runTurn(ctx, run) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
let checkpoint = start.checkpoint;
|
|
48
|
+
// The state is ours alone (R4.2): core never reads it. The turn's manifest is core's choice
|
|
49
|
+
// (the pin, or a variant a message named), and the state follows it.
|
|
50
|
+
if (start.engine === "agent" &&
|
|
51
|
+
checkpoint.state &&
|
|
52
|
+
checkpoint.state.manifestHash !== checkpoint.manifestHash)
|
|
53
|
+
checkpoint = {
|
|
54
|
+
...checkpoint,
|
|
55
|
+
state: { ...checkpoint.state, manifestHash: checkpoint.manifestHash },
|
|
56
|
+
};
|
|
48
57
|
if (start.engine === "agent" && checkpoint.state) {
|
|
49
58
|
transcript = ctx.cache.get(sessionId, cursor) ?? (await read(ctx, run));
|
|
50
59
|
checkpoint = { ...checkpoint, state: withTranscript(checkpoint.state, transcript) };
|
package/dist/run/durable.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AgentManifest } from "@nylorun/core/define";
|
|
|
2
2
|
import type { ExecutionInput, ExecutionState, RunResult } from "../types/execution.js";
|
|
3
3
|
import type { JsonObject } from "@nylorun/core/define";
|
|
4
4
|
import type { EffectOutcome } from "@nylorun/core/contracts";
|
|
5
|
-
import type { AgentRef
|
|
5
|
+
import type { AgentRef } from "@nylorun/core/define";
|
|
6
6
|
import { ENGINE_VERSION } from "../compatibility.js";
|
|
7
7
|
/** Private persistence contract for hosts; this is not a session wire type. */
|
|
8
8
|
export interface DurableCheckpoint {
|
|
@@ -72,8 +72,6 @@ export interface DurableSessionTool {
|
|
|
72
72
|
readonly description?: string;
|
|
73
73
|
readonly inputSchema: JsonObject;
|
|
74
74
|
readonly outputSchema?: JsonObject;
|
|
75
|
-
/** `always`: each call waits for approval (a remote MCP server's, or its tool's, `approval`). */
|
|
76
|
-
readonly approval?: ApprovalMode;
|
|
77
75
|
/**
|
|
78
76
|
* Not in the model's tool list (R2b C10): the model finds it with `tool_search` and runs it
|
|
79
77
|
* with `tool_call`, which makes the call as this tool's own.
|
package/dist/run/durable.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HarnessError } from "@nylorun/core/define";
|
|
2
|
+
import { effectIdOf } from "@nylorun/core/harness-api";
|
|
2
3
|
import { AgentManifestSchema } from "@nylorun/core/contracts";
|
|
3
4
|
import { TOOL_CALL_TOOL, TOOLS_CAPABILITY_ID, agentFrom, withHttpTarget, } from "@nylorun/core/define";
|
|
4
5
|
import { definitionFor } from "../definition/agent-definition.js";
|
|
@@ -43,7 +44,7 @@ export async function runDurable(options) {
|
|
|
43
44
|
const inFlight = new Set();
|
|
44
45
|
// Effect ids are derived from stable names, never call order, so replays line up.
|
|
45
46
|
const effect = async (kind, input, context, identity, target = {}) => {
|
|
46
|
-
const effectId =
|
|
47
|
+
const effectId = effectIdOf(checkpoint.turnId, checkpoint.segment, kind, identity);
|
|
47
48
|
const request = JSON.parse(JSON.stringify({
|
|
48
49
|
effectId,
|
|
49
50
|
sessionId: checkpoint.sessionId,
|
|
@@ -78,8 +79,7 @@ export async function runDurable(options) {
|
|
|
78
79
|
...(tool.description === undefined ? {} : { description: tool.description }),
|
|
79
80
|
inputSchema: schemaFromJSON(tool.inputSchema),
|
|
80
81
|
...(tool.outputSchema ? { outputSchema: schemaFromJSON(tool.outputSchema) } : {}),
|
|
81
|
-
//
|
|
82
|
-
...(tool.approval === "always" ? { approval: () => true } : {}),
|
|
82
|
+
// No approval here: the Tool Gate holds a call its policy asks a person about (R5 step 2).
|
|
83
83
|
async execute(args, ctx) {
|
|
84
84
|
const previous = patchTail;
|
|
85
85
|
let release;
|
|
@@ -137,6 +137,7 @@ export async function runDurable(options) {
|
|
|
137
137
|
// HTTP tool keeps its target (the manifest's hash covers it) and runs as a host effect.
|
|
138
138
|
for (const tool of capability.tools ?? [])
|
|
139
139
|
if (tool.http)
|
|
140
|
+
// A pinned `approval` stays for the definition's hash; the Tool Gate holds the call.
|
|
140
141
|
tools[tool.name] = withHttpTarget(hostedTool(capability.id, tool), {
|
|
141
142
|
http: tool.http,
|
|
142
143
|
...(tool.approval === undefined ? {} : { approval: tool.approval }),
|
|
@@ -219,8 +220,8 @@ function scoped(ref, identity) {
|
|
|
219
220
|
* `tool_call` (R2b C10): runs a deferred tool by name, as that tool's own call. It checks the
|
|
220
221
|
* arguments against the tool's `inputSchema` first, so a mistake comes back to the model as a
|
|
221
222
|
* failed result it can fix. The effect then names the tool, so the host routes it, shapes its
|
|
222
|
-
* result and records `tool.completed` as for a direct call
|
|
223
|
-
*
|
|
223
|
+
* result and records `tool.completed` as for a direct call, and the Tool Gate holds it as it
|
|
224
|
+
* would a direct call.
|
|
224
225
|
*/
|
|
225
226
|
function deferredToolCall(tool, deferred, hostedTool) {
|
|
226
227
|
const hosted = new Map();
|
|
@@ -228,19 +229,10 @@ function deferredToolCall(tool, deferred, hostedTool) {
|
|
|
228
229
|
const name = args?.name;
|
|
229
230
|
return typeof name === "string" ? deferred.get(name) : undefined;
|
|
230
231
|
};
|
|
231
|
-
const gated = [...deferred.values()].some((item) => item.approval === "always");
|
|
232
232
|
return {
|
|
233
233
|
name: tool.name,
|
|
234
234
|
...(tool.description === undefined ? {} : { description: tool.description }),
|
|
235
235
|
inputSchema: schemaFromJSON(tool.inputSchema),
|
|
236
|
-
...(gated
|
|
237
|
-
? {
|
|
238
|
-
approval: (args) => {
|
|
239
|
-
const target = targetOf(args);
|
|
240
|
-
return target?.approval === "always" ? `Approve ${target.name}?` : undefined;
|
|
241
|
-
},
|
|
242
|
-
}
|
|
243
|
-
: {}),
|
|
244
236
|
async execute(args, ctx) {
|
|
245
237
|
const call = args;
|
|
246
238
|
const target = targetOf(call);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nylorun/harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0-beta",
|
|
4
4
|
"description": "Nylorun's TypeScript agent execution engine. See github.com/nylorun/agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/nylorun/agents.git",
|
|
10
|
-
"directory": "harness"
|
|
10
|
+
"directory": "runtime/harness"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://github.com/nylorun/agents",
|
|
13
13
|
"bugs": "https://github.com/nylorun/agents/issues",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"node": "^22.14.0 || ^24.0.0 || >=26.0.0"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
|
-
"build": "npm run clean && node
|
|
60
|
+
"build": "npm run clean && node ../../scripts/check-typescript-version.mjs && tsc -p tsconfig.json",
|
|
61
61
|
"check": "npm run format:check && npm run build && npm run test:types && npm test && node scripts/check-package.mjs",
|
|
62
|
-
"typecheck": "node
|
|
62
|
+
"typecheck": "node ../../scripts/check-typescript-version.mjs && tsc -p tsconfig.json --noEmit",
|
|
63
63
|
"test": "vitest run",
|
|
64
64
|
"test:types": "tsc -p test/types/tsconfig.json",
|
|
65
65
|
"format": "prettier --write .",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"eval:compaction": "vitest run test/compaction-eval.test.ts"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@types/node": "^26.
|
|
72
|
+
"@types/node": "^26.6.4",
|
|
73
73
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
74
74
|
"prettier": "^3.9.9",
|
|
75
75
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"zod": "^4.6.5"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@nylorun/core": "0.
|
|
80
|
+
"@nylorun/core": "0.20.0-beta"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"zod": "^4.6.5"
|