# @octaviaflow/execution-context

## 0.2.0

### Minor Changes

- **Bytes are one binary value (DEV-636).** A `Buffer`, a typed array, an `ArrayBuffer` or a `DataView` infers as `{ type: 'string', format: 'binary' }`, with no example. Before, it was walked as an object, which gave one property per byte: a 140 KB file became a multi-megabyte schema. `JSONSchema` gains `format`.
- **BSON values are inferred from their JSON form (DEV-636).** An `ObjectId` from the MongoDB driver infers as a string with its hex as the example, the value a step's output carries. Before, it was inferred from the driver's internals (`buffer.0` … `buffer.11` on bson 6, `i0` … `i3` on bson 7). A UUID is its string. Any other `Binary` is `format: 'binary'`. `Long`, `Decimal128` and `Timestamp` follow their JSON. The schema is the same on bson 6 and 7.
- **Inference reads as the real type (unreleased since 2026-05-02):**
  - A field that is sometimes `null` is its non-null type, instead of a `oneOf` labelled `unknown`.
  - Mixed types take the first non-null type as their surface type, keeping the `oneOf`.
  - An empty array has no `items`.
  - An array of objects is marked `loopable` (OR-merged across rows).
- **Lineage:** `LineageSource` adds the Variables step's `prompt`, `secret` (no resolved value, by design) and `env` kinds.
- **`iovalkey` ^0.4.0** (from ^0.3.3): fixes only; the store's commands and options are unchanged.
- **Dependencies are no longer bundled into `dist`.** 0.1.x carried its own copy of `iovalkey` (263 KB), so a consumer's version never applied, and `dist` failed to load under Node (`__require is not a function`). The build now leaves packages external and targets Node ESM: 22 KB, loading under Node and Bun.

### Upgrading

A step whose output had nulls, empty arrays, bytes or Mongo values gets a different schema, and a different `schemaHash`, once. A binding to an ObjectId's internals (`_id.buffer.0`) no longer resolves. It never held a value a downstream step received.

## 0.1.1

### Patch Changes

- Two `inferSchema` correctness fixes that surfaced when previewing real Postgres `jsonb`-bearing tables.

  - **Date instances are typed as `string` (ISO 8601 example)** instead of an empty `{type: 'object', properties: {}}`. Postgres `timestamp` columns and any other source that returns `Date` objects now produce a useful leaf schema rather than rendering as an empty expandable branch in field pickers.
  - **Empty arrays no longer pollute the merged item schema with a spurious `oneOf` branch.** Previously, `[{xs: []}, {xs: [{id: 1}]}]` produced `xs.items: { type: 'unknown', oneOf: [{type:'unknown'}, {type:'object', properties:{id:...}}] }` — UIs that walk only `items.type === 'object'` showed the array as empty. Now `{type: 'unknown'}` (with no `properties`/`items`/`oneOf`/`truncated`) acts as an identity element during merge, so empty + populated collapse to a clean `items: {type: 'object', properties: {...}}`. Genuinely heterogeneous items (e.g. `[object, string]`) still produce `oneOf` as before.

  5 new test cases (61 total).

## 0.1.0

### Minor Changes

- Initial release of `@octaviaflow/execution-context` — durable, tenant-isolated execution context for the Octaviaflow workflow engine.

  What's in 0.1.0:

  - **Typed step envelopes** — `StepEnvelope<T>` with `data`, `schema`, `schemaHash`, `lineage`, `metadata`, `status`.
  - **`ExecutionContextStore`** interface + `ValkeyExecutionContextStore` implementation backed by `iovalkey`. Tracks named health states (`ready` / `degraded` / `unavailable`); raises `StoreUnavailableError` on hot-tier write failure rather than silently dropping.
  - **N-th level JSON Schema inferencer** (`inferSchema`, `schemaHash`) — recursive 200-sample × depth-8 walk producing JSON Schema 2020-12 with cardinality, nullability, oneOf unions, and small-domain (≤16) enums. Hash is stable under property reordering.
  - **Tenant prefix discipline** — every Valkey key, S3 prefix, and Mongo DB name carries `tenantId` as the first segment; constructed centrally via typed helpers (`stepKey`, `flowVarsKey`, `executionLeaseKey`, `archiveObjectKey`, `envelopeBlobKey`). `InvalidTenantError` on invalid tenant IDs.
  - **Idempotency primitives** — `idempotencyKey({executionId, stepId, attempt})` for store writes and event publishes.
  - **Execution event stream** — `ExecutionEventPublisher` / `ExecutionEventSubscriber` over Valkey Streams (XADD / XREADGROUP / XACK) for the intra-execution event protocol (`step.committed`, `step.failed`, `execution.status`, `execution.log`). Subscriber dedupes at receive by idempotency key (LRU-bounded per tenant).

  Distinct from `@octaviaflow/eventbus` (NATS, cross-service CDC ingress events). This package handles intra-execution events only.

  56 unit tests; logger-agnostic (accepts any `{debug, info, warn, error}` object; default no-op).
