Skip to content

feat(reader): persist reader workspaces - #1056

Merged
Sinity merged 6 commits into
masterfrom
feature/feat/durable-reader-workspaces
May 15, 2026
Merged

Sinity merged 6 commits into
masterfrom
feature/feat/durable-reader-workspaces

Conversation

@Sinity

@Sinity Sinity commented May 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds durable reader workspaces and the first stack/compare reader route surface. Workspaces now persist resolved/degraded target evidence through SQLite, repository, API, daemon HTTP, CLI, and MCP surfaces; the local reader daemon also exposes stack/compare data envelopes for multi-conversation workflows.

Ref #867
Ref #993

Problem

MK3 workspace scope was represented in plans and design docs, but the runtime had no durable workspace table or public surface for saving tabs/stack/compare/timeline state. The reader also only had single-conversation data routes, so a workspace could not restore multi-conversation state after reload or expose degraded/missing target evidence.

Solution

  • Added schema v14 reader_workspaces plus explicit v13->v14 upgrade coverage.
  • Wired workspace CRUD through storage queries, repository writes, Polylogue, daemon /api/user/workspaces, polylogue user-state workspaces, and MCP mutation tools.
  • Normalized workspace open/active targets through the existing recall-pack target resolver so missing/unsupported targets are preserved instead of silently dropped.
  • Added /w/stack and /w/compare shell routes plus /api/stack and /api/compare envelopes.
  • Kept compare alignment honest: this slice supports align=prompt; time, fork_point, and search are rejected until implemented with real semantics.
  • Split stack/compare payload builders into polylogue.daemon.workspace_routes to keep the daemon HTTP module under file-size budget.
  • Refreshed generated CLI/topology docs and the MCP tool schema witness.

Verification

  • pytest -q -n0 tests/unit/storage/test_schema_upgrades.py tests/unit/storage/test_user_state_contracts.py tests/unit/cli/test_user_state_command.py tests/unit/daemon/test_web_reader.py::TestReaderUserState tests/unit/mcp/test_user_state_tools.py tests/unit/mcp/test_envelope_contracts.py -> 62 passed
  • pytest -q -n0 tests/unit/daemon/test_web_reader.py::TestReaderWorkspaceRoutes -> 6 passed
  • pytest -q -n0 tests/unit/mcp/test_tool_schema_witness.py tests/unit/mcp/test_user_state_tools.py tests/unit/mcp/test_envelope_contracts.py -> 42 passed
  • devtools verify --quick -> pass, 27.24s on b4aac17b
  • devtools verify -> pass before final align-mode correction, 6422 pytest cases counted, 133.36s on 249e8e59; final correction was then covered by focused daemon tests and quick gate.

Summary by CodeRabbit

  • New Features

    • Added durable reader workspaces to save and restore multi-conversation reader layouts, including open targets, layout configuration, and active target across CLI, API, and MCP tools.
    • Added user-state workspaces CLI commands to list, save, and delete reader workspace configurations.
    • Added local reader daemon endpoints (/w/stack, /w/compare, /api/stack, /api/compare) for multi-conversation reader workflows.
  • Database

    • Upgraded schema from v13 to v14 to support persistent reader workspaces with resolved/degraded target tracking.

Review Change Stack

