Skip to content

fix(demo): hide Agent Center's active count on the demo brand, whose agents never count - #2102

Merged
gkhngyk merged 16 commits into
ansvisor:mainfrom
cihan-gyk:feature/demo-agent-center
Nov 5, 2026
Merged

gkhngyk merged 16 commits into
ansvisor:mainfrom
cihan-gyk:feature/demo-agent-center

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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_VERSION 5): four agents made from the ready-to-use ones, owned by the organization's first person and shared with the workspace.

Agent Skills Triggers State
Brewline visibility watch /report Mondays and Thursdays at 08:00 Active
Brewline citation win-back /winback, /faq Action Center signal (recover) Active
Brewline competitor watch /beat, /compare Signal (compete); Mondays at 09:00 Active
Brewline weekly report /report Fridays at 16:00, Full auto Paused

Their runs:

  • Each agent has run history at its schedule's own slots. Each run has its chat (Open run), worded from the demo's own answers.
  • One win-back run waits on its owner's OK to save a draft. The Inbox has it under Needs you, and the last day's results are news there.
  • Names start with "Brewline" because agent names are unique per workspace (00419): they never collide with a person's own agent.

00475: chat_agents.demo_brand_id

  • An agent belongs to the workspace, not to a brand, so the demo's agents carry the demo brand they show.
  • on delete cascade, plus a partial index (where demo_brand_id is not null).
  • A trigger only takes a demo brand of the agent's own workspace, so a real agent can never be marked by mistake.
  • schema.sql is rebuilt, and types/supabase.ts has the column.

Nothing runs, counts or pauses them, by any route (each with a test):

  • agentForAct refuses every act on one with demo_brand (402, which opens the plans): edit, pause, archive, duplicate, run, take over.
  • Leaves them out (.is('demo_brand_id', null)):
    • triggers: activeAgents, so neither schedules nor signals fire;
    • the sweep: its failures part;
    • own key: resumeOwnKeyAgents;
    • the plan's active-agent limit: activeCount;
    • Agent Center's active / activeInWorkspace counts;
    • what may run: runnableAgents, which also feeds Run agent and an action's compatible agents.
  • settleAgentRun leaves a demo brand's runs as built. The waiting run's chat_run_state (the events route reads whose run it is) has no waiting_since, so the engine's sweep (sweepChatRuns), which stops a card a week after it was shown, never picks it up (engine.ts untouched).
  • The waiting run has no Chat run state (chat_run_state), so neither the engine nor its sweep (sweepChatRuns) can pick it up. engine.ts is not touched.
  • Approve, Skip and an answer on a demo brand's card answer the server's demo_brand 402 before anything resumes. The page opens the plans.

Hiding the demo brand deletes its agents with its chats:

  • in the brand menu, and after a purchase;
  • showing it again rebuilds them.

Coverage: chat_agent_runs is now built by the demo.

Not in this PR:

Help:

  • chat/agents.md, Run, pause and archive: one line on the demo's sample agents. The article was approved, so approved-articles.json is refreshed.
  • docs/guides/demo-brand.mdx says 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 feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

Unit tests:

  • Server lib/demo/agents.test.js:
    • four agents marked and scoped to the demo brand only, uniquely named;
    • schedules run at their own slots, before now;
    • every run on the demo brand, with its owner's chat;
    • read and unread;
    • the waiting run: no end, events replayed, the card last;
    • the build deletes the old agents first and keeps a person's own;
    • no people;
    • hideDemoAgents.
  • Server index.test.js (hiding deletes the agents) and coverage.test.js.
  • Web:
    • agents.test.ts: every act refused with demo_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 stays needs_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 402 demo_brand, and nothing resumes.
    • hide-after-purchase.test.ts: agents deleted with the chats.

Manually (00475 applied):

  1. Open the demo brand's Agent Center: four agents, three active and one paused, with next runs and run history.
  2. Run now, Pause, Edit or Duplicate: the plan dialog opens and nothing changes.
  3. Inbox: the win-back run is under Needs you. Approve opens the plans.
  4. Hide the demo brand from the brand menu: its agents and chats are gone. Show it again: they come back.

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 402 demo_brand, nothing resumed), the Inbox's Needs you.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (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 and yarn build pass; server lint, format:check and all tests pass.

🤖 Generated with Claude Code

cihan-gyk and others added 7 commits November 3, 2026 16:03
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]>
# 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]>
@mintlify

mintlify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 92dbc82.

Approve preview

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 3, 2026

@gkhngyk gkhngyk 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.

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:

  • listAgents isn'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.

cihan-gyk and others added 4 commits November 4, 2026 01:39
# Conflicts:
#	web/src/components/chat/chat-home.tsx
…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]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

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.

gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
@gkhngyk

gkhngyk commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

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
gkhngyk
gkhngyk previously approved these changes Nov 4, 2026

@gkhngyk gkhngyk 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.

LGTM.

gkhngyk
gkhngyk previously approved these changes Nov 4, 2026

@gkhngyk gkhngyk 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.

LGTM.

gkhngyk
gkhngyk previously approved these changes Nov 4, 2026

@gkhngyk gkhngyk 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.

LGTM.

@gkhngyk gkhngyk 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.

LGTM.

@gkhngyk
gkhngyk merged commit cbd768e into ansvisor:main Nov 5, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants