Files
magpie/internal/cli
yetone 9dcec67513 archive: the request archive in an S3 bucket is kept under a GiB, oldest calls removed
An R2 user on X: the sync bucket grew by 18 GB in under a month. The
backup and usage files are small and rewritten in place; what grew was
the request archive, every call written whole (bodies up to 32 MiB) as
archive/<date>/<id>.json and never removed. The archive on this computer
is capped at a GiB; the one in the bucket had no cap.

Now the bucket's archive is held to RequestArchiveMB (a GiB unless set,
carried by sync), down to a tenth under it past the cap, oldest first:
- only keys of ArchiveName's own shape under <prefix>/magpie/archive/
  are counted or removed; the backup, usage, other prefixes and anything
  else in the bucket are never touched (a test seeds seven such keys);
- uploads are counted as they go, and the bucket is listed again only
  after a tenth of the cap more is uploaded: one LIST for ~1000 calls,
  never one per call;
- the serving magpie lists once two minutes after it starts, archive on
  or off, so a bucket grown before this update is brought under the cap
  without the user doing anything (auto-cleanup chosen over a button:
  the objects are magpie's own, already capped locally, and a removal
  is logged);
- the Usage page's switch tooltip says the size ("…in <bucket>, up to
  1.1 GB"), in every language; the core script budget is kept, not
  raised: the two tooltips share one options object and the switch's
  aria-checked is set from a boolean.

The Nov 3 rise in Class B reads has no code cause found: archive reads
are click-driven only, and the backup's conditional GET runs every 3
minutes per computer online.

Red on the old logic (bucketAdded and KeepBucketArchiveBounded made
no-ops by hand, on mica): TestRequestArchiveKeptUnderItsSize "after 200
calls the archive holds 248 calls, 7629310 bytes, over its 1048576 (48
from 2020 left); 0 LISTs, 0 DELETEs"; TestBucketArchiveBroughtUnderIts
SizeAtStart keeps 30 calls / 3000 bytes; TestBucketArchiveListedPer
TenthUploaded "0 LISTs". With the fix: "200 calls: 44 kept, 986389
bytes; 4461157 bytes uploaded, 39 LISTs, 203 DELETEs".

Run at this tree (rebased on c6a67dd41):
- mote: gofmt -l internal clean; go test -timeout 45m -count=1
  ./internal/davsync ./internal/gateway ./internal/settings
  ./internal/settingsapi ./internal/cli: all ok (gateway 897s).
- mica: go test ./internal/gui ok (TestCoreScriptBudget included);
  GOOS=windows go vet of the six touched packages ok; GOOS=linux go vet
  of davsync, gateway, settings, settingsapi ok (gui and cli need
  WebKitGTK's cgo, not vetted for Linux).
- mica GUI, Chromium and WebKit, every language: request-archive,
  request-archive-usage, i18n-keys, i18n-en-no-cjk 22/22 at this tree;
  with call-headers, context-text, routing-bodies, routing-side-calls,
  usage-ledger-search and web-page 114/114 before the tooltip's last
  wording change.

Not tried: a real R2 or S3 bucket (fake S3 only), and the reporter's
own bucket contents.
2026-11-16 11:25:30 +08:00
..