Repository navigation
Stream s3_lock via continuation token, fix CF cap on small datasets - #386
Conversation
The offset-based applyObjectLock paginated the entire dataset's S3 prefix on every invocation (full ListObjectsV2 plus a 40-PUT slice). Per-invocation cost was ~7 D1 + ceil(N/1000) LIST + 40 PUTs which tripped Cloudflare's per-invocation subrequest cap on the SCCN deployment for datasets with even a few hundred objects. The CLI's cross-invocation retry from #382 reinvoked correctly but every fresh invocation hit the same cap. Switch to S3 ListObjectsV2 continuation-token streaming: - New applyObjectLockBatch issues exactly one LIST page (max-keys=15) plus up to 15 PutObjectRetention calls per invocation. Returns the next continuation token on hasMore. Subrequest cost is now bounded at ~22 regardless of dataset size. - Backend route accepts s3_lock_continuation_token in the body and returns it in the hasMore response. Legacy s3_lock_offset still parsed but ignored, so v0.8.4-and-earlier CLIs don't reject the request. - CLI approvePublication threads the continuation token through its existing retry loop in place of the offset. - Standalone POST /admin/datasets/:id/s3-lock updated to match. Idempotent on retry: 403 (already-locked) keeps counting as success, so re-invoking with the same continuation token after a transient failure replays the same batch safely. Closes #385
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR386Version: 🤖 Updated on each push. |
Both review agents converged on five real issues with the
continuation-token migration. All addressed:
1. CLI applyS3Lock (nemar admin s3 lock) was structurally broken: still
sent body.offset (server ignores), read result.total/failed:string[]
(server returns failed:{key,error}[]), and would infinite-loop
re-locking page 1 of any dataset > 25 objects. Rewritten to thread
continuation_token; S3LockResponse interface fixed; CLI command
formats {key,error} pairs; defensive guard prevents loop on
server-side missing-token bugs.
2. applyObjectLockBatch silently stopped streaming when S3 returned
IsTruncated=true with no NextContinuationToken (contract violation
or proxy bug). The dataset would be left partially locked - exactly
the failure mode S3 Object Lock exists to prevent. Now throws so
the orchestrator surfaces a 500 and the CLI retries.
3. Empty-page mid-stream early-returned hasMore=false and dropped the
live continuation token. Subsequent pages of objects would never be
locked. Now preserves the token on the empty-page path.
4. Schema accepted legacy s3_lock_offset for "back-compat" but this
was a footgun: the new server doesn't return s3_lock_offset on the
response, so an old CLI's pagination loop breaks out on the first
hasMore=true and silently reports lock complete after only the
first batch. Replaced silent-ignore with explicit 426 Upgrade
Required so admins running old CLIs see a clear error instead of
corrupt-by-omission success.
5. Partial-fail (failed.length > 0) returned 500 without echoing the
continuation token. The CLI's retry would lose its place and
re-stream from page 1. Now echoes the token so retry replays the
exact failing batch (idempotent: 403=already-locked).
Also bumped batchSize 15 → 25: still well under any plan's
per-invocation cap, halves CLI round-trips for medium datasets
(702-object dataset goes from 47 to 28 batches).
Added 426 test case to publish-retry-classifier; verified the upgrade
error is not retried (otherwise old CLIs would loop indefinitely).
/review-pr findings + responsesPushed Critical/High — addressed1. Standalone CLI 2. Truncated-with-missing-token = silent partial lock. 3. Empty-page early-return stranded the continuation chain. 4. Old CLIs (v0.8.4 and earlier) silently report "lock complete". The schema accepted legacy 5. Partial-fail response didn't echo the continuation token. On Important — addressed6. Important — deferred (separate issue)7. Large-dataset strategy ceiling. At Comment / regex / replayThe comment-analyzer-style checks (continuation-token regex correctness, idempotency on replay, ListObjectsV2 contract guarantees) all came back clean from the reviewers. AWS doesn't emit prefixed forms of Test results
|
A lot of its state moved on 2026-09-20 and 2026-09-21. #387 and #397 merged, #399 landed the Python 3.12 floor and the Pyodide-bounded dependency floors, #402 corrected #399, and #403 is open to merge develop into the epic branch. Records the correction rather than quietly restating the conclusion: only compiled floors are a ceiling in the browser, because the test is whether the package publishes a pure-Python wheel and not whether Pyodide bundles it. The earlier claim that threadpoolctl>=3.6.0 was a live broken install was wrong. Also records the integration bug #403 exposed, since it is the argument for not letting the epic branch drift again: MemmapData.__array_function__ returned NotImplemented for everything except copyto and put, and defining that method opts a type into numpy's dispatch protocol where NotImplemented raises rather than falling back. Develop's #351 test covers that path and the epic branch never had it. Notes that the case for holding #386 is weaker now that the epic branch is no longer behind, and carries #400 and #401 as open.
Closes #385.
What broke
`nemar admin publish approve nm000130` (702 S3 objects) hit "Too many subrequests by single Worker invocation" inside the s3_lock step on the SCCN deployment, even after #383's cross-invocation retry. Every retry re-invoked correctly but hit the same cap — because each `applyObjectLock` call paginated the entire dataset's S3 prefix before locking 40 keys.
Root cause
Per-invocation cost was: ~7 D1 + ⌈N/1000⌉ LIST + 40 PUTs. For a 700-object dataset that's ~48 subrequests, at or over the cap on whatever plan the SCCN account is on (default subrequest budgets vary across plans, and the wrangler 3 → 4 bump in #1153e53 may also have affected accounting). User confirmed the same code worked pre-0.8.0 on the previous `neuromechanist` account.
Fix
Switch `applyObjectLock` (offset-paginated, full-list every call) to `applyObjectLockBatch` (continuation-token streamed). Each invocation issues:
Total: ~16 S3 subrequests + ~7 D1 = ~23 per invocation. Comfortable headroom on every plan tier, and constant regardless of dataset size.
Behavior
Out of scope
Test plan