Skip to content

feat(chat): e-mail a person once when their agent's run waits for them, by "Notify me when an agent needs me" (00474) - #2086

Merged
gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-agent-needs-me-email
Nov 4, 2026
Merged

gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-agent-needs-me-email

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

"Notify me when an agent needs me" in Settings › Chat works now. It was hidden in #1903 because nothing read it.

When one of a person's agents stops to ask them something, or to wait for their OK on a change (the agent run's status becomes needs_you), they get:

  • the run's chat under Needs you in their Inbox, as before;
  • with Inbox + email (the default), one email per run, with Open the run: "{Agent} needs you". Inbox only sends none. Inbox + Slack stays disabled until Slack can be connected.

How it works:

  • Web (settleAgentRun in agent-driver.ts): when a run moves to needs_you, it calls the API server's new POST /api/internal/chat/notices/needs-you (CRON_SECRET; agent-needs-you.ts). When the run moves on or ends, the run's notice closes (resolved_at). Neither step throws or holds the run.
  • Server (lib/chat-notices/needs-you.js, the pattern of go-live.js, whose helpers it now exports):
    • it tells the person the run acts as (acting_user_id, else the agent's owner), when they are a member and reach the run's brand;
    • it writes a chat_notices row of the new kind agent_needs_you, dedupe agent_needs_you:{run id}, so a run that waits again sends no second email;
    • it emails through Resend by chat_user_prefs.notify_via, like the other agent notices.
  • Inbox: the notice row isn't shown there. The run's chat is in Needs you already, so noticeOf leaves agent_needs_you out.
  • Settings › Chat: shows the row again. Its note now says what it does.
  • Help: help/chat/chat-settings.md gets a "Notify me when an agent needs me" section. The article is approved, so approved-articles.json is regenerated.

Migration 00474 (00474_chat_notices_agent_needs_you.sql) rewrites chat_notices_kind_check to add agent_needs_you. The full kind list:
own_key_failed, own_key_limit_80, own_key_limit_100, agent_went_live, agent_go_live_off, schedule_failed, schedule_paused, followup_result, agent_needs_you.

It keeps 00446's kinds and 00461's: 00461 is W3-04a's notices for scheduled jobs, in an open pull request. If another open migration also rewrites chat_notices_kind_check, the later one must list every kind, or the other's notices are refused. schema.test.ts checks the list.

If one of the other two Chat settings pull requests ("Answer language", "Thought for N s") merged first, chat-settings.tsx, its test and the Help article conflict on the hidden-settings comment and the sections. Keep every row and section, then run cd web && yarn vitest run -u src/lib/help to regenerate approved-articles.json.

Related issue

None. User priority list, item 3 (the three hidden Chat settings).

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

  1. cd server && npx vitest run src/lib/chat-notices/needs-you.test.js src/routes/internal-chat-notices.test.js. Covered:
    • one email per run;
    • Inbox only sends none;
    • the owner is told when the run acts as no one;
    • nothing for a run that doesn't wait or isn't the workspace's;
    • the route's secret and body.
  2. cd web && yarn vitest run src/lib/chat/agent-driver.test.ts src/lib/chat/agent-needs-you.test.ts src/lib/chat/notices.test.ts src/components/chat/chat-settings.test.tsx src/lib/chat/schema.test.ts.
  3. With an agent whose run asks before a change: when it waits, its person gets "{Agent} needs you" by email, once. Set Inbox only in Chat Settings: no email on the next run.

Needs migration on prod: 00474, after 00473.

No new environment variables (CRON_SECRET and Resend's exist).

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 (95fd81d), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41634857951): 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

…m, by "Notify me when an agent needs me" (00474)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 previously approved these changes Nov 3, 2026
@gkhngyk

gkhngyk commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Conflicts with main. Please merge main in.

…needs-me-email

# Conflicts:
#	web/src/lib/chat/agent-driver.ts
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main (d796cc7): the agent driver keeps the needs-you imports beside main's openHeadlessRun.

@gkhngyk

gkhngyk commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Conflicts again after #2090 merged (chat settings / help). Please merge main in.

gkhngyk
gkhngyk previously approved these changes Nov 4, 2026
…needs-me-email

# Conflicts:
#	help/chat/chat-settings.md
#	web/src/components/chat/chat-settings.test.tsx
#	web/src/components/chat/chat-settings.tsx
#	web/src/lib/help/approved-articles.json
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 4, 2026
00474 is also taken by ansvisor#2086's 00474_chat_notices_agent_needs_you.sql.
00478 is free on main and on every open branch. schema.sql rebuilt with
build-schema.sh; nothing else names the number.

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.

…needs-me-email

# Conflicts:
#	supabase/schema.sql

@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 17c7273 into ansvisor:main Nov 4, 2026
7 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