5 Commits
Author SHA1 Message Date
yetone a6efe07cd7 davsync: a GitHub backup too large for one request goes up in parts (Zhang-Wei, Discord)
Zhang-Wei (Discord, v0.1.1327) saw every GitHub sync fail with "GitHub
sync: HTTP 422: Sorry, your input was too large to process. Consider
creating the blob in a local clone of the repository and then pushing it
to GitHub." Their exported backup is 50.8 MB; with the library's sync off
it works. 93b87d000 sends a backup as one base64 blob in one POST
/git/blobs, so 50.8 MB is about 68 MB of request body. GitHub documents
100 MB per blob (on read) but no request size for creating one; a 19 MB
file's Contents PUT (about 25 MB of body) did go through.

A backup over 16 MiB (githubPart) now goes up in parts, in the same one
commit: magpie.magpie-backup.parts/1, /2, ... beside it, and at the
backup's own path a short list (format magpie-backup, version 2, split
github-parts, total size, each part's blob SHA and size). The version is
the list's blob SHA, and the list names each part by blob SHA, so one
version pins one whole set. get() reads the list, downloads each part by
that SHA (as large single files already were), checks each part's git
blob SHA and the sizes, and returns the backup whole; a list that doesn't
add up or a part that isn't the one named is an error. A write removes
the parts the list at the head named and the new backup doesn't use, in
the same commit (only paths known to be there, so the tree never names a
missing path). Blobs already sent are kept across a non-fast-forward
retry. The errChanged check at the head, the ref update without force and
the three rebuilds are unchanged. Backups up to 16 MiB stay one file; the
64 MiB total (four parts) stays, the bound the library's skill budget is
sized for. An empty repository's first backup in parts skips the Contents
API and follows the README note commit.

Why parts, not compression: the sealed bundle is uncompressed JSON with
skill files base64 inside, so compressing would shrink it, but that is a
backup format change for every backend and every export, every other
computer would need the new magpie even for WebDAV and S3, and it still
bounds nothing on GitHub's side. Parts keep the format and touch GitHub
only.

Older magpies: the list opens in backup.Open (unchanged since efbe5660b)
as format magpie-backup with no kdf and version 2, so it says "this backup
was made by a newer magpie; update magpie to open it" and stops: not
ErrCorrupt or ErrNotBackup, so no rebuild over it and no replace offered.
A backup in one file, from any magpie, still reads.

Library: nothing found that shouldn't be carried, so no second commit.
readSkills already skips .git and caps skill files at 32 MiB (about
57 MiB sealed). The skills on this machine (~/.claude/skills, 64 skills,
43 MB; ~/.agents/skills) hold no node_modules, __pycache__ or .venv; the
large files are real assets (images). Leaving node_modules out could break
a skill that ships its dependencies. Zhang-Wei's folders weren't seen.

Tests (fixture only, no network): the fixture refuses a blob POST over
24 MiB with GitHub's text, and serves any blob by SHA. New in
github_parts_test.go: TestGitHubSplitBackup (50.8 MB in four parts, one
commit, byte for byte back, errNotModified, stale put errChanged, then
two parts and back to one file with no part left),
TestGitHubOneFileBackupStillReads (old small and 30 MB single files read;
parts replace one), TestGitHubPartsOlderMagpie, TestGitHubPartsDamaged,
TestGitHubPartsBranchMovedMeanwhile, TestGitHubEmptyRepositoryPartsBackup
and TestGitHubSyncLargeLibrary (a ~38 MB instruction text syncs to a
second computer through Now). TestGitHubLargeBackup now uses 15 MB, to
keep covering one blob over the Contents API's limit.
docs/subsystems/sync-backup.md says how parts work and names the tests.

Record, at base origin/main e435b8867 plus this change (Go 1.26.8,
GOMODCACHE/GOCACHE pinned):
- gofmt -l internal/davsync: nothing. go vet ./... (darwin): clean.
  GOOS=linux go vet -tags nogui ./internal/davsync/...,
  GOOS=windows go vet ./internal/davsync/...: clean.
- go test -tags nogui -count=1 ./internal/davsync/... ./internal/settings/...
  ./internal/cli/... ./internal/backup/... ./internal/library/...: all ok
  (davsync 58s, settings 30s, cli 47s, backup 8s, library 127s).

Red on the old github.go (new tests, a shim for the new names): every new
test fails, the split ones with the reporter's 422 text, OlderMagpie with
"not a magpie backup" (the old code wrote the backup as is).

