Skip to content

feat(chat): add the Scheduled page, a job's page, Run now and Take over (W3-03) - #2018

Merged
gkhngyk merged 38 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-scheduled-page
Nov 4, 2026
Merged

gkhngyk merged 38 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-scheduled-page

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

The Scheduled page (CHAT-12 items 21–25; mockup #s-sched), behind CHAT_AGENTIC. Stacked on #2015a (W3-04a, on #2014 → #2003 = #2003, and #1958): merge those first. No migration, no new env var. Plan: Chat waves plan, W3-03.

/dashboard/chat/scheduled

  • A Scheduled item in the Chat menu, with the count of the person's jobs that are on. It is also in the Ctrl K palette, and the header reads "Chat › Scheduled".
  • Header: "{n} of {limit} jobs on" (the plan's active jobs) and New schedule, which opens Chat Home with "Every Monday at 9:00, " in the box. This uses W3-07's ?compose=; until that merges, Home opens empty.
  • The mockup's columns, one row per job:
    • Job: title, /skill · brand, and "by {name}" on an Admin's view.
    • When: on the job's own clock ("Every Monday, 08:00"), with the next run or why it is off ("Paused · AI limit reached", "Paused · its creator can't run it", …).
    • Last run: dot, date, status (Done, No change, Failed, Skipped, Needs you, Working), "1 of 3 ready", and "emailed".
    • Result goes to.
    • Mode: hidden below 1180 px, so 1024 px fits.
    • The on/off switch and one action: Open last · Run now · Take over (Admin) · Cancel (follow-up check).
  • Follow-up checks show as "Follow-up check · Set by you / Set by a Full auto run for you". Agents' Schedule triggers show as "Agent: {name}" with their next run and Edit in Agent Center. They stay in chat_agent_triggers (decision 15); nothing is copied.

Who sees and changes what (as 00457's RLS, read again here with the service role)

  • People see their own jobs. Admins see every job in the workspace. A job about a brand is shown only to people who can reach that brand.
  • The creator and Admins can switch a job on or off and delete it. Only the creator edits it or clicks Run now, because its runs act as them.
  • Turning a job back on runs it from its next slot after now; missed runs aren't made up. It must fit the plan's active jobs, and it closes the job's notices.
  • Take over (Wave 3 decision 16): when a job paused because its creator can no longer run it, an Admin takes it. The job becomes the Admin's, turns on from now, and opens a new chat of its own.

A job's page /dashboard/chat/scheduled/{id} ("Chat › Scheduled › {job}")

  • Edit the title, what Chat does each run, When as free text, Deliver to and change-only. When is read on the job's clock as you type, with its line and next 3 runs. Save needs no confirm card (item 23). A repeat can become a one-time job and back.
  • Run now: one run at once, outside the job's slots, with a due run's checks. It waits if no run slot is free and says why it was refused. The next slot stays as it was (worker.runJobNow, chat_schedule_runs.run_now).
  • Delete asks "Delete this schedule? Past results stay in Files."
  • Run history: the last 20 runs with date, status, a link to the result in Chat, and use as a share of the monthly AI limit ("0.6%"). Never dollars.

Also

  • Inbox notices (W3-04a) and the Activity log's Undo now open the job's page.
  • The create_schedule row's route is this page.
  • Help: help/chat/scheduling.md now points at the page and has "The Scheduled page", "A job's page" and "Who sees what".

Code: lib/chat/schedule/views.ts (reads), manage.ts (changes), deliver-choices.ts (pure, for the browser), and server actions in lib/actions/chat-schedules.ts (assertWritable first). UI: components/chat/scheduled/.

Related issue

None. Chat waves plan, Wave 3 (W3-03).

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

With CHAT_AGENTIC on:

  1. Create two jobs from chat (W3-02's card). Open Scheduled from the Chat menu: it shows the count, both rows with When, next run, Result goes to and Mode, and the switch.
  2. Turn one off: the row says "Off" and the count drops. Turn it on: its next run is the next slot after now.
  3. Open a job. Type "next Friday" in When: the line says which two dates it could be and Save turns off. Type "every weekday at 7": the next 3 runs show. Save, then Run now: "Running now · the result shows up in your Inbox", and a run row tagged Run now appears.
  4. As an Admin, open Scheduled: teammates' jobs show "by {name}" with the switch, but no Save or Run now on their page. Set a teammate's job to paused_reason = 'owner_role': the row offers Take over.
  5. At 1024 px, light and dark: no column is cut off (Mode hides).

Screenshots (1024 px, light and dark) are in the PR comment.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes (changed files: 0 errors)
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

Run locally: web — format:check, eslint on the changed files, typecheck, and 17 test files / 315 tests (schedule incl. views/manage/worker Run now, components/chat/scheduled, chat menu, actions, debug, inbox, registry, undo, help, subscription-guard coverage). Full CI runs on the fork.

Screens: shown to the owner in a local preview (1024px, light and dark, with preview data) and approved on 2026-11-02.

CI passed on this branch (2025cad), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41489294713): 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 24 commits November 1, 2026 12:08
…440)

AGENT-OWN-KEY PR 2. When the workspace's own AI key fails, every run ends
"Something went wrong" and nothing names the key. This adds what the next
PRs use to stop runs, pause agents and tell Admins. Nothing is visible yet.

- lib/agent/key-errors.ts: classifyProviderError(provider, error) unwraps
  the AI SDK's RetryError and reads the APICallError's status and body:
  invalid (401, 403, Google API_KEY_INVALID), no_credit (insufficient_quota,
  OpenRouter 402, Anthropic's low credit balance or billing_error), model
  (404, Azure DeploymentNotFound), transient (408/409/429/5xx/529, Google
  RESOURCE_EXHAUSTED, a dropped connection, a timeout) or request (anything
  else, and OpenRouter's 403 moderation flag). invalid, no_credit, model and
  unreadable (a key that can't be decrypted, ours) are the key classes.
- lib/chat/key-health.ts: ownKeyFailure reads the active key's failure
  without decrypting; markKeyFailing starts one episode however many runs
  fail at once (a conditional update on failing_since) and keeps the latest
  class; markKeyWorking clears it only when set and resumes the agents
  paused own_key; resumeOwnKeyAgents for a key that went out of use.
- 00440: organization_ai_keys gets checked_at, failing_since,
  failure_class, failure_status and notified_at, failing_since set exactly
  while failure_class is. A new key string clears all five in a trigger,
  so a key replaced in Settings starts unchecked whatever the route sends,
  and the web may deploy ahead of the migration. chat_agents.paused_reason
  and chat_agent_runs.stop_reason gain own_key. schema.sql and the
  Supabase types are regenerated.

Agents resumed by the system aren't logged, as the cap resume isn't.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g it to the AI limit

AGENT-OWN-KEY PR 7 (§3.1 point 2, §13 item 1). When the workspace's active
own key couldn't be decrypted (the master key rotated without a re-save, a
malformed row), resolveAgentModelConfig answered null and Chat silently ran
on Ansvisor's key and the workspace's AI budget, while chatRunsOnOwnKey
still said "own". A workspace that keeps its data with its own provider
would have had it sent through Ansvisor's key.

- lib/agent/key.ts: readActiveKey tells none saved, unreadable (with its
  provider) and ready apart. resolveAgentModelConfig keeps answering null
  for both, so today's Agent Chat still asks for a key.
- lib/chat/key.ts: resolveChatModelKey throws OwnKeyUnreadableError on an
  unreadable own key, never Ansvisor's key, and marks the key failing
  unreadable (key-health, best effort). The run ends in error; PR 3 gives
  it its own words. chatRunsOnOwnKey already reads it as own.
- Agents: aiLimitReached reads an unreadable key as the workspace's own
  (no AI limit), and the agent form still says the agent runs on that
  provider's key.
- Help "Use your own AI keys": a key the server can no longer read stops
  Chat; save it again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AGENT-OWN-KEY PR 3 (§5.1, §5.2). A revoked key, an account out of credit or
a model the key can't reach ended every run "Something went wrong", the
reading model's failure was tried again on the same key, and a triggered
agent kept firing until 3 failed runs in a row paused it.

- Engine: a failed model call on the workspace's own key is sorted by
  classifyProviderError (engine-key.ts stepFailure). A key class ends the
  run at once with code own_key: no read→write second call, and a Help
  answer stops too. The key is marked failing (one episode) and the run's
  progress keeps keyFailure. The words name the provider and the class
  ("Anthropic turned down your workspace's key." / "…out of credit." /
  "…can't find the model {model}…" / "…can't be read any more.") plus "So
  Chat stopped here. What's done so far is kept."
- A saved key that can't be read (PR 7) ends the run the same way before
  any call.
- A provider that didn't answer after the SDK's retries ends provider_down:
  "{provider} didn't answer, so Chat stopped here… Try again in a moment."
  The key isn't marked.
- Ansvisor's own key failing keeps today's path: it isn't the workspace's
  to fix.
- ChatModels carries the key's provider and its health at the run's start;
  the first answered call on a key marked failing marks it working, which
  resumes the agents it paused (key-health).
- The run's error box: Admins get Open AI Providers, others read "An Admin
  can fix it in Settings › AI Providers." (run.error code own_key,
  kept on reload).
- Agents: an error run with keyFailure is stopped own_key ("Stopped · AI
  key not working"), not failed, so it doesn't count toward 3 failed runs in
  a row. A triggered agent pauses own_key ("Your AI key isn't working"); a
  person's Run now or Run agent doesn't pause it.
- Help: chat.md "When your AI key fails"; agents.md "When your AI key fails".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AGENT-OWN-KEY PR 4 (§5.2 items 4–6). While the workspace's own AI key was
failing, Run now and Run agent queued runs that then failed, Resume turned
a paused agent back on into the same failure, and nothing outside a run
said the key was the cause.

- runChecks refuses own_key_failed (409) when Chat runs on the workspace's
  own key and it is marked failing (failingOwnKey): Run now and Run agent
  queue nothing, on any brand; Activate, Resume and Take over are refused
  the same way. The words: "{why} An Admin can fix it in Settings › AI
  Providers, then run the agent again."
- The runner ends a queued run before any model call: stopped own_key; a
  triggered agent pauses own_key, a person's run doesn't.
- Agent Center: a banner while the key fails, "Your {provider} key isn't
  working · agents are paused" and why; Admins get Fix in AI Providers,
  others read that an Admin can fix it there. The list's answer carries
  the key's class and provider (keyFailure), no dates.
- The composer, on Chat's pages and in the side panel: one line over the
  box, "{why} Chat stops on it until it's fixed.", with Fix in AI Providers
  for Admins. Sending stays on. Read only where Chat runs on the own key.
- Help: agents.md and chat.md "When your AI key fails".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed agents

Settings › AI Providers gets Test on each saved key and on the Replace form:
one call with no retries, sorted into working, out of credit, refused or
unchecked. What it finds is kept on the key (00440): a failing key starts an
episode, a working one ends it and restarts the agents it paused. The list
shows each key's health. The agent sweep restarts agents paused for the own
key once it works again, or once Chat no longer runs on it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fuse

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/chat/_chat-page-access.ts
#	web/src/components/chat/agents/agents-list.tsx
…ils (00441)

AGENT-OWN-KEY PR 6: when the workspace's own key stops working, every
Admin gets one notice for the episode: a row at the top of the Chat
Inbox, "Your {provider} key isn't working · agents are paused", with
Fix it to Settings › AI Providers, and an e-mail (00441 chat_notices,
unique per person and episode). If the key still fails 3 days later,
one reminder. The notices close once the key works again or is removed.
Only while Chat is on for the workspace; nothing on self-hosted.

Help: AI providers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

# Conflicts:
#	help/settings/ai-providers.md
#	web/src/app/api/settings/ai-providers/route.test.ts
#	web/src/app/api/settings/ai-providers/route.ts
#	web/src/lib/chat/agent-sweep.test.ts
#	web/src/lib/chat/agent-sweep.ts
#	web/src/lib/chat/key-health.ts
…or a test passes

Saving a new key string clears the old key's failure (00440's trigger), so
markKeyWorking found nothing failing and never closed the Admins' notices.
The PUT now closes the provider's open notices before the new key's check
is kept, and a passing check closes them whether or not a failure was
still marked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ess and demo coverage tests

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nge and notices (W3-04a)

- A job's answer stays in its own chat, its creator's, so it reaches
  their Inbox as an unread result.
- "Notify only if the answer changed": at the end of the read phase a
  scheduled run fingerprints what it read (times and dates left out);
  a change-only job that read what its last delivered run read stops
  before the writing step as "No change" (run status unchanged). The
  first run always delivers; a delivered run's fingerprint becomes the
  job's last_fingerprint.
- "1 of 3 ready": the run row's parts follow the task strip's ready
  tasks, else the files the run made, while it works and when it ends.
- The server keeps each scheduled run's usage_share after every charge
  or release of its steps (Ansvisor-key spend over the included budget).
- chat_notices for the creator: schedule_failed after the retry also
  failed, schedule_paused when the job turns itself off; closed when the
  job runs again or is turned back on. The Inbox shows them with Open.
- Migration 00461 widens chat_notices_kind_check (keeps 00446's kinds,
  adds schedule_failed, schedule_paused, followup_result).
- Help: "Results and notices" in help/chat/scheduling.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er (W3-03)

- /dashboard/chat/scheduled (mockup #s-sched): Scheduled in the Chat
  menu with the person's jobs on, in the Ctrl K palette and the header's
  breadcrumb. One row per job: the job (/skill · brand, by whom on an
  Admin's view), When on its own clock with the next run or why it is
  off, the last run (status, "1 of 3 ready", emailed), where results go,
  mode, the on/off switch and one action (Open last, Run now, Take over,
  Cancel for a follow-up check). Agents' Schedule triggers are listed
  with Edit in Agent Center (they stay in chat_agent_triggers).
- People see their own jobs, Admins every job, on brands they reach.
  Creator and Admins switch and delete; only the creator edits or runs
  now. On again runs from the next slot after now (no catch-up), within
  the plan's active jobs. An Admin takes over a job whose creator can't
  run it (it becomes theirs, on again, with a chat of its own).
- /dashboard/chat/scheduled/{id}: edit title, prompt, When (read as
  typed, next 3 runs), Deliver to and change-only with no confirm card;
  Run now (worker.runJobNow: one run now, its next slot kept); Delete
  ("Past results stay in Files"); the last 20 runs with their use as a
  share of the monthly AI limit.
- Inbox notices and the Activity log's Undo open the job's page; the
  create_schedule row's route is the page.
- Help: help/chat/scheduling.md points at the page, with its sections.

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 2, 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.

One fix needed; two smaller notes.

Saving an edit to a "ready by" job runs it again. manage.ts:219-231 recomputes next = firstRunOf(...) and writes next_run_at whenever the job is enabled. The detail page fills When with "ready by …", so it reads back as ready_by. Because one-time jobs stay enabled after they run (see #2014), fixing a typo in the title of a ready-by job that already ran re-arms it, and the next tick runs it a second time. A one-time "run at" job that already ran can't be edited at all: its When now reads as past and Save is refused.
Fix: leave next_run_at alone when When didn't change, and never re-arm a one-time job whose run already happened.

Smaller:

  • After Take over, the old creator's "is paused" notice never closes. takeOverSchedule changes created_by (:164) before closeJobNotices (:175), which then filters user_id = job.created_by, now the Admin. Close the notices first, or close by payload->>scheduleId.
  • Run now inserts with attempt: 1 and settles through countRun. A failed Run now therefore queues the 10-minute retry and counts toward the 3 failures that turn the job off. If that isn't intended, skip countRun for run_now rows.

…eave Run now out of retries

Saving a job's page re-read When and wrote next_run_at whenever the job
was on. The page fills When with the job's own phrase, so a title-only
edit of a ready-by job that had already run re-armed it and the next
tick ran it again; a one-time run-at job whose time had passed could not
be saved at all. When is now compared with the job's own phrase (and,
once read, with its kept timing): left as it was, the when columns,
next_run_at and retry_at stay untouched and the other edits save.

Take over changed created_by before closing the job's notices, which
are filtered by the creator, so the old creator's "is paused" notice
never closed. The notices now close while the job is still theirs.

A Run now row settled through countRun with attempt 1, so a failed Run
now queued the 10-minute retry and counted toward the 3 failures that
turn the job off. Run now is outside the job's slots: its rows are no
longer counted or retried.
…it was

The server keeps a job's timing when When is unchanged, but the page still
read the prefilled When on the client: for a one-time job whose time passed
it read as past, so Save stayed disabled and the field was marked invalid.
The page now applies the same rule: a When left as the job's own phrase
doesn't block Save or show the past-time problem. A When typed to another
past time is still refused. Adds a component test.
# Conflicts:
#	server/src/lib/chat-budget.test.js
#	server/src/lib/chat-notices/own-key.js
#	server/src/middleware/demo-brand.test.js
#	server/src/routes/internal-chat-notices.js
#	server/src/routes/internal-chat-notices.test.js
#	supabase/schema.sql
#	web/messages/en.json
#	web/src/app/api/settings/ai-providers/route.test.ts
#	web/src/app/api/settings/ai-providers/route.ts
#	web/src/components/chat/chat-inbox.test.tsx
#	web/src/components/chat/inbox-notices.tsx
#	web/src/lib/actions/chat-notices.ts
#	web/src/lib/chat/agent-sweep.ts
#	web/src/lib/chat/engine.test.ts
#	web/src/lib/subscription-guard-coverage.test.ts
#	web/src/types/supabase.ts
# Conflicts:
#	web/src/lib/actions/chat-notices.ts
gkhngyk
gkhngyk previously approved these changes Nov 2, 2026
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Nov 3, 2026
…o feature/account-time-zone

A job's page keeps both: a When left as it was keeps the job's timing (ansvisor#2018), and a zone picked on the page reads When again on the new clock and makes the next run again (00468).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 7 commits November 4, 2026 00:51
…chat-schedule-delivery

# Conflicts:
#	supabase/schema.sql
#	web/messages/en.json
#	web/src/components/chat/inbox-notices.tsx
#	web/src/lib/chat/engine.test.ts
#	web/src/lib/chat/engine.ts
#	web/src/lib/chat/schedule/worker.ts
# Conflicts:
#	web/src/components/chat/chat-menu.test.tsx
…led-page

# Conflicts:
#	help/chat/scheduling.md
#	web/messages/en.json
#	web/src/components/chat/chat-menu.test.tsx
#	web/src/components/chat/chat-shell.tsx
#	web/src/lib/chat/notices.ts
#	web/src/lib/chat/schedule/worker.test.ts
#	web/src/lib/chat/schedule/worker.ts
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label 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 pushed a commit that referenced this pull request Nov 4, 2026
…2118)

#2043 merged the second batch of What's new entries before the pull
requests they describe. Three of them name things main doesn't have yet,
so they would show once New Chat goes live:

- Follow-up checks: no follow-up check tool, Set check card or result
  notice on main (#2029).
- Scheduled jobs: the schedule card and Inbox delivery are on main, but
  runs aren't e-mailed (#2028) and there is no Scheduled page in the
  Chat menu (#2018).
- Your time zone: Settings › Account has no time zone yet (#2034,
  migration 00468).

Each keeps its approved text and gets published: 2099-12-31, so
pickWhatsNew leaves it out until its pull request sets its merge day.
entries.json regenerated.


Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

Co-authored-by: Claude <[email protected]>
@gkhngyk
gkhngyk merged commit ba19361 into ansvisor:main Nov 4, 2026
7 checks passed
gkhngyk pushed a commit that referenced this pull request Nov 4, 2026
…ain (#2128)

#2118 held three entries back with published 2099-12-31 until their
features merged. Scheduled jobs' Scheduled page (#2018) and e-mailed runs
(#2028), and the time zone setting (#2034), merged on 2026-11-04, so both
entries now show from that day. Follow-up checks stays held: #2029 is open.


Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

Co-authored-by: Claude <[email protected]>
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.

3 participants