# @octaviaflow/execution-context

## 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).
