Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: preserve concurrent benchmark fields from initially empty evidence (#8857)

[._.]/ Adam Eivya677c77f0b88
diff --git a/docs/features/voice.md b/docs/features/voice.md
index 6f3ba90a9c..0e5ae4ff1f 100644
--- a/docs/features/voice.md
+++ b/docs/features/voice.md
@@ -72,8 +72,10 @@ alone never enables the route. A one-use receipt expires after two minutes, bind
the measurement to the rendered profile revision, and saves its boundary, model
revision and route decision together. Restarting the server or changing the
profile requires a fresh benchmark. Playback rejection or timeout cannot qualify.
-The browser reports its own playback event; this is an operator measurement,
-not an attestation of another machine's audio output. No similarity score is
+The browser reports its own playback event; this is a trusted operator-reported
+measurement, not an attestation of another machine's audio output. The receipt
+binds the report to a current probe but cannot prove that a remote client played
+it. Qualification changes profile routing, not execution authority. No similarity score is
invented, and passing this latency gate does not establish intelligibility or
speaker identity.
diff --git a/server/services/voice/profileBenchmarks.js b/server/services/voice/profileBenchmarks.js
index 7b2b30d6a1..6644cd1e80 100644
--- a/server/services/voice/profileBenchmarks.js
+++ b/server/services/voice/profileBenchmarks.js
@@ -98,7 +98,9 @@ export async function benchmarkProfileInteractive(profileId, { maxFirstAudioMs =
return { benchmarkId, profileRevision: profile.version, audioBase64: result.wav.toString('base64') };
}
-/** Save only a receipt for the probe actually played by the browser. */
+/** Save the operator-reported playback measurement for this rendered probe.
+ * The nonce binds revision/lifecycle, not an attestation of a remote audio device.
+ */
export async function completeProfileInteractiveBenchmark(profileId, { benchmarkId, renderRequestLatencyMs, playbackStartupMs }) {
const pending = playbackBenchmarks.get(benchmarkId);
if (!pending || pending.profile.id !== profileId || pending.expiresAt <= performance.now()) {
diff --git a/server/services/voice/profiles.db.test.js b/server/services/voice/profiles.db.test.js
index 37794c6340..cd39720254 100644
--- a/server/services/voice/profiles.db.test.js
+++ b/server/services/voice/profiles.db.test.js
@@ -20,16 +20,29 @@ describe.skipIf(!runDb)('voice profile qualification persistence', () => {
id, version: 1, binding: { universeId: id, characterId: 'example-character' },
label: 'Example Voice', engine: 'piper', kind: 'preset', voiceId: 'piper:example',
routes: { studio: { enabled: true }, interactive: { enabled: false } },
- approval: { status: 'draft' },
+ approval: { status: 'draft' }, benchmark: null,
};
await query(`INSERT INTO voice_profiles (id, universe_id, character_id, approval_status, data)
VALUES ($1, $1, 'example-character', 'draft', $2::jsonb)`, [id, JSON.stringify(profile)]);
- const benchmark = { renderedAt: new Date().toISOString(), profileRevision: 1, interactiveLatencyMs: 250, similarityScore: null };
+ const renderedAt = new Date().toISOString();
+ // Real profiles start with JSON null; the first merge must remain an object.
+ await saveProfileBenchmark(profile, {
+ renderedAt, profileRevision: 1,
+ lines: [{ key: 'identity', text: 'An invented sentence.', filename: 'example.wav', engine: 'piper' }],
+ });
+ const benchmark = {
+ renderedAt, profileRevision: 1, interactiveLatencyMs: 250, similarityScore: null,
+ interactiveMeasurement: {
+ boundary: 'browser-playing-segmented', synthesisLatencyMs: 100,
+ renderRequestLatencyMs: 200, playbackStartupMs: 50, modelRevision: 'example-revision',
+ },
+ };
await saveProfileBenchmark(profile, benchmark, { interactive: { enabled: true, maxFirstAudioMs: 900 } });
expect(await getVoiceProfile(id)).toMatchObject({
label: 'Example Voice', benchmark,
routes: { studio: { enabled: true }, interactive: { enabled: true, maxFirstAudioMs: 900 } },
});
+ expect((await getVoiceProfile(id)).benchmark.lines).toMatchObject([{ key: 'identity', filename: 'example.wav' }]);
await query(`UPDATE voice_profiles SET data = data || '{"version":2,"label":"Revised Voice"}'::jsonb WHERE id = $1`, [id]);
await expect(saveProfileBenchmark(profile, benchmark, { interactive: { enabled: false } }))
.rejects.toMatchObject({ code: 'VOICE_PROFILE_BENCHMARK_STALE' });
diff --git a/server/services/voice/profiles.js b/server/services/voice/profiles.js
index 8d1bef9e51..75d4431e90 100644
--- a/server/services/voice/profiles.js
+++ b/server/services/voice/profiles.js
@@ -589,7 +589,7 @@ export async function saveProfileBenchmark(profile, benchmark, { interactive } =
CASE WHEN $4::jsonb IS NULL THEN data || $2::jsonb
ELSE jsonb_set(data || $2::jsonb, '{routes}',
COALESCE(data->'routes', '{}'::jsonb) || jsonb_build_object('interactive', $4::jsonb)) END,
- '{benchmark}', COALESCE(data->'benchmark', '{}'::jsonb) || ($2::jsonb->'benchmark')),
+ '{benchmark}', COALESCE(NULLIF(data->'benchmark', 'null'::jsonb), '{}'::jsonb) || ($2::jsonb->'benchmark')),
updated_at = $5
WHERE id = $1 AND (data->>'version')::int = $3
RETURNING data`,
diff --git a/server/services/voice/profiles.test.js b/server/services/voice/profiles.test.js
index f1e7cd1afd..3953360d4c 100644
--- a/server/services/voice/profiles.test.js
+++ b/server/services/voice/profiles.test.js
@@ -270,7 +270,7 @@ describe('voice profile contract', () => {
expect(saved.routes.interactive).toEqual(interactive);
const [sql, args] = queryMock.mock.calls[0];
expect(sql).toContain("(data->>'version')::int = $3");
- expect(sql).toContain("COALESCE(data->'benchmark', '{}'::jsonb) || ($2::jsonb->'benchmark')");
+ expect(sql).toContain("COALESCE(NULLIF(data->'benchmark', 'null'::jsonb), '{}'::jsonb) || ($2::jsonb->'benchmark')");
expect(JSON.parse(args[1]).benchmark).not.toHaveProperty('lines');
expect(JSON.parse(args[1]).benchmark.interactiveMeasurement).toEqual(benchmark.interactiveMeasurement);
expect(args[2]).toBe(PROFILE.version);