Skip to content

feat(insights): materialize logical session identity - #1540

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/logical-session-identity
May 25, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/logical-session-identity

Conversation

@Sinity

@Sinity Sinity commented May 25, 2026

Copy link
Copy Markdown
Owner

Summary

Materializes logical session identity for continuation/fork/subagent lineages and exposes a compact read-pull API/MCP envelope for agents.

Problem

#866 already has durable topology edges and graph reads, but session profiles and rollups still counted physical conversations only. Continuations, forks, sidechains, and subagents could inflate daily/tag/workspace views even though they belong to one logical work session. Read-pull consumers also had to use the full topology graph when they only needed the root/thread/sibling navigation envelope.

Solution

  • Bump canonical schema to v13 and add session_profiles.logical_conversation_id.
  • Compute logical roots in full rebuild and incremental refresh using the existing thread-root helpers.
  • Preserve physical conversation_count, then add logical_session_count and logical_conversation_ids_json to day summaries and tag rollups.
  • Make week summaries union day-level logical ids instead of summing day logical counts blindly.
  • Add LogicalSession, Python API get_logical_session(), and MCP get_logical_session with a compact typed payload.
  • Document the contract in docs/architecture.md and docs/internals.md.

Verification

  • ruff format --check polylogue tests && ruff check polylogue tests -> clean
  • python -m mypy polylogue tests/unit/mcp/test_logical_session_tool.py tests/unit/mcp/test_tool_contracts.py tests/unit/api/test_topology_api.py tests/unit/storage/test_session_insight_refresh.py -> clean across 857 files
  • pytest tests/unit/api/test_topology_api.py tests/unit/mcp/test_logical_session_tool.py tests/unit/mcp/test_tool_contracts.py::TestInsightTools::test_session_profile_tool_uses_archive_insight_contract tests/unit/mcp/test_tool_contracts.py::TestInsightTools::test_insight_list_tools_use_archive_queries tests/unit/mcp/test_tool_contracts.py::TestMutationTools::test_session_tree_returns_envelope tests/unit/mcp/test_envelope_contracts.py tests/unit/storage/test_session_insight_refresh.py tests/unit/storage/test_dead_schema_sweep.py tests/unit/insights/test_productivity.py tests/unit/insights/test_rigor_audit.py tests/unit/mcp/test_insight_shape_tools.py -q -> 113 passed
  • devtools render-all --check -> OK
  • devtools verify --quick -> PASS in 33.51s locally and PASS in 32.64s from pre-push

Ref #866

Problem: physical conversations currently overcount continuation, fork, sidechain, and subagent chains in session insights. #866 already has topology edges, but rollups and read-pull consumers still lacked a persisted logical-session root.

What changed: add schema v13 with session_profiles.logical_conversation_id, compute it in rebuild and refresh paths, and carry logical_session_count plus logical_conversation_ids_json through day and tag aggregates. Add a compact LogicalSession API/MCP envelope while keeping get_session_topology as the full graph surface.

Verification: ruff format --check polylogue tests && ruff check polylogue tests; python -m mypy polylogue tests/unit/api/test_topology_api.py tests/unit/mcp/test_logical_session_tool.py tests/unit/mcp/test_tool_contracts.py tests/unit/mcp/test_insight_shape_tools.py tests/unit/insights/test_productivity.py tests/unit/insights/test_rigor_audit.py tests/unit/storage/test_session_insight_refresh.py; pytest tests/unit/api/test_topology_api.py tests/unit/mcp/test_logical_session_tool.py tests/unit/mcp/test_tool_contracts.py::TestInsightTools::test_session_profile_tool_uses_archive_insight_contract tests/unit/mcp/test_tool_contracts.py::TestInsightTools::test_insight_list_tools_use_archive_queries tests/unit/mcp/test_tool_contracts.py::TestMutationTools::test_session_tree_returns_envelope tests/unit/mcp/test_envelope_contracts.py tests/unit/storage/test_session_insight_refresh.py tests/unit/storage/test_dead_schema_sweep.py tests/unit/insights/test_productivity.py tests/unit/insights/test_rigor_audit.py tests/unit/mcp/test_insight_shape_tools.py -q; devtools render-all --check; devtools verify --quick.

Ref #866
@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 36 minutes and 38 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1859a3bb-1f49-4797-a1fd-7dce65f8b913

📥 Commits

Reviewing files that changed from the base of the PR and between 4c504ed and 3855ea2.

📒 Files selected for processing (36)
  • AGENTS.md
  • docs/architecture.md
  • docs/internals.md
  • polylogue/api/insights.py
  • polylogue/archive/session/documents.py
  • polylogue/archive/session/models.py
  • polylogue/archive/session/session_summaries.py
  • polylogue/insights/archive.py
  • polylogue/insights/archive_models.py
  • polylogue/insights/archive_rollups.py
  • polylogue/insights/archive_summaries.py
  • polylogue/insights/topology.py
  • polylogue/mcp/payloads.py
  • polylogue/mcp/server_tools.py
  • polylogue/storage/insights/aggregate/records.py
  • polylogue/storage/insights/session/profiles.py
  • polylogue/storage/insights/session/rebuild.py
  • polylogue/storage/insights/session/records.py
  • polylogue/storage/insights/session/refresh.py
  • polylogue/storage/insights/session/storage.py
  • polylogue/storage/sqlite/queries/mappers_insight_aggregates.py
  • polylogue/storage/sqlite/queries/mappers_insight_profiles.py
  • polylogue/storage/sqlite/queries/session_insight_summary_queries.py
  • polylogue/storage/sqlite/schema_ddl.py
  • polylogue/storage/sqlite/schema_ddl_insight_aggregates.py
  • polylogue/storage/sqlite/schema_ddl_insight_profiles.py
  • tests/infra/mcp.py
  • tests/unit/api/test_topology_api.py
  • tests/unit/insights/test_productivity.py
  • tests/unit/insights/test_rigor_audit.py
  • tests/unit/mcp/test_envelope_contracts.py
  • tests/unit/mcp/test_insight_shape_tools.py
  • tests/unit/mcp/test_logical_session_tool.py
  • tests/unit/mcp/test_tool_contracts.py
  • tests/unit/storage/test_dead_schema_sweep.py
  • tests/unit/storage/test_session_insight_refresh.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/logical-session-identity

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity
Sinity merged commit 02decd7 into master May 25, 2026
7 checks passed
@Sinity
Sinity deleted the feature/feat/logical-session-identity branch May 25, 2026 03:59

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3855ea23c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant