Repository navigation
fix(storage): derive session timestamps from message evidence - #3285
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 28 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (14)
📝 WalkthroughWalkthroughAdds message-derived session timestamp fallbacks during archive writes, a bounded ChangesSession timestamp maintenance
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Doctor
participant RepairDispatch
participant SessionTimestampBackfill
participant SQLite
Doctor->>RepairDispatch: select session_timestamp_backfill
RepairDispatch->>SessionTimestampBackfill: preview or run backfill
SessionTimestampBackfill->>SQLite: aggregate message timestamps
SQLite-->>SessionTimestampBackfill: candidate or repaired row count
SessionTimestampBackfill-->>RepairDispatch: BackfillResult
RepairDispatch-->>Doctor: RepairResult
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@polylogue/storage/repair.py`:
- Around line 6688-6709: Add preview_session_timestamp_backfill and
repair_session_timestamp_backfill to the module’s __all__ export list, matching
the established export parity of the other preview/repair handler pairs. Do not
alter the handler implementations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 4ccad804-0cc7-4a7a-9ed3-57673edc2176
📒 Files selected for processing (14)
docs/cli-reference.mddocs/maintenance.mddocs/plans/topology-target.yamldocs/test-quality-workflows.mddocs/topology-status.mdpolylogue/maintenance/targets.pypolylogue/storage/repair.pypolylogue/storage/session_timestamp_backfill.pypolylogue/storage/sqlite/archive_tiers/write.pytests/unit/core/test_maintenance_targets.pytests/unit/devtools/test_artifact_graph.pytests/unit/storage/test_archive_tiers_write.pytests/unit/storage/test_session_insight_refresh.pytests/unit/storage/test_session_timestamp_backfill.py
| def preview_session_timestamp_backfill(*, count: int) -> RepairResult: | ||
| """Preview handler for the #m3p9 session-timestamp backfill. | ||
|
|
||
| Thin shim over ``session_timestamp_backfill.preview_backfill`` so the | ||
| repair orchestrator's preview dispatch keeps working. | ||
| """ | ||
| from polylogue.storage.session_timestamp_backfill import preview_backfill | ||
|
|
||
| return _session_timestamp_backfill_to_repair_result(preview_backfill(count=count)) | ||
|
|
||
|
|
||
| def repair_session_timestamp_backfill(config: Config, dry_run: bool = False) -> RepairResult: | ||
| """Derive ``sessions.created_at_ms``/``updated_at_ms`` from message | ||
| evidence for rows ingested before the write path fell back to it. | ||
|
|
||
| Delegates to ``storage.session_timestamp_backfill.run_backfill``; the | ||
| implementation lives there to keep this module under its file-size | ||
| budget (see ``docs/plans/file-size-budgets.yaml``). | ||
| """ | ||
| from polylogue.storage.session_timestamp_backfill import run_backfill | ||
|
|
||
| return _session_timestamp_backfill_to_repair_result(run_backfill(config, dry_run=dry_run)) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add the new handlers to __all__.
Every other preview/repair pair in this module (preview_message_type_backfill/repair_message_type_backfill, preview_session_insights/repair_session_insights) is exported in __all__, but preview_session_timestamp_backfill/repair_session_timestamp_backfill are missing, breaking that established parity.
🔧 Proposed fix
"preview_orphaned_messages",
"preview_message_type_backfill",
+ "preview_session_timestamp_backfill",
"preview_session_insights",
"raw_materialization_replay_backlog",
"raw_materialization_scale_profile",
"repair_empty_sessions",
"repair_message_type_backfill",
+ "repair_session_timestamp_backfill",
"repair_orphaned_attachments",Also applies to: 6837-6872
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@polylogue/storage/repair.py` around lines 6688 - 6709, Add
preview_session_timestamp_backfill and repair_session_timestamp_backfill to the
module’s __all__ export list, matching the established export parity of the
other preview/repair handler pairs. Do not alter the handler implementations.
…gue-m3p9) Problem: sessions.created_at_ms/updated_at_ms are plain columns the writer only sets from provider-supplied session-level timestamps. Codex, most Claude Code sessions, and Hermes/observer material never carry those at the session level even though their messages are individually timestamped, so 65,946 of 83,198 sessions (79%) on the live archive have both columns NULL. since:/until:/recency ordering and --by year/month histograms silently exclude that four-fifths of the archive. What changed: - write_parsed_session_to_archive falls back to the min/max of the incoming write's own message occurred_at_ms when the provider gives no session-level created_at/updated_at. A prefix-sharing child's derived created_at_ms reflects the whole conversation's start (the full parsed message set, before prefix-tail slicing); the derived max is correct either way since the newest message always survives slicing into the tail. Provider-supplied timestamps always win; a session with no timestamped message either (genuinely undatable) stays NULL, never backdated to the ingest wall clock. incoming_freshness_ms (the skip-stale-replace guard) now reads the same derived value, so a genuinely stale replay of a no-session-timestamp provider is correctly skipped instead of always winning through an unconditional "freshness unknown" bypass. - New session_timestamp_backfill maintenance target (repair, non- destructive) backfills the derivation for already-archived rows via one bounded UPDATE ... FROM aggregate over messages, COALESCE-guarded so any existing provider timestamp is preserved. Registered in MAINTENANCE_TARGET_SPECS, PREVIEW_HANDLERS, REPAIR_HANDLERS, and the docs-surface/artifact-graph coverage registries. Verification: devtools test tests/unit/storage/test_session_timestamp_backfill.py tests/unit/storage/test_archive_tiers_write.py tests/unit/core/test_maintenance_targets.py tests/unit/devtools/test_artifact_graph.py tests/unit/storage/test_session_insight_refresh.py tests/unit/storage/test_repair.py (175 passed); devtools verify --quick (pass). Ref polylogue-m3p9 Co-Authored-By: Codex <[email protected]> Co-Authored-By: Claude <[email protected]>
b71bde6 to
0f98aaf
Compare
Problem: three snapshot files pinned CLI help/output text and archive diagnostics from before several unrelated, already-merged feature changes: - #3311 (93f2982, "bounded predicate attribution for zero-hit queries") added the `--why` flag to query verbs. - #3285 (f4cd341, "derive session timestamps from message evidence") added the `session_timestamp_backfill` maintenance target. - SOURCE_SCHEMA_VERSION and INDEX_SCHEMA_VERSION advanced (13->14, 43->45) via already-landed additive durable/derived migrations on this branch. - This session's schema-annotation fix (Ref polylogue-c66i, previous commits) changed synthetic-corpus generated content (real user/assistant text instead of `synthetic-<n>` placeholders), which legitimately changed demo-fixture token counts, evidence-ref ordering, and wall-clock distribution figures baked into these snapshots. None of these are test bugs or production regressions -- the snapshots were simply stale relative to already-merged, intentional changes. What changed: regenerated via `pytest ... --snapshot-update`: - tests/unit/cli/__snapshots__/test_help_snapshots.ambr - tests/unit/cli/__snapshots__/test_terminal_snapshots.ambr (--why help text, session_timestamp_backfill --target choice) - tests/unit/cli/__snapshots__/test_plain_cli_snapshots.ambr (token counts, evidence_refs ordering, wallclock distribution, source/index tier user_version, sqlite_stat1_rows) Verification: - devtools test tests/unit/cli/test_help_snapshots.py tests/unit/cli/test_terminal_snapshots.py tests/unit/cli/test_plain_cli_snapshots.py -> 34 passed (21 snapshots passed, 0 updated on the verification re-run). Ref polylogue-c66i Co-Authored-By: Claude <[email protected]>
Summary
Sessions whose provider payload carries no session-level timestamp (Codex, most Claude Code sessions, Hermes/observer material) now get
created_at_ms/updated_at_msderived from their own messages'occurred_at_ms, at write time and via a bounded backfill for already-archived rows.Problem
sessions.created_at_ms/updated_at_msare plain columns the writer only sets from provider-supplied session-level timestamps. On the live archive, 65,946 of 83,198 sessions (79%) have both NULL.since:/until:filters, recency ordering, and--by year/monthhistograms silently exclude that four-fifths of the archive, even though the excluded sessions' individual messages are timestamped.Solution
write_parsed_session_to_archivefalls back to the min/max of the incoming write's own messageoccurred_at_mswhen the provider gives no session-levelcreated_at/updated_at. Computed over the full parsed message set (before prefix-tail slicing) so a prefix-sharing child's derivedcreated_at_msreflects the whole conversation's start. Provider-supplied timestamps always win; a session with no timestamped message either stays NULL rather than being backdated to the ingest wall clock. The skip-stale-replace freshness guard (incoming_freshness_ms) now reads the same derived value, so a genuinely stale replay of a no-session-timestamp provider is correctly skipped instead of always winning through an unconditional "freshness unknown" bypass.session_timestamp_backfillmaintenance target (repair, non-destructive): one boundedUPDATE ... FROMaggregate overmessages, COALESCE-guarded so any existing provider timestamp is preserved — safe to run repeatedly. Registered inMAINTENANCE_TARGET_SPECS,PREVIEW_HANDLERS,REPAIR_HANDLERS, and the docs-surface/artifact-graph coverage registries.Verification
devtools test tests/unit/storage/test_session_timestamp_backfill.py tests/unit/storage/test_archive_tiers_write.py tests/unit/core/test_maintenance_targets.py tests/unit/devtools/test_artifact_graph.py tests/unit/storage/test_session_insight_refresh.py tests/unit/storage/test_repair.py— 175 passed.devtools verify --quick— pass.Not yet done: running the backfill against the live archive (
polylogue ops maintenance --repair --target session_timestamp_backfill) and recording the receipt — planned as a follow-up action once this merges, per polylogue-m3p9's acceptance criteria.Ref polylogue-m3p9
Summary by CodeRabbit
New Features
Documentation
Bug Fixes