dashboard: show answer feedback and auto-select the resumed run

The answer flow ran the whole resume + LLM assessment synchronously before
the frontend cleared the input or flashed anything, so a slow answer looked
like a no-op. Make it optimistic: clear input, disable the button, and show
an in-flight 'answering…' state immediately; then persist a consumed-feedback
line (with a hint when the skill re-asks the same question) and auto-select
the run in the timeline so the answered/assessed/needs_input events are
visible. build_status now carries the pending run_id to drive that selection.
This commit is contained in:
Denton Social committed 2026-09-25 12:10:40 -05:00
1 parent 87438c881a
commit 927f66b696
5 files changed
+93 -4

No files matched your search

+5 -1
View File
@@ -100,7 +100,11 @@ def build_status(scheduler: Scheduler) -> dict:
else None
)
pending = (
{"skill": scheduler.pending.skill.name, "question": scheduler.pending.question}
{
"skill": scheduler.pending.skill.name,
"question": scheduler.pending.question,
"run_id": scheduler.pending.request.id,
}
if scheduler.pending
else None
)
+58 -1
View File
@@ -12,6 +12,7 @@ const state = {
phaseFilter: "",
scrub: 0,
flowSteps: [],
answerFeedback: null,
};
async function getJSON(url, opts) {
@@ -553,7 +554,41 @@ function renderStatus() {
$("#answer-form").classList.toggle("hidden", !pending);
if (pending) {
$("#answer-input").placeholder = `${pending.skill}: ${pending.question}`;
const p = document.createElement("div");
p.className = "pending-line";
p.textContent = `awaiting input (${pending.run_id || pending.skill}): ${pending.question}`;
el.appendChild(p);
}
renderAnswerFeedback();
}
function renderAnswerFeedback() {
const el = $("#answer-feedback");
const fb = state.answerFeedback;
el.className = "hidden";
if (!fb) return;
if (fb.inflight) {
el.className = "";
el.textContent = "answering…";
return;
}
if (fb.status === "error") {
el.className = "feedback-error";
el.textContent = `✗ ${fb.detail}`;
return;
}
let line = `✓ consumed "${fb.text}"`;
if (fb.status === "needs_input") {
el.className = "feedback-awaiting";
line += ` → awaiting: ${fb.detail}`;
if (fb.askedQuestion && fb.detail === fb.askedQuestion) {
line += " (answer received; the skill asked again)";
}
} else {
el.className = "";
line += ` → ${fb.detail}`;
}
el.textContent = line;
}
function stat(k, v) {
@@ -632,6 +667,14 @@ $("#answer-form").addEventListener("submit", async (e) => {
e.preventDefault();
const text = $("#answer-input").value.trim();
if (!text) return;
const btn = $("#answer-btn");
const pending = state.status.pending || {};
const runId = pending.run_id || null;
const askedQuestion = pending.question || null;
$("#answer-input").value = "";
btn.disabled = true;
state.answerFeedback = { inflight: true };
renderAnswerFeedback();
try {
const res = await getJSON("/api/answer", {
method: "POST",
@@ -639,11 +682,25 @@ $("#answer-form").addEventListener("submit", async (e) => {
body: JSON.stringify({ text }),
});
flash(`[${res.status}] ${res.detail}`);
state.answerFeedback = { status: res.status, detail: res.detail, text, askedQuestion };
} catch (err) {
flash(`answer failed: ${err.message}`);
state.answerFeedback = {
status: "error",
detail: `answer failed: ${err.message}`,
text,
askedQuestion,
};
} finally {
btn.disabled = false;
}
$("#answer-input").value = "";
await refreshAll();
if (runId && state.runs.some((r) => r.run_id === runId)) {
state.selectedRunId = runId;
state.selectedDecisionId = null;
state.scrub = 0;
render();
}
});
$("#refresh-btn").addEventListener("click", async () => {
+2 -1
View File
@@ -21,8 +21,9 @@
<form id="answer-form" class="hidden">
<input id="answer-input" type="text" autocomplete="off" spellcheck="false"
placeholder="answer the pending question">
<button type="submit">answer</button>
<button type="submit" id="answer-btn">answer</button>
</form>
<div id="answer-feedback" class="hidden"></div>
<button id="refresh-btn" type="button" title="reload trace">refresh</button>
</section>
+25
View File
@@ -48,6 +48,7 @@ html, body {
.inputbar {
display: flex;
flex-wrap: wrap;
gap: 8px;
padding: 10px 16px;
background: var(--panel-2);
@@ -56,6 +57,19 @@ html, body {
.inputbar form { display: flex; flex: 1; gap: 8px; }
#answer-feedback {
flex: 1 1 100%;
padding: 6px 12px;
font-size: 12px;
color: var(--ok);
background: var(--bg);
border: 1px solid var(--line);
border-radius: 6px;
}
#answer-feedback.feedback-error { color: var(--fail); border-color: var(--fail); }
#answer-feedback.feedback-awaiting { color: var(--warn); border-color: var(--warn); }
#query-input {
flex: 1;
background: var(--bg);
@@ -346,6 +360,17 @@ pre.json {
.stat-grid .stat { background: var(--panel-2); border-radius: 4px; padding: 4px 6px; }
.stat-grid .stat .v { font-weight: 700; }
.pending-line {
margin: 8px 0 4px;
padding: 6px 8px;
background: var(--panel-2);
border-radius: 4px;
border-left: 3px solid var(--warn);
color: var(--warn);
white-space: pre-wrap;
word-break: break-word;
}
/* ---------- scrubber ---------- */
.scrub-label { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
+3 -1
View File
@@ -273,13 +273,15 @@ def test_answer_without_pending_returns_error_json(tmp_path):
def test_status_includes_pending(tmp_path):
scheduler = build_scheduler(tmp_path)
scheduler._run_skill(need_input_skill([]), Request("track my package"))
request = Request("track my package")
scheduler._run_skill(need_input_skill([]), request)
server = Server(scheduler)
try:
status, payload = server.get("/api/status")
assert status == 200
assert payload["pending"]["skill"] == "track.manual"
assert payload["pending"]["question"] == "What's the tracking number?"
assert payload["pending"]["run_id"] == request.id
finally:
server.close()