Broken by hand on the new code, each red:
- stale parts kept: TestGitHubSplitBackup
- part SHA not checked: TestGitHubPartsDamaged/a_part_changed
- blobs sent again on retry: PartsBranchMovedMeanwhile/another_file
- version check at the head skipped: SplitBackup, PartsBranchMoved/
  the_backup, and the older Remote, LargeBackup, BranchMoved tests
- no split (threshold at 64 MiB): SplitBackup, OneFileBackupStillReads,
  PartsOlderMagpie, PartsDamaged
- sizes not added up: PartsDamaged/sizes
- list's format "magpie-backup-parts": PartsOlderMagpie
- empty repository tries the Contents API first: EmptyRepositoryPartsBackup
- list's version 1: OlderMagpie still passes, since old Open also stops
  on the missing kdf; version 2 is a second guard, not the only one.

Not tried: the real GitHub API (no test repository here); the 16 MiB part
is chosen under the largest body seen accepted, not a documented limit.
The full go test ./... and internal/gui's tests were not run: the disk had
under 500 MB free. -race not run; no goroutine was added.
2026-10-23 10:35:44 +08:00
yetone 93b87d0004 davsync: a GitHub backup too large for the Contents API goes up as a blob (Zhang-Wei, Discord)
Zhang-Wei (Discord, v0.1.1318, 102 skills) saw every sync fail with
"GitHub sync: HTTP 422: Sorry, the file is too large to be processed"
on magpie/magpie.magpie-backup; the last backup that went up was about
19 MB. The Contents API's PUT refuses files well under the 100 MB a blob
can hold.

A repository with commits is now written through the Git Data API:
the ref's head, the file's version at that head (it must still be the one
sync read, or errChanged), a base64 blob, a tree on the head's tree, a
commit with the head as its parent, and a ref update without force. Still
one commit per write or removal, and the version is the blob SHA as
before. A ref update that is not a fast-forward is built again on the new
head (the blob is kept), up to three times, then errChanged; if the new
head changed the backup it is errChanged at once, so another computer's
backup goes through the normal merge. A branch deleted meanwhile is an
error, not created. Usage files and their removal take the same path.

An empty repository has no head to build on, so its first write still
goes through the Contents API (one commit, unchanged). If that is refused
as too large (422 "too large" or 413), a short README.md in magpie's
folder makes the first commit and the backup follows as the second.

Reading was already right for large files: the object media type gives
encoding "none" over 1 MB and bytes() downloads by blob SHA; the new
test covers it at 21 MB.

The fixture now serves the Git Data API (blobs, commits, trees, a
fast-forward-only ref update) and refuses a Contents PUT over
contentsLimit with GitHub's 422 text. docs/subsystems/sync-backup.md says
how writes go and names the new tests.

Record for this push: 13 commits on origin/main ca4a1cde0, head tree
539c84e92. Go 1.26.8, sandbox HOME, GOMODCACHE/GOCACHE pinned. The full Go
run and vet were at tree d6393dfc8, the same Go code as this head: only
app.js comments (cut under the core script budget) and one ja string
changed after it.
- gofmt -l: nothing. go build ./...; go vet ./... (darwin), GOOS=linux
  go vet -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -timeout 45m ./..., through tee, one suite on the machine:
  68 packages ok. The one red was internal/gui's
  TestCoreScriptBudget: app.js 1,335,314 > 1,335,000, since main grew
  app.js under the stack. The autoscroll commit's own comments were cut
  (to 1,334,629) rather than the budget raised, and go test -count=1
  ./internal/gui is ok at this head (113s). Packages the run took from
  Go's test cache had the same inputs.
- GUI: the 18 files this stack touches or names, both engines,
  202 of 204 pass (tree 068acf128, this push less the last commit). The
  two reds: gui-ja, red on main since c2636b7b5 and fixed by this push's
  last commit (gui-ja and i18n-keys 6 of 6 there), and usage-fold's
  chromium "several accounts" (#2163, red on main the same way).
- internal/davsync and internal/cli ok, the GitHub large-backup tests and
  TestGitHubCmd among them.
- s3-sync.test.cjs (WebKit en) is red alone on main too: #2448, the
  header over the form's tick. This commit doesn't touch the GUI.
  The whole GUI suite ran at 1c1fc7183 (this stack's first 12 commits on
  0ddcf28a1): 11713 of 11769 pass. Each of the 21 red files was then run
  alone at the stack and at origin/main 8278fd9b0. Eight are red the same
  way on main: plugin-card-update (#3079), quota-count-wrap and
  quota-name-translated (#2228), s3-sync (#2448), usage-agents-hide
  (#2276), usage-checkin (#3091), usage-fold's chromium "several
  accounts" (#2163), usage-ledger (#3104). The other 13 pass alone on both
  and were red only under that run's load (50 to 335): currency #3101,
  plugin-github #3218, provider-fetch-again #3292, rest-try-now #2564,
  routing-auto-reset #3293, routing-keys-fold #1612, routing-steady #1804,
  routing-wb-restricted #1905, sessions-folder-delete #2218,
  sessions-manage #3294, switch-only #3295, text-size #1866, usage-pack
  #3296.

Red on the old github.go (the new tests with the old code):
TestGitHubLargeBackup and TestGitHubEmptyRepositoryLargeBackup fail with
"HTTP 422: Sorry, the file is too large to be processed", TestGitHubRemote
too at its 1.26 MB put, and TestGitHubBranchMovedMeanwhile's three
subtests fail.

Broken by hand on the new code, each red:
- version check at the head skipped: TestGitHubRemote, LargeBackup's
  stale put, BranchMovedMeanwhile/the_backup
- no rebuild on a non-fast-forward: BranchMovedMeanwhile/another_file
  and /the_backup
- large read by base64 only: TestGitHubRemote, TestGitHubLargeBackup
- no README initialization: TestGitHubEmptyRepositoryLargeBackup (409)

Not tried against the real
GitHub API: the fixture follows GitHub's documented Git Data API, and
GitHub's exact Contents API size limit is not documented.
2026-10-23 01:58:00 +08:00
yetone f82aba090b davsync, gui, cli: GitHub sync refuses a repository that isn't private (#1130)
The sealed setup is committed on every sync, so a public repository would
hand anyone every version of it, the whole history, to try passphrases on
offline. prepare now reads the repository's "private" field and refuses
before writing when it is false or missing, naming the repository and what
to do. The form's hint, the CLI usage and docs/reference.md say the
repository must be private; sync-backup.md lists the rule and its
verification command now points at ./internal/cli.

Run: go test -tags nogui ./internal/davsync/ and the cli tests
(TestGitHubCmd|TestWebdavCmd|TestS3Cmd|Help) green;
TestGitHubPublicRepositoryRefused goes red with the check removed. GUI:
github-sync, s3-sync, webdav-settings-refresh, sync-other-kind,
sync-not-backup, i18n-keys, gui-zh-tw, gui-ja, gui-de in Chromium and
WebKit, 72/72. Not tried against the real GitHub API.
2026-10-13 15:25:10 +08:00
yetone cdfe7629a5 davsync: GitHub sync's "not a magpie backup" advice names the file where it is, not under magpie/magpie/ (#1130)
fileWhere passed folder+"/"+file to g.at, which already puts the file under
the configured folder and magpie/, so the recovery advice told the user to
look at <folder>/magpie/magpie/sync.json, a file that isn't there. It now
passes the file alone.

Run: go test -tags nogui ./internal/davsync/ (green). TestGitHubNotBackup's
new assertion goes red with the old path put back.
2026-10-13 15:25:07 +08:00
bingqilinweimaotai 1af326806f sync: magpie's setup syncs to an encrypted file in a GitHub repository, beside WebDAV and S3 (#1130)
A third sync kind: github://owner/repo[/folder] keeps the same sealed
backup WebDAV and S3 keep, as <folder>/magpie/magpie.magpie-backup in a
repository the user already has, written through GitHub's Contents API
with a fine-grained token of its own (Contents read and write), kept in
sync.json apart from the library's GitHub token. The token goes only to
api.github.com: a redirect anywhere else is refused, and the passphrase
may not equal it. Each update is a commit; an empty repository is
initialised by the first backup. Settings › Sync gets a GitHub kind with
Repository, Branch, Folder and token; magpie github mirrors magpie s3.
Inactive servers of every kind are kept in Config.Servers (Other stays
for older clients).

Squashed from yetone/magpie#1130 at 6b5b1c693e1a3a23e177b4d376f3f7f70f3bc23d
onto main. Merge resolutions: the CLI moved to internal/cli since the PR
was cut, so github_cli_test.go moved there (package cli) and the github
command, its help line and `magpie help github` were wired in
internal/cli/main.go and help_cli.go; README's Sync row kept main's
links and took the PR's wording; i18n.js zh-TW kept both sides.
2026-10-13 15:25:06 +08:00