Skip to content

fix: Score only confirmed predictions at market resolution and make claims select the confirmed row - #991

Merged
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
innocentharuna:solver/issue-984-46-a0
Oct 19, 2026
Merged

greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
innocentharuna:solver/issue-984-46-a0

Conversation

@innocentharuna

Copy link
Copy Markdown
Contributor

Summary

Resolution now scores only confirmed predictions, late confirmations are scored, and claims pick the confirmed row deterministically. I couldn't run anything here, so none of it has been run, including the unit and integration tests, lint, tsc and the openapi check. The EXPLAIN output and the repair script's dry-run output the issue asks for are not included.

  • Resolution: atomicResolve in src/services/marketResolutionService.ts now updates only rows with status = 'confirmed' and result IS NULL. The FOR UPDATE transaction is unchanged. Pending and failed rows keep result = NULL, and replays never flip an existing won/lost.
  • Late confirmation: the confirm UPDATE in src/workers/predictionsConfirmer.ts now sets result in the same statement. It takes the value from markets.winning_outcome when the market is already resolved and keeps any existing result.
  • Claims: claimWinnings in src/services/claimService.ts selects only status = 'confirmed' rows, ordered by id, and fetches up to two. Two confirmed rows return 409 ambiguous_prediction and log both ids. If only unconfirmed rows exist, it returns 400 prediction_not_winning before any RPC. If the user has no rows at all, it still returns 404.
  • OpenAPI: the 409 response is added to the claim operation in src/openapi/registry.ts. I also edited openapi.yaml by hand to match, since I couldn't regenerate it. If npm run openapi:check fails, run npm run openapi:generate (check the script name in package.json) and commit the output.
  • Repair script: scripts/repair-unconfirmed-results.ts runs dry by default and writes only with --apply. It resets result on unclaimed, non-confirmed rows in resolved markets. Rows with a claim_tx_hash are listed, not changed. It also lists users with more than one confirmed row in a market.
  • Docs: a "When is a prediction claimable" section is added to docs/predictions-api.md.

Changed files

  • docs/predictions-api.md
  • openapi.yaml
  • src/openapi/registry.ts
  • src/services/claimService.ts
  • src/services/marketResolutionService.ts
  • src/workers/predictionsConfirmer.ts
  • tests/marketResolver.test.ts
  • tests/predictionsConfirmer.test.ts
  • scripts/repair-unconfirmed-results.ts
  • tests/integration/resolutionScoring.test.ts

Test plan

CI should run npm test -- tests/marketResolver.test.ts tests/predictionsConfirmer.test.ts and npm run test:integration -- resolutionScoring against a migrated DB. Then run npm run lint, npx tsc -p tsconfig.json --noEmit, npm test with coverage, and npm run openapi:check.

  • tests/marketResolver.test.ts: covers a market with confirmed, pending and failed rows (only the confirmed one is scored), and a replayed resolution that changes nothing. It uses an in-memory repo, so it doesn't exercise the SQL filter.
  • tests/predictionsConfirmer.test.ts: one test checks that the confirm update's generated SQL scores late confirmations from winning_outcome without overwriting.
  • tests/integration/resolutionScoring.test.ts: covers plan rows 1–8 against the real DB, including the failed-row claim (400, no RPC), the confirmed row chosen over a failed duplicate, the 409 for two confirmed rows, late confirmation, and the repair script's dry run and --apply. The two regression cases (rows 1 and 2) should fail on main and pass now.

Still to do for the PR: the EXPLAIN output on a 10,000-prediction market, the coverage summary, and the repair script's dry-run output against a seeded DB.

This PR was created as a draft by the issue solver bot. It will remain a
draft until repository CI passes.

Closes #984

@drips-wave

drips-wave Bot commented Oct 18, 2026

Copy link
Copy Markdown

@innocentharuna Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@innocentharuna
innocentharuna marked this pull request as ready for review October 18, 2026 23:01
@greatest0fallt1me
greatest0fallt1me merged commit 4a0d52c into Predictify-org:main Oct 19, 2026
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.

Score only confirmed predictions at market resolution and make claims select the confirmed row

3 participants