Files
16gagent/reflections/2026-06-05-falsy-coercion.md
2026-06-06 10:40:48 +08:00

1.2 KiB

Reflection: || vs ?? Falsy Coercion Bug

Date: 2026-06-05 | Severity: P1 | Recurrence: 2

Context

Cross-Agent Certification (PR-30) — Fleet score ranking. Using order[status] || 6 for certification ranking.

Root Cause

JavaScript || operator treats 0 as falsy. When order["healthy"] = 0, order["healthy"] || 6 evaluates to 6, pushing healthy agents to bottom of ranking instead of top. The certification result was reversed — healthy fleets got low scores.

Fix

Changed order[status] || 6order[status] ?? 6. Nullish coalescing (??) only triggers on null/undefined, not on 0.

Pattern Class

JS/TS Falsy Coercion Trap|| treats 0, "", false as falsy. Use ?? for numeric/boolean defaults.

Future Trigger

  • Any JS/TS code writing numeric defaults
  • Any ranking/scoring/ordering logic
  • Any code with value || default where value can legitimately be 0

Checklist

  • Grep all || in scoring/ranking/ordering code → replace with ?? if value can be 0
  • For all numeric defaults: ||??
  • Add || vs ?? check to JS/TS Domain Checklist

Recurrence Count

2 — previously hit in Agent Evolution FK index scoring (same pattern: count || 0 skipped real zeros)