Skip to content
pi-c Artifact [d9db4ce148]
Login

Artifact [d9db4ce148]

Artifact d9db4ce148da69b18d0e6e20cc5d15785e35748ce14eb1fff74d08df99296884:


Context integration boundary

Status: source-based feasibility map and proposed boundaries, not an approved implementation design.

Context was found at /Users/dmestas/projects/context, not /Users/dmestas/context (../context relative to the working directory). The inspected checkout reported check-in cf8edff06f11 on branch tentative-rules; it is not vendored or pinned by the Pi lock. Local context links below depend on that directory layout and may drift independently.

What exists and what it does not imply

ID Existing mechanism Evidence Reuse boundary
C01 One C binary links embedded SQLite and libfossil. build target. Suitable native foundation; not yet a public embedded context library. Most app functions are static in src/ctx.c.
C02 WAL is selected on initialization; ordinary database opens set a 30-second busy timeout. open, initialization. Explicitly set and verify release durability policy on every runtime writer; do not infer process ownership from SQLite locks. No context crash/power-loss experiment was run.
C03 Embedded Fossil repositories occupy tables in the main database and can share transaction commit/rollback. Existing archive batching opens one transaction. embedded repository contract, archive transaction. Enables one transaction across runtime records and selected repository changes. Do not duplicate execution state across independently committed databases.
C04 Search is FTS5-ranked, project-scoped, and excludes retired material by default; history/as-of paths have separate filters. search query and ordering. Reuse for knowledge discovery, not for deciding whether a task has executed.
C05 Extraction removes noise, excludes sidechain turns, flattens selected block kinds, redacts content, and trims tool output. tool trimming, message extraction, filter/redact path. Current archive is intentionally lossy. It cannot be the authoritative provider transcript or execution log. Preserve its redaction guarantees.
C06 Session briefs recover recent decisions, artifacts, messages, and standing-rule proposals from archived turns. Rules are offered separately. session brief, rules offer. Useful human-facing handoff; not a checkpoint, acknowledgement, or authorization mechanism for durable tasks.
C07 Rebuild drops derived search/citation/decision/artifact tables and reconstructs their content; chunk IDs change. derived objects and rebuild. Stable runtime IDs must not reference derived chunk IDs as their only identity. Runtime tables must survive rebuild.
C08 Existing MCP surface exposes search and turn retrieval. MCP tool declarations. Server-side search tools do not provide an MCP client, arbitrary tool hosting, or durable external-call ownership.
C09 Fossil sync makes remote archived sessions searchable; documented transport is plain HTTP and recommends a private network or SSH tunnel. sync behavior and transport. Knowledge replication is not execution failover. Do not transfer task ownership implicitly on sync or use plain HTTP for provider credentials.
C10 Automatic snippet injection is optional and did not outperform skill-guided retrieval in the documented evaluation. retrieval integration measurements. Do not assume injecting more archived text improves context. Preserve targeted search and measure assembled-context quality.

Two approaches considered

  1. Compose the existing CLI. Fast path to a retrieval prototype and preserves separation. Separate ctx subprocess calls cannot implement one atomic harness transition; also pays process/serialization costs.
  2. Extract a reusable embedded context core. Hides storage/retrieval complexity and exposes a transaction-aware boundary. Requires deliberate API extraction and tests so the existing CLI remains unchanged.

Recommendation for a durability-capable native implementation: approach 2. This is a recommendation, not authorization to refactor context. Do not add consumer-side workarounds for bugs that belong in context/libfossil.

Proposed authoritative state, not present today

Keep this state distinct from rebuildable indexes and from the redacted archive. One physical SQLite database is possible; that does not require identical privacy, replication, retention, or representation policies for every table.

Essential invariants

  1. Admit work before execution; publish durable state only after its storage receipt.
  2. Atomically store a result and the state transition that acknowledges it.
  3. Never hold a write transaction while waiting for model HTTP, a subprocess, a person, or a timer.
  4. Resume from explicit task state; do not ask a model to infer completion from the archive.
  5. A replay-unsafe interrupted external action has an unknown outcome, not permission to repeat it.
  6. A replay-safe declaration is not proof of external idempotency. Persist keys and reconcile uncertain outcomes.
  7. Index rebuild, archive redaction, and knowledge synchronization cannot change execution ownership or authoritative task state.
  8. Persist context-version references for requests; new retrieval results must not silently rewrite a prior request on recovery.
  9. Authenticate approvals/signals and preserve who authorized what; a historical decision inferred from text is not a runtime approval token.
  10. One execution owner per store until an explicit, tested fencing/ownership protocol exists.

Design choices still open

These are architectural decisions to resolve before implementation, not reasons to block source mapping.

Development and production requirements

The requested implementation language is C. DST, MC/DC instrumentation, fuzzing, sanitizers, and Fil-C are development/qualification tools. Production must be an optimized native build without those instrumentation runtimes.

First proof slice

Persist input → assemble versioned context → stream a fake-provider tool call → commit tool intent → execute a controlled tool → commit result/checkpoint → finish response. Inject a crash before and after every commit and external action.

Acceptance: no admitted input disappears, deduplication survives reopen, no committed result is executed again, uncertain non-idempotent work is not blindly retried, index rebuild does not destroy runtime state, and observers never treat uncommitted state as durable. Add actual provider access and a terminal UI only after the fake-provider path establishes these contracts.