Python
fix(observability): the coworker page after the live check (T3-16)
Devika Vermacffbce91fdc2
diff --git a/coworker/observability/usage_api.py b/coworker/observability/usage_api.pyindex 44de79de..eb57c922 100644--- a/coworker/observability/usage_api.py+++ b/coworker/observability/usage_api.py@@ -93,6 +93,13 @@ def heaviest(store: Any, *, start: int, end: int, limit: int = 20,ASKED = ("unsure", "context_changed", "could_not_run")+def canonical_model(model: str) -> str:+ """One name per model (T3-16, T3-4): OpenAI is the default provider, so `openai:gpt-5.6-sol`+ and `gpt-5.6-sol` are the same model. Only the `openai:` prefix is dropped, the same rule+ as `canonical_model` on issue/ope-247-openai-model-prefix; every other provider keeps its."""+ return model[len("openai:"):] if isinstance(model, str) and model.startswith("openai:") else model++def approver(store: Any, *, start: int, end: int, persona_id: Optional[str] = None) -> dict[str, Any]:"""`GET /v1/observability/approver`: the Auto-approve strip (§7.3). Live checks by result(asked you includes could-not-run: the card falls back to asking), overridden tool@@ -177,7 +184,8 @@ def persona_doing(store: Any, persona_id: str, *, start: int, end: int, current_Usage page. Fewer than `min_runs` runs: no medians, "too few runs to compare"."""turns = store.usage_turns(start, end, where={"persona_id": persona_id})kept_from = store.usage_kept_from()- models_of_turn = {t["turn_id"]: t.get("own_models", t["models"]) for t in turns}+ models_of_turn = {t["turn_id"]: list(dict.fromkeys(canonical_model(m) for m in t.get("own_models", t["models"])))+ for t in turns}runs: dict[tuple, dict[str, Any]] = {}for t in turns:k = (t["persona_fp"], t["session_id"])@@ -220,7 +228,10 @@ def persona_doing(store: Any, persona_id: str, *, start: int, end: int, current_changes = {}for prev, cur in zip(ordered, ordered[1:]):changes[cur["fp"]] = {"from": prev["fp"], **diff_versions(prev, cur, store)}- number = {v["fp"]: i + 1 for i, v in enumerate(ordered)}+ # a version whose files were not kept still gets its number, by when it was first seen here+ fps = [v["fp"] for v in ordered]+ fps += [r["fp"] for r in sorted(out, key=lambda r: r["first_seen"] or 0) if r["fp"] and r["fp"] not in fps]+ number = {fp: i + 1 for i, fp in enumerate(fps)}for row in out:row["changed"] = changes.get(row["fp"])# T3-15: "v1 · current": versions numbered oldest first, by first sightingdiff --git a/surfaces/gui/src/components/PersonaDoing.test.tsx b/surfaces/gui/src/components/PersonaDoing.test.tsxindex b112d7c9..705f72aa 100644--- a/surfaces/gui/src/components/PersonaDoing.test.tsx+++ b/surfaces/gui/src/components/PersonaDoing.test.tsx@@ -82,6 +82,7 @@ describe("PersonaDoing", () => {const tooFew = screen.getByTestId("persona-doing-too-few");expect(tooFew.textContent).toBe("too few sessions to compare");expect(tooFew.getAttribute("colspan")).toBe("2");+ expect(tooFew.className).toContain("text-center"); // T3-16 (b): across both columns, not under the secondexpect(b.textContent).toContain("or earlier");expect(b.textContent).toContain("2 / 1");// a later version can be compared@@ -101,7 +102,7 @@ describe("PersonaDoing", () => {expect(screen.getByTestId("persona-doing-changed").textContent).toContain("First version seen on this machine.");expect(screen.getByTestId("persona-doing-changed").textContent).not.toContain("unchanged");const line = screen.getByTestId("persona-doing-models");- expect(line.textContent).toBe("Models used: gpt-5.6-sol and 2 more");+ expect(line.textContent).toBe("Models used in the last 30 days: gpt-5.6-sol and 2 more");expect(line.getAttribute("title")).toBe("gpt-5.6-sol, model-a, model-b");});diff --git a/surfaces/gui/src/components/PersonaDoing.tsx b/surfaces/gui/src/components/PersonaDoing.tsxindex 31794ade..7b33170a 100644--- a/surfaces/gui/src/components/PersonaDoing.tsx+++ b/surfaces/gui/src/components/PersonaDoing.tsx@@ -41,7 +41,11 @@ export function PersonaDoing({ personaId, machineId, secClass, scrollIntoView }:{doing.rows.length === 0 ? (<div className="text-meta text-faint">{t("p3.doing.none")}</div>) : (- <table className="p3-t">+ <table className="p3-t p3-doing">+ <colgroup>+ <col style={{ width: "15%" }} /><col style={{ width: "19%" }} /><col style={{ width: "11%" }} />+ <col style={{ width: "15%" }} /><col style={{ width: "14%" }} /><col style={{ width: "12%" }} /><col style={{ width: "14%" }} />+ </colgroup><thead><tr><th>{t("p3.doing.version")}</th>@@ -120,14 +124,14 @@ function DoingTr({ r, t }: { r: DoingRow; t: T }) {{r.current && <span className="text-ok"> · {t("p3.doing.current")}</span>}</span></td>- <td className="whitespace-nowrap">{inUseSpan(r.first_seen, r.last_seen, r.before_kept, t)}</td>+ <td>{inUseSpan(r.first_seen, r.last_seen, r.before_kept, t)}</td><td className="n">{r.runs}{r.automation_runs > 0 && <span className="text-faint"> {t("p3.doing.automation_runs", { count: r.automation_runs })}</span>}</td>{r.too_few ? (// T3-15 (h): one note across both typical-number columns- <td className="n text-faint" colSpan={2} data-testid="persona-doing-too-few">{t("p3.doing.too_few")}</td>+ <td className="text-faint text-center" colSpan={2} data-testid="persona-doing-too-few">{t("p3.doing.too_few")}</td>) : (<><td className="n">{(r.at_least ? "≥ " : "") + formatTokens(r.median_tokens ?? 0)}</td>diff --git a/surfaces/gui/src/components/PersonaView.test.tsx b/surfaces/gui/src/components/PersonaView.test.tsxindex 56e9b2a7..4f162809 100644--- a/surfaces/gui/src/components/PersonaView.test.tsx+++ b/surfaces/gui/src/components/PersonaView.test.tsx@@ -80,8 +80,12 @@ describe("PersonaView", () => {expect(screen.getAllByText(/Ready/).length).toBeGreaterThan(0);expect(screen.getByText("Connect")).toBeTruthy(); // datadog (core, not connected)expect(screen.getByText("Add")).toBeTruthy(); // filesystem (mcp, not connected)- // defaults footer+ // the models it may use, labelled apart from the models its sessions used (T3-16 d);+ // Default mode and Workspace are gone (T3-16 e)expect(screen.getByText("claude-opus-4-8")).toBeTruthy();+ expect(screen.getByTestId("persona-can-use").textContent).toBe("Can use: claude-opus-4-8, gpt-5.5");+ expect(screen.queryByText(/Default mode/)).toBeNull();+ expect(screen.queryByText(/Workspace/)).toBeNull();});it("toggling a default connection POSTs /connections and applies the returned defaults", async () => {diff --git a/surfaces/gui/src/components/PersonaView.tsx b/surfaces/gui/src/components/PersonaView.tsxindex 7b41cbe4..5eb2c2c2 100644--- a/surfaces/gui/src/components/PersonaView.tsx+++ b/surfaces/gui/src/components/PersonaView.tsx@@ -360,29 +360,19 @@ export function PersonaView({{/* Phase 3 OB-15: how each version of this coworker has been doing */}<PersonaDoing personaId={personaId} machineId={mid} secClass={SEC_H} scrollIntoView={focus === "doing"} />- {/* defaults footer */}- <section className="flex flex-wrap gap-x-8 gap-y-2 text-ui">- {detail.recommended_models.length > 0 && (- <div>- <span className="text-faint">{t("persona.models_label")}</span> ·{" "}- {detail.recommended_models.map((m, i) => (- <span key={m}>- <span className="font-mono">{m}</span>- {i < detail.recommended_models.length - 1 ? ", " : ""}- </span>- ))}- </div>- )}- {detail.default_permission_mode && (- <div>- <span className="text-faint">{t("persona.default_mode_label")}</span> · {detail.default_permission_mode}- </div>- )}- <div>- <span className="text-faint">{t("persona.workspace_label")}</span> ·{" "}- {detail.requires_folder ? t("persona.workspace_picked") : t("persona.workspace_scratch")}- </div>- </section>+ {/* the models this coworker may use (T3-16: "Can use", apart from the models its+ sessions used, under How it's been doing; Default mode and Workspace removed) */}+ {detail.recommended_models.length > 0 && (+ <section className="text-ui" data-testid="persona-can-use">+ <span className="text-faint">{t("persona.can_use")}</span>{" "}+ {detail.recommended_models.map((m, i) => (+ <span key={m}>+ <span className="font-mono">{m}</span>+ {i < detail.recommended_models.length - 1 ? ", " : ""}+ </span>+ ))}+ </section>+ )}{/* management — the controls that left the list page (UX-035) */}<section className="border-t border-line pt-4 flex flex-wrap items-center gap-x-5 gap-y-2 text-ui">diff --git a/surfaces/gui/src/locales/en.json b/surfaces/gui/src/locales/en.jsonindex 9a9ff329..79b6c711 100644--- a/surfaces/gui/src/locales/en.json+++ b/surfaces/gui/src/locales/en.json@@ -1532,19 +1532,16 @@"connections_desc": "Declared by the persona — wire {{name}} into these to unlock its full workflow.","connections_full_benefit": "Connections for full benefit","core_tag": "core",- "default_mode_label": "Default mode","disabled": "Disabled","enable_title": "Enable this coworker","enabled": "Enabled","hero_art": "{{slug}} artwork","load_error": "Could not load this coworker.","loading": "Loading…",- "models_label": "Models","new_sessions_default": "New sessions get by default","new_sessions_desc": "When you start a {{name}} session these are enabled automatically. You can still mute any of them per session.","on_by_default": "On by default for new sessions","persona": "Coworker",- "workspace_label": "Workspace","prev_screenshot": "Previous screenshot","next_screenshot": "Next screenshot","screenshot_alt": "{{name}} screenshot {{n}}",@@ -1554,8 +1551,6 @@"col_enable": "Enable","advanced": "Advanced","tool_calls": "Tool calls",- "workspace_picked": "picked folder",- "workspace_scratch": "scratch","show_in_picker": "Show in picker","default_for_new": "Default for new sessions","make_default": "Make default",@@ -1566,7 +1561,8 @@"delete": "Delete","keep": "Keep","delete_ellipsis": "Delete…",- "delete_failed": "delete failed"+ "delete_failed": "delete failed",+ "can_use": "Can use:"},"personas": {"add_help": "Load from a local directory or a public GitHub repo. Files are copied into a managed area (a snapshot), so the source can change without affecting the install.",@@ -4100,8 +4096,8 @@"ratings": "Ratings 👍 / 👎","today": "today","or_earlier": "{{date}} or earlier",- "models_used_one": "Models used: {{model}}",- "models_used_more": "Models used: {{model}} and {{count}} more",+ "models_used_one": "Models used in the last 30 days: {{model}}",+ "models_used_more": "Models used in the last 30 days: {{model}} and {{count}} more","nothing_to_compare": "Nothing to compare yet"},"wake": {diff --git a/surfaces/gui/src/locales/zh.json b/surfaces/gui/src/locales/zh.jsonindex ace75af7..9db06940 100644--- a/surfaces/gui/src/locales/zh.json+++ b/surfaces/gui/src/locales/zh.json@@ -1511,19 +1511,16 @@"connections_desc": "由角色声明 —— 把 {{name}} 接入这些连接以解锁它的完整工作流。","connections_full_benefit": "充分发挥的连接","core_tag": "核心",- "default_mode_label": "默认模式","disabled": "已禁用","enable_title": "启用此同事","enabled": "已启用","hero_art": "{{slug}} 配图","load_error": "无法加载此同事。","loading": "加载中…",- "models_label": "模型","new_sessions_default": "新会话默认启用","new_sessions_desc": "当你开始一个 {{name}} 会话时,这些会自动启用。你仍可在每个会话中静音任意一个。","on_by_default": "新会话默认开启","persona": "同事",- "workspace_label": "工作区","prev_screenshot": "上一张截图","next_screenshot": "下一张截图","screenshot_alt": "{{name}} 截图 {{n}}",@@ -1533,8 +1530,6 @@"col_enable": "启用","advanced": "高级","tool_calls": "工具调用",- "workspace_picked": "选定的文件夹",- "workspace_scratch": "临时目录","show_in_picker": "显示在选择器中","default_for_new": "新会话默认","make_default": "设为默认",@@ -1545,7 +1540,8 @@"delete": "删除","keep": "保留","delete_ellipsis": "删除…",- "delete_failed": "删除失败"+ "delete_failed": "删除失败",+ "can_use": "可以使用:"},"personas": {"add_help": "从本地目录或公开 GitHub 仓库加载。文件会复制到托管区域(快照),因此源文件变更不会影响已安装版本。",@@ -4033,8 +4029,8 @@"ratings": "评价 👍 / 👎","today": "今天","or_earlier": "{{date}} 或更早",- "models_used_one": "使用的模型:{{model}}",- "models_used_more": "使用的模型:{{model}} 等另外 {{count}} 个",+ "models_used_one": "最近 30 天使用的模型:{{model}}",+ "models_used_more": "最近 30 天使用的模型:{{model}} 等另外 {{count}} 个","nothing_to_compare": "还没有可比较的版本"},"wake": {diff --git a/surfaces/gui/src/styles.css b/surfaces/gui/src/styles.cssindex 174fc481..56526dcb 100644--- a/surfaces/gui/src/styles.css+++ b/surfaces/gui/src/styles.css@@ -2662,6 +2662,10 @@ html[data-theme="dark"] { --bar-model:#4c8dff; --bar-tool:#3fb8ad; --bar-wait:#3.p3-t .n { text-align:right; font-variant-numeric:tabular-nums; white-space:nowrap; }/* T3-5: Heaviest turns stays inside its card: fixed columns, text cut with the full text on hover */.p3-heavy { table-layout:fixed; }+/* T3-16: the coworker history table stays inside its card; headers wrap */+.p3-doing { table-layout:fixed; }+.p3-doing th { white-space:normal; vertical-align:bottom; }+.p3-doing td { overflow-wrap:anywhere; }.p3-heavy td { overflow:hidden; }.p3-cut { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }.p3-badges { display:flex; flex-wrap:nowrap; gap:3px; min-width:0; }diff --git a/tests/test_observability_phase3_manual_fixes.py b/tests/test_observability_phase3_manual_fixes.pyindex bba2709f..8aad46c9 100644--- a/tests/test_observability_phase3_manual_fixes.py+++ b/tests/test_observability_phase3_manual_fixes.py@@ -198,13 +198,18 @@ def test_a_versions_models_are_its_own_work_only(tmp_path):t["stamp"].update({"persona_id": "cowork", "persona_fp": "fp1"})store.write_turn(t)usage = {"reported": True, "input_fresh": 10, "cache_read": 0, "cache_write": 0, "output": 1}- for n, (purpose, model) in enumerate([("main", "model-x"), ("helper", "model-h"), ("auto_approver", "reviewer-model"),+ for n, (purpose, model) in enumerate([("main", "model-x"), ("helper", "model-h"), ("main", "openai:model-h"),+ ("main", "together:model-h"), ("auto_approver", "reviewer-model"),("title", "title-model"), ("summary", "summary-model")], start=1):store.write_step(_step("T1", "s1", n, RECENT + n, "model", {"purpose": purpose, "model": model, "usage": usage}))store.write_issues("T1", {"signals_version": signals.version(), "warn": 0, "info": 0, "issues": [], "fine": []}, seen=True)store.flush()got = usage_api.persona_doing(store, "cowork", start=RECENT - 1, end=RECENT + 60_000)[row] = got["rows"]- assert row["models"] == ["model-h", "model-x"]- assert row["model_line"] == {"kind": "first", "models": ["model-h", "model-x"]}+ # T3-16 (d): openai:model-h is model-h (only the openai: prefix goes); together: keeps its own+ assert row["models"] == ["model-h", "model-x", "together:model-h"]+ assert row["model_line"] == {"kind": "first", "models": ["model-h", "model-x", "together:model-h"]}+ assert row["version_n"] == 1 # T3-16: numbered even when its files were not kept+ assert usage_api.canonical_model("openai:gpt-5.6-sol") == "gpt-5.6-sol"+ assert usage_api.canonical_model("openrouter:openai/gpt-5") == "openrouter:openai/gpt-5"store.close()