Repository navigation
fix(demo): hide Agent Center's active count on the demo brand, whose agents never count - #2102
Conversation
The demo brand showed the real Chat, locked and empty (ansvisor#1999). A new demo module (lib/demo/chat.js, DEMO_VERSION 4) now gives each person of the organization five chats on the demo brand, as if they had asked them: the questions, the reads Chat made as steps, the "Data used" chips, next moves under the latest answer, and answers whose figures are counted from the demo's own answers (stats.js) and link to its Action Center actions and Content Editor drafts. A chat is its author's, so each person gets their own copy; someone who joins later gets theirs at the next rebuild. Sending in one, or starting a chat on the demo brand, is refused with the server's demo_brand 402 before anything is kept or run (POST /api/chat/runs), and the page opens the plans, as for a read-only workspace: an answer on the demo brand would still use the workspace's AI. Hiding the demo brand (the brand menu, or the purchase) deletes its chats, since Chat's menu lists a person's chats of every brand; showing it again marks it stale, so the next visit rebuilds it with them. chat_conversations is now built by the demo; agent_conversations (the old Agent chat) is skipped with its reason. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Stacked on the demo's sample chats. The demo brand's Agent Center now has four agents made from the ready-to-use ones (visibility watch, citation win-back, competitor watch and a paused weekly report), with their versions, triggers and run history, each run with its chat (Open run). Schedules run at their own slots, worded from the demo's own answers; one win-back run waits on its owner's OK to save a draft, so the Inbox has something under Needs you. An agent belongs to the workspace, not to a brand, so 00475 marks the demo's agents with the demo brand they show (chat_agents.demo_brand_id, on delete cascade, a partial index, and a trigger that only takes a demo brand of the agent's own workspace). Nothing runs, counts or pauses them: - agentForAct refuses every act on one with demo_brand (402: the plans); - the triggers' active agents, the sweep's failures, the own key's resume, the plan's active-agent counts and limit, and what may run (Run agent, an action's agents) leave them out; - settleAgentRun leaves a demo brand's runs as built (the waiting run has no Chat run state, so the engine's sweep never sees it either); - Approve, Skip and an answer on a demo brand's card answer the server's demo_brand 402 before anything resumes. Hiding the demo brand deletes its agents with its chats; showing it again rebuilds them (DEMO_VERSION 5). chat_agent_runs is now built by the demo. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…not Inbox news Co-Authored-By: Claude Opus 5.5 <[email protected]>
… from the demo's data Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # server/src/lib/demo/chat.js
…rd shows, never expired The events route reads whose run it is from chat_run_state: without it the waiting run's card never showed (404). Its state has no waiting_since, so the engine's sweep, which stops a card a week after it was shown, never picks it up; Approve, Skip and an answer stay refused with demo_brand. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…agents never count Beside the demo brand's four sample agents the count of active agents (the plan's, 00475 leaves them out) read 0. On the demo brand there is none; the plan's count and limit still leave the demo's agents out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
gkhngyk
left a comment
There was a problem hiding this comment.
Demo agent runs are never settled and outlive a hide. settleAgentRun returns early for demo-brand runs (agent-driver.ts ~753), and the sweep's settle pass reads the 500 oldest open runs by queued_at (agent-sweep.ts ~291). Hiding the demo deletes the agents but not their runs (chat_agent_runs.agent_id is on delete set null), so every workspace with a demo keeps a permanent needs_you row. Past ~500 such workspaces they're always the oldest and fill the settle window, so a real run settled only by the sweep stays "Needs you"/"Running". Delete the demo brand's chat_agent_runs in both hide paths, and keep demo brands out of the settle query.
Small:
listAgentsisn't brand-scoped, so the four demo agents show on every brand, next to an active count that leaves them out (the mismatch this PR set out to fix).- Demo agent names can clash with a person's agent (
lower(name)is unique per workspace): create "Brewline visibility watch" while the demo is hidden and every rebuild's insert fails.
# Conflicts: # web/src/components/chat/chat-home.tsx
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d keep them out of the sweep's settle pass Review on ansvisor#2102: a deleted agent's runs stay (agent_id set null), so the demo's waiting run outlived a hide as a permanent needs_you row, and the settle pass, reading the 500 oldest open runs, could fill up with them. - Both hide paths (server hideDemoAgents, web hideDemoBrandAfterPurchase) delete the demo brand's chat_agent_runs before its agents. - The settle pass reads open runs a page at a time and leaves out those on a demo brand, so a real run is settled however many demos wait. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Fixed: both hide paths now delete the demo brand's agent runs before its agents, and the sweep's settle pass reads open runs a page at a time leaving demo brands out (tests added); the two Small items will follow in a separate PR. |
|
Approved; conflicts with main after #2098 merged. Please merge main in and it can go. |
…center # Conflicts: # docs/guides/demo-brand.mdx # server/src/lib/demo/chat.js # server/src/lib/demo/index.js # server/src/lib/demo/index.test.js # web/src/app/api/chat/runs/route.test.ts # web/src/lib/chat/run-api.ts # web/src/lib/demo/hide-after-purchase.test.ts # web/src/lib/demo/hide-after-purchase.ts
…n_agent Main's run_agent (ansvisor#2052) read an agent's Can call without leaving out the demo brand's sample agents (00475), so a saved list naming one let another agent run it. Saving a Can call that names one is now refused (demo_agent, with its own words), and callableAgentsOf leaves them out, as Run agent's picker does, so a run never offers or runs one, even one stored before. Help: the agents article says other agents can't call them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMenyNyxsr2Doq4CaQ3
…center # Conflicts: # supabase/schema.sql
…center # Conflicts: # supabase/schema.sql
…center # Conflicts: # supabase/schema.sql
Summary
The demo brand's Agent Center has agents at work: part 2 of "demo shows Chat and Agent Center one-to-one". Stacked on #2098 (the demo's sample chats). Migration 00475.
What the demo builds (
server/src/lib/demo/agents.js,DEMO_VERSION5): four agents made from the ready-to-use ones, owned by the organization's first person and shared with the workspace.Their runs:
00475:
chat_agents.demo_brand_idon delete cascade, plus a partial index (where demo_brand_id is not null).schema.sqlis rebuilt, andtypes/supabase.tshas the column.Nothing runs, counts or pauses them, by any route (each with a test):
agentForActrefuses every act on one withdemo_brand(402, which opens the plans): edit, pause, archive, duplicate, run, take over..is('demo_brand_id', null)):activeAgents, so neither schedules nor signals fire;resumeOwnKeyAgents;activeCount;active/activeInWorkspacecounts;runnableAgents, which also feeds Run agent and an action's compatible agents.settleAgentRunleaves a demo brand's runs as built. The waiting run'schat_run_state(the events route reads whose run it is) has nowaiting_since, so the engine's sweep (sweepChatRuns), which stops a card a week after it was shown, never picks it up (engine.tsuntouched).chat_run_state), so neither the engine nor its sweep (sweepChatRuns) can pick it up.engine.tsis not touched.demo_brand402 before anything resumes. The page opens the plans.Hiding the demo brand deletes its agents with its chats:
Coverage:
chat_agent_runsis now built by the demo.Not in this PR:
agents.ts.demo_brand_idagents too.chat_schedules.agent_id) are in the open W3 chain; the same applies once their worker merges.Help:
chat/agents.md, Run, pause and archive: one line on the demo's sample agents. The article was approved, soapproved-articles.jsonis refreshed.docs/guides/demo-brand.mdxsays what Agent Center shows.Related issue
None. Priority queue item 4 (demo shows Chat and Agent Center one-to-one).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Unit tests:
lib/demo/agents.test.js:hideDemoAgents.index.test.js(hiding deletes the agents) andcoverage.test.js.agents.test.ts: every act refused withdemo_brand; out of the plan's active agents and of what may run.agent-triggers.test.ts: a marked agent never fires, even with a real brand in its scope.agent-sweep.test.ts: a demo run staysneeds_you, and a demo agent at 3 failures isn't paused.key-health.test.ts: never resumed.route.test.ts: Approve on a demo brand's card is a 402demo_brand, and nothing resumes.hide-after-purchase.test.ts: agents deleted with the chats.Manually (00475 applied):
Screenshots:
.claude/mockups/demo-agent-center/(1024 px): Agent Center (light, dark), an agent's page, Run now opening the plans, the waiting run's card, Approve opening the plans (the approve route answered 402demo_brand, nothing resumed), the Inbox's Needs you.Checklist
yarn lintpassesyarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change)CI passed on this branch (512dfa6), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41685986637): schema is up to date; web
format:check, lint, typecheck, all tests andyarn buildpass; server lint,format:checkand all tests pass.🤖 Generated with Claude Code