Skip to content

feat(tracking): keep the searches the OpenAI API model ran as its query fan-out - #1756

Merged
gkhngyk merged 7 commits into
ansvisor:mainfrom
cihan-gyk:feature/openai-api-fanout
Oct 29, 2026
Merged

gkhngyk merged 7 commits into
ansvisor:mainfrom
cihan-gyk:feature/openai-api-fanout

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

The OpenAI API model (platform chatgpt, set per prompt, default gpt-5-chat-latest) already runs OpenAI's web_search tool, but the searches it ran were thrown away. This keeps them as the answer's query fan-out, read from the same response, with no extra call or cost.

What changes

  • openai-tracker.js: a new searchQueriesOf(output) reads each web_search_call whose action.type is search.
    • It takes action.queries[] (the current field) and action.query (deprecated), trims them, drops empty ones, and keeps each query once per answer.
    • open_page and find_in_page aren't searches, and a failed search is skipped.
    • runPrompt returns them as search_queries: [{ query, source_platform: 'chatgpt' }], the same shape Cloro's engines write.
  • tracking-worker.js: the model path's insertResult now passes search_queries (it already did on the scraper path). Claude and Gemini models return none, so they write [] (the column's default).
  • Health report: chatgpt is judged on a drop only, not expected every day. A model may run few or no searches, so "none today" isn't an outage on its own. The warning points to OpenAI's web_search, not Cloro.
  • Web: chatgpt stays neutral (unknown) on the Query Fan-out page, so an API model that searched rarely isn't flagged as "shares its searches, but none arrived". Its searches show under ChatGPT API. The en.json lines describe the API models too.
  • Docs: prompts.mdx adds a short "API models' fan-out" section. Claude and Gemini read "we don't capture them yet".

Scope: on the cloud no plan allows API models today (allowedModels: []). So this shows where an OpenAI model is tracked: self-hosted installs and Enterprise workspaces opened up with plan_overrides.

Related issue

Follows #1119.

Stacked on #1755 (ChatGPT fan-out sampled through Cloro's legacy interface). The diff against it holds only this change.

Type of change

  • feat — New feature

How to test

  1. Unit tests:
    • openai-tracker.test.js: queries, query, open_page, find_in_page, a failed search, duplicates, and runPrompt making one call that returns search_queries.
    • report.test.js: chatgpt is judged on a drop only.
    • fanout-platforms.test.ts: fanoutSharing behaviour.
  2. Self-hosted with OPENAI_API_KEY: track a prompt with an OpenAI model. After a run, Prompts › Query Fan-out lists its searches under ChatGPT API.

For the maintainer (needs an OpenAI key): one real answer from the default gpt-5-chat-latest, to confirm it returns web_search_call items with action.queries.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Server: format, lint and tests pass (see below)
  • Web: format, lint, typecheck, tests and build pass (see below)
  • Tests added
  • Real OpenAI answer check: the maintainer's

Checks on this branch (fc6d27a): server 281 test files / 3,948 tests (3 skipped); web lint 0 errors (7 warnings), typecheck, build OK; web tests 555 of 556 files: _before-publish.test.tsx failed on the known focus race that #1753 fixes (untouched here).

🤖 Generated with Claude Code

cihan-gyk and others added 4 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]>
…ry fan-out

ChatGPT's fan-out has come only once a week through Cloro since
2026-09-30. The OpenAI API model's answers carry theirs already: the
Responses web_search calls hold the queries they ran. They were dropped.

- openai-tracker.js: searchQueriesOf reads each web_search_call's search
  action (`query`, and `queries` when given; open_page and find_in_page
  aren't searches) into the fan-out shape [{ query, source_platform:
  'chatgpt' }], trimmed and once each. From the same response: no other
  call, no extra cost.
- tracking-worker.js: the model path's insertResult keeps search_queries,
  as the scraper path does (Claude's gives none: an empty list).
- The Query Fan-out page counts `chatgpt` (the API model) among the
  engines that share their searches (fanout-platforms.ts), and the daily
  health report expects it (FANOUT_EXPECTED), its warning pointing at
  OpenAI rather than Cloro.

On Cloud, API-model tracking is off on every plan (allowedModels []), so
this shows where an OpenAI model is tracked: self-host, or an Enterprise
plan_overrides. ChatGPT's own interface (chatgpt-web) is unchanged here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-ups for the API model's query fan-out.

- Health report: `chatgpt` leaves FANOUT_EXPECTED. gpt-5-chat-latest may
  run web_search rarely or not at all, so a silent day is no news; a fall
  from the days before still is, and points at OpenAI.
- Web: `chatgpt` is neither "shares" nor "not shared" on the Query Fan-out
  page; fanout-platforms.test.ts checks fanoutSharing's answers rather than
  the lists.
- searchQueriesOf reads the action's `queries` first (`query` is
  deprecated) and skips web_search calls whose status is `failed`.
- Copy: the Prompts guide calls it "ChatGPT API" as the page does and says
  Claude and Gemini models' searches aren't captured yet; the empty state
  and coverage tooltip mention the API model.

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 9172a35.

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 and #1755's branch forward (b8f9de3): no conflicts in this PR's own files. Typecheck, the related tests and lint pass.

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

What I checked (this PR's own diff against #1755)

  • No extra provider cost. searchQueriesOf reads the web_search_call items of the response runPrompt already gets. There is no second call and no extra include. Claude and Gemini return no search_queries, so the worker writes [], the column's default.
  • Parsing.
    • Only action.type === 'search' counts. open_page/find_in_page and status: 'failed' calls are skipped.
    • queries[] and the deprecated query are both read. Queries are trimmed, and empty ones and duplicates within an answer are dropped.
    • Non-string values are ignored. The loop is linear in the output items.
  • Shape. { query, source_platform: 'chatgpt' } is the platform API-model results are stored under, so the fan-out reads (and the web's "ChatGPT API" label) line up with the result row.
  • Health report. chatgpt is judged on a drop only, not on missing fan-out every day. That's right for a model that may not search.
  • No migration, no PostgREST embeds, no new routes or server actions.
  • Tests: openai-tracker (including the single-call runPrompt case), report and the web fanout-platforms tests pass on this branch.

Merge on main: this branch contains #1755, so it has #1755's conflicts in server/src/lib/cloro-scraper.js and server/src/workers/tracking-worker.js with #1730. See my note there: submitPromptTask needs googleLocationFor(region). This PR's own lines (the model path's insertResult) don't conflict.

Follow-up

  1. On the cloud no plan allows API models today, so this only shows on self-hosted installs and Enterprise workspaces with plan_overrides. The PR already asks for one real answer from gpt-5-chat-latest to confirm it returns action.queries.

@gkhngyk
gkhngyk merged commit 24207bc into ansvisor:main Oct 29, 2026
4 of 6 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 29, 2026
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