Repository navigation
fix(workspace): agent page UX — shared chart, live Start-a-chat, named work rows, contained asks (#2161) - #2166
Conversation
Security pass — 3 low findings, all fixed in 3b91949No critical or high findings. The Two of the three were cases where the code was correct and my prose was wrong, which is the worse half — a comment that overstates a guarantee is what the next reader relies on instead of checking. L1 — don't load prompts to render a label. L2 — "operator-authored" was wrong, and I'd asserted it in the service docstring, the response model, the flow doc and the requirement. L3 — sign-out didn't clear Re-verified: 27 backend tests for #2161, 776 in the schedule/portal slice, 314 frontend, build clean. Also confirmed: the unrelated |
…d work rows, contained asks (#2161) Four defects on the agent page ent#360 shipped two commits ago. Two of the issue's own acceptance criteria are deliberately NOT implemented as written; both overrides are recorded in the flow doc and requirement so a later reader does not "fix" them back. START A CHAT DID NOTHING — and the button was wired correctly. The handler prepared the chat and then failed to leave the route, so PortalAgentPage, which renders FIRST in the stage chain and is keyed on route.params.agentName, kept the stage while the new chat was set up invisibly behind it. The escape test read `route.params.sessionId || route.params.roomId`. That list is written once and goes stale every time a stage route is added: #2128 found roomId missing from guards written when sessionId was the only stage route, and ent#360 then added /workspace/a/:agentName without revisiting them. This is the third occurrence, so the question is inverted rather than extended — shouldEscapeStage(path) asks about route SHAPE (anything that is not the workspace root is a stage to leave) and therefore FAILS CLOSED: a fourth stage route needs no edit here and cannot silently re-break the button. Two live call sites fixed, newChatWithAgent and onSignOut (which carried a room id, then an agent name, into the next session's address bar). A third, startBlankChat, was DELETED — it had no callers at all, which makes patching it the plausible-looking fix that would have changed nothing. RECENT WORK CARRIED NO CONTEXT. The issue's AC #3 asked for a message summary; the answer is the SCHEDULE NAME, and the distinction is the decision. A schedule's `message` is a prompt, and this page serves external clients — its `name` is a short label an operator wrote to tell schedules apart, which is the job the row needs done. AC #3 is therefore met for schedule-backed rows only; chat/loop/reminder rows keep trigger, duration and time. A per-viewer variant (show a viewer their own prompts) was considered and rejected: no prompt text on this surface. _schedule_names maps id -> name and reads nothing else off the Schedule model. One query per page, never get_schedule per row — that is an N+1 whose only symptom is latency, so the test asserts the CALL COUNT. Agent scoping is free: the map holds only this agent's schedules, so a foreign or stale id misses by construction and there is no ownership check to forget. It fails soft — a schedules read that raises costs the labels, never the rows. Misses are ordinary (the __manual__ sentinel, soft-deleted schedules whose executions outlive their name by up to 30 days) and render as a plain trigger label. The name attaches to any row whose id resolves, not only triggered_by == "schedule": a webhook that fires a schedule is running that schedule. ASKS STAY ON THE OVERVIEW — AC #4 overridden. A tab is somewhere you have to go, and an agent reaching you when no chat is open is the page's reason to exist. The defect was that asks were unbounded, not that they were present, so they are contained instead: compact cards, the question clamped, first five with a counted toggle, beside recent work on wide screens. Asks stay FIRST in DOM order so the mobile stack keeps the priority, and there is no nested scroll region — a page that scrolls traps the gesture on touch). The badge reads 20+ at the cap, because MAX_ASKS truncates server-side and a bare 20 against 50 pending is a wrong number, not a rounded one. THE CHART IS NOW THE OPERATOR SURFACE'S CHART. The bespoke full-bleed CSS bar strip is deleted; the Overview opens with a bounded card rendering StackedBarChart (#1107). BUCKET_COLORS moves to utils/executionBuckets.js — a second inline copy is what drifts, and the ORDER is a contract with the backend's _BUCKET_ORDER — and _stats forwards the analytics accessor's own `buckets` rather than letting the portal re-derive one. The legend needed client-facing wording ("Tool call", not "MCP") to match the translation the page already does everywhere else. That is an OPTIONAL `labels` prop, never a rename of the `buckets` array: those entries are the keys the chart indexes by_type with, so translating them in place makes every lookup miss and renders an EMPTY chart — a silent failure that reads as "this agent did nothing this week". Empty and unavailable are now different sentences, and the window selector is hidden on the tabs it does not drive. Tests: the ent#360 exact-dict projection pin is updated rather than loosened — it is what forced schedule_name to be argued instead of absorbed. New backend tests cover the resolve/miss/cost/degrade seam; the frontend spec pins shouldEscapeStage against a route NOBODY HAS WRITTEN YET, which is the property a param-enumerating guard cannot have. workspaceRoomsGate F24 is REWRITTEN, not deleted: it used to require each exit function to contain route.params.roomId, which after this change would mandate the enumeration that was the defect. No new endpoint, no schema change, no migration, no auth change. Fixes #2161 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…t= on sign-out (#2161) Three low-severity findings from the security pass on this branch. None is a disclosure today; two are cases where the code was correct and the PROSE was wrong, which is the worse half — a comment that overstates a guarantee is what the next reader relies on instead of checking. DON'T LOAD THE PROMPT TO RENDER A LABEL. `_schedule_names` resolved through `db.list_agent_schedules`, which is `select(agent_schedules)` — whole `Schedule` models carrying `message` and `validation_prompt`. The projection down to `{id: name}` was correct, but it made this module's own stated principle ("a field that never leaves the service cannot be leaked by a later edit") a review invariant: `{s.id: s}`, or adding `description` for a subtitle, puts the agent's prompts one edit from a client's page. A projected accessor (`db.get_agent_schedule_names`, `SELECT id, name`) makes it structural, and stops pulling N prompts out of the database per page load. Mirrors the shape `find_active_schedules_exceeding_timeout` already uses two functions away. A test pins that the prompt-carrying accessor is NOT called. THE NAME IS NOT "OPERATOR-AUTHORED" — the comfortable mistake, asserted in the service docstring, the response model, the flow doc and the requirement. `POST /api/agents/{name}/schedules` is `AuthorizedAgent` and the MCP `create_agent_schedule` tool exists, so an agent-scoped key — hence a prompt-injected agent — can write the text that renders on an external client's page, and `ScheduleCreate.name` has no length bound. Impact is bounded (Vue escapes it; `asks.title`/`question` already cross by the same precedent), so the fix is honesty plus a cap: the wording now says untrusted, and the name is truncated at the service (`MAX_SCHEDULE_NAME_CHARS`) rather than at the template, where a later list view would miss it. SIGN-OUT DIDN'T CLEAR `?agent=`, AND THE NEW COMMENT CLAIMED IT DID. `shouldEscapeStage('/workspace')` is false while `?agent=` is a live landing parameter that `bootstrap()` re-reads after every sign-in — so signing out at `/workspace?agent=acme-billing` and handing the browser on makes the NEXT person's first screen "You don't have access to acme-billing". Pre-existing (the param enumeration missed it too, so this is the same stale-list class one level over) and bounded, since the name is already in the address bar — but it is exactly what the guard exists to close, and the comment added in the previous commit asserted it was closed. The query is now part of the shape the predicate tests, which also stops `newChatWithAgent` leaving a stale `?agent=A` behind when switching to B. 27 backend tests for #2161, 776 in the schedule/portal slice, 314 frontend, build clean. Refs #2161 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
3b91949 to
a01b846
Compare
Rebased onto
|
…es residue (#2161) CodeQL flagged the comment-stripping helper this branch added as `js/incomplete-multi-character-sanitization` (high): `/<!--[\s\S]*?-->/g` is non-greedy, consumes to the FIRST `-->`, and can leave an opener behind. Not an injection here — nothing renders this string; the structure guards read source and match against it. But the alert is right about the defect, and the consequence is real in its own way: leftover comment text is scanned as if it were code, so a guard fails on the prose describing the rule it enforces, which is the exact failure stripping exists to prevent. The obvious two-line patch — loop the regex to a fixpoint — does NOT fix it, and that is worth recording because it looks like it should. Verified: <!<!---->--> -> <!--> still contains <!--, no longer matches, loop stops So this is an index scan instead. It terminates (each pass is non-increasing in length) and is complete (any surviving `<!--` forces a removal, to its `-->` or to end-of-input when unterminated, so the string must change; at the fixpoint none can remain). The outer loop also catches openers formed ACROSS a removal, e.g. `<!` + comment + `--`. Checked against the case that defeated the loop plus nested, unterminated and no-comment inputs. Extracted to tests/unit/helpers/ rather than fixed in place: there were already two copies and this branch was adding a third, so a fix in one would have left two wrong ones and no way to tell which was authoritative. Both existing callers now import it. 332 frontend tests green, build clean. Refs #2161 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
trinity-ability
left a comment
There was a problem hiding this comment.
Reviewed as second party (PR authored by vybe).
All 26 checks green, including the four required by dev branch protection — CodeQL (python + javascript-typescript), Schema Parity Gate, and container-security verify-non-root — plus backend-unit-test's regression diff, which compares base against head across three pytest seeds and reported no new failures.
Two blockers were found and fixed during validation rather than waved through:
- CodeQL high-severity alert (
js/incomplete-multi-character-sanitization) on the comment-stripping test helper. The obvious loop-the-regex patch was verified NOT to fix it (<!<!---->-->→<!-->, residue remains, loop stops), so it was replaced with an index scan that provably converges, and extracted so the two pre-existing copies stop diverging. pytest (head, seed 99999)cancelled at the 25-minute job budget — the documented #2019 stall class, whose own workflow comment records it hitting all three seeds and both sides including plaindev. Re-run: success.
Docs, requirements §5.11 and a learnings entry accompany the change; both deliberate AC deviations (no prompt text in Recent work, asks contained on Overview rather than a new tab) are recorded in-repo so they read as decisions rather than omissions.
Summary
Four UX defects on the Workspace agent page that ent#360 shipped two commits ago. Two of the issue's own acceptance criteria are deliberately not implemented as written — both overrides are recorded in the flow doc and the requirement so a later reader doesn't "fix" them back.
PortalAgentPage(which renders first in the stage chain, keyed onroute.params.agentName) kept the stage while the chat was set up invisibly behind it.StackedBarChart, bounded.The stage escape now fails closed
The guard read
route.params.sessionId || route.params.roomId. That list goes stale every time a stage route is added: #2128 foundroomIdmissing from guards written whensessionIdwas the only stage route, and ent#360 then added/workspace/a/:agentNamewithout revisiting them. Third occurrence.So the question is inverted rather than extended.
shouldEscapeStage(path)asks about route shape — anything that is not the workspace root is a stage to leave — and therefore fails closed: a fourth stage route needs no edit here and cannot silently re-break the button.Two live call sites fixed (
newChatWithAgent,onSignOut— the latter carried a room id, then an agent name, into the next session's address bar). A third,startBlankChat, was deleted: it had no callers at all, which makes patching it the plausible-looking fix that would have changed nothing.AC #3 — schedule name, not message summary (override)
The issue asked for a message summary; the answer is the schedule name, and the distinction is the decision. A schedule's
messageis a prompt, and this page serves external clients; itsnameis a short label an operator wrote to tell schedules apart, which is the job the row needs done. A per-viewer variant (show a viewer their own prompts) was weighed and rejected — no prompt text on this surface.Honest cost: AC #3 is met for schedule-backed rows only. Chat/loop/reminder rows keep trigger, duration and time.
_schedule_namesmapsid -> nameand reads nothing else off theSchedulemodel. Three properties, each load-bearing:get_scheduleper row — an N+1 whose only symptom is latency, so the test asserts the call count.Misses are ordinary (the
__manual__sentinel; soft-deleted schedules, whose executions outlive their name by up to 30 days) and render as a plain trigger label. The name attaches to any row whose id resolves, not onlytriggered_by == "schedule"— a webhook that fires a schedule is running that schedule.AC #4 — asks stay on the Overview (override)
A tab is somewhere you have to go, and an agent reaching you when no chat is open is the page's reason to exist. The defect was that asks were unbounded, not that they were present. Contained instead: compact cards, question clamped, first five with a counted toggle, beside recent work on wide screens.
20+at the cap:MAX_ASKStruncates server-side, and a bare "20" against 50 pending is a wrong number, not a rounded one.The chart
BUCKET_COLORSmoves toutils/executionBuckets.js— a second inline copy is what drifts, and the order is a contract with the backend's_BUCKET_ORDER._statsnow forwards the analytics accessor's ownbucketsrather than letting the portal re-derive one.The legend needed client-facing wording ("Tool call", not "MCP"). That is an optional
labelsprop, never a rename of thebucketsarray — those entries are the keys the chart indexesby_typewith, so translating them in place makes every lookup miss and renders an empty chart, a silent failure that reads as "this agent did nothing this week". Empty and unavailable are now different sentences, and the window selector is hidden on tabs it does not drive.Changes
client_portal/agent_page.py—_schedule_names, forwardedbucketsclient_portal/models.py—schedule_name,bucketsportal/PortalAgentPage.vue— chart card, contained asks, named rowsportal/portalUtils.js—shouldEscapeStage,PORTAL_BUCKET_LABELSutils/executionBuckets.js(new) — shared withOverviewPanel.vueStackedBarChart.vue— additivelabelsprop ·views/Portal.vue— shared escapeNo new endpoint, no schema change, no migration, no auth change.
Test Plan
pytest tests/unit/test_2161_agent_page_ux.py tests/unit/test_ent360_workspace_agent_page.py— 26 passednpx vitest run— 310 passed (20 files)npx vite build— cleanHEAD)On the full backend suite: three runs give three disjoint failure sets —
devat HEAD → 2 errors intest_subscription_auto_switch_pingpong.py; this branch minus its new test file → 10 errors in that same file; this branch with it → zero there, and 3 unrelated failures elsewhere. All pass in isolation. That is thesys.modulescollection-order class already recorded inlearnings.md(2026-08-12 #2114, which names that very file); adding a test file perturbs collection order. Everything this PR touches is green in every run. Captured as a durable entry.Not visually verified: light/dark was checked mechanically — every color introduced is theme-paired or uses the file's existing dual-safe convention, and the chart component already ships in both themes on Agent Detail — but I did not render it. Worth a look before merge.
Fixes #2161
🤖 Generated with Claude Code