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: reject undecodable music installation completion frames (#9933)

[._.]/ Adam Eivy438b8dbbde1f
diff --git a/client/src/services/apiMusic.js b/client/src/services/apiMusic.js
index 9127dfb4b1..4cac3d2124 100644
--- a/client/src/services/apiMusic.js
+++ b/client/src/services/apiMusic.js
@@ -90,7 +90,7 @@ async function postForSseFrames(url, payload, onEvent) {
throw new Error((typeof parsed?.error === 'string' ? parsed.error : parsed?.error?.message) || raw || `Request failed (${res.status})`);
}
const reader = res.body.getReader();
- const decoder = new TextDecoder();
+ const decoder = new TextDecoder('utf-8', { fatal: true });
let buf = '';
const handleFrame = (frame) => {
const data = frame.split(/\r?\n/).filter((line) => line.startsWith('data:'))
@@ -105,7 +105,11 @@ async function postForSseFrames(url, payload, onEvent) {
try {
for (;;) {
const { value, done } = await reader.read();
- buf += done ? decoder.decode() : decoder.decode(value, { stream: true });
+ try {
+ buf += done ? decoder.decode() : decoder.decode(value, { stream: true });
+ } catch (cause) {
+ throw new Error('Installation stream contained invalid UTF-8. Check installation status before retrying.', { cause });
+ }
const frames = buf.split(/\r?\n\r?\n/);
buf = frames.pop() || '';
if (done && buf) frames.push(buf);
diff --git a/client/src/services/apiMusic.test.js b/client/src/services/apiMusic.test.js
index ae60362d71..cc60683660 100644
--- a/client/src/services/apiMusic.test.js
+++ b/client/src/services/apiMusic.test.js
@@ -8,7 +8,7 @@ afterEach(() => { vi.unstubAllGlobals(); vi.clearAllMocks(); });
const respond = (chunks) => vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
ok: true,
body: new ReadableStream({ start(controller) {
- for (const chunk of chunks) controller.enqueue(new TextEncoder().encode(chunk));
+ for (const chunk of chunks) controller.enqueue(typeof chunk === 'string' ? new TextEncoder().encode(chunk) : chunk);
controller.close();
} }),
}));
@@ -34,6 +34,17 @@ for (const [name, start] of [
await expect(start(events)).resolves.toBeUndefined();
expect(events.mock.calls.map(([event]) => event.type)).toEqual(['log', 'complete']);
});
+ it('rejects undecodable completion bytes without a success callback, preserving earlier progress', async () => {
+ const encode = (text) => new TextEncoder().encode(text);
+ respond([
+ 'data: {"type":"progress","progress":0.5}\n\n',
+ new Uint8Array([...encode('data: {"type":"complete","message":"'), 0xff, ...encode('"}\n\n')]),
+ ]);
+ const events = vi.fn();
+ await expect(start(events)).rejects.toThrow('invalid UTF-8');
+ expect(events.mock.calls.map(([event]) => event.type)).toEqual(['progress']);
+ expect(fetch).toHaveBeenCalledTimes(1);
+ });
it('does not interpret malformed completion as success', async () => {
respond(['data: {"type":"complete"\n\n']);
await expect(start(vi.fn())).rejects.toThrow();