Spaces:
Running on Zero

Restore the Studio Run button when a direct stream ends early

#4
by rpinho1 - opened

CellGemma Studio's direct NDJSON response can end normally before a complete or error event, leaving Run disabled and silent until a manual reset. I replayed nine HTTP 200 responses in Chrome that ended early. Seven stopped after partial results from saved Apple MPS runs, one was empty, and one held only a started event. The Run button stayed disabled in all nine.

The patch checks for an unfinished, un-aborted run when the response ends and reuses existing interruption handling to re-enable Run and show its error. All nine could retry immediately. An explicit server error still displayed verbatim. All ten completed retries displayed the saved prompt and output exactly.

Run this Node regression from the Studio checkout. It sends a started event before the response ends, then checks the error message and retry. It exits 1 on upstream and 0 with the patch.

const assert = require('node:assert/strict');
const fs = require('node:fs');
const vm = require('node:vm');

const elements = new Map();
const document = {
  readyState: 'loading',
  addEventListener() {},
  getElementById(id) {
    if (!elements.has(id)) {
      elements.set(id, { classList: { add() {}, remove() {} } });
    }
    return elements.get(id);
  },
};
const source = fs.readFileSync(process.argv[2] || 'static/app.js', 'utf8');
const window = {};
const fixtures = [];
function fetch() {
  const events = fixtures.shift();
  return new Response(events.map((event) => JSON.stringify(event) + '\n').join(''));
}
vm.runInNewContext(source.replace(/\}\)\(\);\s*$/, `
  syncUI = () => { document.getElementById("run-btn").disabled = appState.stageMode === "running"; };
  window.run = startLiveRun;
})();`), { window, document, fetch, AbortController, TextDecoder, performance });

(async () => {
  const stage = window.__CELLGEMMA_INSPECT__.getStageMode;
  const run = document.getElementById('run-btn');
  const error = document.getElementById('error-banner');
  fixtures.push([{ type: 'started' }]);
  await window.run();
  assert.equal(stage(), 'before');
  assert.equal(run.disabled, false);
  assert.match(error.textContent, /Prediction interrupted/);
  fixtures.push([{ type: 'complete', state: { prompt: 'retried' } }]);
  await window.run();
  assert.equal(stage(), 'after');
  assert.equal(run.disabled, false);
  assert.equal(error.textContent, '');
})().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

🤖 Generated with Claude Code

Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment