Repository navigation
Description
Metadata
Parent: #1807
Related cleanup umbrella: #2177
Cross-pollination source: Sinex admission/explainability doctrine from /tmp/ideas.md and Sinex source-identity map.
Owning surfaces: import pipeline, source parsing, raw/session evidence, CLI, Python API, MCP, daemon HTTP, docs/generated schemas.
Status: partially implemented. PR #2186 added the first CLI ImportExplain vertical for local paths (polylogue import PATH --explain --format json|ndjson) and the shared payload models. Remaining scope is prior-explanation retrieval by raw/source ref plus any Python API, MCP, and daemon/web surfaces that should consume the same payload.
Purpose
Add a first-class import explanation surface that answers:
Why did this raw artifact import this way, and what did it produce?
Polylogue already detects providers by payload shape, lowers raw payloads into provider/session parse modes, stores raw/session/message/block/action data, and reports some failures through status/debt surfaces. What is missing is a durable, structured explanation object that connects one raw artifact or import attempt to the detector, parser, parser mode, produced rows, skipped rows, caveats, and raw evidence refs.
This is the Polylogue analogue of Sinex admission explainability, but it should stay import-shaped. Do not import Sinex's event/admission model wholesale.
Closure audit — 2026-06-20
This issue was closed with a real landed baseline, but a broad audit found it is not fully complete against its own acceptance criteria. Keep the landed CLI/API implementation; do not discard it. Remaining scope is:
- MCP must expose
ImportExplainPayloador the issue must explicitly decide that path-based import explanation is intentionally not safe/useful over MCP. - Daemon/web shell must expose a local/shell-supported import-explain route or explicitly defer with route metadata that names this issue.
- A raw-ref or source-path read path must retrieve an explanation from already-observed archive evidence when
source.db/index.dbrows exist. Re-running detector logic over a path is not enough for this criterion. - The current generated CLI output schema is good, but OpenAPI/route docs should appear only for exposed daemon routes.
- Privacy coverage must prove raw bytes and absolute local paths are omitted/redacted consistently across every exposed surface, not just the CLI/API preflight path.
Treat the existing polylogue import PATH --explain, ImportExplainPayload, and Polylogue.explain_import(...) as the foundation. The remaining work is to make the surface broad and archive-backed enough to justify closure.
Landed baseline
The first implementation landed in #2186:
polylogue import PATH --explain --format json|ndjson
polylogue.sources.import_explain.explain_import_path()
polylogue.surfaces.payloads ImportExplain* payloads
CLI output schema and docs/generated surfaces
That path is intentionally non-mutating: it runs the existing detector/parser stack over local files/directories/ZIP entries and reports artifact classification, provider/origin detection, parser mode, produced-row counts, skips, caveats, and bounded failures without scheduling daemon ingest, writing raw blobs, or printing raw payload bytes.
Remaining work should extend this baseline rather than reintroduce a second import/admission engine. The still-open questions are:
- how to retrieve explanations for already-observed raw/source refs once import evidence exists in the archive;
- whether the Python API, MCP, and daemon/web shell need first-class
ImportExplainPayloadsurfaces now or whether the CLI/local preflight is enough for the current release; - how import explanation rows should feed feat(ops): expose unified archive debt views across import, index, embedding, and transforms #2179 debt rows and feat(providers): report provider/importer package completeness by origin and capture mode #2180 provider-completeness evidence.
Current code reality
Relevant current owners:
polylogue/sources/dispatch.py
detect_provider()
_detect_provider_from_record()
_detect_provider_from_sequence()
_detect_provider_from_raw_bytes()
LoweredPayloadSpec(provider, fallback_id, mode, payload, source_path)
polylogue/sources/source_parsing.py
iter_source_sessions_with_raw()
per-path source walk, artifact classification, parser emission, raw capture
polylogue/sources/emitter.py
parser emission boundary for raw payloads into ParsedSession objects
polylogue/archive/artifact_taxonomy/
artifact classification before parse-as-session filtering
polylogue/storage/sqlite/archive_tiers/
raw/session/message/block/action storage and raw blob linkage
polylogue/daemon/status.py and convergence debt modules
current failure/debt signals, but not per-import explanatory lineage
The current detection pipeline has enough information to explain decisions, but it is mostly transient: provider shape checks, fallback provider, JSONL fallback, parser mode, skipped artifacts, and produced sessions are not exposed as one user-facing payload.
Proposed design
Introduce ImportExplainPayload as a surface payload, not a new import engine:
class ImportExplainPayload(SurfacePayloadModel):
mode: Literal["import-explain"]
raw_ref: str | None
source_path: str | None
artifact_kind: str | None
provider_hint: str | None
detected_origin: str | None
detector: str
detector_evidence: tuple[ImportDetectorEvidencePayload, ...]
parser: str
parser_version: str | None
parser_mode: str | None
schema_resolution: str | None
produced: ImportProducedRowsPayload
skipped: tuple[ImportSkippedRowPayload, ...]
caveats: tuple[str, ...]
raw_evidence_refs: tuple[str, ...]
normalization_warnings: tuple[str, ...]Suggested subpayloads:
ImportDetectorEvidencePayload:
check: str # e.g. browser_capture.looks_like, codex.looks_like
matched: bool
reason: str | None # bounded non-sensitive detail
ImportProducedRowsPayload:
sessions: int
messages: int
blocks: int
actions: int
raw_records: int
blob_refs: tuple[str, ...]
ImportSkippedRowPayload:
reason: str # artifact taxonomy skip, decode failure, parser skip, unsupported sidecar
source_path: str | None
raw_ref: str | NoneThis payload should be generated from existing parse/import evidence. It should not require a second raw-ingest database or a parallel admission log.
Candidate surfaces
CLI:
polylogue import PATH --explain --format json
polylogue import PATH --explain --format ndjson
polylogue read RAW_REF --view import-explain --format jsonPython API:
await archive.explain_import(path_or_raw_ref)MCP:
explain_import(path_or_raw_ref, source_name?, limit?)
Daemon/web API:
GET /api/import/explain?raw_ref=...
GET /api/import/explain?source_path=...
The daemon route should be shell-supported/local, not a stable remote API, unless #1847 route-stability rules say otherwise.
Design constraints
- Use origin/source vocabulary precisely. Provider-wire enum values may appear only where the contract is actual provider detection/parser internals; public explanation should prefer origin/capture/parser wording.
- Preserve privacy boundaries: source paths may be redacted or omitted according to existing status/redaction policy; raw bytes are never embedded by default.
- Keep parser evidence bounded. Do not dump whole payloads or arbitrary exception traces.
- Treat failures as explanatory rows too. A failed import should still explain detector/parser/failure stage when possible.
- Generated schemas/docs must include the payload and CLI output shape.
Acceptance criteria
ImportExplainPayloadexists inpolylogue.surfaces.payloadsor an equally shared surface payload module.- At least one representative provider path, preferably
codex-sessionorclaude-code-session, can produce an explanation that names detector, parser, parser mode, produced sessions/messages/blocks/actions, caveats, and raw refs. polylogue import PATH --explain --format jsonreturns a finite JSON document without importing raw bytes into stdout.- A raw-ref or source-path read surface can retrieve a prior explanation when the relevant raw/import evidence exists.
- Python API, MCP, and daemon/web shell either expose the same payload or explicitly defer with route/tool metadata that points to the owning issue.
- Generated CLI-output schema/OpenAPI/docs are updated where the surface is exposed.
- Failure cases are covered: unknown provider, malformed JSON/ZIP/JSONL, artifact classified as not parse-as-session, and parser exception.
- Privacy tests prove absolute local paths/raw bytes are redacted or omitted in the same way existing status surfaces redact paths.
Tests
Required focused tests:
- Provider detection explanation for a known Codex or Claude Code fixture.
- Parser-mode explanation for grouped-record vs single-record style where applicable.
- Failed/malformed input explanation that is typed and bounded.
- CLI JSON contract smoke.
- MCP/API/daemon route contract if those surfaces are implemented in the same PR.
- Generated schema check for the payload.
Non-goals
- Do not expose raw SQL or raw source payloads.
- Do not create a Sinex-style event admission subsystem inside Polylogue.
- Do not add a second detector/parser registry unless it mechanically drives the existing detection/parsing code.
- Do not classify this as generic GitHub/backlog debt; this is import evidence.
Identity-map dependency
ImportExplain must report provider-wire family, public origin, material source, parser binding, capture mode, and produced archive refs as separate fields. Do not collapse these into one provider or source string. See #2184 for the vocabulary map.
Activity
test(showcase): refresh import help baseline
fix(import): bound ZIP reads in import explain
feat(import): explain parser decisions for local imports (#2178) (#2186)
feat(api): expose import explain payloads (#2178) (#2200)
Sinity commentedon Jun 20, 2026
Reopening after broad closure audit.
The landed baseline is real:
ImportExplainPayload,polylogue import PATH --explain,Polylogue.explain_import(...), CLI JSON/NDJSON tests, API tests, bounded failure handling, and generated CLI output schema are present.The issue is still not complete against its own AC:
explain_importtool or explicit durable deferral;This should remain open until those are either implemented or explicitly rejected in the issue body with rationale. Ref #1807.
feat(import): expose archive-backed import explain (#2249)