@1agh/maude 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/apps/studio/access/request.ts +0 -1
- package/apps/studio/acp/adapter-stderr.ts +43 -13
- package/apps/studio/acp/background-tasks.ts +155 -0
- package/apps/studio/acp/bridge.ts +44 -5
- package/apps/studio/acp/connected-fact.ts +15 -4
- package/apps/studio/acp/index.ts +14 -5
- package/apps/studio/actions/agents.ts +5 -0
- package/apps/studio/actions/defs/view.ts +12 -0
- package/apps/studio/actions.manifest.json +13 -1
- package/apps/studio/actions.parity.json +7 -1
- package/apps/studio/api.ts +31 -24
- package/apps/studio/asset-placeholder.tsx +157 -62
- package/apps/studio/bin/_png-playwright.mjs +10 -1
- package/apps/studio/bin/_pw-launch.mjs +14 -0
- package/apps/studio/bin/_thumbs-playwright.mjs +4 -1
- package/apps/studio/boot-progress.ts +31 -0
- package/apps/studio/bridge/dgn-protocol.ts +34 -4
- package/apps/studio/canvas-build-sandbox.ts +275 -42
- package/apps/studio/canvas-build-worker.ts +10 -0
- package/apps/studio/canvas-create.ts +24 -0
- package/apps/studio/canvas-module-cache.ts +93 -0
- package/apps/studio/canvas-source/errors.ts +39 -0
- package/apps/studio/canvas-source/waiting.ts +290 -0
- package/apps/studio/client/actions/shell-key-handlers.js +5 -0
- package/apps/studio/client/app.jsx +22 -9
- package/apps/studio/client/github.js +23 -3
- package/apps/studio/client/home/home-api.js +30 -19
- package/apps/studio/client/hooks/use-git-actions.jsx +2 -1
- package/apps/studio/client/hooks/use-shell-core.jsx +3 -0
- package/apps/studio/client/hooks/use-tabs.jsx +64 -35
- package/apps/studio/client/index-loader.ts +23 -3
- package/apps/studio/client/panels/ChatPanel.jsx +22 -37
- package/apps/studio/client/panels/DiffView.jsx +314 -248
- package/apps/studio/client/panels/TeamProjects.jsx +119 -69
- package/apps/studio/client/panels/acp-runtime.js +25 -0
- package/apps/studio/client/panels/chat-finish.js +66 -0
- package/apps/studio/client/shell/frame-cap.js +53 -0
- package/apps/studio/client/shell/viewport.jsx +9 -0
- package/apps/studio/client/styles/_index.css +2 -0
- package/apps/studio/client/tree/tree.jsx +48 -21
- package/apps/studio/client/v2/ai/BackgroundStrip.jsx +120 -0
- package/apps/studio/client/v2/ai/StoppedDivider.jsx +2 -1
- package/apps/studio/client/v2/ai/ai-run.css +87 -3
- package/apps/studio/client/v2/ai/background-model.js +113 -0
- package/apps/studio/client/v2/ai/needs-you-store.js +2 -1
- package/apps/studio/client/v2/ai/run-api.js +7 -3
- package/apps/studio/client/v2/ai/runs-store.js +2 -1
- package/apps/studio/client/v2/annotations/vote-store.js +11 -5
- package/apps/studio/client/v2/assets/asset-state-lane.js +176 -8
- package/apps/studio/client/v2/assets/assets-bus.js +10 -8
- package/apps/studio/client/v2/assets/browse-view.jsx +2 -0
- package/apps/studio/client/v2/assets/ds-library-view.jsx +47 -0
- package/apps/studio/client/v2/assets/missing-frame.jsx +8 -4
- package/apps/studio/client/v2/assets/spotlight-model.js +75 -0
- package/apps/studio/client/v2/assets/spotlight.css +153 -0
- package/apps/studio/client/v2/assets/spotlight.jsx +199 -0
- package/apps/studio/client/v2/assets/tile-menu.jsx +3 -1
- package/apps/studio/client/v2/assets/tile.jsx +3 -0
- package/apps/studio/client/v2/assets/use-assets.js +2 -1
- package/apps/studio/client/v2/canvases/canvases-panel.jsx +13 -2
- package/apps/studio/client/v2/canvases/covers.js +11 -5
- package/apps/studio/client/v2/canvases/folder-ask.js +139 -0
- package/apps/studio/client/v2/canvases/folder-dialogs.jsx +150 -0
- package/apps/studio/client/v2/canvases/trash-canvas.js +10 -2
- package/apps/studio/client/v2/canvases/trash-queue.js +152 -0
- package/apps/studio/client/v2/canvases/use-canvas-index.js +42 -18
- package/apps/studio/client/v2/canvases/use-pins.js +2 -1
- package/apps/studio/client/v2/code/canvas-error-card.jsx +70 -5
- package/apps/studio/client/v2/code/canvas-waiting-card.jsx +128 -0
- package/apps/studio/client/v2/code/canvas-waiting.js +164 -0
- package/apps/studio/client/v2/code/code.css +67 -0
- package/apps/studio/client/v2/code/use-canvas-source.js +19 -4
- package/apps/studio/client/v2/create/NameDialog.jsx +4 -2
- package/apps/studio/client/v2/create/name-dialog.css +10 -0
- package/apps/studio/client/v2/ds/advanced-host.jsx +5 -2
- package/apps/studio/client/v2/ds/make-host.jsx +5 -2
- package/apps/studio/client/v2/ds/off-system-host.jsx +5 -2
- package/apps/studio/client/v2/ds/truth-host.jsx +5 -2
- package/apps/studio/client/v2/empty/arriving.jsx +29 -12
- package/apps/studio/client/v2/empty/empty-host.jsx +8 -2
- package/apps/studio/client/v2/empty/not-local.jsx +31 -1
- package/apps/studio/client/v2/empty/use-empty-canvas.js +10 -1
- package/apps/studio/client/v2/export/last-finished.js +2 -1
- package/apps/studio/client/v2/export/native-save.js +44 -0
- package/apps/studio/client/v2/history/git-model.js +18 -4
- package/apps/studio/client/v2/history/git-parts.jsx +60 -42
- package/apps/studio/client/v2/history/history.css +6 -0
- package/apps/studio/client/v2/left-panel/assets-panel.jsx +87 -10
- package/apps/studio/client/v2/left-panel/use-trash.js +2 -1
- package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +100 -33
- package/apps/studio/client/v2/onboarding/HubSheet.jsx +51 -83
- package/apps/studio/client/v2/onboarding/onboarding-model.js +10 -6
- package/apps/studio/client/v2/present/order-notes-artboards.js +2 -1
- package/apps/studio/client/v2/search/search-recent.js +3 -1
- package/apps/studio/client/v2/search/search-remote.js +6 -4
- package/apps/studio/client/v2/settings/connections-model.js +1 -1
- package/apps/studio/client/v2/shell/menu-runner.js +1 -0
- package/apps/studio/client/v2/shell/occlusion-insets.js +14 -2
- package/apps/studio/client/v2/shell/recovery-store.js +2 -1
- package/apps/studio/client/v2/shell/served-routes.js +120 -0
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +2 -1
- package/apps/studio/client/v2/shell/shell-activity.js +19 -0
- package/apps/studio/client/v2/shell/use-occluded-insets.js +3 -0
- package/apps/studio/client/v2/sync-states/conflict-card.jsx +7 -2
- package/apps/studio/client/v2/undo/use-undo-projection.jsx +3 -1
- package/apps/studio/cloud/endpoints.ts +23 -1
- package/apps/studio/dist/client.bundle.js +798 -801
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds-assets.ts +138 -48
- package/apps/studio/editing/minimap-context.tsx +3 -3
- package/apps/studio/editing/page-activity.ts +251 -0
- package/apps/studio/editing/rotate-handle.tsx +9 -5
- package/apps/studio/editing/sticky-name.tsx +4 -4
- package/apps/studio/history/restore-artboard-action.ts +40 -0
- package/apps/studio/home/hub.ts +77 -175
- package/apps/studio/home/routes.ts +47 -8
- package/apps/studio/http.ts +117 -66
- package/apps/studio/index-flight.ts +40 -0
- package/apps/studio/managed-projects.ts +52 -24
- package/apps/studio/migrate/hub.ts +7 -1
- package/apps/studio/routes/asset-state.ts +12 -0
- package/apps/studio/routes/canvas-source.ts +44 -2
- package/apps/studio/routes/ds-assets.ts +8 -0
- package/apps/studio/routes/history.ts +28 -5
- package/apps/studio/routes/hub-signin.ts +115 -0
- package/apps/studio/routes/index.ts +4 -0
- package/apps/studio/routes/table.ts +7 -0
- package/apps/studio/routes/trash.ts +3 -0
- package/apps/studio/server.ts +11 -0
- package/apps/studio/sync/accepted-cold-start.ts +26 -3
- package/apps/studio/sync/accepted-link.ts +9 -4
- package/apps/studio/sync/asset-push.ts +8 -1
- package/apps/studio/sync/asset-state.ts +27 -2
- package/apps/studio/sync/code-module-consent.ts +74 -0
- package/apps/studio/sync/file-ledger.ts +35 -0
- package/apps/studio/sync/file-plane.ts +479 -84
- package/apps/studio/sync/hub-browser-signin.ts +377 -0
- package/apps/studio/sync/hub-text-undo.ts +30 -10
- package/apps/studio/sync/index.ts +73 -11
- package/apps/studio/sync/lfs-pointer.ts +137 -0
- package/apps/studio/sync/projection.ts +44 -2
- package/apps/studio/sync/pull-pacer.ts +160 -0
- package/apps/studio/sync/pull-priority.ts +119 -0
- package/apps/studio/sync/seed-progress.ts +47 -3
- package/apps/studio/sync/transaction-client.ts +71 -6
- package/apps/studio/sync/workspace-signin.ts +6 -256
- package/apps/studio/sync/writer-registry.ts +5 -1
- package/apps/studio/video-links-overlay.tsx +3 -2
- package/apps/studio/whats-new.json +63 -0
- package/cli/lib/design-help.gen.mjs +1 -1
- package/cli/lib/workspace-plan.mjs +14 -0
- package/package.json +8 -8
|
@@ -79,7 +79,10 @@ import {
|
|
|
79
79
|
type JournalEntry,
|
|
80
80
|
type JournalPage,
|
|
81
81
|
} from './journal-client.ts';
|
|
82
|
+
import { LFS_POINTER_REASON, readLfsPointer } from './lfs-pointer.ts';
|
|
82
83
|
import { createPullBudget } from './pull-budget.ts';
|
|
84
|
+
import { createPullPacer, type PullPacer } from './pull-pacer.ts';
|
|
85
|
+
import { activeCanvasWants } from './pull-priority.ts';
|
|
83
86
|
import { failureReason, isBackpressure, refusalWords, retryAfterMs } from './retry-after.ts';
|
|
84
87
|
import { classifyTransportError } from './transport-error.ts';
|
|
85
88
|
|
|
@@ -99,8 +102,11 @@ export const MAX_FILE_BYTES = (() => {
|
|
|
99
102
|
})();
|
|
100
103
|
|
|
101
104
|
/** T18 — above this a download streams to disk (and resumes) instead of
|
|
102
|
-
* being held in memory.
|
|
103
|
-
|
|
105
|
+
* being held in memory. Issue #204: it was 32 MB, so every photo and clip of a
|
|
106
|
+
* first sync was collected chunk by chunk and then copied into one buffer of
|
|
107
|
+
* its full size (twice the file per download); below the threshold that still
|
|
108
|
+
* happens, so it is kept at a size where twice the file does not matter. */
|
|
109
|
+
export const STREAM_DOWNLOAD_ABOVE_BYTES = 1024 * 1024;
|
|
104
110
|
|
|
105
111
|
/** sha256 of a file, read in 1 MiB chunks (T18 — a video is never held whole). */
|
|
106
112
|
export function sha256File(abs: string): string {
|
|
@@ -178,7 +184,28 @@ export const HUB_LIMITS_RETRY_MS = 30_000;
|
|
|
178
184
|
export const MAX_TRUSTED_QUOTA_PAUSE_MS = 2 * 60 * 60_000;
|
|
179
185
|
|
|
180
186
|
/** How many files one pass will move. The remainder is the next pass's work. */
|
|
181
|
-
const MAX_FILES_PER_PASS = 200;
|
|
187
|
+
export const MAX_FILES_PER_PASS = 200;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Issue #204 — write the ledger at most every this many landings while a pass runs (it is always
|
|
191
|
+
* written at the end of the pass). A crash in between loses only the adoption of those files, which
|
|
192
|
+
* the next pass recovers by hashing them — never by downloading them again.
|
|
193
|
+
*/
|
|
194
|
+
export const LEDGER_FLUSH_EVERY_LANDINGS = 250;
|
|
195
|
+
/** …or after this long, so a slow pass of large files still leaves a recent ledger behind. */
|
|
196
|
+
export const LEDGER_FLUSH_EVERY_MS = 15_000;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Issue #204 — this many `fetching from storage` misses IN A ROW is no longer one slow file but a
|
|
200
|
+
* bucket that is not answering: the plane holds for the hub's Retry-After, as it does for any wall.
|
|
201
|
+
*/
|
|
202
|
+
export const STORAGE_MISS_STREAK_LIMIT = 4;
|
|
203
|
+
|
|
204
|
+
/** A staged partial download untouched this long, for bytes no pass wants, is removed. */
|
|
205
|
+
export const STALE_PART_MS = 24 * 60 * 60_000;
|
|
206
|
+
|
|
207
|
+
/** Issue #204 — the most body bytes concurrent downloads may hold in memory at once (see the pool). */
|
|
208
|
+
export const MAX_BUFFERED_IN_FLIGHT_BYTES = 64 * 1024 * 1024;
|
|
182
209
|
|
|
183
210
|
/**
|
|
184
211
|
* How many HTTP REQUESTS one pass will issue. Issue #109.
|
|
@@ -394,6 +421,19 @@ export interface FilePlaneResult {
|
|
|
394
421
|
};
|
|
395
422
|
/** The pass stopped because it had spent its request ceiling. */
|
|
396
423
|
requestsExhausted?: true;
|
|
424
|
+
/** The pass stopped because it had moved `MAX_FILES_PER_PASS` files (issue #204). */
|
|
425
|
+
filesCapped?: true;
|
|
426
|
+
/**
|
|
427
|
+
* Issue #204 — files whose bytes the hub is still FETCHING FROM ITS BUCKET (a cold cell's
|
|
428
|
+
* `503 fetching from storage`). Not delivered, not failed, not stuck: each is backed off for the
|
|
429
|
+
* hub's `Retry-After` and asked again, while the rest of the pass carries on.
|
|
430
|
+
*/
|
|
431
|
+
storageMisses?: number;
|
|
432
|
+
/**
|
|
433
|
+
* The soonest a path skipped for its backoff window may be tried again, in ms from the end of
|
|
434
|
+
* this pass. Lets the runtime come back for it then rather than on the next 20 s tick.
|
|
435
|
+
*/
|
|
436
|
+
nextAttemptInMs?: number;
|
|
397
437
|
/** The door refused our credential; a renewal was requested and the pass ended. */
|
|
398
438
|
authRefused?: true;
|
|
399
439
|
/**
|
|
@@ -541,6 +581,16 @@ export interface FilePlaneOptions {
|
|
|
541
581
|
* true (every caller before this option, and every test hub, takes them).
|
|
542
582
|
*/
|
|
543
583
|
hubTakesV2Files?: boolean;
|
|
584
|
+
/**
|
|
585
|
+
* Issue #204 — how fast this plane talks to the hub (concurrency + requests per minute). One per
|
|
586
|
+
* plane so the adaptive width survives from pass to pass. Default: `createPullPacer()`.
|
|
587
|
+
*/
|
|
588
|
+
pacer?: PullPacer;
|
|
589
|
+
/**
|
|
590
|
+
* Issue #204 — paths to fetch FIRST: the open canvas's own files, imports and assets. Read once
|
|
591
|
+
* per pass. Default: the active canvas named in `_active.json` (`activeCanvasWants`).
|
|
592
|
+
*/
|
|
593
|
+
priorityPaths?: () => ReadonlySet<string>;
|
|
544
594
|
}
|
|
545
595
|
|
|
546
596
|
interface SyncableLocalFile {
|
|
@@ -699,6 +749,9 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
699
749
|
})();
|
|
700
750
|
|
|
701
751
|
const auth = () => ({ authorization: `Bearer ${opts.token()}` });
|
|
752
|
+
/** Issue #204 — concurrency + requests per minute, adaptive across passes. */
|
|
753
|
+
const pacer = opts.pacer ?? createPullPacer({ now });
|
|
754
|
+
const priorityPaths = opts.priorityPaths ?? (() => activeCanvasWants(designRoot));
|
|
702
755
|
|
|
703
756
|
/**
|
|
704
757
|
* A thrown transfer error, in words a PERSON can act on.
|
|
@@ -769,6 +822,12 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
769
822
|
} | null = null;
|
|
770
823
|
/** Consecutive `unreachable` classifications this pass. */
|
|
771
824
|
let unreachableInARow = 0;
|
|
825
|
+
/** Consecutive `fetching from storage` misses this pass (#204). */
|
|
826
|
+
let storageMissesInARow = 0;
|
|
827
|
+
/** The last failure reason logged per path, so a file that keeps failing is named once. */
|
|
828
|
+
const failureSaid = new Map<string, string>();
|
|
829
|
+
/** The soonest a path this pass put in (or found in) a backoff window may go again (#204). */
|
|
830
|
+
let soonestRetryAt = Number.POSITIVE_INFINITY;
|
|
772
831
|
/** The door refused our credential this pass. */
|
|
773
832
|
let authRefused = false;
|
|
774
833
|
/** Set when a write door answered 426 (format) this pass. */
|
|
@@ -833,7 +892,12 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
833
892
|
uploadSessions?: unknown;
|
|
834
893
|
maxSessionBytes?: unknown;
|
|
835
894
|
partBytes?: unknown;
|
|
895
|
+
readsPerMinute?: unknown;
|
|
836
896
|
};
|
|
897
|
+
// Issue #204 — the hub's per-label READ ceiling, when it says (a pre-2.0.4 hub does not, and
|
|
898
|
+
// the pacer's 480 stays under that hub's 600). Clamped inside the pacer (DDR-054).
|
|
899
|
+
if (Number.isFinite(body?.readsPerMinute))
|
|
900
|
+
pacer.setReadCeiling(body.readsPerMinute as number);
|
|
837
901
|
if (
|
|
838
902
|
Number.isFinite(body?.maxFileBytes) &&
|
|
839
903
|
(body.maxFileBytes as number) >= MIN_TRUSTED_MAX_FILE_BYTES
|
|
@@ -980,19 +1044,28 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
980
1044
|
return { ok: false, reason, rateLimited: true };
|
|
981
1045
|
}
|
|
982
1046
|
|
|
983
|
-
/**
|
|
1047
|
+
/**
|
|
1048
|
+
* Fetch one file's bytes and verify them against the hash we were promised — resuming a staged
|
|
1049
|
+
* partial download (T18) when there is one.
|
|
1050
|
+
*
|
|
1051
|
+
* A STAGED PART ALWAYS RESUMES OR RESTARTS, NEVER WEDGES (#204 follow-up: a self-hosted
|
|
1052
|
+
* workspace sat at "7614 / 7617 delivered · 3 waiting" for good, all three large videos). The
|
|
1053
|
+
* staging file is keyed by content hash and outlives the pass, so every way it can disagree with
|
|
1054
|
+
* the hub is handled inside this one attempt rather than as a failure the next pass meets again:
|
|
1055
|
+
* - already whole (the size the journal names): verified on disk and landed with NO request;
|
|
1056
|
+
* overgrown or whole-but-wrong: discarded, fetched fresh;
|
|
1057
|
+
* - the hub cannot honour the range (416), answers it from a different offset, or ignores it
|
|
1058
|
+
* (200): discarded, fetched fresh — at most one restart per attempt;
|
|
1059
|
+
* - resumed bytes that do not hash right (a bad prefix): discarded, fetched fresh once.
|
|
1060
|
+
* What still fails is a real failure: it reaches `failed` with a reason and the path backs off.
|
|
1061
|
+
*/
|
|
984
1062
|
async function fetchVerified(
|
|
985
1063
|
rel: string,
|
|
986
1064
|
expectHash: string,
|
|
987
|
-
ceiling: number
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
| { ok: false; reason: string; overCap?: true; rateLimited?: true }
|
|
992
|
-
> {
|
|
993
|
-
let res: Response;
|
|
994
|
-
requestsThisPass += 1;
|
|
995
|
-
// T18 — a partial download of these exact bytes resumes where it stopped.
|
|
1065
|
+
ceiling: number,
|
|
1066
|
+
/** The size the journal names, when it does — lets a whole staged part land without a request. */
|
|
1067
|
+
sizeHint = 0
|
|
1068
|
+
): Promise<Exclude<Awaited<ReturnType<typeof fetchOnce>>, { restart: true }>> {
|
|
996
1069
|
const staged = path.join(designRoot, '_state', 'downloads', `${expectHash}.part`);
|
|
997
1070
|
let resumeFrom = 0;
|
|
998
1071
|
try {
|
|
@@ -1000,6 +1073,54 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1000
1073
|
} catch {
|
|
1001
1074
|
/* nothing staged */
|
|
1002
1075
|
}
|
|
1076
|
+
if (resumeFrom > 0 && sizeHint > 0 && resumeFrom >= sizeHint) {
|
|
1077
|
+
if (resumeFrom === sizeHint) {
|
|
1078
|
+
let got: string | null = null;
|
|
1079
|
+
try {
|
|
1080
|
+
got = await sha256FileAsync(staged);
|
|
1081
|
+
} catch {
|
|
1082
|
+
got = null;
|
|
1083
|
+
}
|
|
1084
|
+
if (got === expectHash) return { ok: true, file: staged, size: resumeFrom };
|
|
1085
|
+
}
|
|
1086
|
+
rmSync(staged, { force: true });
|
|
1087
|
+
resumeFrom = 0;
|
|
1088
|
+
}
|
|
1089
|
+
const first = await fetchOnce(rel, expectHash, ceiling, staged, resumeFrom);
|
|
1090
|
+
if (!('restart' in first) || resumeFrom === 0) {
|
|
1091
|
+
if ('restart' in first) return { ok: false, reason: first.reason };
|
|
1092
|
+
return first;
|
|
1093
|
+
}
|
|
1094
|
+
log.warn?.(`[sync/files] ${rel}: ${first.reason} — fetching it from the start`);
|
|
1095
|
+
rmSync(staged, { force: true });
|
|
1096
|
+
const again = await fetchOnce(rel, expectHash, ceiling, staged, 0);
|
|
1097
|
+
return 'restart' in again ? { ok: false, reason: again.reason } : again;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/** One request for `rel`, resuming at `resumeFrom` (0 = whole file). `restart` = discard the part. */
|
|
1101
|
+
async function fetchOnce(
|
|
1102
|
+
rel: string,
|
|
1103
|
+
expectHash: string,
|
|
1104
|
+
ceiling: number,
|
|
1105
|
+
staged: string,
|
|
1106
|
+
resumeFrom: number
|
|
1107
|
+
): Promise<
|
|
1108
|
+
| { ok: true; bytes: Uint8Array; file?: undefined; size: number }
|
|
1109
|
+
| { ok: true; file: string; bytes?: undefined; size: number }
|
|
1110
|
+
| {
|
|
1111
|
+
ok: false;
|
|
1112
|
+
reason: string;
|
|
1113
|
+
overCap?: true;
|
|
1114
|
+
rateLimited?: true;
|
|
1115
|
+
/** The hub is still filling these bytes from its bucket (#204). */
|
|
1116
|
+
storageMiss?: true;
|
|
1117
|
+
restart?: undefined;
|
|
1118
|
+
}
|
|
1119
|
+
| { ok: false; restart: true; reason: string }
|
|
1120
|
+
> {
|
|
1121
|
+
let res: Response;
|
|
1122
|
+
requestsThisPass += 1;
|
|
1123
|
+
await pacer.admit('read');
|
|
1003
1124
|
try {
|
|
1004
1125
|
res = await fetchImpl(
|
|
1005
1126
|
`${base}/_project-file/${rel.split('/').map(encodeURIComponent).join('/')}`,
|
|
@@ -1013,11 +1134,59 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1013
1134
|
}
|
|
1014
1135
|
if (res.status === 416) {
|
|
1015
1136
|
// The staged part is not a prefix of what the hub holds now: start over.
|
|
1137
|
+
await res.body?.cancel().catch(() => {});
|
|
1016
1138
|
rmSync(staged, { force: true });
|
|
1017
|
-
return {
|
|
1139
|
+
return {
|
|
1140
|
+
ok: false,
|
|
1141
|
+
restart: true,
|
|
1142
|
+
reason: 'the partial download no longer matches — restarting it',
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
// ISSUE #204 — A COLD CELL STILL FETCHING THESE BYTES FROM ITS BUCKET. The materializer answers
|
|
1146
|
+
// `503 Retry-After {"error":"fetching from storage"}` once its 15 s deadline passes, and keeps
|
|
1147
|
+
// the fill going for the next caller. That is about ONE file, not the door: the whole plane used
|
|
1148
|
+
// to hold on it (a Retry-After 5xx is backpressure) and the pass ended, so one slow video cost
|
|
1149
|
+
// every other file the rest of the pass and the wait for the next tick. Now the file waits out
|
|
1150
|
+
// the hub's Retry-After on its own and the pass carries on; a RUN of them is still a wall
|
|
1151
|
+
// (`STORAGE_MISS_STREAK_LIMIT`). The body is hub-supplied (DDR-054) — misreading it as a miss
|
|
1152
|
+
// buys a per-file backoff instead of a plane hold, both bounded.
|
|
1153
|
+
if (res.status === 503 && res.headers?.get?.('retry-after')) {
|
|
1154
|
+
const words = await failureReason(res);
|
|
1155
|
+
if (/fetching from storage/.test(words)) {
|
|
1156
|
+
storageMissesInARow += 1;
|
|
1157
|
+
if (storageMissesInARow >= STORAGE_MISS_STREAK_LIMIT) {
|
|
1158
|
+
const wait = retryAfterMs(res.headers.get('retry-after'));
|
|
1159
|
+
if (hitRateLimit === null || wait > hitRateLimit.retryAfterMs) {
|
|
1160
|
+
hitRateLimit = { retryAfterMs: wait, cause: 'hub-asked' };
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
return { ok: false, reason: words, storageMiss: true };
|
|
1164
|
+
}
|
|
1165
|
+
// Any other 503 with a Retry-After keeps its meaning: a starting cell, hold the plane.
|
|
1166
|
+
const wait = retryAfterMs(res.headers.get('retry-after'));
|
|
1167
|
+
if (hitRateLimit === null || wait > hitRateLimit.retryAfterMs) {
|
|
1168
|
+
hitRateLimit = { retryAfterMs: wait, cause: 'hub-asked' };
|
|
1169
|
+
}
|
|
1170
|
+
return { ok: false, reason: words, rateLimited: true };
|
|
1018
1171
|
}
|
|
1019
1172
|
if (!res.ok) return await refusal(res);
|
|
1173
|
+
storageMissesInARow = 0;
|
|
1020
1174
|
const resumed = res.status === 206 && resumeFrom > 0;
|
|
1175
|
+
// A 206 must continue EXACTLY where the part ends — appending any other offset is a corrupt
|
|
1176
|
+
// file that only the hash would catch, after the whole download.
|
|
1177
|
+
if (resumed) {
|
|
1178
|
+
const range = /^bytes\s+(\d+)-/.exec(res.headers?.get?.('content-range') ?? '');
|
|
1179
|
+
if (!range || Number(range[1]) !== resumeFrom) {
|
|
1180
|
+
await res.body?.cancel().catch(() => {});
|
|
1181
|
+
return {
|
|
1182
|
+
ok: false,
|
|
1183
|
+
restart: true,
|
|
1184
|
+
reason: 'the server resumed from a different place — restarting it',
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
// Asked to resume and answered with the whole file (no range support): the part is stale.
|
|
1189
|
+
if (resumeFrom > 0 && !resumed) rmSync(staged, { force: true });
|
|
1021
1190
|
|
|
1022
1191
|
// The cap is consulted BEFORE the body exists, and again as it arrives.
|
|
1023
1192
|
// Buffering first and measuring after is not a cap at all: a hub answering
|
|
@@ -1072,7 +1241,10 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1072
1241
|
}
|
|
1073
1242
|
if (got !== expectHash) {
|
|
1074
1243
|
rmSync(staged, { force: true });
|
|
1075
|
-
|
|
1244
|
+
// A resumed file that does not hash right had a bad prefix: one fresh fetch settles it.
|
|
1245
|
+
return resumed
|
|
1246
|
+
? { ok: false, restart: true, reason: 'the resumed download did not verify' }
|
|
1247
|
+
: { ok: false, reason: 'content hash mismatch (racing a write?)' };
|
|
1076
1248
|
}
|
|
1077
1249
|
return { ok: true, file: staged, size: total };
|
|
1078
1250
|
}
|
|
@@ -1258,6 +1430,33 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1258
1430
|
return isFilePlaneClass(cls);
|
|
1259
1431
|
}
|
|
1260
1432
|
|
|
1433
|
+
/**
|
|
1434
|
+
* Drop staged partial downloads nobody is waiting for (#204 follow-up). A part is keyed by content
|
|
1435
|
+
* hash, so once the hub's file moves on (or the file lands another way) its part is dead weight
|
|
1436
|
+
* that nothing would ever resume. Only parts untouched for `STALE_PART_MS` go, and never one whose
|
|
1437
|
+
* hash this pass still wants — a slow download of a big video keeps its progress.
|
|
1438
|
+
*/
|
|
1439
|
+
function sweepStaleParts(wanted: ReadonlySet<string>): void {
|
|
1440
|
+
const dir = path.join(designRoot, '_state', 'downloads');
|
|
1441
|
+
let names: string[];
|
|
1442
|
+
try {
|
|
1443
|
+
names = readdirSync(dir);
|
|
1444
|
+
} catch {
|
|
1445
|
+
return;
|
|
1446
|
+
}
|
|
1447
|
+
for (const name of names.slice(0, 500)) {
|
|
1448
|
+
const m = /^([0-9a-f]{64})\.part$/.exec(name);
|
|
1449
|
+
if (!m || wanted.has(m[1] as string)) continue;
|
|
1450
|
+
const abs = path.join(dir, name);
|
|
1451
|
+
try {
|
|
1452
|
+
if (now() - statSync(abs).mtimeMs < STALE_PART_MS) continue;
|
|
1453
|
+
rmSync(abs, { force: true });
|
|
1454
|
+
} catch {
|
|
1455
|
+
/* gone already */
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1261
1460
|
/** Land bytes at `rel`, atomically. Throws on failure — `adoptAfter` catches.
|
|
1262
1461
|
* A streamed download (T18) is moved into place from its staging file. */
|
|
1263
1462
|
function materialize(rel: string, payload: { bytes?: Uint8Array; file?: string }): void {
|
|
@@ -1361,6 +1560,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1361
1560
|
// rather than as a remote change we must react to.
|
|
1362
1561
|
ledger.outboxAdd(local.hash);
|
|
1363
1562
|
requestsThisPass += 1;
|
|
1563
|
+
await pacer.admit('write');
|
|
1364
1564
|
try {
|
|
1365
1565
|
const res = await fetchImpl(
|
|
1366
1566
|
`${base}/api/file/${local.rel.split('/').map(encodeURIComponent).join('/')}`,
|
|
@@ -1408,6 +1608,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1408
1608
|
(await res.json().catch(() => ({}))) as Record<string, unknown>;
|
|
1409
1609
|
ledger.outboxAdd(local.hash);
|
|
1410
1610
|
requestsThisPass += 1;
|
|
1611
|
+
await pacer.admit('write');
|
|
1411
1612
|
try {
|
|
1412
1613
|
const created = await fetchImpl(`${base}/api/file-uploads`, {
|
|
1413
1614
|
method: 'POST',
|
|
@@ -1509,6 +1710,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1509
1710
|
{ ok: true } | { ok: false; conflict: true } | { ok: false; reason: string; rateLimited?: true }
|
|
1510
1711
|
> {
|
|
1511
1712
|
requestsThisPass += 1;
|
|
1713
|
+
await pacer.admit('write');
|
|
1512
1714
|
try {
|
|
1513
1715
|
const res = await fetchImpl(
|
|
1514
1716
|
`${base}/api/file/${rel.split('/').map(encodeURIComponent).join('/')}`,
|
|
@@ -1662,7 +1864,15 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1662
1864
|
}
|
|
1663
1865
|
|
|
1664
1866
|
async function reconcile(): Promise<FilePlaneResult> {
|
|
1665
|
-
|
|
1867
|
+
// ONE ledger write per batch (#204): the pass writes it every N landings and at its end
|
|
1868
|
+
// (`ledger.flush()` in step 5); nothing in between re-arms the 1 s debounce per file.
|
|
1869
|
+
const release = ledger.deferFlush();
|
|
1870
|
+
let out: FilePlaneResult;
|
|
1871
|
+
try {
|
|
1872
|
+
out = await reconcilePass();
|
|
1873
|
+
} finally {
|
|
1874
|
+
release();
|
|
1875
|
+
}
|
|
1666
1876
|
const refused = hubRefusedRows();
|
|
1667
1877
|
if (refused.length > 0) out.hubRefused = refused;
|
|
1668
1878
|
return out;
|
|
@@ -1699,6 +1909,8 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1699
1909
|
}
|
|
1700
1910
|
hitRateLimit = null;
|
|
1701
1911
|
unreachableInARow = 0;
|
|
1912
|
+
storageMissesInARow = 0;
|
|
1913
|
+
soonestRetryAt = Number.POSITIVE_INFINITY;
|
|
1702
1914
|
authRefused = false;
|
|
1703
1915
|
formatRefused = null;
|
|
1704
1916
|
quotaSpentThisPass = 0;
|
|
@@ -1994,13 +2206,28 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1994
2206
|
out.synced += 1;
|
|
1995
2207
|
continue;
|
|
1996
2208
|
}
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
)
|
|
2003
|
-
|
|
2209
|
+
// NOR IS AN UPLOAD A LANDING (2.0.3). The hub still holds exactly what
|
|
2210
|
+
// we last agreed on, so the only thing that moved is OUR copy: this is
|
|
2211
|
+
// the upward half, which the upload gate below decides (the door then
|
|
2212
|
+
// enforces the owner role). Refusing it here meant an owner without
|
|
2213
|
+
// receive consent uploaded each code module once and never again — the
|
|
2214
|
+
// cell kept the first version (alligators, 2.0.2). Anything else — the
|
|
2215
|
+
// hub moved, or there is no agreed ancestor — still never lands here.
|
|
2216
|
+
const ancestor = ledger.ancestorOf(rel);
|
|
2217
|
+
const uploadOnly =
|
|
2218
|
+
here !== undefined &&
|
|
2219
|
+
ancestor !== null &&
|
|
2220
|
+
ancestor === remoteHash &&
|
|
2221
|
+
(opts.canUploadCodeModules ?? opts.allowCodeModules);
|
|
2222
|
+
if (!uploadOnly) {
|
|
2223
|
+
drop(
|
|
2224
|
+
out,
|
|
2225
|
+
rel,
|
|
2226
|
+
'code modules replicate only from an owner-vouched or loopback hub',
|
|
2227
|
+
ledger
|
|
2228
|
+
);
|
|
2229
|
+
continue;
|
|
2230
|
+
}
|
|
2004
2231
|
}
|
|
2005
2232
|
}
|
|
2006
2233
|
|
|
@@ -2203,13 +2430,23 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2203
2430
|
|
|
2204
2431
|
// ── 4. Apply ─────────────────────────────────────────────────────────
|
|
2205
2432
|
//
|
|
2206
|
-
//
|
|
2207
|
-
//
|
|
2433
|
+
// The open canvas first (#204): its own files, imports and assets are what a person is looking
|
|
2434
|
+
// at. Then referenced assets (DDR-223's strokes→bytes coupling): a picture a just-arrived
|
|
2435
|
+
// annotation points at is the one a person is staring at.
|
|
2208
2436
|
const referenced = referencedAssetNames(designRoot);
|
|
2437
|
+
let wanted: ReadonlySet<string> = new Set();
|
|
2438
|
+
try {
|
|
2439
|
+
wanted = priorityPaths();
|
|
2440
|
+
} catch {
|
|
2441
|
+
/* ordering only — never a reason to stop a pass */
|
|
2442
|
+
}
|
|
2209
2443
|
// …then smallest first (T19): one 1 GB master never makes the forty
|
|
2210
2444
|
// images a canvas needs wait behind it; big media fills in last.
|
|
2211
2445
|
const sizeOf = (w: (typeof work)[number]) => Math.max(claimedSize(w.row), w.local?.size ?? 0);
|
|
2212
|
-
work.sort(
|
|
2446
|
+
work.sort(
|
|
2447
|
+
(a, b) =>
|
|
2448
|
+
rank(a.rel, referenced, wanted) - rank(b.rel, referenced, wanted) || sizeOf(a) - sizeOf(b)
|
|
2449
|
+
);
|
|
2213
2450
|
|
|
2214
2451
|
const budget = createPullBudget({
|
|
2215
2452
|
label: 'sync/files',
|
|
@@ -2217,17 +2454,123 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2217
2454
|
...(opts.maxPassBytes !== undefined ? { maxBytes: opts.maxPassBytes } : {}),
|
|
2218
2455
|
});
|
|
2219
2456
|
|
|
2457
|
+
/**
|
|
2458
|
+
* ISSUE #204 — DOWNLOADS RUN SIDE BY SIDE. One request at a time made the wall clock of a first
|
|
2459
|
+
* sync the SUM of every round trip: 200 files per pass at one cold-cell bucket fill each was the
|
|
2460
|
+
* 2–4 minutes a pass took on a 5 041-file project. A `pull` now runs in a pool `pacer.limit()`
|
|
2461
|
+
* wide; everything else (an upload, a delete, a conflict that parks a copy) still runs alone,
|
|
2462
|
+
* after the pool drains, because those decide against the hub's CAS and their order matters.
|
|
2463
|
+
*
|
|
2464
|
+
* The pool is ONE wide until a transfer of this pass has come back healthy: the first request of
|
|
2465
|
+
* a pass is the probe, so a door that is shut (a starting cell, a 429 window) sees one request,
|
|
2466
|
+
* not `limit` of them.
|
|
2467
|
+
*
|
|
2468
|
+
* The ceilings count what is DISPATCHED, so concurrency never lets a pass past them: requests are
|
|
2469
|
+
* charged at dispatch (`requestsThisPass`), files as `moved + in flight`, bytes are reserved
|
|
2470
|
+
* against the budget before the request leaves.
|
|
2471
|
+
*/
|
|
2220
2472
|
let moved = 0;
|
|
2221
2473
|
let seen = 0;
|
|
2474
|
+
let probed = false;
|
|
2475
|
+
let landedSinceFlush = 0;
|
|
2476
|
+
let lastFlushAt = now();
|
|
2477
|
+
const inFlight = new Set<Promise<void>>();
|
|
2478
|
+
/**
|
|
2479
|
+
* Content hashes being downloaded right now. A large body streams to `_state/downloads/<sha>.part`
|
|
2480
|
+
* — keyed by HASH, so the resume finds it — and a project holding the same video at two paths
|
|
2481
|
+
* would have two transfers appending to one staging file. The second copy waits its turn.
|
|
2482
|
+
*/
|
|
2483
|
+
const hashesInFlight = new Set<string>();
|
|
2484
|
+
/**
|
|
2485
|
+
* Bytes being BUFFERED in memory by downloads in flight. A body up to
|
|
2486
|
+
* `STREAM_DOWNLOAD_ABOVE_BYTES` is read into memory before it is verified and landed, so six
|
|
2487
|
+
* 30 MB videos at once would hold ~360 MB (twice that while the chunks are joined). The pool
|
|
2488
|
+
* admits another buffered body only while the total stays under `MAX_BUFFERED_IN_FLIGHT_BYTES`;
|
|
2489
|
+
* a streamed (larger) body costs one chunk and is not counted. One transfer always runs.
|
|
2490
|
+
*/
|
|
2491
|
+
let bufferedInFlight = 0;
|
|
2492
|
+
const buffered = (w: (typeof work)[number]): number => {
|
|
2493
|
+
const n = claimedSize(w.row);
|
|
2494
|
+
return n <= STREAM_DOWNLOAD_ABOVE_BYTES ? n : 0;
|
|
2495
|
+
};
|
|
2496
|
+
const wall = () => hitRateLimit !== null || formatRefused !== null || authRefused;
|
|
2497
|
+
|
|
2498
|
+
const settle = (
|
|
2499
|
+
item: (typeof work)[number],
|
|
2500
|
+
handled: boolean,
|
|
2501
|
+
mark: { failed: number; pushed: number; pulled: number }
|
|
2502
|
+
): void => {
|
|
2503
|
+
if (handled) moved += 1;
|
|
2504
|
+
if (handled && !probed && !wall()) probed = true;
|
|
2505
|
+
// Arm or clear this path's window from what the pass actually did with
|
|
2506
|
+
// it. A rate limit is excluded: that is the DOOR's state, not this
|
|
2507
|
+
// path's, and punishing the file for it would push a whole project into
|
|
2508
|
+
// backoff for something none of its files did. Scanned from the marks
|
|
2509
|
+
// taken at dispatch, because other transfers append to the same lists.
|
|
2510
|
+
if (hitRateLimit === null && formatRefused === null) {
|
|
2511
|
+
const failedHere = out.failed.slice(mark.failed).some((f) => f.rel === item.rel);
|
|
2512
|
+
if (failedHere) {
|
|
2513
|
+
const delay = ledger.noteAttemptFailed(item.rel, now());
|
|
2514
|
+
// ONE LINE PER FAILING FILE, naming it and why — said again only when the reason
|
|
2515
|
+
// changes, not on every retry of a file that keeps failing the same way.
|
|
2516
|
+
const why = out.failed.slice(mark.failed).find((f) => f.rel === item.rel)?.reason;
|
|
2517
|
+
if (why !== undefined && failureSaid.get(item.rel) !== why) {
|
|
2518
|
+
failureSaid.set(item.rel, why);
|
|
2519
|
+
log.warn?.(
|
|
2520
|
+
`[sync/files] ${item.rel}: ${why} — trying again in ${Math.round(delay / 1000)}s, then less often`
|
|
2521
|
+
);
|
|
2522
|
+
}
|
|
2523
|
+
} else if (
|
|
2524
|
+
handled ||
|
|
2525
|
+
out.pushed.slice(mark.pushed).includes(item.rel) ||
|
|
2526
|
+
out.pulled.slice(mark.pulled).includes(item.rel)
|
|
2527
|
+
) {
|
|
2528
|
+
ledger.noteAttemptOk(item.rel);
|
|
2529
|
+
failureSaid.delete(item.rel);
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
// ONE ledger write per batch, not one per landing (#204).
|
|
2533
|
+
if (handled) landedSinceFlush += 1;
|
|
2534
|
+
if (
|
|
2535
|
+
landedSinceFlush >= LEDGER_FLUSH_EVERY_LANDINGS ||
|
|
2536
|
+
(landedSinceFlush > 0 && now() - lastFlushAt >= LEDGER_FLUSH_EVERY_MS)
|
|
2537
|
+
) {
|
|
2538
|
+
landedSinceFlush = 0;
|
|
2539
|
+
lastFlushAt = now();
|
|
2540
|
+
ledger.flush();
|
|
2541
|
+
}
|
|
2542
|
+
};
|
|
2543
|
+
|
|
2544
|
+
const run = async (item: (typeof work)[number]): Promise<void> => {
|
|
2545
|
+
const mark = {
|
|
2546
|
+
failed: out.failed.length,
|
|
2547
|
+
pushed: out.pushed.length,
|
|
2548
|
+
pulled: out.pulled.length,
|
|
2549
|
+
};
|
|
2550
|
+
let handled = false;
|
|
2551
|
+
try {
|
|
2552
|
+
handled = await applyOne(item, out, budget);
|
|
2553
|
+
} finally {
|
|
2554
|
+
settle(item, handled, mark);
|
|
2555
|
+
}
|
|
2556
|
+
};
|
|
2557
|
+
const drain = async (): Promise<void> => {
|
|
2558
|
+
while (inFlight.size > 0) await Promise.race(inFlight);
|
|
2559
|
+
};
|
|
2560
|
+
|
|
2222
2561
|
for (const item of work) {
|
|
2223
2562
|
// TWO CEILINGS, because they bound different things and only one of them
|
|
2224
2563
|
// survives a bad day. `moved` bounds what LANDS — disk writes, parked
|
|
2225
2564
|
// copies, ledger churn — and it is the one a healthy pass hits. Requests
|
|
2226
2565
|
// bound what we ASK, and it is the one that matters when nothing is
|
|
2227
2566
|
// landing, which is precisely when the first counter stops moving
|
|
2228
|
-
// (issue #109).
|
|
2229
|
-
if (
|
|
2567
|
+
// (issue #109). Both count transfers still in flight.
|
|
2568
|
+
if (
|
|
2569
|
+
moved + inFlight.size >= MAX_FILES_PER_PASS ||
|
|
2570
|
+
requestsThisPass >= MAX_REQUESTS_PER_PASS
|
|
2571
|
+
) {
|
|
2230
2572
|
if (requestsThisPass >= MAX_REQUESTS_PER_PASS) out.requestsExhausted = true;
|
|
2573
|
+
else out.filesCapped = true;
|
|
2231
2574
|
log.warn?.(
|
|
2232
2575
|
`[sync/files] ${work.length - seen} more path(s) to reconcile; taking them next pass.`
|
|
2233
2576
|
);
|
|
@@ -2237,6 +2580,8 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2237
2580
|
out.budgetExhausted = true;
|
|
2238
2581
|
break;
|
|
2239
2582
|
}
|
|
2583
|
+
// A wall met by a transfer in flight ends the dispatch; what is in flight finishes.
|
|
2584
|
+
if (wall()) break;
|
|
2240
2585
|
// A PATH INSIDE ITS BACKOFF WINDOW COSTS NOTHING.
|
|
2241
2586
|
//
|
|
2242
2587
|
// Checked BEFORE the ceilings deliberately: charging a skipped path
|
|
@@ -2246,64 +2591,86 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2246
2591
|
if (ledger.isBackedOff(item.rel, now())) {
|
|
2247
2592
|
seen += 1;
|
|
2248
2593
|
out.backedOff = (out.backedOff ?? 0) + 1;
|
|
2594
|
+
const at = ledger.row(item.rel)?.nextAttemptAt;
|
|
2595
|
+
if (Number.isFinite(at)) soonestRetryAt = Math.min(soonestRetryAt, at as number);
|
|
2249
2596
|
continue;
|
|
2250
2597
|
}
|
|
2251
2598
|
seen += 1;
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
const handled = await applyOne(item, out, budget);
|
|
2258
|
-
if (handled) moved += 1;
|
|
2259
|
-
// Arm or clear this path's window from what the pass actually did with
|
|
2260
|
-
// it. A rate limit is excluded: that is the DOOR's state, not this
|
|
2261
|
-
// path's, and punishing the file for it would push a whole project into
|
|
2262
|
-
// backoff for something none of its files did.
|
|
2263
|
-
if (hitRateLimit === null && formatRefused === null) {
|
|
2264
|
-
if (out.failed.length > before.failed) {
|
|
2265
|
-
const delay = ledger.noteAttemptFailed(item.rel, now());
|
|
2266
|
-
log.warn?.(
|
|
2267
|
-
`[sync/files] ${item.rel}: backing off ${Math.round(delay / 1000)}s before the next attempt`
|
|
2268
|
-
);
|
|
2269
|
-
} else if (
|
|
2270
|
-
out.pushed.length > before.pushed ||
|
|
2271
|
-
out.pulled.length > before.pulled ||
|
|
2272
|
-
handled
|
|
2599
|
+
if (item.decision.action === 'pull' && !hashesInFlight.has(item.remoteHash ?? '')) {
|
|
2600
|
+
// Room in the pool: one until the probe came back, then the pacer's width.
|
|
2601
|
+
while (
|
|
2602
|
+
inFlight.size >= (probed ? pacer.limit() : 1) ||
|
|
2603
|
+
(inFlight.size > 0 && bufferedInFlight + buffered(item) > MAX_BUFFERED_IN_FLIGHT_BYTES)
|
|
2273
2604
|
) {
|
|
2274
|
-
|
|
2605
|
+
await Promise.race(inFlight);
|
|
2606
|
+
if (wall()) break;
|
|
2275
2607
|
}
|
|
2608
|
+
if (wall()) {
|
|
2609
|
+
seen -= 1;
|
|
2610
|
+
break;
|
|
2611
|
+
}
|
|
2612
|
+
const hash = item.remoteHash ?? '';
|
|
2613
|
+
const held = buffered(item);
|
|
2614
|
+
hashesInFlight.add(hash);
|
|
2615
|
+
bufferedInFlight += held;
|
|
2616
|
+
const p: Promise<void> = run(item).finally(() => {
|
|
2617
|
+
inFlight.delete(p);
|
|
2618
|
+
hashesInFlight.delete(hash);
|
|
2619
|
+
bufferedInFlight -= held;
|
|
2620
|
+
});
|
|
2621
|
+
inFlight.add(p);
|
|
2622
|
+
continue;
|
|
2276
2623
|
}
|
|
2277
|
-
//
|
|
2278
|
-
//
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
if (refusedFormat !== null) {
|
|
2283
|
-
// ONE notification, and the pass ends: every other write would meet
|
|
2284
|
-
// the same door. No backoff is armed (the file did nothing wrong).
|
|
2285
|
-
opts.onFormatRefused?.(refusedFormat.formatVersion);
|
|
2286
|
-
out.formatRefused = refusedFormat;
|
|
2287
|
-
log.warn?.(
|
|
2288
|
-
`[sync/files] the project now uses a newer file format than this build writes; nothing more goes up until Maude is updated (${work.length - seen} path(s) still to do).`
|
|
2289
|
-
);
|
|
2290
|
-
break;
|
|
2291
|
-
}
|
|
2292
|
-
if (authRefused) {
|
|
2293
|
-
// ONE notification for the whole pass. `renewCredentialNow()` is
|
|
2294
|
-
// single-flight with a 60 s floor, so 803 refused paths collapse to one
|
|
2295
|
-
// renewal — but there is no reason to call it 803 times to find out.
|
|
2296
|
-
opts.onAuthFailure?.(item.rel, 401);
|
|
2297
|
-
out.authRefused = true;
|
|
2298
|
-
log.warn?.(
|
|
2299
|
-
`[sync/files] the workspace did not accept this connection; asking for a fresh credential and stopping this pass (${work.length - seen} path(s) still to do).`
|
|
2300
|
-
);
|
|
2301
|
-
break;
|
|
2302
|
-
}
|
|
2303
|
-
if (hitRateLimit !== null) {
|
|
2304
|
-
holdIfRateLimited(out, work.length - seen);
|
|
2624
|
+
// Anything that is not a plain download — or a second copy of bytes already on their way —
|
|
2625
|
+
// runs alone, in order.
|
|
2626
|
+
await drain();
|
|
2627
|
+
if (wall()) {
|
|
2628
|
+
seen -= 1;
|
|
2305
2629
|
break;
|
|
2306
2630
|
}
|
|
2631
|
+
await run(item);
|
|
2632
|
+
}
|
|
2633
|
+
await drain();
|
|
2634
|
+
sweepStaleParts(
|
|
2635
|
+
new Set(work.map((w) => w.remoteHash).filter((h): h is string => typeof h === 'string'))
|
|
2636
|
+
);
|
|
2637
|
+
|
|
2638
|
+
// A RATE LIMIT ENDS THE PASS. Every other refusal is about one file and
|
|
2639
|
+
// the next one is worth trying; this one is about the door, and the
|
|
2640
|
+
// remaining requests would do nothing but hold it shut for longer.
|
|
2641
|
+
// (A cast: TS cannot see the assignment inside `refusal()`.)
|
|
2642
|
+
const refusedFormat = formatRefused as { formatVersion: number | null } | null;
|
|
2643
|
+
if (refusedFormat !== null) {
|
|
2644
|
+
// ONE notification, and the pass ends: every other write would meet
|
|
2645
|
+
// the same door. No backoff is armed (the file did nothing wrong).
|
|
2646
|
+
opts.onFormatRefused?.(refusedFormat.formatVersion);
|
|
2647
|
+
out.formatRefused = refusedFormat;
|
|
2648
|
+
log.warn?.(
|
|
2649
|
+
`[sync/files] the project now uses a newer file format than this build writes; nothing more goes up until Maude is updated (${work.length - seen} path(s) still to do).`
|
|
2650
|
+
);
|
|
2651
|
+
} else if (authRefused) {
|
|
2652
|
+
// ONE notification for the whole pass. `renewCredentialNow()` is
|
|
2653
|
+
// single-flight with a 60 s floor, so 803 refused paths collapse to one
|
|
2654
|
+
// renewal — but there is no reason to call it 803 times to find out.
|
|
2655
|
+
opts.onAuthFailure?.(out.failed.at(-1)?.rel ?? '', 401);
|
|
2656
|
+
out.authRefused = true;
|
|
2657
|
+
log.warn?.(
|
|
2658
|
+
`[sync/files] the workspace did not accept this connection; asking for a fresh credential and stopping this pass (${work.length - seen} path(s) still to do).`
|
|
2659
|
+
);
|
|
2660
|
+
} else if (hitRateLimit !== null) {
|
|
2661
|
+
holdIfRateLimited(out, work.length - seen);
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
// ADAPT THE WIDTH for the next pass (#204): a wall halves it, storage misses already stepped it
|
|
2665
|
+
// down one by one, and a pass that moved a pool's worth of files cleanly earns one step up.
|
|
2666
|
+
const metWall = hitRateLimit as { cause: string } | null;
|
|
2667
|
+
if (metWall !== null && metWall.cause === 'hub-asked') {
|
|
2668
|
+
pacer.onBackpressure();
|
|
2669
|
+
} else if (!out.storageMisses && out.pulled.length >= pacer.limit() && !wall()) {
|
|
2670
|
+
pacer.onCleanPass();
|
|
2671
|
+
}
|
|
2672
|
+
if (Number.isFinite(soonestRetryAt)) {
|
|
2673
|
+
out.nextAttemptInMs = Math.max(0, soonestRetryAt - now());
|
|
2307
2674
|
}
|
|
2308
2675
|
if (out.pushed.length > 0 || out.pulled.length > 0) opts.onProgress?.();
|
|
2309
2676
|
|
|
@@ -2391,7 +2758,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2391
2758
|
out.budgetExhausted = true;
|
|
2392
2759
|
return false;
|
|
2393
2760
|
}
|
|
2394
|
-
const got = await fetchVerified(rel, remoteHash, budget.remaining() + claim);
|
|
2761
|
+
const got = await fetchVerified(rel, remoteHash, budget.remaining() + claim, claim);
|
|
2395
2762
|
if (!got.ok) {
|
|
2396
2763
|
if (got.overCap && budget.remaining() + claim < MAX_FILE_BYTES) {
|
|
2397
2764
|
out.budgetExhausted = true;
|
|
@@ -2429,7 +2796,18 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2429
2796
|
out.budgetExhausted = true;
|
|
2430
2797
|
return false;
|
|
2431
2798
|
}
|
|
2432
|
-
const got = await fetchVerified(rel, remoteHash, budget.remaining() + claim);
|
|
2799
|
+
const got = await fetchVerified(rel, remoteHash, budget.remaining() + claim, claim);
|
|
2800
|
+
if (!got.ok && got.storageMiss) {
|
|
2801
|
+
// NOT A FAILURE AND NOT DELIVERED (#204): the hub is still fetching these bytes from its
|
|
2802
|
+
// bucket. The row keeps its state (still on its way) and the path waits out a backoff
|
|
2803
|
+
// window before it is asked again — never at once, which only queues another fill behind
|
|
2804
|
+
// the one already running. Its byte reservation stays spent, like any failed transfer's:
|
|
2805
|
+
// a budget that refunds is one a hub can spin.
|
|
2806
|
+
out.storageMisses = (out.storageMisses ?? 0) + 1;
|
|
2807
|
+
soonestRetryAt = Math.min(soonestRetryAt, now() + ledger.noteAttemptFailed(rel, now()));
|
|
2808
|
+
pacer.onStorageMiss();
|
|
2809
|
+
return false;
|
|
2810
|
+
}
|
|
2433
2811
|
if (!got.ok) {
|
|
2434
2812
|
out.failed.push({ rel, reason: got.reason });
|
|
2435
2813
|
ledger.setState(rel, 'stuck', { reason: got.reason });
|
|
@@ -2469,6 +2847,19 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2469
2847
|
out.heldForFormat = (out.heldForFormat ?? 0) + 1;
|
|
2470
2848
|
return false;
|
|
2471
2849
|
}
|
|
2850
|
+
// 2.0.3 — a Git LFS pointer (a clone without `git lfs pull`) is not the file: never send it
|
|
2851
|
+
// up as if it were. Held like a door's refusal of exactly these bytes (`refusedHash`), so it is
|
|
2852
|
+
// said once and goes up by itself once the real file is restored (the hash changes).
|
|
2853
|
+
if (readLfsPointer(here.abs)) {
|
|
2854
|
+
ledger.setState(rel, 'refused', {
|
|
2855
|
+
reason: LFS_POINTER_REASON,
|
|
2856
|
+
blockedClass: 'refused',
|
|
2857
|
+
refusedHash: here.hash,
|
|
2858
|
+
});
|
|
2859
|
+
out.dropped.push({ rel, reason: LFS_POINTER_REASON });
|
|
2860
|
+
log.warn(`[file-plane] ${rel}: a Git LFS placeholder, not the file — not uploaded`);
|
|
2861
|
+
return true;
|
|
2862
|
+
}
|
|
2472
2863
|
ledger.setState(rel, 'pushing');
|
|
2473
2864
|
const expect = decision.action === 'revive' ? null : remoteHash;
|
|
2474
2865
|
const res = await push(here, expect);
|
|
@@ -2568,7 +2959,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2568
2959
|
});
|
|
2569
2960
|
return false;
|
|
2570
2961
|
}
|
|
2571
|
-
const got = await fetchVerified(rel, remoteHash, budget.remaining() + claim);
|
|
2962
|
+
const got = await fetchVerified(rel, remoteHash, budget.remaining() + claim, claim);
|
|
2572
2963
|
if (!got.ok) {
|
|
2573
2964
|
out.failed.push({ rel, reason: got.reason });
|
|
2574
2965
|
if (got.overCap && budget.remaining() + claim < MAX_FILE_BYTES) {
|
|
@@ -2795,9 +3186,13 @@ function referencedAssetNames(designRoot: string): Set<string> {
|
|
|
2795
3186
|
return out;
|
|
2796
3187
|
}
|
|
2797
3188
|
|
|
2798
|
-
/**
|
|
2799
|
-
|
|
3189
|
+
/**
|
|
3190
|
+
* 0 = the open canvas's own files, imports and assets (#204), 1 = an annotation-referenced asset,
|
|
3191
|
+
* 2 = everything else.
|
|
3192
|
+
*/
|
|
3193
|
+
function rank(rel: string, referenced: Set<string>, wanted: ReadonlySet<string>): number {
|
|
3194
|
+
if (wanted.has(rel)) return 0;
|
|
2800
3195
|
const slash = rel.lastIndexOf('/');
|
|
2801
3196
|
const base = slash === -1 ? rel : rel.slice(slash + 1);
|
|
2802
|
-
return referenced.has(base) ?
|
|
3197
|
+
return referenced.has(base) ? 1 : 2;
|
|
2803
3198
|
}
|