The operator console (operator)

One place to see what is working, what is limiting and what may have crashed, and to act on it: run a failed survey again, reset a stuck one, refund a purchase, hold or release an account. It is at /admin for accounts marked as operators. Everything an operator does is written to a log.

The design follows the monitoring panel built for the Scalp Score app, with its known gaps closed: every action has a guard and a log entry, alerts close by themselves, and no alert carries personal data.

The screens

Tab Shows You can
Now Waiting, running, finished, failed; live workers; "What needs attention"; speed and limits; why attempts failed; today's sign-ups, sales, refunds and model cost Jump to the tab that fixes each item
Surveys Every survey job: account, state, panel size, attempts, duration, cause of failure. Filters: failed, running, waiting, paid, finished. Search by email, product or id Run again, Reset, Stop for good, Refund. Open a row for its full history
Workers One card per worker: working, idle, silent (90 s without a heartbeat), down (5 minutes, no clean stop), stopped (clean). Current survey, finished and failed counts, last error -
Alerts Open alerts, newest first; closed ones on request Acknowledge with a note
People Accounts: joined, sign-in method, waiting / held / admitted, studies, free survey used, purchases. Filters and search Put on hold, Release and let in, Give the free survey back, Refund
Partners Referral partners: code, rate, referred accounts, buyers, net sales, due and paid Add or change a partner, Mark as paid. See Referral partners
Mail 14 days of email: sent, refused by the provider, bounced, refused for now, not sent, spam reports, unsubscribes; the latest 50 reports with the provider's reason - (set-up: Email setup, "Bounces and spam complaints")
Days 14 days: finished, paid, failed, retries, average run, model cost, revenue, refunds, sign-ups, held, let in -
Log Who did what, to what, when, with the reason given -
Audience Opt-ins, studies by state, what people build -

The console refreshes every 15 seconds while its browser tab is visible.

The actions and their guards

Action Allowed when What it does
Run again The survey failed Back in the queue with three fresh attempts. Free: uses the account's free survey again. Paid: cancels the pending refund
Reset The survey is running Hands it back to the queue now, without waiting 2 minutes of silence. A late result from the old worker is discarded
Stop for good Waiting, running or with the provider; a reason is required Marks it failed with your reason, which the customer sees. Free: the free survey and budget come back. Paid: refunded automatically
Refund The purchase is paid and its survey is not running; a reason is required Marks it for refund; a worker sends it to Stripe within a minute and emails the buyer. A waiting survey is taken out of the queue. A delivered result stays with the customer
Put on hold / Release Any account except an operator's Hold: the account can write studies but not run free ones. Release: removes the hold and lets it in
Give the free survey back The account used it and it is not running The account can run one more free survey
Acknowledge The alert is open and not yet acknowledged Records who saw it. It still closes only when the condition clears

Alerts

One alert per condition while it lasts. A repeat raises its count; when the condition clears, the alert closes by itself. Warnings and critical alerts are emailed once to ALERT_EMAIL, and once more if a warning becomes critical.

Alert Raised when Severity Usual fix
A worker stopped without a clean shutdown No heartbeat for 5 minutes and no goodbye critical Restart the worker service; read its log. Its survey has returned to the queue
Surveys are waiting and no worker is running Queue not empty, no live worker critical Start a worker
A paid survey has waited more than 10 minutes Oldest paid job in the queue critical Check workers and the provider; add a worker
Surveys are waiting longer than 30 minutes Oldest runnable job; critical after 2 hours warning Add a worker, or lower admissions per day
Several surveys failed in the last hour 3 or more final failures; critical at 10 warning Read the causes on Now; pause free surveys if the provider is down
The model provider is limiting or overloaded 3 or more attempts hit a rate limit or overload in 15 minutes warning Lower PAID_INTERVIEW_WORKERS or the number of workers; check your limits with the provider
The model provider refused our key or our account Any attempt refused for key, permission, billing or spend limit in the last hour critical Check the key and the account's spend limit; then Run again on the failed surveys
Today's free budget is used up Free jobs deferred to tomorrow info Nothing, or raise FREE_DAILY_BUDGET_USD
A refund has not gone through A refund waiting more than 15 minutes critical Check STRIPE_SECRET_KEY on the workers and its Refunds permission
A payment notification was received but not handled A stored Stripe event unprocessed for 5 minutes critical Read the API log; resend the event from Stripe
The mail provider is refusing messages 5 or more refused in an hour warning Check the SendGrid key and domain authentication
A bulk survey has been with the model provider for more than 25 hours A stage is overdue critical See Bulk surveys
Bulk surveys are not being collected No worker looked for 15 minutes warning Start a worker
A paid bulk survey has taken more than 6 hours Slow provider queue warning Tell the buyer; wait
Many duplicate or throwaway sign-ups 20 or more held accounts in an hour warning Switch on the "I am human" check; consider Cloudflare's attack mode

Getting started (owner)

  1. Apply 0008_operations.sql after 0007 and run the three verification queries in its header.
  2. Make yourself an operator, once, in the Supabase SQL editor (use your own address): update profiles set is_operator = true where email = '<your address>';
  3. Set ALERT_EMAIL on the workers to the mailbox that should get alerts.
  4. Restart the API and the workers. Open /admin.
  5. Recommended: its own hostname. Point operations.koloriq.com at the web app and set OPERATOR_HOST=operations.koloriq.com on the web app. The console and the operator API routes then answer only on that hostname (404 on the main site), and its front page opens the console. Put Cloudflare Access in front of that hostname, allowing only your own addresses: that is a second sign-in before the app's own. Add the hostname to the allowed redirect addresses in Supabase Auth, or sign-in on it will bounce to the main site.
  6. Recommended: watch from outside too. The alert check runs on every worker pass, so with every worker dead nobody raises "no worker is running". Either schedule it in the database (Supabase, Database, Cron: select public.ops_check(); every 2 minutes; the alert then shows in the console, but is only mailed once a worker is back) or point an uptime monitor at the API's /health and at the site.

Isolating it later: the console on its own server

Nothing in the console depends on running beside the public site: it is the same web app and API reading the same database. To move it to a separate, locked-down server:

Where Setting Effect
Operations server: API OPERATOR_ROUTES unset (on) Serves the /admin routes
Operations server: web app OPERATOR_HOST=operations.koloriq.com, API_URL pointing at the API on the same server Console on that hostname only
Public server: API OPERATOR_ROUTES=0 No /admin route exists there; every such request is 404
Public server: web app OPERATOR_CONSOLE=off /admin and /api/admin are 404 on every hostname
  1. On the operations server run one copy of the API and one of the web app with the settings above. It needs DATABASE_URL, the sign-in settings and PUBLIC_BASE_URL; it needs no model key, mail key or Stripe key, and it runs no worker.
  2. Lock the server down: reachable only through the access wall (Cloudflare Access or a VPN), no other tenant, its own firewall rules.
  3. Set the two "off" settings on the public server and restart it.
  4. Check: https://<main site>/admin is "Not found"; the operations hostname shows the console.

The database still checks the operator flag on every call, so a mistake in these settings exposes a sign-in page, not the data.

Limits

  • Operators share one level of access; there are no roles yet.
  • The console cannot start or stop a worker. That is done on the server.
  • The app does not ask operators for a second factor itself. Use the separate hostname behind an access wall (step 5) until that is built.
  • Deleting an account and its data on request is not in the console yet; it is done in Supabase.
  • Model cost is recorded when a survey finishes; a failed attempt's cost is not counted.

Troubleshooting

Symptom or message Cause Fix
"Operators only." Your account is not marked as an operator Step 2 above
/admin shows "Not found" OPERATOR_HOST is set and you are on the main site Use the operator hostname
"Only a failed survey can be run again." It is waiting, running or finished Nothing to do; or Stop it first
"This purchase has already been refunded, so the survey cannot be run again on it." The refund went out before you pressed Run again The customer buys again; offer a discount code
"This account has used its free survey on another study since this one failed." A free failure returned the free survey and the user spent it elsewhere Give the free survey back on People first, if you mean to
"Only a survey that is running can be reset." It already returned to the queue or finished Refresh
"Only a waiting or running survey can be stopped." It finished or failed meanwhile Refresh
"Give a reason; the customer sees it on the study page." Stop was confirmed with an empty reason Type a reason
"Give a reason for the refund; it is kept in the log." Refund was confirmed with an empty reason Type a reason
"This purchase is already refunded or being refunded." Refund pressed twice, or a failed survey already triggered it Nothing; one refund goes out
"Its survey is running. Stop the survey first, or wait for it to finish." Refund of a purchase whose survey is running Stop for good (refunds by itself), or wait
"Its free survey is waiting or running right now." Give back was pressed while the free survey runs Wait for it to end
"This account has not used its free survey." Nothing to give back -
"This alert is already acknowledged." Someone else acknowledged it Refresh
A worker shows "down" but the server says it runs It cannot reach the database Check DATABASE_URL and the network from the server
Alerts show but no email arrives ALERT_EMAIL is empty, or mail is not connected (Now says so) Set it; see Email setup
Every failure reads "Other" The provider's error text matched no known cause Open the survey for the full text; tell us so the cause can be added