A freshly enrolled device reports trust_weight = 1.00, then becomes 0.50 the first time cmd/recompute runs. Nothing is broken, but it looks broken, and it cost real time to explain during the first device session.
Cause: the schema column default and the formula disagree.
internal/db/migrations/0001_init.up.sql defaults trust_weight to 1.00
internal/trust.Compute returns TrustBase = 0.5 for a device with no reports and no tenure — tenure contributes ageDays/30 * 0.5, volume reportCount * 0.05, both zero at enrolment
So every device starts optimistic and is corrected downward within fifteen minutes. Anyone watching the table sees an unexplained halving.
What to do
Pick one and make it deliberate:
- Align the default to
0.50 so the stored value matches what the formula would compute. Simplest, and makes the two sources of truth agree.
- Compute the weight at insert rather than relying on a column default, so there is only one source of truth.
- Keep
1.00 deliberately as a grace period for new devices, and document it as intentional in both the migration and internal/trust.
Option 3 is defensible — being briefly generous to a new device is a reasonable product choice — but right now it is not a choice, it is an accident.
Note that changing the default needs a new migration (0006_*); do not edit 0001, which has already been applied in production.
Where to look
internal/trust/trust.go — Compute, TrustBase
internal/db/migrations/0001_init.up.sql — the devices table
internal/store — where devices are inserted
A freshly enrolled device reports
trust_weight = 1.00, then becomes0.50the first timecmd/recomputeruns. Nothing is broken, but it looks broken, and it cost real time to explain during the first device session.Cause: the schema column default and the formula disagree.
internal/db/migrations/0001_init.up.sqldefaultstrust_weightto1.00internal/trust.ComputereturnsTrustBase = 0.5for a device with no reports and no tenure — tenure contributesageDays/30 * 0.5, volumereportCount * 0.05, both zero at enrolmentSo every device starts optimistic and is corrected downward within fifteen minutes. Anyone watching the table sees an unexplained halving.
What to do
Pick one and make it deliberate:
0.50so the stored value matches what the formula would compute. Simplest, and makes the two sources of truth agree.1.00deliberately as a grace period for new devices, and document it as intentional in both the migration andinternal/trust.Option 3 is defensible — being briefly generous to a new device is a reasonable product choice — but right now it is not a choice, it is an accident.
Note that changing the default needs a new migration (
0006_*); do not edit0001, which has already been applied in production.Where to look
internal/trust/trust.go—Compute,TrustBaseinternal/db/migrations/0001_init.up.sql— thedevicestableinternal/store— where devices are inserted