observation: deliver one execution event sequence to stream and snapshot

This commit is contained in:
Codex committed 2026-11-24 15:30:18 +08:00
1 parent f83d992c61
commit 404d559b86
97 files changed
+2672 -3128

No files matched your search

-340
View File
@@ -1,340 +0,0 @@
# Execution Events v1
Status: **implemented by `marqdo run/call --event-stream jsonl`** (P0 and P1 of
RFC-OBS-0001). It is an independent public protocol: it is not Analysis v2,
not Trace v2 and not Tool Protocol v1. The decision record is
[ADR-0059](../docs/adr/0059-runtime-observability-and-execution-events.md); the
design input is [RFC-OBS-0001](../docs/architecture/RFC-OBS-0001-runtime-observability.md).
## 1. Transport and negotiation
* Media type: `application/x-ndjson` (JSON Lines). One complete UTF-8 JSON
object per line, terminated by `\n`; no unescaped newline occurs inside an
event.
* The stream uses the CLI stdout as a **dedicated machine channel**. While
`--event-stream jsonl` is active, the program's `stdout` and `stderr` are
carried only as `stdout.chunk` / `stderr.chunk` events and are not written
raw to stdout. Human diagnostics may still go to OS stderr.
* `--event-stream jsonl` is available only on `run` and `call`. It is
mutually exclusive with `--json`; `check`, `inspect`, `fmt`, `tool` and the
other static commands reject the option. `--trace-file` may be combined.
* `--mode strict` currently rejects `--event-stream` with a structured
`run.rejected` (`strict.unsupported_grant`); there is no silent downgrade to
`project`.
* The consumer checks the negotiated protocol from `stream.opened`
(`schema` + `schema_version`). Consumers **must reject unknown major
versions**, and must not silently treat another major as v1.
* A consumer that cannot read the stream (slow, closed pipe, killed process)
may see a truncated final line or no terminal event. It must report
`incomplete`; it must never synthesize a successful terminal event.
## 2. Envelope
Every normal line has exactly these top-level fields:
```json
{
"schema": "marqdo.execution-events",
"schema_version": 1,
"run_id": "12345-1700000000000000000",
"seq": 2,
"kind": "call.enter",
"payload": {}
}
```
| Field | Type | Meaning |
|---|---|---|
| `schema` | string | Always `marqdo.execution-events`. |
| `schema_version` | integer | Major version; currently `1`. |
| `run_id` | string | Opaque identity of this one run. Never an OS PID used as a cross-run identity. Different for every invocation, including repeated runs in one process. |
| `seq` | integer | Global, strictly increasing, starts at 0, assigned by one dispatcher. `seq` is the event sequence, not a frame or iteration identity. |
| `kind` | string | Stable namespaced event name. New kinds are additive; consumers ignore unknown kinds. |
| `payload` | object | Kind-specific object defined below. Unknown optional fields are ignored. |
Event ordering is the order of admission to the single dispatcher. Independent
OS streams (for example a foreign subprocess writing its own fd) do not have a
portable physical ordering and are not part of this protocol.
## 3. Lifecycle and event kinds
Exactly one `stream.opened` is written when the JSONL writer is initialized,
before project preparation. At most one `run.started` is written. On success or
failure there is exactly one terminal event, and no event is written after it.
The normal order is:
```text
stream.opened (seq 0)
-> run.rejected (prepare/authorization/compile failure)
or run.started -> ... -> run.completed | run.failed
```
`run.completed`, `run.failed` and `run.rejected` are the only terminal events.
`SIGKILL`, a crash or a broken pipe may leave the stream without a terminal
event; that is a legitimate `incomplete` boundary.
### 3.1 `stream.opened` (base, seq 0)
Required payload fields:
```json
{
"producer": {"name": "marqdo", "version": "3.0.0-beta.1"},
"protocol": {"name": "marqdo.execution-events", "schema_version": 1},
"observation": {
"level": "structural",
"values": false,
"selected_variables": [],
"selected_parameters": [],
"allow_text_values": false
},
"limits": {
"max_observation_events": 100000,
"max_observation_bytes": 16777216,
"max_value_bytes": 256
}
}
```
`observation.level` is `base`, `structural` or `values`. It reports what the
producer is willing to publish, not a security grant. `stream.opened` does not
carry a source identity because no project has been prepared yet.
### 3.2 `run.started` (base)
Required payload fields: `entry`, `mode`, `source`; optional
`started_unix_ms` for diagnostics only.
```json
{
"entry": "root:demo@0.1.0::index.mq.md::main",
"mode": "project",
"source": {
"root_id": "root:demo@0.1.0",
"analysis_digest": "sha256:<64 lowercase hex>"
},
"started_unix_ms": 1763800000000
}
```
`source.analysis_digest` is `sha256:` plus the SHA-256 of the **exact bytes**
of the [Analysis file](analysis-v3.md) produced for the same project and projection
configuration (not a re-serialization of the in-memory IR). If the source
changes, existing events become stale; consumers must not render them onto the
new source.
### 3.3 `stdout.chunk` / `stderr.chunk` (base)
Required payload fields:
```json
{"encoding": "base64", "data_base64": "5byA5aeL5paH5pysCg==", "byte_count": 13}
```
* `encoding` is `base64` (standard alphabet, padded).
* `data_base64` is the byte-exact data. Invalid UTF-8, NUL, binary bytes and
split multi-byte characters are preserved.
* `byte_count` equals the decoded byte length. A consumer must verify it.
* Chunks are bounded (implementation maximum 64 KiB before base64 encoding);
a larger host write is split into consecutive chunks in order.
* These events are emitted at the host's real commit point: bytes are exactly
those accepted by the host output budget. A rejected write emits nothing.
* All committed chunk events precede the terminal event. Concatenating the
decoded bytes must equal the bytes a normal run writes to stdout/stderr for
the same arguments and grants.
### 3.4 Structural events (structural)
| Kind | Required payload fields |
|---|---|
| `call.enter` | `frame_id`, `parent_frame_id`, `function_id`, `module_id`, `span` |
| `call.exit` | `frame_id`, `status`, `module_id`, `span` |
| `return` | `frame_id`, `value_type`, `module_id`, `span` |
| `branch.eval` | `frame_id`, `result`, `module_id`, `span` |
| `loop.iteration` | `frame_id`, `decision`, `module_id`, `span` |
| `control.break`, `control.continue` | `frame_id`, `module_id`, non-null `span` |
| `effect` | `operation`, `result_code`, `module_id`, `span` |
* `frame_id` is an opaque run-unique string (`f1`, `f2`, ...). It identifies
one call instance, not a function and not a source location.
* `parent_frame_id` is `null` for the entry frame, otherwise the direct
caller's `frame_id`.
* A frame is announced by `call.enter` only **after** argument binding
succeeded. A binding failure produces no frame. Every entered frame that is
not cut off by transport loss/truncation gets exactly one `call.exit`;
`return` (when present) precedes `call.exit`.
* `call.exit.status` is `ok`, `return`, or a stable runtime error code.
* `branch.eval.result` is a JSON boolean. `loop.iteration.decision` is
`continue` (body will execute) or `exit` (condition was false). The event is
emitted once per condition evaluation; iteration indices are not part of v1.
* `control.break` and `control.continue` report an executed transfer at
its carrier span. The frame stays active. A continue precedes the next
condition check, and a break skips further checks of the loop it exits.
The structural event budget applies to both events.
* `effect.result_code` is a non-sensitive result summary (for example `ok` or a
stable error code). It never carries effect arguments or file contents.
* `module_id` is a logical package module id; `span` is
`{"start": <byte>, "end": <byte>}` in UTF-8 source offsets, or `null`. A
span must belong to the declared module.
Example:
```json
{"schema":"marqdo.execution-events","schema_version":1,"run_id":"r1","seq":3,"kind":"call.enter","payload":{"frame_id":"f1","parent_frame_id":null,"function_id":"root:demo@0.1.0::index.mq.md::main","module_id":"root:demo@0.1.0::index.mq.md","span":null}}
```
### 3.5 Value observation events (values)
`variable.assigned` required payload fields: `frame_id`, `name`,
`value_type`, `module_id`, `span`, `value_state`; optional `value` when
`value_state` is `observed` or `truncated`.
`parameter.observed` required payload fields: `frame_id`, `name`, `source`,
`value_type`, `module_id`, `span`, `value_state`; optional `value`. `source`
is `provided` or `default` (a source default is a real runtime value but not a
user-provided argument).
`value_state` is one of:
| State | Meaning |
|---|---|
| `not_requested` | The name was not selected for observation; no value is encoded. |
| `redacted` | The name was selected but policy hides the value (for example `Text` without `--observe-text-values`). |
| `truncated` | The value was encoded but exceeded `max_value_bytes`; `value` is the safe prefix. |
| `unsupported` | The value type is not a v1 scalar; only its type is reported. |
| `observed` | The scalar value is encoded normally. |
Value encoding reuses the `marqdo.value.v1` wire representation of the value:
`{"type":"int","decimal":"42"}`, `{"type":"float","value":1.5}`,
`{"type":"bool","value":true}`, `{"type":"text","value":"..."}`. For a
truncated text the object also carries `"truncated": true` and
`"original_byte_count": <n>`. Text truncation never splits a UTF-8 scalar.
Lists, maps, tables, formulas, code, memory, resources and plugin handles are
`unsupported`; they are never recursed into and handles are never serialized.
A text value is never published without the explicit
`--observe-text-values` consent, even when the name was selected. A
`--observe-max-value-bytes` value of `0` means unlimited; otherwise text is
cut only at a UTF-8 scalar boundary and marked `truncated`.
`variable.assigned` is emitted only after the assignment was actually
committed. It never re-evaluates the right-hand side and never back-fills the
final value of a variable into an earlier assignment.
### 3.6 `observation.truncated` (any)
Required payload fields: `reason`, `limit`, `written`, `dropped`. `reason` is
`event_budget` or `byte_budget`. It is emitted at most once per run, only when
the structural/value observation budget is exhausted. It does not stop
stdout/stderr events or the terminal event. `dropped` may be `null` when the
producer cannot know the exact count.
### 3.7 Terminal events (base)
`run.completed`:
```json
{"status":"ok","value":{"type":"int","decimal":"10"}}
```
`run.failed`:
```json
{"status":"error","error":{"code":"runtime.type","message":"safe diagnostic message","module_id":"root:demo@0.1.0::index.mq.md","span":{"start":120,"end":141}}}
```
`run.rejected`:
```json
{"status":"rejected","phase":"prepare","error":{"code":"frontmatter.invalid","message":"safe diagnostic message"}}
```
* `run.completed.value` uses the same wire encoding as `run/call --json`.
* `run.failed.error.code` reuses the existing stable runtime error family; the
message is the same safe diagnostic text already printed to humans. It does
not add argument values, secrets, file contents or memory bytes.
* `run.rejected.phase` is `options`, `prepare`, `compile`, `authorization` or
`strict`. It distinguishes failures before execution started.
* A terminal event is written only after all committed chunk events. A
`run.completed` does not claim the consumer has read or displayed the bytes.
## 4. Budgets, backpressure and failure
Three separate resources exist and are never conflated:
1. **Execution budgets** (`--fuel`, `--timeout`, `--max-output`, memory
budgets). Observation never widens them. A rejected host output write emits
no chunk event.
2. **Observable structural/value budget.** Defaults are 100 000 events and
16 MiB, adjustable with `--observe-max-events` / `--observe-max-bytes`
(`0` = unlimited). Exhaustion truncates only these events and emits
`observation.truncated`.
3. **Critical transport events.** `stream.opened`, `run.started`, stdout/stderr
chunks and the terminal event are not dropped by the structural budget.
Writes are synchronous and bounded. A slow consumer exerts IO backpressure on
the run; the CLI must not accumulate an unbounded queue or spawn an unbounded
event thread. If the JSONL writer fails (closed pipe, write error), the run
must fail with `observe.transport_failed`, return a non-zero exit status and
stop a program that would otherwise keep producing side effects. The CLI must
not write a partial JSON line after a failure. Side effects that already
happened are not rolled back and must not be claimed as rolled back.
If event transport is truncated but still writable (structural budget), the
program's language behavior, return value, output bytes and capability
authorization are unchanged.
## 5. Value policy and security
* Event mode is not a capability grant and cannot enable network, filesystem,
process, foreign, provider or plugin access. `pure`, `project` and `strict`
keep their documented policy; if a project extension is rejected in a mode,
event mode is rejected for the same reason.
* Observation is off by default. Type/status metadata is the default; raw
values require an explicit exact-name selection. Text requires a second
explicit consent. Selection is not automatic from a manifest, View setting
or environment.
* Program stdout/stderr may contain secrets by the program's own intent; the
protocol preserves bytes and does not promise automatic redaction of program
output.
* Trace v2 and Analysis never gain argument/local values, handles, memory
bytes or new secret-bearing fields through this protocol.
* A third-party extension's raw OS stdout/stderr must not pollute the JSONL
channel. Such output remains external process data: it is either captured by
the controlled host transport or the combination is unsupported/fail-closed.
In particular, an in-process **native plugin** can write fd 1 directly, so an
event-mode run that selects one is rejected with
`ext.event_stream_unsupported_native_plugin` before loading; use a worker
plugin or disable event mode.
* Tests use synthetic sentinel values and assert that unselected values never
appear in the stream, Trace or `--json`.
## 6. Relation to Analysis and Trace v2
| Artifact | Relation |
|---|---|
| Analysis v2/v3 | Static only. `run.started.source` binds to its exact bytes via `analysis_digest`. Events never replace it. |
| Trace v2 | Unchanged schema/version and privacy promise. In a combined run both writers share the CLI-generated `run_id`; Trace v2 gains no frame/value fields and is still published atomically after the run. |
| Tool Protocol v1 | Unchanged. A consumer invokes the released binary via `MARQDO_BIN` and negotiates by reading `stream.opened`; `tool.json` does not implicitly advertise an `events` field. |
| View SSE | Implemented by the View repository by adapting this JSONL stream. The CLI implements no HTTP/SSE. |
## 7. Versioning and compatibility
* Independent major version `1`, not tied to the product version or Trace v2.
* Additive optional fields and new event kinds are allowed in v1. Changing a
required field's meaning, ordering guarantees, redaction promise, source
digest definition or making private data public by default requires a new
major.
* Consumers must ignore unknown `kind` and unknown optional fields, and must
reject unknown `schema_version` majors.
* `--help`, `docs/developers/analysis-trace.md`,
`docs/developers/compatibility.md` and `COMPATIBILITY.md` list the protocol
and its exact option names.
## 8. Test fixtures and consumers
* Schema: [`schemas/execution-events-v1.schema.json`](schemas/execution-events-v1.schema.json).
* Independent consumer: `tests/consumers/execution_events_consumer.py`.
* Fixtures: `tests/consumers/fixtures/execution-events/`.
* Rust gate: `crates/cli/tests/execution_events.rs` runs the real binary and
checks envelope, sequence, base64 byte fidelity, terminal behavior,
redaction, frames, traces and output purity.
+78
View File
@@ -0,0 +1,78 @@
# Marqdo Observation
`run` and `call` execute once through the interpreter and capability Host.
The Host emits typed observations at execution boundaries. The CLI assigns
one run ID and one sequence and serializes each public event once.
```sh
marqdo call index.mq.md calculate --arg n=3 --output jsonl
marqdo call index.mq.md calculate --arg n=3 --output json
marqdo call index.mq.md calculate --arg n=3 --output jsonl --observation-file run.json
marqdo check index.mq.md --emit analysis.json
```
Text is the default output. JSONL flushes each event to stdout as it occurs.
JSON writes one snapshot to stdout after the run. `--observation-file`
atomically publishes a snapshot through a private temporary file in the
destination directory. On Unix the published file is private to the caller.
Every destination in one invocation receives the same events. Diagnostics
use OS stderr. Captured program stdout and stderr are byte events, with
standard padded base64 and a decoded byte count. Both may contain sensitive
program output. Machine destinations refuse in-process native plugins.
Strict mode supports text and JSON stdout through its isolation supervisor.
Live and file destinations are rejected in strict mode.
## Event contract
Each object has `schema: "marqdo.observation"`, `schema_version: 1`, an
opaque `run_id`, zero-based contiguous `seq`, `kind` and `payload`. See
the [event schema](schemas/observation-event.schema.json) for the exact
fields. Reject other format identifiers, unknown kinds and invalid payloads.
- `stream.opened` is first, with producer, capture policy and budget limits.
- `run.started` binds an entry, mode and source. `source.root_id` and
`source.analysis_digest` identify the exact Analysis JSON emitted by
`check --emit` for the same project and static options. The digest is
SHA-256 over the file bytes, including formatting. Before highlighting a
source span, validate the binding, module source digest and original UTF-8
half-open byte range. A changed source or Analysis invalidates attribution.
- `call.enter` identifies the call instance and its parent. `call.exit`
closes that same instance. Call carriers belong to the caller module.
Parameter spans identify declarations in the called module.
- `branch.eval`, `loop.iteration`, `control.break`, `control.continue`,
`return` and `effect` record actual execution in order. An effect
includes its operation, result code and source location where available.
- `parameter.observed` and `variable.assigned` carry names, types and
source locations. Values are omitted by default. Select exact names
with `--observe-parameter` and `--observe-variable`. Selected Text also
requires `--observe-text-values`. The same consent applies to file and
stream. Only supported scalars are recorded. Memory, resources and plugin
handles are never included.
- `observation.truncated` reports the first exhausted observation budget.
Structural and selected-value events may stop at that point. Lifecycle
and committed byte chunks remain subject to their own execution and
output limits. The interpreter continues under unchanged program limits.
- `run.completed` contains the explicit return using [Value Wire](value-wire.md).
A result containing a non-transferable handle has a null wire value and
identifies its type. An explicit result, like a program print, can itself
contain sensitive data. `run.failed` follows a started run and contains
the error. `run.rejected` reports failure before start. A complete run
has exactly one terminal event, last. EOF or interrupted delivery without
a terminal is incomplete.
## Snapshot contract
The [snapshot schema](schemas/observation-file.schema.json) describes a
JSON object with the same format identifier, `run` metadata, `capture`
metadata, and `events` validated against the event schema. The `run.id`
matches every event, `run.source` matches the start event or is null,
and `run.status` agrees with the terminal. `capture.truncated` matches
the truncation event or is null. A supervisor that cannot obtain complete
child output may report an incomplete stdout snapshot without a terminal.
An interrupted file write does not replace the previously published file.
EOF during an interrupted stream can leave a partial final line.
Validate schema, sequence, lifecycle and source binding before using
the artifact. A structurally truncated run has a terminal but lacks some
execution events. An incomplete delivery provides no evidence about
the final execution outcome.
@@ -1,291 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://marqdo.dev/schemas/execution-events-v1.schema.json",
"title": "Marqdo Execution Events v1",
"description": "One line of the marqdo.execution-events v1 NDJSON stream.",
"type": "object",
"required": ["schema", "schema_version", "run_id", "seq", "kind", "payload"],
"properties": {
"schema": {"const": "marqdo.execution-events"},
"schema_version": {"const": 1},
"run_id": {"type": "string", "minLength": 1},
"seq": {"type": "integer", "minimum": 0},
"kind": {"type": "string", "minLength": 1},
"payload": {"type": "object"}
},
"additionalProperties": true,
"allOf": [
{
"if": {"required": ["kind"], "properties": {"kind": {"const": "stream.opened"}}},
"then": {
"properties": {
"payload": {
"type": "object",
"required": ["producer", "protocol", "observation", "limits"],
"properties": {
"producer": {
"type": "object",
"required": ["name", "version"],
"properties": {
"name": {"const": "marqdo"},
"version": {"type": "string", "minLength": 1}
},
"additionalProperties": true
},
"protocol": {
"type": "object",
"required": ["name", "schema_version"],
"properties": {
"name": {"const": "marqdo.execution-events"},
"schema_version": {"const": 1}
},
"additionalProperties": true
},
"observation": {
"type": "object",
"required": ["level", "values", "selected_variables", "selected_parameters", "allow_text_values"],
"properties": {
"level": {"enum": ["base", "structural", "values"]},
"values": {"type": "boolean"},
"selected_variables": {"type": "array", "items": {"type": "string"}},
"selected_parameters": {"type": "array", "items": {"type": "string"}},
"allow_text_values": {"type": "boolean"}
},
"additionalProperties": true
},
"limits": {
"type": "object",
"required": ["max_observation_events", "max_observation_bytes", "max_value_bytes"],
"properties": {
"max_observation_events": {"type": "integer", "minimum": 0},
"max_observation_bytes": {"type": "integer", "minimum": 0},
"max_value_bytes": {"type": "integer", "minimum": 0}
},
"additionalProperties": true
}
},
"additionalProperties": true
}
}
}
},
{
"if": {"required": ["kind"], "properties": {"kind": {"const": "run.started"}}},
"then": {
"properties": {
"payload": {
"type": "object",
"required": ["entry", "mode", "source"],
"properties": {
"entry": {"type": "string", "minLength": 1},
"mode": {"enum": ["pure", "project", "strict"]},
"source": {
"type": "object",
"required": ["root_id", "analysis_digest"],
"properties": {
"root_id": {"type": "string", "pattern": "^(root:|sha256:[0-9a-f]{64}$)"},
"analysis_digest": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"}
},
"additionalProperties": true
},
"started_unix_ms": {"type": "integer", "minimum": 0}
},
"additionalProperties": true
}
}
}
},
{
"if": {"required": ["kind"], "properties": {"kind": {"enum": ["stdout.chunk", "stderr.chunk"]}}},
"then": {
"properties": {
"payload": {
"type": "object",
"required": ["encoding", "data_base64", "byte_count"],
"properties": {
"encoding": {"const": "base64"},
"data_base64": {"type": "string", "contentEncoding": "base64"},
"byte_count": {"type": "integer", "minimum": 0}
},
"additionalProperties": true
}
}
}
},
{
"if": {"required": ["kind"], "properties": {"kind": {"const": "call.enter"}}},
"then": {
"properties": {
"payload": {
"type": "object",
"required": ["frame_id", "parent_frame_id", "function_id", "module_id", "span"],
"properties": {
"frame_id": {"type": "string", "pattern": "^f[0-9]+$"},
"parent_frame_id": {"oneOf": [{"type": "null"}, {"type": "string", "pattern": "^f[0-9]+$"}]},
"function_id": {"type": "string", "minLength": 1},
"module_id": {"type": "string", "minLength": 1},
"span": {"$ref": "#/$defs/span"}
},
"additionalProperties": true
}
}
}
},
{
"if": {"required": ["kind"], "properties": {"kind": {"enum": ["call.exit", "return", "branch.eval", "loop.iteration", "effect"]}}},
"then": {
"properties": {
"payload": {
"type": "object",
"required": ["module_id", "span"],
"properties": {
"frame_id": {"type": "string", "pattern": "^f[0-9]+$"},
"status": {"type": "string", "minLength": 1},
"value_type": {"type": "string", "minLength": 1},
"result": {"type": "boolean"},
"decision": {"enum": ["continue", "exit"]},
"operation": {"type": "string", "minLength": 1},
"result_code": {"type": "string", "minLength": 1},
"module_id": {"type": "string", "minLength": 1},
"span": {"$ref": "#/$defs/span"}
},
"additionalProperties": true
}
}
}
},
{
"if": {"required": ["kind"], "properties": {"kind": {"enum": ["control.break", "control.continue"]}}},
"then": {
"properties": {
"payload": {
"type": "object",
"required": ["frame_id", "module_id", "span"],
"properties": {
"frame_id": {"type": "string", "pattern": "^f[0-9]+$"},
"module_id": {"type": "string", "minLength": 1},
"span": {"type": "object", "$ref": "#/$defs/span"}
},
"additionalProperties": true
}
}
}
},
{
"if": {"required": ["kind"], "properties": {"kind": {"enum": ["variable.assigned", "parameter.observed"]}}},
"then": {
"properties": {
"payload": {
"type": "object",
"required": ["frame_id", "name", "value_type", "module_id", "span", "value_state"],
"properties": {
"frame_id": {"type": "string", "pattern": "^f[0-9]+$"},
"name": {"type": "string", "minLength": 1},
"source": {"enum": ["provided", "default"]},
"value_type": {"type": "string", "minLength": 1},
"module_id": {"type": "string", "minLength": 1},
"span": {"$ref": "#/$defs/span"},
"value_state": {"enum": ["not_requested", "redacted", "truncated", "unsupported", "observed"]},
"value": {"type": ["object", "null"]}
},
"additionalProperties": true
}
}
}
},
{
"if": {"required": ["kind"], "properties": {"kind": {"const": "observation.truncated"}}},
"then": {
"properties": {
"payload": {
"type": "object",
"required": ["reason", "limit", "written", "dropped"],
"properties": {
"reason": {"enum": ["event_budget", "byte_budget"]},
"limit": {"type": "integer", "minimum": 0},
"written": {"type": "integer", "minimum": 0},
"dropped": {"type": ["integer", "null"], "minimum": 0}
},
"additionalProperties": true
}
}
}
},
{
"if": {"required": ["kind"], "properties": {"kind": {"const": "run.completed"}}},
"then": {
"properties": {
"payload": {
"type": "object",
"required": ["status", "value"],
"properties": {
"status": {"const": "ok"},
"value": {"type": "object"}
},
"additionalProperties": true
}
}
}
},
{
"if": {"required": ["kind"], "properties": {"kind": {"const": "run.failed"}}},
"then": {
"properties": {
"payload": {
"type": "object",
"required": ["status", "error"],
"properties": {
"status": {"const": "error"},
"error": {"$ref": "#/$defs/error"}
},
"additionalProperties": true
}
}
}
},
{
"if": {"required": ["kind"], "properties": {"kind": {"const": "run.rejected"}}},
"then": {
"properties": {
"payload": {
"type": "object",
"required": ["status", "phase", "error"],
"properties": {
"status": {"const": "rejected"},
"phase": {"enum": ["options", "prepare", "compile", "authorization", "strict"]},
"error": {"$ref": "#/$defs/error"}
},
"additionalProperties": true
}
}
}
}
],
"$defs": {
"span": {
"oneOf": [
{"type": "null"},
{
"type": "object",
"required": ["start", "end"],
"properties": {
"start": {"type": "integer", "minimum": 0},
"end": {"type": "integer", "minimum": 0}
},
"additionalProperties": true
}
]
},
"error": {
"type": "object",
"required": ["code", "message"],
"properties": {
"code": {"type": "string", "minLength": 1},
"message": {"type": "string"},
"module_id": {"type": ["string", "null"]},
"span": {"$ref": "#/$defs/span"}
},
"additionalProperties": true
}
}
}
+855
View File
@@ -0,0 +1,855 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://marqdo.dev/schemas/observation-event.schema.json",
"title": "Marqdo Observation Event",
"description": "One event shared by live JSONL and JSON snapshots.",
"type": "object",
"required": [
"schema",
"schema_version",
"run_id",
"seq",
"kind",
"payload"
],
"properties": {
"schema": {
"const": "marqdo.observation"
},
"schema_version": {
"const": 1
},
"run_id": {
"type": "string",
"minLength": 1
},
"seq": {
"type": "integer",
"minimum": 0
},
"kind": {
"enum": [
"stream.opened",
"run.started",
"call.enter",
"observation.truncated",
"run.completed",
"run.failed",
"run.rejected",
"stdout.chunk",
"stderr.chunk",
"call.exit",
"return",
"branch.eval",
"loop.iteration",
"effect",
"control.break",
"control.continue",
"variable.assigned",
"parameter.observed"
]
},
"payload": {
"type": "object"
}
},
"additionalProperties": false,
"allOf": [
{
"if": {
"required": [
"kind"
],
"properties": {
"kind": {
"const": "stream.opened"
}
}
},
"then": {
"properties": {
"payload": {
"type": "object",
"required": [
"producer",
"observation",
"limits"
],
"properties": {
"producer": {
"type": "object",
"required": [
"name",
"version"
],
"properties": {
"name": {
"const": "marqdo"
},
"version": {
"type": "string",
"minLength": 1
}
},
"additionalProperties": true
},
"observation": {
"type": "object",
"required": [
"level",
"values",
"selected_variables",
"selected_parameters",
"allow_text_values"
],
"properties": {
"level": {
"enum": [
"base",
"structural",
"values"
]
},
"values": {
"type": "boolean"
},
"selected_variables": {
"type": "array",
"items": {
"type": "string"
}
},
"selected_parameters": {
"type": "array",
"items": {
"type": "string"
}
},
"allow_text_values": {
"type": "boolean"
}
},
"additionalProperties": true
},
"limits": {
"type": "object",
"required": [
"max_observation_events",
"max_observation_bytes",
"max_value_bytes"
],
"properties": {
"max_observation_events": {
"type": "integer",
"minimum": 0
},
"max_observation_bytes": {
"type": "integer",
"minimum": 0
},
"max_value_bytes": {
"type": "integer",
"minimum": 0
}
},
"additionalProperties": true
}
},
"additionalProperties": true
}
}
}
},
{
"if": {
"required": [
"kind"
],
"properties": {
"kind": {
"const": "run.started"
}
}
},
"then": {
"properties": {
"payload": {
"type": "object",
"required": [
"entry",
"mode",
"source"
],
"properties": {
"entry": {
"type": "string",
"minLength": 1
},
"mode": {
"enum": [
"pure",
"project",
"strict"
]
},
"source": {
"type": "object",
"required": [
"root_id",
"analysis_digest"
],
"properties": {
"root_id": {
"type": "string",
"pattern": "^(root:|sha256:[0-9a-f]{64}$)"
},
"analysis_digest": {
"type": "string",
"pattern": "^sha256:[0-9a-f]{64}$"
}
},
"additionalProperties": true
},
"started_unix_ms": {
"type": "integer",
"minimum": 0
}
},
"additionalProperties": true
}
}
}
},
{
"if": {
"required": [
"kind"
],
"properties": {
"kind": {
"enum": [
"stdout.chunk",
"stderr.chunk"
]
}
}
},
"then": {
"properties": {
"payload": {
"type": "object",
"required": [
"encoding",
"data_base64",
"byte_count"
],
"properties": {
"encoding": {
"const": "base64"
},
"data_base64": {
"type": "string",
"contentEncoding": "base64"
},
"byte_count": {
"type": "integer",
"minimum": 0
}
},
"additionalProperties": true
}
}
}
},
{
"if": {
"required": [
"kind"
],
"properties": {
"kind": {
"const": "call.enter"
}
}
},
"then": {
"properties": {
"payload": {
"type": "object",
"required": [
"frame_id",
"parent_frame_id",
"function_id",
"module_id",
"span"
],
"properties": {
"frame_id": {
"type": "string",
"pattern": "^f[0-9]+$"
},
"parent_frame_id": {
"oneOf": [
{
"type": "null"
},
{
"type": "string",
"pattern": "^f[0-9]+$"
}
]
},
"function_id": {
"type": "string",
"minLength": 1
},
"module_id": {
"type": "string",
"minLength": 1
},
"span": {
"$ref": "#/$defs/span"
}
},
"additionalProperties": true
}
}
}
},
{
"if": {
"properties": {
"kind": {
"const": "call.exit"
}
}
},
"then": {
"properties": {
"payload": {
"required": [
"frame_id",
"status",
"module_id",
"span"
],
"properties": {
"frame_id": {
"type": "string",
"pattern": "^f[0-9]+$"
},
"status": {
"type": "string",
"minLength": 1
},
"module_id": {
"type": "string",
"minLength": 1
},
"span": {
"$ref": "#/$defs/span"
}
},
"additionalProperties": false
}
}
}
},
{
"if": {
"properties": {
"kind": {
"const": "return"
}
}
},
"then": {
"properties": {
"payload": {
"required": [
"frame_id",
"value_type",
"module_id",
"span"
],
"properties": {
"frame_id": {
"type": "string",
"pattern": "^f[0-9]+$"
},
"value_type": {
"type": "string",
"minLength": 1
},
"module_id": {
"type": "string",
"minLength": 1
},
"span": {
"$ref": "#/$defs/span"
}
},
"additionalProperties": false
}
}
}
},
{
"if": {
"properties": {
"kind": {
"const": "branch.eval"
}
}
},
"then": {
"properties": {
"payload": {
"required": [
"frame_id",
"result",
"module_id",
"span"
],
"properties": {
"frame_id": {
"type": "string",
"pattern": "^f[0-9]+$"
},
"result": {
"type": "boolean"
},
"module_id": {
"type": "string",
"minLength": 1
},
"span": {
"$ref": "#/$defs/span"
}
},
"additionalProperties": false
}
}
}
},
{
"if": {
"properties": {
"kind": {
"const": "loop.iteration"
}
}
},
"then": {
"properties": {
"payload": {
"required": [
"frame_id",
"decision",
"module_id",
"span"
],
"properties": {
"frame_id": {
"type": "string",
"pattern": "^f[0-9]+$"
},
"decision": {
"enum": [
"continue",
"exit"
]
},
"module_id": {
"type": "string",
"minLength": 1
},
"span": {
"$ref": "#/$defs/span"
}
},
"additionalProperties": false
}
}
}
},
{
"if": {
"properties": {
"kind": {
"const": "effect"
}
}
},
"then": {
"properties": {
"payload": {
"required": [
"frame_id",
"operation",
"result_code",
"module_id",
"span"
],
"properties": {
"frame_id": {
"type": [
"string",
"null"
],
"pattern": "^f[0-9]+$"
},
"operation": {
"type": "string",
"minLength": 1
},
"result_code": {
"type": "string",
"minLength": 1
},
"module_id": {
"type": "string",
"minLength": 1
},
"span": {
"$ref": "#/$defs/span"
}
},
"additionalProperties": false
}
}
}
},
{
"if": {
"required": [
"kind"
],
"properties": {
"kind": {
"enum": [
"control.break",
"control.continue"
]
}
}
},
"then": {
"properties": {
"payload": {
"type": "object",
"required": [
"frame_id",
"module_id",
"span"
],
"properties": {
"frame_id": {
"type": "string",
"pattern": "^f[0-9]+$"
},
"module_id": {
"type": "string",
"minLength": 1
},
"span": {
"type": "object",
"$ref": "#/$defs/span"
}
},
"additionalProperties": true
}
}
}
},
{
"if": {
"required": [
"kind"
],
"properties": {
"kind": {
"enum": [
"variable.assigned",
"parameter.observed"
]
}
}
},
"then": {
"properties": {
"payload": {
"type": "object",
"required": [
"frame_id",
"name",
"value_type",
"module_id",
"span",
"value_state"
],
"properties": {
"frame_id": {
"type": "string",
"pattern": "^f[0-9]+$"
},
"name": {
"type": "string",
"minLength": 1
},
"source": {
"enum": [
"provided",
"default"
]
},
"value_type": {
"type": "string",
"minLength": 1
},
"module_id": {
"type": "string",
"minLength": 1
},
"span": {
"$ref": "#/$defs/span"
},
"value_state": {
"enum": [
"not_requested",
"redacted",
"truncated",
"unsupported",
"observed"
]
},
"value": {
"type": [
"object",
"null"
]
}
},
"additionalProperties": true
}
}
}
},
{
"if": {
"required": [
"kind"
],
"properties": {
"kind": {
"const": "observation.truncated"
}
}
},
"then": {
"properties": {
"payload": {
"type": "object",
"required": [
"reason",
"limit",
"written",
"dropped"
],
"properties": {
"reason": {
"enum": [
"event_budget",
"byte_budget"
]
},
"limit": {
"type": "integer",
"minimum": 0
},
"written": {
"type": "integer",
"minimum": 0
},
"dropped": {
"type": [
"integer",
"null"
],
"minimum": 0
}
},
"additionalProperties": true
}
}
}
},
{
"if": {
"required": [
"kind"
],
"properties": {
"kind": {
"const": "run.completed"
}
}
},
"then": {
"properties": {
"payload": {
"type": "object",
"required": [
"status",
"value",
"value_type"
],
"properties": {
"status": {
"const": "ok"
},
"value": {
"type": [
"object",
"null"
]
},
"value_type": {
"type": "string",
"minLength": 1
}
},
"additionalProperties": true
}
}
}
},
{
"if": {
"required": [
"kind"
],
"properties": {
"kind": {
"const": "run.failed"
}
}
},
"then": {
"properties": {
"payload": {
"type": "object",
"required": [
"status",
"error"
],
"properties": {
"status": {
"const": "error"
},
"error": {
"$ref": "#/$defs/error"
}
},
"additionalProperties": true
}
}
}
},
{
"if": {
"required": [
"kind"
],
"properties": {
"kind": {
"const": "run.rejected"
}
}
},
"then": {
"properties": {
"payload": {
"type": "object",
"required": [
"status",
"phase",
"error"
],
"properties": {
"status": {
"const": "rejected"
},
"phase": {
"enum": [
"options",
"prepare",
"compile",
"authorization",
"strict"
]
},
"error": {
"$ref": "#/$defs/error"
}
},
"additionalProperties": true
}
}
}
}
],
"$defs": {
"span": {
"oneOf": [
{
"type": "null"
},
{
"type": "object",
"required": [
"start",
"end"
],
"properties": {
"start": {
"type": "integer",
"minimum": 0
},
"end": {
"type": "integer",
"minimum": 0
}
},
"additionalProperties": true
}
]
},
"error": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "string",
"minLength": 1
},
"message": {
"type": "string"
},
"module_id": {
"type": [
"string",
"null"
]
},
"span": {
"$ref": "#/$defs/span"
}
},
"additionalProperties": true
}
}
}
+122
View File
@@ -0,0 +1,122 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://marqdo.dev/schemas/observation-file.schema.json",
"title": "Marqdo Observation Snapshot",
"type": "object",
"required": [
"schema",
"schema_version",
"run",
"capture",
"events"
],
"additionalProperties": false,
"properties": {
"schema": {
"const": "marqdo.observation"
},
"schema_version": {
"const": 1
},
"run": {
"type": "object",
"required": [
"id",
"status",
"source"
],
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"minLength": 1
},
"status": {
"enum": [
"ok",
"error",
"rejected",
"incomplete"
]
},
"source": {
"type": [
"object",
"null"
],
"if": {
"type": "object"
},
"then": {
"required": [
"root_id",
"analysis_digest"
],
"additionalProperties": false,
"properties": {
"root_id": {
"type": "string",
"minLength": 1
},
"analysis_digest": {
"type": "string",
"pattern": "^sha256:[0-9a-f]{64}$"
}
}
}
}
}
},
"capture": {
"type": "object",
"required": [
"level",
"values",
"selected_variables",
"selected_parameters",
"allow_text_values",
"truncated"
],
"additionalProperties": false,
"properties": {
"level": {
"enum": [
"structural",
"values"
]
},
"values": {
"type": "boolean"
},
"selected_variables": {
"type": "array",
"items": {
"type": "string"
}
},
"selected_parameters": {
"type": "array",
"items": {
"type": "string"
}
},
"allow_text_values": {
"type": "boolean"
},
"truncated": {
"type": [
"object",
"null"
]
}
}
},
"events": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "observation-event.schema.json"
}
}
}
}
-55
View File
@@ -1,55 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://marqdo.dev/schemas/trace-v1.schema.json",
"title": "Marqdo Trace v1",
"type": "object",
"required": ["schema", "schema_version", "run", "source", "events"],
"properties": {
"schema": {"const": "marqdo.trace"},
"schema_version": {"const": 1},
"run": {
"type": "object",
"required": ["id", "entry", "status"],
"properties": {
"id": {"type": "string"},
"entry": {"type": "string"},
"status": {"type": "string"}
},
"additionalProperties": true
},
"source": {
"type": "object",
"required": ["root_id", "analysis_digest"],
"properties": {
"root_id": {"type": "string"},
"analysis_digest": {"type": "string"}
},
"additionalProperties": true
},
"events": {
"type": "array",
"items": {
"type": "object",
"required": ["seq", "kind"],
"properties": {
"seq": {"type": "integer", "minimum": 0},
"kind": {"type": "string"},
"function_id": {"type": ["string", "null"]},
"module": {"type": ["string", "null"]},
"span": {
"type": ["object", "null"],
"properties": {
"start": {"type": "integer", "minimum": 0},
"end": {"type": "integer", "minimum": 0}
}
},
"detail": {"type": ["string", "null"]},
"operation": {"type": "string"},
"duration_micros": {"type": "integer", "minimum": 0}
},
"additionalProperties": true
}
}
},
"additionalProperties": true
}
-86
View File
@@ -1,86 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://marqdo.dev/schemas/trace-v2.schema.json",
"title": "Marqdo Trace v2",
"type": "object",
"required": ["schema", "schema_version", "run", "source", "limits", "truncated", "events"],
"properties": {
"schema": {"const": "marqdo.trace"},
"schema_version": {"const": 2},
"run": {
"type": "object",
"required": ["id", "entry", "status"],
"properties": {
"id": {"type": "string", "minLength": 1},
"entry": {"type": "string", "minLength": 1},
"status": {"type": "string", "minLength": 1}
},
"additionalProperties": true
},
"source": {
"type": "object",
"required": ["root_id", "analysis_digest"],
"properties": {
"root_id": {"type": "string", "pattern": "^(root:|sha256:[0-9a-f]{64}$)"},
"analysis_digest": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"}
},
"additionalProperties": true
},
"limits": {
"type": "object",
"required": ["max_events", "max_bytes"],
"properties": {
"max_events": {"type": "integer", "minimum": 0},
"max_bytes": {"type": "integer", "minimum": 0}
},
"additionalProperties": false
},
"truncated": {
"oneOf": [
{"type": "null"},
{
"type": "object",
"required": ["reason", "limit", "written"],
"properties": {
"reason": {"enum": ["event_budget", "byte_budget"]},
"limit": {"type": "integer", "minimum": 0},
"written": {"type": "integer", "minimum": 0}
},
"additionalProperties": true
}
]
},
"events": {
"type": "array",
"items": {
"type": "object",
"required": ["seq", "kind", "module_id", "span", "detail"],
"properties": {
"seq": {"type": "integer", "minimum": 0},
"kind": {"type": "string", "minLength": 1},
"function_id": {"type": ["string", "null"]},
"module_id": {"type": ["string", "null"]},
"span": {
"oneOf": [
{"type": "null"},
{
"type": "object",
"required": ["start", "end"],
"properties": {
"start": {"type": "integer", "minimum": 0},
"end": {"type": "integer", "minimum": 0}
},
"additionalProperties": true
}
]
},
"detail": {"type": ["string", "null"]},
"operation": {"type": "string"},
"duration_micros": {"type": "integer", "minimum": 0}
},
"additionalProperties": true
}
}
},
"additionalProperties": true
}
-74
View File
@@ -1,74 +0,0 @@
# Marqdo Trace v1
Status: **superseded by [Trace v2](trace-v2.md); never released, do not write
v1.** Kept as history.
## 1. Invariants
* Tracing is observation, not execution. Only `run`/`call` can produce a trace;
`check`, `inspect` and `tool list` never execute a document.
* Events come from the interpreter (`call.*`, `branch.eval`,
`loop.iteration`, `return`) and the host (`effect`).
* The writer is atomic: a failed run does not leave a partially written JSON
file; an error run still records the terminal status if execution started.
* No argument values, secrets, plugin handles or file contents are recorded.
Effect detail is a result summary (`ok` or a stable error code).
* `--trace` keeps its existing human/JSON effect output; `--trace-file` is the
versioned artifact and does not redefine `--trace`.
## 2. Shape
```json
{
"schema": "marqdo.trace",
"schema_version": 1,
"run": {"id": "pid-nanos", "entry": "root:default::index.mq.md::main", "status": "ok"},
"source": {"root_id": "sha256:...", "analysis_digest": "sha256:..."},
"events": [
{"seq": 0, "kind": "call.enter", "function_id": "root:default::index.mq.md::main", "span": null, "detail": null},
{"seq": 1, "kind": "effect", "module": "root:default::index.mq.md", "span": {"start": 40, "end": 52}, "detail": "ok", "operation": "print", "duration_micros": 3},
{"seq": 2, "kind": "call.exit", "function_id": "root:default::index.mq.md::main", "span": null, "detail": "ok"}
]
}
```
`seq` is globally increasing within one run (semantic and effect events share
the counter). `run.status` is `ok` or a stable runtime error code. Span fields
use UTF-8 byte offsets into the source identified by `source.root_id` and
`source.analysis_digest`.
## 3. Event kinds
| kind | detail | Meaning |
|---|---|---|
| `call.enter` | null | function entry; `function_id` is canonical |
| `call.exit` | `ok` / `return` / error code | function exit |
| `return` | value type name | explicit `return` statement; no value content |
| `branch.eval` | `true` / `false` | `if` condition for an `if/else/end` group |
| `loop.iteration` | `continue` / `exit` | `while` condition for a `while/end` group |
| `effect` | result summary | a `HostOp` effect; `operation` names it |
Future event kinds are additive. Consumers must ignore unknown kinds rather
than guessing their semantics.
## 4. Staleness
`source.analysis_digest` is the digest of the Analysis v1 projection built
from the same loaded project. If a consumer compares it with a newer analysis
and the digest differs, the trace is `stale` and must not be presented as the
current document's execution.
## 5. Privacy and limits
* Values and secrets are never serialized into a trace.
* Foreign/plugin effects record only the operation and success/error summary.
* A trace file can be large for long loops; the current implementation has no
event-count cap, but consumers must stream/limit. A future version may add a
bounded mode.
* A failed/aborted run records the status it reached; it is never marked
successful.
## 6. Not included
Interactive breakpoints, a debug server, time travel, notebook sessions,
WebSocket streaming and full argument-value capture are out of scope for v1.
-119
View File
@@ -1,119 +0,0 @@
# Marqdo Trace v2
Status: **implemented by `marqdo run/call --trace-file <path>` (S2).**
Supersedes Trace v1; v1 was never released and is kept as history.
## 1. Invariants
* Tracing is observation, not execution. Only `run`/`call` produce a trace;
`check`, `inspect` and `tool list` never execute a document.
* Events come from the interpreter (`call.*`, `branch.eval`,
`loop.iteration`, `control.break`, `control.continue`, `return`) and the host (`effect`). Both share one sequence.
* The writer is atomic; an error run still records its terminal status.
* No argument values, secrets, handles or file contents are recorded.
* Trace capacity is a bounded observation budget. Reaching it truncates the
trace; it never changes `run.status` or the program’s execution result.
Execution budgets (`--fuel`, `--timeout`, ...) remain separate and still
produce `resource.exhausted`.
## 2. Shape
```json
{
"schema": "marqdo.trace",
"schema_version": 2,
"run": {"id": "pid-nanos", "entry": "root:q@0.1.0::index.mq.md::main", "status": "ok"},
"source": {"root_id": "root:q@0.1.0", "analysis_digest": "sha256:<64 hex>"},
"limits": {"max_events": 100000, "max_bytes": 33554432},
"truncated": null,
"events": [
{"seq": 0, "kind": "call.enter", "function_id": "root:q@0.1.0::index.mq.md::main",
"module_id": "root:q@0.1.0::index.mq.md", "span": null, "detail": null},
{"seq": 1, "kind": "effect", "module_id": "dep:p@0.1.0#<digest>::index.mq.md",
"span": {"start": 40, "end": 52}, "detail": "ok", "operation": "print",
"duration_micros": 3}
]
}
```
`seq` is globally increasing. `run.status` is `ok` or a stable runtime error
code. Every span-bearing event has a `module_id`; the span is a UTF-8 byte
offset range in that module. `source` only carries project identity and the
Analysis digest; it does not identify the span owner.
`source.root_id` is the emitted Analysis `project.root_id`
(`root:<name>@<version>` or `sha256:<workspace snapshot>`).
`source.analysis_digest` is `sha256:` plus the SHA-256 of the exact Analysis
bytes produced for the same project with the same projection configuration.
The [Analysis writer](analysis-v3.md) selects v2 or v3 from the project.
A consumer verifies it by hashing the Analysis file.
`truncated` is `null` or:
```json
{"reason": "event_budget", "limit": 20, "written": 20}
```
`reason` is `event_budget` or `byte_budget`. When truncation occurs, the final
event is `{"kind":"trace.truncated","detail":<reason>,"module_id":null,
"span":null,"seq":<one past the last written event>}`.
## 3. Event kinds and span owners
| kind | detail | `module_id` owner |
|---|---|---|
| `call.enter` | null | caller module (entry call: callee) |
| `call.exit` | `ok` / `return` / error code | caller module (entry call: callee) |
| `return` | value type name | current function’s module |
| `branch.eval` | `true` / `false` | current function’s module |
| `loop.iteration` | `continue` / `exit` | current function’s module |
| `control.break` | null | current function’s module |
| `control.continue` | null | current function’s module |
| `effect` | result summary | module from `ExecutionContext` |
| `trace.truncated` | `event_budget` / `byte_budget` | null |
The explicit transfer events carry the keyword carrier span. `control.continue`
precedes the next evaluation of the enclosing loop condition. `control.break`
leaves that loop without a further condition evaluation.
`function_id` is always the canonical callee function id. Future kinds are
additive; consumers must ignore unknown kinds. `effect.operation` names the
`HostOp` (`print`, `fs.read`, ...).
## 4. Capacity
Defaults: 100 000 events and 32 MiB approximate serialized size. `0` means
unlimited for either limit. `run`/`call` expose `--trace-max-events` and
`--trace-max-bytes`; these are options on existing commands, not new commands.
The host stops accepting events once a limit is reached; the writer also
enforces the byte limit on the final serialized document, dropping trailing
events and recording `byte_budget`. Semantic recording is disabled entirely
when no trace was requested.
The `trace` array in `run --json` uses the same budget.
## 5. Staleness
A trace is stale when its `source.analysis_digest` differs from the digest of
the Analysis emitted for the current document. Consumers must not present a
stale trace as current. Moving a project does not change the manifest identity
or digest; changing executable source does.
## 6. Worker transport limits
Plugin worker frames are a 4-byte big-endian length plus JSON, capped at
8 MiB (`8 * 1024 * 1024`). The wire request/result/capability caps are aligned
to `8 MiB - 4096`; error frames remain 1 MiB. A partial header, zero/oversized
length, truncated payload or invalid JSON is a protocol error. A clean EOF is
distinct from a protocol failure. The host marks a worker dead after a transport
failure and never reuses its stdin.
## 7. Compatibility and tests
* Consumers must reject unknown `schema_version` and validate `module_id`
against Analysis modules.
* JSON Schema: `spec/schemas/trace-v2.schema.json`.
* `tests/consumers/trace_consumer.py` verifies identity, digest and event
module references.
* CLI tests cover call/effect events, no-secret redaction, error terminal
status, and event-budget truncation without changing the run status.