# Contract and feature map

## Status and provenance

This is a first-pass inventory, not an implementation, exhaustive parity certification, or approved architecture. Pi evidence is pinned to `cead615b48b80d1c61eecab2f0b576d16eeaf4c5`; see [the lock](../reference/pi.lock.json). Context evidence comes from the separately maintained local checkout identified in [context-boundary.md](context-boundary.md).

No upstream dependencies were installed, tests executed, or real provider requests made. A test citation means its assertions were read, not that they passed here. A type comment, implementation, and test each supply different evidence; none automatically proves every failure mode.

Initial mapping: **79 IDs** (30 harness, 22 durability, 17 provider, 10 context). Local validation checked **292 links**, numeric line-anchor bounds, unique IDs, the pinned revision, depth-one history, detached HEAD, and an unchanged reference worktree. This checks citation structure, not the truth or completeness of every behavioral claim.

Important qualification to the simple commit-before-visibility description: Pi Durable defaults streamed progress to deferred document commits, with a 1000 ms persistence window. D21 maps that exception; D03/D04 distinguish stored receipts, refused batches, and uncertain outcomes.

## Maps

| Map | Scope | How to use it |
|---|---|---|
| [Harness features](harness-features.md) | User-facing behavior, tools, sessions, extensibility, integration modes, and security boundaries | Define observable behavior parity and optional ecosystem compatibility. |
| [Durability contracts](durability-contracts.md) | Admission, transactions, task transitions, recovery, cancellation, waits, and storage | Derive invariants and failure-injection cases before implementing the scheduler. |
| [Provider contracts](provider-contracts.md) | Typed blocks, stream ordering, argument validation, replay conversion, retries, and usage | Define a provider boundary without flattening away continuation information. |
| [Context boundary](context-boundary.md) | What context already supplies, what must be added, and qualification strategy | Keep execution authority separate from searchable/replicated knowledge. |

Contract IDs are local to each map (`H`, `D`, `P`, `C` prefixes). C implementation consequences are proposals; observed Pi contracts are reference behavior. A future implementation should record intentional divergences rather than silently claiming compatibility.

## Parity is not one checkbox

Track these independently:

1. **Behavior:** what the person and model can do, and when inputs/results become visible.
2. **Recovery:** what survives each failure and what may repeat.
3. **Formats/protocols:** session files, RPC commands/events, MCP behavior, export formats.
4. **Ecosystem:** existing TypeScript extensions, package resolution, SDK callers, and code-mode execution.
5. **Operational envelope:** supported operating systems, terminal behavior, providers, credentials, limits, and deployment ownership.

The first two are the core goal. The others require explicit compatibility decisions; raw C does not automatically provide JavaScript execution or the existing Pi SDK.

## Cross-cutting issues to resolve

- **Lossless runtime versus redacted archive:** preserve both guarantees without promoting search text into execution state.
- **Commit-before-visibility versus latency:** distinguish transient provider parsing from durable client events; measure batching without weakening the acknowledged guarantee.
- **Retry layers:** separate HTTP retry, model-attempt recovery, tool replay, and child-task recovery.
- **External effects:** an idempotency key or reconciliation mechanism is still required outside the database transaction.
- **Rebuild and sync:** rebuilding search cannot delete tasks; syncing history cannot grant execution ownership.
- **Plugin semantics:** reloading or upgrading an extension cannot silently reinterpret saved checkpoints.
- **Security:** project trust is not an OS sandbox; historical user decisions are not fresh approvals; credentials cannot leak through logs or sync.
- **Production speed:** benchmark the optimized native build while holding the semantics, durability, and validation contract constant.

## Implementation planning

- [Implementation and qualification plan](implementation-plan.md): stages S0–S10, exit gates, continuous benchmarks, release evidence, and Hetzner setup/teardown.
- [Core acceptance catalog](acceptance-catalog.md): 30 initial state/fault/recovery cases with observable oracles and reference-contract links.
- [S0 qualification results](s0-results.md): actual local results, open failures, and gated lanes; fixture evidence is not production-contract evidence.
- [End-to-end and nightly conformance](e2e-conformance.md): 24 proposed scenario families against pinned Pi/Pi Durable and independent invariants, with maintenance, drift, evidence, and teardown gates.
- [Machine-readable registry](../contracts/registry.json): all 79 IDs with owning stage, case links, citation, disposition, and evidence status.
- [Remote lifecycle](remote-lifecycle.md): the bounded, actually exercised Fil-C procedure and teardown.
- [S1 substrate results](s1-results.md) and [context API proposal](context-api-proposal.md): real atomicity evidence and the still-unimplemented public integration boundary.

The catalogs are proposed requirements, not blanket execution evidence. Local S0 gates, a narrow Fil-C/lifecycle run on `hetzner-hel`, and the S1 substrate probe have passed within their stated scope; see their result files. Remote resources were manifest-owned, deadline-bounded, collected, and removed. No production harness or nightly/reference environment is implemented.

## Suggested next mapping passes

1. Convert core contracts into a small acceptance catalog: input/state, interruption point, expected persistent state, permitted effects, observer result.
2. Pin context's embedded API and transaction ownership without refactoring it yet.
3. Specify the task/checkpoint and message encodings, including version upgrades and unknown/corrupt records.
4. Detail one provider protocol plus process/file tools using fake responses and DST first.
5. Decide format, extension, and operating-system compatibility targets before promising full parity.
6. Define crash qualification, MC/DC scope, fuzz targets, Fil-C coverage, and native performance baselines.

No implementation schedule or performance claim is established by this inventory.
