Repository navigation
feat(tracking): sample ChatGPT's query fan-out one day a week through Cloro's legacy interface - #1755
Conversation
… Cloro's legacy interface ChatGPT's default (mobile-web) interface has carried no query text since 2026-09-30, so its tasks stopped asking for fan-out (ansvisor#1119). Cloro's legacy desktop interface (`legacy: true`) still returns `searchQueries`, at the add-on's +2 credits a task. - CLORO_CHATGPT_FANOUT = off | sample | all (default sample). On sample a prompt's ChatGPT task asks one UTC weekday a week, picked from a hash of the prompt id (no stored state, spread across the week). That day's answer is the tracked one; no extra request. - The tracking worker decides per task and passes `legacy` to submitScraperTask / buildRequestBody, which stays pure. A legacy task Cloro refuses is submitted again without it. - Health report: on sample, ChatGPT is judged over the last 7 days (flagged when none of its answers carried fan-out) instead of day against days before, which swings by design; on all it is expected daily; on off it is not judged. - Docs: env var in self-host docs and .env.example; Prompts guide explains the weekly sample. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nightly runs Review follow-ups for the sampled ChatGPT fan-out. - A legacy ChatGPT task that Cloro takes and then fails goes once more without legacy, in both paths: the webhook reads it from the new cloro_pending_tasks.legacy column (00378) and swaps in the new task's pending row; polling uses the submission's own record. - A refused submission is sent again without legacy only on 400/422. submitScraperTask errors now carry the HTTP status; a network error, timeout, 429, 5xx, 401 or 402 is never resubmitted, since the first task may exist and be billed. - Only the nightly run's first attempt asks (source 'cron', attempt 1): manual runs, analyze-new, retries and recovered runs don't. - CLORO_CHATGPT_FANOUT unset: sample on the cloud, off on self-host. An unknown value is off and logged once. - Health report: sampled ChatGPT needs 7 x FANOUT_MIN_ANSWERS answers before a silent week or a silent day is flagged; if the extra days can't be read, only ChatGPT goes unjudged. - Web: ChatGPT is neither "shares" nor "not shared" on the Query Fan-out page, and its copy says ChatGPT's searches are sampled on some days. - Docs: per-location cost, nightly-only, and the UTC-midnight caveat; the probe notes the legacy sources/footnote check still to run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
…out-legacy # Conflicts: # server/src/lib/cloro-scraper.js # server/src/workers/tracking-worker.js # supabase/schema.sql
|
Merged main forward (conflicts in Typecheck and the conflicted files' tests pass ( |
… and a resent fan-out task its state
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good with 735471a: your conflict fix is right — submitPromptTask sends googleLocationFor(region) — and two tests now pin it (a US-state Google task keeps its state on the nightly submit and on a resend). At merge time main's first-run test mocks submitPromptTask.
What I checked
- Migration 00378. It adds
cloro_pending_tasks.legacy boolean not null default false. On PG 11+ a constant default needs no rewrite, and the table only holds tasks in flight. It's idempotent (add column if not exists). RLS on the table is unchanged: on, with no policies, so only the service role reads or writes it. No new grants or functions. - Cost. The
searchQueriesadd-on is +2 credits per ChatGPT task that asks for it. Withsample(the cloud default) that's one task per prompt × location a week:- +2 credits × (active prompts tracked on ChatGPT × their locations) per week.
- A full Starter workspace (50 prompts, 1 location) is +100 a week. Growth at 200 prompts × 2 locations is +800 a week.
- Only the nightly run's first attempt asks (
source === 'cron' && attempt === 1).claimWaitingJobcounts attempts from 1, so a retry or a recovered job is 2 or more and never asks. Manual runs andanalyze-newareimmediate, so they never ask either. - The 400/422 resend and the FAILED resend (webhook and polling) go without
legacy, so they never pay the add-on twice. They do cost a second base task when Cloro charges for the failed one. - Self-hosted defaults to
off, and an unknown value isoff.
- Plan gating. ChatGPT (
chatgpt-web) is in every plan's scrapers, and Query Fan-out has no plan feature of its own. So the add-on is spent for every active or trialing workspace that tracks ChatGPT, trials included. Ended plans don't run at all (skipUnpaid). That's consistent with how fan-out is offered today. If trials shouldn't carry the extra credits,runAsksChatgptFanoutis the place to add atrialingcheck. - Only ChatGPT's body changes.
buildRequestBodyaddslegacyandsearchQueriesonly forchatgpt-webwhen asked. The other engines' bodies are pinned withtoEqual. - Webhook resend. The new pending row is inserted after the new task is submitted, and the old one is deleted. An ended plan or an empty
CLORO_WEBHOOK_URLdoesn't resend. The resend islegacy: false, so it can't loop. - No PostgREST embeds are added (
prompts.select('text')only). - Tests:
chatgpt-fanout,cloro-scraper,cloro-callback,tracking-worker,reportandopenai-tracker(132), plus the web fan-out tests (9), pass on #1756's head (which contains this one).
Merge on main: conflicts in server/src/lib/cloro-scraper.js and server/src/workers/tracking-worker.js, with #1730 (Google AIO / AI Mode from a US state, by its name). This needs more than a text merge. #1730 now passes location: googleLocationFor(t.region) where this PR's submitPromptTask passes location: city?.google. When resolving, submitPromptTask has to take googleLocationFor(region), or state-level Google tasks lose their location. That applies to the nightly submit and the webhook/polling resend alike. A test that a US-CA Google AIO task submitted through submitPromptTask sends the state's name would catch it.
Follow-ups
- Data on sampled days. On any day, about 1/7 of ChatGPT answers come from the legacy desktop interface. The PR already asks for a check of
sources/footnoteon a legacy answer (#1119's footnote filtering). It's also worth comparing mention and citation rates of legacy vs default answers over the first week. A systematic difference would show up as a weekly ripple per prompt. - Watching the spend. The submit log now counts
chatgptFanoutper run. A line in the weekly health report with the week's legacy task count would make the credit use visible without reading logs.
Summary
ChatGPT's query fan-out has been empty since 2026-09-30 (#1119). Cloro's default ChatGPT interface stopped carrying the query text. Sending
legacy: truewithinclude.searchQueries: truebrings the searches back: a test request on 2026-10-29 returned them, withmodel: gpt-6. ThesearchQueriesadd-on costs +2 Cloro credits per task, so this turns it on for each prompt one day a week instead of every day.When a ChatGPT task asks for fan-out
sha256(prompt_id)(first 4 bytes)% 7, compared with the run'sgetUTCDay(). No state is kept, a prompt keeps its day, and all its locations fall on the same day.source === 'cron'andattempt === 1). Manual checks,analyze-new, job retries and recovery never ask, so they never add credits.CLORO_CHATGPT_FANOUT(server/src/lib/chatgpt-fanout.js):sample: the default on the cloud.all: every ChatGPT task asks.off: the default when self-hosted, so an upgrade doesn't start spending credits by itself.off, with one warning in the log.allis +2 on every ChatGPT task.buildRequestBodyadds the two fields only forchatgpt-webwhen asked. Google AIO, AI Mode, Shopping, Copilot, Perplexity, Gemini and Grok send exactly what they send today, andcloro-scraper.test.jspins that withtoEqual.If Cloro refuses or fails a legacy task, the day's answer is still tracked
legacy. Network errors, timeouts, 429, 5xx, 401 and 402 are not resent this way: on a network error Cloro may already have created the task, and a resend would charge twice.submitScraperTaskerrors now carry the HTTPstatus.cloro-callback.js) and polling resend a failed legacy ChatGPT task once withoutlegacy. Webhook mode reads this from the newcloro_pending_tasks.legacycolumn (00378); polling reads it from the submit record. The webhook doesn't resend for a brand whose plan has ended, or whenCLORO_WEBHOOK_URLis empty.Health report (
server/src/lib/health/report.js)samplemode: ChatGPT is judged over the last 7 days, and the "no fan-out at all" warnings (weekly, and daily on a big install) need at least 140 ChatGPT answers (7 ×FANOUT_MIN_ANSWERS). A few sampled answers with no searches are ordinary chance, not an outage.alljudges ChatGPT daily, like Copilot;offleaves it out.Web
chatgpt-webas neutral (unknown), not "not shared".en.jsonlines that said ChatGPT doesn't share its searches now say they are sampled on some days.Docs:
docs/guides/prompts.mdxhas a new "Query Fan-out" section with a### ChatGPT fan-outsubsection. It anddocs/self-host/env-variables.mdxandserver/.env.exampledocument the modes, the per-location cost and a self-host note: a cron near UTC midnight can sample a prompt 0 or 2 times in a week.Related issue
Follows #1119 (ChatGPT fan-out stopped arriving on 2026-09-30).
Type of change
feat— New featurefix— Bug fix (ChatGPT fan-out missing)How to test
legacyoncloro_pending_tasks, and without the column the pending rows can't be inserted and webhook results would be lost.chatgpt-fanout.test.js: each prompt asks on exactly one day in 7, 700 prompts spread over the week, and how each mode and value is read.cloro-scraper.test.js: the request body with and without legacy, and the 400/422-only resend.cloro-callback.test.js: a FAILED legacy task is resent without legacy.tracking-worker.test.js: onlychatgpt-web, only the nightly first attempt.report.test.js: the 7-day rules.CLORO_CHATGPT_FANOUT=allfor one run. ChatGPT answers getsearch_querieswithsource_platform: 'chatgpt-web', and the Query Fan-out page lists them.For the maintainer (needs the Cloro key):
node server/src/scripts/probe-cloro-fanout.js, which now sendslegacy: truefor ChatGPT, and checksources/footnoteon a legacy answer. fix(cloro): count only cited ChatGPT sources and stop requesting its empty searchQueries #1119's footnote filtering must still apply on legacy days, or ChatGPT citation counts would jump on those days.Checklist
bash supabase/build-schema.sh:schema.sqlis current (00378)prompts.mdx,env-variables.mdx,.env.example)sources/footnote): the maintainer'sChecks on this branch (ee6cf87): server 280 test files / 3,944 tests (3 skipped); web lint 0 errors (7 warnings), typecheck, 555 test files / 5,315 tests, build OK;
schema.sqlcurrent.🤖 Generated with Claude Code