Skip to content

feat(server): read a draft's Content Quality for an agent's go-live gate, on the run's budget - #1978

Merged
gkhngyk merged 7 commits into
ansvisor:mainfrom
cihan-gyk:feature/server-go-live-quality-reads
Nov 2, 2026
Merged

gkhngyk merged 7 commits into
ansvisor:mainfrom
cihan-gyk:feature/server-go-live-quality-reads

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

AUTONOMOUS-GO-LIVE PR 2b-1: the server reads a draft's Content Quality for an agent's go-live gate, on the agent run's budget (§6.2; the owner's 2026-11-02 decision). Stacked on #1970. No migration. Nothing calls it yet; PR 2b-2's web gate will.

What changes

  • POST /api/internal/chat/go-live/quality-reads (CRON_SECRET, in routes/internal-chat-go-live.js), { orgId, agentRunId, runId, actingUserId, draftId, sites }.
    • Checks first: the run is running, acts as the person, and is the workspace's. The person is an Admin or Manager with access to the draft's brand. The draft isn't archived or the demo brand's.
    • Reads the draft as saved:
      • its links (link-check.js, the person's hourly reads);
      • with Quality's phase 2, its claims, its page read, and the kinds of the sites the gate's rules can't place (only ones the draft links, not ones whose every link the person kept).
    • With them, the brand's facts (phase 2, readBrandFacts) and its site's trust (readSiteTrust), as the editor reads them through the API.
    • Each read answers on its own: { ok: true, value } or { ok: false, code } (run_cap, ai_budget, off, failed). The gate can then hold the page on just the read it lacks.
  • chat-budget.js:
    • agentRunReserve(orgId, { runId, agentRunId }) is a meter with plan-guard's reserveAiBudget interface (charge, release, keep). It holds each read as the run's own step: feature agent, within the run's cap and the month's budget. Write errors are logged, as reserveAiBudget's are.
    • reserveChatStep takes holdUsd for such small calls.
  • readDraftClaims, readPage, readSourceClasses take an optional reserve. Without it, nothing changes (the workspace's Quality budget).
  • The page read's brand context (site type, name, approved claims) moves to content-page-context.js, used by the editor's route and the gate. The route reads the same.

Costs: a new read holds CLAIMS_HOLD_USD, PAGE_HOLD_USD or SOURCE_CLASS_HOLD_USD and is charged at its real cost. A kept read costs nothing.

Related issue

None. AUTONOMOUS-GO-LIVE spec, PR 2 (2b, server part).

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

Server unit tests:

  • chat-budget: the meter's hold, charge, second call, release, keep, run cap;
  • the claims, page and source-class reads on a given meter;
  • content-pages: unchanged;
  • internal-chat-go-live: reads on the run's meter, each failure on its own, phase 1, refusals.

No visible change, no Help article, no AI call in tests.

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 (3ae561b), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41362898951): 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 6 commits November 1, 2026 23:56
…permission

AUTONOMOUS-GO-LIVE PR 1 (migration 00443), with nothing reading it yet:
chat_settings gains the workspace switch (auto_go_live_groups, who turned
it on, when, under which terms); chat_agent_go_live keeps an agent's
permission for the version it was given on, with its daily limit (1-20,
5 unless set); chat_agent_go_live_events keeps each step an agent takes
live on its own, read by brand access. reserve_agent_go_live and
finish_agent_go_live (service role) hold the daily limit under a lock per
agent, once per (draft, target); a failed step frees its slot. Types,
schema.sql, and the brand-access and demo coverage lists follow.

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

AUTONOMOUS-GO-LIVE PR 4 (migration 00444). POST
/api/internal/chat/go-live/send (CRON_SECRET) is how the web's engine will
send an agent's page on its own: it checks everything again from the
database (Chat on, Full auto's plan, the Admins' switch, the run running
as the person, the agent's permission for the run's version, the person's
role and the Managers' publishing switch, brand access, not the demo
brand, and the step's own reservation), then sends as a person's Send to
CMS does, with the agent run kept on the delivery
(content_draft_deliveries.agent_run_id). The step is finished done, or
failed with why, which frees its slot; a refusal frees only this step's
own slot. Never retried. v1 takes CMS drafts only. Nothing calls it yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ate, on the run's budget

AUTONOMOUS-GO-LIVE PR 2b-1 (the owner's 2026-11-02 decision). POST
/api/internal/chat/go-live/quality-reads (CRON_SECRET) reads the draft as
saved for the web's gate: its links, and with Quality's phase 2 its
claims, its page read and the kinds of the sites the gate's rules can't
place. A kept read costs nothing; a new one is the agent run's own step
(chat-budget agentRunReserve: feature agent, within the run's cap and the
month's budget), not the workspace's Quality budget. Each read answers on
its own (run_cap, ai_budget, off, failed), so the gate can hold the page
on the one it lacks. The three reads take an optional meter; the page
read's brand context moves to content-page-context.js for both callers.
Nothing calls the endpoint yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…trust with the draft's reads

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 1, 2026
gkhngyk
gkhngyk previously approved these changes 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.

LGTM

# Conflicts:
#	server/src/lib/brand-access-policies.test.js
#	server/src/routes/internal-chat-go-live.js
#	server/src/routes/internal-chat-go-live.test.js
#	supabase/schema.sql
@github-actions github-actions Bot removed 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.

LGTM

@gkhngyk
gkhngyk merged commit 97f840f into ansvisor:main Nov 2, 2026
5 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.

2 participants