Skip to content

fix(miner): sweep a claim with an unparseable claimedAt instead of retaining it forever - #7746

Merged
JSONbored merged 1 commit into
JSONbored:mainfrom
shin-core:fix/sweep-unparseable-claimedat-7732
Jul 21, 2026
Merged

fix(miner): sweep a claim with an unparseable claimedAt instead of retaining it forever#7746
JSONbored merged 1 commit into
JSONbored:mainfrom
shin-core:fix/sweep-unparseable-claimedat-7732

Conversation

@shin-core

Copy link
Copy Markdown
Contributor

What

claimAgeMs (packages/loopover-miner/lib/claim-ledger-expiry.ts) returns null when claim.claimedAt can't be parsed (Date.parseNaN), and findExpiredClaims skipped any claim with a null age:

if (ageMs === null) continue;
if (ageMs > maxAgeMs) expired.push(claim);

So a corrupted or hand-edited claim-ledger row was never swept — it stayed permanently un-expirable. claimedAt is always written via new Date().toISOString() in claim-ledger.ts, so this is only reachable through a corrupted row, but when it happens the row is stuck active forever, contradicting this module's own fail-closed posture.

Fix

Treat a null (unparseable) age as expired — fail closed — so the row is swept rather than retained:

if (ageMs === null || ageMs > maxAgeMs) expired.push(claim);

claimAgeMs's signature and its behavior for valid timestamps are unchanged; only how findExpiredClaims handles the null-age case.

Test

test/unit/miner-claim-ledger-expiry.test.ts's existing dangling-age test (previously asserting the bogus claim was skipped) is updated to assert the corrected fail-closed behavior: an unparseable-claimedAt claim is now swept alongside a genuinely stale one, while a fresh claim stays within the window. Proven to fail against the pre-fix skip.

Validation

  • npx vitest run test/unit/miner-claim-ledger-expiry.test.ts — 11/11.
  • npm run typecheck — exit 0. npm run build:miner:check (committed .js/.d.ts matches .ts), npm run test:miner-pack — pass. git diff --check clean.

Closes #7732

…taining it forever

claimAgeMs returns null when claim.claimedAt can't be parsed (Date.parse -> NaN),
and findExpiredClaims skipped any claim with a null age entirely -- so a
corrupted or hand-edited claim-ledger row was never swept and stayed
permanently un-expirable. claimedAt is always written via
new Date().toISOString() in claim-ledger.ts, so this is only reachable through
a corrupted row, but when it happens the row is stuck active forever, which
contradicts this module's own fail-closed posture.

Treat a null (unparseable) age as expired, so such a row is swept rather than
retained. claimAgeMs's signature and its behavior for valid timestamps are
unchanged -- only how findExpiredClaims handles the null-age case.

Closes JSONbored#7732
@shin-core
shin-core requested a review from JSONbored as a code owner July 21, 2026 12:24
@superagent-security superagent-security Bot added the contributor:flagged Contributor flagged for review by trust analysis. label Jul 21, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

🚨 Contributor flagged. Click here for more info: Superagent Dashboard

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.58%. Comparing base (0709850) to head (e0c6a4c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7746      +/-   ##
==========================================
  Coverage   88.57%   88.58%              
==========================================
  Files         725       84     -641     
  Lines       76410    20685   -55725     
  Branches    22762     3656   -19106     
==========================================
- Hits        67683    18323   -49360     
+ Misses       7681     2184    -5497     
+ Partials     1046      178     -868     
Flag Coverage Δ
shard-1 100.00% <100.00%> (+44.59%) ⬆️
shard-2 71.42% <100.00%> (+18.84%) ⬆️
shard-3 71.42% <100.00%> (+24.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/loopover-miner/lib/claim-ledger-expiry.ts 100.00% <100.00%> (ø)

... and 641 files with indirect coverage changes

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 21, 2026
@loopover-orb

loopover-orb Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Warning

⏸️ LoopOver review result - manual review recommended

Review updated: 2026-07-21 13:55:34 UTC

3 files · 1 AI reviewer · no blockers · CI green · unstable

⏸️ Suggested Action - Manual Review

Review summary
This is a correct, narrowly-scoped fix: findExpiredClaims now treats an unparseable claimedAt (null age) as expired rather than silently skipping it, matching the module's stated fail-closed posture and closing issue #7732. The .js and .ts sources are kept in sync, the accompanying test was updated (not just added) to assert the corrected behavior including a fresh-claim control case, and both the mirrored portfolio-queue-expiry.js module and sweepExpiredClaims' downstream apiBaseUrl-echo logic are correctly left untouched since neither is affected by this change.

Nits — 4 non-blocking
  • The JSDoc comment above findExpiredClaims in both claim-ledger-expiry.ts/js (packages/loopover-miner/lib/claim-ledger-expiry.ts:20) still only documents the maxAgeMs-equality boundary and doesn't mention the new null-age-is-expired behavior — worth a one-line addition for future readers.
  • The sibling portfolio-queue-expiry.js's findStuckItems (packages/loopover-miner/lib/portfolio-queue-expiry.js) still skips null-age items with the old `if (ageMs === null) continue;` pattern — if that module has the same fail-closed intent, it may warrant an identical fix in a follow-up, though it's out of scope for this PR.
  • Consider filing/linking a follow-up issue for portfolio-queue-expiry.js's identical null-age-skip pattern if its fail-closed posture should also apply there.
  • Add a short note to the findExpiredClaims doc comment stating that a null (unparseable) age is now treated as expired, not skipped.
Flagged checks (non-blocking)
  • Contributor trust — Contributor flagged for review

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #7732
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 86 registered-repo PR(s), 46 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor shin-core; Gittensor profile; 86 PR(s), 0 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Linked issue satisfaction

Partially addressed
The fix logic itself (treating a null claimAgeMs as expired in findExpiredClaims, plus a new test asserting the unparseable-claimedAt claim is swept) matches exactly what the issue asks for, but the issue explicitly targets packages/loopover-engine/src/claim-ledger-expiry.ts while the PR modifies packages/loopover-miner/lib/claim-ledger-expiry.ts and a test under test/unit/miner-claim-ledger-expir

Review context
  • Author: shin-core
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: TypeScript, JavaScript, Solidity, Dart, Python, CSS, PHP, Rust
  • Official Gittensor activity: 86 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LoopOver approves — the gate is satisfied and CI is green.

@JSONbored JSONbored left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

.js is no longer necessary once my PR merges - c

@JSONbored
JSONbored merged commit 352c49f into JSONbored:main Jul 21, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:flagged Contributor flagged for review by trust analysis. gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A claim with an unparseable claimedAt is never swept by findExpiredClaims

2 participants