Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(likeness): stop an unmeasured capture cohesion from reading as total disagreement

nirholas0f083305a3b3
diff --git a/api/_lib/likeness-store.js b/api/_lib/likeness-store.js
index 7ede9c977..7014403b3 100644
--- a/api/_lib/likeness-store.js
+++ b/api/_lib/likeness-store.js
@@ -173,6 +173,19 @@ function intOrNull(v) {
return Number.isFinite(v) ? Math.round(v) : null;
}
+// Read-side companion to numOrNull, and NOT the same function: `Number(null)`
+// is 0 and `Number.isFinite(0)` is true, so putting a nullable column through
+// numOrNull turns "not measured" into a real reading of zero. That is not a
+// cosmetic difference here. capture_cohesion is null for a single-photo
+// capture because agreement between photos is undefined with one photo, and
+// surfacing that as 0.000 reads as "these photos are of different people",
+// which is the opposite of what the row says.
+function columnNumber(v) {
+ if (v === null || v === undefined) return null;
+ const n = Number(v);
+ return Number.isFinite(n) ? n : null;
+}
+
// Histogram edges in the roadmap's own units. The 4.0 boundary is the gate the
// phase is verified against, so it is a bucket edge rather than something a
// reader has to compute from a chart.
@@ -243,13 +256,13 @@ export async function likenessDistribution({ days = 30, scorerVersion = SCORER_V
atOrAboveGate: agg?.at_or_above_gate ?? 0,
gateRate: scored ? (agg.at_or_above_gate ?? 0) / scored : null,
sameIdentity: agg?.same_identity ?? 0,
- meanScore: numOrNull(Number(agg?.mean_score)),
- medianScore: numOrNull(Number(agg?.median_score)),
- minScore: numOrNull(Number(agg?.min_score)),
- maxScore: numOrNull(Number(agg?.max_score)),
- meanCosine: numOrNull(Number(agg?.mean_cosine)),
- meanTurnFalloff: numOrNull(Number(agg?.mean_turn_falloff)),
- meanScoreMs: numOrNull(Number(agg?.mean_score_ms)),
+ meanScore: columnNumber(agg?.mean_score),
+ medianScore: columnNumber(agg?.median_score),
+ minScore: columnNumber(agg?.min_score),
+ maxScore: columnNumber(agg?.max_score),
+ meanCosine: columnNumber(agg?.mean_cosine),
+ meanTurnFalloff: columnNumber(agg?.mean_turn_falloff),
+ meanScoreMs: columnNumber(agg?.mean_score_ms),
histogram: SCORE_BUCKETS.map((b, i) => ({ ...b, count: counts.get(i + 1) || 0 })),
statuses: statuses.map((s) => ({ status: s.status, count: s.n })),
};
@@ -279,15 +292,15 @@ export async function recentLikenessScores({ limit = 25, scorerVersion = SCORER_
return rows.map((r) => ({
creationId: r.creation_id,
status: r.status,
- likenessScore: numOrNull(Number(r.likeness_score)),
- identityCosine: numOrNull(Number(r.identity_cosine)),
- meanScore: numOrNull(Number(r.mean_score)),
- worstCosine: numOrNull(Number(r.worst_cosine)),
- turnFalloff: numOrNull(Number(r.turn_falloff)),
+ likenessScore: columnNumber(r.likeness_score),
+ identityCosine: columnNumber(r.identity_cosine),
+ meanScore: columnNumber(r.mean_score),
+ worstCosine: columnNumber(r.worst_cosine),
+ turnFalloff: columnNumber(r.turn_falloff),
sameIdentity: r.same_identity,
capturesTotal: r.captures_total,
capturesEmbedded: r.captures_embedded,
- captureCohesion: numOrNull(Number(r.capture_cohesion)),
+ captureCohesion: columnNumber(r.capture_cohesion),
viewsScored: r.views_scored,
scoreMs: r.score_ms,
scoredAt: r.scored_at,
diff --git a/tests/likeness-score.test.js b/tests/likeness-score.test.js
index 3da710817..1d8e232ad 100644
--- a/tests/likeness-score.test.js
+++ b/tests/likeness-score.test.js
@@ -38,6 +38,15 @@ vi.mock('../api/_lib/face-embed.js', async () => {
return { ...actual, embedFace: (...a) => embedFace(...a) };
});
+// The store's read path is exercised against a stand-in `sql` tag so the
+// null-vs-zero contract below is testable without a database.
+const sqlRows = vi.fn();
+vi.mock('../api/_lib/db.js', () => ({
+ sql: (...a) => sqlRows(...a),
+ isDbUnavailableError: () => false,
+}));
+vi.mock('../api/_lib/env.js', () => ({ databaseConfigured: () => true }));
+
const {
LIKENESS_VIEWS,
SFACE_SAME_IDENTITY_COSINE,
@@ -45,7 +54,7 @@ const {
cosineToScore5,
scoreLikeness,
} = await import('../api/_lib/likeness-score.js');
-const { capturesFromParams } = await import('../api/_lib/likeness-store.js');
+const { capturesFromParams, recentLikenessScores } = await import('../api/_lib/likeness-store.js');
// A unit vector at a chosen angle from the reference, so a test can request an
// exact cosine instead of hoping a random pair lands near one.
@@ -262,3 +271,64 @@ describe('capturesFromParams', () => {
expect(capturesFromParams({ images: [null, 42, ''] })).toEqual([]);
});
});
+
+describe('recentLikenessScores column mapping', () => {
+ it('keeps "not measured" null instead of reporting it as zero', async () => {
+ // A single-capture reconstruction stores capture_cohesion as NULL, because
+ // agreement between photos is undefined with one photo. Number(null) is 0
+ // and Number.isFinite(0) is true, so a naive conversion turns that into a
+ // cohesion of 0.000, which reads as "these photos are of different people":
+ // the opposite of what the row says.
+ sqlRows.mockResolvedValueOnce([
+ {
+ creation_id: 'c-1',
+ status: 'ok',
+ likeness_score: '4.12',
+ identity_cosine: '0.7011',
+ mean_score: null,
+ worst_cosine: null,
+ turn_falloff: null,
+ same_identity: true,
+ captures_total: 1,
+ captures_embedded: 1,
+ capture_cohesion: null,
+ views_scored: 3,
+ score_ms: 61000,
+ scored_at: '2026-08-14T01:00:00.000Z',
+ },
+ ]);
+
+ const [row] = await recentLikenessScores({ limit: 1 });
+ expect(row.captureCohesion).toBeNull();
+ expect(row.meanScore).toBeNull();
+ expect(row.turnFalloff).toBeNull();
+ // Real numeric columns still come back as numbers, not strings.
+ expect(row.likenessScore).toBe(4.12);
+ expect(row.identityCosine).toBeCloseTo(0.7011, 6);
+ });
+
+ it('preserves a genuine zero, which is a different fact from null', async () => {
+ sqlRows.mockResolvedValueOnce([
+ {
+ creation_id: 'c-2',
+ status: 'ok',
+ likeness_score: '2.0',
+ identity_cosine: '0.2',
+ mean_score: '2.0',
+ worst_cosine: '0.2',
+ turn_falloff: 0,
+ same_identity: false,
+ captures_total: 3,
+ captures_embedded: 3,
+ capture_cohesion: 0,
+ views_scored: 3,
+ score_ms: 60000,
+ scored_at: '2026-08-14T01:00:00.000Z',
+ },
+ ]);
+
+ const [row] = await recentLikenessScores({ limit: 1 });
+ expect(row.turnFalloff).toBe(0);
+ expect(row.captureCohesion).toBe(0);
+ });
+});