Skip to content

fix(workspace): agent page UX — shared chart, live Start-a-chat, named work rows, contained asks (#2161) - #2166

Merged
trinity-ability merged 3 commits into
devfrom
feature/2161-agent-page-ux
Aug 13, 2026
Merged

trinity-ability merged 3 commits into
devfrom
feature/2161-agent-page-ux

Conversation

@vybe

@vybe vybe commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

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.

  • "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, keyed on route.params.agentName) kept the stage while the chat was set up invisibly behind it.
  • Recent work rows carried no context — eight rows reading "Scheduled run". They now carry the schedule's name.
  • Asks were unbounded on the Overview — now contained, still on the Overview.
  • The header chart was a bespoke full-bleed bar strip — now the operator surface's own 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 found roomId missing from guards written when sessionId was the only stage route, and ent#360 then added /workspace/a/:agentName without 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 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. 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_names maps id -> name and reads nothing else off the Schedule model. Three properties, each load-bearing:

  • One query per page, never get_schedule per row — 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. 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.

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.

The chart

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. _stats now 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"). 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 tabs it does not drive.

Changes

Layer File
Service client_portal/agent_page.py — _schedule_names, forwarded buckets
Models client_portal/models.py — schedule_name, buckets
UI portal/PortalAgentPage.vue — chart card, contained asks, named rows
UI portal/portalUtils.js — shouldEscapeStage, PORTAL_BUCKET_LABELS
UI utils/executionBuckets.js (new) — shared with OverviewPanel.vue
UI StackedBarChart.vue — additive labels prop · views/Portal.vue — shared escape
Docs flow doc + requirement §5.11 (both overrides + the disclosure recorded)

No 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 passed
  • Portal/analytics backend slice — 330 passed
  • npx vitest run — 310 passed (20 files)
  • npx vite build — clean
  • Raw-color ratchet: no regression attributable to this change (the two baseline deltas reproduce identically at HEAD)

On the full backend suite: three runs give three disjoint failure sets — dev at HEAD → 2 errors in test_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 the sys.modules collection-order class already recorded in learnings.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

@vybe

vybe commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Security pass — 3 low findings, all fixed in 3b91949

No critical or high findings. The schedule_name disclosure boundary, the agent scoping of the id→name map, XSS (interpolation, no v-html), the response_model projection, the untouched asks filter, and the absence of any new auth surface were all verified clean.

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. _schedule_names resolved through db.list_agent_schedules, i.e. select(agent_schedules) — whole Schedule models carrying message and validation_prompt. The projection to {id: name} was correct, but it made this module's own 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. Now a projected SELECT id, name accessor — structural, and it stops pulling N prompts per page load. A test pins that the prompt-carrying accessor is not called.

L2 — "operator-authored" was wrong, and I'd asserted it 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 — a prompt-injected agent — can author the text that renders on an external client's page, and ScheduleCreate.name has no length bound. Bounded impact (Vue escapes it; asks.title/question already cross by the same precedent), so the fix is honesty plus a cap at the service rather than the template, where a later list view would miss it.

L3 — sign-out didn't clear ?agent=, and my 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 old param enumeration missed it too — the same stale-list class one level over) and bounded, since the name is already in the address bar. The query is now part of the shape the predicate tests, which also stops newChatWithAgent leaving a stale ?agent=A when switching to B.

Re-verified: 27 backend tests for #2161, 776 in the schedule/portal slice, 314 frontend, build clean.

Also confirmed: the unrelated src/backend/enterprise submodule bump in the working tree is not in this PR.

vybe and others added 2 commits August 13, 2026 17:57
…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]>
@vybe
vybe force-pushed the feature/2161-agent-page-ux branch from 3b91949 to a01b846 Compare August 13, 2026 16:57
@vybe
vybe changed the base branch from main to dev August 13, 2026 16:58
@vybe

vybe commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto dev — and the base branch was wrong

Two corrections since the original push:

The PR targeted main. gh pr create defaulted to the repo's default branch, so this read as CONFLICTING against a hundred release commits. Retargeted to dev — now MERGEABLE, 2 commits, 18 files.

Rebased onto dev @ c1cc22bc, which had moved three commits, two of them on this exact surface.

Overlap with #2158 — same defect, fixed concurrently

a682b074 (#2158) fixed "Start a chat" independently and reached the same conclusion: stop enumerating route params, ask about route shape. That rule is kept as-is. What this PR adds on top, and why the inline form couldn't cover it:

  • It's a pure function (shouldEscapeStage in portalUtils). This project has no component-mount harness, so an inline closure over route can only be pinned by scanning source for a spelling; extracted, it's tested by calling it — including against /workspace/x/whatever, a route nobody has written yet.
  • It covers the query. /workspace?agent=X passes the path check while still carrying X. ?agent= is the ent#358 landing spot, re-read by bootstrap() after every sign-in — so signing out there and handing the browser on makes the next person's first screen "You don't have access to X". Found by this branch's security pass; fix(workspace): "Start a chat" on the agent page did nothing (ent#360) #2158's inline check doesn't catch it.

startBlankChat is deleted, not fixed

#2158 converted it, describing it as a control that "looked just as dead as the one in the report". It has zero callers — verified on dev (git grep matches only its own definition), and the cause is traceable: ent#361 (8e5157f1) renamed it out of the @new-chat binding and gave that event to the picker. So it's been orphaned since, and a dead function carrying a "fixed" comment reads as live to the next person. Deleted here, with a test pinning its absence and the orphaning commit named in the comment. Happy to restore it if it's meant to be wired up — that's a call for @dolho.

Test guards updated rather than relaxed

Both guards from #2158 asserted the inline spelling, so they failed once the rule moved behind a name. Both now assert the new structure and keep their original property:

  • portalLeaveSpecificRoute.spec.js — exits must delegate to escapeStage(); the shape check and the bare-route push are asserted once, against the single place that now answers for all of them.
  • workspaceRoomsGate.spec.js F24 — merged both sides: requires the shared call and keeps fix(workspace): "Start a chat" on the agent page did nothing (ent#360) #2158's stronger anti-enumeration assertion (not.toMatch(/route\.params\.(sessionId|roomId|agentName)/)), which mine lacked. An enumeration creeping back beside the call is something a delegation-only check wouldn't notice.

#2160 merged cleanly

c1cc22bc touched PortalAgentPage.vue too (skeleton loaders, pageCache, dimmed stat placeholders). Auto-merged with no conflict and verified intact alongside this PR's chart card and asks split — including that pageCache.clear() and allAsks = false both survive in the per-agent watcher.

Re-verified post-rebase: 332 frontend tests (22 files), 785 backend in the portal/schedule slice, 27 for #2161, build clean.

@vybe vybe closed this Aug 13, 2026
@vybe vybe reopened this Aug 13, 2026
…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 trinity-ability left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 plain dev. 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.

@trinity-ability
trinity-ability merged commit f5f2461 into dev Aug 13, 2026
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(workspace): agent page UX — Overview chart reuse, dead Start-a-chat, contextless Recent work, asks need their own tab

3 participants