Repository navigation
fix(chat): decouple optional terminal fallback and bound chat reads #791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
devswha
merged 11 commits into
devswha:main
from
kilhyeonjun:fix/chat-read-fallback-20261011
Oct 11, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
22f707b
fix(chat): decouple optional terminal fallback and bound chat reads
kilhyeonjun a1ff9a3
fix(chat): clarify fallback state and announce terminal errors
kilhyeonjun dd27a07
fix(chat): no empty-chat hint behind the terminal disclosure, alert o…
devswha 0b08673
Merge remote-tracking branch 'origin/main' into pr-791-fix
devswha b4df847
test(ci): count the browser lane's row from main's merged script
devswha eb84aba
Merge PR #791 head a1ff9a39 into pr-791-fix
devswha 992aae6
fix(chat): give remote-PC chat reads a 30-second deadline
devswha 245ae09
docs: drop the terminal fallback notes and screenshot added by this PR
devswha fb3ef77
Merge remote-tracking branch 'origin/main' into pr-791-sync
devswha eb9489c
fix: address review threads
devswha a0f8dc7
Merge remote-tracking branch 'origin/main' into pr-791-sync
devswha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /** Real ChatView with an unavailable conversation and a stalled optional terminal. */ | ||
| import assert from "node:assert/strict"; | ||
| import { mkdtempSync, mkdirSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { chromium } from "playwright-core"; | ||
| import { build as viteBuild } from "vite"; | ||
| import { CONTENT_SECURITY_POLICY } from "../server/static.ts"; | ||
| const root = realpathSync(mkdtempSync(join(tmpdir(), "herdr-chat-fallback-"))); | ||
| let browser: Awaited<ReturnType<typeof chromium.launch>> | undefined; | ||
| let server: ReturnType<typeof Bun.serve> | undefined; | ||
| try { | ||
| const repo = join(import.meta.dir, ".."), output = join(root, "dist"); | ||
| symlinkSync(join(repo, "node_modules"), join(root, "node_modules"), "dir"); | ||
| symlinkSync(join(repo, "scripts/chat-fallback-fixture.tsx"), join(root, "fixture.tsx")); | ||
| writeFileSync(join(root, "index.html"), '<html><head><meta name="viewport" content="width=device-width,initial-scale=1"></head><body><div id="root"></div><script type="module" src="/fixture.tsx"></script></body></html>'); | ||
| await viteBuild({ configFile: join(repo, "vite.config.ts"), root, publicDir: false, logLevel: "warn", build: { outDir: output, emptyOutDir: true } }); | ||
| const terminalReads: string[] = []; | ||
| let structured = false, resolveAgent!: () => void, agentReadArrived!: () => void; | ||
| // resolved by the server's handler: a browser-side waitForRequest can win the race against it | ||
| const agentRead = new Promise<void>((resolve) => { agentReadArrived = resolve; }); | ||
| server = Bun.serve({ hostname: "127.0.0.1", port: 0, fetch(request) { | ||
| const url = new URL(request.url), pane = url.searchParams.get("pane_id"); | ||
| if (url.pathname === "/api/pane/prompt") return Response.json({ prompt: null }); | ||
| if (url.pathname === "/api/pane/conversation") return Response.json({ source: (structured && pane === "agent") || pane === "empty" ? "codex-transcript" : "scrollback", cursor: null, turns: structured && pane === "agent" ? [{ role: "assistant", ts: null, parts: [{ kind: "text", text: "Structured conversation arrived" }] }] : [] }); | ||
| if (url.pathname === "/api/pane/read") { | ||
| terminalReads.push(pane ?? ""); | ||
| if (pane === "error") return Response.json({ error: { code: "read_failed", message: "Terminal output unavailable" } }, { status: 500 }); | ||
| const response = () => Response.json({ read: { text: pane === "shell" ? "Shell inline output" : "OLD AGENT TERMINAL", truncated: false } }); | ||
| if (pane === "agent") return new Promise<Response>((resolve) => { resolveAgent = () => resolve(response()); agentReadArrived(); }); | ||
| return response(); | ||
| } | ||
| if (url.pathname === "/favicon.ico") return new Response(null, { status: 204 }); | ||
| return new Response(Bun.file(join(output, url.pathname === "/" ? "index.html" : url.pathname.slice(1))), { headers: { "content-security-policy": CONTENT_SECURITY_POLICY } }); | ||
| } }); | ||
| browser = await chromium.launch({ executablePath: process.env.CHROME_PATH ?? "/opt/google/chrome/chrome", headless: true, args: ["--no-sandbox"] }); | ||
| const page = await browser.newPage(); page.setDefaultTimeout(10_000); | ||
| await page.addInitScript(() => localStorage.setItem("herdr-web-ui:settings", JSON.stringify({ language: "en" }))); | ||
| const errors: string[] = []; | ||
| page.on("pageerror", (error) => errors.push(error.message)); | ||
| await page.goto(`http://127.0.0.1:${server.port}`); | ||
| const summary = page.locator(".chat-terminal-fallback summary"); | ||
| await summary.waitFor(); | ||
| await page.getByText("Loading conversation…", { exact: true }).waitFor({ state: "detached" }); | ||
| assert.equal(terminalReads.length, 0, "a hidden terminal read cannot hold the initial chat"); | ||
| assert.equal(await page.locator(".chat-empty").count(), 0, "an agent terminal fallback does not claim the conversation is empty"); | ||
| if (process.env.UI_EVIDENCE_DIR) { | ||
| mkdirSync(process.env.UI_EVIDENCE_DIR, { recursive: true }); | ||
| await page.screenshot({ path: join(process.env.UI_EVIDENCE_DIR, "terminal-fallback-closed.png") }); | ||
| } | ||
| await summary.click(); | ||
| let deadline: ReturnType<typeof setTimeout> | undefined; | ||
| await Promise.race([agentRead, new Promise<never>((_, reject) => { deadline = setTimeout(() => reject(new Error("opening the disclosure never read the agent terminal")), 10_000); })]); | ||
| clearTimeout(deadline); | ||
| assert.ok(terminalReads.includes("agent")); | ||
| structured = true; | ||
| await page.evaluate(() => window.chatFallbackQA.refresh()); | ||
| await page.getByText("Structured conversation arrived", { exact: true }).waitFor(); | ||
| const nextKindRead = page.waitForRequest((request) => new URL(request.url()).pathname === "/api/pane/conversation", { timeout: 3_000 }); | ||
| await page.evaluate(() => window.chatFallbackQA.agent("claude")); | ||
| await nextKindRead; | ||
| resolveAgent(); | ||
| await page.locator(".chat-terminal-fallback").waitFor({ state: "detached" }); | ||
| assert.ok(!(await page.locator("body").innerText()).includes("OLD AGENT TERMINAL")); | ||
| await page.evaluate(() => window.chatFallbackQA.pane("shell")); | ||
| await page.getByText("Shell inline output", { exact: true }).waitFor(); | ||
| assert.ok(terminalReads.includes("shell"), "non-agent scrollback remains inline"); | ||
| await page.evaluate(() => window.chatFallbackQA.pane("error")); | ||
| await summary.waitFor(); | ||
| await summary.click(); | ||
| const fallbackError = page.getByText("Terminal output unavailable"); | ||
| await fallbackError.waitFor(); | ||
| assert.equal(await fallbackError.getAttribute("role"), "alert", "terminal-read failures are announced as errors"); | ||
| assert.equal(await page.locator(".chat-empty").count(), 0, "a fallback failure is not an empty structured conversation"); | ||
| await page.evaluate(() => window.chatFallbackQA.pane("empty")); | ||
| await page.getByText("No conversation yet — say something below", { exact: true }).waitFor(); | ||
| assert.equal(await page.locator(".chat-terminal-fallback").count(), 0, "an empty structured conversation keeps its ordinary prompt"); | ||
| assert.deepEqual(errors, []); | ||
| console.log("chat fallback: browser OK (no hidden terminal reads, opened stalled output cannot block structured refresh, late cleanup, non-agent inline output, fallback error announcement and accurate empty state)"); | ||
|
|
||
| } finally { | ||
| await browser?.close(); server?.stop(true); rmSync(root, { recursive: true, force: true }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import React, { useState } from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import "../src/styles.css"; | ||
| import { ChatView } from "../src/components/ChatView.tsx"; | ||
| import { SettingsProvider } from "../src/lib/settings.ts"; | ||
| declare global { interface Window { chatFallbackQA: { pane: (pane: string) => void; refresh: () => void; agent: (agent: string | null) => void } } } | ||
| function Fixture() { | ||
| const [agent, setAgent] = useState<string | null>("codex"); | ||
| const [pane, setPane] = useState("agent"); | ||
| const [refresh, setRefresh] = useState(0); | ||
| window.chatFallbackQA = { pane: setPane, agent: setAgent, refresh: () => setRefresh((key) => key + 1) }; | ||
| return <main style={{ height: "100vh" }}><ChatView key={pane} paneId={pane} refreshKey={refresh} connected ended={false} agent={pane === "shell" ? null : agent} /></main>; | ||
| } | ||
| createRoot(document.getElementById("root")!).render(<React.StrictMode><SettingsProvider><Fixture /></SettingsProvider></React.StrictMode>); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.