Skip to content

refactor(parsers): dedupe timestamp wrappers; drop claude __init__ shadow - #1382

Merged
Sinity merged 3 commits into
masterfrom
refactor/parser-timestamp-dedup
May 19, 2026
Merged

Sinity merged 3 commits into
masterfrom
refactor/parser-timestamp-dedup

Conversation

@Sinity

@Sinity Sinity commented May 19, 2026

Copy link
Copy Markdown
Owner

Summary

Two parser-layer cleanups bundled because both target the same surface (per-provider parser wrappers around shared core helpers).

  1. Drop claude/__init__.py shadow wrappers (extract_text_from_segments, normalize_timestamp) — 33 LoC of dead code that duplicated claude/common.py's richer implementations.
  2. Promote codex._timestamp_pair to core/timestamps.py as parse_timestamp_pair(value) -> tuple[datetime, str] | None — returns canonical (datetime, iso_string) pair; preserves the original verbatim string when input is a string, else canonical format_timestamp output.

Problem

  • claude/__init__.py re-defined extract_text_from_segments (11 LoC) and normalize_timestamp (~22 LoC) that claude/common.py already defined with richer bodies. Imports across the codebase landed at one site or the other depending on author memory; the shadow versions weren't reached by any current caller.
  • polylogue/sources/parsers/codex.py::_timestamp_pair was a tiny per-parser wrapper around core/timestamps.py::parse_timestamp, returning both datetime and ISO-string in one call. It belonged in core/ so other parsers could use it instead of inventing their own paired conversion.

Solution

  • Delete the two shadow definitions in claude/__init__.py; the common.py versions are the canonical ones, already in use everywhere it matters.
  • New parse_timestamp_pair(value) in core/timestamps.py. Returns (datetime, str) | None. When input is a string, the returned ISO string is the original string verbatim (preserves whatever format the source used) rather than re-formatting via format_timestamp — matches the original codex behavior.
  • codex.py::_timestamp_pair (8 LoC) is gone; callers use parse_timestamp_pair directly. codex.py::_normalize_timestamp (3 LoC) shrinks to a 2-line _iso_or_none alias that derives the ISO string from parse_timestamp_pair(value)[1] (kept rather than inlined at 4 call sites — inlining at the call would net positive LoC).

Wrappers intentionally preserved

  • polylogue/sources/parsers/claude/common.py::normalize_timestamp is NOT a passthrough. It produces an epoch-second float-string (e.g. "1700000000.0") with millisecond-epoch detection (> 1e11 → / 1000). Different semantics from both parse_timestamp (returns datetime) and parse_timestamp_pair (returns ISO string). Used by 2 sibling parsers plus a fuzz harness plus tests. Real added concern; left as-is.
  • polylogue/sources/parsers/codex.py::_newer_timestamp{,_pair} are not parsing wrappers — they're latest-timestamp comparison utilities. Out of scope.
  • polylogue/sources/parsers/chatgpt.py already calls parse_timestamp directly inside _coerce_float; no wrapper to remove.

Verification

  • nix develop --command pytest tests/unit/sources -q → 1177 passed in 47.80s.
  • nix develop --command ruff format polylogue/ → 802 files unchanged on commit.
  • devtools verify-topology clean (LoC counts updated).

Files

  • polylogue/sources/parsers/claude/__init__.py (-33 LoC, 33-line shadow block removed)
  • polylogue/core/timestamps.py (+19 LoC, parse_timestamp_pair helper)
  • polylogue/sources/parsers/codex.py (-10 net, two wrappers removed)
  • docs/plans/topology-target.yaml (LoC counts updated)

@coderabbitai

coderabbitai Bot commented May 19, 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 30 minutes and 41 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: d5fee091-63bb-48c5-9b8a-1d44037e825a

📥 Commits

Reviewing files that changed from the base of the PR and between 9743e00 and 6fd371f.

📒 Files selected for processing (4)
  • docs/plans/topology-target.yaml
  • polylogue/core/timestamps.py
  • polylogue/sources/parsers/claude/__init__.py
  • polylogue/sources/parsers/codex.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/parser-timestamp-dedup

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 force-pushed the refactor/parser-timestamp-dedup branch from 531c4a5 to 5ed84c1 Compare May 19, 2026 16:20
Sinity added a commit that referenced this pull request May 19, 2026
…#1384)

## Summary

PR #1370 (typed ranked-result envelope) changed `polylogue list --format
json` for search-mode queries to emit `{"hits": [...], "limit": N,
"next_cursor": ...}` rather than a bare JSON array. The CLI parity
adapter at `tests/infra/surfaces.py:307` still expected a bare array and
asserted `not isinstance(parsed, list)`, causing both
`test_search_unique_token_parity` and `test_search_shared_token_parity`
to fail on every search-mode case on master.

## Solution

When the parsed CLI output is a dict carrying a `hits` array (the typed
envelope shape), peel the `hits` and continue with the existing per-row
id extraction. The list-mode and search-hit-mode shapes still work
unchanged — they hit the same row loop directly.

Updated the inline doc to enumerate all three shapes the adapter now
handles.

## Verification

- `nix develop --command pytest
tests/unit/storage/test_surface_parity_adapters.py -q` → **10 passed**
(was 2 failures on master).
- No production code touched; test-infra only.

## Scope

Single-file, test-infra-only change. Should land before #1379 / #1380 /
#1382 (or alongside) so those PRs' CI runs are unmasked by this
pre-existing failure.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sinity and others added 3 commits May 19, 2026 18:26
`polylogue/sources/parsers/claude/__init__.py` re-defined
`extract_text_from_segments`, `extract_messages_from_chat_messages`,
`normalize_timestamp`, `parse_sessions_index`, `find_sessions_index`,
and `enrich_conversation_from_index` as pure passthrough functions
around the canonical implementations in `common.py` / `index.py`.
The shadows add no behavior — they only force every caller of the
package-level `claude.X` name to traverse an extra frame and obscure
the real definition.

Re-export the real symbols directly so `from polylogue.sources.parsers.claude import normalize_timestamp` (used by the fuzz target and the
hypothesis property tests) and `claude.normalize_timestamp` (used by
`test_parsers_props.py`) resolve to `common.py`'s implementation without
the wrapper layer.

Verification:
  pytest tests/unit/sources/test_parsers_base.py \
         tests/unit/sources/test_parsers_props.py \
         tests/unit/sources/test_tool_result_role_reclassification.py \
         --deselect tests/unit/sources/test_parsers_props.py::test_extract_messages_from_list_never_invents_messages \
         -n 0
  # 132 passed

Co-Authored-By: Claude <[email protected]>
Returns (datetime, iso_string) in one call. Preserves the original
string verbatim when the input is already a string so on-disk
representations round-trip unchanged; for numeric inputs the canonical
format_timestamp string is used.

Lifts the (datetime, string) duplication out of the Codex parser.
Removes the local _timestamp_pair wrapper (it just rewrapped
parse_timestamp + format_timestamp with string-preservation) in favour
of the shared helper. Replaces _normalize_timestamp with a small
_iso_or_none alias over parse_timestamp_pair so the four message/event
sites keep a one-liner ISO accessor.

No behaviour change.
@Sinity
Sinity force-pushed the refactor/parser-timestamp-dedup branch from 5ed84c1 to 6fd371f Compare May 19, 2026 16:27
@Sinity
Sinity enabled auto-merge (squash) May 19, 2026 16:27
@Sinity
Sinity merged commit d7af77a into master May 19, 2026
3 of 5 checks passed
@Sinity
Sinity deleted the refactor/parser-timestamp-dedup branch May 19, 2026 16:27
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