Skip to content

[aw][code health] parser.py / pricing.py housekeeping: module-level constant, sort sentinel, missing model #182

@microsasa

Description

@microsasa

Root Cause

Three independent small issues in parser.py and pricing.py that together are worth a single cleanup PR.


1. _RESUME_INDICATOR_TYPES defined inside a function on every call (parser.py)

In build_session_summary (called once per session on every get_all_sessions invocation), a set literal is recreated each time:

# parser.py — inside build_session_summary()
_RESUME_INDICATOR_TYPES: set[str] = {
    EventType.SESSION_RESUME,
    EventType.USER_MESSAGE,
    EventType.ASSISTANT_MESSAGE,
}

This set is invariant and should be a module-level constant (preferably frozenset to signal immutability):

_RESUME_INDICATOR_TYPES: frozenset[str] = frozenset({
    EventType.SESSION_RESUME,
    EventType.USER_MESSAGE,
    EventType.ASSISTANT_MESSAGE,
})

2. _sort_key in get_all_sessions uses ISO string comparison (parser.py)

def _sort_key(s: SessionSummary) -> str:
    if s.start_time is None:
        return ""
    return s.start_time.isoformat()

Sorting by ISO strings works for UTC-normalised datetimes, but using "" as the None sentinel is non-obvious and relies on implicit string ordering. A more explicit pattern uses a datetime sentinel:

_EPOCH = datetime.min.replace(tzinfo=UTC)

def _sort_key(s: SessionSummary) -> datetime:
    return s.start_time if s.start_time is not None else _EPOCH

This also avoids the hidden assumption that all datetimes produce identical ISO format strings (e.g. +00:00 vs Z).


3. gpt-5.4-mini absent from _RAW_MULTIPLIERS (pricing.py)

All sibling models are registered:

Model Multiplier
gpt-5.4 1.0×
gpt-5-mini 0.0×
gpt-5.1-codex-mini 0.33×
gpt-5.4-mini missing

gpt-5.4-mini is a fast/cheap model analogous to gpt-5-mini. Its absence means any session file that references it triggers the UserWarning: Unknown model 'gpt-5.4-mini'; assuming 1× standard pricing. fallback — wrong tier, wrong multiplier. It should be added at 0.0× (free/included, consistent with gpt-5-mini) unless GitHub Copilot documentation specifies otherwise.


Testing Requirement

  • Item 1: No new test needed — existing test_parser.py coverage validates behaviour is unchanged. Verify ruff/pyright still pass.
  • Item 2: Add a test asserting sessions with start_time=None sort last (after all dated sessions) in get_all_sessions results.
  • Item 3: Add a parametrized entry to the existing test_known_multipliers test for ("gpt-5.4-mini", 0.0) and a test_known_tiers entry asserting PricingTier.LIGHT (consistent with other 0× models).

Generated by Code Health Analysis ·

Metadata

Metadata

Assignees

No one assigned

    Labels

    awCreated by agentic workflowaw-dispatchedIssue has been dispatched to implementercode-healthCode cleanup and maintenance

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions