Skip to content

[Backend] scoreDecayService reads/writes a non-existent borrowers table, so inactivity decay always throws #1095

Description

@grantfox-oss

Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0

Why this matters

backend/src/services/scoreDecayService.ts:14 selects FROM borrowers b (columns b.id, b.score) and line 40 runs UPDATE borrowers SET score = $1 WHERE id = $2. No migration creates a borrowers table - grep of backend/migrations only ever CREATEs scores, loan_events, indexer_state and loan_disputes; the 1789000000000_ensure-core-tables migration shows the canonical credit-score table is scores(borrower, score), not borrowers(id, score). cron/scoreDecayJob.ts:16-19 calls getInactiveBorrowers()/applyScoreDecay() (the file's own header says it is meant to be scheduled periodically), so when wired it fails with relation borrowers does not exist, the job records a failure and decays nothing - and even if the table existed it targets a different table/columns than the canonical scores used by scoreController, so decay would never affect the score the rest of the app reads.

Acceptance criteria

  • scoreDecayService queries and updates the canonical scores table using its real columns (borrower/score) instead of a non-existent borrowers table
  • getInactiveBorrowers and applyScoreDecay run without throwing against the migrated schema
  • Decay applied by the job is reflected in the score returned by the scoring endpoints
  • Unit test exercises the query/update against the actual scores schema

Files to touch

  • backend/src/services/scoreDecayService.ts
  • backend/src/cron/scoreDecayJob.ts

Out of scope

  • The separately filed scores user_id/current_score column-rename mismatch
  • Adding new score-decay configuration or scheduling wiring
  • Changing the decay rate/min-score policy

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendIssues related to backend developmentbugSomething isn't workingdatabaseDatabase related issues

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions