Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(console): inspect retained call traces without a Window hash
  • Loading branch information
swjnxyf committed Sep 29, 2026
commit ccfcb8dc4673ebe41c5eed1b2f778a0da38a4326
6,332 changes: 3,182 additions & 3,150 deletions frontend/dist/admin.js

Large diffs are not rendered by default.

18,475 changes: 9,410 additions & 9,065 deletions frontend/dist/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/dist/styles.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions frontend/src/runtime-v2/api/traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export type TracePage = {
reason?: string;
error_kind?: string;
capture_mode?: string;
capture_health?: { scope: string; queue_drops: number; budget_drops: number; write_failures: number };
response_handoff_observed?: boolean;
trace_mode?: string;
coverage?: string;
events?: TraceEvent[];
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/runtime-v2/components/TraceCallDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function TraceCallPanel({ client, traceRef, language }: {
useEffect(() => { setPage(null); setEvents([]); setPayload(null); }, [client]);
const load = async (offset = 0) => {
const next = await request.read({ trace_ref: traceRef, offset, limit: 12 });
if (next === undefined) return; // Superseded/aborted reads cannot clear newer evidence.
if (!next) { setPage(null); setEvents([]); setPayload(null); return; }
setPage(next);
setEvents(previous => offset ? [...previous, ...(next.events || [])] : next.events || []);
Expand All @@ -46,6 +47,7 @@ function TraceCallPanel({ client, traceRef, language }: {
{request.error && <p role="alert">{t(request.error)}</p>}
{page?.status === "unavailable" && <p className="inventory-note">{t("Capture is not retained; it may be disabled, dropped, expired or evicted.")}</p>}
{page?.status === "available" && <p className="inventory-note">{t("Captured mode")}: {page.trace_mode} · {t("Current capture")}: {page.capture_mode}</p>}
{page?.capture_health && <details className="trace-event"><summary>{t("Capture health (process-wide)")}</summary><pre>{JSON.stringify(page.capture_health, null, 2)}</pre></details>}
{events.map((event, index) => <details key={index} className="trace-event" open={Boolean(event.diagnostic)}>
<summary>{event.phase || event.event || t("Event")}</summary>
<pre>{JSON.stringify(event.diagnostic ?? event, null, 2)}</pre>
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/runtime-v2/components/TraceSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import type { RuntimeLanguage } from "../../runtime_i18n.js";
import { translate } from "../../runtime_i18n.js";
import type { RuntimeV2Client } from "../api/client.js";
Expand All @@ -9,7 +9,7 @@ import { TraceCallDetails } from "./TraceCallDetails.js";

function localDate(value: number): string {
const date = new Date(value);
return new Date(value - date.getTimezoneOffset() * 60_000).toISOString().slice(0, 16);
return new Date(value - date.getTimezoneOffset() * 60_000).toISOString().slice(0, 19);
}

export function TraceSearch({ client, language, onSelectWindow }: {
Expand All @@ -24,6 +24,7 @@ export function TraceSearch({ client, language, onSelectWindow }: {
const [page, setPage] = useState<TracePage | null>(null);
const [invalid, setInvalid] = useState(false);
const request = useTraceRead(client);
useEffect(() => { setPage(null); }, [client]);
const search = async (query?: TraceQuery, offset = 0) => {
setInvalid(false);
const from = new Date(since).getTime(); const to = new Date(until).getTime();
Expand All @@ -43,8 +44,8 @@ export function TraceSearch({ client, language, onSelectWindow }: {
<form onSubmit={event => { event.preventDefault(); void search(); }}>
<label>{t("Exact Project ID")}<input value={project} onChange={event => setProject(event.target.value)} placeholder="agent:special:project" /></label>
<label>{t("Exact tool name")}<input value={tool} onChange={event => setTool(event.target.value)} placeholder="work_on_project" /></label>
<label>{t("From")}<input type="datetime-local" value={since} onChange={event => setSince(event.target.value)} /></label>
<label>{t("Until")}<input type="datetime-local" value={until} onChange={event => setUntil(event.target.value)} /></label>
<label>{t("From")}<input type="datetime-local" step="1" value={since} onChange={event => setSince(event.target.value)} /></label>
<label>{t("Until")}<input type="datetime-local" step="1" value={until} onChange={event => setUntil(event.target.value)} /></label>
<label className="trace-passive"><input type="checkbox" checked={includePassive} onChange={event => setIncludePassive(event.target.checked)} />{t("Include passive calls")}</label>
<button type="submit" className="text-button">{t("Search retained calls")}</button>
</form>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/runtime-v2/components/WindowActivityFeed.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { RuntimeV2Client } from "../api/client.js";
import { TraceCallDetails } from "./TraceCallDetails.js";
import { CopyIdentity } from "./ui/CopyIdentity.js";
import { displayProjectPath } from "../../ui/projectPresentation.js";
import type { RuntimeLanguage } from "../../runtime_i18n.js";
Expand All @@ -10,6 +12,7 @@ import {
} from "../model/windowSessions.js";

type Props = {
client?: RuntimeV2Client;
detail: WindowDetail;
projects: ProjectRow[];
language: RuntimeLanguage;
Expand All @@ -19,6 +22,7 @@ type Props = {
};

export function WindowActivityFeed({
client,
detail,
projects,
language,
Expand All @@ -38,6 +42,7 @@ export function WindowActivityFeed({
const calls = [
...detail.activity.map((row, index) => ({
key: row.server_trace_id || `completed-${row.started_at_ms}-${index}`,
traceRef: row.server_trace_id,
tool: row.tool_name || row.method,
project: row.project,
startedAt: row.started_at_ms,
Expand All @@ -53,6 +58,7 @@ export function WindowActivityFeed({
})),
...detail.active_requests.filter((row) => !completedTraces.has(row.server_trace_id)).map((row) => ({
key: row.server_trace_id,
traceRef: row.server_trace_id,
tool: row.tool_name || row.method,
project: row.project,
startedAt: row.started_at_ms,
Expand Down Expand Up @@ -192,6 +198,7 @@ export function WindowActivityFeed({
</>
)}
</div>
{client && call.traceRef && <TraceCallDetails client={client} traceRef={call.traceRef} language={language} />}
</article>
);
})}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/runtime-v2/components/WindowSessionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Props = {
};

export function WindowSessionPanel({
client,
detail,
projects,
language,
Expand All @@ -39,6 +40,7 @@ export function WindowSessionPanel({
return (
<section className="window-session-panel" aria-label={t("Work Sessions")}>
<WindowActivityFeed
client={client}
detail={detail}
projects={projects}
language={language}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/runtime-v2/components/WindowWorkbench.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { useWindowWorkspace } from "../state/useWindowWorkspace.js";
import { WorkSurfaceSwitch, type WorkSurface } from "./GoalWorkbench.js";
import { WindowCollaboration } from "./WindowCollaboration.js";
import { WindowActivityFeed } from "./WindowActivityFeed.js";
import { TraceSearch } from "./TraceSearch.js";


type Props = {
Expand Down Expand Up @@ -305,6 +306,7 @@ export function WindowWorkbench({
/>
</div>
<div className="work-list-scroll" ref={listRef}>
<TraceSearch client={client} language={language} onSelectWindow={windows.select} />
{selectedIsPinned && <div className="window-current-selection">
<div className="window-list-summary"><span>{t("Current Window")}</span></div>
{selectedNavigationRow ? renderWindow(selectedNavigationRow) : (
Expand Down Expand Up @@ -436,6 +438,7 @@ export function WindowWorkbench({
)}
{detail ? (
<WindowActivityFeed
client={client}
key={detail.client_window_key}
detail={detail}
projects={projects}
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/runtime-v2/state/useTraceRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export function useTraceRead(client: RuntimeV2Client) {
current.current?.abort();
current.current = null;
}, [client]);
const read = useCallback(async (request: TraceRequest): Promise<TracePage | null> => {
const read = useCallback(async (request: TraceRequest): Promise<TracePage | null | undefined> => {
current.current?.abort();
const controller = new AbortController();
current.current = controller;
setPending(true);
setError("");
try {
const response = await readTrace(client, request, controller.signal);
if (controller.signal.aborted || current.current !== controller) return null;
if (controller.signal.aborted || current.current !== controller) return undefined;
if (!response?.ok || !response.data) {
setError(response?.status === 403 ? "Administrator diagnostic access required" :
response?.status === 401 ? "Sign in to inspect diagnostics" :
Expand All @@ -33,7 +33,8 @@ export function useTraceRead(client: RuntimeV2Client) {
}
return response.data;
} catch {
if (!controller.signal.aborted && current.current === controller) setError("Diagnostics unavailable");
if (controller.signal.aborted || current.current !== controller) return undefined;
setError("Diagnostics unavailable");
return null;
} finally {
if (current.current === controller) {
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/runtime-v2/styles-trace.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.trace-search { padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 12px; min-width: 0; }
.trace-search > summary, .trace-event > summary { cursor: pointer; overflow-wrap: anywhere; }
.trace-search form { display: grid; gap: 8px; margin-block: 12px; }
.trace-search label { display: grid; gap: 4px; color: var(--muted); }
.trace-search input:not([type="checkbox"]) { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); }
.trace-search .trace-passive { display: flex; align-items: center; }
.trace-search-call { display: grid; gap: 5px; padding: 10px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.trace-search-call time, .trace-search-call small { color: var(--muted); }
.trace-call-details { margin-top: 6px; min-width: 0; }
.trace-call-details section { padding: 8px 0; min-width: 0; }
.trace-event { margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.trace-event pre { max-width: 100%; max-height: 32rem; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11px; line-height: 1.5; }
.trace-call-details button, .trace-search button { white-space: normal; text-align: start; }
1 change: 1 addition & 0 deletions frontend/src/runtime-v2/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "./styles-trace.css";
:root {
font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ui-text-primary);
Expand Down
32 changes: 32 additions & 0 deletions frontend/src/runtime_i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,38 @@ export type RuntimeLanguage = "en" | "zh-CN";
export const LANGUAGE_STORAGE_KEY = "webcodex.runtime.language.v1";

export const RUNTIME_ZH_TEXT: Record<string, string> = {
"Capture health (process-wide)": "捕获状态(本进程累计,不代表单次调用完整性)",
"Inspect call diagnostics": "查看调用诊断",
"Hide call diagnostics": "收起调用诊断",
"Call diagnostics": "调用诊断",
"Trace": "追踪标识",
"Observed Server evidence only; not proof of delivery or model reading.": "仅表示 Server 观察到的事实,不证明客户端收到或模型已阅读。",
"Refresh diagnostics": "刷新诊断",
"Loading diagnostics…": "正在加载诊断…",
"Administrator diagnostic access required": "需要管理员诊断权限",
"Sign in to inspect diagnostics": "请登录后查看诊断",
"Diagnostics unavailable": "诊断暂不可用",
"Capture is not retained; it may be disabled, dropped, expired or evicted.": "未保留捕获记录:可能未启用、写入丢弃、过期或被淘汰。",
"Captured mode": "捕获模式",
"Current capture": "当前捕获配置",
"Read retained full payload": "读取已保留的完整载荷",
"Retained full payload": "已保留的完整载荷",
"More trace events": "更多追踪事件",
"Diagnostic view limit reached. Use the exact trace reader for more.": "已达到页面显示上限,可通过精确追踪读取工具继续查看。",
"Find calls by time or Project": "按时间或项目查找调用",
"Administrator diagnostics. No Window hash is required. Queries run only on request.": "管理员诊断,无需事先知道窗口哈希;仅点击时查询。",
"Exact Project ID": "精确项目 ID",
"Exact tool name": "精确工具名称",
"From": "起始时间",
"Until": "截止时间",
"Include passive calls": "包含被动刷新与辅助调用",
"Search retained calls": "查询已保留调用",
"Choose an ordered time range of at most 31 days.": "请选择顺序正确且不超过 31 天的时间范围。",
"Showing retained calls in this page, not a complete Window history.": "这里只展示本页保留的调用,不是整个窗口的完整历史。",
"Open Window": "打开窗口",
"Window identity unavailable": "未观察到窗口身份",
"No retained calls match these filters.": "没有符合条件的保留调用。",
"Next call page": "下一页调用",
"Load more": "加载更多",
"Show less": "收起更多",
"Some linked Sessions are not available in this view.": "此视图仅展示部分已关联的 Session。",
Expand Down
79 changes: 79 additions & 0 deletions frontend/test-v2/trace-diagnostics.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { act, fireEvent, render as renderRaw, screen, waitFor } from "@testing-library/react";
import type { ReactElement } from "react";
import { expect, it, vi } from "vitest";
import type { RuntimeV2Client } from "../src/runtime-v2/api/client.js";
import { TraceCallDetails } from "../src/runtime-v2/components/TraceCallDetails.js";
import { TraceSearch } from "../src/runtime-v2/components/TraceSearch.js";
import { UiProvider } from "../src/ui/UiProvider.js";

const render = (ui: ReactElement) => renderRaw(<UiProvider>{ui}</UiProvider>);
const ok = (data: unknown) => ({ ok: true, status: 200, data });
function client(post: ReturnType<typeof vi.fn>): RuntimeV2Client { return { post } as unknown as RuntimeV2Client; }

it("reads metadata only on expansion, caches it, pages and requires explicit full-payload read", async () => {
const post = vi.fn(async (_path, request) => request.payload_index === 0
? ok({ payload_available: true, payload: { full_body: "explicit only" } })
: request.offset ? ok({ status: "available", events: [{ event: "handler_returned" }], next_offset: null })
: ok({ status: "available", trace_mode: "metadata", capture_mode: "off", events: [
{ event: "tool_trace_diagnostic", diagnostic: { command: "cargo check" } },
{ event: "tool_trace_payload_captured", payload_index: 0, payload_bytes: 20 },
], next_offset: 2 }));
render(<TraceCallDetails client={client(post)} traceRef="exact-trace" language="en" />);
expect(post).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole("button", { name: "Inspect call diagnostics" }));
await screen.findByText(/cargo check/);
expect(post).toHaveBeenCalledTimes(1);
fireEvent.click(screen.getByRole("button", { name: "Hide call diagnostics" }));
fireEvent.click(screen.getByRole("button", { name: "Inspect call diagnostics" }));
expect(post).toHaveBeenCalledTimes(1);
fireEvent.click(screen.getByRole("button", { name: "More trace events" }));
await screen.findByText("handler_returned");
expect(post.mock.calls[1][1]).toEqual({ trace_ref: "exact-trace", offset: 2, limit: 12 });
fireEvent.click(screen.getByRole("button", { name: /Read retained full payload/ }));
await screen.findByText(/explicit only/);
expect(post.mock.calls[2][1]).toEqual({ trace_ref: "exact-trace", payload_index: 0 });
});

it("ignores a delayed response after the exact trace identity changes", async () => {
let resolve: (value: unknown) => void = () => {};
const post = vi.fn((_path, request) => request.trace_ref === "old"
? new Promise(done => { resolve = done; })
: Promise.resolve(ok({ status: "available", events: [{ diagnostic: { marker: "new-evidence" } }] })));
const api = client(post);
const view = render(<TraceCallDetails client={api} traceRef="old" language="en" />);
fireEvent.click(screen.getByRole("button", { name: "Inspect call diagnostics" }));
view.rerender(<UiProvider><TraceCallDetails client={api} traceRef="new" language="en" /></UiProvider>);
fireEvent.click(screen.getByRole("button", { name: "Inspect call diagnostics" }));
await screen.findByText(/new-evidence/);
await act(async () => resolve(ok({ status: "available", events: [{ diagnostic: { marker: "stale-evidence" } }] })));
expect(screen.queryByText(/stale-evidence/)).toBeNull();
expect(screen.getByText(/new-evidence/)).toBeTruthy();
});

it("keeps permission denials explicit without automatic retries", async () => {
const post = vi.fn(async () => ({ ok: false, status: 403, data: null }));
render(<TraceCallDetails client={client(post)} traceRef="denied" language="zh-CN" />);
fireEvent.click(screen.getByRole("button", { name: "查看调用诊断" }));
await screen.findByRole("alert");
expect(screen.getByRole("alert").textContent).toContain("需要管理员诊断权限");
expect(post).toHaveBeenCalledTimes(1);
});

it("queries without a Window hash and pages with the returned effective time range", async () => {
const query = { since_ms: 100, until_ms: 200, tool_name: "read_files" };
const post = vi.fn(async () => ok({ status: "available", query, next_offset: 20, calls: [
{ trace_ref: "a", window_key: null, tool_name: "read_files", project: "agent:xa:p", observed_at_ms: 100 },
{ trace_ref: "b", window_key: "b".repeat(64), tool_name: "read_files", observed_at_ms: 200 },
] }));
const selected = vi.fn();
render(<TraceSearch client={client(post)} language="en" onSelectWindow={selected} />);
fireEvent.click(screen.getByText("Find calls by time or Project"));
expect(post).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole("button", { name: "Search retained calls" }));
await screen.findByText("Window identity unavailable");
fireEvent.click(screen.getByRole("button", { name: /Open Window/ }));
expect(selected).toHaveBeenCalledWith("b".repeat(64));
fireEvent.click(screen.getByRole("button", { name: "Next call page" }));
await waitFor(() => expect(post).toHaveBeenCalledTimes(2));
expect(post.mock.calls[1][1]).toEqual({ query, offset: 20, limit: 20 });
});