Sinity added 5 commits May 15, 2026 18:08
Problem: MK3 workspaces had durable design scope but no runtime substrate, so stack/compare/tab state could not survive reloads or flow through CLI/MCP/daemon surfaces.\n\nWhat changed: add schema v14 reader_workspaces with an explicit v13 upgrade path; wire storage, repository, API, daemon /api/user/workspaces, CLI user-state workspaces, and MCP mutation tools. Workspace targets are normalized through the existing target-resolution path so missing or unsupported targets are preserved as degraded evidence instead of being silently dropped.\n\nVerification:\n- pytest -q -n0 tests/unit/storage/test_schema_upgrades.py tests/unit/storage/test_user_state_contracts.py tests/unit/cli/test_user_state_command.py tests/unit/daemon/test_web_reader.py::TestReaderUserState tests/unit/mcp/test_user_state_tools.py tests/unit/mcp/test_envelope_contracts.py -> 62 passed\n- ruff format --check <touched files> -> 18 files already formatted\n- ruff check <touched files> -> All checks passed\n- python -m mypy <touched polylogue files> -> Success: no issues found in 12 source files\n- devtools render-all --check -> OK
Problem: durable reader workspaces needed route-level stack and compare data, but the daemon only exposed single-conversation reader envelopes.\n\nWhat changed: serve /w/{stack,compare} shell routes and add /api/stack plus /api/compare envelopes that preserve resolved and missing conversation targets. Compare responses include paired/unpaired message rows and align validation for prompt/time/fork_point/search.\n\nVerification:\n- pytest -q -n0 tests/unit/daemon/test_web_reader.py::TestReaderWorkspaceRoutes tests/unit/daemon/test_web_reader.py::TestReaderUserState -> 12 passed\n- ruff format --check polylogue/daemon/http.py tests/unit/daemon/test_web_reader.py && ruff check polylogue/daemon/http.py tests/unit/daemon/test_web_reader.py -> All checks passed\n- python -m mypy polylogue/daemon/http.py -> Success: no issues found in 1 source file\n- devtools render-all --check -> OK
Problem: adding stack/compare route handling pushed the daemon HTTP module over the file-size budget, making future reader route work harder to review.\n\nWhat changed: move stack/compare payload builders and dispatch glue into polylogue.daemon.workspace_routes, keep http.py as transport dispatch, refresh topology status, and update the schema bootstrap budget exception from v13 to v14 to match the new reviewed migration branch.\n\nVerification:\n- pytest -q -n0 tests/unit/daemon/test_web_reader.py::TestReaderWorkspaceRoutes tests/unit/daemon/test_web_reader.py::TestReaderUserState -> 12 passed\n- ruff format --check polylogue/daemon/http.py polylogue/daemon/workspace_routes.py tests/unit/daemon/test_web_reader.py && ruff check polylogue/daemon/http.py polylogue/daemon/workspace_routes.py tests/unit/daemon/test_web_reader.py -> All checks passed\n- python -m mypy polylogue/daemon/http.py polylogue/daemon/workspace_routes.py -> Success: no issues found in 2 source files\n- devtools verify-file-budgets -> clean\n- devtools render-all --check -> OK
Problem: topology verification treats new source files as orphans until the topology projection records ownership.\n\nWhat changed: regenerate docs/plans/topology-target.yaml so polylogue/daemon/workspace_routes.py is declared as a stable daemon surface module.\n\nVerification:\n- devtools build-topology-projection -> wrote 728 rows\n- devtools render-topology-status -> completed
Problem: adding workspace MCP tools intentionally changed the admin tool catalog, so the committed wire-schema witness drifted.\n\nWhat changed: regenerate tests/data/witnesses/mcp-tool-schemas.json and carry the generated topology-status refresh from the new daemon workspace route module.\n\nVerification:\n- pytest -q -n0 tests/unit/mcp/test_tool_schema_witness.py tests/unit/mcp/test_user_state_tools.py tests/unit/mcp/test_envelope_contracts.py -> 42 passed
@coderabbitai

coderabbitai Bot commented May 15, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ee325518-bfab-4d60-aa67-6c9b71f4ebfa

📥 Commits

Reviewing files that changed from the base of the PR and between fccf937 and b4aac17.

📒 Files selected for processing (26)
  • CHANGELOG.md
  • docs/cli-reference.md
  • docs/plans/file-size-budgets.yaml
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/api/archive.py
  • polylogue/cli/commands/user_state.py
  • polylogue/daemon/http.py
  • polylogue/daemon/user_state_http.py
  • polylogue/daemon/workspace_routes.py
  • polylogue/mcp/payloads.py
  • polylogue/mcp/server_mutation_tools.py
  • polylogue/storage/repository/archive/repository_writes.py
  • polylogue/storage/sqlite/queries/conversations.py
  • polylogue/storage/sqlite/queries/conversations_identity.py
  • polylogue/storage/sqlite/schema.py
  • polylogue/storage/sqlite/schema_bootstrap.py
  • polylogue/storage/sqlite/schema_ddl.py
  • polylogue/storage/sqlite/schema_ddl_archive.py
  • tests/data/witnesses/mcp-tool-schemas.json
  • tests/unit/cli/test_user_state_command.py
  • tests/unit/daemon/test_web_reader.py
  • tests/unit/mcp/test_envelope_contracts.py
  • tests/unit/mcp/test_user_state_tools.py
  • tests/unit/storage/test_schema_upgrades.py
  • tests/unit/storage/test_user_state_contracts.py

📝 Walkthrough

Walkthrough

This PR introduces durable reader workspaces—a feature enabling users to save, retrieve, and manage multi-conversation reader layouts with explicit handling of resolved/degraded conversation targets across tabs, stack, compare, and timeline modes. The changes span schema v13→v14, SQLite persistence, HTTP/CLI/MCP APIs, and comprehensive tests.

Changes

Durable Reader Workspaces Feature

