Skip to content

fix: log via context["log"] not print(), fix LRC timestamp rollover - #9

Merged
cchacs merged 9 commits into
mainfrom
claude/bug-search-mfyoq0
Sep 9, 2026
Merged

cchacs merged 9 commits into
mainfrom
claude/bug-search-mfyoq0

Conversation

@cchacs

@cchacs cchacs commented Sep 8, 2026

Copy link
Copy Markdown

Summary

  • lk_generate_pitch's /pitch fallback logging used bare print() instead of context["log"], violating the plugin contract (bypasses correlation IDs and log rotation) and core's print()-guard CI check. Added a module-level _log wired from context["log"] in setup(), defaulting to a plain stdlib logger of the same name so nothing needs a None-check.
  • _format_lrc computed minutes/seconds independently (int(t // 60), f"{t % 60:05.2f}"), so a seconds remainder that rounds up to 60.00 under :05.2f (e.g. 59.996) printed an invalid timestamp like [01:60.00] instead of rolling into the next minute. New _lrc_timestamp() rounds to whole centiseconds first, then splits into minutes/seconds (same fix applied to the lyrics_sync plugin's copy of this same bug — see fix: LRC timestamp rollover, malformed-segment 500s, non-ASCII export crash feedBack-plugin-lyrics-sync#11).
  • Follow-up commit: swapped asyncio.get_event_loop() for asyncio.get_running_loop() at the one call site — a no-behavior-change modernization (confirmed no deprecation warning was actually firing), not a bug fix.

Test plan

  • pytest tests/test_helpers.py — 26 passed (new tests for the rollover, a source-level guard against a future print() creeping back in, and setup() wiring context["log"] into the module global)

🤖 Generated with Claude Code

https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy


Generated by Claude Code

…lover

- lk_generate_pitch's /pitch fallback logging used bare print() instead
  of context["log"], violating the plugin contract (bypasses correlation
  IDs and log rotation) and core's print()-guard CI check. Added a
  module-level _log wired from context["log"] in setup(), defaulting to
  a plain stdlib logger of the same name so nothing needs a None-check.
- _format_lrc computed minutes/seconds independently
  (int(t // 60), f"{t % 60:05.2f}"), so a seconds remainder that rounds
  up to 60.00 under :05.2f (e.g. 59.996) printed an invalid timestamp
  like [01:60.00] instead of rolling into the next minute. New
  _lrc_timestamp() rounds to whole centiseconds first, then splits into
  minutes/seconds, so the carry happens before formatting (same fix
  applied to the lyrics_sync plugin's copy of this same bug).
- Bumped plugin.json to 1.4.6 (bug fixes affecting real behavior).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy
get_event_loop() is deprecated for the 'no running loop' case (creating
one implicitly); this call site is always inside a running loop already
(an async route handler), so get_running_loop() is the more correct,
self-documenting call — get_event_loop() here never actually triggered
the deprecation warning (a running loop already exists whenever this
line executes), so this is a no-behavior-change modernization, not a
bug fix. No version bump — nothing user-visible changed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy

@pullfrog pullfrog 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.

ℹ️ Minor suggestions only — the fixes themselves are correct and well-tested; one test-hygiene nit inline.

Reviewed changes

  • _lrc_timestamp() rollover fix — _format_lrc now rounds to whole centiseconds before splitting into minutes/seconds, so 59.996 formats as 01:00.00 instead of the invalid 01:60.00. Verified by hand: output is byte-identical for non-rollover inputs (the existing test_format_lrc_basic_timestamps still pins [01:05.50]).
  • print() → context["log"] — both /pitch-fallback prints in _worker now go through a module-level _log wired from context["log"] in setup() (falling back to a namespaced stdlib logger so no None-check is needed). Grep confirms no other print() remains in routes.py, and _log is always captured after setup() has run.
  • asyncio.get_event_loop() → get_running_loop() — genuine no-behavior-change modernization; the call site lives inside async def lk_generate_pitch (routes.py:794), where both calls return the running loop.
  • Version bump 1.4.5 → 1.4.6 plus three new tests with exact-equality assertions. ci/python and all three compliance checks are green on 729b78a.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using Big Pickle (free) | 𝕏

Comment thread tests/test_helpers.py Resolved

cchacs commented Sep 8, 2026

Copy link
Copy Markdown
Author

Reviewed this PR (not driving it, just leaving findings).

Same _lrc_timestamp helper as feedBack-plugin-lyrics-sync#11 (the two plugins duplicate this LRC-formatting logic, per lyrics-karaoke#6's own note) has an unguarded crash on infinite input:

total_centis = round(max(0.0, float(t)) * 100)

float(t) succeeds for the string "Infinity"/"inf" (Python's float() parses those without raising), so it passes the try/except (KeyError, TypeError, ValueError) around the conversion — the crash is one line later: round() can't convert inf to an int, raising an unhandled OverflowError → 500. Pre-existing (the old int(t // 60) had the same crash), not a regression from this PR, but this PR is already touching the exact function.

Left the same note on lyrics-sync#11 — feedpakr's ws_build hit this same "float() parses inf/nan happily" class of bug for manual_offset and fixed it with math.isfinite(); same shape of fix would close it here too.


Generated by Claude Code

Pullfrog review finding on PR #9: test_setup_wires_context_log_into_module_global
only restored routes._log in its finally block, but setup() also mutates
_config_dir, _get_dlc_dir, and SLOPPAK_CACHE_DIR -- left set to junk
values for any test appended after this one (pytest preserves definition
order). Safe today only by accident (this is the last test in the file).
Restores all four now, per the suggested fix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • tests/test_helpers.py — test_setup_wires_context_log_into_module_global now captures and restores all four module globals setup() mutates (_config_dir, _get_dlc_dir, SLOPPAK_CACHE_DIR, _log), so a test appended after it no longer inherits poisoned config state. This addresses the prior review's inline nit.

The rollover fix, context["log"] wiring, and loop modernization were reviewed in the prior pass and remain sound; CI is green on ec22fe8.

Pullfrog  | View workflow run | Using Big Pickle (free) | 𝕏

cchacs and others added 3 commits September 8, 2026 17:08
…g newline

ebf1bfe fixed a real bug (non-finite LRC timestamps raising OverflowError
instead of being rejected/skipped) without a version bump; this repo's own
convention bumps on every user-visible fix. Also restores the trailing
newline routes.py lost in that commit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Added tests/test_lrc_nonfinite.py — parametrized ValueError("...finite") check for _lrc_timestamp over six non-finite spellings, plus exact-output assertions that _format_lrc and _persist_lyrics skip non-finite segments. The tests are genuine red→green: each fails against the pre-ebf1bfe code (OverflowError, or a silent 00:00.00 where a raise was expected).
  • Added math.isfinite guards in routes.py — _lrc_timestamp now raises ValueError on non-finite input, and _format_lrc/_persist_lyrics/_lyrics_tokens skip non-finite entries. This closes a latent crash predating the PR: /export previously raised OverflowError on a non-finite start, and /save-lyrics could round-trip Infinity/NaN into lyrics.json.
  • Bumped plugin.json to 1.4.7 and restored routes.py's trailing newline.

Verified by running the new tests directly against the real routes.py (fastapi stubbed): zero failures. ci/python, ci/js, and all three compliance checks are green on the current head e34e520; the branch tip moved to e34e520 after the triggering event fired at 74367a3, so this review covers the three commits since the prior review.

Pullfrog  | View workflow run | Using Big Pickle (free) | 𝕏

Comment thread routes.py Resolved
@kilo-code-bot

kilo-code-bot Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • plugin.json
Previous Review Summaries (3 snapshots, latest commit 0e4023e)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 0e4023e)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • plugin.json
  • routes.py
  • tests/test_lrc_nonfinite.py

Previous review (commit 2acf545)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
routes.py 585 Huge finite timestamps still make /export fail

Fix these issues in Kilo Cloud

Files Reviewed (3 files)
  • plugin.json - 0 issues
  • routes.py - 1 issue
  • tests/test_lrc_nonfinite.py - 0 issues

Previous review (commit e34e520)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
routes.py 580 Finite timestamps can overflow during centisecond conversion

Fix these issues in Kilo Cloud

Files Reviewed (4 files)
  • plugin.json - 0 issues
  • routes.py - 1 issue
  • tests/test_helpers.py - 0 issues
  • tests/test_lrc_nonfinite.py - 0 issues

Reviewed by gpt-5.6-sol-discounted · Input: 24 · Output: 3K · Cached: 226.1K

…Error

Kilo Code Review finding on PR #9: math.isfinite(seconds) accepts values
like 1e307 (a real, finite double), but 1e307 * 100 = 1e309 exceeds the
max representable double and becomes inf -- round(inf) then raised the
same OverflowError the finiteness check was added to prevent. Check the
scaled (centisecond) value for finiteness too, before rounding it.

Bumped plugin.json to 1.4.8.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy
@get-flashbacks get-flashbacks deleted a comment from coderabbitai Bot Sep 9, 2026
Comment thread routes.py
# which round() below would turn into the same unhelpful
# OverflowError this function exists to guard against.
scaled = max(0.0, seconds) * 100
if not math.isfinite(scaled):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[WARNING]: Huge finite timestamps still make /export fail

For a segment starting at 1e307, _format_lrc() passes its math.isfinite(t) check and reaches this new branch. Raising ValueError here still propagates out of _format_lrc() and lk_export(), so the endpoint continues to return a 500; only the exception type changed from OverflowError. Skip scaled-overflow values in _format_lrc() (or catch this error around _lrc_timestamp()), and cover the formatter or endpoint rather than only asserting the helper raises.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 0e4023e — _format_lrc now catches the ValueError from _lrc_timestamp(t) and skips the segment, and a new test exercises _format_lrc directly with start=1e307 to confirm it's skipped rather than raising.


Generated by Claude Code

@pullfrog pullfrog 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.

Important

The new _lrc_timestamp guard converts the finite-but-huge OverflowError into a ValueError, but the /export route path through _format_lrc still 500s on such a timestamp — leaving the very crash this commit set out to eliminate reachable.

Reviewed changes

  • _lrc_timestamp now scales to centiseconds before rounding and re-checks math.isfinite(scaled), so a finite-but-huge input like 1e307 (whose *100 overflows to inf) raises a clean ValueError instead of OverflowError.
  • Added test_lrc_timestamp_rejects_a_finite_value_that_overflows_when_scaled — a genuine red→green case (verified 1e307 is finite, 1e307*100 == inf).
  • Bumped plugin.json to 1.4.8.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using Big Pickle (free) | 𝕏

Comment thread routes.py Outdated
Comment on lines +602 to +604
if not math.isfinite(t):
continue
lines.append(f"[{_lrc_timestamp(t)}]{seg.get('text', '')}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_format_lrc's guard only skips non-finite values (math.isfinite(t)), but _lrc_timestamp now raises for finite-but-huge values that overflow once scaled (e.g. start = 1e307). That ValueError is uncaught here, so it propagates to lk_export at routes.py:935 and 500s /export. I reproduced this: _format_lrc([{"start": 1e307}]) raises ValueError: LRC timestamp must be finite. The new helper-level guard converts the prior OverflowError into a ValueError, but the route path this PR set out to harden is still crashable. The new test only covers _lrc_timestamp directly, not the _format_lrc//export path.

Technical details
# /export still crashes on finite-but-huge start

## Affected sites
- routes.py:602-604 — `_format_lrc` only checks `math.isfinite(t)`, then calls `_lrc_timestamp(t)` unconditionally; a finite-but-huge `t` (e.g. `1e307`) raises `ValueError` which is not caught here.
- routes.py:935 — `lk_export` calls `_format_lrc(segments)` with no try/except, so the `ValueError` becomes a 500.

## Required outcome
- `/export` must not 500 on a finite-but-huge `start`; it should skip such segments the way it skips non-finite ones (routes.py:602), or otherwise handle the raise.

## Suggested approach
- In `_format_lrc`, extend the guard to also skip values whose centisecond scaling is non-finite, e.g. `if not math.isfinite(t) or not math.isfinite(t * 100): continue` (mirroring the new check inside `_lrc_timestamp`).
- Add a test exercising `_format_lrc` (not just `_lrc_timestamp`) with a huge-but-finite segment, asserting it is skipped rather than raising.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 0e4023e — _format_lrc now wraps the _lrc_timestamp(t) call in try/except and skips the segment on ValueError, matching the same wrapping already applied to the lyrics_sync plugin's copy of this code. Added a test exercising _format_lrc directly (not just _lrc_timestamp), per your suggestion — verified it fails against the pre-fix code.


Generated by Claude Code

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0e4023e — _format_lrc now catches ValueError from _lrc_timestamp and skips the segment.

Pullfrog  | View workflow run | via Pullfrog | Using Big Pickle (free) | 𝕏

Kilo and Pullfrog both caught this on the previous commit: _lrc_timestamp
now raises ValueError for a scaled-overflow value like 1e307, but
_format_lrc's guard only checked math.isfinite(t) (true for 1e307) before
calling _lrc_timestamp(t) unconditionally -- so the ValueError propagated
straight through to lk_export, still 500ing /export, just with a
different exception type than before this whole fix chain started.

_format_lrc now catches that ValueError and skips the segment, matching
the same wrapping already applied in the lyrics_sync plugin's copy of
this code. Added a test exercising _format_lrc directly (not just
_lrc_timestamp), per Pullfrog's review -- confirmed it fails against the
prior commit's code.

Bumped plugin.json to 1.4.9.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • _format_lrc now catches the ValueError that _lrc_timestamp raises for finite-but-huge timestamps (e.g. start=1e307, whose *100 overflows to inf) and skips that segment instead of letting it propagate to lk_export and 500 /export — closing the gap the previous review flagged.
  • Added test_format_lrc_skips_a_finite_value_that_overflows_when_scaled exercising the _format_lrc path directly (not just _lrc_timestamp), asserting the huge segment is dropped and the valid line survives.
  • Bumped plugin.json to 1.4.9.

The fix and its test are correct and consistent with the sibling lyrics_sync hardening; the try/except approach is equally sound to the suggested isfinite(t*100) guard. No new issues.

Pullfrog  | View workflow run | Using Big Pickle (free) | 𝕏

@get-flashbacks get-flashbacks deleted a comment from coderabbitai Bot Sep 9, 2026
The overflow-guard fix went through three review-driven follow-up
commits (e34e520, 2acf545, 0e4023e), each bumping plugin.json as if it
were its own release. It's one logical fix landing as one PR, so it
should read as one version bump — 1.4.5 to 1.4.6, not 1.4.9.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy
@cchacs
cchacs merged commit 56e7fce into main Sep 9, 2026
8 checks passed
@cchacs
cchacs deleted the claude/bug-search-mfyoq0 branch September 9, 2026 04:17
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