Bulk surveys: answered through the provider's batch service

A survey can be sent to the model provider in bulk instead of live. The provider answers it at half the price and without touching our live rate limit, but in hours, not minutes. The result is the same kind of result: same respondents, same questions, same report.

What it does

An interview has two turns, and the second depends on the first, so a bulk survey goes to the provider in up to three stages:

Stage Sent Skipped when
first Every respondent's first question never
second The paid question, to respondents who answered the first the study has no paid offer
rate The separate rater's 1 to 5 rating of every answer nobody answered

Each stage is usually back within the hour; the provider's limit is 24 hours per stage. While a stage is with the provider the survey holds no worker, so live surveys carry on.

For the person who ran the survey

The study page shows "The panel is answering" with: "This survey is being answered in bulk. That usually takes one to three hours and can take up to a day. You can close this page; we email you when the result is ready." Nothing else differs. The sample card of the result says "Answered through the provider's batch service."

Which surveys go in bulk (operator)

Decided at the moment a survey joins the queue, from two settings shown on the console's Now tab:

Setting Meaning Default
batch_when_waiting A free survey goes in bulk when at least this many free surveys are already waiting. 0 means never 0
batch_plans Paid panels that always go in bulk panel-5000

Change them (operators only): POST /admin/ops/batch-settings with {"batch_when_waiting": 25, "batch_plans": ["panel-5000"]}. The change is logged and applies to surveys queued from then on.

How to choose batch_when_waiting: two workers clear about 40 free surveys an hour. At 25 waiting, a new arrival would wait over half an hour live; in bulk it waits one to three hours but costs half and leaves the live lane to people already in it. Start at 25 and watch "oldest wait" on Now. Paid panels of 300 and 1,000 should stay live: buyers expect minutes.

Getting started (owner)

  1. Apply 0009_batch.sql after 0008 and run the three verification queries in its header.

  2. Restart the workers. Nothing else is needed: with the defaults no free survey goes in bulk.

  3. Test with real money once, by hand, on the desktop (about half the live cost):

    python -m marketsim run examples/study-example.json --provider anthropic --batch --out bulk.json --yes
    

    It prints each stage while it waits. Expect it to take up to a few hours.

  4. To sell the 5,000 panel: after step 3 has worked, set BATCH_PANELS=1 on the API (see Payments setup).

  5. To send free surveys in bulk on busy days: set batch_when_waiting as above.

  6. If you scheduled the alert check in the database (article 20, step 6), schedule select public.ops_check_batch(); beside it.

[unverified]: the batch calls are written from the provider's SDK documentation and tested with a stand-in. Step 3 is the first real run.

How it behaves

Behaviour Detail
Collecting A worker looks at each waiting survey about once a minute. A look that finds it unfinished costs nothing and spends no attempt
A worker dies while collecting The survey returns to the queue after 2 minutes and the next worker picks up the same stage. Nothing is sent twice
The provider cannot be reached The survey stays waiting and is looked at again a minute later
Missing answers A request the provider failed, cancelled or let expire is a missing respondent. Over 20 percent missing fails the attempt and the survey starts again from the first stage, up to 3 attempts
Cost Half the live price per token. Recorded on the survey when it finishes
Free daily budget A free bulk survey commits the same estimate as a live one, so the budget is conservative
Stopping The owner cannot take a bulk survey out once it has started. An operator can stop it; the stage already sent is still billed by the provider
Limits One stage holds at most 100,000 requests or 256 MB; a 5,000 panel is about 5,000 requests per stage

Troubleshooting

Symptom Cause Fix
A bulk survey shows "The panel is answering" for many hours The provider's batch queue is slow; up to 24 hours per stage is within its terms Wait. Alert "A paid bulk survey has taken more than 6 hours" tells you when to write to the buyer
Alert: "A bulk survey has been with the model provider for more than 25 hours" A stage expired or the batch id is lost Console, Surveys, "With the provider": Stop for good (paid: refunded automatically), then the owner runs it again; or wait if the provider reports an incident
Alert: "Bulk surveys are not being collected" No worker has looked for 15 minutes Start or restart a worker
A bulk survey fails with "the batch request was expired" in the reason The provider did not finish the stage in 24 hours It is retried from the start by itself; after 3 attempts it fails and a paid one is refunded
Worker log: "batch ... could not be read" The provider was unreachable or refused the read Nothing if it clears; check the key if it repeats
Free surveys never go in bulk batch_when_waiting is 0, or fewer free surveys are waiting than the number set Set it on the console; see above
The command prints "waiting for stage ..." for a long time Normal for the batch service Leave it running; it resumes nothing if stopped, so a stopped run is paid for and lost