Layer / File(s) Summary
Schema definition and version upgrade
polylogue/storage/sqlite/schema_ddl_archive.py, polylogue/storage/sqlite/schema_ddl.py, polylogue/storage/sqlite/schema_bootstrap.py, polylogue/storage/sqlite/schema.py
Defines reader_workspaces table DDL with workspace metadata, layout, and target JSON fields plus indexes. Upgrades schema version from 13 to 14 and establishes conditional upgrade path that applies DDL only when the table is absent.
SQLite workspace queries and row mapping
polylogue/storage/sqlite/queries/conversations_identity.py, polylogue/storage/sqlite/queries/conversations.py
Implements workspace CRUD operations (save/get/list/delete) with SQL upsert logic and row mapping. Exports functions through conversations.py module.
Repository and archive API methods
polylogue/storage/repository/archive/repository_writes.py, polylogue/api/archive.py
Repository layer delegates to SQLite queries with timestamp generation. Archive mixin adds validation, target normalization via recall-pack item resolution, JSON encoding with stable key ordering, and CRUD entry points.
HTTP daemon user-state workspace handlers
polylogue/daemon/user_state_http.py
Adds HTTP request dispatch and payload parsing for /workspaces routes (list, get, save, delete). Handlers validate request bodies, normalize JSON payloads with deterministic serialization, return 201 for new workspaces and 200 for updates, and 404 for missing workspaces.
Workspace routes for stack/compare modes
polylogue/daemon/workspace_routes.py
Introduces daemon-side route handlers building structured API responses for stack (per-conversation loaded items with resolved/degraded status) and compare (pairwise message alignment with paired/unpaired indices) modes, including missing-target evidence and degradation metrics.
HTTP dispatcher integration
polylogue/daemon/http.py
Integrates workspace_routes module into main HTTP GET dispatcher, permits unauthenticated /w/<mode> shell paths for supported modes, and delegates /api/workspace paths to workspace route handlers.
CLI workspace command group
polylogue/cli/commands/user_state.py
Adds user-state workspaces subcommand with list, save, and delete operations. Includes canonical JSON helpers for parsing/serializing target and layout payloads and text/JSON output formatting.
MCP workspace payload models
polylogue/mcp/payloads.py
Defines typed Pydantic models MCPReaderWorkspacePayload and MCPReaderWorkspaceListPayload representing workspace metadata with resolved targets, layout, and timestamps.
MCP workspace mutation tools
polylogue/mcp/server_mutation_tools.py
Registers three MCP tools (list_workspaces, save_workspace, delete_workspace) with input validation, JSON parsing for target/layout fields, and mutation result envelopes (added/updated vs. not_found).
Storage and schema upgrade tests
tests/unit/storage/test_schema_upgrades.py, tests/unit/storage/test_user_state_contracts.py
Unit tests verify v13→v14 schema upgrade creates table with expected columns, and workspace persistence preserves resolved/degraded target status, conversation hash stability, and active target identity.
HTTP daemon and CLI tests
tests/unit/cli/test_user_state_command.py, tests/unit/daemon/test_web_reader.py
Tests verify /api/user/workspaces and /api/stack//api/compare endpoints handle mixed resolved/missing/unsupported targets, validate required parameters, and CLI commands serialize JSON canonically.
MCP tool and envelope tests
tests/unit/mcp/test_envelope_contracts.py, tests/unit/mcp/test_user_state_tools.py
Tests verify MCP workspace tools have correct envelope signatures (items/total for list, operation_result for mutations), handle roundtrip payloads with typed fields, and return proper status/detail on success and failure.
Documentation and metadata
CHANGELOG.md, docs/cli-reference.md, docs/plans/file-size-budgets.yaml, docs/plans/topology-target.yaml, docs/topology-status.md
Updates CHANGELOG with workspace persistence across archive API and MCP tools, CLI reference with workspaces subcommand, file-size budget for schema_bootstrap.py (v14), and generated topology metadata (module line counts and stability totals).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

type:test, area:storage, area:schema, area:qa

Poem

🐰 Workspaces saved with hearts so bright,
Reader layouts persist through the night,
Stacks and compares in schema v14,
Resolved targets dance—no need for despair!
From SQLite to MCP, the journey's clear. 🎉

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/durable-reader-workspaces

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.

Problem: the compare route accepted time/fork_point/search align values while still using positional prompt pairing, which made unsupported modes look successful.\n\nWhat changed: restrict accepted compare alignment to prompt for this route slice and add a regression asserting unimplemented align modes are rejected until real semantics exist.\n\nVerification:\n- pytest -q -n0 tests/unit/daemon/test_web_reader.py::TestReaderWorkspaceRoutes -> 6 passed\n- ruff format --check polylogue/daemon/workspace_routes.py tests/unit/daemon/test_web_reader.py && ruff check polylogue/daemon/workspace_routes.py tests/unit/daemon/test_web_reader.py -> All checks passed\n- python -m mypy polylogue/daemon/workspace_routes.py -> Success: no issues found in 1 source file
@Sinity
Sinity merged commit 87c37f2 into master May 15, 2026
3 of 4 checks passed
@Sinity
Sinity deleted the feature/feat/durable-reader-workspaces branch May 15, 2026 16:28

@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: 249e8e59f7

ℹ️ 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".

Comment thread polylogue/daemon/workspace_routes.py Resolved
@Sinity

Sinity commented Sep 30, 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.

  • 65.F045 / P2: fixed-already at the checked revision: The supported comparison-mode set now contains only prompt at polylogue/daemon/workspace_routes.py:19. The HTTP handler checks that set and returns HTTP 400 for time, fork_point or search at lines 177-179, before constructing any pairs; it no longer accepts those modes and returns positional results under misleading mode labels.

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