Skip to content

Fix: Recent Activity rows intermittently dropping AM/PM#181

Merged
Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:fix/recent-activity-ampm-consistency
Jun 5, 2026
Merged

Fix: Recent Activity rows intermittently dropping AM/PM#181
Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:fix/recent-activity-ampm-consistency

Conversation

@Brandon-Haney

Copy link
Copy Markdown
Collaborator

Problem

A single row in the dashboard's Recent Activity feed could render its time without the AM/PM suffix while the other rows in the same run kept theirs — e.g. 12:32:53 next to 12:32:56 PM.

Root cause

FileActivity.to_dict() called get_time_format() — which re-reads plexcache_settings.json from disk — once per row. The web settings writer rewrote that file non-atomically (open(..., 'w') truncates it to zero bytes before writing). When a settings write overlapped a dashboard render, one row's read could land in the truncated-file window, raise JSONDecodeError, and fall back to the 24h default. At the noon hour the 24h string (12:32:53) is identical to the 12h one apart from the missing PM, so it looked like one row had simply lost its suffix.

Fix

  • FileActivity.to_dict() accepts an explicit time_format; the activity render path reads the format once and passes it to every row, so a render is always internally consistent (all rows share one format).
  • The settings writer now writes atomically (write-temp-then-os.replace) via the shared save_json_atomically() helper, so concurrent readers never observe a partial/empty settings file. This protects every settings reader, not just the activity feed.
  • save_json_atomically() returns a bool so the settings writer keeps its success/failure contract.

Testing

  • Added tests covering to_dict() honoring an explicit time_format (and not re-reading settings), and save_json_atomically() reporting success/failure.
  • Full suite passes.

Manual verification

  1. Open the dashboard's Recent Activity feed.
  2. Trigger a run that writes activity while saving a settings change around the same time (the overlap that previously dropped the suffix).
  3. Confirm every row within a run shows a consistent time format with its AM/PM suffix.

A row in the Recent Activity feed could render without its AM/PM suffix
while its siblings kept theirs. FileActivity.to_dict() called
get_time_format() — which re-reads plexcache_settings.json — once per row,
and the web settings writer truncated the file in place before rewriting
it. When a settings write overlapped a render, one row's read could land
in the empty-file window, raise JSONDecodeError, and fall back to the 24h
default; at the noon hour that looks identical apart from the missing PM.

- to_dict() now accepts an explicit time_format; recent_activity reads it
  once and passes it to every row so a render is internally consistent.
- _save_raw() writes the settings file atomically via save_json_atomically()
  (write-temp-then-replace) so concurrent readers never see a partial file.
- save_json_atomically() returns a bool so the writer keeps its success
  contract.
@Brandon-Haney Brandon-Haney merged commit da469b5 into StudioNirin:main Jun 5, 2026
2 checks passed
@Brandon-Haney Brandon-Haney deleted the fix/recent-activity-ampm-consistency branch June 7, 2026 04: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.

2 participants