Skip to content

fix(engine): stop scoring issues with unknown timestamps as maximally fresh - #2857

Closed
JSONbored wants to merge 1 commit into
mainfrom
fix/opportunity-freshness-clock-drift
Closed

fix(engine): stop scoring issues with unknown timestamps as maximally fresh#2857
JSONbored wants to merge 1 commit into
mainfrom
fix/opportunity-freshness-clock-drift

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

  • Root-caused the reported "date-drift flakiness" in test/unit/opportunity-branch-internals.test.ts, opportunity-freshness.test.ts, and opportunity-metadata-signals.test.ts: it is not a clock/date issue. issueAgeDays (packages/gittensory-engine/src/opportunity-freshness.ts) returns 0 — the freshest possible age — whenever an open issue's updatedAt/createdAt are both missing or unparseable, deterministically, regardless of what "now" is. An issue with no usable timestamp at all was being scored as "just updated" (freshness 1) instead of falling to the 0.05 floor a genuinely stale issue gets.
  • This is a real behavioral bug, not a stale test fixture: the same PR that introduced this file's current issueAgeDays (feat(engine): add opportunity freshness scorer #2780) has a commit explicitly titled "fall back to createdAt when updatedAt is unparseable ... so malformed updatedAt cannot score a stale issue as fresh" — the intent was already to prevent exactly this outcome, but the remaining "no valid timestamp survived either fallback" case was left returning 0. Fixed by flooring that case to a large sentinel (9999), which the existing exponential decay clamps to the same 0.05 floor a stale issue reaches — matching every failing assertion across all three test files.
  • While verifying this fix's own gate (npm run typecheck / npm run build:miner), found and fixed two separate, unrelated, currently-broken-on-main build issues blocking any PR from passing test:ci right now:
    • packages/gittensory-engine/src/index.ts: a merge collision between two concurrent PRs (feat(miner-discovery): goal model — translate MinerGoalSpec into ranker weights #2787 and an earlier contributor-fit export) dropped the export { opener before the contributor-fit.js re-export block, leaving four bare identifiers with no enclosing statement — a hard tsc parse error for the whole barrel file (Expected a semicolon / Expression expected).
    • packages/gittensory-engine/src/governor-ledger.ts: imports node:util's isDeepStrictEqual, which doesn't type-check under this package's "types": [] tsconfig (no ambient Node types) and pulls a Node-only builtin into a package explicitly shared with the Worker backend. Replaced with a small self-contained structural-equality check scoped to its one call site (a JSON round-trip fidelity check, so it only ever needs to compare plain objects/arrays/primitives) — keeps the package portable, matches the file's stated "shared by the Worker backend and the Node-only miner CLI" design.

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused — one root cause plus two build-blocking prerequisites discovered while verifying this fix's own gate (not opportunistic unrelated cleanup).
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • Small enough that the summary explains why an issue is not needed — a targeted bug fix with an obvious repro (4 pre-existing failing assertions).

Validation

  • git diff --check
  • npm run actionlint (unaffected — no workflow files touched)
  • npm run typecheck — also confirms the index.ts barrel-file fix (this was failing on unmodified origin/main before this PR)
  • npm run db:migrations:check (no schema change)
  • npm run build:miner — confirms the governor-ledger.ts fix (also failing on unmodified origin/main before this PR)
  • npm run test:coverage locally (full, unsharded) — 403 files / 7876 tests, 0 failures (previously 4 failures across 3 files before this fix)
  • npm run test:workers (unaffected — no Worker-pool test files touched)
  • npm run build:mcp / npm run test:mcp-pack (unaffected — no MCP package changes)
  • npm run ui:openapi:check (unaffected — no API/schema changes)
  • npm run ui:lint / npm run ui:typecheck / npm run ui:build (unaffected — no apps/gittensory-ui changes)
  • npm audit --audit-level=moderate — 0 vulnerabilities
  • Existing tests already fully exercise both changes: the three previously-failing files pin the issueAgeDays fix exactly (.toBe(9999) / .toBe(0.05)), and test/unit/governor-ledger.test.ts's { value: undefined } round-trip case pins the deepStrictEqual replacement's core behavior. No new test files needed.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • No auth/CORS/session paths touched — pure logic fix in a deterministic, side-effect-free package.
  • No UI changes.
  • No changelog edit.

… fresh

issueAgeDays returned 0 (the freshest possible age) whenever an open
issue's updatedAt and createdAt were both missing or unparseable, so a
garbage/missing-timestamp issue outranked genuinely fresh ones instead
of falling to the freshness floor. Floor unknown-age issues to a large
sentinel so they clamp to the same 0.05 floor a genuinely stale issue
gets, matching this PR's own commit history intent ("malformed
updatedAt cannot score a stale issue as fresh") and every existing
opportunity-freshness/opportunity-metadata-signals/opportunity-branch-
internals test assertion.

Also fixes two unrelated build breaks on main discovered while
verifying this fix's gate:
- packages/gittensory-engine/src/index.ts: a merge collision dropped
  the `export {` opener before the contributor-fit re-export block,
  breaking `tsc` for the whole barrel file.
- packages/gittensory-engine/src/governor-ledger.ts: importing
  node:util's isDeepStrictEqual doesn't type-check under this
  package's ambient-types-off tsconfig, and depends on a Node builtin
  in a package shared with the Worker backend. Replaced with a small
  self-contained structural-equality check scoped to its one call
  site (JSON round-trip fidelity), keeping the package portable.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
gittensory-ui 38f355c Commit Preview URL

Branch Preview URL
Jul 03 2026, 11:35 PM

@JSONbored JSONbored self-assigned this Jul 3, 2026
@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 4, 2026
@loopover-orb

loopover-orb Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-04 00:13:28 UTC

3 files · 1 AI reviewer · 1 blocker · readiness 100/100 · CI green · dirty

⏸️ Suggested Action - Manual Review

  • Maintainer test expectations unmet — Add or update tests, or attach passing validation output that satisfies the maintainer's test expectations.

Review summary
The freshness fix moves the unknown-timestamp case from age 0 to a very stale sentinel, so open issues with no usable timestamp no longer receive the maximum freshness factor. The barrel export repair is straightforward, and replacing node:util with a scoped structural comparison keeps governor-ledger portable without changing the validated plain-JSON payload contract. I do not see a reachable correctness defect in the provided post-change files, but the source changes have no accompanying test-path evidence despite changing scoring behavior and validation internals.

Nits — 6 non-blocking
  • nit: packages/gittensory-engine/src/opportunity-freshness.ts:27 changes a user-visible scoring edge case without a direct regression test for an open issue whose updatedAt and createdAt are both missing or invalid.
  • nit: packages/gittensory-engine/src/governor-ledger.ts:33 adds a custom deep equality helper without direct test coverage for the edge cases it is intended to reject, such as payload values that JSON.stringify drops or normalizes.
  • Add a regression test that drives computeOpportunityFreshness with an open issue lacking both usable timestamps and asserts the floor value.
  • Add serialize/normalizeGovernorLedgerEvent coverage for non-round-trippable payload fields so the custom deepStrictEqual replacement is pinned to the intended contract.
  • Consider keeping UNKNOWN_AGE_DAYS close to the decay math with a short note or named helper so future changes to the decay constant do not accidentally make the sentinel score above the floor.
  • Code changes lack test evidence — Add focused regression tests or explain why existing coverage is sufficient.

Concerns raised — review before merging

  • Maintainer test expectations unmet — Add or update tests, or attach passing validation output that satisfies the maintainer's test expectations.
Signal Result Evidence
Code review ❌ 1 blocker 1 reviewer
Linked issue ✅ No-issue rationale PR body explains why no issue is linked.
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 (no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 60 registered-repo PR(s), 51 merged, 448 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 60 PR(s), 448 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: Python, TypeScript, JavaScript, Ruby, Go, Kotlin, MDX, Shell
  • Official Gittensor activity: 60 PR(s), 448 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • No action.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
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.

🟩 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 Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@JSONbored JSONbored closed this Jul 4, 2026
@JSONbored
JSONbored deleted the fix/opportunity-freshness-clock-drift branch July 4, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant