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(ui): show a running turn's Vault key request immediately (#2282)

Call White4a9154bc93d4
diff --git a/ui/src/components/ui/vault-chat-requests.test.tsx b/ui/src/components/ui/vault-chat-requests.test.tsx
index 13fd35be4..e2cb1a9e0 100644
--- a/ui/src/components/ui/vault-chat-requests.test.tsx
+++ b/ui/src/components/ui/vault-chat-requests.test.tsx
@@ -1,6 +1,6 @@
// @vitest-environment jsdom
-import { cleanup, render, screen } from '@testing-library/react';
+import { act, cleanup, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import type { VaultRequest } from '@/context/ApiContext';
@@ -31,17 +31,37 @@ const request = (id: string, requestType: 'access' | 'provision'): VaultRequest
});
describe('VaultChatRequests', () => {
- afterEach(() => cleanup());
+ afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+ });
- it('keeps provision forms out of the transcript footer', () => {
+ it('renders the given provision forms but reports only approvals off-screen', () => {
+ const observed: Element[] = [];
+ let notify: (entries: Partial<IntersectionObserverEntry>[]) => void = () => {};
+ vi.stubGlobal('IntersectionObserver', class {
+ constructor(callback: (entries: Partial<IntersectionObserverEntry>[]) => void) {
+ notify = callback;
+ }
+ observe(element: Element) {
+ observed.push(element);
+ }
+ disconnect() {}
+ });
+ const onOffscreen = vi.fn();
render(
<VaultChatRequests
requests={[request('provision', 'provision'), request('approval', 'access')]}
onResolved={vi.fn()}
+ onOffscreenApprovalsChange={onOffscreen}
/>,
);
- expect(screen.queryByTestId('request-card-provision')).toBeNull();
+ expect(screen.getByTestId('request-card-provision')).toBeTruthy();
expect(screen.getByTestId('request-card-approval')).toBeTruthy();
+ expect(observed.map((element) => (element as HTMLElement).dataset.requestId)).toEqual(['approval']);
+
+ act(() => notify(observed.map((target) => ({ target, isIntersecting: false }))));
+ expect(onOffscreen.mock.lastCall?.[0].map((item: VaultRequest) => item.id)).toEqual(['approval']);
});
});
diff --git a/ui/src/components/ui/vault-chat-requests.tsx b/ui/src/components/ui/vault-chat-requests.tsx
index 8eb9bee5f..c4833ef4f 100644
--- a/ui/src/components/ui/vault-chat-requests.tsx
+++ b/ui/src/components/ui/vault-chat-requests.tsx
@@ -4,27 +4,24 @@ import { useTranslation } from 'react-i18next';
import { cn } from '@/lib/utils';
import type { VaultRequest } from '@/context/ApiContext';
+import { isVaultApprovalRequest } from '@/lib/vaultRequestPlacement';
import { buttonVariants } from './button-variants';
import { VaultApprovalDialog } from './vault-approval-dialog';
import { VaultRequestCard } from './vault-request-card';
-const isApproval = (request: VaultRequest): boolean => {
- const type = (request.card as { request_type?: string } | null)?.request_type ?? request.request_type;
- return type === 'access' || type === 'sign';
-};
-
/**
- * In-scroll list of a session's pending approval cards (design: Form A), rendered at the end of
- * the chat transcript. Presentational — data comes from `usePendingVaultRequests`. Each card is
- * observed individually so the floating bar reflects exactly which approvals have scrolled
- * off-viewport.
+ * In-scroll list of the pending request cards that belong at the end of the chat transcript
+ * (design: Form A): approvals, plus provision forms still waiting for their turn's reply. The
+ * caller decides which requests belong here. Each APPROVAL card is observed individually so the
+ * floating bar reflects exactly which approvals have scrolled off-viewport; a provision form
+ * never enters that bar.
*/
export const VaultChatRequests: React.FC<{
requests: VaultRequest[];
onResolved: () => void;
onOffscreenApprovalsChange?: (offscreen: VaultRequest[]) => void;
}> = ({ requests, onResolved, onOffscreenApprovalsChange }) => {
- const approvalRequests = useMemo(() => requests.filter(isApproval), [requests]);
+ const approvalRequests = useMemo(() => requests.filter(isVaultApprovalRequest), [requests]);
const cardRefs = useRef<Map<string, HTMLElement>>(new Map());
const offscreen = useRef<Set<string>>(new Set());
@@ -58,17 +55,21 @@ export const VaultChatRequests: React.FC<{
report();
}, [approvalRequests, report]);
- if (approvalRequests.length === 0) return null;
+ if (requests.length === 0) return null;
return (
<div className="flex flex-col gap-2">
- {approvalRequests.map((request) => (
+ {requests.map((request) => (
<div
key={request.id}
data-request-id={request.id}
- ref={(el) => {
- if (el) cardRefs.current.set(request.id, el);
- else cardRefs.current.delete(request.id);
- }}
+ ref={
+ isVaultApprovalRequest(request)
+ ? (el) => {
+ if (el) cardRefs.current.set(request.id, el);
+ else cardRefs.current.delete(request.id);
+ }
+ : undefined
+ }
>
<VaultRequestCard request={request} onResolved={onResolved} />
</div>
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index b32c2d785..7ba6676df 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -550,10 +550,11 @@ export const ChatPage: React.FC = () => {
() => placeVaultProvisionRequests(messages, vaultRequests),
[messages, vaultRequests],
);
- // Provision cards belong beside the Agent reply that owns them. Requests whose
- // owning message is outside the retained window stay unanchored here; they are
- // intentionally not moved into the transcript footer, so opening a Session
- // never turns a historical form into a bottom-fixed card or a scroll target.
+ // Provision cards belong beside the Agent reply that owns them. Only a request
+ // from the latest turn that no reply has claimed yet (typically one the running
+ // Agent just made) waits in the transcript footer. Requests whose owner is
+ // outside the retained window stay out of it, so opening a Session never turns
+ // a historical form into a bottom card.
// Mirror the latest messages into a ref (updated every render) so effects that
// must NOT re-run on every message change — chiefly the deep-link jump effect,
// whose around-fetch would otherwise be cancelled by an SSE/reconcile update —
@@ -589,10 +590,18 @@ export const ChatPage: React.FC = () => {
// detaching the tail while the reader is scrolled up (see MAX_RETAINED_MESSAGES).
// Suppresses live append/reconcile and shows the jump-to-latest button, which
// reloads the tail. Consumers: the SSE-append skip, reconcile skip, the
- // send-path reloadLatest, and the inbox mark-read gate.
+ // send-path reloadLatest, the inbox mark-read gate, and the Vault footer.
const [historicalWindow, setHistoricalWindow] = useState(false);
const historicalWindowRef = useRef(false);
historicalWindowRef.current = historicalWindow;
+ // The transcript footer holds every pending approval plus the provision forms
+ // still awaiting a reply. A detached window's end is not the live tail.
+ const footerVaultRequests = useMemo(() => {
+ const waiting = new Set(
+ historicalWindow ? [] : provisionPlacement.awaitingReply.map((request) => request.id),
+ );
+ return vaultRequests.filter((request) => isVaultApprovalRequest(request) || waiting.has(request.id));
+ }, [historicalWindow, provisionPlacement, vaultRequests]);
// Realtime dictation context: the body of the latest Agent reply in this chat,
// without Avibe's generated footer. A result row is persisted whole, so a
// running Turn still reads the previous reply. A window detached from the live
@@ -3013,7 +3022,7 @@ export const ChatPage: React.FC = () => {
// approve/deny buttons would write to a session that can't accept it.
sessionId && !readOnly && capabilities.can_use_vault_secrets ? (
<VaultChatRequests
- requests={pendingApprovals}
+ requests={footerVaultRequests}
onResolved={refreshVaultRequests}
onOffscreenApprovalsChange={setOffscreenApprovals}
/>
diff --git a/ui/src/lib/vaultRequestPlacement.test.ts b/ui/src/lib/vaultRequestPlacement.test.ts
index 5197ce9b8..1298c2251 100644
--- a/ui/src/lib/vaultRequestPlacement.test.ts
+++ b/ui/src/lib/vaultRequestPlacement.test.ts
@@ -98,17 +98,17 @@ describe('placeVaultProvisionRequests', () => {
);
expect(placed.byMessageId.get('agent-later')?.map((item) => item.id)).toEqual(['p']);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
- it('keeps an unresolved explicit reply id unanchored', () => {
+ it('keeps an unresolved explicit reply id out of the transcript', () => {
const placed = placeVaultProvisionRequests(
[message('unrelated-reply', '2026-07-30T10:01:00Z')],
[request('missing-reply', 'provision', '2026-07-30T10:00:00Z', 'trimmed-reply')],
);
expect(placed.byMessageId).toEqual(new Map());
- expect(placed.unanchored.map((item) => item.id)).toEqual(['missing-reply']);
+ expect(placed.awaitingReply).toEqual([]);
});
it('anchors legacy requests to the first Agent reply after creation', () => {
@@ -129,7 +129,7 @@ describe('placeVaultProvisionRequests', () => {
);
expect(placed.byMessageId.get(output.id)?.map((item) => item.id)).toEqual(['p']);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
it('skips interim narration when inferring the request owner', () => {
@@ -181,7 +181,7 @@ describe('placeVaultProvisionRequests', () => {
);
expect(placed.byMessageId.get(detached.id)?.map((item) => item.id)).toEqual(['p']);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
it('uses the message id clock when the reply shares the request second', () => {
@@ -194,7 +194,7 @@ describe('placeVaultProvisionRequests', () => {
]);
expect(placed.byMessageId.get(sameSecondMessages[1].id)?.map((item) => item.id)).toEqual(['p']);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
it('does not round a request back onto an earlier reply in the same millisecond', () => {
@@ -207,7 +207,7 @@ describe('placeVaultProvisionRequests', () => {
expect(placed.byMessageId.has(earlierReply.id)).toBe(false);
expect(placed.byMessageId.get(ownerReply.id)?.map((item) => item.id)).toEqual(['p']);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
it('does not cross a later user or harness input-turn boundary', () => {
@@ -221,7 +221,7 @@ describe('placeVaultProvisionRequests', () => {
]);
expect([...placed.byMessageId]).toEqual([]);
- expect(placed.unanchored.map((item) => item.id)).toEqual([`p-${boundaryKind}`]);
+ expect(placed.awaitingReply).toEqual([]);
}
});
@@ -246,7 +246,7 @@ describe('placeVaultProvisionRequests', () => {
);
expect(placed.byMessageId.get(reply.id)?.map((item) => item.id)).toEqual(['late']);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
it('resolves a native requester message id to its durable transcript row', () => {
@@ -258,7 +258,7 @@ describe('placeVaultProvisionRequests', () => {
);
expect(placed.byMessageId.get(reply.id)?.map((item) => item.id)).toEqual(['native-late']);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
it('scopes native requester matching to the originating platform', () => {
@@ -284,7 +284,7 @@ describe('placeVaultProvisionRequests', () => {
expect(placed.byMessageId.get(slackReply.id)?.map((item) => item.id)).toEqual(['native-platform']);
expect(placed.byMessageId.has(webReply.id)).toBe(false);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
it('uses a resolved durable source override for stable turn identities', () => {
@@ -297,7 +297,7 @@ describe('placeVaultProvisionRequests', () => {
);
expect(placed.byMessageId.get(reply.id)?.map((item) => item.id)).toEqual(['turn-late']);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
it('does not cross a later input when resolving from the requester message', () => {
@@ -310,7 +310,9 @@ describe('placeVaultProvisionRequests', () => {
);
expect([...placed.byMessageId]).toEqual([]);
- expect(placed.unanchored.map((item) => item.id)).toEqual(['late']);
+ // Created after the latest turn's reply: the newest pending state, so it
+ // waits at the tail rather than borrowing that unrelated reply.
+ expect(placed.awaitingReply.map((item) => item.id)).toEqual(['late']);
});
it('does not timestamp-place an unresolved explicit source onto another turn', () => {
@@ -321,7 +323,7 @@ describe('placeVaultProvisionRequests', () => {
);
expect([...placed.byMessageId]).toEqual([]);
- expect(placed.unanchored.map((item) => item.id)).toEqual(['missing-source']);
+ expect(placed.awaitingReply).toEqual([]);
});
it('keeps a delayed reply when the next input arrives after request creation', () => {
@@ -336,7 +338,7 @@ describe('placeVaultProvisionRequests', () => {
expect(placed.byMessageId.get(reply.id)?.map((item) => item.id)).toEqual(['late']);
expect(placed.byMessageId.has(unrelatedReply.id)).toBe(false);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
it('uses transcript time for queued source-turn boundaries', () => {
@@ -356,7 +358,7 @@ describe('placeVaultProvisionRequests', () => {
expect(placed.byMessageId.get(ownerReply.id)?.map((item) => item.id)).toEqual(['late']);
expect(placed.byMessageId.has(unrelatedReply.id)).toBe(false);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
it('ignores a stale requester message when a later turn owns the request', () => {
@@ -371,7 +373,7 @@ describe('placeVaultProvisionRequests', () => {
expect(placed.byMessageId.get(actualReply.id)?.map((item) => item.id)).toEqual(['late']);
expect(placed.byMessageId.has(oldReply.id)).toBe(false);
- expect(placed.unanchored).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
it('keeps approvals out of message placement and leaves unmatched provisions visible', () => {
@@ -381,7 +383,7 @@ describe('placeVaultProvisionRequests', () => {
]);
expect([...placed.byMessageId]).toEqual([]);
- expect(placed.unanchored.map((item) => item.id)).toEqual(['future']);
+ expect(placed.awaitingReply.map((item) => item.id)).toEqual(['future']);
});
it('does not attach a request whose owning reply may be outside the retained window', () => {
@@ -391,7 +393,7 @@ describe('placeVaultProvisionRequests', () => {
);
expect([...placed.byMessageId]).toEqual([]);
- expect(placed.unanchored.map((item) => item.id)).toEqual(['older']);
+ expect(placed.awaitingReply).toEqual([]);
});
it('uses transcript-entry time when a queued row was accepted after the request', () => {
@@ -408,6 +410,38 @@ describe('placeVaultProvisionRequests', () => {
);
expect([...placed.byMessageId]).toEqual([]);
- expect(placed.unanchored.map((item) => item.id)).toEqual(['trimmed']);
+ expect(placed.awaitingReply).toEqual([]);
+ });
+
+ it('shows a running turn request at the tail until its reply lands', () => {
+ const source = message('source-user', '2026-07-30T10:00:00Z', 'user');
+ const interim = { ...message('agent-interim', '2026-07-30T10:01:30Z'), type: 'interim' };
+ const live = request('live', 'provision', '2026-07-30T10:01:00Z', null, { turn_id: 'turn-live' });
+
+ const running = placeVaultProvisionRequests([source, interim], [live]);
+ expect([...running.byMessageId]).toEqual([]);
+ expect(running.awaitingReply.map((item) => item.id)).toEqual(['live']);
+
+ const reply = { ...message('owner-reply', '2026-07-30T10:02:00Z'), metadata: { turn_id: 'turn-live' } };
+ const settled = placeVaultProvisionRequests([source, interim, reply], [live]);
+ expect(settled.byMessageId.get(reply.id)?.map((item) => item.id)).toEqual(['live']);
+ expect(settled.awaitingReply).toEqual([]);
+ });
+
+ it('stops waiting at the tail once a later input starts another turn', () => {
+ const source = message('source-user', '2026-07-30T10:00:00Z', 'user');
+ const queuedInput = message(
+ 'queued-input',
+ '2026-07-30T10:00:30Z',
+ 'user',
+ '2026-07-30T10:02:00Z',
+ );
+ const placed = placeVaultProvisionRequests(
+ [source, queuedInput],
+ [request('superseded', 'provision', '2026-07-30T10:01:00Z')],
+ );
+
+ expect([...placed.byMessageId]).toEqual([]);
+ expect(placed.awaitingReply).toEqual([]);
});
});
diff --git a/ui/src/lib/vaultRequestPlacement.ts b/ui/src/lib/vaultRequestPlacement.ts
index 8ce592952..22e6cdbf5 100644
--- a/ui/src/lib/vaultRequestPlacement.ts
+++ b/ui/src/lib/vaultRequestPlacement.ts
@@ -19,7 +19,8 @@ export function isVaultApprovalRequest(request: VaultRequest): boolean {
export type VaultProvisionPlacement = {
byMessageId: Map<string, VaultRequest[]>;
- unanchored: VaultRequest[];
+ /** Requests of the transcript's latest turn whose owning reply has not landed. */
+ awaitingReply: VaultRequest[];
};
function isAgentReplyWithExplicitProvenance(message: WorkbenchMessage): boolean {
@@ -100,6 +101,14 @@ function inferReplyWithinTurn(
return undefined;
}
+// Either clock counts: a queued input can be authored before the request and
+// still enter the transcript after it, starting the next turn.
+function inputFollowsRequest(messages: WorkbenchMessage[], requestTime: number): boolean {
+ return messages.some((message) => isInputTurn(message) && (
+ messageOrderTimeMs(message) >= requestTime || transcriptOrderTimeMs(message) >= requestTime
+ ));
+}
+
function inferReplyFromSourceMessage(
messages: WorkbenchMessage[],
sourceMessageId: string,
@@ -140,8 +149,9 @@ function inferReplyFromSourceMessage(
*
* Newer producers can set `message_id` explicitly. Historical CLI-created rows
* do not, so use the session's serialized turn order: the first Agent-authored
- * message created after the request is the reply that owns it. Requests without
- * either anchor remain visible at the transcript tail until a reply arrives.
+ * message created after the request is the reply that owns it. A request made
+ * during a turn that is still running has no owner yet; it waits at the
+ * transcript tail until its reply arrives or another input starts a new turn.
*/
export function placeVaultProvisionRequests(
messages: WorkbenchMessage[],
@@ -149,7 +159,7 @@ export function placeVaultProvisionRequests(
sourceMessageIds: ReadonlyMap<string, string> = new Map(),
): VaultProvisionPlacement {
const byMessageId = new Map<string, VaultRequest[]>();
- const unanchored: VaultRequest[] = [];
+ const awaitingReply: VaultRequest[] = [];
const messagesById = new Map(messages.map((message) => [message.id, message]));
const agentMessages = messages.filter(isAgentReplyWithExplicitProvenance);
// Window coverage follows transcript-entry order. A queued row can be authored
@@ -200,9 +210,21 @@ export function placeVaultProvisionRequests(
?? (sourceUnresolved || Number.isNaN(requestTime) || !windowCoversRequest
? undefined
: inferReplyWithinTurn(messages, requestTime));
- if (inferred) appendRequest(byMessageId, inferred.id, request);
- else unanchored.push(request);
+ if (inferred) {
+ appendRequest(byMessageId, inferred.id, request);
+ continue;
+ }
+ // Without an owner, only a request from the latest loaded turn belongs at the
+ // tail. A named but unloaded anchor, an uncovered window, or a later input
+ // means the request's turn has ended, so it must not sit below newer turns.
+ if (
+ !explicitReplyUnresolved && !sourceUnresolved &&
+ !Number.isNaN(requestTime) && windowCoversRequest &&
+ !inputFollowsRequest(messages, requestTime)
+ ) {
+ awaitingReply.push(request);
+ }
}
- return { byMessageId, unanchored };
+ return { byMessageId, awaitingReply };
}