Skip to content

feat(insights): productivity rollups with explicit caveats (#1134) - #1167

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/productivity-rollups-v2
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/productivity-rollups-v2

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026

Copy link
Copy Markdown
Owner

Summary

Add ProductivityRollupInsight envelope computed live over already-materialized session_profile and session_work_event substrates. Productivity-style aggregates — hour-of-day histogram, project focus share, context-switch count, and work-event outcome breakdown — at day / week / project granularity. Every envelope ships a baseline disclaimer naming the structural limits of any rollup over archived AI conversations; every entry carries typed caveats plus opaque evidence_inputs linking back to the source rows.

Problem

#1134 (parent #994, W16 of #827) asks for productivity rollups derived from the existing session insights, but with explicit caveats so the read surface never claims more than the evidence supports. The substrate (session_profiles, session_work_events) already carries the necessary signal; the missing pieces are a typed envelope that (a) refuses subjective composite scores, (b) makes caveats a first-class field readers cannot accidentally drop, and (c) gives readers evidence_inputs they can drill into.

Solution

New module polylogue/insights/productivity.py:

  • ProductivityRollupInsight envelope with entries, baseline_caveats, total counters, and provenance — single envelope returned per call, consistent with the day/week summary precedent.
  • ProductivityRollupEntry carries bucket_key, objective metrics (session/work-event counts, hour-of-day histogram, project focus share, context-switch count, outcome breakdown), evidence_inputs, and per-entry caveats.
  • BASELINE_CAVEATS constant — five typed strings naming the structural limits (off-screen work not represented, untimed sessions excluded from histograms, cwd_paths provenance, context-switch ceiling semantics, work-event classifier support level). Surfaced on every envelope; tests pin its presence.
  • build_productivity_rollup_insight — pure aggregator, ownership-free of the fetch, exercised identically from tests, operations, CLI, and MCP.
  • Caveat invariants: low-evidence (< 3 sessions/bucket), high untimed share (≥ 25%), high unattributed share (≥ 25%), and missing work events each emit specific caveats; baseline caveats are never dropped.

Wiring:

  • polylogue/operations/archive.py: list_productivity_rollup_insights reads profile and work-event insights via a typed cross-mixin Protocol (_SessionInsightReaders) and delegates aggregation to the pure builder. Module-level convenience function added.
  • polylogue/insights/registry.py: registered with cli_command_name="productivity", readiness_exempt=True, mcp_default_limit=200, and CLI options for granularity / provider / since / until — registry dispatch automatically materializes the CLI subcommand and the MCP productivity_rollups tool.
  • polylogue/api/insights.py and polylogue/api/sync/insights.py: async and sync facade methods.
  • polylogue/operations/specs.py + polylogue/artifacts/runtime.py: query-productivity-rollups operation and productivity_rollup_results artifact node + path.
  • polylogue/scenarios/execution.py: scenario-name mapping for the new operation.

Tests in tests/unit/insights/test_productivity.py (22 cases) cover:

  1. Registry wiring (entry routes to the operations method, query model matches).
  2. Baseline envelope invariants (caveats always present, provenance/version stamped).
  3. Day / week / project bucket aggregation.
  4. Hour-of-day histogram + untimed exclusion + tracking.
  5. Context-switch ceiling (n-1 distinct paths).
  6. Outcome breakdown by work_event.kind and evidence_inputs linkage.
  7. Caveat firing (low evidence, untimed share, unattributed share, missing events).
  8. Provider and time-window filtering.

tests/unit/mcp/test_envelope_contracts.py extended to classify the new MCP tool as an {items, total} envelope; tests/data/witnesses/mcp-tool-schemas.json regenerated to include the new tool's wire schema.

docs/plans/file-size-budgets.yaml ceiling for operations/archive.py raised from 1200 → 1300 to absorb the cross-mixin Protocol plus the new method; the corresponding split candidate already exists in the same row. Topology projection regenerated.

Verification

nix develop -c pytest tests/unit/insights tests/unit/mcp
# 259 passed in 13.05s

nix develop -c devtools verify --quick
# total_duration_s: 23.77, exit_code: 0

nix develop -c mypy polylogue/insights/productivity.py polylogue/operations/archive.py \
  polylogue/api/insights.py polylogue/api/sync/insights.py polylogue/insights/registry.py \
  polylogue/operations/__init__.py polylogue/operations/specs.py \
  polylogue/artifacts/runtime.py polylogue/scenarios/execution.py \
  tests/unit/insights/test_productivity.py
# Success: no issues found in 10 source files

nix develop -c polylogue insights productivity --help
# Renders day/week/project flag + provider/since/until from the registry.

Pre-existing test_check.py KeyError('message_embeddings') failures reproduce on origin/master (confirmed by reset-and-rerun); they are inherited and out of scope for this PR.

Closes #1134

@coderabbitai

coderabbitai Bot commented May 17, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 5 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 86e56f6a-f414-46a2-aed5-7a6197a4a3bd

📥 Commits

Reviewing files that changed from the base of the PR and between c7fc08a and 36a2a9e.

📒 Files selected for processing (18)
  • docs/cli-reference.md
  • docs/plans/file-size-budgets.yaml
  • docs/plans/topology-target.yaml
  • docs/test-quality-workflows.md
  • docs/topology-status.md
  • docs/verification-catalog.md
  • polylogue/api/insights.py
  • polylogue/api/sync/insights.py
  • polylogue/artifacts/runtime.py
  • polylogue/insights/productivity.py
  • polylogue/insights/registry.py
  • polylogue/operations/__init__.py
  • polylogue/operations/archive.py
  • polylogue/operations/specs.py
  • polylogue/scenarios/execution.py
  • tests/data/witnesses/mcp-tool-schemas.json
  • tests/unit/insights/test_productivity.py
  • tests/unit/mcp/test_envelope_contracts.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/productivity-rollups-v2

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.

Add ProductivityRollupInsight envelope computed live over already-
materialized session_profile and session_work_event substrates.
Granularity is day / week / project; aggregates are objective counts
and distributions (hour-of-day histogram, project focus share, context
switch count, work-event outcome breakdown). Every envelope ships a
baseline disclaimer naming the structural limits of any rollup over
archived AI conversations, and every entry carries typed caveats plus
opaque evidence_inputs that link back to the source rows.

Wired through the registry so CLI (`polylogue insights productivity`),
MCP (`productivity_rollups`), and the async/sync Python APIs surface
the same envelope, consistent with the day/week summary precedent.
No new command island.

Closes #1134

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Sinity
Sinity force-pushed the feature/feat/productivity-rollups-v2 branch from e1a7685 to 36a2a9e Compare May 17, 2026 09:42
@Sinity
Sinity merged commit c5c5a1f into master May 17, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/feat/productivity-rollups-v2 branch May 17, 2026 09:42

@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: e1a76852ac

ℹ️ 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/insights/productivity.py Resolved
Comment thread polylogue/insights/productivity.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.

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.

feat(insights): productivity analytics rollups with explicit caveats

1 participant