@defrex/autobuild 1.9.0 → 1.11.0
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 +3 -3
- package/SPEC.md +2232 -175
- package/bin/ab-dispatch-generation.ts +5 -1
- package/docs/accounts.md +2 -1
- package/docs/agent-runtimes.md +30 -3
- package/docs/answering-blocked-builds.md +35 -7
- package/docs/architecture.md +436 -63
- package/docs/build-store.md +10 -7
- package/docs/builds.md +5 -0
- package/docs/cli.md +40 -2
- package/docs/configuration-overview.md +5 -1
- package/docs/configuration.md +649 -74
- package/docs/dispatcher.md +79 -6
- package/docs/forges.md +8 -1
- package/docs/getting-started.md +1 -1
- package/docs/integration-overview.md +4 -2
- package/docs/integration-tree.md +102 -11
- package/docs/merge-policy.md +30 -14
- package/docs/migration-1.0.md +2 -1
- package/docs/operating.md +36 -6
- package/docs/operator-api.md +251 -20
- package/docs/operator-surfaces.md +85 -0
- package/docs/optimization-nodes.md +1100 -0
- package/docs/overview.md +1 -1
- package/docs/plugin-authoring.md +83 -13
- package/docs/remote-store-protocol.md +137 -17
- package/docs/remote-ticket-protocol.md +90 -2
- package/docs/restacking.md +119 -15
- package/docs/seams.md +2 -2
- package/docs/setup.md +27 -4
- package/docs/skills.md +4 -2
- package/docs/spec-standard.md +2 -1
- package/docs/ticket-dependencies.md +15 -3
- package/docs/ticket-migration.md +4 -2
- package/docs/ticket-sources.md +54 -14
- package/docs/tickets.md +21 -6
- package/docs/troubleshooting.md +11 -2
- package/docs/verification.md +15 -3
- package/docs/workspaces.md +6 -1
- package/package.json +9 -5
- package/packages/core/src/accounts/chatgpt-oauth.ts +7 -5
- package/packages/core/src/cli/accounts.ts +7 -2
- package/packages/core/src/cli/attempt.ts +103 -0
- package/packages/core/src/cli/attention.ts +11 -2
- package/packages/core/src/cli/binary-direct.ts +54 -1
- package/packages/core/src/cli/binary-lifecycle.ts +2 -1
- package/packages/core/src/cli/binary.ts +5 -3
- package/packages/core/src/cli/build-control.ts +407 -67
- package/packages/core/src/cli/context.ts +272 -15
- package/packages/core/src/cli/dashboard/detail.ts +26 -2
- package/packages/core/src/cli/dashboard/facts.ts +89 -56
- package/packages/core/src/cli/dashboard/header.ts +101 -0
- package/packages/core/src/cli/dashboard/integration-detail.ts +7 -2
- package/packages/core/src/cli/dashboard/landing-display.ts +15 -2
- package/packages/core/src/cli/dashboard/model.ts +133 -66
- package/packages/core/src/cli/dashboard/objective-row.ts +221 -0
- package/packages/core/src/cli/dashboard/poll.ts +178 -76
- package/packages/core/src/cli/dashboard/render.ts +172 -227
- package/packages/core/src/cli/dashboard/reopen-display.ts +39 -0
- package/packages/core/src/cli/dashboard/row-text.ts +538 -0
- package/packages/core/src/cli/dashboard/timeline.ts +288 -0
- package/packages/core/src/cli/dashboard/tree.ts +12 -1
- package/packages/core/src/cli/dashboard/vocabulary.ts +188 -0
- package/packages/core/src/cli/dispatch-args.ts +44 -1
- package/packages/core/src/cli/dispatch-frontend.ts +29 -30
- package/packages/core/src/cli/dispatch-launch-stop.ts +73 -0
- package/packages/core/src/cli/dispatch-launcher.ts +41 -46
- package/packages/core/src/cli/dispatch-repository-feed.ts +1 -1
- package/packages/core/src/cli/dispatch-web.ts +155 -0
- package/packages/core/src/cli/dispatch.ts +216 -38
- package/packages/core/src/cli/env.ts +42 -0
- package/packages/core/src/cli/help.ts +293 -12
- package/packages/core/src/cli/init-agent.ts +4 -1
- package/packages/core/src/cli/init-readiness-remote.ts +3 -2
- package/packages/core/src/cli/init-validation.ts +5 -5
- package/packages/core/src/cli/init.ts +3 -2
- package/packages/core/src/cli/judge-entry.ts +82 -0
- package/packages/core/src/cli/judge.ts +233 -0
- package/packages/core/src/cli/landings.ts +3 -2
- package/packages/core/src/cli/main.ts +481 -148
- package/packages/core/src/cli/mcp.ts +35 -3
- package/packages/core/src/cli/measurement-text.ts +19 -0
- package/packages/core/src/cli/objective.ts +154 -0
- package/packages/core/src/cli/operator-preference.ts +57 -0
- package/packages/core/src/cli/publication-settlement.ts +106 -22
- package/packages/core/src/cli/repo-lease.ts +3 -0
- package/packages/core/src/cli/repo-state.ts +56 -6
- package/packages/core/src/cli/repository-status.ts +205 -56
- package/packages/core/src/cli/status.ts +275 -16
- package/packages/core/src/cli/store-opening.ts +4 -0
- package/packages/core/src/cli/terminal-restore.ts +32 -7
- package/packages/core/src/cli/terminals.ts +205 -8
- package/packages/core/src/cli/ticket-start.ts +53 -0
- package/packages/core/src/cli/ticket.ts +166 -38
- package/packages/core/src/cli/upgrade-agent.ts +12 -8
- package/packages/core/src/cli/wait.ts +22 -8
- package/packages/core/src/cli/watch.ts +361 -95
- package/packages/core/src/cli/web.ts +139 -0
- package/packages/core/src/config/create-labels.ts +23 -0
- package/packages/core/src/config/live.ts +101 -14
- package/packages/core/src/config/load.ts +61 -20
- package/packages/core/src/config/local.ts +212 -0
- package/packages/core/src/config/pipeline-source.ts +3 -3
- package/packages/core/src/config/reference.ts +18 -0
- package/packages/core/src/config/roles.ts +182 -73
- package/packages/core/src/config/schema.ts +157 -19
- package/packages/core/src/events/catalog.ts +43 -3
- package/packages/core/src/events/compatibility.ts +7 -1
- package/packages/core/src/events/payloads.ts +685 -1
- package/packages/core/src/events/policy.ts +63 -0
- package/packages/core/src/events/repository.ts +153 -27
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +1797 -199
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/017d8dd5bb6dd80b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/0ab2a90d0305dc9d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/10a4657408d4e121.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1152a2e97ee81728.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/13ca84752c5f8b54.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1411d1cdbdd9911e.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1444fe1fa7fc802c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1491ac0600349391.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/178e12f1759b7552.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1921f86f752428c9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1972c1d66008ef6b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/19e8e43e7f3f1a06.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/20a85c143c3e8164.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/21ce2c0bf58318e1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/293dcb3a94fb3470.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/2ab7436356267118.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/2d084641735caaff.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/3237bcecf68e5db9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/33d0cc593610e56f.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/3451ed2136dcc356.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/358ec8693f2237e6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/35cf9ccc4478b2d2.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/3649e7bd1203f154.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/378da6dece82202a.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/38c75099d9191471.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/398952f1f01db1a3.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/3b64d352d56c9121.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/3dc486226c05372d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/431c9bb2ee8838e0.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4400dffca929e2f0.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/49064fc079964a5c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4932c70a2af97faf.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4edded75f17742f4.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4f00c0f2c8afd159.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/516a5a7aadf97587.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/516dc6ea85d67cd7.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/536085773daf6b58.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/584e2ba74608e051.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/59ffaa6974094c72.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/5bb43afb121674c6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/5f0ca42af862c4ee.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6118031132db9bfc.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/63107a8d58776b63.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/63546b08d4d6fa11.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/643d70429ce03dad.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/677ea92572c29082.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6ae5bf60504d6467.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6bd6275061aaffa5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6efdc8defc75fccb.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/71c53d33f09d8204.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/7267ca2757cffba7.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/76b7d4244082b3f9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/7749f918c6f10968.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/7833e42d16301424.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/7d4edad0614adaf1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/837365898d04f45a.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/85f9f0c921b8b5bb.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8879f57a24733897.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/88cb9e71bdec972d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/89625654b02e9ac1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8a0cd6dd06cc155e.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8aa9ca8609dc051d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8c8640255bd61658.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8cc15eb1807c0157.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8ced97c44bc0af3a.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8d4144004720b9f8.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8db633ead1807f8b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8e42cdbd0994ab0c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9011d0f6ff955ef9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/916ebc5433801c41.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9539b995af5c54a9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/95f391bfd7b7dbd7.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9613e8fa568a9281.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9a68f8753bd9038d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9b25e58227080094.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9ee3919fbd4f9458.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a04a34cc2717147b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a0b32c12e4e6edb6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a55218252707bdd3.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a732fd08b31522a6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a98af134be2da8a9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a9d206a01f9039e5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/abf7fe3c92c82f2d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ac928b04842c00db.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/af953392d81911da.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/b0d877c44810ecb0.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/b0f7c6ebb2db57fc.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/b905c22ec17eed31.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/bce0c54e865f4b79.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/c68b7ee2e2610f30.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/c7f7e0378aeea237.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/c98cb1659eb142b6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ca830adf06ed55a1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/cb3a219f33e437ca.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/cf1e0c0d82567e0c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d008d86d9ff77b30.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d1432a819d8e48c5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d185ed6aa9192aff.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d5d5ccca80a893d8.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d873fad29d6c7e55.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/db84b12316e2da4a.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ddf6dc967d898767.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/dfc64de6e7bfc0a0.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/e2f18fa32fe1f6d0.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/e37393fed29e84c5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/e6a8585e2a054ff6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/e7e9e327baca6903.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/e86447af0571672c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ea819202d22122e5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/eb4535585f2e84f6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/eb7ddd5319d09e27.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/eca4959b2b87ae15.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ee10d7959ec4843c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ef1b68347966ab26.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f3e55425cc41f230.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f40042c1cdb9fd43.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f48466215c790a3f.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f5b9ace9b59351e7.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f8155387eb5f375c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/fa8f1475a55be935.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/fb21116a15d0b1f1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/fe95444fbeabe592.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/09bf0a1611d07363.json +984 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/10eac4988d66e161.json +1067 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/1a436b5fb45aee3e.json +1116 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/249db6f7a41f90e2.json +161 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/25dcb2fb6eaa83f4.json +858 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/2e1bdc763924616f.json +4932 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/30e9dabce3c4263d.json +399 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3c27f918b194e3b3.json +465 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/4898ef339c68fa36.json +83 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/51816c0ffa62af6e.json +417 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/561bf45320062a44.json +83 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/5672d0233085d050.json +84 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/5e39f42cbdbf35ef.json +163 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/7771a7a2250f9964.json +868 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/79f0e0f4ccd43ba2.json +455 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/859c09edac738823.json +1086 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/881c491321bec99a.json +1074 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/965f25c3af1d2cdc.json +160 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9b76d89da575ca90.json +20 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9eb485320a72a9ff.json +233 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a283c1f3462b1cc1.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a60448c01016135e.json +18 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a6584fb61b6679bd.json +97 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a6e570fb126991ff.json +36 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a8acf22c968b6e3d.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/ba7b85895bf6698e.json +1153 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/c88365c25b3186d3.json +543 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e8f0481b23f90056.json +711 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/ee55782ed40ebbac.json +110 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fc5082fac8167f3d.json +98 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fc66408cde0b6b04.json +637 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fd55c329cfe921cc.json +1069 -0
- package/packages/core/src/kernel/attempt-creation-key.ts +20 -0
- package/packages/core/src/kernel/attempt-settlement.ts +125 -0
- package/packages/core/src/kernel/auto-merge-default.ts +1 -3
- package/packages/core/src/kernel/auto-merge.ts +1 -3
- package/packages/core/src/kernel/build-roster.ts +230 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +316 -40
- package/packages/core/src/kernel/dispatch-placement.ts +1 -1
- package/packages/core/src/kernel/dispatch-settings.ts +1 -4
- package/packages/core/src/kernel/dispatch-status.ts +3 -5
- package/packages/core/src/kernel/dispatch-upgrade.ts +1 -1
- package/packages/core/src/kernel/engine.ts +152 -18
- package/packages/core/src/kernel/execution-intervals.ts +61 -0
- package/packages/core/src/kernel/forge-checks.ts +140 -0
- package/packages/core/src/kernel/forge-health.ts +2 -2
- package/packages/core/src/kernel/generated-files.ts +43 -0
- package/packages/core/src/kernel/generated-regeneration.ts +254 -0
- package/packages/core/src/kernel/generators/build-log.ts +30 -2
- package/packages/core/src/kernel/generators/optimization-log.ts +679 -0
- package/packages/core/src/kernel/generators/panel-log.ts +133 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +13 -0
- package/packages/core/src/kernel/guarded-forge.ts +76 -11
- package/packages/core/src/kernel/harvest.ts +1 -4
- package/packages/core/src/kernel/head-paths.ts +4 -1
- package/packages/core/src/kernel/history-retention.ts +337 -0
- package/packages/core/src/kernel/incremental-fixtures.ts +6 -0
- package/packages/core/src/kernel/incremental.ts +14 -4
- package/packages/core/src/kernel/integration-landing.ts +64 -13
- package/packages/core/src/kernel/integration-stack.ts +123 -20
- package/packages/core/src/kernel/integration-state.ts +39 -2
- package/packages/core/src/kernel/janitor-failure.ts +2 -0
- package/packages/core/src/kernel/kernel-git.ts +1 -1
- package/packages/core/src/kernel/landing-measurement.ts +275 -0
- package/packages/core/src/kernel/landing-readiness.ts +2 -0
- package/packages/core/src/kernel/landing-state.ts +20 -1
- package/packages/core/src/kernel/leaf-restack-base.ts +33 -7
- package/packages/core/src/kernel/leaf-restack-state.ts +99 -4
- package/packages/core/src/kernel/log-index-value.ts +2 -0
- package/packages/core/src/kernel/log-index.ts +100 -3
- package/packages/core/src/kernel/measurement.ts +406 -0
- package/packages/core/src/kernel/mixed-version.ts +6 -3
- package/packages/core/src/kernel/node-landing.ts +92 -18
- package/packages/core/src/kernel/node-restack-state.ts +27 -1
- package/packages/core/src/kernel/node-restack-transaction.ts +80 -23
- package/packages/core/src/kernel/node-verification-context.ts +14 -4
- package/packages/core/src/kernel/open-pr-backpressure-state.ts +24 -0
- package/packages/core/src/kernel/open-pr-backpressure.ts +133 -0
- package/packages/core/src/kernel/optimization-admission.ts +490 -0
- package/packages/core/src/kernel/optimization.ts +953 -0
- package/packages/core/src/kernel/panel.ts +225 -0
- package/packages/core/src/kernel/phase-failures.ts +121 -0
- package/packages/core/src/kernel/phases.ts +42 -6
- package/packages/core/src/kernel/pr-attachments.ts +4 -16
- package/packages/core/src/kernel/pr-summary.ts +2 -2
- package/packages/core/src/kernel/published-branch-head.ts +60 -0
- package/packages/core/src/kernel/read-deferrals.ts +2 -2
- package/packages/core/src/kernel/read-facts.ts +69 -31
- package/packages/core/src/kernel/reconcile-restack.ts +352 -103
- package/packages/core/src/kernel/reducer-identity.ts +659 -0
- package/packages/core/src/kernel/reducer-registry.ts +62 -9
- package/packages/core/src/kernel/reducer-revisions.ts +75 -0
- package/packages/core/src/kernel/reducer.ts +269 -11
- package/packages/core/src/kernel/reopen-state.ts +48 -0
- package/packages/core/src/kernel/reopen.ts +143 -0
- package/packages/core/src/kernel/replay-retention.ts +208 -39
- package/packages/core/src/kernel/repository-attention.ts +1 -1
- package/packages/core/src/kernel/rollup.ts +61 -0
- package/packages/core/src/kernel/service-facts.ts +19 -7
- package/packages/core/src/kernel/setup-streak.ts +38 -0
- package/packages/core/src/kernel/step-durations.ts +257 -0
- package/packages/core/src/kernel/target-observation.ts +6 -1
- package/packages/core/src/kernel/target-rewrite-recovery.ts +116 -0
- package/packages/core/src/kernel/terminal-guard.ts +13 -5
- package/packages/core/src/kernel/ticket-handbacks.ts +1 -1
- package/packages/core/src/kernel/ticket-migrations.ts +1 -1
- package/packages/core/src/kernel/ticket-preparation.ts +1 -1
- package/packages/core/src/kernel/ticket-source-health.ts +1 -1
- package/packages/core/src/kernel/ticket-starts.ts +118 -0
- package/packages/core/src/kernel/ticket-wait.ts +37 -2
- package/packages/core/src/kernel/verify-diff-base.ts +67 -0
- package/packages/core/src/kernel/verify-stage-state.ts +1 -0
- package/packages/core/src/kernel/verify-stages.ts +51 -1
- package/packages/core/src/objective.ts +532 -0
- package/packages/core/src/ontology.ts +54 -6
- package/packages/core/src/operator/agent-context-serve.ts +631 -0
- package/packages/core/src/operator/annotations.ts +105 -4
- package/packages/core/src/operator/attention.ts +470 -0
- package/packages/core/src/operator/canonical-skills.ts +35 -0
- package/packages/core/src/operator/cli-equivalents.ts +270 -0
- package/packages/core/src/operator/context-prompts.ts +61 -0
- package/packages/core/src/operator/control.ts +2 -1
- package/packages/core/src/operator/index.ts +61 -1
- package/packages/core/src/operator/landings.ts +28 -19
- package/packages/core/src/operator/optimization.ts +314 -0
- package/packages/core/src/operator/protocol.ts +33 -1
- package/packages/core/src/operator/query.ts +137 -73
- package/packages/core/src/operator/read-view.ts +5 -2
- package/packages/core/src/operator/registry.ts +625 -59
- package/packages/core/src/operator/requests.ts +45 -20
- package/packages/core/src/operator/sandbox-host.ts +107 -11
- package/packages/core/src/operator/sandbox-resolver.ts +253 -0
- package/packages/core/src/operator/sandbox.ts +778 -82
- package/packages/core/src/operator/ticket-asset-list.ts +77 -0
- package/packages/core/src/operator/ticket-assets.ts +167 -0
- package/packages/core/src/operator/ticket-start.ts +152 -0
- package/packages/core/src/operator/tickets.ts +36 -4
- package/packages/core/src/plugin-sdk/index.ts +24 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/plugins/registry.ts +1 -0
- package/packages/core/src/ports/forge/contract.ts +9 -0
- package/packages/core/src/ports/forge/fake.ts +114 -2
- package/packages/core/src/ports/forge/git-blob.ts +15 -0
- package/packages/core/src/ports/forge/git-rewrite.ts +6 -4
- package/packages/core/src/ports/forge/github-readiness.ts +1 -1
- package/packages/core/src/ports/forge/github-transport.ts +156 -1
- package/packages/core/src/ports/forge/github.ts +388 -100
- package/packages/core/src/ports/forge/local-git.ts +61 -1
- package/packages/core/src/ports/forge/readiness.ts +15 -3
- package/packages/core/src/ports/forge-failure.ts +46 -0
- package/packages/core/src/ports/forge-request-context.ts +23 -1
- package/packages/core/src/ports/forge-telemetry.ts +16 -0
- package/packages/core/src/ports/runner/antigravity-test.fixture.ts +149 -0
- package/packages/core/src/ports/runner/antigravity.ts +1071 -0
- package/packages/core/src/ports/runner/claude-test.fixture.ts +71 -0
- package/packages/core/src/ports/runner/claude.ts +6 -1
- package/packages/core/src/ports/runner/codex-test.fixture.ts +63 -0
- package/packages/core/src/ports/runner/codex.ts +11 -2
- package/packages/core/src/ports/runner/contract.ts +25 -1
- package/packages/core/src/ports/runner/fake.ts +2 -2
- package/packages/core/src/ports/runner/native-cli-fixture.ts +40 -5
- package/packages/core/src/ports/runner/native-process-fixture.ts +4 -1
- package/packages/core/src/ports/runner/pi.ts +23 -7
- package/packages/core/src/ports/runner/production.ts +19 -2
- package/packages/core/src/ports/runner/session-env.ts +65 -5
- package/packages/core/src/ports/runner/start-prompt.ts +6 -4
- package/packages/core/src/ports/tickets/contract.ts +75 -2
- package/packages/core/src/ports/tickets/fake.ts +11 -0
- package/packages/core/src/ports/tickets/file.ts +18 -0
- package/packages/core/src/ports/tickets/github-fake.ts +136 -4
- package/packages/core/src/ports/tickets/github.ts +407 -35
- package/packages/core/src/ports/tickets/hosted-index.ts +16 -1
- package/packages/core/src/ports/tickets/labels.ts +21 -0
- package/packages/core/src/ports/tickets/linear.ts +163 -0
- package/packages/core/src/ports/tickets/migration.ts +2 -0
- package/packages/core/src/ports/tickets/priority.ts +20 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +105 -6
- package/packages/core/src/ports/tickets/remote.ts +203 -17
- package/packages/core/src/ports/tickets/search.ts +139 -0
- package/packages/core/src/ports/tickets/tree.ts +17 -4
- package/packages/core/src/ports/types.ts +202 -6
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +16 -4
- package/packages/core/src/ports/workspace/commit-preservation.ts +182 -64
- package/packages/core/src/ports/workspace/create.ts +18 -1
- package/packages/core/src/ports/workspace/fake.ts +340 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +846 -43
- package/packages/core/src/ports/workspace/operator-sandbox.ts +129 -12
- package/packages/core/src/ports/workspace/process-group.ts +48 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +1539 -221
- package/packages/core/src/processes/agent-context-assemble.ts +576 -0
- package/packages/core/src/processes/agent-context.ts +469 -0
- package/packages/core/src/processes/build-execution-state.ts +1 -3
- package/packages/core/src/processes/build-runner.ts +1982 -528
- package/packages/core/src/processes/dispatch-failure-budget.ts +1 -1
- package/packages/core/src/processes/dispatcher-selectors.ts +15 -13
- package/packages/core/src/processes/dispatcher.ts +3003 -308
- package/packages/core/src/processes/execution-no-progress.ts +40 -1
- package/packages/core/src/processes/execution-settlement.ts +2 -6
- package/packages/core/src/processes/harvest-execution-state.ts +2 -6
- package/packages/core/src/processes/harvest-runner.ts +7 -2
- package/packages/core/src/processes/infrastructure-failure-budget.ts +1 -3
- package/packages/core/src/processes/judge-launcher.ts +38 -0
- package/packages/core/src/processes/measurement-runner.ts +235 -0
- package/packages/core/src/processes/optimization-activity.ts +120 -0
- package/packages/core/src/processes/optimization-merges.ts +101 -0
- package/packages/core/src/processes/optimization-stop.ts +179 -0
- package/packages/core/src/processes/panel-runner.ts +756 -0
- package/packages/core/src/processes/phase-failure-budget.ts +2 -0
- package/packages/core/src/processes/publication-state.ts +1 -4
- package/packages/core/src/processes/repo-view.ts +154 -6
- package/packages/core/src/processes/sandbox-state.ts +54 -10
- package/packages/core/src/processes/tick-publication.ts +2 -0
- package/packages/core/src/processes/tick-state.ts +1 -3
- package/packages/core/src/processes/workspace-preparation.ts +76 -0
- package/packages/core/src/processes/workspace-preservation.ts +67 -9
- package/packages/core/src/scenarios/harness.ts +19 -13
- package/packages/core/src/store/account-redaction.ts +1 -0
- package/packages/core/src/store/adapter.ts +52 -1
- package/packages/core/src/store/agent-context.ts +432 -0
- package/packages/core/src/store/build-feed.ts +291 -0
- package/packages/core/src/store/build-scope.ts +19 -1
- package/packages/core/src/store/contract.ts +955 -14
- package/packages/core/src/store/digest.ts +104 -9
- package/packages/core/src/store/histogram.ts +113 -0
- package/packages/core/src/store/judge-authority.ts +161 -0
- package/packages/core/src/store/local/schema.ts +62 -0
- package/packages/core/src/store/local/store.ts +628 -22
- package/packages/core/src/store/local/ticket-asset-heads.ts +23 -0
- package/packages/core/src/store/memory.ts +461 -69
- package/packages/core/src/store/open-builds.ts +19 -0
- package/packages/core/src/store/phase-session.ts +256 -6
- package/packages/core/src/store/reduced-reads.ts +24 -4
- package/packages/core/src/store/reducer-value-shapes.json +18023 -11824
- package/packages/core/src/store/reducer-values.ts +6 -1
- package/packages/core/src/store/remote/client.ts +220 -4
- package/packages/core/src/store/remote/compatibility.ts +1 -1
- package/packages/core/src/store/remote/credentials.ts +31 -1
- package/packages/core/src/store/remote/index.ts +41 -0
- package/packages/core/src/store/remote/protocol.ts +107 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.10.0.json +34439 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.0.json +35680 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/remote/token.ts +13 -4
- package/packages/core/src/store/repo-state-events.ts +6 -8
- package/packages/core/src/store/retention.ts +23 -1
- package/packages/core/src/store/rollups.ts +337 -0
- package/packages/core/src/store/session-handle.ts +20 -2
- package/packages/core/src/store/session-reducer.ts +1 -4
- package/packages/core/src/store/snapshots.ts +10 -0
- package/packages/core/src/store/ticket-assets.ts +1 -3
- package/packages/core/src/store/types.ts +117 -9
- package/packages/core/src/testing/dispatch-read-budget.ts +1162 -2
- package/packages/core/src/testing/git-config-isolation.ts +27 -0
- package/packages/core/src/testing/index.ts +40 -0
- package/packages/core/src/testing/memory-operator-sandbox.ts +346 -0
- package/packages/core/src/testing/reduced-read-budget.ts +5349 -153
- package/packages/core/src/web/analytics-source.ts +303 -0
- package/packages/core/src/web/assets/Atkinson-OFL.txt +93 -0
- package/packages/core/src/web/assets/AtkinsonHyperlegibleNext.latin.woff2 +0 -0
- package/packages/core/src/web/assets/JetBrains-OFL.txt +93 -0
- package/packages/core/src/web/assets/JetBrainsMono.latin.woff2 +0 -0
- package/packages/core/src/web/assets/app.css +1 -0
- package/packages/core/src/web/assets/app.js +9 -0
- package/packages/core/src/web/assets/manifest.json +31 -0
- package/packages/core/src/web/assets/theme.js +1 -0
- package/packages/core/src/web/bounded.ts +31 -0
- package/packages/core/src/web/http.ts +315 -0
- package/packages/core/src/web/hub.ts +160 -0
- package/packages/core/src/web/options.ts +38 -0
- package/packages/core/src/web/overview-source.ts +322 -0
- package/packages/core/src/web/page.ts +56 -0
- package/packages/core/src/web/protocol.ts +151 -0
- package/packages/core/src/web/read-only.ts +23 -0
- package/packages/core/src/web/repository-source.ts +35 -0
- package/packages/core/src/web/server.ts +97 -0
- package/skills/code-review/SKILL.md +26 -2
- package/skills/finalize/SKILL.md +10 -4
- package/skills/guide/SKILL.md +743 -123
- package/skills/guide/references/accounts.md +2 -1
- package/skills/guide/references/integration-tree.md +102 -11
- package/skills/guide/references/merge-policy.md +30 -14
- package/skills/guide/references/migration-1.0.md +2 -1
- package/skills/guide/references/operator-api.md +251 -20
- package/skills/guide/references/optimization-nodes.md +1100 -0
- package/skills/guide/references/plugin-authoring.md +83 -13
- package/skills/guide/references/remote-store-protocol.md +137 -17
- package/skills/guide/references/remote-ticket-protocol.md +90 -2
- package/skills/guide/references/restacking.md +119 -15
- package/skills/guide/references/setup.md +27 -4
- package/skills/guide/references/spec-standard.md +2 -1
- package/skills/guide/references/ticket-dependencies.md +15 -3
- package/skills/guide/references/ticket-migration.md +4 -2
- package/skills/implement/SKILL.md +74 -5
- package/skills/judge/SKILL.md +43 -0
- package/skills/operate/SKILL.md +374 -57
- package/skills/plan/SKILL.md +28 -4
- package/skills/plan-review/SKILL.md +24 -3
- package/skills/propose/SKILL.md +121 -0
- package/skills/reconcile/SKILL.md +21 -2
- package/skills/spec/SKILL.md +63 -11
- package/skills/tickets/SKILL.md +94 -9
- package/templates/hosted-service/package.json +2 -2
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from '../../accounts/availability'
|
|
5
5
|
import { WorkspaceCleanupRequired } from '../types'
|
|
6
6
|
import { inspectGitCandidate, preserveGitCommits, restoreGitCommits } from './commit-preservation'
|
|
7
|
+
import { isArchiveRefusal } from '../../kernel/history-retention'
|
|
7
8
|
import { accountPolicy, accountGuestEnvironment } from './account-policy'
|
|
8
9
|
import { HOSTED_ACCOUNT_READINESS_ENV } from '../../accounts/hosted-readiness'
|
|
9
10
|
import { gitRewrite, parseRemoteHead } from '../forge/git-rewrite'
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
} from '../../config/schema'
|
|
21
22
|
import { distributionStampFor, resolveDistributionArchive } from './distribution-archive'
|
|
22
23
|
import type {
|
|
24
|
+
ForgeRewrite,
|
|
23
25
|
WorkspaceHandle,
|
|
24
26
|
WorkspaceProvider,
|
|
25
27
|
WorkspaceProvisionResult,
|
|
@@ -32,7 +34,14 @@ import {
|
|
|
32
34
|
type SandboxCommandRequest,
|
|
33
35
|
type SandboxCommandResult,
|
|
34
36
|
type SandboxEnvironmentIdentity,
|
|
37
|
+
type SandboxProviderStatus,
|
|
38
|
+
type SandboxProvisionStage,
|
|
39
|
+
type SandboxRefreshResult,
|
|
35
40
|
type SandboxWaitResult,
|
|
41
|
+
redactSandboxMessage,
|
|
42
|
+
SANDBOX_INTERRUPTED_MESSAGE,
|
|
43
|
+
SANDBOX_REFRESH_DIRTY_MESSAGE,
|
|
44
|
+
sandboxRefreshDivergedMessage,
|
|
36
45
|
} from './operator-sandbox'
|
|
37
46
|
import type {
|
|
38
47
|
BuildExecution,
|
|
@@ -184,14 +193,19 @@ export interface VercelSandboxHandle {
|
|
|
184
193
|
stop(opts?: { signal?: AbortSignal }): Promise<unknown>
|
|
185
194
|
delete(opts?: { signal?: AbortSignal }): Promise<void>
|
|
186
195
|
update(
|
|
187
|
-
params: { networkPolicy
|
|
196
|
+
params: { networkPolicy?: NetworkPolicy; timeout?: number },
|
|
188
197
|
opts?: { signal?: AbortSignal },
|
|
189
198
|
): Promise<unknown>
|
|
199
|
+
/** Add `duration` ms to the running session's lifetime (SDK
|
|
200
|
+
* `extendTimeout`: additive, never a set). */
|
|
201
|
+
extendTimeout(duration: number, opts?: { signal?: AbortSignal }): Promise<void>
|
|
190
202
|
}
|
|
191
203
|
|
|
192
204
|
export type VercelSandboxCreateInput = {
|
|
193
205
|
name: string
|
|
194
|
-
source
|
|
206
|
+
/** Absent starts a sandbox without a git source (SDK 3.1.0); only the
|
|
207
|
+
* deployment-fallback operator sandbox omits it and clones in the guest. */
|
|
208
|
+
source?: {
|
|
195
209
|
type: 'git'
|
|
196
210
|
url: string
|
|
197
211
|
revision: string
|
|
@@ -236,6 +250,15 @@ export const VERCEL_LIFETIME_MARGIN_MS = 5 * 60 * 1000
|
|
|
236
250
|
* much per observation; the next tick retries. */
|
|
237
251
|
export const VERCEL_OBSERVE_WAIT_MS = 5_000
|
|
238
252
|
|
|
253
|
+
/** The expected wall time of one build `provision`: clone, Bun, system steps,
|
|
254
|
+
* distribution, dependencies, runtime installs and a snapshot stop typically
|
|
255
|
+
* take two to three minutes. A bounded dispatcher invocation won't start
|
|
256
|
+
* provisioning with less budget left. It errs low: an estimate too high would
|
|
257
|
+
* starve builds whenever pre-dispatch tick work is slow, while one slightly
|
|
258
|
+
* too low only costs an uncharged teardown abandonment the next invocation
|
|
259
|
+
* finishes. */
|
|
260
|
+
export const VERCEL_PROVISION_ESTIMATE_MS = 150_000
|
|
261
|
+
|
|
239
262
|
/** The snapshot rows that hold billed storage. `deleted`/`failed` rows hold
|
|
240
263
|
* none and are never purge targets. */
|
|
241
264
|
const LIVE_SNAPSHOT_STATUS = 'created'
|
|
@@ -498,7 +521,15 @@ export async function purgeEnvironmentSnapshots(
|
|
|
498
521
|
|
|
499
522
|
const cleanGithubOrigin = validateVercelGithubOrigin
|
|
500
523
|
|
|
524
|
+
/** The build slug a build branch names: leaves use `ab/<slug>`, integration
|
|
525
|
+
* nodes `ab-node/<slug>`. The delegation target must name the build itself. */
|
|
526
|
+
function buildSlugFromBranch(branch: string): string {
|
|
527
|
+
return branch.replace(/^ab(?:-node)?\//, '')
|
|
528
|
+
}
|
|
529
|
+
|
|
501
530
|
function sandboxName(origin: string, branch: string, generation = 0): string {
|
|
531
|
+
// Deliberately strips only the leaf prefix, unlike `buildSlugFromBranch`:
|
|
532
|
+
// changing the readable label would rename, and so orphan, live node sandboxes.
|
|
502
533
|
const readable = branch
|
|
503
534
|
.replace(/^ab\//, '')
|
|
504
535
|
.toLowerCase()
|
|
@@ -626,6 +657,30 @@ async function relocateCheckout(
|
|
|
626
657
|
}
|
|
627
658
|
}
|
|
628
659
|
|
|
660
|
+
/** Clone the bare HTTPS origin inside the guest with no credential in argv,
|
|
661
|
+
* env or git config; the host-side upload-pack egress transform authenticates
|
|
662
|
+
* the two upload-pack requests. `GIT_TERMINAL_PROMPT=0` makes a missing
|
|
663
|
+
* transform fail fast instead of prompting. */
|
|
664
|
+
async function guestCloneCheckout(
|
|
665
|
+
sandbox: VercelSandboxHandle,
|
|
666
|
+
url: string,
|
|
667
|
+
head: string,
|
|
668
|
+
): Promise<void> {
|
|
669
|
+
await commandOrThrow(sandbox, {
|
|
670
|
+
cmd: 'mkdir',
|
|
671
|
+
args: ['-p', VERCEL_WORKSPACE_PATH.slice(0, VERCEL_WORKSPACE_PATH.lastIndexOf('/'))],
|
|
672
|
+
})
|
|
673
|
+
await commandOrThrow(sandbox, {
|
|
674
|
+
cmd: 'git',
|
|
675
|
+
args: ['clone', '--no-checkout', url, VERCEL_WORKSPACE_PATH],
|
|
676
|
+
env: { GIT_TERMINAL_PROMPT: '0' },
|
|
677
|
+
})
|
|
678
|
+
await commandOrThrow(sandbox, {
|
|
679
|
+
cmd: 'git',
|
|
680
|
+
args: ['-C', VERCEL_WORKSPACE_PATH, 'checkout', '--detach', head],
|
|
681
|
+
})
|
|
682
|
+
}
|
|
683
|
+
|
|
629
684
|
async function commandOrThrow(
|
|
630
685
|
sandbox: VercelSandboxHandle,
|
|
631
686
|
params: {
|
|
@@ -874,6 +929,33 @@ async function readableCommand(
|
|
|
874
929
|
return stdout
|
|
875
930
|
}
|
|
876
931
|
|
|
932
|
+
/** The commit the guest checkout is actually on: HEAD and the build branch
|
|
933
|
+
* must resolve to the same commit, which is the only base a provisioning
|
|
934
|
+
* fact may record (AUT-1252). */
|
|
935
|
+
async function checkedOutBranchHead(
|
|
936
|
+
sandbox: VercelSandboxHandle,
|
|
937
|
+
branch: string,
|
|
938
|
+
signal?: AbortSignal,
|
|
939
|
+
): Promise<string> {
|
|
940
|
+
const stdout = await readableCommand(sandbox, {
|
|
941
|
+
cmd: 'git',
|
|
942
|
+
args: ['rev-parse', 'HEAD^{commit}', `refs/heads/${branch}^{commit}`],
|
|
943
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
944
|
+
...(signal ? { signal } : {}),
|
|
945
|
+
})
|
|
946
|
+
const lines = stdout
|
|
947
|
+
.split('\n')
|
|
948
|
+
.map((line) => line.trim())
|
|
949
|
+
.filter((line) => line.length > 0)
|
|
950
|
+
const objectId = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
951
|
+
if (lines.length !== 2 || !lines.every((line) => objectId.test(line)))
|
|
952
|
+
throw new Error(`unreadable checkout head for ${branch}: ${JSON.stringify(stdout.trim())}`)
|
|
953
|
+
const [head, branchHead] = lines as [string, string]
|
|
954
|
+
if (head !== branchHead)
|
|
955
|
+
throw new Error(`checkout HEAD ${head} disagrees with ${branch} at ${branchHead}`)
|
|
956
|
+
return head
|
|
957
|
+
}
|
|
958
|
+
|
|
877
959
|
/** Create, inspect, and always delete one remote readiness environment. Unlike
|
|
878
960
|
* build provisioning this never uses a stable name, branch, or marker. */
|
|
879
961
|
export async function validateVercelSandbox(
|
|
@@ -1203,6 +1285,201 @@ async function effectiveArchive(
|
|
|
1203
1285
|
return (await resolveDistributionArchive()).archive
|
|
1204
1286
|
}
|
|
1205
1287
|
|
|
1288
|
+
// ── Operator sandbox provisioning state (#1246) ─────────────────────────────
|
|
1289
|
+
//
|
|
1290
|
+
// A hosted deployment composes the provider per warm function instance and
|
|
1291
|
+
// may freeze it after the response, so provisioning state lives in the
|
|
1292
|
+
// guest, where any process can read it with one probe command. The host
|
|
1293
|
+
// phase (create, checkout, scrub, Bun, system provisioning, distribution)
|
|
1294
|
+
// runs in the caller's background; the slow tail (dependencies, runtimes,
|
|
1295
|
+
// setup, marker) runs as one detached guest command bounded only by the
|
|
1296
|
+
// session timer.
|
|
1297
|
+
|
|
1298
|
+
/** The guest directory holding one fresh provision's state, outside the
|
|
1299
|
+
* checkout: `host` (`<step> <guest epoch seconds>`, the host phase's
|
|
1300
|
+
* heartbeat), one `stage-NN-<name>.sh` per tail stage, `tail.sh`, the
|
|
1301
|
+
* tail's `pid`, `stage`, `log` and `failed` files, and `resuming` (the guest
|
|
1302
|
+
* epoch at which a runtime refresh of a provisioned environment started),
|
|
1303
|
+
* which outranks the success marker until that refresh succeeds. */
|
|
1304
|
+
export const VERCEL_OPERATOR_PROVISION_DIR = `${VERCEL_AUTOBUILD_PATH}/operator-provision`
|
|
1305
|
+
/** Heartbeat age after which a host phase with no running tail counts as
|
|
1306
|
+
* interrupted: above the 300-second hosted function limit, and every host
|
|
1307
|
+
* step refreshes the heartbeat. A host step longer than this on a long-lived
|
|
1308
|
+
* local `ab mcp` can be judged interrupted by another process; the journal's
|
|
1309
|
+
* compare-and-append still settles it once and the next open recovers. */
|
|
1310
|
+
export const VERCEL_OPERATOR_HOST_STALE_SECONDS = 600
|
|
1311
|
+
/** Grace after the `launched` heartbeat for the detached tail to record its
|
|
1312
|
+
* pid before a missing tail counts as interrupted. */
|
|
1313
|
+
export const VERCEL_OPERATOR_LAUNCH_GRACE_SECONDS = 30
|
|
1314
|
+
|
|
1315
|
+
/** Host-phase heartbeat steps. `launched` follows the tail launch. */
|
|
1316
|
+
type OperatorHostStep = 'checkout' | 'provision' | 'launched'
|
|
1317
|
+
|
|
1318
|
+
const PROVISION_STAGES: readonly SandboxProvisionStage[] = [
|
|
1319
|
+
'checkout',
|
|
1320
|
+
'setup',
|
|
1321
|
+
'environment',
|
|
1322
|
+
'resume',
|
|
1323
|
+
'provision',
|
|
1324
|
+
]
|
|
1325
|
+
|
|
1326
|
+
/** One classified probe of an operator sandbox's guest state. Rows are
|
|
1327
|
+
* checked in order and the first match wins: a recorded failure always
|
|
1328
|
+
* outranks an older success marker. */
|
|
1329
|
+
export type VercelOperatorProbe =
|
|
1330
|
+
| { kind: 'failed'; record: string; log: string }
|
|
1331
|
+
| { kind: 'resuming'; ageSeconds: number }
|
|
1332
|
+
| {
|
|
1333
|
+
kind: 'ready'
|
|
1334
|
+
marker: { baseSha?: string }
|
|
1335
|
+
headSha?: string
|
|
1336
|
+
bunVersion?: string
|
|
1337
|
+
distribution?: string
|
|
1338
|
+
}
|
|
1339
|
+
| { kind: 'running'; stage?: string }
|
|
1340
|
+
| { kind: 'host'; step: string; ageSeconds: number }
|
|
1341
|
+
| { kind: 'none' }
|
|
1342
|
+
|
|
1343
|
+
/** The read-only probe, run as `sh -c <script> probe <dir> <marker>
|
|
1344
|
+
* <workspace> <bun> <distribution marker>` with no environment. File
|
|
1345
|
+
* contents ride base64-encoded so the parser never sees raw guest bytes;
|
|
1346
|
+
* ages come from the guest clock. */
|
|
1347
|
+
export const VERCEL_OPERATOR_PROBE_SCRIPT = [
|
|
1348
|
+
'd=$1',
|
|
1349
|
+
'enc() { base64 | tr -d "\\n"; }',
|
|
1350
|
+
'if [ -f "$d/failed" ]; then',
|
|
1351
|
+
' echo "result failed"',
|
|
1352
|
+
' printf "failed %s\\n" "$(head -c 4096 "$d/failed" | enc)"',
|
|
1353
|
+
' printf "log %s\\n" "$(tail -c 4096 "$d/log" 2>/dev/null | enc)"',
|
|
1354
|
+
' exit 0',
|
|
1355
|
+
'fi',
|
|
1356
|
+
'if [ -f "$d/resuming" ]; then',
|
|
1357
|
+
' echo "result resuming"',
|
|
1358
|
+
' printf "resuming %s\\n" "$(head -n 1 "$d/resuming")"',
|
|
1359
|
+
' printf "now %s\\n" "$(date +%s)"',
|
|
1360
|
+
' exit 0',
|
|
1361
|
+
'fi',
|
|
1362
|
+
'if [ -f "$2" ]; then',
|
|
1363
|
+
' echo "result ready"',
|
|
1364
|
+
' printf "marker %s\\n" "$(head -c 4096 "$2" | enc)"',
|
|
1365
|
+
' printf "head %s\\n" "$(git -C "$3" rev-parse HEAD 2>/dev/null)"',
|
|
1366
|
+
' printf "bun %s\\n" "$("$4" --version 2>/dev/null | head -n 1)"',
|
|
1367
|
+
' printf "distribution %s\\n" "$(head -n 1 "$5" 2>/dev/null)"',
|
|
1368
|
+
' exit 0',
|
|
1369
|
+
'fi',
|
|
1370
|
+
'pid=$(cat "$d/pid" 2>/dev/null)',
|
|
1371
|
+
'if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null && grep -q tail.sh "/proc/$pid/cmdline" 2>/dev/null; then',
|
|
1372
|
+
' echo "result running"',
|
|
1373
|
+
' printf "stage %s\\n" "$(head -n 1 "$d/stage" 2>/dev/null)"',
|
|
1374
|
+
' exit 0',
|
|
1375
|
+
'fi',
|
|
1376
|
+
'if [ -f "$d/host" ]; then',
|
|
1377
|
+
' echo "result host"',
|
|
1378
|
+
' printf "host %s\\n" "$(head -n 1 "$d/host")"',
|
|
1379
|
+
' printf "now %s\\n" "$(date +%s)"',
|
|
1380
|
+
' exit 0',
|
|
1381
|
+
'fi',
|
|
1382
|
+
'echo "result none"',
|
|
1383
|
+
].join('\n')
|
|
1384
|
+
|
|
1385
|
+
/** Parse the probe's `key value` lines. Unparseable output is `none`. */
|
|
1386
|
+
export function parseVercelOperatorProbe(stdout: string): VercelOperatorProbe {
|
|
1387
|
+
const fields = new Map<string, string>()
|
|
1388
|
+
for (const line of stdout.split('\n')) {
|
|
1389
|
+
const space = line.indexOf(' ')
|
|
1390
|
+
if (space > 0) fields.set(line.slice(0, space), line.slice(space + 1).trim())
|
|
1391
|
+
}
|
|
1392
|
+
const decode = (value: string | undefined): string =>
|
|
1393
|
+
value === undefined || value === '' ? '' : Buffer.from(value, 'base64').toString('utf8')
|
|
1394
|
+
const optional = (value: string | undefined): string | undefined =>
|
|
1395
|
+
value === undefined || value === '' ? undefined : value
|
|
1396
|
+
switch (fields.get('result')) {
|
|
1397
|
+
case 'failed':
|
|
1398
|
+
return {
|
|
1399
|
+
kind: 'failed',
|
|
1400
|
+
record: decode(fields.get('failed')),
|
|
1401
|
+
log: decode(fields.get('log')),
|
|
1402
|
+
}
|
|
1403
|
+
case 'ready': {
|
|
1404
|
+
let marker: { baseSha?: string } = {}
|
|
1405
|
+
try {
|
|
1406
|
+
const parsed = JSON.parse(decode(fields.get('marker'))) as { baseSha?: unknown }
|
|
1407
|
+
if (typeof parsed?.baseSha === 'string' && /^[0-9a-f]{40,64}$/.test(parsed.baseSha))
|
|
1408
|
+
marker = { baseSha: parsed.baseSha }
|
|
1409
|
+
} catch {
|
|
1410
|
+
// A legacy empty marker records no base head.
|
|
1411
|
+
}
|
|
1412
|
+
const headSha = optional(fields.get('head'))
|
|
1413
|
+
const bunVersion = optional(fields.get('bun'))
|
|
1414
|
+
const distribution = optional(fields.get('distribution'))
|
|
1415
|
+
return {
|
|
1416
|
+
kind: 'ready',
|
|
1417
|
+
marker,
|
|
1418
|
+
...(headSha !== undefined && /^[0-9a-f]{40,64}$/.test(headSha) ? { headSha } : {}),
|
|
1419
|
+
...(bunVersion !== undefined ? { bunVersion } : {}),
|
|
1420
|
+
...(distribution !== undefined ? { distribution } : {}),
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
case 'resuming': {
|
|
1424
|
+
const since = Number(fields.get('resuming'))
|
|
1425
|
+
const now = Number(fields.get('now'))
|
|
1426
|
+
return {
|
|
1427
|
+
kind: 'resuming',
|
|
1428
|
+
ageSeconds:
|
|
1429
|
+
Number.isFinite(since) && Number.isFinite(now) && fields.get('resuming') !== ''
|
|
1430
|
+
? Math.max(0, now - since)
|
|
1431
|
+
: 0,
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
case 'running': {
|
|
1435
|
+
const stage = optional(fields.get('stage'))
|
|
1436
|
+
return { kind: 'running', ...(stage !== undefined ? { stage } : {}) }
|
|
1437
|
+
}
|
|
1438
|
+
case 'host': {
|
|
1439
|
+
const [step = '', at = ''] = (fields.get('host') ?? '').split(/\s+/)
|
|
1440
|
+
const now = Number(fields.get('now'))
|
|
1441
|
+
const then = Number(at)
|
|
1442
|
+
const ageSeconds =
|
|
1443
|
+
Number.isFinite(now) && Number.isFinite(then) && at !== '' ? Math.max(0, now - then) : 0
|
|
1444
|
+
return { kind: 'host', step, ageSeconds }
|
|
1445
|
+
}
|
|
1446
|
+
default:
|
|
1447
|
+
return { kind: 'none' }
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
/** The file-safe form of a runtime name inside a tail stage name. */
|
|
1452
|
+
function tailRuntimeName(runtime: string): string {
|
|
1453
|
+
return runtime.replace(/[^A-Za-z0-9._-]+/g, '_')
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
/** Single-quote one value for a POSIX shell. */
|
|
1457
|
+
function shellQuote(value: string): string {
|
|
1458
|
+
return `'${value.split("'").join(`'\\''`)}'`
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/** A host-phase failure, already recorded in the guest when `created`. */
|
|
1462
|
+
class OperatorHostFailure extends Error {
|
|
1463
|
+
override readonly name = 'OperatorHostFailure'
|
|
1464
|
+
constructor(
|
|
1465
|
+
readonly failure: { stage: SandboxProvisionStage; message: string },
|
|
1466
|
+
readonly created: boolean,
|
|
1467
|
+
cause: unknown,
|
|
1468
|
+
) {
|
|
1469
|
+
super(failure.message, { cause })
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
/** A host phase stopped by `close` or `release`. */
|
|
1474
|
+
class OperatorAttemptCancelled extends Error {
|
|
1475
|
+
override readonly name = 'OperatorAttemptCancelled'
|
|
1476
|
+
constructor(readonly created: boolean) {
|
|
1477
|
+
super('operator sandbox provisioning was cancelled')
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
const DEPENDENCY_INSTALL_COMMAND = `if [ -f bun.lock ] || [ -f bun.lockb ]; then ${VERCEL_BUN_EXECUTABLE} install --frozen-lockfile; elif [ -f package-lock.json ]; then npm ci; elif [ -f pnpm-lock.yaml ]; then corepack pnpm install --frozen-lockfile; elif [ -f yarn.lock ]; then corepack yarn install --immutable; fi`
|
|
1482
|
+
|
|
1206
1483
|
export interface VercelSandboxProviderOptions {
|
|
1207
1484
|
delegateCredential?: typeof delegateCredential
|
|
1208
1485
|
config: VercelSandboxConfig
|
|
@@ -1226,6 +1503,10 @@ export interface VercelSandboxProviderOptions {
|
|
|
1226
1503
|
* the branch does not exist. Default runs `git ls-remote` from `repo` on
|
|
1227
1504
|
* the host. */
|
|
1228
1505
|
remoteBranchHead?: (branch: string) => Promise<string | undefined>
|
|
1506
|
+
/** Host-side archive fallback, called only after the guest git transport
|
|
1507
|
+
* refuses an exact archive push. It must create exactly that ref at that SHA,
|
|
1508
|
+
* create-only, and the guest's exact readback still decides publication. */
|
|
1509
|
+
refusedArchive?: (ref: string, sha: string) => Promise<void>
|
|
1229
1510
|
/** Test seam: the distribution identity stamp the current archive source
|
|
1230
1511
|
* delivers (package version plus remote-store protocol version plus the
|
|
1231
1512
|
* sha256 digest of the archive bytes, see `readDistributionIdentityStamp`).
|
|
@@ -1237,6 +1518,9 @@ export interface VercelSandboxProviderOptions {
|
|
|
1237
1518
|
/** Test seam: the bound on the observation path's wait on a command whose
|
|
1238
1519
|
* lookup shows no exit. Defaults to `VERCEL_OBSERVE_WAIT_MS`. */
|
|
1239
1520
|
observeWaitMs?: number
|
|
1521
|
+
/** Test seam: the expected wall time of one `provision`. Defaults to
|
|
1522
|
+
* `VERCEL_PROVISION_ESTIMATE_MS`. */
|
|
1523
|
+
provisionEstimateMs?: number
|
|
1240
1524
|
/** The repository's raw `[commands].setup` shell string, run once at the end
|
|
1241
1525
|
* of a fresh operator-sandbox provision (never on resume). Set once at
|
|
1242
1526
|
* construction; never per call. */
|
|
@@ -1246,6 +1530,20 @@ export interface VercelSandboxProviderOptions {
|
|
|
1246
1530
|
* environment is otherwise always built from an empty record — never the
|
|
1247
1531
|
* process environment — so no credential can leak in. */
|
|
1248
1532
|
sandboxEnvironmentVariables?: readonly string[]
|
|
1533
|
+
/** `[orchestrator.sandbox].idleMinutes` (default 30): the provider timeout
|
|
1534
|
+
* an operator sandbox is created and resumed with, extended by every tool
|
|
1535
|
+
* call, so the provider's own timer stops an idle sandbox. Build and
|
|
1536
|
+
* harvest workspaces keep `timeoutSeconds`. */
|
|
1537
|
+
sandboxIdleMinutes?: number
|
|
1538
|
+
/** Internal deployment composition only, never user configuration: the git
|
|
1539
|
+
* read credential of a hosted deployment's fallback operator sandbox. It is
|
|
1540
|
+
* placed only in the host-side upload-pack egress transform (GET
|
|
1541
|
+
* `info/refs?service=git-upload-pack` and POST `git-upload-pack`), never in
|
|
1542
|
+
* a create `source`, a guest command, or the guest env; the operator
|
|
1543
|
+
* sandbox is then created source-less and clones in the guest. Build
|
|
1544
|
+
* provisioning never uses it. Mutually exclusive with a configured
|
|
1545
|
+
* `gitPasswordEnv`. */
|
|
1546
|
+
egressReadCredential?: { username: string; password: string }
|
|
1249
1547
|
}
|
|
1250
1548
|
|
|
1251
1549
|
/** Vercel-backed working copy and executor. Completed SDK command output is
|
|
@@ -1291,6 +1589,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1291
1589
|
private readonly origins = new Map<string, ReturnType<typeof cleanGithubOrigin>>()
|
|
1292
1590
|
private readonly sessions = new Map<string, VercelSandboxHandle>()
|
|
1293
1591
|
private readonly observeWaitMs: number
|
|
1592
|
+
readonly provisionEstimateMs: number
|
|
1294
1593
|
|
|
1295
1594
|
/** The archive bytes this provider installs: the injected `packageArchive`
|
|
1296
1595
|
* seam when set, else the per-process memoized running distribution
|
|
@@ -1317,9 +1616,17 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1317
1616
|
) {
|
|
1318
1617
|
throw new Error('vercel-sandbox requires an HTTPS BuildStore and scoped AB_TOKEN authority')
|
|
1319
1618
|
}
|
|
1619
|
+
if (options.egressReadCredential !== undefined && options.config.gitPasswordEnv !== undefined) {
|
|
1620
|
+
throw new Error(
|
|
1621
|
+
'vercel-sandbox accepts either a deployment egress read credential or a configured gitPasswordEnv, not both',
|
|
1622
|
+
)
|
|
1623
|
+
}
|
|
1320
1624
|
this.facade = options.facade ?? createVercelSdkFacade(options.env)
|
|
1321
1625
|
this.exec = options.exec ?? spawnExec
|
|
1322
1626
|
this.observeWaitMs = options.observeWaitMs ?? VERCEL_OBSERVE_WAIT_MS
|
|
1627
|
+
// Constructor-body assignment, never a field initializer (see the
|
|
1628
|
+
// `useDefineForClassFields` note on `sandboxPublication`).
|
|
1629
|
+
this.provisionEstimateMs = options.provisionEstimateMs ?? VERCEL_PROVISION_ESTIMATE_MS
|
|
1323
1630
|
this.buildExecution = {
|
|
1324
1631
|
start: (input, auth) => this.start(input, auth),
|
|
1325
1632
|
observe: (identity) =>
|
|
@@ -1331,6 +1638,12 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1331
1638
|
this.withPolicyLock(identity.workspaceRef, () => this.observeExecution(identity)),
|
|
1332
1639
|
}
|
|
1333
1640
|
this.orchestratorSandbox = {
|
|
1641
|
+
lifecycleSupported: true,
|
|
1642
|
+
open: (input) => this.openOperator(input),
|
|
1643
|
+
status: (input) => this.statusOperator(input),
|
|
1644
|
+
close: (input) => this.closeOperator(input),
|
|
1645
|
+
refresh: (handle, input) =>
|
|
1646
|
+
this.withPolicyLock(handle.environmentId, () => this.refreshOperator(handle, input)),
|
|
1334
1647
|
describe: (input) => this.describeOperatorSandbox(input),
|
|
1335
1648
|
ensure: (input) => this.ensureOperatorSandbox(input),
|
|
1336
1649
|
exec: (handle, request) => this.sandboxExec(handle, request),
|
|
@@ -1392,11 +1705,17 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1392
1705
|
archiveRef,
|
|
1393
1706
|
})
|
|
1394
1707
|
if (available)
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1708
|
+
try {
|
|
1709
|
+
await this.archiveTransport(exec).archive({
|
|
1710
|
+
workspacePath: VERCEL_WORKSPACE_PATH,
|
|
1711
|
+
ref: archiveRef,
|
|
1712
|
+
sha: input.sha,
|
|
1713
|
+
})
|
|
1714
|
+
} catch (error) {
|
|
1715
|
+
// Archive refs are best effort: the settlement rewrite retains
|
|
1716
|
+
// the candidate through its `retain` fallback.
|
|
1717
|
+
if (!isArchiveRefusal(error)) throw error
|
|
1718
|
+
}
|
|
1400
1719
|
return available
|
|
1401
1720
|
})
|
|
1402
1721
|
}),
|
|
@@ -1420,7 +1739,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1420
1739
|
throw new Error(
|
|
1421
1740
|
`preservation could not confirm the checkout at ${VERCEL_WORKSPACE_PATH} (exit ${checkout.exitCode})`,
|
|
1422
1741
|
)
|
|
1423
|
-
const capability =
|
|
1742
|
+
const capability = this.archiveTransport(exec)
|
|
1424
1743
|
const remote = await this.remoteBranchHead(input.branch, 'preservation branch')
|
|
1425
1744
|
const base =
|
|
1426
1745
|
remote === null
|
|
@@ -1430,6 +1749,8 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1430
1749
|
branch: input.branch,
|
|
1431
1750
|
destinationRef: `refs/autobuild/reconcile/${input.slug}/preservation`,
|
|
1432
1751
|
})
|
|
1752
|
+
// After the guest push and the host REST fallback both refuse,
|
|
1753
|
+
// `input.retain` keeps the head as a store copy host-side.
|
|
1433
1754
|
return preserveGitCommits({
|
|
1434
1755
|
...input,
|
|
1435
1756
|
base,
|
|
@@ -1468,11 +1789,13 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1468
1789
|
/** Ignored: a sandbox clone never holds archive refs, so restoration here
|
|
1469
1790
|
* always fetches each exact ref from origin, whatever the forge. */
|
|
1470
1791
|
restorationArchives?: 'local' | 'remote'
|
|
1792
|
+
restoreStored?: Parameters<WorkspaceProvider['provision']>[0]['restoreStored']
|
|
1793
|
+
adoptAbandoned?: boolean
|
|
1471
1794
|
}): Promise<WorkspaceProvisionResult> {
|
|
1472
1795
|
const scopedToken = await (this.options.delegateCredential ?? delegateCredential)(
|
|
1473
1796
|
this.options.storeRef,
|
|
1474
1797
|
this.options.storeToken,
|
|
1475
|
-
{ kind: 'build-runner', id: opts.branch
|
|
1798
|
+
{ kind: 'build-runner', id: buildSlugFromBranch(opts.branch) },
|
|
1476
1799
|
)
|
|
1477
1800
|
const rawOrigin = await this.origin()
|
|
1478
1801
|
const origin = cleanGithubOrigin(rawOrigin)
|
|
@@ -1508,12 +1831,31 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1508
1831
|
)
|
|
1509
1832
|
}
|
|
1510
1833
|
|
|
1834
|
+
let checkedOut = base
|
|
1511
1835
|
if (sandbox !== null) {
|
|
1512
1836
|
const marker = await sandbox.runCommand({
|
|
1513
1837
|
cmd: 'test',
|
|
1514
1838
|
args: ['-f', VERCEL_PROVISIONED_MARKER],
|
|
1515
1839
|
})
|
|
1516
1840
|
if (marker.exitCode === 0) {
|
|
1841
|
+
// A completed sandbox from an attempt that recorded nothing keeps the
|
|
1842
|
+
// commit that attempt checked out, however far the target has moved
|
|
1843
|
+
// since. Read it before any stop: a command after stop would resume
|
|
1844
|
+
// the persistent guest.
|
|
1845
|
+
try {
|
|
1846
|
+
checkedOut = await checkedOutBranchHead(sandbox, opts.branch, this.operationSignal())
|
|
1847
|
+
} catch (error) {
|
|
1848
|
+
throw new WorkspaceCleanupRequired(
|
|
1849
|
+
{
|
|
1850
|
+
provider: this.name,
|
|
1851
|
+
ref: name,
|
|
1852
|
+
path: VERCEL_WORKSPACE_PATH,
|
|
1853
|
+
branch: opts.branch,
|
|
1854
|
+
base: { source: 'existing', sha: base },
|
|
1855
|
+
},
|
|
1856
|
+
error,
|
|
1857
|
+
)
|
|
1858
|
+
}
|
|
1517
1859
|
const installed = await readDistributionVersionMarker(sandbox, this.operationSignal())
|
|
1518
1860
|
if (installed === distributionIdentity) {
|
|
1519
1861
|
await sandbox.stop({ signal: this.operationSignal() })
|
|
@@ -1545,7 +1887,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1545
1887
|
}
|
|
1546
1888
|
await sandbox.stop({ signal: this.operationSignal() })
|
|
1547
1889
|
}
|
|
1548
|
-
} else {
|
|
1890
|
+
} else if (!opts.adoptAbandoned) {
|
|
1549
1891
|
// A named VM without the marker is a crashed/legacy provisioning
|
|
1550
1892
|
// attempt. Never expose its potentially unscrubbed checkout to agents.
|
|
1551
1893
|
throw new WorkspaceCleanupRequired(
|
|
@@ -1558,6 +1900,40 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1558
1900
|
},
|
|
1559
1901
|
new Error('incomplete provisioning marker'),
|
|
1560
1902
|
)
|
|
1903
|
+
} else {
|
|
1904
|
+
// The dispatcher recorded this generation's attempt as abandoned at
|
|
1905
|
+
// its own teardown, and its lease is gone. Finish the same sandbox in
|
|
1906
|
+
// place, but only after verification; any doubt still reaps it.
|
|
1907
|
+
try {
|
|
1908
|
+
// Quiesce first: stopping ends any command the dead invocation left
|
|
1909
|
+
// running, and the persistent guest resumes on the next command.
|
|
1910
|
+
await sandbox.stop({ signal: this.operationSignal() })
|
|
1911
|
+
const checkout = await sandbox.runCommand({
|
|
1912
|
+
cmd: 'test',
|
|
1913
|
+
args: ['-e', `${VERCEL_WORKSPACE_PATH}/.git`],
|
|
1914
|
+
})
|
|
1915
|
+
if (checkout.exitCode !== 0)
|
|
1916
|
+
throw new Error('abandoned provisioning left no checkout to finish')
|
|
1917
|
+
checkedOut = await this.completeProvisioning(sandbox, {
|
|
1918
|
+
origin,
|
|
1919
|
+
branch: opts.branch,
|
|
1920
|
+
base,
|
|
1921
|
+
distributionIdentity,
|
|
1922
|
+
scopedToken,
|
|
1923
|
+
verifyClean: true,
|
|
1924
|
+
})
|
|
1925
|
+
} catch (error) {
|
|
1926
|
+
throw new WorkspaceCleanupRequired(
|
|
1927
|
+
{
|
|
1928
|
+
provider: this.name,
|
|
1929
|
+
ref: name,
|
|
1930
|
+
path: VERCEL_WORKSPACE_PATH,
|
|
1931
|
+
branch: opts.branch,
|
|
1932
|
+
base: { source: 'remote', sha: base },
|
|
1933
|
+
},
|
|
1934
|
+
error,
|
|
1935
|
+
)
|
|
1936
|
+
}
|
|
1561
1937
|
}
|
|
1562
1938
|
}
|
|
1563
1939
|
|
|
@@ -1599,56 +1975,13 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1599
1975
|
})
|
|
1600
1976
|
try {
|
|
1601
1977
|
await relocateCheckout(sandbox, origin.directory)
|
|
1602
|
-
await
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
cmd: 'git',
|
|
1609
|
-
args: ['remote', 'set-url', 'origin', origin.url],
|
|
1610
|
-
cwd: VERCEL_WORKSPACE_PATH,
|
|
1611
|
-
})
|
|
1612
|
-
for (const key of [
|
|
1613
|
-
'credential.helper',
|
|
1614
|
-
'http.extraheader',
|
|
1615
|
-
`http.${origin.url}.extraheader`,
|
|
1616
|
-
]) {
|
|
1617
|
-
const result = await sandbox.runCommand({
|
|
1618
|
-
cmd: 'git',
|
|
1619
|
-
args: ['config', '--local', '--unset-all', key],
|
|
1620
|
-
cwd: VERCEL_WORKSPACE_PATH,
|
|
1621
|
-
})
|
|
1622
|
-
if (result.exitCode !== 0 && result.exitCode !== 5)
|
|
1623
|
-
throw new Error(`failed to scrub git config ${key}`)
|
|
1624
|
-
}
|
|
1625
|
-
await provisionBun(sandbox, this.options.config.image)
|
|
1626
|
-
await runSystemProvisioning(sandbox, this.options.config.provisioning ?? [])
|
|
1627
|
-
const archive = await this.archiveBytes()
|
|
1628
|
-
await installDistribution(sandbox, archive, distributionIdentity, this.operationSignal())
|
|
1629
|
-
// Repository dependencies precede branch-owned package plugin loading.
|
|
1630
|
-
// The fixed bootstrap supports the consuming repository's lockfile; its
|
|
1631
|
-
// configured setup command still runs at every runner attachment.
|
|
1632
|
-
await commandOrThrow(sandbox, {
|
|
1633
|
-
cmd: 'sh',
|
|
1634
|
-
args: [
|
|
1635
|
-
'-c',
|
|
1636
|
-
`if [ -f bun.lock ] || [ -f bun.lockb ]; then ${VERCEL_BUN_EXECUTABLE} install --frozen-lockfile; elif [ -f package-lock.json ]; then npm ci; elif [ -f pnpm-lock.yaml ]; then corepack pnpm install --frozen-lockfile; elif [ -f yarn.lock ]; then corepack yarn install --immutable; fi`,
|
|
1637
|
-
],
|
|
1638
|
-
cwd: VERCEL_WORKSPACE_PATH,
|
|
1639
|
-
})
|
|
1640
|
-
await bootstrapRuntimes(
|
|
1641
|
-
sandbox,
|
|
1642
|
-
this.options.config,
|
|
1643
|
-
{ ...this.guestEnvironment(), AB_TOKEN: scopedToken },
|
|
1644
|
-
currentRuntimeReferences(this.options.runtimeReferences),
|
|
1645
|
-
true,
|
|
1646
|
-
)
|
|
1647
|
-
await commandOrThrow(sandbox, {
|
|
1648
|
-
cmd: 'touch',
|
|
1649
|
-
args: [VERCEL_PROVISIONED_MARKER],
|
|
1978
|
+
checkedOut = await this.completeProvisioning(sandbox, {
|
|
1979
|
+
origin,
|
|
1980
|
+
branch: opts.branch,
|
|
1981
|
+
base,
|
|
1982
|
+
distributionIdentity,
|
|
1983
|
+
scopedToken,
|
|
1650
1984
|
})
|
|
1651
|
-
await sandbox.stop({ signal: this.operationSignal() })
|
|
1652
1985
|
} catch (error) {
|
|
1653
1986
|
throw new WorkspaceCleanupRequired(
|
|
1654
1987
|
{
|
|
@@ -1662,7 +1995,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1662
1995
|
)
|
|
1663
1996
|
}
|
|
1664
1997
|
}
|
|
1665
|
-
let provisionHead =
|
|
1998
|
+
let provisionHead = checkedOut
|
|
1666
1999
|
let restorationSkipped: import('../types').RestorationSkip[] = []
|
|
1667
2000
|
if (opts.restoration?.length) {
|
|
1668
2001
|
provisionHead = await this.withTrustedGit(sandbox, name, async (exec) => {
|
|
@@ -1673,6 +2006,14 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1673
2006
|
branch: opts.branch,
|
|
1674
2007
|
heads: opts.restoration!,
|
|
1675
2008
|
replaced: opts.restorationReplaced,
|
|
2009
|
+
// Store copies are read host-side and applied over the trusted
|
|
2010
|
+
// transport; the guest never holds store credentials.
|
|
2011
|
+
...(opts.restoreStored
|
|
2012
|
+
? {
|
|
2013
|
+
restoreStored: (sha: string) =>
|
|
2014
|
+
opts.restoreStored!({ exec, workspacePath: VERCEL_WORKSPACE_PATH, sha }),
|
|
2015
|
+
}
|
|
2016
|
+
: {}),
|
|
1676
2017
|
})
|
|
1677
2018
|
).skipped
|
|
1678
2019
|
const result = await exec(
|
|
@@ -1690,6 +2031,8 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1690
2031
|
ref: name,
|
|
1691
2032
|
path: VERCEL_WORKSPACE_PATH,
|
|
1692
2033
|
branch: opts.branch,
|
|
2034
|
+
// The recorded sha is the guest's verified checkout (or restored branch
|
|
2035
|
+
// head), never the separately read target head (AUT-1252).
|
|
1693
2036
|
base: {
|
|
1694
2037
|
source: opts.restoration?.length || existing !== null ? 'existing' : 'remote',
|
|
1695
2038
|
sha: provisionHead,
|
|
@@ -1698,6 +2041,86 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1698
2041
|
}
|
|
1699
2042
|
}
|
|
1700
2043
|
|
|
2044
|
+
/** The idempotent post-create sequence: branch checkout at the selected
|
|
2045
|
+
* base, credential scrub, toolchain, distribution, dependencies, runtimes,
|
|
2046
|
+
* then the completion marker and a snapshot stop. Shared by a fresh create
|
|
2047
|
+
* and by finishing a teardown-abandoned attempt in place. Returns the
|
|
2048
|
+
* verified checked-out head. */
|
|
2049
|
+
private async completeProvisioning(
|
|
2050
|
+
sandbox: VercelSandboxHandle,
|
|
2051
|
+
input: {
|
|
2052
|
+
origin: ReturnType<typeof cleanGithubOrigin>
|
|
2053
|
+
branch: string
|
|
2054
|
+
base: string
|
|
2055
|
+
distributionIdentity: string
|
|
2056
|
+
scopedToken: string
|
|
2057
|
+
/** Require no tracked modifications before the marker is written. */
|
|
2058
|
+
verifyClean?: boolean
|
|
2059
|
+
},
|
|
2060
|
+
): Promise<string> {
|
|
2061
|
+
const { origin, branch, base, distributionIdentity, scopedToken } = input
|
|
2062
|
+
await commandOrThrow(sandbox, {
|
|
2063
|
+
cmd: 'git',
|
|
2064
|
+
args: ['checkout', '-B', branch, base],
|
|
2065
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
2066
|
+
})
|
|
2067
|
+
const head = await checkedOutBranchHead(sandbox, branch, this.operationSignal())
|
|
2068
|
+
if (head !== base)
|
|
2069
|
+
throw new Error(`checked out ${branch} at ${head}, expected selected base ${base}`)
|
|
2070
|
+
if (input.verifyClean) {
|
|
2071
|
+
// A finished abandoned attempt must not expose tracked edits the dead
|
|
2072
|
+
// invocation may have left behind.
|
|
2073
|
+
const diff = await sandbox.runCommand({
|
|
2074
|
+
cmd: 'git',
|
|
2075
|
+
args: ['diff', '--quiet', 'HEAD', '--'],
|
|
2076
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
2077
|
+
})
|
|
2078
|
+
if (diff.exitCode !== 0) throw new Error('abandoned provisioning left tracked modifications')
|
|
2079
|
+
}
|
|
2080
|
+
await commandOrThrow(sandbox, {
|
|
2081
|
+
cmd: 'git',
|
|
2082
|
+
args: ['remote', 'set-url', 'origin', origin.url],
|
|
2083
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
2084
|
+
})
|
|
2085
|
+
for (const key of ['credential.helper', 'http.extraheader', `http.${origin.url}.extraheader`]) {
|
|
2086
|
+
const result = await sandbox.runCommand({
|
|
2087
|
+
cmd: 'git',
|
|
2088
|
+
args: ['config', '--local', '--unset-all', key],
|
|
2089
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
2090
|
+
})
|
|
2091
|
+
if (result.exitCode !== 0 && result.exitCode !== 5)
|
|
2092
|
+
throw new Error(`failed to scrub git config ${key}`)
|
|
2093
|
+
}
|
|
2094
|
+
await provisionBun(sandbox, this.options.config.image)
|
|
2095
|
+
await runSystemProvisioning(sandbox, this.options.config.provisioning ?? [])
|
|
2096
|
+
const archive = await this.archiveBytes()
|
|
2097
|
+
await installDistribution(sandbox, archive, distributionIdentity, this.operationSignal())
|
|
2098
|
+
// Repository dependencies precede branch-owned package plugin loading.
|
|
2099
|
+
// The fixed bootstrap supports the consuming repository's lockfile; its
|
|
2100
|
+
// configured setup command still runs at every runner attachment.
|
|
2101
|
+
await commandOrThrow(sandbox, {
|
|
2102
|
+
cmd: 'sh',
|
|
2103
|
+
args: [
|
|
2104
|
+
'-c',
|
|
2105
|
+
`if [ -f bun.lock ] || [ -f bun.lockb ]; then ${VERCEL_BUN_EXECUTABLE} install --frozen-lockfile; elif [ -f package-lock.json ]; then npm ci; elif [ -f pnpm-lock.yaml ]; then corepack pnpm install --frozen-lockfile; elif [ -f yarn.lock ]; then corepack yarn install --immutable; fi`,
|
|
2106
|
+
],
|
|
2107
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
2108
|
+
})
|
|
2109
|
+
await bootstrapRuntimes(
|
|
2110
|
+
sandbox,
|
|
2111
|
+
this.options.config,
|
|
2112
|
+
{ ...this.guestEnvironment(), AB_TOKEN: scopedToken },
|
|
2113
|
+
currentRuntimeReferences(this.options.runtimeReferences),
|
|
2114
|
+
true,
|
|
2115
|
+
)
|
|
2116
|
+
await commandOrThrow(sandbox, {
|
|
2117
|
+
cmd: 'touch',
|
|
2118
|
+
args: [VERCEL_PROVISIONED_MARKER],
|
|
2119
|
+
})
|
|
2120
|
+
await sandbox.stop({ signal: this.operationSignal() })
|
|
2121
|
+
return head
|
|
2122
|
+
}
|
|
2123
|
+
|
|
1701
2124
|
async release(handle: WorkspaceHandle): Promise<void> {
|
|
1702
2125
|
if (this.active.has(handle.ref)) throw new Error(`cannot release active sandbox ${handle.ref}`)
|
|
1703
2126
|
await this.reap(handle.ref)
|
|
@@ -1820,6 +2243,27 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1820
2243
|
return result.policy
|
|
1821
2244
|
}
|
|
1822
2245
|
|
|
2246
|
+
/** The upload-pack egress transform's authorization: the deployment egress
|
|
2247
|
+
* read credential when set, else the configured env pair, Basic-encoded.
|
|
2248
|
+
* Every policy write after creation goes through here, so a reset never
|
|
2249
|
+
* drops or widens the transform. */
|
|
2250
|
+
private uploadPackAuthorization(): string | undefined {
|
|
2251
|
+
const egress = this.options.egressReadCredential
|
|
2252
|
+
if (egress !== undefined) {
|
|
2253
|
+
return `Basic ${Buffer.from(`${egress.username}:${egress.password}`).toString('base64')}`
|
|
2254
|
+
}
|
|
2255
|
+
if (this.options.config.gitPasswordEnv === undefined) return undefined
|
|
2256
|
+
const username = requireVercelEnvironmentValue(
|
|
2257
|
+
this.options.env,
|
|
2258
|
+
this.options.config.gitUsernameEnv!,
|
|
2259
|
+
)
|
|
2260
|
+
const password = requireVercelEnvironmentValue(
|
|
2261
|
+
this.options.env,
|
|
2262
|
+
this.options.config.gitPasswordEnv,
|
|
2263
|
+
)
|
|
2264
|
+
return `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`
|
|
2265
|
+
}
|
|
2266
|
+
|
|
1823
2267
|
private async normalNetworkPolicy(ref: string): Promise<{
|
|
1824
2268
|
origin: ReturnType<typeof cleanGithubOrigin>
|
|
1825
2269
|
policy: NetworkPolicy
|
|
@@ -1828,15 +2272,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
1828
2272
|
this.origins.set(ref, origin)
|
|
1829
2273
|
return {
|
|
1830
2274
|
origin,
|
|
1831
|
-
policy: this.billingPolicy(
|
|
1832
|
-
uploadPackPolicy(
|
|
1833
|
-
origin,
|
|
1834
|
-
this.options.config.gitPasswordEnv === undefined
|
|
1835
|
-
? undefined
|
|
1836
|
-
: `Basic ${Buffer.from(`${requireVercelEnvironmentValue(this.options.env, this.options.config.gitUsernameEnv!)}:${requireVercelEnvironmentValue(this.options.env, this.options.config.gitPasswordEnv)}`).toString('base64')}`,
|
|
1837
|
-
),
|
|
1838
|
-
ref,
|
|
1839
|
-
),
|
|
2275
|
+
policy: this.billingPolicy(uploadPackPolicy(origin, this.uploadPackAuthorization()), ref),
|
|
1840
2276
|
}
|
|
1841
2277
|
}
|
|
1842
2278
|
|
|
@@ -2320,12 +2756,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
2320
2756
|
if (Object.keys(accounts).length) {
|
|
2321
2757
|
const origin =
|
|
2322
2758
|
this.origins.get(identity.workspaceRef) ?? cleanGithubOrigin(await this.origin())
|
|
2323
|
-
const base = uploadPackPolicy(
|
|
2324
|
-
origin,
|
|
2325
|
-
this.options.config.gitPasswordEnv === undefined
|
|
2326
|
-
? undefined
|
|
2327
|
-
: `Basic ${Buffer.from(`${requireVercelEnvironmentValue(this.options.env, this.options.config.gitUsernameEnv!)}:${requireVercelEnvironmentValue(this.options.env, this.options.config.gitPasswordEnv)}`).toString('base64')}`,
|
|
2328
|
-
)
|
|
2759
|
+
const base = uploadPackPolicy(origin, this.uploadPackAuthorization())
|
|
2329
2760
|
const refreshed = accountPolicy(
|
|
2330
2761
|
base,
|
|
2331
2762
|
accounts,
|
|
@@ -2434,23 +2865,24 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
2434
2865
|
}
|
|
2435
2866
|
}
|
|
2436
2867
|
|
|
2437
|
-
/** Provision-or-resume
|
|
2438
|
-
*
|
|
2439
|
-
*
|
|
2440
|
-
* the
|
|
2441
|
-
*
|
|
2442
|
-
*
|
|
2443
|
-
*
|
|
2868
|
+
/** Provision-or-resume, blocking: the provider's own primitive for tests
|
|
2869
|
+
* and callers without a journal. A persistent sandbox auto-resumes on the
|
|
2870
|
+
* first SDK call that needs a running session, so the reuse path applies
|
|
2871
|
+
* the idle timeout and network policy, brings Bun to the pin and re-checks
|
|
2872
|
+
* the distribution marker as the build paths do. A fresh provision runs the
|
|
2873
|
+
* host phase, then waits for the detached tail and probes its outcome; a
|
|
2874
|
+
* failure reaps the environment, because `ensure` has no journal to
|
|
2875
|
+
* publish its evidence to and its caller holds the error. */
|
|
2444
2876
|
private async ensureOperatorSandbox(input: {
|
|
2445
2877
|
repo: string
|
|
2446
2878
|
operator: string
|
|
2447
2879
|
baseBranch: string
|
|
2448
2880
|
}): Promise<SandboxEnvironmentIdentity> {
|
|
2449
|
-
const origin =
|
|
2450
|
-
const name = sandboxEnvironmentName(origin.url, input.operator)
|
|
2881
|
+
const { origin, name } = await this.operatorName(input.operator)
|
|
2451
2882
|
const distributionIdentity = await this.identityStamp()
|
|
2452
2883
|
let sandbox = await this.facade.get(name, this.operationSignal())
|
|
2453
2884
|
if (sandbox !== null) {
|
|
2885
|
+
await this.applyOperatorSession(sandbox, name)
|
|
2454
2886
|
const marker = await sandbox.runCommand({
|
|
2455
2887
|
cmd: 'test',
|
|
2456
2888
|
args: ['-f', VERCEL_PROVISIONED_MARKER],
|
|
@@ -2518,150 +2950,1015 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
2518
2950
|
}
|
|
2519
2951
|
}
|
|
2520
2952
|
}
|
|
2521
|
-
const
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
: `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`
|
|
2537
|
-
sandbox = await this.facade.create({
|
|
2538
|
-
name,
|
|
2539
|
-
source: {
|
|
2540
|
-
type: 'git',
|
|
2541
|
-
url: origin.url,
|
|
2542
|
-
revision: head,
|
|
2543
|
-
...(username !== undefined && password !== undefined ? { username, password } : {}),
|
|
2544
|
-
},
|
|
2545
|
-
image: this.options.config.image,
|
|
2546
|
-
resources: { vcpus: this.options.config.vcpus },
|
|
2547
|
-
timeout: this.options.config.timeoutSeconds * 1000,
|
|
2548
|
-
persistent: true,
|
|
2549
|
-
...(this.options.config.region !== undefined ? { region: this.options.config.region } : {}),
|
|
2550
|
-
...(this.options.config.failoverRegions.length > 0
|
|
2551
|
-
? { failoverRegions: this.options.config.failoverRegions }
|
|
2552
|
-
: {}),
|
|
2553
|
-
...(this.options.config.snapshotExpirationSeconds === undefined
|
|
2554
|
-
? {}
|
|
2555
|
-
: { snapshotExpiration: this.options.config.snapshotExpirationSeconds * 1000 }),
|
|
2556
|
-
networkPolicy: uploadPackPolicy(origin, readAuth),
|
|
2557
|
-
keepLastSnapshots: { count: VERCEL_KEEP_LAST_SNAPSHOTS, deleteEvicted: true },
|
|
2558
|
-
signal: this.operationSignal(),
|
|
2559
|
-
})
|
|
2560
|
-
try {
|
|
2561
|
-
await relocateCheckout(sandbox, origin.directory)
|
|
2562
|
-
await commandOrThrow(sandbox, {
|
|
2563
|
-
cmd: 'git',
|
|
2564
|
-
args: ['remote', 'set-url', 'origin', origin.url],
|
|
2565
|
-
cwd: VERCEL_WORKSPACE_PATH,
|
|
2566
|
-
})
|
|
2567
|
-
for (const key of [
|
|
2568
|
-
'credential.helper',
|
|
2569
|
-
'http.extraheader',
|
|
2570
|
-
`http.${origin.url}.extraheader`,
|
|
2571
|
-
]) {
|
|
2572
|
-
const result = await sandbox.runCommand({
|
|
2573
|
-
cmd: 'git',
|
|
2574
|
-
args: ['config', '--local', '--unset-all', key],
|
|
2575
|
-
cwd: VERCEL_WORKSPACE_PATH,
|
|
2576
|
-
})
|
|
2577
|
-
if (result.exitCode !== 0 && result.exitCode !== 5)
|
|
2578
|
-
throw new Error(`failed to scrub git config ${key}`)
|
|
2579
|
-
}
|
|
2580
|
-
await provisionBun(sandbox, this.options.config.image)
|
|
2581
|
-
await runSystemProvisioning(sandbox, this.options.config.provisioning ?? [])
|
|
2582
|
-
const archive = await this.archiveBytes()
|
|
2583
|
-
await installDistribution(sandbox, archive, distributionIdentity, this.operationSignal())
|
|
2584
|
-
// Repository dependencies precede the setup command; the fixed
|
|
2585
|
-
// bootstrap is the same one build provisioning runs.
|
|
2586
|
-
await commandOrThrow(sandbox, {
|
|
2587
|
-
cmd: 'sh',
|
|
2588
|
-
args: [
|
|
2589
|
-
'-c',
|
|
2590
|
-
`if [ -f bun.lock ] || [ -f bun.lockb ]; then ${VERCEL_BUN_EXECUTABLE} install --frozen-lockfile; elif [ -f package-lock.json ]; then npm ci; elif [ -f pnpm-lock.yaml ]; then corepack pnpm install --frozen-lockfile; elif [ -f yarn.lock ]; then corepack yarn install --immutable; fi`,
|
|
2591
|
-
],
|
|
2592
|
-
cwd: VERCEL_WORKSPACE_PATH,
|
|
2593
|
-
})
|
|
2594
|
-
// Runtime provisioning precedes the setup command, exactly as the build
|
|
2595
|
-
// chain orders it. The guest env is the sandbox-forwarded set only: a
|
|
2596
|
-
// runtime provisioning command that needs a build-workspace variable
|
|
2597
|
-
// must have that name added to [orchestrator].sandbox.environmentVariables.
|
|
2598
|
-
const runtimeReferences = currentRuntimeReferences(this.options.runtimeReferences)
|
|
2599
|
-
if (runtimeReferences.length > 0) {
|
|
2600
|
-
await bootstrapRuntimes(
|
|
2601
|
-
sandbox,
|
|
2602
|
-
this.options.config,
|
|
2603
|
-
this.sandboxEnv(),
|
|
2604
|
-
runtimeReferences,
|
|
2605
|
-
true,
|
|
2606
|
-
this.operationSignal(),
|
|
2607
|
-
)
|
|
2608
|
-
}
|
|
2609
|
-
const setupCommand = this.options.setupCommand
|
|
2610
|
-
if (setupCommand !== undefined && setupCommand.trim() !== '') {
|
|
2611
|
-
await readableCommand(sandbox, {
|
|
2612
|
-
cmd: 'sh',
|
|
2613
|
-
args: ['-c', `${this.sandboxPathPrefix()}${setupCommand}`],
|
|
2614
|
-
cwd: VERCEL_WORKSPACE_PATH,
|
|
2615
|
-
env: this.sandboxEnv(),
|
|
2616
|
-
})
|
|
2953
|
+
const failEnsure = async (
|
|
2954
|
+
failure: { stage: SandboxProvisionStage; message: string },
|
|
2955
|
+
created: boolean,
|
|
2956
|
+
cause?: unknown,
|
|
2957
|
+
): Promise<never> => {
|
|
2958
|
+
if (created) {
|
|
2959
|
+
// Nothing unrecorded or half-built survives a blocking provision.
|
|
2960
|
+
try {
|
|
2961
|
+
await this.reap(name)
|
|
2962
|
+
} catch (deleteError) {
|
|
2963
|
+
throw new AggregateError(
|
|
2964
|
+
[cause ?? new Error(failure.message), deleteError],
|
|
2965
|
+
`operator sandbox ${name} setup failed and its incomplete environment could not be confirmed deleted`,
|
|
2966
|
+
)
|
|
2967
|
+
}
|
|
2617
2968
|
}
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2969
|
+
throw new SandboxOperationError(
|
|
2970
|
+
failure.stage === 'environment' ? 'environment' : 'provision',
|
|
2971
|
+
failure.message,
|
|
2972
|
+
cause === undefined ? undefined : { cause },
|
|
2973
|
+
)
|
|
2974
|
+
}
|
|
2975
|
+
let launched: Awaited<ReturnType<typeof this.runOperatorHostPhase>>
|
|
2976
|
+
try {
|
|
2977
|
+
launched = await this.runOperatorHostPhase({ origin, name, baseBranch: input.baseBranch })
|
|
2622
2978
|
} catch (error) {
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
this.sessions.set(name, sandbox)
|
|
2627
|
-
await this.reap(name)
|
|
2628
|
-
} catch (deleteError) {
|
|
2629
|
-
throw new AggregateError(
|
|
2630
|
-
[error, deleteError],
|
|
2631
|
-
`operator sandbox ${name} setup failed and its incomplete environment could not be confirmed deleted`,
|
|
2632
|
-
)
|
|
2633
|
-
}
|
|
2634
|
-
throw error instanceof SandboxOperationError
|
|
2635
|
-
? error
|
|
2636
|
-
: new SandboxOperationError(
|
|
2637
|
-
'provision',
|
|
2638
|
-
error instanceof Error ? error.message : String(error),
|
|
2639
|
-
{ cause: error },
|
|
2640
|
-
)
|
|
2979
|
+
if (error instanceof OperatorHostFailure)
|
|
2980
|
+
return failEnsure(error.failure, error.created, error)
|
|
2981
|
+
throw error
|
|
2641
2982
|
}
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2983
|
+
if (launched.outcome === 'concurrent') {
|
|
2984
|
+
throw new SandboxOperationError(
|
|
2985
|
+
'provision',
|
|
2986
|
+
`operator sandbox ${name} is being provisioned by another process`,
|
|
2987
|
+
)
|
|
2988
|
+
}
|
|
2989
|
+
const deadline = Date.now() + this.idleMs()
|
|
2990
|
+
await waitForCommandExit(launched.command, () => Date.now() > deadline)
|
|
2991
|
+
const probe = await this.probeOperator(launched.sandbox)
|
|
2992
|
+
if (probe.kind !== 'ready') {
|
|
2993
|
+
return failEnsure(
|
|
2994
|
+
probe.kind === 'failed' ? this.probeFailure(probe) : this.interruptedFailure(),
|
|
2995
|
+
true,
|
|
2996
|
+
)
|
|
2997
|
+
}
|
|
2998
|
+
const sessionId = launched.sandbox.currentSession?.().sessionId
|
|
2645
2999
|
return {
|
|
2646
3000
|
provider: this.name,
|
|
2647
3001
|
environmentId: name,
|
|
2648
3002
|
...(sessionId !== undefined ? { sessionId } : {}),
|
|
2649
3003
|
workspacePath: VERCEL_WORKSPACE_PATH,
|
|
2650
|
-
baseSha:
|
|
3004
|
+
baseSha: launched.baseSha,
|
|
2651
3005
|
}
|
|
2652
3006
|
}
|
|
2653
3007
|
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
3008
|
+
// ── Operator sandbox lifecycle (#1246) ─────────────────────────────────
|
|
3009
|
+
//
|
|
3010
|
+
// `open` returns after a `get`, at most one probe and one `update`; the
|
|
3011
|
+
// host phase runs as this process's background attempt (which a hosted
|
|
3012
|
+
// caller keeps alive with its background seam) and launches the detached
|
|
3013
|
+
// tail. `status` reads the session status first and never runs a guest
|
|
3014
|
+
// command on a session that is not running: a guest command would resume
|
|
3015
|
+
// it. Failure evidence in the guest is reaped only by `open` (after the
|
|
3016
|
+
// service recorded the failure), `release`, or a blocking `ensure`.
|
|
3017
|
+
|
|
3018
|
+
private readonly operatorInflight = new Map<
|
|
3019
|
+
string,
|
|
3020
|
+
{
|
|
3021
|
+
kind: 'provision' | 'resume'
|
|
3022
|
+
promise: Promise<SandboxProviderStatus>
|
|
3023
|
+
abort: AbortController
|
|
3024
|
+
}
|
|
3025
|
+
>()
|
|
3026
|
+
private readonly operatorFailures = new Map<
|
|
3027
|
+
string,
|
|
3028
|
+
{ stage: SandboxProvisionStage; message: string }
|
|
3029
|
+
>()
|
|
3030
|
+
|
|
3031
|
+
/** The operator sandbox's provider idle timeout, in milliseconds. */
|
|
3032
|
+
private idleMs(): number {
|
|
3033
|
+
return (this.options.sandboxIdleMinutes ?? 30) * 60_000
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
private async operatorName(
|
|
3037
|
+
operator: string,
|
|
3038
|
+
): Promise<{ origin: ReturnType<typeof cleanGithubOrigin>; name: string }> {
|
|
3039
|
+
const origin = cleanGithubOrigin(await this.origin())
|
|
3040
|
+
return { origin, name: sandboxEnvironmentName(origin.url, operator) }
|
|
3041
|
+
}
|
|
3042
|
+
|
|
3043
|
+
/** Every credential value a provisioning message could carry, removed:
|
|
3044
|
+
* forwarded guest values, the upload-pack authorization and git password,
|
|
3045
|
+
* then the forbidden host names' values. */
|
|
3046
|
+
private redactOperatorMessage(message: string): string {
|
|
3047
|
+
let env: Record<string, string> = {}
|
|
3048
|
+
try {
|
|
3049
|
+
env = this.sandboxEnv()
|
|
3050
|
+
} catch {
|
|
3051
|
+
// A missing forwarded value has no value to redact.
|
|
3052
|
+
}
|
|
3053
|
+
let redacted = redactRuntimeError(message, env)
|
|
3054
|
+
const secrets: string[] = []
|
|
3055
|
+
try {
|
|
3056
|
+
const authorization = this.uploadPackAuthorization()
|
|
3057
|
+
if (authorization !== undefined) {
|
|
3058
|
+
secrets.push(authorization, authorization.slice('Basic '.length))
|
|
3059
|
+
}
|
|
3060
|
+
} catch {
|
|
3061
|
+
// An unresolvable credential pair cannot appear in the message.
|
|
3062
|
+
}
|
|
3063
|
+
if (this.options.egressReadCredential !== undefined) {
|
|
3064
|
+
secrets.push(this.options.egressReadCredential.password)
|
|
3065
|
+
}
|
|
3066
|
+
const passwordEnv = this.options.config.gitPasswordEnv
|
|
3067
|
+
if (passwordEnv !== undefined) secrets.push(this.options.env[passwordEnv] ?? '')
|
|
3068
|
+
for (const secret of secrets.sort((a, b) => b.length - a.length)) {
|
|
3069
|
+
if (secret !== '') redacted = redacted.split(secret).join('[REDACTED]')
|
|
3070
|
+
}
|
|
3071
|
+
return redactSandboxMessage(redacted)
|
|
3072
|
+
}
|
|
3073
|
+
|
|
3074
|
+
/** Apply the idle timeout and the current network policy to an operator
|
|
3075
|
+
* sandbox: a resumed session then runs with the idle timeout, and the
|
|
3076
|
+
* upload-pack transform carries the deployment's current read credential. */
|
|
3077
|
+
private async applyOperatorSession(sandbox: VercelSandboxHandle, name: string): Promise<void> {
|
|
3078
|
+
const { policy } = await this.normalNetworkPolicy(name)
|
|
3079
|
+
await sandbox.update(
|
|
3080
|
+
{ timeout: this.idleMs(), networkPolicy: policy },
|
|
3081
|
+
{ signal: this.operationSignal() },
|
|
3082
|
+
)
|
|
3083
|
+
}
|
|
3084
|
+
|
|
3085
|
+
/** Extend the running session so it outlives `max(idleMs, boundMs)` from
|
|
3086
|
+
* now. The SDK's `extendTimeout` adds to the lifetime, so only the deficit
|
|
3087
|
+
* is requested. A failed extension is swallowed: it can only let the
|
|
3088
|
+
* sandbox stop sooner, which is cost-safe, and the next call extends. */
|
|
3089
|
+
private async extendOperatorTimer(sandbox: VercelSandboxHandle, boundMs: number): Promise<void> {
|
|
3090
|
+
const expiresAt = sandbox.sessionExpiresAt
|
|
3091
|
+
if (expiresAt === undefined) return
|
|
3092
|
+
const deficit = Date.now() + Math.max(this.idleMs(), boundMs) - expiresAt
|
|
3093
|
+
if (deficit <= 0) return
|
|
3094
|
+
try {
|
|
3095
|
+
await sandbox.extendTimeout(deficit, { signal: this.operationSignal() })
|
|
3096
|
+
} catch {
|
|
3097
|
+
// Cost-safe: see above.
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
private async probeOperator(sandbox: VercelSandboxHandle): Promise<VercelOperatorProbe> {
|
|
3102
|
+
const stdout = await readableCommand(sandbox, {
|
|
3103
|
+
cmd: 'sh',
|
|
3104
|
+
args: [
|
|
3105
|
+
'-c',
|
|
3106
|
+
VERCEL_OPERATOR_PROBE_SCRIPT,
|
|
3107
|
+
'probe',
|
|
3108
|
+
VERCEL_OPERATOR_PROVISION_DIR,
|
|
3109
|
+
VERCEL_PROVISIONED_MARKER,
|
|
3110
|
+
VERCEL_WORKSPACE_PATH,
|
|
3111
|
+
VERCEL_BUN_EXECUTABLE,
|
|
3112
|
+
VERCEL_DISTRIBUTION_VERSION_MARKER,
|
|
3113
|
+
],
|
|
3114
|
+
signal: this.operationSignal(),
|
|
3115
|
+
})
|
|
3116
|
+
return parseVercelOperatorProbe(stdout)
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3119
|
+
private async heartbeat(sandbox: VercelSandboxHandle, step: OperatorHostStep): Promise<void> {
|
|
3120
|
+
await commandOrThrow(sandbox, {
|
|
3121
|
+
cmd: 'sh',
|
|
3122
|
+
args: [
|
|
3123
|
+
'-c',
|
|
3124
|
+
'printf "%s %s\\n" "$1" "$(date +%s)" > "$2"',
|
|
3125
|
+
'heartbeat',
|
|
3126
|
+
step,
|
|
3127
|
+
`${VERCEL_OPERATOR_PROVISION_DIR}/host`,
|
|
3128
|
+
],
|
|
3129
|
+
signal: this.operationSignal(),
|
|
3130
|
+
})
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
/** Best-effort: record a failure in the guest `failed` file, the durable
|
|
3134
|
+
* evidence any later process reads. The message is already redacted. */
|
|
3135
|
+
private async writeOperatorFailure(
|
|
3136
|
+
sandbox: VercelSandboxHandle,
|
|
3137
|
+
failure: { stage: SandboxProvisionStage; message: string },
|
|
3138
|
+
): Promise<void> {
|
|
3139
|
+
try {
|
|
3140
|
+
await sandbox.runCommand({
|
|
3141
|
+
cmd: 'sh',
|
|
3142
|
+
args: [
|
|
3143
|
+
'-c',
|
|
3144
|
+
'mkdir -p "$1" && printf "%s\\n%s\\n" "$2" "$3" > "$1/failed"',
|
|
3145
|
+
'failed',
|
|
3146
|
+
VERCEL_OPERATOR_PROVISION_DIR,
|
|
3147
|
+
failure.stage,
|
|
3148
|
+
failure.message,
|
|
3149
|
+
],
|
|
3150
|
+
signal: this.operationSignal(),
|
|
3151
|
+
})
|
|
3152
|
+
} catch {
|
|
3153
|
+
// The in-process record and the journal remain.
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
|
|
3157
|
+
/** The failure a `failed` probe records: a host or resume record carries
|
|
3158
|
+
* its stage and message verbatim; a tail record names its step, mapped onto
|
|
3159
|
+
* the existing stages with the redacted log tail as detail. */
|
|
3160
|
+
private probeFailure(probe: Extract<VercelOperatorProbe, { kind: 'failed' }>): {
|
|
3161
|
+
stage: SandboxProvisionStage
|
|
3162
|
+
message: string
|
|
3163
|
+
} {
|
|
3164
|
+
const [first = '', ...rest] = probe.record.split('\n')
|
|
3165
|
+
const step = first.trim()
|
|
3166
|
+
const recorded = rest.join('\n').trim()
|
|
3167
|
+
if (recorded !== '') {
|
|
3168
|
+
return {
|
|
3169
|
+
stage: (PROVISION_STAGES as readonly string[]).includes(step)
|
|
3170
|
+
? (step as SandboxProvisionStage)
|
|
3171
|
+
: 'provision',
|
|
3172
|
+
message: this.redactOperatorMessage(recorded),
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
const detail = this.redactOperatorMessage(probe.log.trim()) || '(no output)'
|
|
3176
|
+
if (step === 'setup') {
|
|
3177
|
+
return { stage: 'setup', message: `operator sandbox setup failed: ${detail}` }
|
|
3178
|
+
}
|
|
3179
|
+
if (step === 'dependencies') {
|
|
3180
|
+
return { stage: 'provision', message: `dependency install failed: ${detail}` }
|
|
3181
|
+
}
|
|
3182
|
+
const runtime = /^runtime-(.+)-(install|preflight)$/.exec(step)
|
|
3183
|
+
if (runtime !== null) {
|
|
3184
|
+
const group = currentRuntimeReferences(this.options.runtimeReferences).find(
|
|
3185
|
+
(candidate) => tailRuntimeName(candidate.runtime) === runtime[1],
|
|
3186
|
+
)
|
|
3187
|
+
return {
|
|
3188
|
+
stage: 'provision',
|
|
3189
|
+
message:
|
|
3190
|
+
group === undefined
|
|
3191
|
+
? `runtime ${runtime[1]} ${runtime[2]} failed: ${detail}`
|
|
3192
|
+
: `runtime ${displayName(group.runtime)} ${runtime[2]} failed (selected by ${group.references.join(', ')}); fix workspace.config.runtimeProvisioning.${group.runtime}.${runtime[2]}: ${detail}`,
|
|
3193
|
+
}
|
|
3194
|
+
}
|
|
3195
|
+
return {
|
|
3196
|
+
stage: 'provision',
|
|
3197
|
+
message: `operator sandbox provisioning step ${step || '(unknown)'} failed: ${detail}`,
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
|
|
3201
|
+
/** An interrupted provision: the host heartbeat's step names the stage. */
|
|
3202
|
+
private interruptedFailure(step?: string): {
|
|
3203
|
+
stage: SandboxProvisionStage
|
|
3204
|
+
message: string
|
|
3205
|
+
} {
|
|
3206
|
+
if (step === 'checkout' || step === 'provision') {
|
|
3207
|
+
return {
|
|
3208
|
+
stage: step,
|
|
3209
|
+
message: `provisioning was interrupted during ${step}; call sandbox.open to retry`,
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
return { stage: 'provision', message: SANDBOX_INTERRUPTED_MESSAGE }
|
|
3213
|
+
}
|
|
3214
|
+
|
|
3215
|
+
private readyStatus(
|
|
3216
|
+
name: string,
|
|
3217
|
+
sandbox: VercelSandboxHandle,
|
|
3218
|
+
probe: Extract<VercelOperatorProbe, { kind: 'ready' }>,
|
|
3219
|
+
kind?: 'provision' | 'resume',
|
|
3220
|
+
): SandboxProviderStatus {
|
|
3221
|
+
const sessionId = sandbox.currentSession?.().sessionId
|
|
3222
|
+
return {
|
|
3223
|
+
state: 'ready',
|
|
3224
|
+
handle: {
|
|
3225
|
+
provider: this.name,
|
|
3226
|
+
environmentId: name,
|
|
3227
|
+
...(sessionId !== undefined ? { sessionId } : {}),
|
|
3228
|
+
workspacePath: VERCEL_WORKSPACE_PATH,
|
|
3229
|
+
...(probe.marker.baseSha !== undefined ? { baseSha: probe.marker.baseSha } : {}),
|
|
3230
|
+
},
|
|
3231
|
+
...(probe.headSha !== undefined ? { headSha: probe.headSha } : {}),
|
|
3232
|
+
...(kind !== undefined ? { kind } : {}),
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
|
|
3236
|
+
/** Classify a running session's probe. `inFlight` marks a provision some
|
|
3237
|
+
* process is still driving (a running tail, a fresh host heartbeat, or a
|
|
3238
|
+
* tail launched within its grace). */
|
|
3239
|
+
private classifyOperatorProbe(
|
|
3240
|
+
name: string,
|
|
3241
|
+
sandbox: VercelSandboxHandle,
|
|
3242
|
+
probe: VercelOperatorProbe,
|
|
3243
|
+
): { status: SandboxProviderStatus; inFlight: boolean } {
|
|
3244
|
+
switch (probe.kind) {
|
|
3245
|
+
case 'failed':
|
|
3246
|
+
return { status: { state: 'failed', failure: this.probeFailure(probe) }, inFlight: false }
|
|
3247
|
+
case 'ready':
|
|
3248
|
+
return { status: this.readyStatus(name, sandbox, probe), inFlight: false }
|
|
3249
|
+
case 'resuming':
|
|
3250
|
+
// Some process is refreshing the toolchain under the old marker.
|
|
3251
|
+
if (probe.ageSeconds < VERCEL_OPERATOR_HOST_STALE_SECONDS) {
|
|
3252
|
+
return { status: { state: 'resuming' }, inFlight: true }
|
|
3253
|
+
}
|
|
3254
|
+
return {
|
|
3255
|
+
status: {
|
|
3256
|
+
state: 'failed',
|
|
3257
|
+
failure: {
|
|
3258
|
+
stage: 'resume',
|
|
3259
|
+
message: 'resuming was interrupted before it finished; call sandbox.open to retry',
|
|
3260
|
+
},
|
|
3261
|
+
},
|
|
3262
|
+
inFlight: false,
|
|
3263
|
+
}
|
|
3264
|
+
case 'running':
|
|
3265
|
+
return { status: { state: 'provisioning' }, inFlight: true }
|
|
3266
|
+
case 'host': {
|
|
3267
|
+
const grace =
|
|
3268
|
+
probe.step === 'launched'
|
|
3269
|
+
? VERCEL_OPERATOR_LAUNCH_GRACE_SECONDS
|
|
3270
|
+
: VERCEL_OPERATOR_HOST_STALE_SECONDS
|
|
3271
|
+
if (probe.ageSeconds < grace) return { status: { state: 'provisioning' }, inFlight: true }
|
|
3272
|
+
return {
|
|
3273
|
+
status: { state: 'failed', failure: this.interruptedFailure(probe.step) },
|
|
3274
|
+
inFlight: false,
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
case 'none':
|
|
3278
|
+
return {
|
|
3279
|
+
status: { state: 'failed', failure: this.interruptedFailure() },
|
|
3280
|
+
inFlight: false,
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
|
|
3285
|
+
/** The detached tail's files: one stage script per step, then the runner.
|
|
3286
|
+
* Every stage command is byte-identical to the host-driven chain it
|
|
3287
|
+
* replaces; the files carry no environment values (forwarded values ride
|
|
3288
|
+
* only in the launch's env record). */
|
|
3289
|
+
private operatorTailFiles(baseSha: string): { path: string; content: Uint8Array }[] {
|
|
3290
|
+
const stages: { name: string; script: string }[] = [
|
|
3291
|
+
{ name: 'dependencies', script: DEPENDENCY_INSTALL_COMMAND },
|
|
3292
|
+
]
|
|
3293
|
+
const references = currentRuntimeReferences(this.options.runtimeReferences)
|
|
3294
|
+
for (const group of [...references].sort((left, right) =>
|
|
3295
|
+
left.runtime < right.runtime ? -1 : left.runtime > right.runtime ? 1 : 0,
|
|
3296
|
+
)) {
|
|
3297
|
+
const provisioning = this.options.config.runtimeProvisioning?.[group.runtime]
|
|
3298
|
+
if (provisioning === undefined) {
|
|
3299
|
+
throw new Error(
|
|
3300
|
+
`runtime ${displayName(group.runtime)} selected by ${group.references.join(', ')} has no provisioning; add [workspace.config.runtimeProvisioning.${tomlKey(group.runtime)}] with install and preflight commands`,
|
|
3301
|
+
)
|
|
3302
|
+
}
|
|
3303
|
+
for (const step of ['install', 'preflight'] as const) {
|
|
3304
|
+
stages.push({
|
|
3305
|
+
name: `runtime-${tailRuntimeName(group.runtime)}-${step}`,
|
|
3306
|
+
script: provisioning[step],
|
|
3307
|
+
})
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
const setupCommand = this.options.setupCommand
|
|
3311
|
+
if (setupCommand !== undefined && setupCommand.trim() !== '') {
|
|
3312
|
+
stages.push({ name: 'setup', script: `${this.sandboxPathPrefix()}${setupCommand}` })
|
|
3313
|
+
}
|
|
3314
|
+
stages.push({
|
|
3315
|
+
name: 'marker',
|
|
3316
|
+
script: `printf '%s' ${shellQuote(JSON.stringify({ baseSha }))} > ${shellQuote(VERCEL_PROVISIONED_MARKER)}`,
|
|
3317
|
+
})
|
|
3318
|
+
const dir = VERCEL_OPERATOR_PROVISION_DIR
|
|
3319
|
+
const files = stages.map((stage, index) => ({
|
|
3320
|
+
name: stage.name,
|
|
3321
|
+
file: `stage-${String(index + 1).padStart(2, '0')}-${stage.name}.sh`,
|
|
3322
|
+
script: stage.script,
|
|
3323
|
+
}))
|
|
3324
|
+
const runner = [
|
|
3325
|
+
`d=${shellQuote(dir)}`,
|
|
3326
|
+
'echo $$ > "$d/pid"',
|
|
3327
|
+
'run() {',
|
|
3328
|
+
' printf "%s\\n" "$1" > "$d/stage"',
|
|
3329
|
+
' printf "== %s\\n" "$1" >> "$d/log"',
|
|
3330
|
+
' if ! sh "$d/$2" >> "$d/log" 2>&1; then',
|
|
3331
|
+
' printf "%s\\n" "$1" > "$d/failed"',
|
|
3332
|
+
' exit 1',
|
|
3333
|
+
' fi',
|
|
3334
|
+
'}',
|
|
3335
|
+
...files.map((stage) => `run ${shellQuote(stage.name)} ${shellQuote(stage.file)}`),
|
|
3336
|
+
'',
|
|
3337
|
+
].join('\n')
|
|
3338
|
+
return [
|
|
3339
|
+
...files.map((stage) => ({
|
|
3340
|
+
path: `${dir}/${stage.file}`,
|
|
3341
|
+
content: new Uint8Array(Buffer.from(`${stage.script}\n`)),
|
|
3342
|
+
})),
|
|
3343
|
+
{ path: `${dir}/tail.sh`, content: new Uint8Array(Buffer.from(runner)) },
|
|
3344
|
+
]
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3347
|
+
/** The host phase of one fresh provision: create with the idle timeout,
|
|
3348
|
+
* check out and scrub, provision Bun, system steps and the distribution,
|
|
3349
|
+
* write the tail files and launch the detached tail. Each step rewrites
|
|
3350
|
+
* the guest heartbeat first. A failure after create writes the guest
|
|
3351
|
+
* `failed` record and leaves the sandbox for its idle timer — the evidence
|
|
3352
|
+
* must outlive this process until the journal holds it. */
|
|
3353
|
+
private async runOperatorHostPhase(input: {
|
|
3354
|
+
origin: ReturnType<typeof cleanGithubOrigin>
|
|
3355
|
+
name: string
|
|
3356
|
+
baseBranch: string
|
|
3357
|
+
signal?: AbortSignal
|
|
3358
|
+
}): Promise<
|
|
3359
|
+
| { outcome: 'launched'; sandbox: VercelSandboxHandle; command: VercelCommand; baseSha: string }
|
|
3360
|
+
| { outcome: 'concurrent' }
|
|
3361
|
+
> {
|
|
3362
|
+
const { origin, name, signal } = input
|
|
3363
|
+
const checkpoint = (): void => {
|
|
3364
|
+
if (signal?.aborted) throw new OperatorAttemptCancelled(sandbox !== undefined)
|
|
3365
|
+
}
|
|
3366
|
+
let step: OperatorHostStep = 'checkout'
|
|
3367
|
+
let sandbox: VercelSandboxHandle | undefined
|
|
3368
|
+
try {
|
|
3369
|
+
const distributionIdentity = await this.identityStamp()
|
|
3370
|
+
const head = await this.remoteBranchHead(input.baseBranch, `remote base ${input.baseBranch}`)
|
|
3371
|
+
if (head === null) throw new Error(`remote base ${input.baseBranch} does not exist`)
|
|
3372
|
+
// The deployment-fallback operator sandbox (egress read credential) is
|
|
3373
|
+
// created without a git source and clones in the guest: its credential
|
|
3374
|
+
// reaches only the upload-pack egress transform, never the Vercel
|
|
3375
|
+
// source API. Every other provision keeps the configured source clone.
|
|
3376
|
+
const guestClone = this.options.egressReadCredential !== undefined
|
|
3377
|
+
const username =
|
|
3378
|
+
guestClone || this.options.config.gitUsernameEnv === undefined
|
|
3379
|
+
? undefined
|
|
3380
|
+
: requireVercelEnvironmentValue(this.options.env, this.options.config.gitUsernameEnv)
|
|
3381
|
+
const password =
|
|
3382
|
+
guestClone || this.options.config.gitPasswordEnv === undefined
|
|
3383
|
+
? undefined
|
|
3384
|
+
: requireVercelEnvironmentValue(this.options.env, this.options.config.gitPasswordEnv)
|
|
3385
|
+
const readAuth = guestClone
|
|
3386
|
+
? this.uploadPackAuthorization()
|
|
3387
|
+
: password === undefined
|
|
3388
|
+
? undefined
|
|
3389
|
+
: `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`
|
|
3390
|
+
checkpoint()
|
|
3391
|
+
try {
|
|
3392
|
+
sandbox = await this.facade.create({
|
|
3393
|
+
name,
|
|
3394
|
+
...(guestClone
|
|
3395
|
+
? {}
|
|
3396
|
+
: {
|
|
3397
|
+
source: {
|
|
3398
|
+
type: 'git' as const,
|
|
3399
|
+
url: origin.url,
|
|
3400
|
+
revision: head,
|
|
3401
|
+
...(username !== undefined && password !== undefined
|
|
3402
|
+
? { username, password }
|
|
3403
|
+
: {}),
|
|
3404
|
+
},
|
|
3405
|
+
}),
|
|
3406
|
+
image: this.options.config.image,
|
|
3407
|
+
resources: { vcpus: this.options.config.vcpus },
|
|
3408
|
+
timeout: this.idleMs(),
|
|
3409
|
+
persistent: true,
|
|
3410
|
+
...(this.options.config.region !== undefined
|
|
3411
|
+
? { region: this.options.config.region }
|
|
3412
|
+
: {}),
|
|
3413
|
+
...(this.options.config.failoverRegions.length > 0
|
|
3414
|
+
? { failoverRegions: this.options.config.failoverRegions }
|
|
3415
|
+
: {}),
|
|
3416
|
+
...(this.options.config.snapshotExpirationSeconds === undefined
|
|
3417
|
+
? {}
|
|
3418
|
+
: { snapshotExpiration: this.options.config.snapshotExpirationSeconds * 1000 }),
|
|
3419
|
+
networkPolicy: uploadPackPolicy(origin, readAuth),
|
|
3420
|
+
keepLastSnapshots: { count: VERCEL_KEEP_LAST_SNAPSHOTS, deleteEvicted: true },
|
|
3421
|
+
signal: this.operationSignal(),
|
|
3422
|
+
})
|
|
3423
|
+
} catch (error) {
|
|
3424
|
+
// A concurrent instance that created the same name first owns this
|
|
3425
|
+
// provision; anything else is this attempt's failure.
|
|
3426
|
+
const existing = await this.facade.get(name, this.operationSignal()).catch(() => null)
|
|
3427
|
+
if (existing !== null) return { outcome: 'concurrent' }
|
|
3428
|
+
throw error
|
|
3429
|
+
}
|
|
3430
|
+
this.origins.set(name, origin)
|
|
3431
|
+
this.sessions.set(name, sandbox)
|
|
3432
|
+
await commandOrThrow(sandbox, { cmd: 'mkdir', args: ['-p', VERCEL_OPERATOR_PROVISION_DIR] })
|
|
3433
|
+
await this.heartbeat(sandbox, 'checkout')
|
|
3434
|
+
checkpoint()
|
|
3435
|
+
if (guestClone) {
|
|
3436
|
+
await guestCloneCheckout(sandbox, origin.url, head)
|
|
3437
|
+
} else {
|
|
3438
|
+
await relocateCheckout(sandbox, origin.directory)
|
|
3439
|
+
}
|
|
3440
|
+
await commandOrThrow(sandbox, {
|
|
3441
|
+
cmd: 'git',
|
|
3442
|
+
args: ['remote', 'set-url', 'origin', origin.url],
|
|
3443
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
3444
|
+
})
|
|
3445
|
+
for (const key of [
|
|
3446
|
+
'credential.helper',
|
|
3447
|
+
'http.extraheader',
|
|
3448
|
+
`http.${origin.url}.extraheader`,
|
|
3449
|
+
]) {
|
|
3450
|
+
const result = await sandbox.runCommand({
|
|
3451
|
+
cmd: 'git',
|
|
3452
|
+
args: ['config', '--local', '--unset-all', key],
|
|
3453
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
3454
|
+
})
|
|
3455
|
+
if (result.exitCode !== 0 && result.exitCode !== 5)
|
|
3456
|
+
throw new Error(`failed to scrub git config ${key}`)
|
|
3457
|
+
}
|
|
3458
|
+
checkpoint()
|
|
3459
|
+
step = 'provision'
|
|
3460
|
+
await this.heartbeat(sandbox, 'provision')
|
|
3461
|
+
await provisionBun(sandbox, this.options.config.image, signal)
|
|
3462
|
+
checkpoint()
|
|
3463
|
+
await runSystemProvisioning(sandbox, this.options.config.provisioning ?? [], signal)
|
|
3464
|
+
checkpoint()
|
|
3465
|
+
await installDistribution(
|
|
3466
|
+
sandbox,
|
|
3467
|
+
await this.archiveBytes(),
|
|
3468
|
+
distributionIdentity,
|
|
3469
|
+
this.operationSignal(),
|
|
3470
|
+
)
|
|
3471
|
+
checkpoint()
|
|
3472
|
+
await sandbox.writeFiles(this.operatorTailFiles(head), { signal: this.operationSignal() })
|
|
3473
|
+
// Forwarded values are demanded only when a runtime or setup stage
|
|
3474
|
+
// runs, as in the host-driven chain this replaces.
|
|
3475
|
+
const setup = this.options.setupCommand
|
|
3476
|
+
const env =
|
|
3477
|
+
currentRuntimeReferences(this.options.runtimeReferences).length > 0 ||
|
|
3478
|
+
(setup !== undefined && setup.trim() !== '')
|
|
3479
|
+
? this.sandboxEnv()
|
|
3480
|
+
: {}
|
|
3481
|
+
checkpoint()
|
|
3482
|
+
const command = (await sandbox.runCommand({
|
|
3483
|
+
cmd: 'sh',
|
|
3484
|
+
args: ['-c', 'exec sh "$1"', 'tail', `${VERCEL_OPERATOR_PROVISION_DIR}/tail.sh`],
|
|
3485
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
3486
|
+
env,
|
|
3487
|
+
detached: true,
|
|
3488
|
+
signal: this.operationSignal(),
|
|
3489
|
+
})) as VercelCommand
|
|
3490
|
+
step = 'launched'
|
|
3491
|
+
await this.heartbeat(sandbox, 'launched')
|
|
3492
|
+
await this.extendOperatorTimer(sandbox, 0)
|
|
3493
|
+
return { outcome: 'launched', sandbox, command, baseSha: head }
|
|
3494
|
+
} catch (error) {
|
|
3495
|
+
if (error instanceof OperatorAttemptCancelled || signal?.aborted) {
|
|
3496
|
+
throw new OperatorAttemptCancelled(sandbox !== undefined)
|
|
3497
|
+
}
|
|
3498
|
+
const failure = {
|
|
3499
|
+
stage:
|
|
3500
|
+
error instanceof SandboxOperationError && error.stage === 'environment'
|
|
3501
|
+
? ('environment' as const)
|
|
3502
|
+
: step === 'checkout'
|
|
3503
|
+
? ('checkout' as const)
|
|
3504
|
+
: ('provision' as const),
|
|
3505
|
+
message:
|
|
3506
|
+
this.redactOperatorMessage(error instanceof Error ? error.message : String(error)) ||
|
|
3507
|
+
'operator sandbox provisioning failed',
|
|
3508
|
+
}
|
|
3509
|
+
if (sandbox !== undefined) await this.writeOperatorFailure(sandbox, failure)
|
|
3510
|
+
throw new OperatorHostFailure(failure, sandbox !== undefined, error)
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
|
|
3514
|
+
/** Register one background attempt; its body resolves, never rejects. */
|
|
3515
|
+
private startOperatorAttempt(
|
|
3516
|
+
name: string,
|
|
3517
|
+
kind: 'provision' | 'resume',
|
|
3518
|
+
body: (signal: AbortSignal) => Promise<SandboxProviderStatus>,
|
|
3519
|
+
): { status: SandboxProviderStatus; settled: Promise<SandboxProviderStatus> } {
|
|
3520
|
+
const abort = new AbortController()
|
|
3521
|
+
const entry = {
|
|
3522
|
+
kind,
|
|
3523
|
+
abort,
|
|
3524
|
+
promise: Promise.resolve<SandboxProviderStatus>({ state: 'absent' }),
|
|
3525
|
+
}
|
|
3526
|
+
this.operatorInflight.set(name, entry)
|
|
3527
|
+
entry.promise = (async (): Promise<SandboxProviderStatus> => {
|
|
3528
|
+
try {
|
|
3529
|
+
return await body(abort.signal)
|
|
3530
|
+
} catch (error) {
|
|
3531
|
+
const failure = {
|
|
3532
|
+
stage: kind === 'resume' ? ('resume' as const) : ('provision' as const),
|
|
3533
|
+
message:
|
|
3534
|
+
this.redactOperatorMessage(error instanceof Error ? error.message : String(error)) ||
|
|
3535
|
+
'operator sandbox provisioning failed',
|
|
3536
|
+
}
|
|
3537
|
+
this.operatorFailures.set(name, failure)
|
|
3538
|
+
return { state: 'failed', failure }
|
|
3539
|
+
} finally {
|
|
3540
|
+
if (this.operatorInflight.get(name) === entry) this.operatorInflight.delete(name)
|
|
3541
|
+
}
|
|
3542
|
+
})()
|
|
3543
|
+
return {
|
|
3544
|
+
status: { state: kind === 'resume' ? 'resuming' : 'provisioning', kind },
|
|
3545
|
+
settled: entry.promise,
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3549
|
+
/** A fresh provision, replacing `stale` first when given. Settles
|
|
3550
|
+
* `provisioning` once the tail is launched: the tail's outcome is observed
|
|
3551
|
+
* later through the probe. */
|
|
3552
|
+
private async freshOperatorAttempt(
|
|
3553
|
+
input: { baseBranch: string },
|
|
3554
|
+
origin: ReturnType<typeof cleanGithubOrigin>,
|
|
3555
|
+
name: string,
|
|
3556
|
+
stale: VercelSandboxHandle | undefined,
|
|
3557
|
+
signal: AbortSignal,
|
|
3558
|
+
): Promise<SandboxProviderStatus> {
|
|
3559
|
+
if (stale !== undefined) {
|
|
3560
|
+
// The journal already records this environment's failure (the
|
|
3561
|
+
// service's precondition for calling open). Replace the evidence with
|
|
3562
|
+
// a checkout heartbeat first, so a concurrent probe reads the
|
|
3563
|
+
// replacement as in flight rather than as the old failure.
|
|
3564
|
+
try {
|
|
3565
|
+
await stale.runCommand({
|
|
3566
|
+
cmd: 'sh',
|
|
3567
|
+
args: [
|
|
3568
|
+
'-c',
|
|
3569
|
+
'mkdir -p "$1" && rm -f "$1/failed" "$1/resuming" "$1/pid" "$2" && printf "checkout %s\\n" "$(date +%s)" > "$1/host"',
|
|
3570
|
+
'replace',
|
|
3571
|
+
VERCEL_OPERATOR_PROVISION_DIR,
|
|
3572
|
+
VERCEL_PROVISIONED_MARKER,
|
|
3573
|
+
],
|
|
3574
|
+
signal: this.operationSignal(),
|
|
3575
|
+
})
|
|
3576
|
+
} catch {
|
|
3577
|
+
// The reap below removes it either way.
|
|
3578
|
+
}
|
|
3579
|
+
this.sessions.set(name, stale)
|
|
3580
|
+
try {
|
|
3581
|
+
await this.reap(name)
|
|
3582
|
+
} catch (error) {
|
|
3583
|
+
const failure = {
|
|
3584
|
+
stage: 'checkout' as const,
|
|
3585
|
+
message: this.redactOperatorMessage(
|
|
3586
|
+
`could not replace the previous environment: ${describeError(error)}`,
|
|
3587
|
+
),
|
|
3588
|
+
}
|
|
3589
|
+
this.operatorFailures.set(name, failure)
|
|
3590
|
+
return { state: 'failed', failure }
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
if (signal.aborted) return { state: 'absent', cancelled: true }
|
|
3594
|
+
try {
|
|
3595
|
+
await this.runOperatorHostPhase({
|
|
3596
|
+
origin,
|
|
3597
|
+
name,
|
|
3598
|
+
baseBranch: input.baseBranch,
|
|
3599
|
+
signal,
|
|
3600
|
+
})
|
|
3601
|
+
return { state: 'provisioning', kind: 'provision' }
|
|
3602
|
+
} catch (error) {
|
|
3603
|
+
if (error instanceof OperatorAttemptCancelled) {
|
|
3604
|
+
if (error.created) await this.reap(name).catch(() => {})
|
|
3605
|
+
return { state: 'absent', cancelled: true }
|
|
3606
|
+
}
|
|
3607
|
+
if (error instanceof OperatorHostFailure) {
|
|
3608
|
+
this.operatorFailures.set(name, error.failure)
|
|
3609
|
+
return { state: 'failed', failure: error.failure }
|
|
3610
|
+
}
|
|
3611
|
+
throw error
|
|
3612
|
+
}
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
/** Bring a provisioned environment's Bun and distribution to the current
|
|
3616
|
+
* pin, then report it ready. A failure is recorded in the guest first
|
|
3617
|
+
* (stage `resume`), superseding the marker. */
|
|
3618
|
+
private async refreshOperatorRuntime(
|
|
3619
|
+
sandbox: VercelSandboxHandle,
|
|
3620
|
+
name: string,
|
|
3621
|
+
probe: Extract<VercelOperatorProbe, { kind: 'ready' }>,
|
|
3622
|
+
): Promise<SandboxProviderStatus> {
|
|
3623
|
+
try {
|
|
3624
|
+
// Every process's probe reads the refresh as in flight (outranking the
|
|
3625
|
+
// old marker) until it succeeds; a failure supersedes it with `failed`.
|
|
3626
|
+
await commandOrThrow(sandbox, {
|
|
3627
|
+
cmd: 'sh',
|
|
3628
|
+
args: [
|
|
3629
|
+
'-c',
|
|
3630
|
+
'mkdir -p "$1" && printf "%s\\n" "$(date +%s)" > "$1/resuming"',
|
|
3631
|
+
'resuming',
|
|
3632
|
+
VERCEL_OPERATOR_PROVISION_DIR,
|
|
3633
|
+
],
|
|
3634
|
+
signal: this.operationSignal(),
|
|
3635
|
+
})
|
|
3636
|
+
await ensurePinnedBun(sandbox, this.options.config.image, this.operationSignal())
|
|
3637
|
+
const identity = await this.identityStamp()
|
|
3638
|
+
if (probe.distribution !== identity) {
|
|
3639
|
+
await installDistribution(
|
|
3640
|
+
sandbox,
|
|
3641
|
+
await this.archiveBytes(),
|
|
3642
|
+
identity,
|
|
3643
|
+
this.operationSignal(),
|
|
3644
|
+
)
|
|
3645
|
+
}
|
|
3646
|
+
await commandOrThrow(sandbox, {
|
|
3647
|
+
cmd: 'sh',
|
|
3648
|
+
args: ['-c', 'rm -f "$1/resuming"', 'resumed', VERCEL_OPERATOR_PROVISION_DIR],
|
|
3649
|
+
signal: this.operationSignal(),
|
|
3650
|
+
})
|
|
3651
|
+
} catch (error) {
|
|
3652
|
+
const failure = {
|
|
3653
|
+
stage: 'resume' as const,
|
|
3654
|
+
message:
|
|
3655
|
+
this.redactOperatorMessage(error instanceof Error ? error.message : String(error)) ||
|
|
3656
|
+
'operator sandbox resume failed',
|
|
3657
|
+
}
|
|
3658
|
+
await this.writeOperatorFailure(sandbox, failure)
|
|
3659
|
+
this.operatorFailures.set(name, failure)
|
|
3660
|
+
return { state: 'failed', failure }
|
|
2664
3661
|
}
|
|
3662
|
+
await this.extendOperatorTimer(sandbox, 0)
|
|
3663
|
+
this.sessions.set(name, sandbox)
|
|
3664
|
+
return this.readyStatus(name, sandbox, probe, 'resume')
|
|
3665
|
+
}
|
|
3666
|
+
|
|
3667
|
+
/** Resume a stopped environment: the only path that recovers evidence
|
|
3668
|
+
* from a stopped sandbox, because status never resumes one. A recorded
|
|
3669
|
+
* failure settles with its recorded stage and message; nothing is reaped
|
|
3670
|
+
* here. */
|
|
3671
|
+
private async resumeOperatorAttempt(
|
|
3672
|
+
sandbox: VercelSandboxHandle,
|
|
3673
|
+
name: string,
|
|
3674
|
+
): Promise<SandboxProviderStatus> {
|
|
3675
|
+
await this.applyOperatorSession(sandbox, name)
|
|
3676
|
+
let probe = await this.probeOperator(sandbox)
|
|
3677
|
+
if (probe.kind === 'resuming') {
|
|
3678
|
+
// The stop ended that refresh; this attempt redoes it.
|
|
3679
|
+
await commandOrThrow(sandbox, {
|
|
3680
|
+
cmd: 'sh',
|
|
3681
|
+
args: ['-c', 'rm -f "$1/resuming"', 'resumed', VERCEL_OPERATOR_PROVISION_DIR],
|
|
3682
|
+
signal: this.operationSignal(),
|
|
3683
|
+
})
|
|
3684
|
+
probe = await this.probeOperator(sandbox)
|
|
3685
|
+
}
|
|
3686
|
+
if (probe.kind === 'ready') return this.refreshOperatorRuntime(sandbox, name, probe)
|
|
3687
|
+
if (probe.kind === 'running') return { state: 'provisioning', kind: 'provision' }
|
|
3688
|
+
const failure =
|
|
3689
|
+
probe.kind === 'failed'
|
|
3690
|
+
? this.probeFailure(probe)
|
|
3691
|
+
: this.interruptedFailure(probe.kind === 'host' ? probe.step : undefined)
|
|
3692
|
+
this.operatorFailures.set(name, failure)
|
|
3693
|
+
return { state: 'failed', failure }
|
|
3694
|
+
}
|
|
3695
|
+
|
|
3696
|
+
private async openOperator(input: {
|
|
3697
|
+
repo: string
|
|
3698
|
+
operator: string
|
|
3699
|
+
baseBranch: string
|
|
3700
|
+
}): Promise<{ status: SandboxProviderStatus; settled?: Promise<SandboxProviderStatus> }> {
|
|
3701
|
+
const { origin, name } = await this.operatorName(input.operator)
|
|
3702
|
+
return this.withPolicyLock(name, async () => {
|
|
3703
|
+
const inflight = this.operatorInflight.get(name)
|
|
3704
|
+
if (inflight !== undefined) {
|
|
3705
|
+
return {
|
|
3706
|
+
status: {
|
|
3707
|
+
state: inflight.kind === 'resume' ? 'resuming' : 'provisioning',
|
|
3708
|
+
kind: inflight.kind,
|
|
3709
|
+
},
|
|
3710
|
+
settled: inflight.promise,
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
this.operatorFailures.delete(name)
|
|
3714
|
+
const sandbox = await this.facade.get(name, this.operationSignal())
|
|
3715
|
+
if (sandbox === null) {
|
|
3716
|
+
return this.startOperatorAttempt(name, 'provision', (signal) =>
|
|
3717
|
+
this.freshOperatorAttempt(input, origin, name, undefined, signal),
|
|
3718
|
+
)
|
|
3719
|
+
}
|
|
3720
|
+
const session = sandbox.sessionStatus
|
|
3721
|
+
if (session === undefined || session === 'running') {
|
|
3722
|
+
await this.applyOperatorSession(sandbox, name)
|
|
3723
|
+
const probe = await this.probeOperator(sandbox)
|
|
3724
|
+
if (probe.kind === 'ready') {
|
|
3725
|
+
if (
|
|
3726
|
+
probe.bunVersion === VERCEL_BUN_VERSION &&
|
|
3727
|
+
probe.distribution === (await this.identityStamp())
|
|
3728
|
+
) {
|
|
3729
|
+
await this.extendOperatorTimer(sandbox, 0)
|
|
3730
|
+
this.sessions.set(name, sandbox)
|
|
3731
|
+
return { status: this.readyStatus(name, sandbox, probe, 'resume') }
|
|
3732
|
+
}
|
|
3733
|
+
return this.startOperatorAttempt(name, 'resume', () =>
|
|
3734
|
+
this.refreshOperatorRuntime(sandbox, name, probe),
|
|
3735
|
+
)
|
|
3736
|
+
}
|
|
3737
|
+
if (this.classifyOperatorProbe(name, sandbox, probe).inFlight) {
|
|
3738
|
+
// Another process's provision or refresh is in flight.
|
|
3739
|
+
return {
|
|
3740
|
+
status:
|
|
3741
|
+
probe.kind === 'resuming'
|
|
3742
|
+
? { state: 'resuming', kind: 'resume' }
|
|
3743
|
+
: { state: 'provisioning', kind: 'provision' },
|
|
3744
|
+
}
|
|
3745
|
+
}
|
|
3746
|
+
// A failed, interrupted or marker-less environment. The service
|
|
3747
|
+
// calls open only after the journal records its failure, so its
|
|
3748
|
+
// evidence may now be replaced.
|
|
3749
|
+
return this.startOperatorAttempt(name, 'provision', (signal) =>
|
|
3750
|
+
this.freshOperatorAttempt(input, origin, name, sandbox, signal),
|
|
3751
|
+
)
|
|
3752
|
+
}
|
|
3753
|
+
if (session === 'pending') return { status: { state: 'resuming', kind: 'resume' } }
|
|
3754
|
+
return this.startOperatorAttempt(name, 'resume', () =>
|
|
3755
|
+
this.resumeOperatorAttempt(sandbox, name),
|
|
3756
|
+
)
|
|
3757
|
+
})
|
|
3758
|
+
}
|
|
3759
|
+
|
|
3760
|
+
private async statusOperator(input: {
|
|
3761
|
+
repo: string
|
|
3762
|
+
operator: string
|
|
3763
|
+
}): Promise<SandboxProviderStatus> {
|
|
3764
|
+
const { name } = await this.operatorName(input.operator)
|
|
3765
|
+
const inflight = this.operatorInflight.get(name)
|
|
3766
|
+
if (inflight !== undefined) {
|
|
3767
|
+
return { state: inflight.kind === 'resume' ? 'resuming' : 'provisioning' }
|
|
3768
|
+
}
|
|
3769
|
+
const failure = this.operatorFailures.get(name)
|
|
3770
|
+
if (failure !== undefined) return { state: 'failed', failure }
|
|
3771
|
+
const sandbox = await this.facade.get(name, this.operationSignal())
|
|
3772
|
+
if (sandbox === null) return { state: 'absent' }
|
|
3773
|
+
// Never a guest command on a session that is not running: it would
|
|
3774
|
+
// resume it.
|
|
3775
|
+
const session = sandbox.sessionStatus
|
|
3776
|
+
if (session === 'pending') return { state: 'resuming' }
|
|
3777
|
+
if (session !== undefined && session !== 'running') return { state: 'stopped' }
|
|
3778
|
+
const { status, inFlight } = this.classifyOperatorProbe(
|
|
3779
|
+
name,
|
|
3780
|
+
sandbox,
|
|
3781
|
+
await this.probeOperator(sandbox),
|
|
3782
|
+
)
|
|
3783
|
+
// Only a provision in flight keeps the timer alive; polling a ready,
|
|
3784
|
+
// idle environment never does.
|
|
3785
|
+
if (inFlight) await this.extendOperatorTimer(sandbox, 0)
|
|
3786
|
+
return status
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3789
|
+
private async closeOperator(input: {
|
|
3790
|
+
repo: string
|
|
3791
|
+
operator: string
|
|
3792
|
+
environmentId: string
|
|
3793
|
+
}): Promise<{ outcome: 'closed' | 'absent'; attempt?: SandboxProviderStatus }> {
|
|
3794
|
+
const { name } = await this.operatorName(input.operator)
|
|
3795
|
+
let attempt: SandboxProviderStatus | undefined
|
|
3796
|
+
const inflight = this.operatorInflight.get(name)
|
|
3797
|
+
if (inflight !== undefined) {
|
|
3798
|
+
inflight.abort.abort()
|
|
3799
|
+
attempt = await inflight.promise
|
|
3800
|
+
}
|
|
3801
|
+
return this.withPolicyLock(name, async () => {
|
|
3802
|
+
const withAttempt = <T extends object>(result: T) =>
|
|
3803
|
+
attempt === undefined ? result : { ...result, attempt }
|
|
3804
|
+
const sandbox = await this.facade.get(name, this.operationSignal())
|
|
3805
|
+
if (sandbox === null) return withAttempt({ outcome: 'absent' as const })
|
|
3806
|
+
if (attempt?.cancelled === true) return withAttempt({ outcome: 'absent' as const })
|
|
3807
|
+
const session = sandbox.sessionStatus
|
|
3808
|
+
const running = session === undefined || session === 'running'
|
|
3809
|
+
if (running && attempt === undefined) {
|
|
3810
|
+
const probe = await this.probeOperator(sandbox)
|
|
3811
|
+
const { status, inFlight } = this.classifyOperatorProbe(name, sandbox, probe)
|
|
3812
|
+
if (inFlight && probe.kind !== 'resuming') {
|
|
3813
|
+
// Closing an in-flight provision is a user-requested cancel; a
|
|
3814
|
+
// refresh of a provisioned checkout is stopped, never discarded.
|
|
3815
|
+
this.sessions.set(name, sandbox)
|
|
3816
|
+
await this.reap(name)
|
|
3817
|
+
return { outcome: 'absent' as const, attempt: { state: 'absent', cancelled: true } }
|
|
3818
|
+
}
|
|
3819
|
+
if (status.state === 'failed') attempt = status
|
|
3820
|
+
}
|
|
3821
|
+
// Stopping releases capacity and keeps the snapshot — and with it any
|
|
3822
|
+
// failure evidence, which a later open recovers. A pending session
|
|
3823
|
+
// (another process resuming it) is stopped too, without a guest
|
|
3824
|
+
// command: it would otherwise start and hold capacity until its timer.
|
|
3825
|
+
if (running || session === 'pending') {
|
|
3826
|
+
try {
|
|
3827
|
+
await sandbox.stop({ signal: this.operationSignal() })
|
|
3828
|
+
} catch (error) {
|
|
3829
|
+
// A failed or interrupted stop request is not confirmation: only an
|
|
3830
|
+
// authoritative re-read showing the session no longer active is.
|
|
3831
|
+
// Anything else refuses, so the journal never records `closed`
|
|
3832
|
+
// while the session still holds capacity.
|
|
3833
|
+
const after = await this.facade.get(name, this.operationSignal())
|
|
3834
|
+
if (after === null) return withAttempt({ outcome: 'absent' as const })
|
|
3835
|
+
const now = after.sessionStatus
|
|
3836
|
+
if (now === undefined || now === 'running' || now === 'pending') {
|
|
3837
|
+
throw new SandboxOperationError(
|
|
3838
|
+
'close',
|
|
3839
|
+
`could not confirm operator sandbox ${name} stopped (${describeError(error)}); call sandbox.close again`,
|
|
3840
|
+
{ cause: error },
|
|
3841
|
+
)
|
|
3842
|
+
}
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
this.sessions.delete(name)
|
|
3846
|
+
return withAttempt({ outcome: 'closed' as const })
|
|
3847
|
+
})
|
|
3848
|
+
}
|
|
3849
|
+
|
|
3850
|
+
private async refreshOperator(
|
|
3851
|
+
handle: SandboxEnvironmentIdentity,
|
|
3852
|
+
input: { repo: string; baseBranch: string },
|
|
3853
|
+
): Promise<SandboxRefreshResult> {
|
|
3854
|
+
const base = await this.remoteBranchHead(input.baseBranch, `remote base ${input.baseBranch}`)
|
|
3855
|
+
if (base === null) {
|
|
3856
|
+
throw new SandboxOperationError('refresh', `remote base ${input.baseBranch} does not exist`)
|
|
3857
|
+
}
|
|
3858
|
+
const sandbox = await this.sandboxHandle(handle)
|
|
3859
|
+
const git = (args: string[], env?: Record<string, string>) =>
|
|
3860
|
+
sandbox.runCommand({
|
|
3861
|
+
cmd: 'git',
|
|
3862
|
+
args,
|
|
3863
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
3864
|
+
...(env !== undefined ? { env } : {}),
|
|
3865
|
+
signal: this.operationSignal(),
|
|
3866
|
+
}) as Promise<VercelCommand>
|
|
3867
|
+
const status = await readableCommand(sandbox, {
|
|
3868
|
+
cmd: 'git',
|
|
3869
|
+
args: ['status', '--porcelain'],
|
|
3870
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
3871
|
+
})
|
|
3872
|
+
if (status.trim() !== '') {
|
|
3873
|
+
return { outcome: 'refused', reason: 'dirty', message: SANDBOX_REFRESH_DIRTY_MESSAGE }
|
|
3874
|
+
}
|
|
3875
|
+
const head = (
|
|
3876
|
+
await readableCommand(sandbox, {
|
|
3877
|
+
cmd: 'git',
|
|
3878
|
+
args: ['rev-parse', 'HEAD'],
|
|
3879
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
3880
|
+
})
|
|
3881
|
+
).trim()
|
|
3882
|
+
// No credential rides the fetch: the upload-pack egress transform
|
|
3883
|
+
// authenticates it.
|
|
3884
|
+
const fetched = await git(['fetch', '--quiet', 'origin', input.baseBranch], {
|
|
3885
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
3886
|
+
})
|
|
3887
|
+
if (fetched.exitCode !== 0) {
|
|
3888
|
+
const stderr = (await fetched.stderr?.().catch(() => '')) ?? ''
|
|
3889
|
+
throw new SandboxOperationError(
|
|
3890
|
+
'refresh',
|
|
3891
|
+
this.redactOperatorMessage(
|
|
3892
|
+
`git fetch origin ${input.baseBranch} exited ${fetched.exitCode}: ${stderr.trim() || '(no output)'}`,
|
|
3893
|
+
),
|
|
3894
|
+
)
|
|
3895
|
+
}
|
|
3896
|
+
const isAncestor = async (ancestor: string, descendant: string): Promise<boolean> => {
|
|
3897
|
+
const result = await git(['merge-base', '--is-ancestor', ancestor, descendant])
|
|
3898
|
+
if (result.exitCode === 0) return true
|
|
3899
|
+
if (result.exitCode === 1) return false
|
|
3900
|
+
throw new SandboxOperationError(
|
|
3901
|
+
'refresh',
|
|
3902
|
+
`git merge-base --is-ancestor ${ancestor} ${descendant} exited ${result.exitCode}`,
|
|
3903
|
+
)
|
|
3904
|
+
}
|
|
3905
|
+
if (head === base || (await isAncestor(base, head))) {
|
|
3906
|
+
return { outcome: 'current', headSha: head, baseSha: base, previousHeadSha: head }
|
|
3907
|
+
}
|
|
3908
|
+
if (!(await isAncestor(head, base))) {
|
|
3909
|
+
return {
|
|
3910
|
+
outcome: 'refused',
|
|
3911
|
+
reason: 'diverged',
|
|
3912
|
+
message: sandboxRefreshDivergedMessage(head, input.baseBranch, base),
|
|
3913
|
+
}
|
|
3914
|
+
}
|
|
3915
|
+
await readableCommand(sandbox, {
|
|
3916
|
+
cmd: 'git',
|
|
3917
|
+
args: ['-c', 'advice.detachedHead=false', 'checkout', '--quiet', '--detach', base],
|
|
3918
|
+
cwd: VERCEL_WORKSPACE_PATH,
|
|
3919
|
+
})
|
|
3920
|
+
await commandOrThrow(sandbox, {
|
|
3921
|
+
cmd: 'sh',
|
|
3922
|
+
args: [
|
|
3923
|
+
'-c',
|
|
3924
|
+
'printf %s "$1" > "$2"',
|
|
3925
|
+
'marker',
|
|
3926
|
+
JSON.stringify({ baseSha: base }),
|
|
3927
|
+
VERCEL_PROVISIONED_MARKER,
|
|
3928
|
+
],
|
|
3929
|
+
})
|
|
3930
|
+
return { outcome: 'refreshed', headSha: base, baseSha: base, previousHeadSha: head }
|
|
3931
|
+
}
|
|
3932
|
+
|
|
3933
|
+
/** Resolve the live handle behind a journal-carried environment id. A
|
|
3934
|
+
* missing environment is a typed `not-found`; a session the provider timer
|
|
3935
|
+
* stopped refuses typed `not-ready` (`stopped`) rather than resuming
|
|
3936
|
+
* inline — `sandbox.open` resumes it. A running session's timer is
|
|
3937
|
+
* extended to cover `boundMs` (the call's own wait bound) or the idle
|
|
3938
|
+
* timeout, whichever is longer. */
|
|
3939
|
+
private async sandboxHandle(
|
|
3940
|
+
handle: SandboxEnvironmentIdentity,
|
|
3941
|
+
boundMs = 0,
|
|
3942
|
+
): Promise<VercelSandboxHandle> {
|
|
3943
|
+
const sandbox = await this.facade.get(handle.environmentId, this.operationSignal())
|
|
3944
|
+
if (sandbox === null) {
|
|
3945
|
+
throw new SandboxOperationError(
|
|
3946
|
+
'not-found',
|
|
3947
|
+
`operator sandbox ${handle.environmentId} no longer exists`,
|
|
3948
|
+
)
|
|
3949
|
+
}
|
|
3950
|
+
const session = sandbox.sessionStatus
|
|
3951
|
+
if (session !== undefined && session !== 'running') {
|
|
3952
|
+
const state = session === 'pending' ? 'resuming' : 'stopped'
|
|
3953
|
+
throw new SandboxOperationError(
|
|
3954
|
+
'not-ready',
|
|
3955
|
+
state === 'resuming'
|
|
3956
|
+
? 'operator sandbox is resuming; poll sandbox.status until it reports ready'
|
|
3957
|
+
: 'operator sandbox is stopped; call sandbox.open and poll sandbox.status until it reports ready',
|
|
3958
|
+
{ state },
|
|
3959
|
+
)
|
|
3960
|
+
}
|
|
3961
|
+
await this.extendOperatorTimer(sandbox, boundMs)
|
|
2665
3962
|
this.sessions.set(handle.environmentId, sandbox)
|
|
2666
3963
|
return sandbox
|
|
2667
3964
|
}
|
|
@@ -2722,11 +4019,11 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
2722
4019
|
handle: SandboxEnvironmentIdentity,
|
|
2723
4020
|
request: SandboxCommandRequest,
|
|
2724
4021
|
): Promise<SandboxCommandResult> {
|
|
2725
|
-
const sandbox = await this.sandboxHandle(handle)
|
|
2726
4022
|
const timeoutSeconds = Math.min(
|
|
2727
4023
|
Math.max(request.timeoutSeconds ?? 120, 1),
|
|
2728
4024
|
SANDBOX_MAX_WAIT_SECONDS,
|
|
2729
4025
|
)
|
|
4026
|
+
const sandbox = await this.sandboxHandle(handle, timeoutSeconds * 1000 + 60_000)
|
|
2730
4027
|
const command = await this.sandboxLaunch(sandbox, request)
|
|
2731
4028
|
const deadline = Date.now() + timeoutSeconds * 1000
|
|
2732
4029
|
let exit: { exitCode: number }
|
|
@@ -2771,8 +4068,8 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
2771
4068
|
handle: SandboxEnvironmentIdentity,
|
|
2772
4069
|
input: { commandId: string; waitSeconds: number },
|
|
2773
4070
|
): Promise<SandboxWaitResult> {
|
|
2774
|
-
const sandbox = await this.sandboxHandle(handle)
|
|
2775
4071
|
const waitSeconds = Math.min(Math.max(input.waitSeconds, 0), SANDBOX_MAX_WAIT_SECONDS)
|
|
4072
|
+
const sandbox = await this.sandboxHandle(handle, waitSeconds * 1000 + 60_000)
|
|
2776
4073
|
const lookup = await sandbox.getCommand(input.commandId, { signal: this.operationSignal() })
|
|
2777
4074
|
if (lookup.exitCode !== null) {
|
|
2778
4075
|
const [stdout, stderr] = await Promise.all([
|
|
@@ -2900,6 +4197,13 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
2900
4197
|
}): Promise<{
|
|
2901
4198
|
snapshots: { outcome: 'confirmed' | 'unknown'; deleted?: number; error?: string }
|
|
2902
4199
|
}> {
|
|
4200
|
+
// An in-flight attempt is cancelled and awaited before the teardown.
|
|
4201
|
+
const inflight = this.operatorInflight.get(input.environmentId)
|
|
4202
|
+
if (inflight !== undefined) {
|
|
4203
|
+
inflight.abort.abort()
|
|
4204
|
+
await inflight.promise
|
|
4205
|
+
}
|
|
4206
|
+
this.operatorFailures.delete(input.environmentId)
|
|
2903
4207
|
const reap = await this.reap(input.environmentId)
|
|
2904
4208
|
return {
|
|
2905
4209
|
snapshots: {
|
|
@@ -2918,6 +4222,11 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
2918
4222
|
return execOrThrow(this.exec, ['git', 'remote', 'get-url', 'origin'], this.options.repo)
|
|
2919
4223
|
}
|
|
2920
4224
|
|
|
4225
|
+
/** Guest git transport whose refused archive pushes fall back to the host. */
|
|
4226
|
+
private archiveTransport(exec: Exec): ForgeRewrite {
|
|
4227
|
+
return gitRewrite(exec, false, undefined, this.options.refusedArchive)
|
|
4228
|
+
}
|
|
4229
|
+
|
|
2921
4230
|
private async remoteBranchHead(branch: string, _label: string): Promise<string | null> {
|
|
2922
4231
|
if (this.options.remoteBranchHead !== undefined) {
|
|
2923
4232
|
const head = (await this.options.remoteBranchHead(branch)) ?? null
|
|
@@ -3019,6 +4328,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
3019
4328
|
expected?: string
|
|
3020
4329
|
localExpected?: string
|
|
3021
4330
|
archives?: { ref: string; sha: string }[]
|
|
4331
|
+
retain?: Parameters<NonNullable<WorkspacePublication['rewrite']>>[0]['retain']
|
|
3022
4332
|
}): Promise<void | import('../types').RewriteResult> {
|
|
3023
4333
|
if (this.active.has(input.ref) || this.uncertain.has(input.ref)) {
|
|
3024
4334
|
throw new Error('publication is forbidden until sandbox execution teardown is confirmed')
|
|
@@ -3087,7 +4397,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
3087
4397
|
{ signal: this.operationSignal() },
|
|
3088
4398
|
)
|
|
3089
4399
|
if (input.expected !== undefined) {
|
|
3090
|
-
const
|
|
4400
|
+
const trustedExec: Exec = async (cmd) => {
|
|
3091
4401
|
const result = await sandbox.runCommand({
|
|
3092
4402
|
cmd: cmd[0]!,
|
|
3093
4403
|
args: cmd.slice(1),
|
|
@@ -3102,9 +4412,17 @@ export class VercelSandboxProvider implements WorkspaceProvider {
|
|
|
3102
4412
|
stdout: await result.stdout!(),
|
|
3103
4413
|
stderr: await result.stderr!(),
|
|
3104
4414
|
}
|
|
3105
|
-
}
|
|
4415
|
+
}
|
|
4416
|
+
const capability = this.archiveTransport(trustedExec)
|
|
3106
4417
|
for (const archive of input.archives ?? [])
|
|
3107
|
-
|
|
4418
|
+
if (input.retain)
|
|
4419
|
+
await input.retain({
|
|
4420
|
+
exec: trustedExec,
|
|
4421
|
+
workspacePath: VERCEL_WORKSPACE_PATH,
|
|
4422
|
+
archive: capability.archive,
|
|
4423
|
+
...archive,
|
|
4424
|
+
})
|
|
4425
|
+
else await capability.archive({ workspacePath: VERCEL_WORKSPACE_PATH, ...archive })
|
|
3108
4426
|
return await capability.replace({
|
|
3109
4427
|
workspacePath: VERCEL_WORKSPACE_PATH,
|
|
3110
4428
|
branch: input.branch,
|