Repository navigation
Closed
Labels
area:insightsSession intelligence and analysis surfacesarea:schemaSchemaarea:storageStoragephase:architectureArchitecture and design spinetype:featNew feature
Description
Problem
Polylogue has partial lineage fields, but no durable topology graph that coding agents can rely on for sessions, continuations, sidechains, subagents, forks, unresolved native parents, and artifact/source provenance.
Current substrate is useful but incomplete:
conversations.parent_conversation_idandbranch_typegive one resolved parent edge.messages.parent_message_idandbranch_indexgive message-local lineage.identity_ledgertracks provider/source identity across reset cycles, not session topology.work_threadssummarize lineage for insights, but are not a general graph contract.- Parser/materialization paths can drop or null unresolved provider-native parent edges when the canonical parent row is absent.
This issue owns the graph. #864, #839, #802, #838, and #848 consume or supply evidence, but none of them should invent topology ad hoc.
Scope
Define and materialize a canonical topology model for:
- conversation/session lineage;
- message branches;
- provider-native parent/child IDs;
- continuations, sidechains, forks, and subagents;
- raw/source/artifact/hook links where available;
- unresolved parent edges that can be repaired when the parent arrives later;
- edge provenance, confidence, observed source, and resolution state.
Expected implementation shape:
- Keep
conversations.parent_conversation_idas the fast resolved parent pointer where it is sufficient. - Add a typed topology projection/table set when one FK cannot preserve the semantics, for example topology edges with edge type, native IDs, resolved IDs, raw/artifact evidence, confidence, status, and timestamps.
- Move
work_threadsto consume this topology projection, or document exactly whywork_threadsremains a derived lineage summary rather than the topology source of truth. - Expose topology reads through archive operations / Python API first. Reader, MCP, and context packs should adapt the shared read model later.
Likely files/modules:
polylogue/storage/sqlite/schema_ddl_archive.pypolylogue/storage/sqlite/schema_ddl_identity.py- possible new
polylogue/storage/sqlite/schema_ddl_topology.py polylogue/pipeline/prepare_enrichment.pypolylogue/pipeline/materialization_runtime.pypolylogue/pipeline/services/ingest_batch/polylogue/storage/repository/archive/tree.pypolylogue/archive/conversation/threads.pypolylogue/storage/insights/session/threads.pypolylogue/operations/archive.pypolylogue/sources/parsers/claude/code_parser.pypolylogue/sources/parsers/codex.py- ChatGPT parser branch/message handling
docs/architecture.mddocs/insights.mdif thread semantics change
Non-goals
- Do not build a graph-first UI in feat(reader): finish interactive reader and unified surface shell #848.
- Do not make a generic knowledge graph.
- Do not store new topology semantics only in
provider_meta. - Do not use raw JSONL rescans as the normal read model.
- Do not add productivity or work-quality inference in this slice.
Dependencies
- refactor(schema): graduate universal semantics out of provider_meta #864 for universal identity fields promoted out of provider metadata.
- fix(archive): store context and protocol artifacts semantically, not via projection fallbacks #839 for semantic context/protocol artifacts.
- feat(acquisition): Claude Code + Codex hook integration for 100% session data coverage #802 for future hook/lifecycle evidence.
- chore(schema): inventory universal archive semantics vs provider metadata #840 for provider-specific vs universal semantic classification.
- feat(context): build project/date/query context packs for agent analysis #838 for downstream context packs after topology exists.
- feat(reader): finish interactive reader and unified surface shell #848/refactor(api): define shared query/status contracts for all read surfaces #859 for later reader/API consumption.
Acceptance criteria
- Missing provider-native parents are preserved as durable unresolved edges instead of being discarded.
- Late parent arrival deterministically resolves or repairs previously unresolved edges.
- Cycles are rejected, quarantined, or marked invalid with structured evidence.
- Claude Code subagent/sidechain, Codex continuation, and ChatGPT branch/message fixtures are covered.
- Topology read model exposes ancestors, descendants, siblings, thread/root membership, edge type, confidence, and provenance.
-
work_threadseither consumes the topology model or is explicitly documented as a derived lineage summary. - No topology semantics land only in provider metadata.
Verification
Focused checks should include:
- parser fixture tests for Claude Code, Codex, and ChatGPT lineage shapes;
- storage topology tests for unresolved parents, late repair, cycles, ancestors/descendants/siblings, and provenance;
- thread/insight refresh tests if
work_threadschanges; devtools verify-schema-roundtripwhen schema DDL or schema packages change;devtools render-all --checkwhen generated docs change;devtools verify --quick, then fulldevtools verifybefore PR readiness.
Suggested new test file: tests/unit/storage/test_session_topology.py.
Metadata
Metadata
Assignees
Labels
area:insightsSession intelligence and analysis surfacesarea:schemaSchemaarea:storageStoragephase:architectureArchitecture and design spinetype:featNew feature
Activity
Sinity commentedon May 7, 2026
Reconnaissance Report -- #866: topology/lineage graph
Status: BLOCKED -- cannot start yet
This issue depends on #864/#839/#840/#802. After audit:
docs/plans/schema-inventory.md, 21K) classifying provider-meta fields, but the inventory comment specifying which fields are universal vs provider-specific for parent/lineage purposes has NOT yet been finalized. Without that classification, the topology model cannot know which native parent IDs are canonical.conversations.source_nameis still a generated column overjson_extract(provider_meta, '$.source'). Attachment native IDs are still in JSON expression indexes overprovider_meta. Lineage-critical fields likeparent_conversation_provider_idare correctly first-class onParsedConversation, but the resolution path inprepare_enrichment.pysilently drops unresolved parents (line 46-49: if candidate_parent not in cache.known_ids, parent_conversation_id stays None). refactor(schema): graduate universal semantics out of provider_meta #864 must land first so topology edges have stable identity targets.Recommendation: Cannot start until #864 has a stable shape for parent-conversation identity resolution. #840's inventory comment on lineage fields is needed but not a hard block.
Build this
Topology edge table (
topology_edges): durable directed edges with:edge_type: continuation, sidechain, fork, subagent, parent-of, child-of, unresolvedsource_conversation_id,target_conversation_id(canonical Polylogue IDs once resolved)source_provider_id,target_provider_id(native provider IDs, always preserved)confidence: enum (resolved, inferred, unresolved, ambiguous)edge_provenance: observed-source, parser-inferred, repairedresolved_at,created_at,updated_atUnresolved edge preservation: When
parent_conversation_provider_idexists but the canonical parent row is absent (not yet ingested or before this child), store the edge withconfidence=unresolvedandtarget_conversation_id=NULL. Do NOT silently drop it.Late-parent repair: On ingest of a new conversation, check
topology_edgesfor unresolved edges whosetarget_provider_idmatches the new arrival. Resolve the FK, update confidence toresolved, and setresolved_at.Cycle detection: Before inserting any resolved edge, walk ancestors. If the proposed parent is a descendant of the child, reject with
confidence=cyclicand structured evidence (the cycle path).Topology read model: Expose through
ArchiveOperations:get_conversation_ancestors(conv_id)get_conversation_descendants(conv_id)get_conversation_siblings(conv_id)get_thread_root(conv_id)get_thread_members(thread_root_id)work_threads consumes topology: Either rebuild work_threads from
topology_edgesor document exactly that work_threads is a derived lineage summary.Do NOT build this
conversationscolumn for every topology attribute -- use dedicated edges table(s).topology_edgestable with a typededge_typeenum is sufficient.Files to touch
polylogue/storage/sqlite/schema_ddl_topology.py(NEW)topology_edgesDDL, indexes, upgrade migrationpolylogue/storage/sqlite/schema_bootstrap.pypolylogue/pipeline/prepare_enrichment.py(L44-49)polylogue/pipeline/materialization_runtime.py(L276-280)polylogue/pipeline/services/ingest_batch/polylogue/operations/archive.pypolylogue/archive/conversation/threads.pypolylogue/storage/insights/session/threads.py(if separate)polylogue/sources/parsers/claude/code_parser.py(L238-260)polylogue/sources/parsers/codex.py(L434-461)polylogue/sources/parsers/chatgpt.pydocs/architecture.mdtests/unit/storage/test_session_topology.py(NEW)Coordination
schema_ddl_archive.pyoverlap with refactor(schema): graduate universal semantics out of provider_meta #864/refactor(storage): make conversation writes bundle/hash-honest #841/fix(chatgpt): align parsed message metadata with persisted archive contract #842. Use a separateschema_ddl_topology.pyto minimize conflicts.Focused tests
Acceptance matrix
Ambiguities / Risks
parent_message_provider_idper message. It does NOT setparent_conversation_provider_idon the conversation. Does ChatGPT have continuation/branch semantics to expose?make_conversation_id(provider, provider_conversation_id)pattern may not produce stable IDs if provider_conversation_id format varies. Need to verify with existing fixtures.topology_edgesshould be a separate table or useconversations.parent_conversation_idas a resolved edge and add a parallel unresolved-edges table. The issue body favors a separate typed topology table.feat: browser extension harness, reader smoke tests, session lineage (#…
feat: cost query tests, session lineage, reader marks (#803/#866/#867)
feat: browser extension MV3 harness, reader smoke, lineage (#940)
feat: cost query tests, session lineage, reader marks (#942)
feat: browser extension MV3 harness, reader smoke, lineage (#940)
feat: cost query tests, session lineage, reader marks (#942)
Sinity commentedon May 7, 2026
Reopening after closed-issue/codebase reconciliation. This topology issue is not implemented; the close state appears to have preserved only reconnaissance.
Current evidence on
master:topology_edges,schema_ddl_topology,SessionTopology, ortests/unit/storage/test_session_topology.pyexists.conversations.parent_conversation_idplus derived thread/read helpers.polylogue/pipeline/prepare_enrichment.py:53-58still drops unresolved native parent references when the candidate parent is not incache.known_ids.tests/unit/pipeline/test_ingest_batch.py:285-301explicitly asserts missing parent FKs are cleared toNone, which is the opposite of this issue's unresolved-edge preservation requirement.Remaining scope stays here: canonical topology edge model, unresolved-edge preservation, late-parent repair, cycle handling, typed read operations, and storage/parser fixtures for Claude Code, Codex, and ChatGPT lineage shapes.
Scope note: exclude this from #944 except as a referenced reopened issue.
9 remaining items
feat(reader): session lineage and topology view (#1121) (#1176)
feat(reader): support non-conversation target kinds for marks (#1113) (…
Sinity commentedon May 18, 2026
Decomposed into 4 slices
Sequence: A blocks B/C/D. B/C/D can proceed in parallel after A lands.
feat(topology): late-parent arrival deterministic edge repair (#1259) (…
feat(topology): cycle rejection and quarantine (#1260) (#1395)
feat(topology): typed read model API — ancestors/descendants/siblings…
feat(topology): typed read model API — ancestors/descendants/siblings…
Sinity commentedon May 24, 2026
Absorbed slice
Slice D — typed read model API (was #1261)
Scope:
polylogue/operations/archive.py(or new topology operations module):get_topology(conv_id),get_ancestors,get_descendants,get_siblings,get_thread_rootwork_threadspolicy: consume topology OR document explicitly as derived lineage summaryAcceptance:
tests/unit/api/for each readwork_threadsdecision recorded in PR + relevant module docstringprovider_metaOptional expansion: expose graph queries via MCP as
polylogue.get_session_topologyfor multi-agent orchestration use case.Original issue ref: #1261 — closed, content preserved here.
Sinity commentedon May 25, 2026
Cross-link from a 2026-05-25 archive audit: this issue's "session identity and lineage graph" is the prerequisite primitive for several follow-up insight tools. Concretely surfaced by data:
parent_conversation_idset today — that's the substrate this issue would materialize against.logical_conversation_idas a first-class join key, monthly session-count aggregates are wildly off: Jan 2026 reports 1,705 sessions / 280h engaged, May reports 125 sessions / 248h engaged. Same total engaged hours, 13× different session count — purely because of segmentation policy. Thelast_message_at-keyed rollup measures JSONL files, not logical chats.:agent-acompactsuffix is a marginal effect (72 conversations total, 0.9%). The bulk of the divergence is general resume-chain segmentation. Don't special-case:agent-acompact— use the general parent chain.Concrete deliverable that downstream issues now depend on:
logical_conversation_idcolumn (or view) onsession_profilesthat walks the parent chain to a root.logical_session_countalongsidesession_countinday_session_summaries,week_session_summaries,productivity_rollups,session_tag_rollups.get_logical_session(conversation_id)returning the full lineage (root + descendants + ordered timestamps).SELECT COUNT(DISTINCT logical_conversation_id) FROM session_profiles WHERE first_message_at LIKE '2026-01%'returns a value strictly between 202 (conversations.created_at count for January, the lower bound) and 1,705 (session_profiles count, the upper bound).find_lineage_anomalies().Downstream consumers waiting on this primitive: #1529 (find_resume_candidates uses logical IDs as ranking keys), #1527 (workflow_shape rolls up at the logical level), #1528 (terminal_state of a logical session = state of its latest descendant).
Sinity commentedon May 25, 2026
Implemented the logical-session identity slice on
feature/feat/logical-session-identity.What changed:
session_profiles.logical_conversation_id, materialized from the existing parent-chain/thread-root helpers;conversation_countand addlogical_session_countpluslogical_conversation_ids_json;get_logical_session(conversation_id)as the compact read-pull envelope: root, thread, siblings, descendants, cycle flag;get_session_topologyremains the full graph surface, so this does not duplicate topology edges.Focused local verification:
pytest tests/unit/api/test_topology_api.py ... tests/unit/mcp/test_insight_shape_tools.py -q-> 113 passedpython -m mypy polylogue ... touched tests-> clean across 859 source filesruff format --check polylogue tests && ruff check polylogue tests-> cleandevtools render-all --check-> OKRemaining before closing #866: live archive rebuild/distribution evidence on the latest schema. This should be batched with the pending #1530 live evidence because schema v13 supersedes the earlier v12 rebuild target.
feat(insights): materialize logical session identity (#1540)
Sinity commentedon May 27, 2026
Claude Code 2.1.139+: machine-readable agent identity via OTEL + env vars
Claude Code now emits agent lineage through two new channels:
OTEL spans (2.1.139):
llm_requestspans carryagent_id+parent_agent_idattributes.toolspans carry the same. Theparent_agent_idis set by the dispatching Agent tool span, so subagent lineage traces back to the originating session.CLAUDE_CODE_SESSION_ID(2.1.132): exported into every Bash subprocess environment. Any tool call, hook, or subprocess can read it.For polylogue topology, these provide observed lineage evidence (parser-independent, machine-assigned) alongside the existing parser-inferred parent references. A topology edge backed by both parser inference AND OTEL parent_agent_id has higher confidence than either alone.
Suggested adjustment: Add OTEL
agent_id/parent_agent_idandCLAUDE_CODE_SESSION_IDas recognized topology evidence sources in the edge-confidence model. These don't replace parser-inferred lineage — they're an independent signal that raises confidence or catches mismatches.Sinity commentedon May 28, 2026
Future extension: dynamic agent addressability via topology
Once the static lineage primitives are solid (topology_edges, logical session identity, typed read API), the natural extension is dynamic agent addressability: making a session routable at runtime via its logical session ID.
What this enables:
Implementation sketch:
session_profiles.logical_conversation_id)polylogue.read_channel(session_id)returns notes + lineage contextPrerequisite for: recursive agent orchestration vision.
This is a future extension, not current scope for #866. The static lineage primitives need to be solid first.
Sinity commentedon May 28, 2026
Infrastructure already exists in the codebase. topology_edges table + session_profiles.logical_conversation_id for #866. provider_events table for #1486.