Repository navigation
Conversation
A run whose attempt is waiting on a chained run reports status paused, so the client now waits until the run is completed, failed or canceled. The README no longer claims a parent awaiting a retry-as-poll task keeps running; the docs only say its attempt is paused.
jacobprall
left a comment
There was a problem hiding this comment.
Requesting changes. urllib.request.urlopen accepts file:// and ftp://, unlike fetch in the TypeScript version. The download is also uncapped.
Example PRs in this repo edit the root README table and will conflict if merged sequentially. The repo has no CI. Confirm default model IDs before publish.
| matter how big the CSV is (a run's arguments are capped at 4 MB). | ||
| """ | ||
| if csv_url: | ||
| with urllib.request.urlopen(csv_url, timeout=30) as resp: |
There was a problem hiding this comment.
urllib.request.urlopen accepts file:// and ftp://. A caller-supplied csv_url such as file:///etc/passwd or file:///proc/self/environ is read, parsed as CSV, and sent to OpenAI.
The TypeScript version uses fetch(), which does not read file: URLs. Allow only http/https, as in product-image-import and ffmpeg-transcode. Cap the size, e.g. resp.read(MAX + 1), as in pdf-extraction.
There was a problem hiding this comment.
Fixed in 9144448: csv_url must be http or https, including after redirects, and the download stops at 5 MB (MAX_CSV_BYTES). file://, ftp:// and oversized files come back as errors. The default model is gpt-6.2-sol, the same as the other examples, and set by OPENAI_MODEL.
There was a problem hiding this comment.
Confirmed in 9144448: the scheme is checked on the URL and on redirects; the read is capped at MAX_CSV_BYTES (5 MB); invalid schemes and oversize downloads are returned as results.
# Conflicts: # README.md
urllib.request.urlopen also opens file:// and ftp:// URLs, so a csv_url like file:///proc/self/environ would be read and sent to OpenAI. Allow only http and https, including on redirects, and stop reading past MAX_CSV_BYTES (5 MB).
jacobprall
left a comment
There was a problem hiding this comment.
Approve. 9144448 rejects non-http(s) CSV URLs, including after redirects, and caps the download at MAX_CSV_BYTES (5 MB). Invalid schemes and oversize files are returned as results.
Summary
Adds
batch-enrichment/: enrich every row of a CSV of companies (industry, size bucket, one-line summary) through the OpenAI Batch API, which costs 50% less than normal calls but can take up to 24 hours.submit_batch(ctx, csv_url=None): reads the CSV (bundledcompanies.csvor a URL), holds back invalid rows, builds one/v1/responsesrequest per row with a strict JSON schema, uploads the JSONL and creates the batch. Before creating, it looks for a batch with the samejob_key(hash of rows + model + prompt version) in the batch metadata and reuses it.wait_for_batch(ctx, batch_id):flex,timeout_seconds=86400. Checks the batch everyBATCH_POLL_SECONDS(default 60) and sleeps in between, in one attempt. Errors while checking are logged and tried again on the next check.collect_results(ctx, batch_id, csv_url=None): downloads the output and error files, validates every answer with pydantic, joins bycustom_id, and returns enriched rows plus afailedlist.enrich_csv(ctx, csv_url=None): chains the three.max_retries=0, 24 h timeout.client.pystartsenrich_csvwithstart_task, then checks it withget_task_run.Motivation
One of the 12 new examples. Trigger.dev (Smart Spreadsheet), Vercel (Lead Agent) and Inngest (CSV import) all ship CSV or lead enrichment. Nothing in Render's examples waits on a slow external job, and Render has no durable sleep, so the example has to show an honest way to wait for hours.
Design notes
How to wait: a sleep loop on flex, not "retry until done". Measured on Render with a throwaway probe workflow (deleted):
max_retries=30, wait_duration_ms=20000, backoff_scaling=1.0, raise until ready): 25 attempts (24 retries), then success. Each retry boots a fresh instance about 0.5 s before the code runs (pid 1 age 0.55 s, ~0.54 CPU-s of startup each), so nothing runs during the wait. But the API records each retry attempt as starting when the previous one failed (every retry attempt shows 20.7 s = 20 s wait + 0.7 s of code). The docs don't say whether that wait is billed.max_retries=1000andwait_duration_ms=86_400_000both registered (versionready). The docs give no maximum.Both cost cents. The sleep loop keeps the retry budget for real errors, doesn't show every check as a failed attempt, and a parent awaiting a retry-as-poll task still has an open attempt for the whole wait (status
paused; the docs don't say whether a paused attempt is billed). The README has the comparison table.24 h fit. OpenAI's only window is
24hand it returns partial results onexpired, so the batch reaches a final status about whenwait_for_batchwould time out. If it runs past,enrich_csvtimes out. Rerunning with the same CSV reuses the batch via the job key, so nothing is paid for twice. That's also whyclient.pydoesn't set a Render idempotency key: a key would hand back the failed run for 24 h instead of resuming.Arguments stay small. Tasks pass the CSV URL and the batch ID, never rows (4 MB argument cap).
enrich_csvreturns rows inline; the README says to write to storage for big files.Retries.
submit_batchandcollect_results2× (safe: idempotent submit, read-only collect),wait_for_batch1×,enrich_csv0. OpenAI client retries off. Errors a retry can't fix (missing key, unreadable CSV, OpenAI 400/401/403/404/422, batch failed validation) are returned.Pins:
render==1.11.0,openai==3.60.0,pydantic==2.14.4(same as openai-agents-sdk). Default modelgpt-6.2-sol(envOPENAI_MODEL); verified with the Batch API + strict json_schema.Test plan (real results)
requirements.txt(Python 3.12), import OK.render workflows dev --port 8440 --env-file <root .env>,enrich_csvwith[]: real batchbatch_6b099280…, completed after 170 s waiting; 11 of 12 rows enriched,C-011reported asRow has no company name. Sample:C-001 Manufacturing 51-200,C-004 Fintech 201-1000,C-008 Healthcare 1000+.enrich_csv []→reused_batch: true,waited_seconds: 1, same batch, no new batch.["https://example.com/does-not-exist.csv"]→{"error": "Could not read the CSV: HTTP Error 404: Not Found"}, no retries.wait_for_batch/collect_resultswithbatch_doesnotexist→ returnedOpenAI error 404.OPENAI_API_KEY→{"error": "OPENAI_API_KEY is not set"}.OPENAI_MODEL=gpt-does-not-exist→ batch fails validation;enrich_csvreturnsBatch failed validationwith OpenAI's per-linemodel_not_founderrors.RENDER_WORKFLOWS_TEMPLATES_PYTHON=<worktree> render workflows init --language python --template batch-enrichment …, followed the steps (port 8444,--env-fileinstead of pasting the key):enrich_csv []completed, 11/12.wfx-batch-enrichment-py: before the key was linked,enrich_csv []→OPENAI_API_KEY is not set(runtrn-08t4gdc4pbgbvdgeg009ba5s0).workflows-examples, released a new version.enrich_csv []→ reused the local batch, completed in 12 s (trn-08t4gdc4pkjqqovrg00c2jcs0).enrich_csvwith a 7-row CSV passed as adata:URL (so the job key differs) → batchbatch_6b099a6e5514…, waited 121 s, 6 of 7 enriched,C-011failed (trn-08t4gdc4pkqf2qerg00bsf4o0). Run tree: 4 runs, each 1 attempt, 0 retries.WORKFLOW_SLUG=wfx-batch-enrichment-py python client.pyagainst Render →Enriched 11 of 12 rows. The first TS client run exposed that a parent waiting on a chained run reportspaused; both clients now wait untilcompleted/failed/canceled(third commit) and were rerun green.wfx-batch-enrichment-py,wfx-batch-enrichment-tsand the probe workflowwfx-batch-enrichment-probe(all 204); deleted branchrt/batch-enrichment-probe.Commits:
Add batch-enrichment example,Add batch-enrichment to the root README, thenbatch-enrichment: wait through paused runs in the clientPlease squash-merge.Risks and rollout