From 8751e7c08e3ff93abf87155f323ea2bf19b22c40 Mon Sep 17 00:00:00 2001 From: Gabby Morgan Date: Thu, 1 Oct 2026 20:35:38 +0000 Subject: [PATCH] dashboard: show a pending submit while its run spins up; retune codegen defaults Submitting from the dashboard cleared the input and then showed nothing until the next poll, so a slow submit looked like a no-op. POST /api/submit now returns the new request_id alongside status/detail (Scheduler.submit_request), and the front end keeps a `pendingSubmit` entry: it immediately renders a synthetic "submitted" node plus an in-flight spinner, then swaps to the real run once its trace row appears (matching by request_id) and clears the pending state. A run that has landed but has no decisions yet also gets the spinner instead of an empty flow. Adds a test asserting the returned request_id matches a trace run. Also flip config.example.json codegen defaults to stream:true and temperature 1 / top_p 0.95 / presence_penalty 0 / frequency_penalty 1. --- config.example.json | 10 +++--- semif_agent/dashboard.py | 4 +-- semif_agent/static/app.js | 64 +++++++++++++++++++++++++++++++++++- semif_agent/static/style.css | 25 ++++++++++++++ tests/test_dashboard_api.py | 18 ++++++++++ 5 files changed, 113 insertions(+), 8 deletions(-) diff --git a/config.example.json b/config.example.json index 184cfb4..20566d3 100644 --- a/config.example.json +++ b/config.example.json @@ -48,7 +48,7 @@ "api_key_env": "", "user_agent": "", "timeout": 1200, - "stream": false, + "stream": true, "idle_warn": 60, "idle_timeout": 180, "context_window": 0, @@ -58,10 +58,10 @@ "warn_fill_ratio": 0.7, "max_output": 0.85, "chars_per_token": 4.0, - "temperature": 0.7, - "top_p": 0.85, - "presence_penalty": 1.5, - "frequency_penalty": 0.2, + "temperature": 1, + "top_p": 0.95, + "presence_penalty": 0, + "frequency_penalty": 1, "max_attempts": 3, "elicitation": { "_comment": "Ask the product owner implementation questions before the body is written: which service/account, how to connect, where the credential comes from, what success looks like. Every front end defers questions to the questions panel and the single-slot writer waits up to wait_timeout seconds. Questions never ask for operational data values (collected at first fire) or config-vs-input cadence (the config step owns that).", diff --git a/semif_agent/dashboard.py b/semif_agent/dashboard.py index f656ff9..4ae4f53 100644 --- a/semif_agent/dashboard.py +++ b/semif_agent/dashboard.py @@ -236,13 +236,13 @@ class DashboardHandler(BaseHTTPRequestHandler): with self.lock: try: body = self._read_json() - status, detail = self.scheduler.submit( + status, detail, request_id = self.scheduler.submit_request( str(body.get("text", "")), source=str(body.get("source", "dashboard")) ) except Exception as exc: self._send_error(500, str(exc)) return - self._send(200, {"status": status, "detail": detail}) + self._send(200, {"status": status, "detail": detail, "request_id": request_id}) return if path == "/api/relabel": with self.lock: diff --git a/semif_agent/static/app.js b/semif_agent/static/app.js index aedce15..938f627 100644 --- a/semif_agent/static/app.js +++ b/semif_agent/static/app.js @@ -13,6 +13,7 @@ const state = { scrub: 0, flowSteps: [], answerFeedback: null, + pendingSubmit: null, }; async function getJSON(url, opts) { @@ -36,6 +37,13 @@ async function refreshAll() { state.selectedRunId = null; state.selectedDecisionId = null; } + const pending = state.pendingSubmit; + if (pending && pending.requestId && state.runs.some((r) => r.run_id === pending.requestId)) { + state.selectedRunId = pending.requestId; + state.selectedDecisionId = null; + state.scrub = 0; + state.pendingSubmit = null; + } render(); } @@ -214,6 +222,10 @@ function renderFlow() { el.innerHTML = ""; if (!run) { + if (state.pendingSubmit) { + renderPendingFlow(el); + return; + } const empty = document.createElement("div"); empty.className = "muted"; empty.textContent = "select a run from the timeline"; @@ -233,6 +245,45 @@ function renderFlow() { if (i > state.scrub) node.classList.add("dim"); el.appendChild(node); } + + if (run.decisions.length === 0 && runInFlight(run)) { + if (steps.length) el.appendChild(edge(steps[steps.length - 1].data)); + el.appendChild(pendingIndicatorNode("decisions in process…")); + } +} + +const RESTING_EVENTS = ["ran", "rejected", "dropped", "error", "assessed", "needs_input", "pending_abandoned"]; + +function runInFlight(run) { + return !run.events.some((evt) => RESTING_EVENTS.includes(evt.kind)); +} + +function renderPendingFlow(el) { + const node = document.createElement("div"); + node.className = "node event-node pending-request"; + const kind = document.createElement("div"); + kind.className = "evt-kind"; + kind.textContent = "submitted"; + node.appendChild(kind); + const body = document.createElement("div"); + body.className = "node-question"; + body.textContent = state.pendingSubmit.text; + node.appendChild(body); + el.appendChild(node); + el.appendChild(edge({ kind: "event" })); + el.appendChild(pendingIndicatorNode("decisions in process…")); +} + +function pendingIndicatorNode(text) { + const node = document.createElement("div"); + node.className = "node pending-indicator"; + const dot = document.createElement("span"); + dot.className = "spinner"; + node.appendChild(dot); + const label = document.createElement("span"); + label.textContent = text; + node.appendChild(label); + return node; } function edge(prev) { @@ -776,6 +827,12 @@ $("#submit-form").addEventListener("submit", async (e) => { e.preventDefault(); const text = $("#query-input").value.trim(); if (!text) return; + $("#query-input").value = ""; + state.pendingSubmit = { text, requestId: null }; + state.selectedRunId = null; + state.selectedDecisionId = null; + state.scrub = 0; + render(); try { const res = await getJSON("/api/submit", { method: "POST", @@ -783,10 +840,15 @@ $("#submit-form").addEventListener("submit", async (e) => { body: JSON.stringify({ text }), }); flash(`[${res.status}] ${res.detail}`); + if (res.request_id) { + state.pendingSubmit.requestId = res.request_id; + } else { + state.pendingSubmit = null; + } } catch (err) { flash(`submit failed: ${err.message}`); + state.pendingSubmit = null; } - $("#query-input").value = ""; await refreshAll(); }); diff --git a/semif_agent/static/style.css b/semif_agent/static/style.css index f200ceb..6860b5d 100644 --- a/semif_agent/static/style.css +++ b/semif_agent/static/style.css @@ -317,6 +317,31 @@ select { 50% { opacity: 0.35; } } +/* ---------- pending submit ---------- */ + +.node.pending-indicator { + display: flex; + align-items: center; + gap: 8px; + width: auto; + color: var(--warn); + font-size: 12px; + border-style: dashed; + cursor: default; +} + +.node.pending-indicator:hover { border-color: var(--line); } + +.pending-indicator .spinner { + width: 9px; + height: 9px; + border-radius: 50%; + background: var(--warn); + animation: writing-pulse 1.2s ease-in-out infinite; +} + +.node.event-node.pending-request { border-left: 3px solid var(--accent); } + /* ---------- inspector / tree / status ---------- */ .right { border-right: none; } diff --git a/tests/test_dashboard_api.py b/tests/test_dashboard_api.py index d63b298..0d0239d 100644 --- a/tests/test_dashboard_api.py +++ b/tests/test_dashboard_api.py @@ -156,6 +156,24 @@ def test_submit_without_engine_returns_fatal_json(tmp_path): server.close() +def test_submit_returns_request_id_matching_trace(tmp_path): + """Submit hands the front end the request id so it can open the new run's + flow container and follow it as decisions land.""" + scheduler = build_scheduler(tmp_path) + server = Server(scheduler) + try: + status, payload = server.post("/api/submit", {"text": "hello"}) + assert status == 200 + request_id = payload["request_id"] + assert request_id + + status, trace = server.get("/api/trace") + assert status == 200 + assert any(run["run_id"] == request_id for run in trace["runs"]) + finally: + server.close() + + def test_relabel_roundtrip(tmp_path): scheduler = build_scheduler(tmp_path) seed_decision(scheduler.log)