Repository navigation
fix: log via context["log"] not print(), fix LRC timestamp rollover - #9
Conversation
…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
There was a problem hiding this comment.
ℹ️ Minor suggestions only — the fixes themselves are correct and well-tested; one test-hygiene nit inline.
Reviewed changes
_lrc_timestamp()rollover fix —_format_lrcnow rounds to whole centiseconds before splitting into minutes/seconds, so59.996formats as01:00.00instead of the invalid01:60.00. Verified by hand: output is byte-identical for non-rollover inputs (the existingtest_format_lrc_basic_timestampsstill pins[01:05.50]).print()→context["log"]— both/pitch-fallback prints in_workernow go through a module-level_logwired fromcontext["log"]insetup()(falling back to a namespaced stdlib logger so noNone-check is needed). Grep confirms no otherprint()remains inroutes.py, and_logis always captured aftersetup()has run.asyncio.get_event_loop()→get_running_loop()— genuine no-behavior-change modernization; the call site lives insideasync def lk_generate_pitch(routes.py:794), where both calls return the running loop.- Version bump
1.4.5→1.4.6plus three new tests with exact-equality assertions.ci/pythonand all three compliance checks are green on729b78a.
Big Pickle (free) | 𝕏
|
Reviewed this PR (not driving it, just leaving findings). Same total_centis = round(max(0.0, float(t)) * 100)
Left the same note on lyrics-sync#11 — 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
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
tests/test_helpers.py—test_setup_wires_context_log_into_module_globalnow captures and restores all four module globalssetup()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.
Big Pickle (free) | 𝕏
…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
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Added
tests/test_lrc_nonfinite.py— parametrizedValueError("...finite")check for_lrc_timestampover six non-finite spellings, plus exact-output assertions that_format_lrcand_persist_lyricsskip non-finite segments. The tests are genuine red→green: each fails against the pre-ebf1bfecode (OverflowError, or a silent00:00.00where a raise was expected). - Added
math.isfiniteguards inroutes.py—_lrc_timestampnow raisesValueErroron non-finite input, and_format_lrc/_persist_lyrics/_lyrics_tokensskip non-finite entries. This closes a latent crash predating the PR:/exportpreviously raisedOverflowErroron a non-finitestart, and/save-lyricscould round-tripInfinity/NaNintolyrics.json. - Bumped
plugin.jsonto1.4.7and restoredroutes.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.
Big Pickle (free) | 𝕏
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
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)
Previous review (commit 2acf545)Status: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Fix these issues in Kilo Cloud Files Reviewed (3 files)
Previous review (commit e34e520)Status: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Fix these issues in Kilo Cloud Files Reviewed (4 files)
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
| # 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): |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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_timestampnow scales to centiseconds before rounding and re-checksmath.isfinite(scaled), so a finite-but-huge input like1e307(whose*100overflows toinf) raises a cleanValueErrorinstead ofOverflowError.- Added
test_lrc_timestamp_rejects_a_finite_value_that_overflows_when_scaled— a genuine red→green case (verified1e307is finite,1e307*100 == inf). - Bumped
plugin.jsonto1.4.8.
Big Pickle (free) | 𝕏
| if not math.isfinite(t): | ||
| continue | ||
| lines.append(f"[{_lrc_timestamp(t)}]{seg.get('text', '')}") |
There was a problem hiding this comment.
_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.There was a problem hiding this comment.
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
There was a problem hiding this comment.
Addressed in 0e4023e — _format_lrc now catches ValueError from _lrc_timestamp and skips the segment.
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
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
_format_lrcnow catches theValueErrorthat_lrc_timestampraises for finite-but-huge timestamps (e.g.start=1e307, whose*100overflows toinf) and skips that segment instead of letting it propagate tolk_exportand 500/export— closing the gap the previous review flagged.- Added
test_format_lrc_skips_a_finite_value_that_overflows_when_scaledexercising the_format_lrcpath directly (not just_lrc_timestamp), asserting the huge segment is dropped and the valid line survives. - Bumped
plugin.jsonto1.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.
Big Pickle (free) | 𝕏
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

Summary
lk_generate_pitch's/pitchfallback logging used bareprint()instead ofcontext["log"], violating the plugin contract (bypasses correlation IDs and log rotation) and core'sprint()-guard CI check. Added a module-level_logwired fromcontext["log"]insetup(), defaulting to a plain stdlib logger of the same name so nothing needs aNone-check._format_lrccomputed minutes/seconds independently (int(t // 60),f"{t % 60:05.2f}"), so a seconds remainder that rounds up to60.00under: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 thelyrics_syncplugin's copy of this same bug — see fix: LRC timestamp rollover, malformed-segment 500s, non-ASCII export crash feedBack-plugin-lyrics-sync#11).asyncio.get_event_loop()forasyncio.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 futureprint()creeping back in, andsetup()wiringcontext["log"]into the module global)🤖 Generated with Claude Code
https://claude.ai/code/session_01HVxQShyx8Mrqe1GKNstjHy
Generated by Claude Code