Skip to content

Upload: renew S3 credentials during long copies - #1648

Closed
bruAristimunha wants to merge 2 commits into
nemarOrg:feature/issue-1671-epic-bru-upload-fixesfrom
bruAristimunha:fix/issue-1644-upload-sts-refresh
Closed

bruAristimunha wants to merge 2 commits into
nemarOrg:feature/issue-1671-epic-bru-upload-fixesfrom
bruAristimunha:fix/issue-1644-upload-sts-refresh

Conversation

@bruAristimunha

@bruAristimunha bruAristimunha commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1647 (this branch contains its commit). Draft until that one merges; I will rebase then, and the diff will shrink to the last commit.

Problem

#1644: upload credentials are one STS session capped at 2 h (backend/src/routes/datasets/upload.ts, duration_seconds max 7200), requested once, followed by a single git annex copy over everything. A copy that runs longer fails every remaining file with an expired token and has to be re-run by hand.

Change

New src/lib/upload/s3-copy-session.ts:

  • The pending paths (from the location log, as in Upload: verify every annexed file reached S3 and stop re-reading annexed content on save #1647) are copied in batches of at most 200 files or 50 GiB.
  • Before each batch the lease is renewed when the time left would not cover a 20 min margin plus the longest batch seen so far.
  • Each batch runs under a deadline 2 min before expiry; at the deadline the git annex copy is stopped rather than left to fail every file with ExpiredToken.
  • A batch that hit the deadline or reported an expired-credential error is retried with fresh credentials; the location log skips what already arrived.
  • Renewals are bounded (48). Two consecutive renewals that make no progress, or a failed renewal, stop with an explicit error. Non-credential copy errors are not retried.
  • copyPathsToAnnexRemote takes an optional absolute deadline.

Behavior to know about

  • This relies on git-annex reading AWS_* from the environment before its cached credentials, which the S3 special remote does.
  • A single file that takes longer than one lease (~2 h) still cannot finish: a multipart upload does not resume across git annex copy runs.

Closes #1644

Testing

  • test/upload-sts-refresh.unit.test.ts (new, 12 tests), simulated clock and copy function: a 3 h copy renews once and no batch is killed; ExpiredToken and deadline retries; the renewal bound; no-progress stop; non-credential errors are not retried; batch limits by count and size.

  • Related suites: 237 pass, 0 fail across 16 files that import the changed modules (on this branch rebased on current dev).

  • bun run typecheck, biome check on the changed files.

  • Not exercised against live S3 with a real credential expiry.

  • CI api-test and integration-dev fail on this PR because it comes from a fork: both call the dev API with the TEST_*_API_KEY secrets, which GitHub does not pass to fork pull requests, so the authenticated cases fail and the unauthenticated ones pass. lint, unit-pure and e2e-sandbox run normally.

- git annex copy is driven with --json --json-error-messages; filesCopied
  counts success records instead of scraping 'copy ... ok' lines (nm000358
  logged 'Uploaded 0 data files' while all 165 keys were recorded at
  nemar-s3 during that copy).
- The copy set is taken from the location log (annexed paths not yet at
  nemar-s3), and the post-copy check now requires EVERY annexed file to be
  recorded at the remote, not only this run's targets.
- A data file larger than the annex size threshold that git-annex did not
  annex (policy overridden, e.g. an inherited .gitattributes) now fails the
  upload instead of being committed to git silently.
- saveDataset takes skipContentCheckPaths; the upload's save step marks the
  annexed paths assume-unchanged around git add -A/status/commit so git does
  not stream every freshly annexed unlocked file through git-annex
  filter-process (zero-stat index entries after git annex add). Refs nemarOrg#1455.
- The success line states sent / already-present / verified totals.
Upload credentials are 2 h STS sessions; the upload requested them once and
ran one git annex copy over everything, so TB-scale uploads died part-way
with ExpiredToken and had to be re-run by hand (the iEEG campaign wrapped
the upload in a 12-attempt retry loop).

The pending paths (from the location log) are now copied in bounded
batches (200 files / 50 GiB). Before each batch the lease is renewed when
what is left would not cover a 20 min margin plus the longest batch seen;
each batch runs under a deadline just before expiry, and a batch that is
killed at the deadline or fails with an expired-credential error is retried
with fresh credentials. Renewals are bounded (48), and two consecutive
renewals that deliver nothing stop with an explicit error.

copyPathsToAnnexRemote gains an optional absolute deadline.
@neuromechanist

Copy link
Copy Markdown
Contributor

This original source PR is superseded by epic replacements #1687, #1691, #1693, #1696, and #1699. The complete epic landing is tracked by #1702. #1644 remains open for its documented live-S3 and sandboxCommand acceptance; closing this source PR does not close that issue.

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