Skip to content

feat(tracking): sample ChatGPT's query fan-out one day a week through Cloro's legacy interface - #1755

Merged
gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/chatgpt-fanout-legacy
Oct 29, 2026
Merged

gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/chatgpt-fanout-legacy

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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: true with include.searchQueries: true brings the searches back: a test request on 2026-10-29 returned them, with model: gpt-6. The searchQueries add-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

  • Sampling: a prompt's day is sha256(prompt_id) (first 4 bytes) % 7, compared with the run's getUTCDay(). No state is kept, a prompt keeps its day, and all its locations fall on the same day.
  • Nightly runs only: only the nightly run's first attempt asks (source === 'cron' and attempt === 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.
    • An unrecognised value counts as off, with one warning in the log.
  • Cost: +2 credits per prompt per location per week. For example, 100 prompts × 2 locations = 400 credits a week. all is +2 on every ChatGPT task.
  • Only ChatGPT's request body changes: buildRequestBody adds the two fields only for chatgpt-web when asked. Google AIO, AI Mode, Shopping, Copilot, Perplexity, Gemini and Grok send exactly what they send today, and cloro-scraper.test.js pins that with toEqual.

If Cloro refuses or fails a legacy task, the day's answer is still tracked

  • Refused when sent (400/422): the task is sent again once without 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. submitScraperTask errors now carry the HTTP status.
  • Accepted, then FAILED: both the webhook (cloro-callback.js) and polling resend a failed legacy ChatGPT task once without legacy. Webhook mode reads this from the new cloro_pending_tasks.legacy column (00378); polling reads it from the submit record. The webhook doesn't resend for a brand whose plan has ended, or when CLORO_WEBHOOK_URL is empty.

Health report (server/src/lib/health/report.js)

  • sample mode: 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.
  • Daily drop check: ChatGPT is left out of it, since a sampled share moves day to day.
  • Extra 3-day read: this read completes the week. If it fails, only ChatGPT is marked "could not be checked"; the other engines are reported as usual.
  • Other modes: all judges ChatGPT daily, like Copilot; off leaves it out.

Web

  • The Query Fan-out page treats chatgpt-web as neutral (unknown), not "not shared".
  • The two en.json lines that said ChatGPT doesn't share its searches now say they are sampled on some days.

Docs: docs/guides/prompts.mdx has a new "Query Fan-out" section with a ### ChatGPT fan-out subsection. It and docs/self-host/env-variables.mdx and server/.env.example document 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 feature
  • fix — Bug fix (ChatGPT fan-out missing)

How to test

  1. Deploy order: apply 00378 before deploying the server. The server now writes legacy on cloro_pending_tasks, and without the column the pending rows can't be inserted and webhook results would be lost.
  2. Unit tests:
    • 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: only chatgpt-web, only the nightly first attempt.
    • report.test.js: the 7-day rules.
  3. On staging with Cloro, set CLORO_CHATGPT_FANOUT=all for one run. ChatGPT answers get search_queries with source_platform: 'chatgpt-web', and the Query Fan-out page lists them.

For the maintainer (needs the Cloro key):

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • bash supabase/build-schema.sh: schema.sql is current (00378)
  • Server: format, lint and tests pass (see below)
  • Web: format, lint, typecheck, tests and build pass (see below)
  • Docs updated (prompts.mdx, env-variables.mdx, .env.example)
  • Live legacy answer check (sources / footnote): the maintainer's

Checks 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.sql current.

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 29, 2026 12:15
… 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]>
@mintlify

mintlify Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit d50cec0.

Approve preview

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 29, 2026
…out-legacy

# Conflicts:
#	server/src/lib/cloro-scraper.js
#	server/src/workers/tracking-worker.js
#	supabase/schema.sql
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main forward (conflicts in server/src/workers/tracking-worker.js, server/src/lib/cloro-scraper.js and supabase/schema.sql). Main switched the Google location from city?.google to googleLocationFor(t.region) (cities and US states); this branch had moved that submission into submitPromptTask, so the worker keeps submitPromptTask and submitPromptTask now uses googleLocationFor(region). The JSDoc keeps both sides; the schema is regenerated with build-schema.sh (00378 doesn't collide).

Typecheck and the conflicted files' tests pass (cloro-scraper, tracking-worker, locations, chatgpt-fanout, plus cloro-callback, health/report, job-runner); server lint clean.

@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.

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 searchQueries add-on is +2 credits per ChatGPT task that asks for it. With sample (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). claimWaitingJob counts attempts from 1, so a retry or a recovered job is 2 or more and never asks. Manual runs and analyze-new are immediate, 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 is off.
  • 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, runAsksChatgptFanout is the place to add a trialing check.
  • Only ChatGPT's body changes. buildRequestBody adds legacy and searchQueries only for chatgpt-web when asked. The other engines' bodies are pinned with toEqual.
  • 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_URL doesn't resend. The resend is legacy: false, so it can't loop.
  • No PostgREST embeds are added (prompts.select('text') only).
  • Tests: chatgpt-fanout, cloro-scraper, cloro-callback, tracking-worker, report and openai-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

  1. 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/footnote on 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.
  2. Watching the spend. The submit log now counts chatgptFanout per run. A line in the weekly health report with the week's legacy task count would make the credit use visible without reading logs.

@gkhngyk
gkhngyk merged commit 144e8a2 into ansvisor:main Oct 29, 2026
4 of 6 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.

2 participants