Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(chat): contain failure actions and preserve mobile select all (#2426)

Call Whitea92bca3d8e68
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index c2335755a..97da5efbb 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -90,6 +90,7 @@ jobs:
npm run test:badge-triggers
npm run test:workbench-general -- sidebar-floating.spec.ts desktop-window-chrome.spec.ts
npm run test:voice-shortcut
+ npm run test:chat-interactions
show-router-integration:
runs-on: ubuntu-latest
diff --git a/docs/plans/mobile-selection-toolbar-ios27.md b/docs/plans/mobile-selection-toolbar-ios27.md
index e4b75a836..6575d7dde 100644
--- a/docs/plans/mobile-selection-toolbar-ios27.md
+++ b/docs/plans/mobile-selection-toolbar-ios27.md
@@ -40,6 +40,17 @@ pointer ownership that is released only by those terminal events, so a withheld
not intersect either expanded endpoint handle region, or the candidate with
the smallest overlap when no fully safe slot exists.
+## Select-all touch completion
+
+Select all widens the DOM range during `pointerup`. The native `touchend` tap
+processing follows it; cancelling only `pointerdown` does not cancel that touch
+default. Consume `touchend` for a successfully activated toolbar button without
+holding or restoring the selection. Keep the receipt separate from the bounded
+press state, and clear it on touch completion or the next pointer gesture.
+Incomplete gestures retain their native defaults. The browser regression and
+physical-device limits are documented in
+[`ui/e2e/chat-interactions/README.md`](../../ui/e2e/chat-interactions/README.md).
+
## Validation
- Component tests simulate pointerdown without any terminal pointer event,
diff --git a/ui/e2e/chat-interactions/README.md b/ui/e2e/chat-interactions/README.md
new file mode 100644
index 000000000..884ccfb42
--- /dev/null
+++ b/ui/e2e/chat-interactions/README.md
@@ -0,0 +1,35 @@
+# Chat notice and selection interactions
+
+Run `npm run test:chat-interactions` in `ui/` after installing the Playwright
+Chromium and WebKit browsers. CI runs this suite in `lint / ui-checks`.
+
+## Change contract
+
+- The failure notice's Copy record button is on its own line below the turn ID,
+ wholly inside the bubble. A long ID wraps instead of creating overflow.
+- A completed toolbar touch consumes the trailing `touchend` default action,
+ so native tap processing cannot undo Select all after `pointerup`. This is
+ not a selection lock: later clearing or selecting other text still works.
+- Desktop, keyboard, assistive clicks, incomplete gestures, and the bounded
+ missing-terminal-event recovery retain their existing behavior.
+
+## Evidence and ownership
+
+The fixture renders the real MessageRow, SelectionQuoteToolbar, Markdown, i18n,
+and CSS. Only message/provenance data is supplied. External requests, unknown
+API paths, and writes are refused; the dev server points at a dead backend.
+No live Avibe state, credentials, or user browser profile is used.
+
+- Browser layout tests cover 320/390/768px and both languages. The old row layout
+ fails the measured next-line assertion; jsdom cannot measure this contract.
+- Component tests own the touch completion contract, incomplete gesture and
+ subsequent clearing. The pre-fix handler leaves `touchend` uncancelled.
+- Native browser taps in Chromium and WebKit additionally verify React's real
+ listener is non-passive, and that the toolbar and full range survive past
+ the selection debounce. Desktop uses real mouse input.
+
+Headless WebKit is not a physical iOS PWA and does not reproduce its OS selection
+menu/gesture recognizer. A physical-device check is still needed: long-press a
+partial chat message, tap Select all, wait, copy/quote the full bubble, then
+select other text or clear the selection. No automated physical-device pass is
+claimed.
diff --git a/ui/e2e/chat-interactions/fixture.html b/ui/e2e/chat-interactions/fixture.html
new file mode 100644
index 000000000..68c0c2e9a
--- /dev/null
+++ b/ui/e2e/chat-interactions/fixture.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>Chat interactions fixture</title>
+ </head>
+ <body>
+ <div id="root"></div>
+ <script type="module" src="./fixture.tsx"></script>
+ </body>
+</html>
diff --git a/ui/e2e/chat-interactions/fixture.tsx b/ui/e2e/chat-interactions/fixture.tsx
new file mode 100644
index 000000000..97a561f51
--- /dev/null
+++ b/ui/e2e/chat-interactions/fixture.tsx
@@ -0,0 +1,47 @@
+import { useRef } from 'react';
+import { createRoot } from 'react-dom/client';
+import { MemoryRouter } from 'react-router-dom';
+
+import { MessageRow } from '../../src/components/workbench/ChatPage';
+import { SelectionQuoteToolbar } from '../../src/components/workbench/SelectionQuoteToolbar';
+import type { WorkbenchMessage, WorkbenchSession } from '../../src/context/ApiContext';
+import { InstanceAuthorizationContext } from '../../src/context/InstanceAuthorizationContext';
+import { ToastContext } from '../../src/context/ToastContext';
+import { DENIED_INSTANCE_CAPABILITIES } from '../../src/lib/sessionInfo';
+import '../../src/i18n';
+import '../../src/index.css';
+
+const session = { id: 'interaction-fixture', metadata: {} } as WorkbenchSession;
+const message = {
+ id: 'answer', session_id: session.id, author: 'agent', source: 'agent', type: 'result',
+ text: 'Use **bold 中文** now.\n\nSecond paragraph 🌱.', content: {}, metadata: {},
+} as WorkbenchMessage;
+const notice = {
+ ...message, id: 'notice', type: 'notify', text: 'Model connection interrupted.',
+ metadata: { event: 'backend_failure', failure_id: 'failure', turn_id: 'turn_0123456789abcdef0123456789abcdef' },
+} as WorkbenchMessage;
+const noop = () => {};
+
+export function Fixture() {
+ const containerRef = useRef<HTMLDivElement>(null);
+ const failure = new URLSearchParams(location.search).has('failure');
+ return (
+ <div ref={containerRef} className="h-dvh overflow-y-auto bg-background px-4 py-32 text-foreground">
+ <MessageRow message={failure ? notice : message} session={session} messageFontSize={14} />
+ <SelectionQuoteToolbar containerRef={containerRef} onQuote={noop} />
+ </div>
+ );
+}
+
+createRoot(document.getElementById('root')!).render(
+ <MemoryRouter>
+ <ToastContext.Provider value={{ showToast: noop }}>
+ <InstanceAuthorizationContext.Provider value={{
+ remote: false, instanceKind: 'personal', instanceRole: 'owner',
+ capabilities: { ...DENIED_INSTANCE_CAPABILITIES, can_manage_instance: true },
+ }}>
+ <Fixture />
+ </InstanceAuthorizationContext.Provider>
+ </ToastContext.Provider>
+ </MemoryRouter>,
+);
diff --git a/ui/e2e/chat-interactions/interactions.spec.ts b/ui/e2e/chat-interactions/interactions.spec.ts
new file mode 100644
index 000000000..079895130
--- /dev/null
+++ b/ui/e2e/chat-interactions/interactions.spec.ts
@@ -0,0 +1,73 @@
+import { expect, test } from '@playwright/test';
+
+const TURN = 'turn_0123456789abcdef0123456789abcdef';
+
+for (const lang of ['en', 'zh'] as const) {
+ test.describe(lang, () => {
+ test.beforeEach(async ({ page }) => {
+ await page.addInitScript((value) => localStorage.setItem('i18nextLng', value), lang);
+ await page.route('**/*', async (route) => {
+ const url = new URL(route.request().url());
+ if (url.origin !== 'http://127.0.0.1:5227' || route.request().method() !== 'GET') return route.abort();
+ if (url.pathname === `/api/models/turns/${TURN}/provenance`) {
+ return route.fulfill({ json: { provenance: {
+ contract_version: 1, turn_id: TURN, agent: 'codex', requested_model_id: 'fixture-model',
+ outcome: 'failed_terminal', failed_attempts: [], blockers: [],
+ terminal_error: { source_id: 'fixture-source', configured_model_id: 'fixture-model', reason: 'engine_down' },
+ } } });
+ }
+ if (url.pathname === '/api/models/sources') return route.fulfill({ json: { sources: [] } });
+ if (url.pathname.startsWith('/api/')) return route.abort();
+ return route.continue();
+ });
+ });
+
+ test('copy record is below the turn ID and inside the notice at narrow widths', async ({ page }) => {
+ for (const width of [320, 390, 768]) {
+ await page.setViewportSize({ width, height: 844 });
+ await page.goto('/e2e/chat-interactions/fixture.html?failure');
+ await page.getByRole('button', { name: lang === 'zh' ? '查看详情' : 'Show details' }).click();
+ const copy = page.getByRole('button', { name: lang === 'zh' ? '复制记录' : 'Copy record' });
+ const button = (await copy.boundingBox())!;
+ const turn = (await page.getByText(TURN, { exact: true }).boundingBox())!;
+ const bubble = (await page.locator('[data-message-id="notice"] .group\\/message > div').first().boundingBox())!;
+ expect(button.y).toBeGreaterThanOrEqual(turn.y + turn.height);
+ expect(button.x).toBeGreaterThanOrEqual(bubble.x);
+ expect(button.x + button.width).toBeLessThanOrEqual(bubble.x + bubble.width);
+ expect(button.y + button.height).toBeLessThanOrEqual(bubble.y + bubble.height);
+ expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(width);
+ }
+ });
+
+ test('select all survives the complete native tap and can still be dismissed', async ({ page }, testInfo) => {
+ await page.goto('/e2e/chat-interactions/fixture.html');
+ await page.locator('strong').evaluate((node) => {
+ const range = document.createRange();
+ range.selectNodeContents(node);
+ const selection = window.getSelection()!;
+ selection.removeAllRanges();
+ selection.addRange(range);
+ });
+ const selectAll = page.getByRole('button', { name: lang === 'zh' ? '全选' : 'Select all' });
+ await expect(selectAll).toBeVisible();
+ // Real React/DOM delivery is needed here: a passive touchend listener
+ // would appear correct in jsdom but fail to cancel the browser default.
+ await page.evaluate(() => document.addEventListener('touchend', (event) => {
+ document.body.dataset.touchEndConsumed = String(event.defaultPrevented);
+ }, { once: true }));
+ if (testInfo.project.use.hasTouch) {
+ await selectAll.tap();
+ await expect(page.locator('body')).toHaveAttribute('data-touch-end-consumed', 'true');
+ } else await selectAll.click();
+ // Inspect after the compatibility mouse/click events and the selection
+ // debounce, not just synchronously inside the pointerup handler.
+ await page.waitForTimeout(900);
+ expect(await page.evaluate(() => window.getSelection()?.toString())).toContain('Second paragraph 🌱.');
+ await expect(page.getByRole('toolbar')).toBeVisible();
+ // Headless touch browsers do not expose the OS selection menu/handles;
+ // clear through the Selection API to check that no sticky lock restores it.
+ await page.evaluate(() => window.getSelection()?.removeAllRanges());
+ await expect(page.getByRole('toolbar')).toBeHidden();
+ });
+ });
+}
diff --git a/ui/e2e/chat-interactions/tsconfig.json b/ui/e2e/chat-interactions/tsconfig.json
new file mode 100644
index 000000000..7f5ef816f
--- /dev/null
+++ b/ui/e2e/chat-interactions/tsconfig.json
@@ -0,0 +1,6 @@
+{
+ "extends": "../../tsconfig.app.json",
+ "compilerOptions": { "types": ["vite/client", "node"] },
+ "include": ["*.ts", "*.tsx", "../../playwright.chat-interactions.config.ts", "../../agentation.d.ts"],
+ "exclude": []
+}
diff --git a/ui/package.json b/ui/package.json
index c65ade9ef..49c2a6ccf 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -19,6 +19,7 @@
"test:crypto": "vitest run src/lib/vaultCrypto.test.ts",
"e2e": "playwright test",
"e2e:headed": "playwright test --headed",
+ "test:chat-interactions": "tsc -p e2e/chat-interactions/tsconfig.json --noEmit && playwright test --config playwright.chat-interactions.config.ts",
"test:chat-paging": "tsc -p e2e/chat-paging/tsconfig.json --noEmit && playwright test --config playwright.chat-paging.config.ts",
"test:citations": "tsc -p e2e/citations/tsconfig.json --noEmit && playwright test --config playwright.citations.config.ts",
"test:inbox-return": "tsc -p e2e/inbox-return/tsconfig.json --noEmit && playwright test --config playwright.inbox-return.config.ts",
diff --git a/ui/playwright.chat-interactions.config.ts b/ui/playwright.chat-interactions.config.ts
new file mode 100644
index 000000000..fbff6da3a
--- /dev/null
+++ b/ui/playwright.chat-interactions.config.ts
@@ -0,0 +1,20 @@
+import { defineConfig, devices } from '@playwright/test';
+
+// Real chat components and CSS, with all backend reads answered by the suite.
+export default defineConfig({
+ testDir: './e2e/chat-interactions',
+ outputDir: './e2e/.artifacts/chat-interactions',
+ workers: 1,
+ retries: 0,
+ use: { baseURL: 'http://127.0.0.1:5227', locale: 'en-US', trace: 'retain-on-failure' },
+ webServer: {
+ command: 'npm run dev -- --host 127.0.0.1 --port 5227 --strictPort',
+ env: { VIBE_UI_BACKEND: 'http://127.0.0.1:9' },
+ url: 'http://127.0.0.1:5227/e2e/chat-interactions/fixture.html',
+ },
+ projects: [
+ { name: 'chromium-touch', use: { ...devices['iPhone 13'], browserName: 'chromium' } },
+ { name: 'webkit-touch', use: { ...devices['iPhone 13'], browserName: 'webkit' } },
+ { name: 'desktop', use: { ...devices['Desktop Chrome'] } },
+ ],
+});
diff --git a/ui/src/components/workbench/FailureDetails.tsx b/ui/src/components/workbench/FailureDetails.tsx
index 96015376c..0e13c5477 100644
--- a/ui/src/components/workbench/FailureDetails.tsx
+++ b/ui/src/components/workbench/FailureDetails.tsx
@@ -171,8 +171,8 @@ export function FailureDetails({ message }: { message: WorkbenchMessage }) {
</div>
)}
{upstreamFacts && <p className="text-gold-ink/70">{t('chat.failureDetails.upstreamNote')}</p>}
- <span className="flex items-center gap-2 text-gold-ink/70">
- <span className="font-mono">{record.turn_id}</span>
+ <span className="flex min-w-0 flex-col items-start gap-2 text-gold-ink/70">
+ <span className="max-w-full break-all font-mono">{record.turn_id}</span>
<CopyButton value={JSON.stringify(record, null, 2)} label={t('chat.failureDetails.copyRecord') as string} />
</span>
</div>
diff --git a/ui/src/components/workbench/SelectionQuoteToolbar.test.tsx b/ui/src/components/workbench/SelectionQuoteToolbar.test.tsx
index 940d1e66b..83f0788a8 100644
--- a/ui/src/components/workbench/SelectionQuoteToolbar.test.tsx
+++ b/ui/src/components/workbench/SelectionQuoteToolbar.test.tsx
@@ -254,6 +254,43 @@ describe('chat selection action gesture lifetime', () => {
expect(writeText).toHaveBeenCalledExactlyOnceWith(content);
});
+ it('consumes the touchend default after Select all without relying on pointerdown cancellation', () => {
+ const container = mountBubble();
+ const range = document.createRange();
+ range.selectNodeContents(container.querySelector('strong')!);
+ window.getSelection()!.addRange(range);
+ settle();
+
+ const button = screen.getByRole('button', { name: 'chat.selection.selectAll' });
+ fireEvent.pointerDown(button, press);
+ fireEvent.touchStart(button);
+ fireEvent.pointerUp(button, press);
+ // iOS processes the native tap after pointerup. Pointerdown.preventDefault
+ // suppresses compatibility mouse events, not this touchend default action.
+ const end = new Event('touchend', { bubbles: true, cancelable: true });
+ fireEvent(button, end);
+ expect(end.defaultPrevented).toBe(true);
+ settle();
+ expect(window.getSelection()!.toString()).toBe('Use bold now');
+ expect(screen.queryByRole('toolbar')).not.toBeNull();
+
+ // No sticky selection lock: a later user gesture may clear it normally.
+ fireEvent.pointerDown(container, press);
+ clearSelection();
+ expect(screen.queryByRole('toolbar')).toBeNull();
+ });
+
+ it('does not consume touchend for an unactivated toolbar gesture', () => {
+ mountToolbar();
+ const button = screen.getByRole('button', { name: 'chat.selection.quote' });
+ fireEvent.pointerDown(button, press);
+ fireEvent.pointerUp(button, { ...press, clientX: 500 });
+ const end = new Event('touchend', { bubbles: true, cancelable: true });
+ fireEvent(button, end);
+ expect(end.defaultPrevented).toBe(false);
+ expect(quote).not.toHaveBeenCalled();
+ });
+
it('leaves a selection made after Copy in place', async () => {
const container = mountToolbar();
await act(async () => {
diff --git a/ui/src/components/workbench/SelectionQuoteToolbar.tsx b/ui/src/components/workbench/SelectionQuoteToolbar.tsx
index aa4e06b55..d3f60aa6f 100644
--- a/ui/src/components/workbench/SelectionQuoteToolbar.tsx
+++ b/ui/src/components/workbench/SelectionQuoteToolbar.tsx
@@ -86,6 +86,9 @@ export const SelectionQuoteToolbar: React.FC<{
} | null>(null);
const pressExpiryRef = useRef<number | null>(null);
const activatedAtRef = useRef(Number.NEGATIVE_INFINITY);
+ // A receipt for the touch action already run on pointerup, not a selection
+ // lock. Only its trailing touchend is consumed; a new gesture clears it.
+ const touchActivationRef = useRef<HTMLButtonElement | null>(null);
const [width, setWidth] = useState(0);
const [height, setHeight] = useState(TOOLBAR_H);
// Touch (coarse pointer — phones AND tablets/iPads) is where the OS selection
@@ -163,6 +166,7 @@ export const SelectionQuoteToolbar: React.FC<{
const onPointerDown = () => {
// A new gesture invalidates any prior button press, including one whose
// terminal event was delivered outside the toolbar or not delivered at all.
+ touchActivationRef.current = null;
clearPress();
};
const onSelectionChange = () => {
@@ -292,8 +296,16 @@ export const SelectionQuoteToolbar: React.FC<{
return;
}
activatedAtRef.current = e.timeStamp;
+ touchActivationRef.current = e.pointerType === 'touch' ? e.currentTarget : null;
run();
};
+ const handleTouchEnd = (e: React.TouchEvent) => {
+ // iOS's native tap processing follows pointerup and can clear the range we
+ // just widened. Cancelling pointerdown only suppresses compatibility mouse
+ // events; consume this touch default too, but only for a completed action.
+ if (touchActivationRef.current?.contains(e.target as Node)) e.preventDefault();
+ touchActivationRef.current = null;
+ };
const handleKeyDown = (e: React.KeyboardEvent, run: () => void) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
@@ -383,6 +395,7 @@ export const SelectionQuoteToolbar: React.FC<{
<div
ref={toolbarRef}
role="toolbar"
+ onTouchEnd={handleTouchEnd}
style={{ position: 'fixed', top, left, maxWidth: 'calc(100vw - 16px)', transform: 'translateX(-50%)', zIndex: 60 }}
className="flex items-center overflow-x-auto rounded-lg border border-border-strong bg-surface-2 shadow-[0_12px_30px_-8px_rgba(0,0,0,0.7)]"
>