fix: extinction countdown ticks down by 2 seconds instead of 1#107
Conversation
Agent-Logs-Url: https://github.com/nitrocode/token-deathclock/sessions/7fd5f569-36ed-4fc9-83e4-c1ea9f0bd26a Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
Agent-Logs-Url: https://github.com/nitrocode/token-deathclock/sessions/7fd5f569-36ed-4fc9-83e4-c1ea9f0bd26a Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
📝 WalkthroughWalkthroughAdds a pure helper Changes
Sequence Diagram(s)Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
I pity the fool who skips the review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #107 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 247 256 +9
Branches 110 112 +2
=========================================
+ Hits 247 256 +9
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/LEARNINGS.md`:
- Line 105: Update the incorrect PR reference string: replace occurrences of
“#104” in the new learning row and the PR log heading in LEARNINGS.md with the
correct tracked PR number “#107” so the documentation matches the actual change
set; search for the literal “#104” near the A5 learning row (the line containing
the extinction formula tExtinction = ln(1+(target-BASE_TOKENS)*k/R0)/k) and
update those instances to “#107”.
In `@tests/death-clock.test.js`:
- Around line 907-912: The test name claims it supplies a non-numeric nowMs but
the call to computeExtinctionSecsRemaining(TARGET) omits nowMs, so the
non-numeric branch isn't exercised; update the test so it actually passes a
non-numeric nowMs (for example null or 'abc') to
computeExtinctionSecsRemaining(TARGET, nowMs) and assert the result is a finite
number, or alternatively change the test name to reflect that nowMs was omitted
— reference computeExtinctionSecsRemaining and the test block in
death-clock.test.js to locate the code to edit.
🪄 Autofix (Beta)
✅ Autofix completed
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 45e75a97-43da-4362-90a7-a1d598f93dbe
📒 Files selected for processing (5)
death-clock-core.jsdocs/LEARNINGS.mdsrc/js/00-state.jssrc/js/02-counter.jstests/death-clock.test.js
|
@coderabbitai apply |
|
🧠 Learnings used✅ Actions performedReview triggered.
|
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 2 file(s) based on 2 unresolved review comments. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 2 file(s) based on 2 unresolved review comments. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/death-clock.test.js (1)
895-898: Tighten the test name to match the assertion, fool-proof style.At Line 895, the title says “returns 0 or negative,” but Line 896-897 assert exactly
0for both cases. Rename for precision.Suggested rename
- test('returns 0 or negative when target equals or is below BASE_TOKENS', () => { + test('returns 0 when target equals or is below BASE_TOKENS', () => {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/death-clock.test.js` around lines 895 - 898, The test description is inaccurate: it says "returns 0 or negative" but the assertions check for exactly 0; update the test title string in the test block that calls computeExtinctionSecsRemaining(BASE_TOKENS, baseMs) and computeExtinctionSecsRemaining(BASE_TOKENS - 1, baseMs) to accurately reflect the expectation (e.g., "returns 0 when target equals or is below BASE_TOKENS") so the test name matches the assertions and references BASE_TOKENS and computeExtinctionSecsRemaining.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/death-clock.test.js`:
- Around line 895-898: The test description is inaccurate: it says "returns 0 or
negative" but the assertions check for exactly 0; update the test title string
in the test block that calls computeExtinctionSecsRemaining(BASE_TOKENS, baseMs)
and computeExtinctionSecsRemaining(BASE_TOKENS - 1, baseMs) to accurately
reflect the expectation (e.g., "returns 0 when target equals or is below
BASE_TOKENS") so the test name matches the assertions and references BASE_TOKENS
and computeExtinctionSecsRemaining.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: fe955733-0c90-45d0-9d04-4273df46bdc0
📒 Files selected for processing (2)
docs/LEARNINGS.mdtests/death-clock.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/LEARNINGS.md


The extinction countdown header decremented by ~2 seconds per tick instead of 1. The bug was a model inconsistency:
updateExtinctionCountdowncomputedsecsRemaining = tokensRemaining / currentRate(linear, constant-rate assumption), whilegetCurrentTokensintegrates an exponentially-growing rate (~30%/yr). At ~3.7 years from extinction, this causes the countdown to tick at1 + secsRemaining × k ≈ 2.17 s/s.Fix: Replace the linear approximation with the closed-form inverse of the cumulative-token integral:
tExtinctionis a constant;tNowadvances 1 s/s → countdown decreases by exactly 1.000000 s/s.Changes
computeExtinctionSecsRemaining(targetTokens, nowMs)pure function todeath-clock-core.jsusing the integral inverse formulacomputeExtinctionSecsRemainingfromdeath-clock-core.jsand import it insrc/js/00-state.jstokensRemaining / currentRateinupdateExtinctionCountdown(src/js/02-counter.js) with the new functiontests/death-clock.test.js, including the key 1-second-per-tick invariant that would fail against the old linear approximationdocs/LEARNINGS.mdAgent Checklist
npm run test:cipasses (all unit tests green, coverage not decreased)npm run build && npm run test:e2epasses (all E2E tests green)script.js,styles.css,*-data.js)innerHTMLvalues pass throughescHtml()death-clock-core.jsuses:pins use a full commit SHA + inline semver commentfeat:,fix:,docs:,chore:, etc.)project-stats.yamlupdated if this session merges one or more PRsdocs/LEARNINGS.md(new pattern or lesson learned)Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests