fix(chat): recover web approvals and questions across clients and reconnects
This commit is contained in:
@@ -183,6 +183,28 @@ history, so that row stays as closed history (there is no delete command). The
|
||||
page keeps its own ephemeral throwaway row in memory so the check can switch back
|
||||
to it, but the server never lists it and a reload drops it.
|
||||
|
||||
## Web interaction recovery (2026-10-20)
|
||||
|
||||
- C10 approvals are read from the **session-owned** OpenCode endpoint, including
|
||||
turns started in another client/directory. Merely subscribing starts polling;
|
||||
no web prompt is needed. Room recreation no longer suppresses an already-seen
|
||||
pending approval. Requests answered in the harness clear on readback.
|
||||
- C10/B6 retain multiple approvals and questions independently, recover questions
|
||||
from the session form list after reconnect/server restart, and keep typed
|
||||
question answers across unrelated streaming paints. Long approval resources
|
||||
can be expanded before deciding. No permission policy is bypassed.
|
||||
- Scratch Chrome regression captures `mobile-pending-interactions.png` at 390px:
|
||||
two broker-originated approvals and two questions survive a reload; both
|
||||
decisions and both answers reach the server. This is not a claim about every
|
||||
backend: Codex request recovery remains limited to its live App Server socket.
|
||||
|
||||
Runs layout follow-up: run task titles wrap without ellipsis (including long
|
||||
unbroken tokens); all applied pipeline/status/time filters have their own
|
||||
clearable, wrapping row beneath Filter/Sort. Browser measurements at 390/420px
|
||||
confirm no horizontal overflow and full-width run rows; the selected row also
|
||||
fills its scroll pane at 1100px. Captures: `wrapped-run-title-390.png`,
|
||||
`wrapped-run-title-420.png`, `full-width-selected-run.png`.
|
||||
|
||||
## Settings, layout, platform
|
||||
| # | Feature | Protocol | Status |
|
||||
| --- | --- | --- | --- |
|
||||
|
||||
+25
-6
@@ -1576,18 +1576,21 @@ export function applyChatForm(thread, form) {
|
||||
const id = str(form?.id);
|
||||
if (id === "") return current;
|
||||
const existing = current.form ?? null;
|
||||
const forms = [...(current.forms ?? (existing ? [existing] : []))].filter((entry) => entry.id !== id);
|
||||
if (form?.resolved !== true && form?.cancelled !== true) forms.push(form);
|
||||
const next = { ...current, forms };
|
||||
if (form?.cancelled === true) {
|
||||
if (str(existing?.id) !== id) return current;
|
||||
return { ...current, form: null };
|
||||
if (str(existing?.id) !== id) return next;
|
||||
return { ...next, form: forms.at(-1) ?? null };
|
||||
}
|
||||
if (form?.resolved === true) {
|
||||
if (str(existing?.id) !== id) return current;
|
||||
return { ...current, form: { ...existing, ...form, resolved: true } };
|
||||
if (str(existing?.id) !== id) return next;
|
||||
return { ...next, form: forms.at(-1) ?? { ...existing, ...form, resolved: true } };
|
||||
}
|
||||
if (str(existing?.id) === id) {
|
||||
return { ...current, form: { ...existing, ...form } };
|
||||
return { ...next, form: { ...existing, ...form } };
|
||||
}
|
||||
return { ...current, form };
|
||||
return { ...next, form };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2324,9 +2327,25 @@ export function applyChatPermission(thread, frame) {
|
||||
const current = thread ?? newChatThread(str(frame?.session_id));
|
||||
const requestId = str(frame?.request_id);
|
||||
const sameRequest = requestId !== "" && str(current.permission?.request_id) === requestId;
|
||||
const permissions = [...(current.permissions ?? (current.permission ? [current.permission] : []))]
|
||||
.filter((entry) => str(entry?.request_id) !== requestId && entry?.resolved !== true);
|
||||
if (requestId && frame?.resolved !== true) permissions.push(frame);
|
||||
return {
|
||||
...current,
|
||||
permissions,
|
||||
permission: frame ?? null,
|
||||
permissionAnswer: sameRequest ? str(current.permissionAnswer) : "",
|
||||
};
|
||||
}
|
||||
|
||||
export function chatApprovalCards(thread) {
|
||||
return (thread?.permissions ?? (thread?.permission ? [thread.permission] : []))
|
||||
.map((frame) => approvalCard(frame, thread?.permissionAnswers?.[frame.request_id] ??
|
||||
(frame.request_id === thread?.permission?.request_id ? thread.permissionAnswer : "")))
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
export function chatPendingForms(thread) {
|
||||
return (thread?.forms ?? (thread?.form ? [thread.form] : []))
|
||||
.filter((form) => form?.resolved !== true && form?.cancelled !== true);
|
||||
}
|
||||
|
||||
+50
-18
@@ -79,6 +79,9 @@ import {
|
||||
applyChatEvent,
|
||||
applyChatOverrides,
|
||||
applyChatPermission,
|
||||
applyChatForm,
|
||||
chatApprovalCards,
|
||||
chatPendingForms,
|
||||
abbreviateHome,
|
||||
appendChatNotice,
|
||||
approvalCard,
|
||||
@@ -738,7 +741,12 @@ function refreshChatTranscript(sessionId) {
|
||||
if (rows.length === 0 && notices.length === 0 && !thread.running && !approval && !form) {
|
||||
return false;
|
||||
}
|
||||
const running = thread.running === true && approval?.actionable !== true;
|
||||
const awaiting = chatApprovalCards(thread).some((card) => card.actionable) || chatPendingForms(thread).length > 0;
|
||||
const running = thread.running === true && !awaiting;
|
||||
const bar = document.querySelector(".chat-bar");
|
||||
const jump = bar?.querySelector(".chat-approval-jump");
|
||||
if (awaiting && bar && !jump) bar.append(approvalJumpButton());
|
||||
else if (!awaiting) jump?.remove();
|
||||
captureChatPosition();
|
||||
// The background-tasks bar sits outside the transcript but is driven by the
|
||||
// same shell frames. Patch it in place instead of full-rendering the pane (and
|
||||
@@ -841,7 +849,8 @@ function onChatPermission(frame) {
|
||||
next.permissionError = "";
|
||||
}
|
||||
state.chatThreads.set(sessionId, next);
|
||||
if (state.view === "chat" && sessionId === state.chatActiveId) scheduleChatRender();
|
||||
markBackgroundChatUnseen(sessionId);
|
||||
if (state.view === "chat" && sessionId === state.chatActiveId) scheduleChatRender("transcript");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -854,9 +863,9 @@ function onChatPermission(frame) {
|
||||
*/
|
||||
async function answerPermission(sessionId, requestId, decision) {
|
||||
const thread = state.chatThreads.get(sessionId);
|
||||
const permission = thread?.permission;
|
||||
if (!thread || String(permission?.request_id ?? "") !== requestId) return;
|
||||
setThread(sessionId, { permissionAnswer: decision });
|
||||
const permission = (thread?.permissions ?? [thread?.permission]).find((entry) => entry?.request_id === requestId);
|
||||
if (!thread || !permission) return;
|
||||
setThread(sessionId, { permissionAnswers: { ...thread.permissionAnswers, [requestId]: decision } });
|
||||
renderContent();
|
||||
try {
|
||||
await repo.chatReply(sessionId, requestId, decision);
|
||||
@@ -870,9 +879,9 @@ async function answerPermission(sessionId, requestId, decision) {
|
||||
}
|
||||
} catch (error) {
|
||||
const current = state.chatThreads.get(sessionId);
|
||||
if (!current || String(current.permission?.request_id ?? "") !== requestId) return;
|
||||
if (!current || !(current.permissions ?? [current.permission]).some((entry) => entry?.request_id === requestId)) return;
|
||||
const reason = describeError(error);
|
||||
setThread(sessionId, { permissionAnswer: "", error: reason, permissionError: reason });
|
||||
setThread(sessionId, { permissionAnswers: { ...current.permissionAnswers, [requestId]: "" }, error: reason, permissionError: reason });
|
||||
renderContent();
|
||||
}
|
||||
}
|
||||
@@ -887,9 +896,7 @@ async function answerChatQuestion(sessionId, form, answers) {
|
||||
try {
|
||||
await repo.answerChatForm(sessionId, form.id, answers);
|
||||
const current = state.chatThreads.get(sessionId);
|
||||
if (current?.form && current.form.id === form.id) {
|
||||
setThread(sessionId, { form: { ...current.form, resolved: true } });
|
||||
}
|
||||
if (current) state.chatThreads.set(sessionId, applyChatForm(current, { ...form, resolved: true }));
|
||||
renderContent();
|
||||
} catch (error) {
|
||||
state.actionError = describeError(error);
|
||||
@@ -1017,7 +1024,10 @@ async function loadChatHistory(id) {
|
||||
// The merged page replaces only the history fields; spreading it over the
|
||||
// held thread keeps the composer's draft, attachments and flags intact (a
|
||||
// draft typed while the page was loading is not lost).
|
||||
setThread(id, mergeHistoryPage(previous, page, { older: false }));
|
||||
// Live approvals/questions can arrive before this HTTP read finishes. Merge
|
||||
// over the current thread, never the pre-request snapshot that would erase
|
||||
// the just-delivered interaction (and any draft typed during the read).
|
||||
setThread(id, mergeHistoryPage(state.chatThreads.get(id) ?? previous, page, { older: false }));
|
||||
} catch (error) {
|
||||
setThread(id, { loading: false, loaded: true, error: describeError(error) });
|
||||
}
|
||||
@@ -2449,7 +2459,7 @@ function renderChatConversation() {
|
||||
thread?.form && thread.form.resolved !== true && thread.form.cancelled !== true
|
||||
? thread.form
|
||||
: null;
|
||||
const awaiting = approval?.actionable === true || form != null;
|
||||
const awaiting = chatApprovalCards(thread).some((card) => card.actionable) || chatPendingForms(thread).length > 0;
|
||||
|
||||
const bar = h("div", { class: "chat-bar" });
|
||||
const lead = h("div", { class: "chat-bar-lead" });
|
||||
@@ -3007,8 +3017,19 @@ function renderChatTranscript(
|
||||
// The approval card is the transcript's last item (C10) — after the notices and
|
||||
// after the running indicator when it is shown — so the pane's jump control
|
||||
// and a fresh card both land at the end.
|
||||
if (approval) transcript.append(renderChatApproval(sessionId, approval));
|
||||
if (form) transcript.append(renderChatQuestion(sessionId, form));
|
||||
const approvals = chatApprovalCards(thread);
|
||||
const forms = chatPendingForms(thread);
|
||||
if (!approvals.length && approval) approvals.push(approval);
|
||||
approvals.forEach((card, index) => {
|
||||
const node = renderChatApproval(sessionId, card);
|
||||
if (index === 0) node.id = "chatApproval";
|
||||
transcript.append(node);
|
||||
});
|
||||
forms.forEach((pending, index) => {
|
||||
const node = renderChatQuestion(sessionId, pending);
|
||||
if (index === 0) node.id = "chatQuestion";
|
||||
transcript.append(node);
|
||||
});
|
||||
wrap.append(transcript);
|
||||
wrap.append(
|
||||
h("button", {
|
||||
@@ -3057,7 +3078,7 @@ function approvalJumpButton() {
|
||||
function renderChatApproval(sessionId, card) {
|
||||
const node = h("div", {
|
||||
class: `chat-approval${card.actionable ? " chat-approval-pending" : ""}`,
|
||||
id: "chatApproval",
|
||||
id: `chatApproval-${card.requestId}`,
|
||||
"data-request-id": card.requestId,
|
||||
});
|
||||
const head = h("div", { class: "chat-approval-head" });
|
||||
@@ -3073,6 +3094,12 @@ function renderChatApproval(sessionId, card) {
|
||||
const box = h("div", { class: "chat-approval-resources" });
|
||||
box.append(h("pre", { class: "chat-approval-resources-text", text: card.resourceText }));
|
||||
node.append(box);
|
||||
const full = card.resources.join("\n");
|
||||
if (full !== card.resourceText) {
|
||||
node.append(h("details", { class: "chat-approval-details" },
|
||||
h("summary", { text: "Show full request" }),
|
||||
h("pre", { text: full, style: "white-space: pre-wrap; overflow-wrap: anywhere;" })));
|
||||
}
|
||||
}
|
||||
if (card.showRisk && card.risk.trim() !== "") {
|
||||
const risk = h("div", { class: "chat-approval-risk" });
|
||||
@@ -3102,7 +3129,7 @@ function renderChatApproval(sessionId, card) {
|
||||
function renderChatQuestion(sessionId, form) {
|
||||
const node = h("div", {
|
||||
class: "chat-question",
|
||||
id: "chatQuestion",
|
||||
id: `chatQuestion-${form.id}`,
|
||||
"data-form-id": form.id,
|
||||
});
|
||||
const head = h("div", { class: "chat-question-head" });
|
||||
@@ -3112,7 +3139,10 @@ function renderChatQuestion(sessionId, form) {
|
||||
);
|
||||
node.append(head);
|
||||
|
||||
const answers = {};
|
||||
// Keep entered answers across unrelated streaming frames and reconnect paints.
|
||||
const thread = state.chatThreads.get(sessionId);
|
||||
if (thread && !thread.formAnswers) thread.formAnswers = {};
|
||||
const answers = thread ? (thread.formAnswers[form.id] ??= {}) : {};
|
||||
const parts = [];
|
||||
for (const field of form.fields ?? []) {
|
||||
const key = String(field.key ?? "");
|
||||
@@ -3168,6 +3198,7 @@ function renderChatQuestion(sessionId, form) {
|
||||
buttons.push(button);
|
||||
rows.append(button);
|
||||
}
|
||||
paint();
|
||||
part.append(rows);
|
||||
}
|
||||
if (field.custom === true || options.length === 0) {
|
||||
@@ -3176,6 +3207,7 @@ function renderChatQuestion(sessionId, form) {
|
||||
type: "text",
|
||||
placeholder: options.length ? "Type another answer" : "Your answer",
|
||||
autocomplete: "off",
|
||||
value: typeof answers[key] === "string" ? answers[key] : "",
|
||||
});
|
||||
input.addEventListener("input", () => {
|
||||
const value = input.value.trim();
|
||||
@@ -4186,7 +4218,7 @@ function updateChatJump(el) {
|
||||
function refreshChatClock() {
|
||||
chatNow = Date.now();
|
||||
const thread = state.chatActiveId ? state.chatThreads.get(state.chatActiveId) : null;
|
||||
const awaiting = approvalCard(thread?.permission, thread?.permissionAnswer)?.actionable === true;
|
||||
const awaiting = chatApprovalCards(thread).some((card) => card.actionable) || chatPendingForms(thread).length > 0;
|
||||
if (state.view !== "chat" || !thread?.running || awaiting) {
|
||||
stopChatClock();
|
||||
return;
|
||||
|
||||
@@ -107,8 +107,34 @@ try {
|
||||
await page.fill("#chatInput", "New message must scroll into view");
|
||||
await page.click("#chatSend");
|
||||
await eventually(() => page.evaluate("(() => { const t=document.querySelector('#chatTranscript'); return t.textContent.includes('New message must scroll into view') && t.scrollHeight-t.scrollTop-t.clientHeight<3; })()"));
|
||||
// These requests originate at the broker snapshot, not an injected browser
|
||||
// frame. A reload must recover all of them, and each control reaches Go.
|
||||
assert.equal((await fetch(`http://${target}/fixture-attention`,{method:'POST'})).status,204);
|
||||
await eventually(() => page.evaluate("document.querySelectorAll('.chat-approval-pending').length===2 && document.querySelectorAll('.chat-question').length===2"));
|
||||
await page.goto(`http://127.0.0.1:${port}/chat/${sessionId}`);
|
||||
try {
|
||||
await eventually(() => page.evaluate("document.querySelectorAll('.chat-approval-pending').length===2 && document.querySelectorAll('.chat-question').length===2"));
|
||||
} catch(error) {
|
||||
console.log(await page.evaluate("({approvals:document.querySelectorAll('.chat-approval-pending').length,questions:document.querySelectorAll('.chat-question').length,errors:window.__errors,text:document.body.innerText.slice(-2000)})"));
|
||||
throw error;
|
||||
}
|
||||
assert.equal(await page.evaluate("!!document.querySelector('.chat-approval-jump')"),true);
|
||||
await page.click('.chat-approval-jump');
|
||||
if(process.env.PIPELINES_CAPTURE_DIR) await page.screenshot(join(process.env.PIPELINES_CAPTURE_DIR,'mobile-pending-interactions.png'));
|
||||
await page.evaluate("document.querySelector('[data-request-id=per_first] .chat-approval-control').click()");
|
||||
await eventually(() => page.evaluate("document.querySelectorAll('.chat-approval-pending').length===1"));
|
||||
await page.evaluate("document.querySelector('[data-request-id=per_second] .chat-approval-control:last-child').click()");
|
||||
await eventually(() => page.evaluate("document.querySelectorAll('.chat-approval-pending').length===0"));
|
||||
for(const id of ['form_first','form_second']) {
|
||||
await page.fill(`[data-form-id=${id}] .chat-question-input`,'Browser answer');
|
||||
await emit({message_id:'msg_answer',kind:'text',part:{id:'draft-check',type:'text',text:'unrelated frame'}});
|
||||
await eventually(() => page.evaluate(`document.querySelector('[data-form-id=${id}] .chat-question-input')?.value==='Browser answer'`));
|
||||
await page.evaluate(`document.querySelector('[data-form-id=${id}] .chat-question-submit').click()`);
|
||||
await eventually(() => page.evaluate(`!document.querySelector('[data-form-id=${id}]')`));
|
||||
}
|
||||
await eventually(() => page.evaluate("!document.querySelector('.chat-approval-jump')"));
|
||||
assert.deepEqual(await page.evaluate("window.__errors"), []);
|
||||
console.log("Model dialog, stable activity mark, keyboard/caret, Back restoration and send-to-bottom passed.");
|
||||
console.log("Model dialog, stable activity mark, keyboard/caret, Back restoration, send-to-bottom and all recovered approvals/questions passed.");
|
||||
} finally {
|
||||
await browser?.close();
|
||||
serve.kill("SIGTERM");
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { applyChatForm, applyChatPermission, chatApprovalCards, chatPendingForms } from '../src/chat.js';
|
||||
|
||||
test('parallel approvals stay independently actionable and resolve by identity',()=>{
|
||||
let thread={};
|
||||
for(const id of ['a','b']) thread=applyChatPermission(thread,{session_id:'s',request_id:id,action:'shell'});
|
||||
assert.deepEqual(chatApprovalCards(thread).map(c=>c.requestId),['a','b']);
|
||||
thread=applyChatPermission(thread,{session_id:'s',request_id:'a',resolved:true});
|
||||
assert.deepEqual(chatApprovalCards(thread).map(c=>c.requestId),['b']);
|
||||
thread=applyChatPermission(thread,{session_id:'s',request_id:'b',resolved:true});
|
||||
assert.deepEqual(chatApprovalCards(thread),[]);
|
||||
});
|
||||
|
||||
test('parallel questions survive replies and cancellation of a different question',()=>{
|
||||
let thread={};
|
||||
for(const id of ['a','b']) thread=applyChatForm(thread,{id,session_id:'s',fields:[]});
|
||||
assert.deepEqual(chatPendingForms(thread).map(f=>f.id),['a','b']);
|
||||
thread=applyChatForm(thread,{id:'a',resolved:true});
|
||||
assert.deepEqual(chatPendingForms(thread).map(f=>f.id),['b']);
|
||||
thread=applyChatForm(thread,{id:'b',cancelled:true});
|
||||
assert.deepEqual(chatPendingForms(thread),[]);
|
||||
});
|
||||
Reference in New Issue
Block a user