@outerlayer/cli 0.38.0-next.20261106003041 → 0.38.0-next.20261106190200

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.
Files changed (165) hide show
  1. package/README.md +16 -0
  2. package/dist/{agent-setup-CBEPGNFY.js → agent-setup-RO2DJUF3.js} +18 -18
  3. package/dist/{agent-subcommand-UNSXJUHA.js → agent-subcommand-PSI3BAXM.js} +3 -3
  4. package/dist/{bridge-JI4IO7JN.js → bridge-3WAVT5SX.js} +6 -6
  5. package/dist/{build-2L3L2OJO.js → build-4KG7H2XK.js} +12 -12
  6. package/dist/{build-disk-CKBEEF4N.js → build-disk-GGGJ237B.js} +10 -10
  7. package/dist/build-info.json +1 -1
  8. package/dist/{builder-PKDA7X2H.js → builder-HV7PUSZZ.js} +9 -9
  9. package/dist/caller-3P3AEY7W.js +23 -0
  10. package/dist/{check-FG32SYJF.js → check-LENGOFUF.js} +68 -52
  11. package/dist/{chunk-DXBYNJRM.js → chunk-27P5FSZT.js} +5 -5
  12. package/dist/{chunk-T524XQKI.js → chunk-2MA2KWHN.js} +1 -1
  13. package/dist/{chunk-FGVVBYCT.js → chunk-2VN36ZPA.js} +1 -1
  14. package/dist/{chunk-ZCEM4GJ5.js → chunk-3E65OLJ4.js} +3 -3
  15. package/dist/{chunk-EXIZ3G6I.js → chunk-3KVYSJAL.js} +4 -4
  16. package/dist/{chunk-EHJYXABQ.js → chunk-4PH3KXDP.js} +1 -1
  17. package/dist/{chunk-WF2NXBOM.js → chunk-5BDYRHZZ.js} +7 -7
  18. package/dist/{chunk-ZTJTAKVW.js → chunk-5MWE5IOO.js} +1 -1
  19. package/dist/{chunk-ERQLHUWU.js → chunk-5QBTW367.js} +5 -5
  20. package/dist/{chunk-4MSEUIMK.js → chunk-6744TXEY.js} +5 -5
  21. package/dist/{chunk-MDKLSY43.js → chunk-677TCNML.js} +1 -1
  22. package/dist/{chunk-3FAJMXBA.js → chunk-6BPCEGJL.js} +8 -8
  23. package/dist/{chunk-S7CE7QCF.js → chunk-6ZSUJ3ES.js} +3 -3
  24. package/dist/{chunk-TAEDH2SU.js → chunk-76Y35TWH.js} +1 -1
  25. package/dist/{chunk-HG2ZG6ZU.js → chunk-7ATHSAAT.js} +1 -1
  26. package/dist/{chunk-KLQLQQGG.js → chunk-7B4A6PBC.js} +3 -3
  27. package/dist/{chunk-PARDL7HH.js → chunk-7KF36CVC.js} +1 -1
  28. package/dist/{chunk-ZO3RUMUR.js → chunk-A24MNKYN.js} +4 -4
  29. package/dist/{chunk-O4Z2YVC3.js → chunk-ANFGBAWY.js} +4 -4
  30. package/dist/{chunk-L4ACBB5R.js → chunk-BEKYNGLH.js} +1 -1
  31. package/dist/{chunk-YWWW47OY.js → chunk-CFTSVW7W.js} +1 -1
  32. package/dist/{chunk-RSRNZB4T.js → chunk-DF6ZHOIA.js} +6 -6
  33. package/dist/{chunk-U5EE7PGC.js → chunk-E2ZWGLNZ.js} +3 -3
  34. package/dist/{chunk-K6JOU4CT.js → chunk-F2PTLH3J.js} +152 -48
  35. package/dist/{chunk-ZLJXMXZP.js → chunk-FBBI6K7D.js} +2 -2
  36. package/dist/{chunk-OUHM6U6Z.js → chunk-FCU7WSCV.js} +144 -5
  37. package/dist/{chunk-MPE4NOKD.js → chunk-G2EWER4K.js} +2 -2
  38. package/dist/{chunk-ONOINHY4.js → chunk-G2ITKUX4.js} +1 -1
  39. package/dist/{chunk-QWDGHEQL.js → chunk-GM3H4ZHG.js} +1 -1
  40. package/dist/{chunk-AVEF3T6Y.js → chunk-GM4TY5H2.js} +1 -1
  41. package/dist/{chunk-DL5N6V3D.js → chunk-GQEVQIS6.js} +1 -1
  42. package/dist/{chunk-5R5FEPLH.js → chunk-H2L5NB5U.js} +98 -17
  43. package/dist/{chunk-CGXYPLK3.js → chunk-HTQFAHXD.js} +2 -2
  44. package/dist/{chunk-QONY6C2B.js → chunk-IOURL3LH.js} +15 -9
  45. package/dist/{chunk-XE2PXGZT.js → chunk-JKQAOSSX.js} +3 -3
  46. package/dist/{chunk-3XWZKL2P.js → chunk-JKYCEXZX.js} +7 -7
  47. package/dist/{chunk-45TFVWNT.js → chunk-JW25JVK4.js} +5 -5
  48. package/dist/{chunk-VWNQRD4I.js → chunk-KMUERD5F.js} +4 -4
  49. package/dist/{chunk-AJC5Q2NY.js → chunk-LFBQL4AP.js} +5 -5
  50. package/dist/{chunk-3DVCPRKE.js → chunk-LRE4QIMD.js} +7 -7
  51. package/dist/{chunk-GMRVWRHD.js → chunk-M4JFGNG7.js} +2 -2
  52. package/dist/{chunk-X2DX3A7H.js → chunk-MCLSXTLY.js} +1 -1
  53. package/dist/{chunk-BO3NOGKE.js → chunk-ML3O3A3Q.js} +1 -1
  54. package/dist/{chunk-ABN4UBR5.js → chunk-NMCRJ7NZ.js} +2 -2
  55. package/dist/{chunk-CCMKLF7K.js → chunk-NTRXOTO7.js} +4 -4
  56. package/dist/{chunk-256R6O56.js → chunk-OMCDOJO2.js} +8 -5
  57. package/dist/{chunk-OGQW7A4G.js → chunk-QHOC32DP.js} +8 -8
  58. package/dist/{chunk-SMFWLPXC.js → chunk-RDPLNQFI.js} +18 -17
  59. package/dist/{chunk-JTDMSQMI.js → chunk-RFBJKK2L.js} +7 -7
  60. package/dist/{chunk-BL6CCU26.js → chunk-SUMXGPSG.js} +5 -5
  61. package/dist/{chunk-XDRZ3BNA.js → chunk-T7KETYNW.js} +1 -1
  62. package/dist/{chunk-PMJ6IEUM.js → chunk-TDBP62O2.js} +7 -7
  63. package/dist/{chunk-RZ6WJTUP.js → chunk-TDUBZ4FR.js} +1 -1
  64. package/dist/{chunk-AMG5ICDO.js → chunk-TFBNHDPT.js} +4 -4
  65. package/dist/{chunk-DVFGCVTV.js → chunk-TMYBADTM.js} +5 -5
  66. package/dist/{chunk-EFAOERZH.js → chunk-TOVSIUEJ.js} +1 -1
  67. package/dist/{chunk-EERD7VI3.js → chunk-U4ZHNHCF.js} +1 -1
  68. package/dist/{chunk-VNT2IRLM.js → chunk-UF3YTRGU.js} +70 -11
  69. package/dist/{chunk-U7L4GBGS.js → chunk-USJVENIV.js} +1 -1
  70. package/dist/{chunk-2MQQASWB.js → chunk-VOSC32UF.js} +6 -6
  71. package/dist/{chunk-FOUG2R4Q.js → chunk-VRSUCU2N.js} +1 -1
  72. package/dist/{chunk-YZRDJOOR.js → chunk-XDVLF6OT.js} +3 -3
  73. package/dist/{chunk-DK5YFDYI.js → chunk-YL6GWLK5.js} +8 -8
  74. package/dist/{chunk-YKWOVYVN.js → chunk-YSIVKYLW.js} +9 -6
  75. package/dist/{chunk-5VAXNAOD.js → chunk-YZ5M7S7U.js} +1 -1
  76. package/dist/{chunk-RUJR3SDB.js → chunk-ZGN3NOVS.js} +1 -1
  77. package/dist/{chunk-OFWNBTLU.js → chunk-ZOWUJUSF.js} +1 -1
  78. package/dist/{chunk-FER7JJ3S.js → chunk-ZPCUXCQX.js} +1 -1
  79. package/dist/{chunk-Z4R36YDJ.js → chunk-ZYQT6Q5R.js} +1379 -628
  80. package/dist/{claude-launcher-FHQTSQOM.js → claude-launcher-G73I5AGW.js} +6 -6
  81. package/dist/{cli-GNC4MFMP.js → cli-5SILU2LX.js} +154 -147
  82. package/dist/{command-47EYM2FJ.js → command-DBBEP7VM.js} +56 -49
  83. package/dist/{config-EA6WVKAS.js → config-KOSTQZXG.js} +11 -11
  84. package/dist/{connect-cmd-4JO2LBUT.js → connect-cmd-UNBJYFYM.js} +10 -10
  85. package/dist/{container-start-XR7KANS6.js → container-start-AAOLPVAH.js} +45 -45
  86. package/dist/{context-cleanup-6CTKLEUT.js → context-cleanup-MKVMFRNR.js} +3 -3
  87. package/dist/{context-show-cmd-Z7NQAKNE.js → context-show-cmd-P3LBILMP.js} +11 -11
  88. package/dist/{control-plane-launch-4PLBJKBS.js → control-plane-launch-2GOJKA53.js} +13 -13
  89. package/dist/{demo-record-cmd-3B2ME2ZI.js → demo-record-cmd-BPINCNYS.js} +7 -7
  90. package/dist/{demo-voice-cmd-LIXAA3OS.js → demo-voice-cmd-HBK3TWM5.js} +17 -17
  91. package/dist/{dist-3TV6G4YF.js → dist-MUOHO52Q.js} +1 -1
  92. package/dist/{docker-FPEQS6HK.js → docker-NUPVSMVQ.js} +9 -9
  93. package/dist/{doctor-AFH6UUX6.js → doctor-GHRSOZLB.js} +53 -47
  94. package/dist/{emit-artifact-cmd-5XIEUWFX.js → emit-artifact-cmd-CULA5AM4.js} +16 -16
  95. package/dist/{emit-cmd-IKYF27IK.js → emit-cmd-746N7PYR.js} +6 -6
  96. package/dist/{emit-criteria-cmd-YS5ZSLCN.js → emit-criteria-cmd-NY4RPUPD.js} +13 -13
  97. package/dist/{emit-demo-cmd-IDC2JC46.js → emit-demo-cmd-MYXTGMJI.js} +17 -17
  98. package/dist/{emit-finding-cmd-C4NRTIZO.js → emit-finding-cmd-ZGGMPQFT.js} +13 -13
  99. package/dist/{emit-result-cmd-GC2I7JQU.js → emit-result-cmd-GNEQHIIZ.js} +15 -15
  100. package/dist/{emit-step-cmd-TTH4FYFW.js → emit-step-cmd-NYCJ3XFQ.js} +13 -13
  101. package/dist/{exec-client-DT5EWVQL.js → exec-client-QHB62OZ6.js} +7 -7
  102. package/dist/find-unit-UVS2FM7E.js +24 -0
  103. package/dist/{findings-cmd-MSV52ODM.js → findings-cmd-ZINCPCAB.js} +13 -13
  104. package/dist/{fleet-readiness-O76CSI7M.js → fleet-readiness-FZCSJ7FY.js} +12 -12
  105. package/dist/{governing-source-QEFYVBQF.js → governing-source-CQML5N2D.js} +18 -18
  106. package/dist/{guest-init-X7M5AIOI.js → guest-init-C6FWJVAQ.js} +8 -8
  107. package/dist/{hook-fast-T6FOTZHA.js → hook-fast-6IOLZ45F.js} +1 -1
  108. package/dist/{hook-install-OUSUHQ6C.js → hook-install-VL4CEO4S.js} +3 -3
  109. package/dist/host-checks-HPCMZ7XT.js +79 -0
  110. package/dist/{host-key-UFUIBFBF.js → host-key-5APXLMY2.js} +7 -7
  111. package/dist/{image-tag-AE6EKDPV.js → image-tag-IBAYH5XH.js} +7 -7
  112. package/dist/index.js +4 -4
  113. package/dist/{init-PUN3PKOT.js → init-EIQFBAZI.js} +43 -43
  114. package/dist/init-YD4MNH5U.js +79 -0
  115. package/dist/{init-agent-D3KK24QX.js → init-agent-7UQZFG5E.js} +43 -43
  116. package/dist/{init-cmd-LGRN3U7K.js → init-cmd-TNJXWFQU.js} +24 -24
  117. package/dist/{init-update-ZL2J7EQI.js → init-update-KJWMEKR3.js} +21 -21
  118. package/dist/{install-cmd-4ID4VBH2.js → install-cmd-UXH2LGVA.js} +9 -9
  119. package/dist/{layout-G6K72TXK.js → layout-YVTZDKVU.js} +3 -3
  120. package/dist/{logs-DIA3NWC2.js → logs-22Y7QG42.js} +6 -6
  121. package/dist/loop-SVE6TL6G.js +90 -0
  122. package/dist/machine-RQIO5VRG.js +79 -0
  123. package/dist/{machine-skills-JLJJDXBS.js → machine-skills-6PJOJU5J.js} +3 -3
  124. package/dist/{mcp-install-cmd-OTAX7QP2.js → mcp-install-cmd-LJ7AYDDT.js} +3 -3
  125. package/dist/{mcp-serve-cmd-63KQEQYS.js → mcp-serve-cmd-34LDKQSR.js} +8 -8
  126. package/dist/{paths-KVMMJQ7T.js → paths-2KOZGV5U.js} +6 -6
  127. package/dist/{pending-2IE3VBAN.js → pending-RYWBDJCE.js} +7 -7
  128. package/dist/{pidfile-NCBBWZNH.js → pidfile-FQBXIHX7.js} +7 -7
  129. package/dist/{record-PQDJVKYV.js → record-7ENQ7Y5M.js} +7 -7
  130. package/dist/relay-JLU7RTFS.js +474 -0
  131. package/dist/{relay-protocol-PJ2HOP6B.js → relay-protocol-AEIZCA3K.js} +4 -4
  132. package/dist/{runner-agents-CEW4Z3FR.js → runner-agents-I5YLJY7G.js} +3 -3
  133. package/dist/{runner-env-23OLQBQZ.js → runner-env-GXY2VMNH.js} +13 -13
  134. package/dist/{runner-identity-IJKE4SRJ.js → runner-identity-MW53HCYG.js} +9 -9
  135. package/dist/{runner-key-4J4MHN3S.js → runner-key-GERK5EV3.js} +43 -43
  136. package/dist/{session-sender-HKNACIH5.js → session-sender-65X5PR7Q.js} +16 -16
  137. package/dist/{spec-cmd-4R7AYTBU.js → spec-cmd-3TNVJBN7.js} +14 -14
  138. package/dist/{starter-pack-6C7HPT4O.js → starter-pack-PLSMFXBU.js} +4 -4
  139. package/dist/{state-DPEWDXQN.js → state-EKXXOPA5.js} +7 -7
  140. package/dist/{status-GMVC666R.js → status-KGSQF55G.js} +43 -43
  141. package/dist/{sync-cmd-UMAENSGZ.js → sync-cmd-FNATZ5VL.js} +15 -15
  142. package/dist/update-steps-3LOJ377U.js +80 -0
  143. package/dist/{watch-RAUF223H.js → watch-FEBBRV22.js} +15 -15
  144. package/dist/{work-claim-cmd-A3ISXUFA.js → work-claim-cmd-2EPUH3KT.js} +19 -19
  145. package/dist/{work-cmd-U7YLMDZ7.js → work-cmd-V5A3MDXV.js} +13 -13
  146. package/dist/{work-comment-cmd-CMWMOWVG.js → work-comment-cmd-PUE47SUV.js} +15 -15
  147. package/dist/{work-demo-cmd-EKTJHIVM.js → work-demo-cmd-7Q3KW2OO.js} +13 -13
  148. package/dist/{work-logs-cmd-Z3QOFYTJ.js → work-logs-cmd-SQBJX6MC.js} +13 -13
  149. package/dist/{work-open-pr-cmd-NJXIX3QZ.js → work-open-pr-cmd-PNDF2CR5.js} +14 -14
  150. package/dist/{work-pr-cmd-JUV3SN7I.js → work-pr-cmd-U7WL7KYE.js} +13 -13
  151. package/dist/{work-proofs-cmd-MIDPIFTH.js → work-proofs-cmd-YHOM2NIH.js} +15 -15
  152. package/dist/{work-proofs-record-6FTMJDQG.js → work-proofs-record-CYIZ2RDH.js} +21 -21
  153. package/dist/{work-stop-cmd-Z7MYNR7R.js → work-stop-cmd-ENRSBWFT.js} +13 -13
  154. package/package.json +1 -1
  155. package/skill-pack/maintained/outerlayer-amend/SKILL.md +13 -13
  156. package/skill-pack/maintained/outerlayer-amend/references/failed-checks.md +35 -0
  157. package/skill-pack/maintained/outerlayer-build/SKILL.md +3 -1
  158. package/dist/caller-XETCC46J.js +0 -23
  159. package/dist/find-unit-337Y4QAC.js +0 -24
  160. package/dist/host-checks-OXB5J3KR.js +0 -79
  161. package/dist/init-V7X3KA7B.js +0 -79
  162. package/dist/loop-AWBFKDV7.js +0 -90
  163. package/dist/machine-BZPKYURG.js +0 -79
  164. package/dist/relay-QDB526DJ.js +0 -223
  165. package/dist/update-steps-GTXNCG3Z.js +0 -80
@@ -1,60 +1,60 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from 'node:module';
3
- import { itemsSentence, criteriaOf, hostItemsOf, loadCitationFinder, testFileMatcher, planCriteria, judgeGroups, failedItems, inCriteriaOrder, testsByCriterion, oneLineReason, criterionInputs, parseJudgeAnswer, judgedItems, MAX_TEST_FILE_BYTES } from './chunk-BO3NOGKE.js';
3
+ import { itemsSentence, criteriaOf, hostItemsOf, loadCitationFinder, testFileMatcher, planCriteria, judgeGroups, failedItems, inCriteriaOrder, testsByCriterion, oneLineReason, criterionInputs, parseJudgeAnswer, judgedItems, MAX_TEST_FILE_BYTES } from './chunk-ML3O3A3Q.js';
4
4
  import { sha256OfFile, downloadPinned, VoiceDownloadError } from './chunk-2PGI6RDE.js';
5
5
  import { zodProblem } from './chunk-I3LTIAOR.js';
6
- import { hasStoredCredential, storedCredentialVariables, storeAgentCredential, isAgentName, credentialFromStdin } from './chunk-AJC5Q2NY.js';
7
- import { upgradedStarterText } from './chunk-ERQLHUWU.js';
8
- import { HELPER_PATH, HELPER_RECORD, DOCKERD_LOG } from './chunk-YZRDJOOR.js';
9
- import { writeDockerClientConfig } from './chunk-ONOINHY4.js';
10
- import { senderPidfile } from './chunk-VWNQRD4I.js';
11
- import { installScrubContext } from './chunk-3DVCPRKE.js';
6
+ import { hasStoredCredential, storedCredentialVariables, storeAgentCredential, isAgentName, credentialFromStdin } from './chunk-LFBQL4AP.js';
7
+ import { upgradedStarterText } from './chunk-5QBTW367.js';
8
+ import { HELPER_PATH, HELPER_RECORD, DOCKERD_LOG } from './chunk-XDVLF6OT.js';
9
+ import { writeDockerClientConfig } from './chunk-G2ITKUX4.js';
10
+ import { senderPidfile } from './chunk-KMUERD5F.js';
11
+ import { installScrubContext } from './chunk-LRE4QIMD.js';
12
12
  import { readsJobState, READ_JOB_STATE_FORMATS, jobStateFormatOf } from './chunk-ZVB57WI6.js';
13
- import { runnerImageVersion } from './chunk-TAEDH2SU.js';
14
- import { claimCalls, spoolHomeFor, itemCalls, claimItem, leftByRunnerKey } from './chunk-ZLJXMXZP.js';
13
+ import { runnerImageVersion } from './chunk-76Y35TWH.js';
14
+ import { claimCalls, spoolHomeFor, itemCalls, claimItem, leftByRunnerKey } from './chunk-FBBI6K7D.js';
15
15
  import { receiveFiles } from './chunk-NN33FYXG.js';
16
- import { readDefaultBranchFiles, readDefaultBranchHead, buildRepositoryImage, fetchCommit, readBranchHead, diffBetween, prepareImageBuild, KEY_PREFIX, TAG_HOST, SHARED_OWNER, SHARED_NAME, universalBase, metadataFromLabels, writeRecord } from './chunk-WF2NXBOM.js';
17
- import { FETCHED_DIR, toolsDockerfile, FETCHED_FFMPEG, FETCHED_GH, FETCHED_TINI, FETCHED_HEADLESS_SHELL, FETCHED_PLAYWRIGHT_FFMPEG, FETCHED_VOICE_DIR } from './chunk-YKWOVYVN.js';
16
+ import { readDefaultBranchFiles, readDefaultBranchHead, buildRepositoryImage, fetchCommit, readBranchHead, diffBetween, prepareImageBuild, KEY_PREFIX, TAG_HOST, SHARED_OWNER, SHARED_NAME, universalBase, metadataFromLabels, writeRecord } from './chunk-5BDYRHZZ.js';
17
+ import { FETCHED_DIR, toolsDockerfile, FETCHED_FFMPEG, FETCHED_GH, FETCHED_TINI, FETCHED_HEADLESS_SHELL, FETCHED_PLAYWRIGHT_FFMPEG, FETCHED_VOICE_DIR } from './chunk-YSIVKYLW.js';
18
18
  import { isSameProcess, startTimeOf } from './chunk-JBJTC3UU.js';
19
19
  import { currentCliBuild } from './chunk-OGFGZQA3.js';
20
- import { vmExecArgs, runExec, execCapture, waitForAgent } from './chunk-HG2ZG6ZU.js';
21
- import { socketPathProblem, vsockLinks, linkVsockSockets, GUEST_CID, LEASE_LINK } from './chunk-U5EE7PGC.js';
22
- import { describeCallFailure, shortClaim, retrySend, commandWithShim, logStamp, createRunnerLog, formatDuration, removeKeptContext, formatClock, stageGovernedContext, keptContextTree, removeStagedContext, WORKFLOW_PERMISSION_REASON, refusalCode, resolveGoverningSource, prefetchGovernedContext, controlPlaneTokenFailure, keepStagedContext, pinnedSourceOf, shimScript } from './chunk-3XWZKL2P.js';
23
- import { postJson, WorkCommandError, getJson, isSignatureRefusal } from './chunk-JTDMSQMI.js';
24
- import { runnerCredentialProblem, builtinKind, keyRunnerFactory, optionalEgress, isBuiltinContainer, isBuiltinVm, egressSummary, DEFAULT_WORKSPACE_KEEP_DAYS, DEFAULT_CHECK_TIME_LIMIT_MINUTES, DEFAULT_SETUP_MINUTES, allowHostProblem, systemClock, emptyEgressCounts, hostAllowed, imageBuildOf, DEFAULT_SAVED_STATE_MAX_BYTES } from './chunk-VNT2IRLM.js';
25
- import { formatBytes, volumeBytes, allocatedBytes, DEFAULT_BUILD_DISK, DEFAULT_CACHE_DISK, freeBytes } from './chunk-MPE4NOKD.js';
26
- import { firstLine, writeJobFile, readJobFile, spawnRun, RUNNER_LABEL, BUILD_LABEL, said, NETWORK_HELPER_MEMORY, createDockerHost, builderSpec, containerExecArgs, childEnvironment, readDu, withAnswerProtocol, MAX_REPORT_BYTES, parseSize, runnerLabelValue, readJobFileChecked, NETWORK_READY_FILE, networkHelperName, prepareRunArgs, containerRunArgs, judgeCommand, JUDGE_TREE, WORKSPACE_LABEL, homeCopyRunArgs, networkHelperRunArgs, JUDGE_MAX_TURNS, JUDGE_DIR, hashJudgeProgram, identityScript, identityArgs, parseIdentity, mountableHome, homeCopyScript, homeCopyArgs, COMMAND_DIR, judgeProgramRecord, MAX_ITEMS_BYTES, JUDGE_ITEMS, JUDGE_REPORT, identityRunArgs, SAVED_STATE_LABEL } from './chunk-3FAJMXBA.js';
27
- import { universalImagePending, RecipeError, writeSanitizedRecipe, classifyProperties, DOCKER_FEATURE } from './chunk-FER7JJ3S.js';
20
+ import { vmExecArgs, runExec, execCapture, waitForAgent } from './chunk-7ATHSAAT.js';
21
+ import { socketPathProblem, vsockLinks, linkVsockSockets, GUEST_CID, LEASE_LINK } from './chunk-E2ZWGLNZ.js';
22
+ import { describeCallFailure, shortClaim, retrySend, resolveGoverningSource, prefetchGovernedContext, refusalCode, commandWithShim, logStamp, createRunnerLog, formatDuration, removeKeptContext, formatClock, stageGovernedContext, keptContextTree, removeStagedContext, keepStagedContext, pinnedSourceOf, WORKFLOW_PERMISSION_REASON, shimScript, controlPlaneTokenFailure } from './chunk-JKYCEXZX.js';
23
+ import { postJson, WorkCommandError, getJson, isSignatureRefusal } from './chunk-RFBJKK2L.js';
24
+ import { runnerCredentialProblem, builtinKind, keyRunnerFactory, sandboxSizeOf, networkOf, sandboxTimeLimitMinutes, DEFAULT_SETUP_MINUTES, optionalEgress, isBuiltinContainer, isBuiltinVm, isBuiltinSandbox, egressSummary, DEFAULT_WORKSPACE_KEEP_DAYS, DEFAULT_CHECK_TIME_LIMIT_MINUTES, allowHostProblem, systemClock, emptyEgressCounts, hostAllowed, imageBuildOf, DEFAULT_SAVED_STATE_MAX_BYTES } from './chunk-UF3YTRGU.js';
25
+ import { formatBytes, volumeBytes, allocatedBytes, DEFAULT_BUILD_DISK, DEFAULT_CACHE_DISK, freeBytes } from './chunk-G2EWER4K.js';
26
+ import { runnerLabelValue, said, RUNNER_LABEL, BUILD_LABEL, prepareRunArgs, containerRunArgs, firstLine, writeJobFile, readJobFile, spawnRun, NETWORK_HELPER_MEMORY, createDockerHost, builderSpec, mountableHome, homeCopyRunArgs, containerExecArgs, childEnvironment, readDu, identityRunArgs, parseIdentity, withAnswerProtocol, MAX_REPORT_BYTES, parseSize, readJobFileChecked, NETWORK_READY_FILE, networkHelperName, judgeCommand, JUDGE_TREE, WORKSPACE_LABEL, networkHelperRunArgs, JUDGE_MAX_TURNS, JUDGE_DIR, hashJudgeProgram, identityScript, identityArgs, homeCopyScript, homeCopyArgs, COMMAND_DIR, judgeProgramRecord, MAX_ITEMS_BYTES, JUDGE_ITEMS, JUDGE_REPORT, SAVED_STATE_LABEL } from './chunk-6BPCEGJL.js';
27
+ import { universalImagePending, RecipeError, writeSanitizedRecipe, classifyProperties, DOCKER_FEATURE } from './chunk-ZPCUXCQX.js';
28
28
  import { sanitizeTerminal, planArtifactUpload } from './chunk-IXB2IIEW.js';
29
- import { sharedSkillNames, skillConflictMessage } from './chunk-QWDGHEQL.js';
29
+ import { sharedSkillNames, skillConflictMessage } from './chunk-GM3H4ZHG.js';
30
30
  import { readCloudConfig } from './chunk-HWVMRETT.js';
31
- import { signerFor } from './chunk-EFAOERZH.js';
32
- import { vmAssetsDir, RUNNER_DIR_MODE, RUNNER_FILE_MODE, runnerDir, workspacesDir, jobsDir, storeScopes, spoolDir, orgStoreIn, rootfsDir, imagesDir, sessionsDir, builderCacheDiskPath, buildsDir, buildDir, ghConfigDir, runnerDirOfBuild, mirrorDir, orgHomeDir, jobConsolePath, vsockPath, builderConsolePath, rootfsPathFor, diskTemplatesDir, deliveryDir, SHIM_DIR } from './chunk-5VAXNAOD.js';
33
- import { BUILD_HOME, JOB_MOUNT, heldBuildAuthority, IMAGE_BUNDLES, writeTrustFiles, buildEnvironment, trustEnvironment, CHECKOUT_DIR, parseIsolation, containerLocalAddress, destinationEnvironment, withHooksPath, startBuildServices, headerVariables, authorEnvironment, sharedUserEnvironment, withTunnelRecord, commitIdentityRecord, repositoriesOf, RELAY_PORT, repositoryPath, lifecycleWorkdir, CHECK_ITEMS_FILE, parseProxied, readBundleScript, applyTrust, STAND_IN, proxyEnvironment, dropBuildAuthority, hostKeyOf, buildAuthorityFor, checkEnvironment, withMiseVariables, checkoutPath, primaryOf, variablesFor, carried6to4, classifyAddress, EVAL_INPUT_DIR, isMiseVariableAllowed, variableForPath, droppedRequestHeaders, hasDotDotSegment, routeNameOf } from './chunk-OUHM6U6Z.js';
34
- import { agentCredential, RUNNER_WORDED_REASONS, UNKNOWN_TRACKING_REASON, UNKNOWN_TRANSPORT_REASON, RELAY_USER, currentAgentCredential, removedAgentCredentialValues, managedAgentCredential, realFdStorePort, builtInNames, MAX_MALFORMED_SESSIONS, MALFORMED_REASON, JOIN_WAIT_MS, MAX_OPEN_STREAMS, STREAM_RESET_RATE, STREAM_RESET_BURST, STREAM_WINDOW, SESSION_WINDOW, targetOfPath, AGENT_CREDENTIAL_MISSING, fdName, RELAY_ID, DOCKER_DESKTOP_REASON } from './chunk-CGXYPLK3.js';
31
+ import { signerFor } from './chunk-TOVSIUEJ.js';
32
+ import { vmAssetsDir, RUNNER_DIR_MODE, RUNNER_FILE_MODE, runnerDir, buildDir, ghConfigDir, workspacesDir, jobsDir, storeScopes, spoolDir, orgStoreIn, rootfsDir, imagesDir, sessionsDir, builderCacheDiskPath, buildsDir, runnerDirOfBuild, mirrorDir, orgHomeDir, deliveryDir, jobConsolePath, vsockPath, SHIM_DIR, builderConsolePath, rootfsPathFor, diskTemplatesDir } from './chunk-YZ5M7S7U.js';
33
+ import { BUILD_HOME, repositoriesOf, primaryOf, SandboxError, describeSandboxError, buildEnvironment, CHECKOUT_DIR, JOB_MOUNT, heldBuildAuthority, IMAGE_BUNDLES, writeTrustFiles, trustEnvironment, parseIsolation, containerLocalAddress, destinationEnvironment, withHooksPath, startBuildServices, headerVariables, authorEnvironment, sharedUserEnvironment, withTunnelRecord, commitIdentityRecord, RELAY_PORT, repositoryPath, lifecycleWorkdir, CHECK_ITEMS_FILE, parseProxied, toolProxyEnvironment, readBundleScript, applyTrust, STAND_IN, proxyEnvironment, dropBuildAuthority, sandboxSettingsFrom, createSandboxClient, hostKeyOf, buildAuthorityFor, checkEnvironment, withMiseVariables, checkoutPath, variablesFor, carried6to4, classifyAddress, EVAL_INPUT_DIR, isMiseVariableAllowed, variableForPath, droppedRequestHeaders, hasDotDotSegment, routeNameOf } from './chunk-FCU7WSCV.js';
34
+ import { agentCredential, builtInNames, RUNNER_WORDED_REASONS, UNKNOWN_TRACKING_REASON, UNKNOWN_TRANSPORT_REASON, RELAY_USER, MAX_MALFORMED_SESSIONS, MALFORMED_REASON, JOIN_WAIT_MS, currentAgentCredential, removedAgentCredentialValues, managedAgentCredential, realFdStorePort, RELAY_ID, MAX_OPEN_STREAMS, STREAM_RESET_RATE, STREAM_RESET_BURST, STREAM_WINDOW, SESSION_WINDOW, targetOfPath, AGENT_CREDENTIAL_MISSING, fdName, DOCKER_DESKTOP_REASON } from './chunk-HTQFAHXD.js';
35
35
  import { versionAtLeast } from './chunk-SF2TBJBP.js';
36
- import { jobAgent, firecrackerArch, MICROVM_ARCHES, FIRECRACKER_VERSION, hostHelperPinned, builderDiskPinned, guestAssetsPinned, runnerAgentNamed, credentialForms, orList, credentialShapes, agentCommands, defaultCommandLine, credentialAgent, GUEST_HELPER_SHA256, GUEST_ASSETS_BASE_URL, GUEST_KERNEL_SHA256, JAILER_BINARY_SHA256, FIRECRACKER_BINARY_SHA256, FIRECRACKER_SHA256, GUEST_ASSETS_VERSION, BUILDER_DISK_VERSION, credentialHandOffKey, strippedVariables, runnerAgents, judgeAgent, networkHelperPinned, NETWORK_HELPER_SHA256, universalImagePinned, UNIVERSAL_IMAGE, FFMPEG_STATIC, FFMPEG_BUILD_TAG, GH_SHA256, GH_VERSION, TINI_SHA256, TINI_VERSION, HEADLESS_SHELL, HEADLESS_SHELL_BASE_URL, PLAYWRIGHT_FFMPEG, PLAYWRIGHT_FFMPEG_BASE_URL, VOICE_PACK_FILES, BUILDER_DISK_SHA256, BUILDER_DISK_BASE_URL, DEFAULT_BASE_IMAGE, agentVersionOf } from './chunk-RZ6WJTUP.js';
37
- import { sessionFolderIn, legacyAgent, defaultAgents, parsePolicy, AGENTS_SKILLS_BASE, OUTERLAYER_SKILLS_BASE, orderSessions, extractFacts, sessionsToTimeline, resolvePackRoot } from './chunk-AVEF3T6Y.js';
36
+ import { jobAgent, firecrackerArch, MICROVM_ARCHES, FIRECRACKER_VERSION, hostHelperPinned, builderDiskPinned, guestAssetsPinned, runnerAgentNamed, credentialForms, orList, credentialShapes, agentCommands, defaultCommandLine, credentialAgent, agentVersionOf, GUEST_HELPER_SHA256, GUEST_ASSETS_BASE_URL, GUEST_KERNEL_SHA256, JAILER_BINARY_SHA256, FIRECRACKER_BINARY_SHA256, FIRECRACKER_SHA256, GUEST_ASSETS_VERSION, BUILDER_DISK_VERSION, credentialHandOffKey, strippedVariables, runnerAgents, judgeAgent, networkHelperPinned, NETWORK_HELPER_SHA256, universalImagePinned, UNIVERSAL_IMAGE, FFMPEG_STATIC, FFMPEG_BUILD_TAG, GH_SHA256, GH_VERSION, TINI_SHA256, TINI_VERSION, HEADLESS_SHELL, HEADLESS_SHELL_BASE_URL, PLAYWRIGHT_FFMPEG, PLAYWRIGHT_FFMPEG_BASE_URL, VOICE_PACK_FILES, BUILDER_DISK_SHA256, BUILDER_DISK_BASE_URL, DEFAULT_BASE_IMAGE } from './chunk-TDUBZ4FR.js';
37
+ import { sessionFolderIn, legacyAgent, defaultAgents, parsePolicy, AGENTS_SKILLS_BASE, OUTERLAYER_SKILLS_BASE, orderSessions, extractFacts, sessionsToTimeline, resolvePackRoot } from './chunk-GM4TY5H2.js';
38
38
  import { MAINTAINED_SKILLS } from './chunk-CDDED64E.js';
39
39
  import { resolveVersion } from './chunk-RA3O54FC.js';
40
40
  import { homeFromEnv } from './chunk-352DHUTP.js';
41
- import { scrubText, MIN_SCRUBBED_LITERAL, setCustomScrubbers, setLocalIdentity, setRepoRoot, forkFor, scrubDeep } from './chunk-5R5FEPLH.js';
41
+ import { scrubText, MIN_SCRUBBED_LITERAL, setCustomScrubbers, setLocalIdentity, setRepoRoot, forkFor, scrubDeep } from './chunk-H2L5NB5U.js';
42
42
  import { CheckItemsSchema, CHECK_ITEM_HREF_MAX_LENGTH, downconvertSession } from './chunk-YXXJBHHF.js';
43
43
  import { randomUUID, randomBytes, createHash } from 'crypto';
44
- import { rmSync, mkdirSync, existsSync, readFileSync, mkdtempSync, statSync, appendFileSync, writeFileSync, readdirSync, accessSync, constants, openSync, closeSync, renameSync, rmdirSync, createReadStream, lstatSync, unlinkSync, chmodSync, realpathSync, writeSync, truncateSync, cpSync, fstatSync, readSync, createWriteStream, copyFileSync, linkSync } from 'fs';
44
+ import { rmSync, mkdirSync, existsSync, readFileSync, mkdtempSync, statSync, appendFileSync, writeFileSync, readdirSync, accessSync, constants, openSync, closeSync, renameSync, rmdirSync, chmodSync, createReadStream, lstatSync, unlinkSync, realpathSync, writeSync, truncateSync, cpSync, fstatSync, readSync, createWriteStream, copyFileSync, linkSync } from 'fs';
45
45
  import { join, dirname, isAbsolute, delimiter, basename, sep, relative, resolve } from 'path';
46
- import { Readable, PassThrough, Duplex, Transform } from 'stream';
46
+ import { PassThrough, Writable, Duplex, Readable, Transform } from 'stream';
47
47
  import { spawn, spawnSync } from 'child_process';
48
48
  import { createServer, createConnection, connect, isIP } from 'net';
49
49
  import { availableParallelism, networkInterfaces, tmpdir } from 'os';
50
+ import { gzipSync, createGunzip, gunzipSync, constants as constants$1 } from 'zlib';
51
+ import http2 from 'http2';
50
52
  import { once } from 'events';
51
53
  import { createServer as createServer$1, request, Agent } from 'http';
52
54
  import { lookup as lookup$1 } from 'dns/promises';
53
55
  import { TLSSocket, createSecureContext, connect as connect$1 } from 'tls';
54
- import http2 from 'http2';
55
56
  import { request as request$1 } from 'https';
56
57
  import { pipeline, finished } from 'stream/promises';
57
- import { createGunzip, gunzipSync, constants as constants$1 } from 'zlib';
58
58
 
59
59
  createRequire(import.meta.url);
60
60
 
@@ -335,6 +335,23 @@ async function restoreSession(input) {
335
335
  return { ok: false, reason: describeCallFailure(err) };
336
336
  }
337
337
  }
338
+ var NAMES_A_FAILURE = /\b(error|failed|fatal|denied|refused|cannot|could not|unable|not found|timed out|timeout)\b/i;
339
+ function failedStepLine(log) {
340
+ const lines = log.split(/\r?\n/);
341
+ const end = lines.findLastIndex((line2) => /^#\d+ ERROR: /.test(line2));
342
+ if (end === -1) return void 0;
343
+ const step = /^#(\d+) /.exec(lines[end])[1];
344
+ const prefix = new RegExp(`^#${step} \\d+(?:\\.\\d+)? (.*)$`);
345
+ const output = lines.map((line2) => (prefix.exec(line2)?.[1] ?? "").trim()).filter((line2) => line2 !== "");
346
+ return output.filter((line2) => !line2.startsWith("at ") && NAMES_A_FAILURE.test(line2)).at(-1) ?? output.at(-1);
347
+ }
348
+ function failedStepLineOf(path) {
349
+ try {
350
+ return failedStepLine(readFileSync(path ?? "", "utf8"));
351
+ } catch {
352
+ return void 0;
353
+ }
354
+ }
338
355
 
339
356
  // src/runner/managed-claude-key.ts
340
357
  var FETCH_RETRY_WINDOW_MS = 3e4;
@@ -1395,6 +1412,25 @@ function createMicroVmPorts(over = {}) {
1395
1412
  };
1396
1413
  }
1397
1414
 
1415
+ // src/runner/sandbox/ports.ts
1416
+ function createSandboxPorts(opts, hostEnv) {
1417
+ let made;
1418
+ return {
1419
+ client: opts?.client ?? (() => {
1420
+ if (made !== void 0) return made;
1421
+ const found = sandboxSettingsFrom(hostEnv);
1422
+ if (!found.ok) throw new SandboxError(`${found.missing.join(", ")} not set in the runner's environment`, 0, "no_api_key");
1423
+ made = createSandboxClient(found.settings);
1424
+ return made;
1425
+ }),
1426
+ ...opts?.webSocket === void 0 ? {} : { webSocket: opts.webSocket },
1427
+ sandboxes: opts?.sandboxes ?? /* @__PURE__ */ new Map(),
1428
+ creating: opts?.creating ?? /* @__PURE__ */ new Set(),
1429
+ joinSecrets: opts?.joinSecrets ?? /* @__PURE__ */ new Map(),
1430
+ sleep: opts?.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)))
1431
+ };
1432
+ }
1433
+
1398
1434
  // src/runner/verdict.ts
1399
1435
  var VERDICT_SETTLE_MS = 5 * 6e4;
1400
1436
  var VERDICT_READ_EVERY_MS = 3e4;
@@ -2273,6 +2309,7 @@ async function decideHostBuildSkill(input, agents = defaultAgents(), job) {
2273
2309
  }
2274
2310
  var BranchPrepareError = class extends Error {
2275
2311
  };
2312
+ var KEPT_REF_PREFIX = "refs/outerlayer/kept/";
2276
2313
  var OWN_PREFIX = "outerlayer/";
2277
2314
  var GIT_TIMEOUT_MS = 12e4;
2278
2315
  var REPO_BINDING_GIT_VARS = new Set(
@@ -2332,13 +2369,30 @@ async function prepareBranch(opts) {
2332
2369
  } else {
2333
2370
  throw new BranchPrepareError(`the pull request's branch ${branch} is not on the remote`);
2334
2371
  }
2372
+ const kept = await keepUnpushedCommits(git2, workdir, branch);
2335
2373
  await mustGit(git2, workdir, `checking out ${branch}`, ["checkout", "--quiet", "-B", branch, start]);
2336
2374
  return {
2337
2375
  branch,
2376
+ ...kept === void 0 ? {} : { kept },
2338
2377
  head: await mustGit(git2, workdir, "reading the checked-out commit", ["rev-parse", "HEAD"]),
2339
2378
  startCommit: await mustGit(git2, workdir, `reading the commit of ${defaultBranch}`, ["rev-parse", `origin/${defaultBranch}`])
2340
2379
  };
2341
2380
  }
2381
+ async function keepUnpushedCommits(git2, workdir, branch) {
2382
+ const local = await git2(workdir, ["rev-parse", "--quiet", "--verify", `refs/heads/${branch}^{commit}`]);
2383
+ if (local.status !== 0) return void 0;
2384
+ const head = local.stdout;
2385
+ const counted = await mustGit(git2, workdir, `counting the commits of ${branch} that no remote branch has`, ["rev-list", "--count", head, "--not", "--remotes"]);
2386
+ const count = Number(counted);
2387
+ if (!(count > 0)) return void 0;
2388
+ const ref = `${KEPT_REF_PREFIX}${head}`;
2389
+ await mustGit(git2, workdir, `keeping the unpushed commits of ${branch}`, ["update-ref", ref, head]);
2390
+ return { count, head, ref };
2391
+ }
2392
+ function keptCommitsLine(branch, kept) {
2393
+ const commits = kept.count === 1 ? "1 commit" : `${kept.count} commits`;
2394
+ return `${branch} at ${kept.head.slice(0, 8)} has ${commits} that no remote branch has. The build does not start from ${kept.count === 1 ? "it" : "them"}, and ${kept.ref} keeps the old head`;
2395
+ }
2342
2396
  async function isMerged(git2, workdir, branch, defaultBranch) {
2343
2397
  const result = await git2(workdir, ["merge-base", "--is-ancestor", `origin/${branch}`, `origin/${defaultBranch}`]);
2344
2398
  if (result.status === 0) return true;
@@ -2800,6 +2854,7 @@ async function checkOut(input, entry, restored, fromItemDisk) {
2800
2854
  return { status: ran.status, stdout: ran.stdout.trim(), stderr: ran.stderr.trim() };
2801
2855
  }
2802
2856
  });
2857
+ if (prepared.kept !== void 0) log.line(`${tag} ${entry.primary ? "" : `${entry.repository}: `}${keptCommitsLine(prepared.branch, prepared.kept)}`);
2803
2858
  log.line(`${tag} ${entry.primary ? "" : `${entry.repository} `}on ${prepared.branch} at ${prepared.head.slice(0, 8)}`);
2804
2859
  return { ok: true, head: prepared.head, startCommit: prepared.startCommit };
2805
2860
  } catch (err) {
@@ -2959,158 +3014,1212 @@ async function runBuildSteps(input) {
2959
3014
  ...miseVariables === void 0 ? {} : { miseVariables }
2960
3015
  };
2961
3016
  }
2962
- function savedStatesDir(runnerDirPath) {
2963
- return join(runnerDirPath, "saved-states");
3017
+ var DeliveryFailure = class extends Error {
3018
+ };
3019
+ var BLOCK2 = 512;
3020
+ var DELIVERY_TIMEOUT_MS = 5 * 6e4;
3021
+ var RECEIVE_ARGV = ["/opt/outerlayer/bin/node", "/opt/outerlayer/cli/dist/index.js", "receive-files"];
3022
+ var REASON_LINE_MAX = 240;
3023
+ var STEPS = {
3024
+ gh: "the build's gh configuration",
3025
+ "git-hooks": "the commit hooks",
3026
+ context: "the staged context",
3027
+ "eval-input": "the checks' input",
3028
+ inbox: "the comments for the agent"
3029
+ };
3030
+ function field(header, at, length, text2) {
3031
+ header.write(text2, at, length, "latin1");
2964
3032
  }
2965
- function writeRecord2(dir, record) {
2966
- mkdirSync(dir, { recursive: true, mode: RUNNER_DIR_MODE });
2967
- const target2 = join(dir, `${record.id}.json`);
2968
- const partial = `${target2}.partial`;
2969
- writeFileSync(partial, `${JSON.stringify(record, null, 2)}
2970
- `, { mode: RUNNER_FILE_MODE });
2971
- renameSync(partial, target2);
3033
+ function octalField(header, at, length, value) {
3034
+ field(header, at, length, `${value.toString(8).padStart(length - 1, "0")}\0`);
2972
3035
  }
2973
- function isRecord(value) {
2974
- if (typeof value !== "object" || value === null) return false;
2975
- const r = value;
2976
- return typeof r.id === "string" && (r.kind === "volume" || r.kind === "tar" || r.kind === "disk") && typeof r.savedAt === "string" && Number.isFinite(Date.parse(r.savedAt)) && typeof r.bytes === "number" && typeof r.baseKey === "string" && typeof r.key === "string" && typeof r.fileHashes === "object" && r.fileHashes !== null && typeof r.complete === "boolean";
3036
+ function tarHeader2(name, type, mode, size) {
3037
+ const header = Buffer.alloc(BLOCK2);
3038
+ header.write(name, 0, 100, "utf8");
3039
+ octalField(header, 100, 8, mode);
3040
+ octalField(header, 108, 8, 0);
3041
+ octalField(header, 116, 8, 0);
3042
+ octalField(header, 124, 12, size);
3043
+ octalField(header, 136, 12, 0);
3044
+ field(header, 148, 8, " ");
3045
+ header.write(type, 156, 1, "latin1");
3046
+ field(header, 257, 6, "ustar\0");
3047
+ field(header, 263, 2, "00");
3048
+ let sum = 0;
3049
+ for (const byte of header) sum += byte;
3050
+ field(header, 148, 8, `${sum.toString(8).padStart(6, "0")}\0 `);
3051
+ return header;
2977
3052
  }
2978
- function readRecords(dir) {
2979
- let names;
2980
- try {
2981
- names = readdirSync(dir);
2982
- } catch {
2983
- return [];
2984
- }
2985
- const records = [];
2986
- for (const name of names) {
2987
- if (!name.endsWith(".json")) continue;
2988
- try {
2989
- const parsed = JSON.parse(readFileSync(join(dir, name), "utf8"));
2990
- if (isRecord(parsed)) records.push(parsed);
2991
- } catch {
2992
- }
2993
- }
2994
- return records;
3053
+ function padded(data) {
3054
+ const rest = data.length % BLOCK2;
3055
+ return rest === 0 ? data : Buffer.concat([data, Buffer.alloc(BLOCK2 - rest)]);
2995
3056
  }
2996
- function deleteRecord(dir, id) {
2997
- rmSync(join(dir, `${id}.json`), { force: true });
3057
+ function paxRecord(key, value) {
3058
+ const body = Buffer.from(` ${key}=${value}
3059
+ `, "utf8");
3060
+ let length = body.length + 1;
3061
+ while (String(length).length + body.length !== length) length = String(length).length + body.length;
3062
+ return Buffer.concat([Buffer.from(String(length), "latin1"), body]);
2998
3063
  }
2999
-
3000
- // src/runner/saved-state/remove.ts
3001
- async function removeSavedState(record, deps) {
3002
- if (record.kind === "volume" && record.volume !== void 0) {
3003
- const result = await deps.removeVolume(record.volume);
3004
- if (result !== void 0 && result.status !== 0) {
3005
- const line2 = (result.stderr ?? "").trim().split("\n").filter((text2) => text2.trim() !== "").at(-1);
3006
- throw new Error(`Docker could not remove volume ${record.volume} (exit ${result.status}${line2 === void 0 ? "" : `: ${line2}`})`);
3064
+ function packTar(entries) {
3065
+ const blocks = [];
3066
+ for (const entry of entries) {
3067
+ const data = entry.type === "file" ? entry.data ?? Buffer.alloc(0) : Buffer.alloc(0);
3068
+ const name = entry.type === "dir" && !entry.path.endsWith("/") ? `${entry.path}/` : entry.path;
3069
+ if (Buffer.byteLength(name, "utf8") > 100) {
3070
+ const record = paxRecord("path", name);
3071
+ blocks.push(tarHeader2("PaxHeader", "x", 420, record.length), padded(record));
3007
3072
  }
3073
+ blocks.push(tarHeader2(name, entry.type === "dir" ? "5" : "0", entry.mode, data.length), padded(data));
3008
3074
  }
3009
- if ((record.kind === "tar" || record.kind === "disk") && record.path !== void 0) {
3010
- rmSync(`${record.path}.partial`, { force: true });
3011
- rmSync(record.path, { force: true });
3012
- }
3013
- deleteRecord(deps.dir, record.id);
3075
+ blocks.push(Buffer.alloc(BLOCK2 * 2));
3076
+ return Buffer.concat(blocks);
3014
3077
  }
3015
- async function removeOldestUntil(input) {
3016
- const removed = [];
3017
- for (const record of oldestFirst(input.records)) {
3018
- if (input.enough()) break;
3019
- try {
3020
- await removeSavedState(record, input.deps);
3021
- removed.push(record);
3022
- input.log(`removed saved state ${record.id} from ${record.savedAt}`);
3023
- } catch (err) {
3024
- input.log(`could not remove saved state ${record.id}: ${describeCallFailure(err)}`);
3025
- }
3026
- }
3027
- return removed;
3078
+ function fileMode(hostMode) {
3079
+ return 292 | hostMode & 128 | ((hostMode & 73) === 0 ? 0 : 73);
3028
3080
  }
3029
- async function removeSuperseded(input) {
3030
- for (const old of input.records.filter((record) => record.complete && record.key === input.made.key && record.id !== input.made.id && Date.parse(record.savedAt) < Date.parse(input.made.savedAt))) {
3031
- try {
3032
- await removeSavedState(old, input.deps);
3033
- input.log(`removed saved state ${old.id}, saved state ${input.made.id} replaces it`);
3034
- } catch (err) {
3035
- input.log(`could not remove saved state ${old.id}: ${describeCallFailure(err)}`);
3081
+ function packFolder(dir, options = {}) {
3082
+ const entries = options.rootMode === void 0 ? [] : [{ path: "./", type: "dir", mode: options.rootMode }];
3083
+ const walk = (current, prefix) => {
3084
+ for (const name of readdirSync(current).sort()) {
3085
+ const path = join(current, name);
3086
+ const stat = lstatSync(path);
3087
+ const rel = prefix === "" ? name : `${prefix}/${name}`;
3088
+ if (stat.isDirectory()) {
3089
+ entries.push({ path: rel, type: "dir", mode: options.dirModes?.[rel] ?? 493 });
3090
+ walk(path, rel);
3091
+ } else if (stat.isFile()) {
3092
+ entries.push({ path: rel, type: "file", mode: fileMode(stat.mode), data: readFileSync(path) });
3093
+ }
3036
3094
  }
3037
- }
3038
- }
3039
-
3040
- // src/runner/saved-state/plan.ts
3041
- function savedStateBase(report) {
3042
- const digest = report.recipe === "default" ? report.base?.digest : void 0;
3043
- return digest === void 0 ? void 0 : { digest };
3095
+ };
3096
+ walk(dir, "");
3097
+ return packTar(entries);
3044
3098
  }
3045
- function savedStateMaxOf(config) {
3046
- return config.housekeeping?.savedStateMax ?? DEFAULT_SAVED_STATE_MAX_BYTES;
3099
+ function scrubDelivery(text2, secrets) {
3100
+ let out = text2.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, "").replace(/[\u0000-\u001f\u007f-\u009f]/g, " ");
3101
+ for (const secret of secrets()) if (secret !== "") out = out.split(secret).join("[redacted]");
3102
+ out = out.replace(/\b(?:gh[pousr]_|github_pat_)[A-Za-z0-9_]+/g, "[redacted]");
3103
+ out = out.trim();
3104
+ return out.length > REASON_LINE_MAX ? `${out.slice(0, REASON_LINE_MAX)}...` : out;
3047
3105
  }
3048
- async function planSavedState(input) {
3049
- const { config, runtime, log } = input;
3050
- const refused2 = savingRefusedBecause({ universalImage: input.base !== void 0, fleet: config.fleet === true, savedStateMax: savedStateMaxOf(config) });
3051
- if (refused2 !== void 0 || input.base === void 0) {
3052
- const why = refused2 ?? "its image comes from a devcontainer file";
3053
- log(`this build saves no state: ${why}`);
3054
- return { keyCommits: {}, noSave: why };
3055
- }
3056
- const root = runnerDir(config.configPath);
3057
- const repositories = [];
3058
- const keyCommits = {};
3059
- for (const entry of input.repositories) {
3060
- let token;
3061
- try {
3062
- token = entry.primary ? await input.tokens.token("read") : await input.tokens.token("read", entry.repository);
3063
- } catch (err) {
3064
- return unread(`the read token for ${entry.repository} could not be had: ${describeCallFailure(err)}`, log);
3065
- }
3066
- const [owner = "", name = ""] = entry.repository.split("/");
3067
- const read = await runtime.readKeyFiles({
3068
- remote: runtime.remoteFor?.(entry.repository) ?? `${runtime.github.gitUrl}/${entry.repository}.git`,
3069
- dir: join(root, "key-files", owner, name),
3070
- paths: keyFilePaths(),
3071
- token
3072
- });
3073
- if (!read.ok) return unread(read.reason, log);
3074
- keyCommits[entry.repository] = read.commit;
3075
- repositories.push({ repository: entry.repository, commit: read.commit, files: read.files });
3106
+ async function deliverTar(runtime, state, input) {
3107
+ try {
3108
+ const result = await runtime.host.exec(
3109
+ {
3110
+ container: state.container,
3111
+ user: RELAY_USER,
3112
+ env: { literals: {}, passed: {} },
3113
+ argv: [...RECEIVE_ARGV, "--into", input.into, ...input.replace === true ? ["--replace"] : []],
3114
+ stdin: input.tar
3115
+ },
3116
+ { timeoutMs: DELIVERY_TIMEOUT_MS }
3117
+ );
3118
+ if (result.status === 0) return { ok: true };
3119
+ const line2 = scrubDelivery(result.stderr.trim().split("\n")[0] ?? "", input.secrets);
3120
+ return { ok: false, reason: `${input.step} could not be delivered (exit ${result.status})${line2 === "" ? "" : `: ${line2}`}` };
3121
+ } catch (err) {
3122
+ return { ok: false, reason: `${input.step} could not be delivered: ${scrubDelivery(describeCallFailure(err), input.secrets)}` };
3076
3123
  }
3077
- const key = stateKey({
3078
- factory: keyRunnerFactory(config),
3079
- repositories,
3080
- imageDigest: input.base.digest,
3081
- diskBytes: input.diskBytes
3082
- });
3083
- const found = lookup(readRecords(savedStatesDir(root)), key, input.now.getTime());
3084
- if (found.kind !== "none" && found.record.kind === "tar") {
3124
+ }
3125
+ async function deliverJobFiles(runtime, state, parts, secrets) {
3126
+ for (const part of parts) {
3127
+ const dir = join(state.buildDir, part === "eval-input" ? EVAL_INPUT_NAME : part);
3128
+ if (!existsSync(dir)) continue;
3129
+ let tar;
3085
3130
  try {
3086
- await removeSavedState(found.record, { dir: savedStatesDir(root), removeVolume: async () => void 0 });
3087
- log(`saved state ${found.record.id} is a tar file, which this runner no longer restores; removed it; starting from a fresh disk`);
3131
+ tar = packFolder(dir);
3088
3132
  } catch (err) {
3089
- log(`saved state ${found.record.id} is a tar file, which this runner no longer restores, and it could not be removed: ${describeCallFailure(err)}; starting from a fresh disk`);
3133
+ return { ok: false, reason: `${STEPS[part]} could not be read on the host: ${scrubDelivery(describeCallFailure(err), secrets)}` };
3090
3134
  }
3091
- return { key, keyCommits };
3092
- }
3093
- if (found.kind === "usable" && input.allowRestore) {
3094
- log(`starting from saved state ${found.record.id}, saved ${formatDuration(found.ageMs)} ago`);
3095
- return { key, keyCommits, restore: { record: found.record, ageMs: found.ageMs } };
3096
- }
3097
- if (found.kind === "expired") {
3098
- log(`saved state ${found.record.id} is ${formatDuration(found.ageMs)} old, past the limit of ${SAVED_STATE_MAX_AGE_MS / 864e5} days; starting from a fresh disk`);
3099
- } else if (found.kind === "changed") {
3100
- log(`the setup script or version files changed on the default branch since saved state ${found.record.id}: ${found.files.join(", ")}; starting from a fresh disk`);
3101
- } else if (found.kind === "none") {
3102
- log("no saved state matches this build's key; starting from a fresh disk");
3135
+ const delivered = await deliverTar(runtime, state, { step: STEPS[part], tar, into: `${JOB_MOUNT}/${part}`, replace: part === "eval-input", secrets });
3136
+ if (!delivered.ok) return delivered;
3103
3137
  }
3104
- return { key, keyCommits };
3138
+ return { ok: true };
3105
3139
  }
3106
- function unread(reason, log) {
3107
- log(`this build starts from no saved state and saves none: ${reason}`);
3108
- return { keyCommits: {}, noSave: `its key files could not be read: ${reason}` };
3140
+ function deliverGhConfig(runtime, state, secrets) {
3141
+ return deliverJobFiles(runtime, state, ["gh"], secrets);
3109
3142
  }
3110
- var RECORD_FILE = "record.json";
3111
- var DISK_FILE = "disk.ext4";
3112
- var WORK_ITEM_ID2 = /^[A-Za-z0-9_-]{1,64}$/;
3113
- function itemDiskDir(configPath, organizationId, workItemId) {
3143
+ function deliverEvalInput(runtime, state, secrets) {
3144
+ return deliverJobFiles(runtime, state, ["eval-input"], secrets);
3145
+ }
3146
+ async function deliverJudgeInputs(runtime, state, dir, secrets) {
3147
+ return deliverTar(runtime, state, { step: "the judge's inputs", tar: packFolder(dir, { rootMode: 1023, dirModes: { home: 511, "home/tmp": 511 } }), into: JUDGE_DIR, replace: true, secrets });
3148
+ }
3149
+ function clearJudgeFolder(runtime, state, secrets) {
3150
+ return deliverTar(runtime, state, { step: "clearing the judge's folder", tar: packTar([]), into: JUDGE_DIR, replace: true, secrets });
3151
+ }
3152
+ var FILE_MODE = 420;
3153
+ var DIR_MODE = 493;
3154
+ function replaceFile(path, text2) {
3155
+ const partial = `${path}.${process.pid}.partial`;
3156
+ writeFileSync(partial, text2);
3157
+ chmodSync(partial, FILE_MODE);
3158
+ renameSync(partial, path);
3159
+ }
3160
+ function ghHostsYml(token) {
3161
+ return [
3162
+ "github.com:",
3163
+ " users:",
3164
+ " x-access-token:",
3165
+ ` oauth_token: ${token}`,
3166
+ ` oauth_token: ${token}`,
3167
+ " user: x-access-token",
3168
+ " git_protocol: https",
3169
+ ""
3170
+ ].join("\n");
3171
+ }
3172
+ var GH_CONFIG_YML = 'version: "1"\n';
3173
+ function writeGhConfig(dir, token) {
3174
+ mkdirSync(dir, { recursive: true, mode: DIR_MODE });
3175
+ chmodSync(dir, DIR_MODE);
3176
+ replaceFile(join(dir, "hosts.yml"), ghHostsYml(token));
3177
+ replaceFile(join(dir, "config.yml"), GH_CONFIG_YML);
3178
+ }
3179
+ var noop = () => void 0;
3180
+ var FRAME_HEADER_BYTES = 9;
3181
+ var GOAWAY_FRAME = 7;
3182
+ function describeGoawayCode(code) {
3183
+ const names = [
3184
+ "NO_ERROR",
3185
+ "PROTOCOL_ERROR",
3186
+ "INTERNAL_ERROR",
3187
+ "FLOW_CONTROL_ERROR",
3188
+ "SETTINGS_TIMEOUT",
3189
+ "STREAM_CLOSED",
3190
+ "FRAME_SIZE_ERROR",
3191
+ "REFUSED_STREAM",
3192
+ "CANCEL",
3193
+ "COMPRESSION_ERROR",
3194
+ "CONNECT_ERROR",
3195
+ "ENHANCE_YOUR_CALM",
3196
+ "INADEQUATE_SECURITY",
3197
+ "HTTP_1_1_REQUIRED"
3198
+ ];
3199
+ const name = names[code];
3200
+ return name === void 0 ? `error code ${code}` : `${name} (${code})`;
3201
+ }
3202
+ function goawayNote(label, code) {
3203
+ return code === void 0 ? "" : ` \xB7 ${label} ${describeGoawayCode(code)}`;
3204
+ }
3205
+ function watchSentGoaway(onError) {
3206
+ let head = Buffer.alloc(0);
3207
+ let want = FRAME_HEADER_BYTES;
3208
+ let skip = 0;
3209
+ return (chunk) => {
3210
+ let at = 0;
3211
+ while (at < chunk.length) {
3212
+ if (skip > 0) {
3213
+ const n = Math.min(skip, chunk.length - at);
3214
+ skip -= n;
3215
+ at += n;
3216
+ continue;
3217
+ }
3218
+ const take = Math.min(want - head.length, chunk.length - at);
3219
+ head = Buffer.concat([head, chunk.subarray(at, at + take)]);
3220
+ at += take;
3221
+ if (head.length < want) return;
3222
+ const length = head.readUIntBE(0, 3);
3223
+ if (want === FRAME_HEADER_BYTES && head[3] === GOAWAY_FRAME && length >= 8) {
3224
+ want = FRAME_HEADER_BYTES + 8;
3225
+ continue;
3226
+ }
3227
+ if (want > FRAME_HEADER_BYTES) {
3228
+ const code = head.readUInt32BE(FRAME_HEADER_BYTES + 4);
3229
+ if (code !== http2.constants.NGHTTP2_NO_ERROR) onError(code);
3230
+ }
3231
+ skip = length - (want - FRAME_HEADER_BYTES);
3232
+ head = Buffer.alloc(0);
3233
+ want = FRAME_HEADER_BYTES;
3234
+ }
3235
+ };
3236
+ }
3237
+ function writeStringsAsBuffers(stream) {
3238
+ const own = stream._writev;
3239
+ if (typeof own !== "function") return;
3240
+ stream._writev = function(chunks, callback) {
3241
+ const buffers = chunks.map(({ chunk, encoding }) => ({
3242
+ chunk: typeof chunk === "string" ? Buffer.from(chunk, encoding) : chunk,
3243
+ encoding: "buffer"
3244
+ }));
3245
+ buffers.allBuffers = true;
3246
+ own.call(this, buffers, callback);
3247
+ };
3248
+ }
3249
+ function serveSession(transport, services, opts = {}) {
3250
+ const maxStreams = opts.maxStreams ?? MAX_OPEN_STREAMS;
3251
+ let open = 0;
3252
+ let served = 0;
3253
+ let malformed = false;
3254
+ let goawayCode;
3255
+ transport.on("error", noop);
3256
+ const watch = watchSentGoaway((code) => {
3257
+ malformed = true;
3258
+ goawayCode ??= code;
3259
+ setImmediate(() => session.destroy());
3260
+ });
3261
+ const outbound = new Transform({
3262
+ transform(chunk, _encoding, done) {
3263
+ watch(chunk);
3264
+ done(null, chunk);
3265
+ }
3266
+ });
3267
+ outbound.on("error", noop);
3268
+ outbound.pipe(transport);
3269
+ const wire = Duplex.from({ readable: transport, writable: outbound });
3270
+ wire.on("error", noop);
3271
+ const session = http2.performServerHandshake(wire, {
3272
+ settings: { initialWindowSize: STREAM_WINDOW, enablePush: false },
3273
+ streamResetBurst: STREAM_RESET_BURST,
3274
+ streamResetRate: STREAM_RESET_RATE
3275
+ });
3276
+ try {
3277
+ session.setLocalWindowSize(SESSION_WINDOW);
3278
+ } catch {
3279
+ }
3280
+ const ended = new Promise((resolve2) => {
3281
+ session.on("error", (err) => {
3282
+ if (typeof err.code === "string" && err.code.startsWith("ERR_HTTP2_")) malformed = true;
3283
+ });
3284
+ session.on("goaway", (code) => {
3285
+ if (code !== http2.constants.NGHTTP2_NO_ERROR) goawayCode ??= code;
3286
+ });
3287
+ session.on("close", () => resolve2({ malformed, served, goawayCode }));
3288
+ });
3289
+ session.on("stream", (stream, headers) => {
3290
+ stream.on("error", noop);
3291
+ const target2 = headers[":method"] === "POST" ? targetOfPath(headers[":path"], opts.builtIns) : void 0;
3292
+ if (target2 === void 0 || open >= maxStreams) {
3293
+ stream.close(http2.constants.NGHTTP2_REFUSED_STREAM);
3294
+ return;
3295
+ }
3296
+ open++;
3297
+ stream.once("close", () => {
3298
+ open--;
3299
+ });
3300
+ writeStringsAsBuffers(stream);
3301
+ if (!services.accept(target2, stream)) {
3302
+ stream.close(http2.constants.NGHTTP2_REFUSED_STREAM);
3303
+ return;
3304
+ }
3305
+ served++;
3306
+ if (!stream.headersSent && !stream.destroyed) stream.respond({ ":status": 200 });
3307
+ });
3308
+ return {
3309
+ ended,
3310
+ // A session the peer is closing gracefully waits for its open streams, which a stopped container never ends: destroy it whatever its state.
3311
+ close: () => {
3312
+ if (!session.destroyed) session.destroy();
3313
+ }
3314
+ };
3315
+ }
3316
+ var FIRST_BACKOFF_MS = 200;
3317
+ var LONGEST_BACKOFF_MS = 5e3;
3318
+ var JOINED_AFTER_MS = 2e3;
3319
+ var EXIT_WAIT_MS = 5e3;
3320
+ var SOCKET_NOT_READY = /\b(ENOENT|ECONNREFUSED)\b/;
3321
+ function exitedWithin(stream, ms) {
3322
+ let timer;
3323
+ const late = new Promise((resolve2) => {
3324
+ timer = setTimeout(() => resolve2(void 0), ms);
3325
+ timer.unref();
3326
+ });
3327
+ return Promise.race([stream.exited, late]).finally(() => clearTimeout(timer));
3328
+ }
3329
+ function superviseRelay(input) {
3330
+ const sleep = input.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
3331
+ const exitWaitMs = input.exitWaitMs ?? EXIT_WAIT_MS;
3332
+ const now = input.now ?? Date.now;
3333
+ const startedAt = now();
3334
+ let closed = false;
3335
+ let fatal;
3336
+ let running;
3337
+ let wake;
3338
+ const loop = (async () => {
3339
+ let malformedInARow = 0;
3340
+ let backoff = FIRST_BACKOFF_MS;
3341
+ let failing = false;
3342
+ while (!closed && fatal === void 0) {
3343
+ const startedMs = Date.now();
3344
+ const stream = input.execStream({
3345
+ container: input.container,
3346
+ user: RELAY_USER,
3347
+ env: { literals: {}, passed: {} },
3348
+ argv: ["outerlayer", "broker-relay", "join"],
3349
+ interactive: true
3350
+ });
3351
+ stream.stdin.on("error", noop);
3352
+ stream.stdout.on("error", noop);
3353
+ const session = serveSession(Duplex.from({ readable: stream.stdout, writable: stream.stdin }), input.services, { builtIns: input.builtIns });
3354
+ running = { stream, session };
3355
+ void stream.exited.then(() => session.close());
3356
+ const end = await session.ended;
3357
+ stream.kill();
3358
+ const status = await exitedWithin(stream, exitWaitMs);
3359
+ running = void 0;
3360
+ if (status === void 0) input.log?.(`the relay's exec into ${input.container} did not end when killed \xB7 going on without it`);
3361
+ const joined = end.served > 0 || Date.now() - startedMs >= JOINED_AFTER_MS;
3362
+ if (joined) {
3363
+ backoff = FIRST_BACKOFF_MS;
3364
+ failing = false;
3365
+ if (!closed) input.log?.(`the session with ${input.container} ended \xB7 joining again${goawayNote("GOAWAY", end.goawayCode)}`);
3366
+ }
3367
+ if (!end.malformed && end.served > 0) malformedInARow = 0;
3368
+ if (end.malformed) {
3369
+ malformedInARow++;
3370
+ if (malformedInARow >= MAX_MALFORMED_SESSIONS) {
3371
+ fatal = MALFORMED_REASON;
3372
+ input.log?.(`the session with ${input.container} broke HTTP/2 framing ${malformedInARow} times in a row${goawayNote("last GOAWAY", end.goawayCode)} \xB7 ending the build`);
3373
+ input.onFatal?.(fatal);
3374
+ return;
3375
+ }
3376
+ } else if (!joined && !failing) {
3377
+ const reason = stream.stderrTail?.().trim() ?? "";
3378
+ const starting = SOCKET_NOT_READY.test(reason) && now() - startedAt < JOIN_WAIT_MS;
3379
+ if (!starting) {
3380
+ failing = true;
3381
+ input.log?.(`could not join the relay in ${input.container}${status === 0 || status === void 0 ? "" : ` (exec exited ${status})`}${reason === "" ? "" : `: ${reason}`} \xB7 trying again`);
3382
+ }
3383
+ }
3384
+ if (closed) return;
3385
+ await Promise.race([sleep(backoff), new Promise((resolve2) => wake = resolve2)]);
3386
+ backoff = Math.min(backoff * 2, LONGEST_BACKOFF_MS);
3387
+ }
3388
+ })();
3389
+ return {
3390
+ fatal: () => fatal,
3391
+ close: async () => {
3392
+ closed = true;
3393
+ wake?.();
3394
+ running?.session.close();
3395
+ running?.stream.kill();
3396
+ await loop;
3397
+ }
3398
+ };
3399
+ }
3400
+
3401
+ // src/runner/record-proofs.ts
3402
+ var RECORD_PROOFS_ARGV = ["outerlayer", "work", "proofs", "--record", "--comment"];
3403
+ var PROOFS_LOG = "proofs.log";
3404
+
3405
+ // src/runner/sandbox/sweep.ts
3406
+ var RUNNER_METADATA = "outerlayerRunner";
3407
+ var BUILD_METADATA = "outerlayerBuild";
3408
+ function orphanedSandboxes(sandboxes, runnerId, heldBuilds) {
3409
+ return sandboxes.filter((sandbox) => {
3410
+ if (sandbox.metadata[RUNNER_METADATA] !== runnerId) return false;
3411
+ if (sandbox.state === "ended") return false;
3412
+ const build = sandbox.metadata[BUILD_METADATA];
3413
+ return build === void 0 || !heldBuilds.has(build);
3414
+ });
3415
+ }
3416
+ async function sweepSandboxes(input) {
3417
+ let listed;
3418
+ try {
3419
+ listed = await input.client.list();
3420
+ } catch (err) {
3421
+ input.log?.(`could not list sandboxes: ${err instanceof Error ? err.message : String(err)}`);
3422
+ return 0;
3423
+ }
3424
+ let ended = 0;
3425
+ for (const sandbox of orphanedSandboxes(listed, input.runnerId, input.heldBuilds())) {
3426
+ try {
3427
+ await input.client.end(sandbox.id);
3428
+ ended++;
3429
+ input.log?.(`ended sandbox ${sandbox.id} (${sandbox.name}): no unfinished build holds it`);
3430
+ } catch (err) {
3431
+ input.log?.(`could not end sandbox ${sandbox.id}: ${err instanceof Error ? err.message : String(err)}`);
3432
+ }
3433
+ }
3434
+ return ended;
3435
+ }
3436
+ var BUFFER_HIGH_WATER = 1024 * 1024;
3437
+ var DRAIN_POLL_MS = 5;
3438
+ var OPEN_TIMEOUT_MS = 3e4;
3439
+ var defaultWebSocket = (url) => new WebSocket(url);
3440
+ function sandboxExecStream(opts) {
3441
+ const create = opts.webSocket ?? defaultWebSocket;
3442
+ return () => {
3443
+ const stdout = new PassThrough();
3444
+ let socket;
3445
+ let open = false;
3446
+ let finished2 = false;
3447
+ let tail = "";
3448
+ let finish2;
3449
+ const exited = new Promise((resolve2) => finish2 = resolve2);
3450
+ const end = (status, why) => {
3451
+ if (finished2) return;
3452
+ finished2 = true;
3453
+ if (why !== void 0) tail = `${tail}${why}`.slice(-400);
3454
+ stdout.end();
3455
+ try {
3456
+ socket?.close();
3457
+ } catch {
3458
+ }
3459
+ finish2(status);
3460
+ };
3461
+ const opened = new Promise((resolve2, reject) => {
3462
+ const timer = setTimeout(() => reject(new Error("the WebSocket did not open in time")), OPEN_TIMEOUT_MS);
3463
+ timer.unref();
3464
+ opts.url().then((url) => {
3465
+ socket = create(url);
3466
+ socket.binaryType = "arraybuffer";
3467
+ socket.addEventListener("open", () => {
3468
+ clearTimeout(timer);
3469
+ open = true;
3470
+ socket.send(opts.secret);
3471
+ resolve2();
3472
+ });
3473
+ socket.addEventListener("message", (event) => {
3474
+ if (event.data instanceof ArrayBuffer) stdout.write(Buffer.from(event.data));
3475
+ else if (ArrayBuffer.isView(event.data)) stdout.write(Buffer.from(event.data.buffer, event.data.byteOffset, event.data.byteLength));
3476
+ });
3477
+ socket.addEventListener("error", (event) => {
3478
+ clearTimeout(timer);
3479
+ reject(new Error(event.message ?? "the WebSocket failed"));
3480
+ });
3481
+ socket.addEventListener("close", (event) => {
3482
+ clearTimeout(timer);
3483
+ reject(new Error("the WebSocket closed before it opened"));
3484
+ end(event.code === 1e3 || event.code === void 0 ? 0 : 1, event.code === 1008 ? "the relay refused the join secret" : void 0);
3485
+ });
3486
+ }).catch((err) => {
3487
+ clearTimeout(timer);
3488
+ reject(err);
3489
+ });
3490
+ });
3491
+ opened.catch((err) => end(1, err instanceof Error ? err.message : String(err)));
3492
+ const stdin = new Writable({
3493
+ write(chunk, _encoding, callback) {
3494
+ opened.then(
3495
+ async () => {
3496
+ if (finished2) return callback(new Error("the connection is closed"));
3497
+ socket.send(chunk);
3498
+ while (open && !finished2 && socket.bufferedAmount > BUFFER_HIGH_WATER) await new Promise((resolve2) => setTimeout(resolve2, DRAIN_POLL_MS));
3499
+ callback();
3500
+ },
3501
+ () => callback(new Error("the connection did not open"))
3502
+ );
3503
+ },
3504
+ final(callback) {
3505
+ end(0);
3506
+ callback();
3507
+ }
3508
+ });
3509
+ stdin.on("error", () => void 0);
3510
+ stdout.on("error", () => void 0);
3511
+ return { stdin, stdout, exited, kill: () => end(-1), stderrTail: () => tail };
3512
+ };
3513
+ }
3514
+ var RUN_DIR = "/tmp/ol-run";
3515
+ var CHUNK_BYTES = 9e4;
3516
+ var READ_ATTEMPTS = 4;
3517
+ var POLL_FIRST_MS = 50;
3518
+ var POLL_LONGEST_MS = 1e3;
3519
+ function quote(word) {
3520
+ return /^[A-Za-z0-9_@%+=:,./-]+$/.test(word) ? word : `'${word.replace(/'/g, `'\\''`)}'`;
3521
+ }
3522
+ function sandboxLine(command, args, env) {
3523
+ const values = Object.entries(env ?? {}).filter((entry) => entry[1] !== void 0).map(([name, value]) => `${name}=${quote(value)}`);
3524
+ return ["sudo", "env", ...values, command, ...args.map(quote)].join(" ");
3525
+ }
3526
+ function sandboxRunner(client2, sandbox, options = {}) {
3527
+ const sleep = options.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
3528
+ return async (command, args, opts = {}) => {
3529
+ const id = randomBytes(6).toString("hex");
3530
+ const file = (suffix) => `${RUN_DIR}/${id}.${suffix}`;
3531
+ const line2 = sandboxLine(command, args, opts.env);
3532
+ options.onCommand?.(line2);
3533
+ if (opts.input !== void 0) {
3534
+ await client2.command(sandbox, `mkdir -p ${RUN_DIR}`);
3535
+ await client2.upload(sandbox, file("in"), Buffer.isBuffer(opts.input) ? opts.input : Buffer.from(opts.input));
3536
+ }
3537
+ const start = `mkdir -p ${RUN_DIR}; echo $$ > ${file("pid")}; ${line2} < ${opts.input === void 0 ? "/dev/null" : file("in")} > ${file("out")} 2> ${file("err")}; echo $? > ${file("code.tmp")}; mv -f ${file("code.tmp")} ${file("code")}`;
3538
+ await client2.command(sandbox, start, { background: true });
3539
+ const deadline = opts.timeoutMs === void 0 ? void 0 : Date.now() + opts.timeoutMs;
3540
+ const collect = `if [ -f ${file("code")} ]; then cat ${file("code")}; head -c ${CHUNK_BYTES} ${file("out")} | base64 | tr -d '\\n'; echo; head -c ${CHUNK_BYTES} ${file("err")} | base64 | tr -d '\\n'; echo; wc -c < ${file("out")}; wc -c < ${file("err")}; fi`;
3541
+ const ask2 = async (cmd) => {
3542
+ for (let attempt = 1; ; attempt++) {
3543
+ try {
3544
+ return await client2.command(sandbox, cmd);
3545
+ } catch (err) {
3546
+ const transient = err instanceof SandboxError && (err.status === 0 || err.status >= 500);
3547
+ if (!transient || attempt >= READ_ATTEMPTS) throw err;
3548
+ await sleep(POLL_FIRST_MS * attempt);
3549
+ }
3550
+ }
3551
+ };
3552
+ let wait = POLL_FIRST_MS;
3553
+ for (; ; ) {
3554
+ const polled = await ask2(collect);
3555
+ if (polled.stdout.trim() !== "") {
3556
+ const [code = "", out = "", err = "", outSize = "0", errSize = "0"] = polled.stdout.split("\n").map((part) => part.trim());
3557
+ const pieces = [Buffer.from(out, "base64")];
3558
+ const errPieces = [Buffer.from(err, "base64")];
3559
+ const more = async (name, size, into) => {
3560
+ for (let read = CHUNK_BYTES; read < size; read += CHUNK_BYTES) {
3561
+ const next = await ask2(`tail -c +${read + 1} ${file(name)} | head -c ${CHUNK_BYTES} | base64 | tr -d '\\n'`);
3562
+ into.push(Buffer.from(next.stdout.trim(), "base64"));
3563
+ }
3564
+ };
3565
+ await more("out", Number(outSize), pieces);
3566
+ await more("err", Number(errSize), errPieces);
3567
+ await client2.command(sandbox, `rm -f ${RUN_DIR}/${id}.*`);
3568
+ const result = { status: Number(code) || 0, stdout: Buffer.concat(pieces).toString("utf8"), stderr: Buffer.concat(errPieces).toString("utf8") };
3569
+ if (opts.logPath !== void 0) {
3570
+ mkdirSync(dirname(opts.logPath), { recursive: true });
3571
+ appendFileSync(opts.logPath, result.stdout + result.stderr);
3572
+ }
3573
+ return result;
3574
+ }
3575
+ if (deadline !== void 0 && Date.now() >= deadline) {
3576
+ await client2.command(sandbox, `kill -9 $(cat ${file("pid")}) 2>/dev/null; rm -f ${RUN_DIR}/${id}.*`).catch(() => void 0);
3577
+ const extra = `${command}: no answer within ${Math.round(opts.timeoutMs / 1e3)}s
3578
+ `;
3579
+ if (opts.logPath !== void 0) {
3580
+ mkdirSync(dirname(opts.logPath), { recursive: true });
3581
+ appendFileSync(opts.logPath, extra);
3582
+ }
3583
+ return { status: 124, stdout: "", stderr: extra };
3584
+ }
3585
+ await sleep(wait);
3586
+ wait = Math.min(wait * 2, POLL_LONGEST_MS);
3587
+ }
3588
+ };
3589
+ }
3590
+ function sandboxHost(client2, sandbox, options = {}) {
3591
+ return createContainerHost({ run: sandboxRunner(client2, sandbox, options) });
3592
+ }
3593
+
3594
+ // src/runner/sandbox/hooks.ts
3595
+ var SANDBOX_DIR = "/tmp/ol";
3596
+ var CLI_DIR = `${SANDBOX_DIR}/dist`;
3597
+ var SECRET_FILE = `${SANDBOX_DIR}/join-secret`;
3598
+ var CONTAINER_SECRET_FILE = "/run/outerlayer-relay/join-secret";
3599
+ var JOIN_WS_PORT = 7077;
3600
+ var SANDBOX_RESERVE_MIB = 512;
3601
+ var RELAY_ATTEMPTS = 40;
3602
+ var RELAY_WAIT_MS = 500;
3603
+ var SANDBOX_PROBE_BYTES = 96 * 1024;
3604
+ var MAX_TAIL_READS2 = 8;
3605
+ var NO_ENV = { literals: {}, passed: {} };
3606
+ function sandboxNameOf(runnerLabel, buildId) {
3607
+ const short = runnerLabel.toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 8);
3608
+ return `ol-${short === "" ? "runner" : short}-${buildId}`;
3609
+ }
3610
+ async function endUnansweredSandbox(sandboxClient, runnerId, buildId, warn) {
3611
+ try {
3612
+ for (const found of await sandboxClient.list()) {
3613
+ if (found.state !== "ended" && found.metadata[RUNNER_METADATA] === runnerId && found.metadata[BUILD_METADATA] === buildId) await sandboxClient.end(found.id);
3614
+ }
3615
+ } catch (err) {
3616
+ warn(`could not end a sandbox that a lost create may have made: ${describeCallFailure(err)} \xB7 the next sweep ends it`);
3617
+ }
3618
+ }
3619
+ function client(runtime) {
3620
+ return runtime.sandbox.client();
3621
+ }
3622
+ async function sandboxOfBuild(runtime, state) {
3623
+ const held3 = runtime.sandbox.sandboxes.get(state.buildId);
3624
+ if (held3 !== void 0) return held3;
3625
+ try {
3626
+ const found = await client(runtime).get(state.sandboxId);
3627
+ if (found.state === "ended" || found.secret === "") return void 0;
3628
+ runtime.sandbox.sandboxes.set(state.buildId, found);
3629
+ return found;
3630
+ } catch (err) {
3631
+ if (err instanceof SandboxError && err.status === 404) return void 0;
3632
+ throw err;
3633
+ }
3634
+ }
3635
+ function runtimeInSandbox(runtime, sandbox) {
3636
+ return { ...runtime, host: sandboxHost(client(runtime), sandbox, { sleep: runtime.sandbox.sleep }) };
3637
+ }
3638
+ var SandboxGoneError = class extends Error {
3639
+ constructor(sandboxId, endedReason) {
3640
+ super(`The provider ended sandbox ${sandboxId} while the build ran${endedReason === void 0 || endedReason === "" ? "" : ` (${endedReason})`}`);
3641
+ this.endedReason = endedReason;
3642
+ this.name = "SandboxGoneError";
3643
+ }
3644
+ };
3645
+ async function inSandbox(runtime, state) {
3646
+ const sandbox = await sandboxOfBuild(runtime, state);
3647
+ if (sandbox === void 0) throw new SandboxGoneError(state.sandboxId);
3648
+ return runtimeInSandbox(runtime, sandbox);
3649
+ }
3650
+ async function goneReason(runtime, state) {
3651
+ try {
3652
+ const found = await client(runtime).get(state.sandboxId);
3653
+ return found.state === "ended" ? new SandboxGoneError(state.sandboxId, found.endedReason ?? void 0) : void 0;
3654
+ } catch (err) {
3655
+ return err instanceof SandboxError && err.status === 404 ? new SandboxGoneError(state.sandboxId) : void 0;
3656
+ }
3657
+ }
3658
+ function sandboxRunArgs(args) {
3659
+ const out = [...args];
3660
+ const network = out.indexOf("--network");
3661
+ if (network !== -1) out[network + 1] = "host";
3662
+ const entrypoint = out.indexOf("--entrypoint");
3663
+ out.splice(
3664
+ entrypoint,
3665
+ 0,
3666
+ "--mount",
3667
+ `type=bind,src=${CLI_DIR},dst=/opt/outerlayer/cli/dist,readonly`,
3668
+ "--mount",
3669
+ `type=bind,src=${SECRET_FILE},dst=${CONTAINER_SECRET_FILE},readonly`,
3670
+ ...Object.entries(toolProxyEnvironment()).flatMap(([name, value]) => ["--env", `${name}=${value}`])
3671
+ );
3672
+ out.push("--join-ws", String(JOIN_WS_PORT), "--join-secret-file", CONTAINER_SECRET_FILE);
3673
+ return out;
3674
+ }
3675
+ var RELAY_PROBE = `const s=require("net").connect(3128,"127.0.0.1");s.on("connect",()=>process.exit(0));s.on("error",()=>process.exit(1));setTimeout(()=>process.exit(1),2000)`;
3676
+ async function waitForRelay(runtime, container) {
3677
+ for (let attempt = 0; attempt < RELAY_ATTEMPTS; attempt++) {
3678
+ const probe = await runtime.host.exec({ container, user: RELAY_USER, env: NO_ENV, argv: ["/opt/outerlayer/bin/node", "-e", RELAY_PROBE] });
3679
+ if (probe.status === 0) return true;
3680
+ await runtime.sandbox.sleep(RELAY_WAIT_MS);
3681
+ }
3682
+ return false;
3683
+ }
3684
+ async function cleanupSandbox(runtime, state) {
3685
+ const failures = [];
3686
+ const relay = runtime.relays.get(state.buildId);
3687
+ if (relay !== void 0) {
3688
+ runtime.relays.delete(state.buildId);
3689
+ await relay.close();
3690
+ }
3691
+ runtime.relayFatal.delete(state.buildId);
3692
+ runtime.leases.get(state.buildId)?.close();
3693
+ runtime.leases.delete(state.buildId);
3694
+ if (state.sandboxId !== "") {
3695
+ try {
3696
+ await client(runtime).end(state.sandboxId);
3697
+ } catch (err) {
3698
+ failures.push(`sandbox ${state.sandboxId} was not ended: ${err instanceof SandboxError ? describeSandboxError(err) : describeCallFailure(err)}`);
3699
+ }
3700
+ }
3701
+ runtime.sandbox.sandboxes.delete(state.buildId);
3702
+ runtime.sandbox.joinSecrets.delete(state.buildId);
3703
+ const tunnel = runtime.tunnels.get(state.buildId);
3704
+ if (tunnel !== void 0) {
3705
+ runtime.tunnels.delete(state.buildId);
3706
+ await tunnel.close();
3707
+ }
3708
+ if (state.container !== void 0) rmSync(state.container.buildDir, { recursive: true, force: true });
3709
+ if (failures.length > 0) throw new Error(failures.join("; "));
3710
+ }
3711
+ async function provisionSandbox(input) {
3712
+ const { config, runtime, item, itemKey, jobDir, log, tokens } = input;
3713
+ const tag = itemTag({ item: item.number, organizationId: input.organizationId, claimId: input.claimId });
3714
+ const logPath = join(jobDir, "provision.log");
3715
+ const fail = (reason) => ({ ok: false, reason });
3716
+ const own = config.sandbox;
3717
+ if (own === void 0) return fail("runner.sandbox is not set in the config file");
3718
+ const repositories = repositoriesOf({ repositories: input.repositories, repository: item.specRepository, branch: input.branch });
3719
+ const primary = primaryOf(repositories);
3720
+ if (primary === void 0) return fail("the work item names no repository to clone");
3721
+ const repository = primary.repository;
3722
+ const sized = sandboxSizeOf(config.build);
3723
+ if (!sized.ok) return fail(`${sized.field} ${sized.problem}`);
3724
+ let sandboxClient;
3725
+ try {
3726
+ sandboxClient = client(runtime);
3727
+ } catch (err) {
3728
+ return fail(err instanceof SandboxError ? describeSandboxError(err) : describeCallFailure(err));
3729
+ }
3730
+ const governing = await resolveGoverningSource({ config, repository, fetchImpl: input.fetchImpl });
3731
+ if (!governing.ok) return fail(governing.reason);
3732
+ const governingSource = governing.source;
3733
+ const controlPlaneUrl = (controlPlane) => runtime.remoteFor?.(controlPlane) ?? `${runtime.github.gitUrl}/${controlPlane}.git`;
3734
+ if (governingSource.kind === "governed") {
3735
+ const unfetched = await prefetchGovernedContext({
3736
+ configPath: config.configPath,
3737
+ repository,
3738
+ source: governingSource,
3739
+ controlPlaneUrl,
3740
+ controlPlaneToken: () => tokens.controlPlane(),
3741
+ log,
3742
+ tag
3743
+ });
3744
+ if (unfetched !== void 0) return fail(unfetched);
3745
+ }
3746
+ const buildId = randomBytes(6).toString("hex");
3747
+ const runnerId = runnerLabelValue(config.configPath);
3748
+ const name = sandboxNameOf(runnerId, buildId);
3749
+ const container = `outerlayer-build-${buildId}`;
3750
+ const buildDir2 = buildDir(config.configPath, buildId);
3751
+ const image = own.image;
3752
+ const containerState = {
3753
+ buildId,
3754
+ container,
3755
+ volume: container,
3756
+ buildDir: buildDir2,
3757
+ repository,
3758
+ imageId: image,
3759
+ builtIns: true,
3760
+ ...governingSource.kind === "governed" ? { governing: { repository: governingSource.repository, ref: governingSource.ref, commit: governingSource.sha } } : {},
3761
+ transport: "exec",
3762
+ jobFiles: "copied"
3763
+ };
3764
+ const state = { sandboxId: "", name, dataPlaneUrl: "", buildId, container: containerState };
3765
+ const secrets = secretsOf(runtime, jobDir);
3766
+ const env = buildEnvironment({
3767
+ config,
3768
+ item: item.number,
3769
+ itemKey,
3770
+ repository,
3771
+ repositories,
3772
+ hostEnv: runtime.hostEnv,
3773
+ agents: runtime.agents,
3774
+ ...input.job === void 0 ? {} : { job: input.job },
3775
+ containerEnv: {},
3776
+ builtIns: true
3777
+ });
3778
+ if (env.skippedTokenVariables.length > 0) {
3779
+ log.line(`${tag} not passing ${env.skippedTokenVariables.join(", ")} from runner.build.variables into the build: its repository token comes from the runner`);
3780
+ }
3781
+ const environment = {
3782
+ isolation: "vm",
3783
+ imageId: image,
3784
+ variables: env.variables,
3785
+ cliVersion: input.cliVersion
3786
+ };
3787
+ const bail = async (reason, aborted2 = false) => {
3788
+ try {
3789
+ await cleanupSandbox(runtime, { buildId, sandboxId: state.sandboxId, container: containerState });
3790
+ } catch (err) {
3791
+ log.error(`${tag} cleanup failed: ${describeCallFailure(err)}`);
3792
+ }
3793
+ return aborted2 ? { ok: false, reason: "ended before provision finished", aborted: true } : fail(reason);
3794
+ };
3795
+ if (input.aborted()) return bail("", true);
3796
+ mkdirSync(buildDir2, { recursive: true });
3797
+ const ghDir = ghConfigDir(buildDir2);
3798
+ let readToken;
3799
+ try {
3800
+ readToken = await tokens.token("read");
3801
+ writeGhConfig(ghDir, readToken);
3802
+ } catch (err) {
3803
+ return bail(err instanceof WorkCommandError ? `the build's read token could not be had: ${refusalCode(err)}` : `the build's gh configuration could not be written: ${describeCallFailure(err)}`);
3804
+ }
3805
+ for (const entry of repositories) {
3806
+ if (entry.repository === primary.repository) continue;
3807
+ try {
3808
+ await tokens.token("read", entry.repository);
3809
+ } catch (err) {
3810
+ return bail(`the build's read token for ${entry.repository} could not be had: ${refusalCode(err)}`);
3811
+ }
3812
+ }
3813
+ keepGhConfigCurrent(tokens, buildDir2, (err) => log.error(`${tag} the read token could not be written for gh: ${describeCallFailure(err)}`));
3814
+ tokens.markUsed("read");
3815
+ environment.credentials = tokens.used();
3816
+ let services;
3817
+ try {
3818
+ const gitRemote = gitRemoteFor(runtime, { repositories, tokens, buildDir: buildDir2, log: (line2) => log.line(`${tag} ${line2}`) });
3819
+ services = await startServicesFor(runtime, config, buildDir2, jobDir, itemKey, true, gitRemote, "stream", input.leaseExpiryMs === void 0 ? void 0 : leaseFor(runtime, buildId, input.leaseExpiryMs), void 0, (line2) => log.line(`${tag} ${line2}`));
3820
+ runtime.tunnels.set(buildId, services);
3821
+ } catch (err) {
3822
+ return bail(`the tunnel could not start: ${describeCallFailure(err)}`);
3823
+ }
3824
+ if (input.aborted()) return bail("", true);
3825
+ let sandbox;
3826
+ runtime.sandbox.creating.add(buildId);
3827
+ try {
3828
+ sandbox = await sandboxClient.create({
3829
+ name,
3830
+ from: own.snapshot,
3831
+ ...sized.size,
3832
+ idleMinutes: own.idleMinutes,
3833
+ timeLimitMinutes: sandboxTimeLimitMinutes(config.timeLimitMinutes),
3834
+ network: networkOf(own.allowHosts),
3835
+ metadata: { [RUNNER_METADATA]: runnerId, [BUILD_METADATA]: buildId }
3836
+ });
3837
+ } catch (err) {
3838
+ if (err instanceof SandboxError && err.status === 0) await endUnansweredSandbox(sandboxClient, runnerId, buildId, (line2) => log.error(`${tag} ${line2}`));
3839
+ runtime.sandbox.creating.delete(buildId);
3840
+ return bail(`The provider refused to create the sandbox: ${err instanceof SandboxError ? describeSandboxError(err) : describeCallFailure(err)}`);
3841
+ }
3842
+ runtime.sandbox.sandboxes.set(buildId, sandbox);
3843
+ state.sandboxId = sandbox.id;
3844
+ state.dataPlaneUrl = sandbox.dataPlaneUrl;
3845
+ input.save(state, environment);
3846
+ runtime.sandbox.creating.delete(buildId);
3847
+ log.line(`${tag} sandbox ${sandbox.id} created \xB7 ${name}`);
3848
+ if (input.aborted()) return bail("", true);
3849
+ const sandboxed = runtimeInSandbox(runtime, sandbox);
3850
+ const { host } = sandboxed;
3851
+ const dockerFailed = (what, result) => bail(`${what} failed (exit ${result.status})${said(result.stderr)}`);
3852
+ const joinSecret = randomBytes(32);
3853
+ runtime.sandbox.joinSecrets.set(buildId, joinSecret);
3854
+ try {
3855
+ await sandboxClient.command(sandbox, `mkdir -p ${CLI_DIR}`);
3856
+ await sandboxClient.upload(sandbox, `${SANDBOX_DIR}/dist.tgz`, gzipSync(packFolder(runtime.cliBuild().distDir)));
3857
+ await sandboxClient.upload(sandbox, SECRET_FILE, joinSecret);
3858
+ const unpacked = await sandboxClient.command(sandbox, `tar xzf ${SANDBOX_DIR}/dist.tgz -C ${CLI_DIR} && rm -f ${SANDBOX_DIR}/dist.tgz && sudo chown 60100:60100 ${SECRET_FILE} && sudo chmod 400 ${SECRET_FILE}`);
3859
+ if (unpacked.exitCode !== 0) return bail(`putting the CLI in the sandbox failed (exit ${unpacked.exitCode ?? "none"})${said(unpacked.stderr)}`);
3860
+ } catch (err) {
3861
+ return bail(`putting the CLI in the sandbox failed: ${err instanceof SandboxError ? describeSandboxError(err) : describeCallFailure(err)}`);
3862
+ }
3863
+ const engine = await host.version();
3864
+ if (engine === null) return bail("Docker is not available in the sandbox: `docker version` failed");
3865
+ const limits2 = { memory: `${Math.max(512, sized.size.memoryMib - SANDBOX_RESERVE_MIB)}m`, cpus: sized.size.vcpu, pids: config.build?.pids ?? 4096 };
3866
+ const volume = await host.createVolume(container, { [BUILD_LABEL]: buildId, [RUNNER_LABEL]: runnerId });
3867
+ if (volume.status !== 0) return dockerFailed("creating the build's volume", volume);
3868
+ const runInput = {
3869
+ buildId,
3870
+ runnerId,
3871
+ container,
3872
+ volume: container,
3873
+ image,
3874
+ user: ADDED_USER,
3875
+ limits: limits2,
3876
+ destinations: config.build?.destinations?.length ?? 0,
3877
+ builtIns: true,
3878
+ transport: "exec",
3879
+ jobFiles: "copied"
3880
+ };
3881
+ const prepared = await host.run(prepareRunArgs(runInput), { logPath });
3882
+ if (prepared.status !== 0) return dockerFailed("preparing the build's volume", prepared);
3883
+ const imageConfig = await host.imageConfig(image);
3884
+ const resolved = await resolveBuildUser(sandboxed, runInput, { imageUser: imageConfig.user }, logPath);
3885
+ if (!resolved.ok) return bail(resolved.reason);
3886
+ containerState.agentUser = resolved.user;
3887
+ if (resolved.home !== void 0) containerState.home = resolved.home;
3888
+ const agentUser = resolved.user;
3889
+ input.save(state, environment);
3890
+ if (input.aborted()) return bail("", true);
3891
+ const started = await host.run(sandboxRunArgs(containerRunArgs({ ...runInput, home: containerState.home }, runtime.agents)), { logPath });
3892
+ if (started.status !== 0) return dockerFailed("starting the build's container", started);
3893
+ const exec = sandboxExecStream({
3894
+ url: () => sandboxClient.portUrl(sandbox, JOIN_WS_PORT),
3895
+ secret: joinSecret,
3896
+ ...runtime.sandbox.webSocket === void 0 ? {} : { webSocket: runtime.sandbox.webSocket }
3897
+ });
3898
+ runtime.relays.set(
3899
+ buildId,
3900
+ superviseRelay({
3901
+ container,
3902
+ services: services.streams,
3903
+ execStream: () => exec(),
3904
+ log: (line2) => log.line(`${tag} ${line2}`),
3905
+ onFatal: (reason) => runtime.relayFatal.set(buildId, reason),
3906
+ builtIns: builtInNames(runtime.agents)
3907
+ })
3908
+ );
3909
+ if (input.aborted()) return bail("", true);
3910
+ if (!await waitForRelay(sandboxed, container)) return bail("the relay in the build's container did not start");
3911
+ const ghDelivered = await deliverJobFiles(sandboxed, containerState, ["gh"], secrets);
3912
+ if (!ghDelivered.ok) return bail(ghDelivered.reason);
3913
+ keepGhConfigCurrent(tokens, buildDir2, (err) => log.error(`${tag} the read token could not be written for gh: ${describeCallFailure(err)}`), {
3914
+ runtime: sandboxed,
3915
+ state: containerState,
3916
+ secrets,
3917
+ delivered: readToken,
3918
+ onFailure: (reason) => log.error(`${tag} ${reason}`)
3919
+ });
3920
+ const tools = await host.exec({ container, user: ADDED_USER, env: NO_ENV, argv: ["cat", "/opt/outerlayer/tools.json"] });
3921
+ const agentVersion = agentVersionOf(tools.status === 0 ? tools.stdout : "", runtime.agents, input.job);
3922
+ environment.agentVersion = agentVersion;
3923
+ input.save(state, environment);
3924
+ const stepExec = async (argv, workdir, opts) => {
3925
+ const ran = await host.exec({ container, user: agentUser, workdir, env: withMiseVariables(env, opts?.variables), argv }, { ...opts?.quiet === true ? {} : { logPath }, ...opts?.timeoutMs === void 0 ? {} : { timeoutMs: opts.timeoutMs } });
3926
+ return endedAtLimit(ran) ? { ...ran, timedOut: true } : ran;
3927
+ };
3928
+ const setupMinutes = config.build?.setupMinutes ?? DEFAULT_SETUP_MINUTES;
3929
+ const steps = await runBuildSteps({
3930
+ repository,
3931
+ branch: primary.branch,
3932
+ repositories,
3933
+ ...governingSource.kind === "governed" ? { governing: { repository: governingSource.repository } } : {},
3934
+ agentVersion,
3935
+ agents: runtime.agents,
3936
+ ...input.job === void 0 ? {} : { job: input.job },
3937
+ lifecycle: {},
3938
+ exec: stepExec,
3939
+ log,
3940
+ tag,
3941
+ aborted: input.aborted,
3942
+ stageContext: () => stageGovernedContext({
3943
+ config,
3944
+ repository,
3945
+ source: pinnedSourceOf(governingSource),
3946
+ buildId,
3947
+ buildDir: buildDir2,
3948
+ fetchImpl: input.fetchImpl,
3949
+ controlPlaneUrl,
3950
+ controlPlaneToken: () => tokens.controlPlane(),
3951
+ log,
3952
+ tag
3953
+ }),
3954
+ deliverContext: async () => {
3955
+ const delivered = await deliverJobFiles(sandboxed, containerState, ["context"], secrets);
3956
+ return delivered.ok ? delivered : { ok: false, reason: `context_unavailable: ${delivered.reason}` };
3957
+ },
3958
+ removeStagedContext: () => removeStagedContext(buildDir2),
3959
+ keepIn: jobDir,
3960
+ ...input.requireBuildSkill === true ? { requireBuildSkill: true } : {},
3961
+ // The image in the snapshot is the universal image, so the build chooses and installs its runtimes.
3962
+ ...runtimeStepInput({ base: {} }, services),
3963
+ setup: { timeoutMs: setupMinutes * 6e4, limitMinutes: setupMinutes, restored: false }
3964
+ });
3965
+ if (!steps.ok) return steps.aborted === true ? bail("", true) : bail(steps.reason);
3966
+ containerState.startCommit = steps.startCommit;
3967
+ keepRuntimeStep(containerState, steps);
3968
+ keepMissingSetupScripts(containerState, steps);
3969
+ if (steps.controlPlane !== void 0) environment.controlPlane = steps.controlPlane;
3970
+ input.save(state, environment);
3971
+ return { ok: true, workdir: CHECKOUT_DIR, state, environment };
3972
+ }
3973
+ function asContainerJob(job) {
3974
+ return { ...job, container: job.sandbox.container };
3975
+ }
3976
+ async function deliverSandboxHooks(runtime, state, jobDir) {
3977
+ try {
3978
+ return await deliverJobFiles(await inSandbox(runtime, state), state.container, ["git-hooks"], secretsOf(runtime, jobDir));
3979
+ } catch (err) {
3980
+ return { ok: false, reason: `the commit hooks could not be delivered: ${describeCallFailure(err)}` };
3981
+ }
3982
+ }
3983
+ async function startSandboxCommand(input) {
3984
+ const own = input.job.sandbox;
3985
+ const runtime = await inSandbox(input.runtime, own);
3986
+ const exec = containerCommandExec({ job: asContainerJob(input.job), cmdline: input.cmdline, runtime, config: input.config, ...input.extraEnv === void 0 ? {} : { extraEnv: input.extraEnv } });
3987
+ const started = await runtime.host.execDetached(exec);
3988
+ if (started.status !== 0) {
3989
+ const first = started.stderr.trim().split("\n")[0] ?? "";
3990
+ throw new Error(`docker exec exited ${started.status}${first === "" ? "" : `: ${first}`}`);
3991
+ }
3992
+ }
3993
+ async function probeSandboxCommand(runtime, state, offset) {
3994
+ let sandboxed;
3995
+ try {
3996
+ sandboxed = await inSandbox(runtime, state);
3997
+ } catch (err) {
3998
+ if (err instanceof SandboxGoneError) throw await goneReason(runtime, state) ?? err;
3999
+ return void 0;
4000
+ }
4001
+ try {
4002
+ const result = await sandboxed.host.exec(
4003
+ { container: state.container.container, user: state.container.agentUser ?? ADDED_USER, env: NO_ENV, argv: probeArgvOf(offset) },
4004
+ { timeoutMs: 6e4 }
4005
+ );
4006
+ return result.status === 0 ? parseProbe(result.stdout) : void 0;
4007
+ } catch (err) {
4008
+ if (err instanceof SandboxError && err.status === 404) throw await goneReason(runtime, state) ?? new SandboxGoneError(state.sandboxId);
4009
+ if (err instanceof SandboxError) return void 0;
4010
+ throw err;
4011
+ }
4012
+ }
4013
+ function probeArgvOf(offset) {
4014
+ const argv = probeArgv(offset);
4015
+ argv[argv.length - 1] = String(SANDBOX_PROBE_BYTES);
4016
+ return argv;
4017
+ }
4018
+ async function endSandboxCommand(runtime, state, jobDir, warn) {
4019
+ try {
4020
+ const sandboxed = await inSandbox(runtime, state);
4021
+ for (let reads = 0; reads < MAX_TAIL_READS2; reads++) {
4022
+ const offset = commandLogOffset(jobDir, state.commandLogBase);
4023
+ const probe = await probeSandboxCommand(runtime, state, offset);
4024
+ if (probe === void 0) break;
4025
+ appendCommandLog(jobDir, probe.bytes);
4026
+ if (probe.bytes.length === 0 || offset + probe.bytes.length >= probe.size) break;
4027
+ }
4028
+ await sandboxed.host.stop(state.container.container);
4029
+ } catch (err) {
4030
+ warn(`ending the build's command in its sandbox failed: ${describeCallFailure(err)} \xB7 continuing`);
4031
+ }
4032
+ }
4033
+ async function runCliInSandbox(input, argv, logName) {
4034
+ const { job } = input;
4035
+ const own = job.sandbox;
4036
+ try {
4037
+ const sandboxed = await inSandbox(input.runtime, own);
4038
+ const state = own.container;
4039
+ const env = buildEnvironment({
4040
+ config: claimCalls(input.config, job),
4041
+ item: job.item,
4042
+ itemKey: job.itemKey,
4043
+ branch: job.branch,
4044
+ repository: state.repository,
4045
+ repositories: job.repositories,
4046
+ hostEnv: input.runtime.hostEnv,
4047
+ agents: input.runtime.agents,
4048
+ job,
4049
+ containerEnv: state.containerEnv ?? {},
4050
+ unpinnedRuntimes: state.unpinnedRuntimes,
4051
+ missingSetupScripts: state.missingSetupScripts,
4052
+ miseVariables: state.miseVariables,
4053
+ builtIns: true,
4054
+ identity: job.commitIdentity
4055
+ });
4056
+ const result = await sandboxed.host.exec(
4057
+ { container: state.container, user: state.agentUser ?? ADDED_USER, workdir: job.workdir ?? CHECKOUT_DIR, env, argv },
4058
+ { logPath: join(input.jobDir, logName) }
4059
+ );
4060
+ return result.status === 0 ? { ok: true } : { ok: false, reason: `exit ${result.status}` };
4061
+ } catch (err) {
4062
+ return { ok: false, reason: describeCallFailure(err) };
4063
+ }
4064
+ }
4065
+ function syncInSandbox(input) {
4066
+ return runCliInSandbox(input, ["outerlayer", "sync"], "sync.log");
4067
+ }
4068
+ function recordProofsInSandbox(input) {
4069
+ return runCliInSandbox(input, [...RECORD_PROOFS_ARGV], PROOFS_LOG);
4070
+ }
4071
+ function savedStatesDir(runnerDirPath) {
4072
+ return join(runnerDirPath, "saved-states");
4073
+ }
4074
+ function writeRecord2(dir, record) {
4075
+ mkdirSync(dir, { recursive: true, mode: RUNNER_DIR_MODE });
4076
+ const target2 = join(dir, `${record.id}.json`);
4077
+ const partial = `${target2}.partial`;
4078
+ writeFileSync(partial, `${JSON.stringify(record, null, 2)}
4079
+ `, { mode: RUNNER_FILE_MODE });
4080
+ renameSync(partial, target2);
4081
+ }
4082
+ function isRecord(value) {
4083
+ if (typeof value !== "object" || value === null) return false;
4084
+ const r = value;
4085
+ return typeof r.id === "string" && (r.kind === "volume" || r.kind === "tar" || r.kind === "disk") && typeof r.savedAt === "string" && Number.isFinite(Date.parse(r.savedAt)) && typeof r.bytes === "number" && typeof r.baseKey === "string" && typeof r.key === "string" && typeof r.fileHashes === "object" && r.fileHashes !== null && typeof r.complete === "boolean";
4086
+ }
4087
+ function readRecords(dir) {
4088
+ let names;
4089
+ try {
4090
+ names = readdirSync(dir);
4091
+ } catch {
4092
+ return [];
4093
+ }
4094
+ const records = [];
4095
+ for (const name of names) {
4096
+ if (!name.endsWith(".json")) continue;
4097
+ try {
4098
+ const parsed = JSON.parse(readFileSync(join(dir, name), "utf8"));
4099
+ if (isRecord(parsed)) records.push(parsed);
4100
+ } catch {
4101
+ }
4102
+ }
4103
+ return records;
4104
+ }
4105
+ function deleteRecord(dir, id) {
4106
+ rmSync(join(dir, `${id}.json`), { force: true });
4107
+ }
4108
+
4109
+ // src/runner/saved-state/remove.ts
4110
+ async function removeSavedState(record, deps) {
4111
+ if (record.kind === "volume" && record.volume !== void 0) {
4112
+ const result = await deps.removeVolume(record.volume);
4113
+ if (result !== void 0 && result.status !== 0) {
4114
+ const line2 = (result.stderr ?? "").trim().split("\n").filter((text2) => text2.trim() !== "").at(-1);
4115
+ throw new Error(`Docker could not remove volume ${record.volume} (exit ${result.status}${line2 === void 0 ? "" : `: ${line2}`})`);
4116
+ }
4117
+ }
4118
+ if ((record.kind === "tar" || record.kind === "disk") && record.path !== void 0) {
4119
+ rmSync(`${record.path}.partial`, { force: true });
4120
+ rmSync(record.path, { force: true });
4121
+ }
4122
+ deleteRecord(deps.dir, record.id);
4123
+ }
4124
+ async function removeOldestUntil(input) {
4125
+ const removed = [];
4126
+ for (const record of oldestFirst(input.records)) {
4127
+ if (input.enough()) break;
4128
+ try {
4129
+ await removeSavedState(record, input.deps);
4130
+ removed.push(record);
4131
+ input.log(`removed saved state ${record.id} from ${record.savedAt}`);
4132
+ } catch (err) {
4133
+ input.log(`could not remove saved state ${record.id}: ${describeCallFailure(err)}`);
4134
+ }
4135
+ }
4136
+ return removed;
4137
+ }
4138
+ async function removeSuperseded(input) {
4139
+ for (const old of input.records.filter((record) => record.complete && record.key === input.made.key && record.id !== input.made.id && Date.parse(record.savedAt) < Date.parse(input.made.savedAt))) {
4140
+ try {
4141
+ await removeSavedState(old, input.deps);
4142
+ input.log(`removed saved state ${old.id}, saved state ${input.made.id} replaces it`);
4143
+ } catch (err) {
4144
+ input.log(`could not remove saved state ${old.id}: ${describeCallFailure(err)}`);
4145
+ }
4146
+ }
4147
+ }
4148
+
4149
+ // src/runner/saved-state/plan.ts
4150
+ function savedStateBase(report) {
4151
+ const digest = report.recipe === "default" ? report.base?.digest : void 0;
4152
+ return digest === void 0 ? void 0 : { digest };
4153
+ }
4154
+ function savedStateMaxOf(config) {
4155
+ return config.housekeeping?.savedStateMax ?? DEFAULT_SAVED_STATE_MAX_BYTES;
4156
+ }
4157
+ async function planSavedState(input) {
4158
+ const { config, runtime, log } = input;
4159
+ const refused2 = savingRefusedBecause({ universalImage: input.base !== void 0, fleet: config.fleet === true, savedStateMax: savedStateMaxOf(config) });
4160
+ if (refused2 !== void 0 || input.base === void 0) {
4161
+ const why = refused2 ?? "its image comes from a devcontainer file";
4162
+ log(`this build saves no state: ${why}`);
4163
+ return { keyCommits: {}, noSave: why };
4164
+ }
4165
+ const root = runnerDir(config.configPath);
4166
+ const repositories = [];
4167
+ const keyCommits = {};
4168
+ for (const entry of input.repositories) {
4169
+ let token;
4170
+ try {
4171
+ token = entry.primary ? await input.tokens.token("read") : await input.tokens.token("read", entry.repository);
4172
+ } catch (err) {
4173
+ return unread(`the read token for ${entry.repository} could not be had: ${describeCallFailure(err)}`, log);
4174
+ }
4175
+ const [owner = "", name = ""] = entry.repository.split("/");
4176
+ const read = await runtime.readKeyFiles({
4177
+ remote: runtime.remoteFor?.(entry.repository) ?? `${runtime.github.gitUrl}/${entry.repository}.git`,
4178
+ dir: join(root, "key-files", owner, name),
4179
+ paths: keyFilePaths(),
4180
+ token
4181
+ });
4182
+ if (!read.ok) return unread(read.reason, log);
4183
+ keyCommits[entry.repository] = read.commit;
4184
+ repositories.push({ repository: entry.repository, commit: read.commit, files: read.files });
4185
+ }
4186
+ const key = stateKey({
4187
+ factory: keyRunnerFactory(config),
4188
+ repositories,
4189
+ imageDigest: input.base.digest,
4190
+ diskBytes: input.diskBytes
4191
+ });
4192
+ const found = lookup(readRecords(savedStatesDir(root)), key, input.now.getTime());
4193
+ if (found.kind !== "none" && found.record.kind === "tar") {
4194
+ try {
4195
+ await removeSavedState(found.record, { dir: savedStatesDir(root), removeVolume: async () => void 0 });
4196
+ log(`saved state ${found.record.id} is a tar file, which this runner no longer restores; removed it; starting from a fresh disk`);
4197
+ } catch (err) {
4198
+ log(`saved state ${found.record.id} is a tar file, which this runner no longer restores, and it could not be removed: ${describeCallFailure(err)}; starting from a fresh disk`);
4199
+ }
4200
+ return { key, keyCommits };
4201
+ }
4202
+ if (found.kind === "usable" && input.allowRestore) {
4203
+ log(`starting from saved state ${found.record.id}, saved ${formatDuration(found.ageMs)} ago`);
4204
+ return { key, keyCommits, restore: { record: found.record, ageMs: found.ageMs } };
4205
+ }
4206
+ if (found.kind === "expired") {
4207
+ log(`saved state ${found.record.id} is ${formatDuration(found.ageMs)} old, past the limit of ${SAVED_STATE_MAX_AGE_MS / 864e5} days; starting from a fresh disk`);
4208
+ } else if (found.kind === "changed") {
4209
+ log(`the setup script or version files changed on the default branch since saved state ${found.record.id}: ${found.files.join(", ")}; starting from a fresh disk`);
4210
+ } else if (found.kind === "none") {
4211
+ log("no saved state matches this build's key; starting from a fresh disk");
4212
+ }
4213
+ return { key, keyCommits };
4214
+ }
4215
+ function unread(reason, log) {
4216
+ log(`this build starts from no saved state and saves none: ${reason}`);
4217
+ return { keyCommits: {}, noSave: `its key files could not be read: ${reason}` };
4218
+ }
4219
+ var RECORD_FILE = "record.json";
4220
+ var DISK_FILE = "disk.ext4";
4221
+ var WORK_ITEM_ID2 = /^[A-Za-z0-9_-]{1,64}$/;
4222
+ function itemDiskDir(configPath, organizationId, workItemId) {
3114
4223
  if (!WORK_ITEM_ID2.test(workItemId)) throw new Error(`cannot keep a disk for the work item ${JSON.stringify(workItemId)}`);
3115
4224
  return join(workspacesDir(configPath, organizationId), workItemId);
3116
4225
  }
@@ -3466,172 +4575,10 @@ async function saveMicroVmDiskState(input) {
3466
4575
  const done = { ...record, bytes: statSync(path).blocks * 512, complete: true };
3467
4576
  writeRecord2(input.dir, done);
3468
4577
  return { ok: true, record: done };
3469
- } catch (err) {
3470
- if (session !== void 0) await session.thaw().catch(() => void 0);
3471
- return discard(`the state could not be saved: ${describeCallFailure(err)}`);
3472
- }
3473
- }
3474
- var FILE_MODE = 420;
3475
- var DIR_MODE = 493;
3476
- function replaceFile(path, text2) {
3477
- const partial = `${path}.${process.pid}.partial`;
3478
- writeFileSync(partial, text2);
3479
- chmodSync(partial, FILE_MODE);
3480
- renameSync(partial, path);
3481
- }
3482
- function ghHostsYml(token) {
3483
- return [
3484
- "github.com:",
3485
- " users:",
3486
- " x-access-token:",
3487
- ` oauth_token: ${token}`,
3488
- ` oauth_token: ${token}`,
3489
- " user: x-access-token",
3490
- " git_protocol: https",
3491
- ""
3492
- ].join("\n");
3493
- }
3494
- var GH_CONFIG_YML = 'version: "1"\n';
3495
- function writeGhConfig(dir, token) {
3496
- mkdirSync(dir, { recursive: true, mode: DIR_MODE });
3497
- chmodSync(dir, DIR_MODE);
3498
- replaceFile(join(dir, "hosts.yml"), ghHostsYml(token));
3499
- replaceFile(join(dir, "config.yml"), GH_CONFIG_YML);
3500
- }
3501
- var DeliveryFailure = class extends Error {
3502
- };
3503
- var BLOCK2 = 512;
3504
- var DELIVERY_TIMEOUT_MS = 5 * 6e4;
3505
- var RECEIVE_ARGV = ["/opt/outerlayer/bin/node", "/opt/outerlayer/cli/dist/index.js", "receive-files"];
3506
- var REASON_LINE_MAX = 240;
3507
- var STEPS = {
3508
- gh: "the build's gh configuration",
3509
- "git-hooks": "the commit hooks",
3510
- context: "the staged context",
3511
- "eval-input": "the checks' input",
3512
- inbox: "the comments for the agent"
3513
- };
3514
- function field(header, at, length, text2) {
3515
- header.write(text2, at, length, "latin1");
3516
- }
3517
- function octalField(header, at, length, value) {
3518
- field(header, at, length, `${value.toString(8).padStart(length - 1, "0")}\0`);
3519
- }
3520
- function tarHeader2(name, type, mode, size) {
3521
- const header = Buffer.alloc(BLOCK2);
3522
- header.write(name, 0, 100, "utf8");
3523
- octalField(header, 100, 8, mode);
3524
- octalField(header, 108, 8, 0);
3525
- octalField(header, 116, 8, 0);
3526
- octalField(header, 124, 12, size);
3527
- octalField(header, 136, 12, 0);
3528
- field(header, 148, 8, " ");
3529
- header.write(type, 156, 1, "latin1");
3530
- field(header, 257, 6, "ustar\0");
3531
- field(header, 263, 2, "00");
3532
- let sum = 0;
3533
- for (const byte of header) sum += byte;
3534
- field(header, 148, 8, `${sum.toString(8).padStart(6, "0")}\0 `);
3535
- return header;
3536
- }
3537
- function padded(data) {
3538
- const rest = data.length % BLOCK2;
3539
- return rest === 0 ? data : Buffer.concat([data, Buffer.alloc(BLOCK2 - rest)]);
3540
- }
3541
- function paxRecord(key, value) {
3542
- const body = Buffer.from(` ${key}=${value}
3543
- `, "utf8");
3544
- let length = body.length + 1;
3545
- while (String(length).length + body.length !== length) length = String(length).length + body.length;
3546
- return Buffer.concat([Buffer.from(String(length), "latin1"), body]);
3547
- }
3548
- function packTar(entries) {
3549
- const blocks = [];
3550
- for (const entry of entries) {
3551
- const data = entry.type === "file" ? entry.data ?? Buffer.alloc(0) : Buffer.alloc(0);
3552
- const name = entry.type === "dir" && !entry.path.endsWith("/") ? `${entry.path}/` : entry.path;
3553
- if (Buffer.byteLength(name, "utf8") > 100) {
3554
- const record = paxRecord("path", name);
3555
- blocks.push(tarHeader2("PaxHeader", "x", 420, record.length), padded(record));
3556
- }
3557
- blocks.push(tarHeader2(name, entry.type === "dir" ? "5" : "0", entry.mode, data.length), padded(data));
3558
- }
3559
- blocks.push(Buffer.alloc(BLOCK2 * 2));
3560
- return Buffer.concat(blocks);
3561
- }
3562
- function fileMode(hostMode) {
3563
- return 292 | hostMode & 128 | ((hostMode & 73) === 0 ? 0 : 73);
3564
- }
3565
- function packFolder(dir, options = {}) {
3566
- const entries = options.rootMode === void 0 ? [] : [{ path: "./", type: "dir", mode: options.rootMode }];
3567
- const walk = (current, prefix) => {
3568
- for (const name of readdirSync(current).sort()) {
3569
- const path = join(current, name);
3570
- const stat = lstatSync(path);
3571
- const rel = prefix === "" ? name : `${prefix}/${name}`;
3572
- if (stat.isDirectory()) {
3573
- entries.push({ path: rel, type: "dir", mode: options.dirModes?.[rel] ?? 493 });
3574
- walk(path, rel);
3575
- } else if (stat.isFile()) {
3576
- entries.push({ path: rel, type: "file", mode: fileMode(stat.mode), data: readFileSync(path) });
3577
- }
3578
- }
3579
- };
3580
- walk(dir, "");
3581
- return packTar(entries);
3582
- }
3583
- function scrubDelivery(text2, secrets) {
3584
- let out = text2.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, "").replace(/[\u0000-\u001f\u007f-\u009f]/g, " ");
3585
- for (const secret of secrets()) if (secret !== "") out = out.split(secret).join("[redacted]");
3586
- out = out.replace(/\b(?:gh[pousr]_|github_pat_)[A-Za-z0-9_]+/g, "[redacted]");
3587
- out = out.trim();
3588
- return out.length > REASON_LINE_MAX ? `${out.slice(0, REASON_LINE_MAX)}...` : out;
3589
- }
3590
- async function deliverTar(runtime, state, input) {
3591
- try {
3592
- const result = await runtime.host.exec(
3593
- {
3594
- container: state.container,
3595
- user: RELAY_USER,
3596
- env: { literals: {}, passed: {} },
3597
- argv: [...RECEIVE_ARGV, "--into", input.into, ...input.replace === true ? ["--replace"] : []],
3598
- stdin: input.tar
3599
- },
3600
- { timeoutMs: DELIVERY_TIMEOUT_MS }
3601
- );
3602
- if (result.status === 0) return { ok: true };
3603
- const line2 = scrubDelivery(result.stderr.trim().split("\n")[0] ?? "", input.secrets);
3604
- return { ok: false, reason: `${input.step} could not be delivered (exit ${result.status})${line2 === "" ? "" : `: ${line2}`}` };
3605
- } catch (err) {
3606
- return { ok: false, reason: `${input.step} could not be delivered: ${scrubDelivery(describeCallFailure(err), input.secrets)}` };
3607
- }
3608
- }
3609
- async function deliverJobFiles(runtime, state, parts, secrets) {
3610
- for (const part of parts) {
3611
- const dir = join(state.buildDir, part === "eval-input" ? EVAL_INPUT_NAME : part);
3612
- if (!existsSync(dir)) continue;
3613
- let tar;
3614
- try {
3615
- tar = packFolder(dir);
3616
- } catch (err) {
3617
- return { ok: false, reason: `${STEPS[part]} could not be read on the host: ${scrubDelivery(describeCallFailure(err), secrets)}` };
3618
- }
3619
- const delivered = await deliverTar(runtime, state, { step: STEPS[part], tar, into: `${JOB_MOUNT}/${part}`, replace: part === "eval-input", secrets });
3620
- if (!delivered.ok) return delivered;
4578
+ } catch (err) {
4579
+ if (session !== void 0) await session.thaw().catch(() => void 0);
4580
+ return discard(`the state could not be saved: ${describeCallFailure(err)}`);
3621
4581
  }
3622
- return { ok: true };
3623
- }
3624
- function deliverGhConfig(runtime, state, secrets) {
3625
- return deliverJobFiles(runtime, state, ["gh"], secrets);
3626
- }
3627
- function deliverEvalInput(runtime, state, secrets) {
3628
- return deliverJobFiles(runtime, state, ["eval-input"], secrets);
3629
- }
3630
- async function deliverJudgeInputs(runtime, state, dir, secrets) {
3631
- return deliverTar(runtime, state, { step: "the judge's inputs", tar: packFolder(dir, { rootMode: 1023, dirModes: { home: 511, "home/tmp": 511 } }), into: JUDGE_DIR, replace: true, secrets });
3632
- }
3633
- function clearJudgeFolder(runtime, state, secrets) {
3634
- return deliverTar(runtime, state, { step: "clearing the judge's folder", tar: packTar([]), into: JUDGE_DIR, replace: true, secrets });
3635
4582
  }
3636
4583
  async function serveLease(socketPath, channel, makeServer = createServer, listenOn) {
3637
4584
  const server = makeServer((socket) => channel.accept(socket));
@@ -3688,9 +4635,9 @@ async function probeMicroVmCommand(runtime, state, offset) {
3688
4635
  return void 0;
3689
4636
  }
3690
4637
  }
3691
- var MAX_TAIL_READS2 = 8;
4638
+ var MAX_TAIL_READS3 = 8;
3692
4639
  async function copyMicroVmLogTail(runtime, state, jobDir) {
3693
- for (let reads = 0; reads < MAX_TAIL_READS2; reads++) {
4640
+ for (let reads = 0; reads < MAX_TAIL_READS3; reads++) {
3694
4641
  const offset = commandLogOffset(jobDir, state.commandLogBase);
3695
4642
  const probe = await probeMicroVmCommand(runtime, state, offset);
3696
4643
  if (probe === void 0) return false;
@@ -3786,10 +4733,6 @@ function copyJudgeTree(from, to, limits2 = { files: MAX_TREE_FILES, bytes: MAX_T
3786
4733
  walk(from, to, true);
3787
4734
  }
3788
4735
 
3789
- // src/runner/record-proofs.ts
3790
- var RECORD_PROOFS_ARGV = ["outerlayer", "work", "proofs", "--record", "--comment"];
3791
- var PROOFS_LOG = "proofs.log";
3792
-
3793
4736
  // src/runner/microvm/hooks.ts
3794
4737
  var MANAGED_NO_BUILDER_DISK_REASON = "this release of the CLI pins no builder root disk, and a managed runner builds its images in a builder microVM, never on the host. The build did not start; update the CLI";
3795
4738
  var DEFAULT_MEMORY = "8g";
@@ -4567,10 +5510,10 @@ async function syncInMicroVm(input) {
4567
5510
  async function recordProofsInMicroVm(input) {
4568
5511
  return runCliInMicroVm(input, [...RECORD_PROOFS_ARGV], PROOFS_LOG, "the microVM is gone, so its proofs cannot be recorded");
4569
5512
  }
4570
- async function runCliInMicroVm(input, argv, logName, goneReason) {
5513
+ async function runCliInMicroVm(input, argv, logName, goneReason2) {
4571
5514
  const { runtime, job } = input;
4572
5515
  const state = job.microvm;
4573
- if (!isRunning(runtime, state)) return { ok: false, reason: goneReason };
5516
+ if (!isRunning(runtime, state)) return { ok: false, reason: goneReason2 };
4574
5517
  try {
4575
5518
  const env = buildEnvironment({
4576
5519
  config: claimCalls(input.config, job),
@@ -5214,15 +6157,15 @@ function createDecryptor(deps) {
5214
6157
  server.on("clientError", (_err, socket) => socket.destroy());
5215
6158
  return {
5216
6159
  matches: (host, port) => variablesFor(decrypt.variables(), host, port).length > 0,
5217
- accept(client, head, target2) {
6160
+ accept(client2, head, target2) {
5218
6161
  const host = target2.host.toLowerCase();
5219
6162
  const leaf = decrypt.authority.leafFor(host);
5220
- let carrier = client;
6163
+ let carrier = client2;
5221
6164
  if (head.length > 0) {
5222
6165
  const inbound = new PassThrough();
5223
6166
  inbound.write(head);
5224
- client.pipe(inbound);
5225
- carrier = Duplex.from({ readable: inbound, writable: client });
6167
+ client2.pipe(inbound);
6168
+ carrier = Duplex.from({ readable: inbound, writable: client2 });
5226
6169
  }
5227
6170
  const tls = new TLSSocket(carrier, { isServer: true, secureContext: createSecureContext({ key: leaf.keyPem, cert: leaf.certPem }), ALPNProtocols: ["http/1.1"] });
5228
6171
  const agent = new Agent({ keepAlive: true, maxSockets: MAX_UPSTREAM_SOCKETS });
@@ -5251,7 +6194,7 @@ function createDecryptor(deps) {
5251
6194
  tls.once("close", () => {
5252
6195
  open.delete(tls);
5253
6196
  agent.destroy();
5254
- client.destroy();
6197
+ client2.destroy();
5255
6198
  });
5256
6199
  server.emit("connection", tls);
5257
6200
  },
@@ -5564,41 +6507,41 @@ async function startTunnel(socketPath, opts = {}) {
5564
6507
  sockets.add(socket);
5565
6508
  socket.on("close", () => sockets.delete(socket));
5566
6509
  });
5567
- server.on("connect", (req, client, head) => {
5568
- void tunnelConnect(req, client, head);
6510
+ server.on("connect", (req, client2, head) => {
6511
+ void tunnelConnect(req, client2, head);
5569
6512
  });
5570
6513
  const statusLine = (status) => `HTTP/1.1 ${status} ${status === 403 ? "Forbidden" : status === 429 ? "Too Many Requests" : "Bad Gateway"}`;
5571
- const reply = (client, status, body) => {
5572
- client.end(`${statusLine(status)}\r
6514
+ const reply = (client2, status, body) => {
6515
+ client2.end(`${statusLine(status)}\r
5573
6516
  Content-Type: text/plain\r
5574
6517
  Content-Length: ${Buffer.byteLength(body)}\r
5575
6518
  Connection: close\r
5576
6519
  \r
5577
6520
  ${body}`);
5578
6521
  };
5579
- async function tunnelConnect(req, client, head) {
5580
- client.on("error", () => client.destroy());
6522
+ async function tunnelConnect(req, client2, head) {
6523
+ client2.on("error", () => client2.destroy());
5581
6524
  const target2 = parseTarget(req.url ?? "");
5582
6525
  if (target2 === void 0) {
5583
- client.end("HTTP/1.1 400 Bad Request\r\nConnection: close\r\nContent-Length: 0\r\n\r\n");
6526
+ client2.end("HTTP/1.1 400 Bad Request\r\nConnection: close\r\nContent-Length: 0\r\n\r\n");
5584
6527
  return;
5585
6528
  }
5586
6529
  const over = admit();
5587
6530
  if (over !== void 0) {
5588
6531
  const refusal = refuseOverLimit(target2.host, over);
5589
- reply(client, refusal.status, refusal.body);
6532
+ reply(client2, refusal.status, refusal.body);
5590
6533
  return;
5591
6534
  }
5592
- client.once("close", release);
6535
+ client2.once("close", release);
5593
6536
  const decision = await decide(target2.host, target2.port);
5594
6537
  if (!decision.ok) {
5595
- reply(client, decision.status, decision.body);
6538
+ reply(client2, decision.status, decision.body);
5596
6539
  return;
5597
6540
  }
5598
6541
  if (decryptor?.matches(target2.host, target2.port) === true) {
5599
6542
  reached(target2.host);
5600
- client.write("HTTP/1.1 200 Connection Established\r\n\r\n");
5601
- decryptor.accept(client, head, { host: target2.host, port: target2.port, address: decision.address });
6543
+ client2.write("HTTP/1.1 200 Connection Established\r\n\r\n");
6544
+ decryptor.accept(client2, head, { host: target2.host, port: target2.port, address: decision.address });
5602
6545
  return;
5603
6546
  }
5604
6547
  const upstream = openConnection({ address: decision.address, port: target2.port });
@@ -5606,54 +6549,54 @@ ${body}`);
5606
6549
  const failed = (err) => {
5607
6550
  upstream.destroy();
5608
6551
  logBadGateway(`could not connect to ${target2.host}:${target2.port}, ${err === void 0 ? "ETIMEDOUT" : errorCode(err)}`);
5609
- reply(client, 502, `could not connect to ${target2.host}
6552
+ reply(client2, 502, `could not connect to ${target2.host}
5610
6553
  `);
5611
6554
  };
5612
6555
  const timedOut = () => failed();
5613
6556
  upstream.once("error", failed);
5614
6557
  upstream.once("timeout", timedOut);
5615
- client.on("close", () => upstream.destroy());
6558
+ client2.on("close", () => upstream.destroy());
5616
6559
  const established = () => {
5617
6560
  upstream.removeListener("error", failed);
5618
6561
  upstream.removeListener("timeout", timedOut);
5619
6562
  upstream.setTimeout(idleTimeoutMs, () => upstream.destroy());
5620
- upstream.on("error", (err) => client.destroy(err));
6563
+ upstream.on("error", (err) => client2.destroy(err));
5621
6564
  upstream.on("close", () => {
5622
- if (!upstream.readableEnded && !client.writableEnded) client.destroy(abortedError("the tunnel closed the connection to the server before it ended"));
5623
- else client.resume();
6565
+ if (!upstream.readableEnded && !client2.writableEnded) client2.destroy(abortedError("the tunnel closed the connection to the server before it ended"));
6566
+ else client2.resume();
5624
6567
  });
5625
6568
  const buildEnded = () => {
5626
6569
  upstream.destroy();
5627
- client.end();
6570
+ client2.end();
5628
6571
  };
5629
6572
  const metered = limits2.sendBytesPerSecond > 0 ? meter() : void 0;
5630
- if (metered === void 0) client.once("end", buildEnded);
6573
+ if (metered === void 0) client2.once("end", buildEnded);
5631
6574
  else metered.once("end", buildEnded);
5632
6575
  reached(target2.host);
5633
- client.write("HTTP/1.1 200 Connection Established\r\n\r\n");
6576
+ client2.write("HTTP/1.1 200 Connection Established\r\n\r\n");
5634
6577
  if (metered !== void 0) {
5635
6578
  if (head.length > 0) metered.write(head);
5636
6579
  } else {
5637
6580
  counts.bytesSent += head.length;
5638
6581
  upstream.write(head);
5639
6582
  }
5640
- releaseWhenStalled(client, upstream);
5641
- upstream.pipe(client);
6583
+ releaseWhenStalled(client2, upstream);
6584
+ upstream.pipe(client2);
5642
6585
  if (metered === void 0) {
5643
- client.on("data", (chunk) => {
6586
+ client2.on("data", (chunk) => {
5644
6587
  counts.bytesSent += chunk.length;
5645
6588
  persistSoon();
5646
6589
  });
5647
- client.pipe(upstream);
6590
+ client2.pipe(upstream);
5648
6591
  } else {
5649
- client.once("close", () => metered.destroy());
5650
- client.pipe(metered).pipe(upstream);
6592
+ client2.once("close", () => metered.destroy());
6593
+ client2.pipe(metered).pipe(upstream);
5651
6594
  }
5652
6595
  };
5653
6596
  if (upstream.readyState === "open") established();
5654
6597
  else upstream.once("connect", established);
5655
6598
  }
5656
- function releaseWhenStalled(client, upstream) {
6599
+ function releaseWhenStalled(client2, upstream) {
5657
6600
  let delivered = 0;
5658
6601
  upstream.on("data", (chunk) => delivered += chunk.length);
5659
6602
  let read = delivered;
@@ -5661,13 +6604,13 @@ ${body}`);
5661
6604
  const blocked = () => upstream.isPaused() || upstream.readableEnded;
5662
6605
  const check = () => {
5663
6606
  timer = void 0;
5664
- if (client.writableFinished || !blocked()) return;
6607
+ if (client2.writableFinished || !blocked()) return;
5665
6608
  if (delivered > read) {
5666
6609
  read = delivered;
5667
6610
  timer = setTimeout(check, stalledResponseMs);
5668
6611
  return;
5669
6612
  }
5670
- client.destroy(abortedError("the build stopped reading the response"));
6613
+ client2.destroy(abortedError("the build stopped reading the response"));
5671
6614
  };
5672
6615
  let clientClosed = false;
5673
6616
  const watch = () => {
@@ -5677,7 +6620,7 @@ ${body}`);
5677
6620
  };
5678
6621
  upstream.on("pause", watch);
5679
6622
  upstream.on("end", watch);
5680
- client.once("close", () => {
6623
+ client2.once("close", () => {
5681
6624
  clientClosed = true;
5682
6625
  clearTimeout(timer);
5683
6626
  });
@@ -6075,6 +7018,7 @@ async function startSender(input) {
6075
7018
  const { config, job, jobDir, deps } = input;
6076
7019
  const tag = `${itemTag(job)}`;
6077
7020
  if (job.itemKey === void 0) return void 0;
7021
+ if (job.sandbox !== void 0) return void 0;
6078
7022
  const spawnFn = deps.spawnFn ?? spawn;
6079
7023
  try {
6080
7024
  const launch = launchFor(config, job, jobDir, deps);
@@ -7705,6 +8649,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
7705
8649
  }
7706
8650
  const build = job.container === void 0 ? void 0 : { state: job.container, runtime: deps.container ?? createContainerRuntime() };
7707
8651
  const vmBuild = job.microvm === void 0 ? void 0 : { state: job.microvm, runtime: deps.container ?? createContainerRuntime() };
8652
+ const sandboxBuild = job.sandbox === void 0 ? void 0 : { state: job.sandbox, runtime: deps.container ?? createContainerRuntime() };
7708
8653
  const commandMayRun = job.pid !== void 0 && isGroupAlive(job.pid) || isContainerTracked(job) && job.exitCode === void 0;
7709
8654
  if (vmBuild !== void 0) {
7710
8655
  const sample = await sampleGuest(vmBuild.runtime, vmBuild.state);
@@ -7716,6 +8661,9 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
7716
8661
  if (vmBuild !== void 0 && isMicroVmTracked(job) && job.exitCode === void 0) {
7717
8662
  await endMicroVmCommand(vmBuild.runtime, vmBuild.state, jobDirPath, (line2) => log.error(`${tag} ${line2}`));
7718
8663
  }
8664
+ if (sandboxBuild !== void 0 && isSandboxTracked(job) && job.exitCode === void 0) {
8665
+ await endSandboxCommand(sandboxBuild.runtime, sandboxBuild.state, jobDirPath, (line2) => log.error(`${tag} ${line2}`));
8666
+ }
7719
8667
  if (build !== void 0 && commandMayRun) {
7720
8668
  if (isContainerTracked(job) && build.state.stopped !== true) {
7721
8669
  await copyCommandLogTail(build.runtime, build.state, jobDirPath).catch((err) => {
@@ -7753,14 +8701,14 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
7753
8701
  log.error(`${tag} sync skipped: ${VALUES_NOT_HELD}`);
7754
8702
  return;
7755
8703
  }
7756
- if (job.container === void 0 && job.microvm === void 0 && job.build?.exec === void 0 && workdirProblem(workdir) !== void 0) {
8704
+ if (job.container === void 0 && job.microvm === void 0 && job.sandbox === void 0 && job.build?.exec === void 0 && workdirProblem(workdir) !== void 0) {
7757
8705
  log.line(`${tag} sync skipped: workdir ${workdir} is gone`);
7758
8706
  } else if (job.itemKey === void 0) {
7759
8707
  log.line(`${tag} sync skipped: the job file holds no item key`);
7760
8708
  } else {
7761
8709
  log.line(`${tag} sync started`);
7762
8710
  const startedMs = now().getTime();
7763
- const sync = build !== void 0 ? await syncInContainer({ config, runtime: build.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : vmBuild !== void 0 ? await syncInMicroVm({ config, runtime: vmBuild.runtime, job, jobDir: jobDirPath }) : job.build?.exec !== void 0 ? await runSyncViaExec(config, job, jobDirPath, spawnFn) : await runSync(claimCalls(config, job), job.item, job.itemKey, workdir, jobDirPath, spawnFn, job.branch, job.commitIdentity?.author, spoolHomeFor(config, job));
8711
+ const sync = build !== void 0 ? await syncInContainer({ config, runtime: build.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : vmBuild !== void 0 ? await syncInMicroVm({ config, runtime: vmBuild.runtime, job, jobDir: jobDirPath }) : sandboxBuild !== void 0 ? await syncInSandbox({ config, runtime: sandboxBuild.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : job.build?.exec !== void 0 ? await runSyncViaExec(config, job, jobDirPath, spawnFn) : await runSync(claimCalls(config, job), job.item, job.itemKey, workdir, jobDirPath, spawnFn, job.branch, job.commitIdentity?.author, spoolHomeFor(config, job));
7764
8712
  const took = formatDuration(now().getTime() - startedMs);
7765
8713
  if (sync.ok) log.line(`${tag} sync ok (${took})`);
7766
8714
  else log.error(`${tag} sync failed: ${sync.reason ?? "no reason given"} \xB7 continuing`);
@@ -7829,7 +8777,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
7829
8777
  log.line(`${tag} proofs started`);
7830
8778
  const startedMs = now().getTime();
7831
8779
  try {
7832
- const recorded = build !== void 0 ? await recordProofsInContainer({ config, runtime: build.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : vmBuild !== void 0 ? await recordProofsInMicroVm({ config, runtime: vmBuild.runtime, job, jobDir: jobDirPath }) : job.build?.exec !== void 0 ? await runRecordProofsViaExec(config, job, jobDirPath, spawnFn) : await runRecordProofs(config, job, jobDirPath, spawnFn);
8780
+ const recorded = build !== void 0 ? await recordProofsInContainer({ config, runtime: build.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : vmBuild !== void 0 ? await recordProofsInMicroVm({ config, runtime: vmBuild.runtime, job, jobDir: jobDirPath }) : sandboxBuild !== void 0 ? await recordProofsInSandbox({ config, runtime: sandboxBuild.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : job.build?.exec !== void 0 ? await runRecordProofsViaExec(config, job, jobDirPath, spawnFn) : await runRecordProofs(config, job, jobDirPath, spawnFn);
7833
8781
  const took = formatDuration(now().getTime() - startedMs);
7834
8782
  if (recorded.ok) log.line(`${tag} proofs ok (${took}) \xB7 see ${PROOFS_LOG}`);
7835
8783
  else log.error(`${tag} proofs not all current (${took}): ${recorded.reason ?? "no reason given"} \xB7 see ${PROOFS_LOG} \xB7 continuing`);
@@ -7838,7 +8786,11 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
7838
8786
  }
7839
8787
  }
7840
8788
  if (valuesNotHeld && outcome === "ok" && !job.cleanupRan) log.error(`${tag} the host's judge and checks skipped: ${VALUES_NOT_HELD}`);
7841
- if (outcome === "ok" && !job.cleanupRan && job.judgeRan !== true && !valuesNotHeld) {
8789
+ if (outcome === "ok" && !job.cleanupRan && job.sandbox !== void 0 && job.judgeRan !== true) {
8790
+ job.judgeNotRun = "the host's judge and checks do not run for a build in a sandbox";
8791
+ log.line(`${tag} the host's judge and checks are not run for a build in a sandbox`);
8792
+ }
8793
+ if (outcome === "ok" && !job.cleanupRan && job.judgeRan !== true && !valuesNotHeld && job.sandbox === void 0) {
7842
8794
  setStage(job, jobDirPath, "judge");
7843
8795
  job.judgeRan = true;
7844
8796
  writeJobFile(jobFilePath, job);
@@ -7853,7 +8805,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
7853
8805
  log.error(`${tag} the host's judge stopped: ${describeCallFailure(err)} \xB7 continuing`);
7854
8806
  }
7855
8807
  }
7856
- if (outcome === "ok" && !job.cleanupRan && job.checksRan !== true && !valuesNotHeld) {
8808
+ if (outcome === "ok" && !job.cleanupRan && job.checksRan !== true && !valuesNotHeld && job.sandbox === void 0) {
7857
8809
  setStage(job, jobDirPath, "checks");
7858
8810
  job.checksRan = true;
7859
8811
  writeJobFile(jobFilePath, job);
@@ -7921,6 +8873,17 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
7921
8873
  }
7922
8874
  if (cleanedUp && !buildVmStopLogged) log.line(`${tag} build microVM stopped`);
7923
8875
  if (cleanedUp) log.line(`${tag} cleanup ok (${formatDuration(now().getTime() - cleanupStartedMs)})`);
8876
+ } else if (sandboxBuild !== void 0) {
8877
+ let cleanedUp = true;
8878
+ tunnelRecord = sandboxBuild.runtime.tunnels.get(sandboxBuild.state.buildId)?.record();
8879
+ try {
8880
+ await cleanupSandbox(sandboxBuild.runtime, sandboxBuild.state);
8881
+ log.line(`${tag} ended sandbox ${sandboxBuild.state.sandboxId}`);
8882
+ } catch (err) {
8883
+ cleanedUp = false;
8884
+ log.error(`${tag} cleanup failed: ${describeCallFailure(err)} \xB7 continuing`);
8885
+ }
8886
+ if (cleanedUp) log.line(`${tag} cleanup ok (${formatDuration(now().getTime() - cleanupStartedMs)})`);
7924
8887
  } else if (build !== void 0 || !hostMade && isBuiltinContainer(config.hooks.cleanup)) {
7925
8888
  let cleanedUp = true;
7926
8889
  if (build !== void 0) {
@@ -7934,7 +8897,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
7934
8897
  }
7935
8898
  if (cleanedUp) log.line(`${tag} cleanup ok (${formatDuration(now().getTime() - cleanupStartedMs)})`);
7936
8899
  } else {
7937
- if (!isBuiltinContainer(config.hooks.cleanup) && !isBuiltinVm(config.hooks.cleanup)) {
8900
+ if (!isBuiltinContainer(config.hooks.cleanup) && !isBuiltinVm(config.hooks.cleanup) && !isBuiltinSandbox(config.hooks.cleanup)) {
7938
8901
  const cleanupEnv = {
7939
8902
  ...jobEnv(claimCalls(config, job), job.item, job.itemKey, jobDirPath, process.env, job.branch, job.commitIdentity?.author, spoolHomeFor(config, job)),
7940
8903
  ...job.build === void 0 ? {} : { OUTERLAYER_BUILD_DIR: job.build.buildDir },
@@ -8021,7 +8984,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
8021
8984
  log.error(`${tag} report exited ${report.code} (${reportTook}) \xB7 continuing`);
8022
8985
  }
8023
8986
  }
8024
- const isolated = job.container !== void 0 || job.microvm !== void 0;
8987
+ const isolated = isIsolatedJob(job);
8025
8988
  const held3 = deps.container?.credentials.get(jobDirPath);
8026
8989
  if (held3 !== void 0) {
8027
8990
  await held3.revokeAll();
@@ -8041,7 +9004,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
8041
9004
  job.reason = scrubReason(job.commandEndReason, config, void 0, jobDirPath);
8042
9005
  }
8043
9006
  const cliVersion = deps.cliVersion ?? resolveVersion();
8044
- const base = job.environment ?? (job.microvm !== void 0 ? { isolation: "vm", cliVersion } : job.container === void 0 ? sharedUserEnvironment(cliVersion) : { isolation: "container", cliVersion });
9007
+ const base = job.environment ?? (job.microvm !== void 0 ? { isolation: "vm", cliVersion } : !isIsolatedJob(job) ? sharedUserEnvironment(cliVersion) : { isolation: "container", cliVersion });
8045
9008
  if (isolated || job.build !== void 0) {
8046
9009
  tunnelRecord ??= readTunnelRecord(join(jobDirPath, "tunnel.json"));
8047
9010
  job.environment = withTunnelRecord(base, scrubTunnelRecord(tunnelRecord, config, jobDirPath), !isolated);
@@ -8174,8 +9137,14 @@ function isContainerTracked(job) {
8174
9137
  function isMicroVmTracked(job) {
8175
9138
  return job.microvm?.tracking === "microvm";
8176
9139
  }
9140
+ function isSandboxTracked(job) {
9141
+ return job.sandbox?.tracking === "sandbox";
9142
+ }
8177
9143
  function isTracked(job) {
8178
- return isContainerTracked(job) || isMicroVmTracked(job);
9144
+ return isContainerTracked(job) || isMicroVmTracked(job) || isSandboxTracked(job);
9145
+ }
9146
+ function isIsolatedJob(job) {
9147
+ return job.container !== void 0 || job.microvm !== void 0 || job.sandbox !== void 0;
8179
9148
  }
8180
9149
  function trackingOf(job) {
8181
9150
  return job.container?.tracking ?? job.microvm?.tracking;
@@ -9556,227 +10525,6 @@ async function sweepImageBuilders(configPath, ports, onError) {
9556
10525
  }
9557
10526
  return swept;
9558
10527
  }
9559
- var noop = () => void 0;
9560
- var FRAME_HEADER_BYTES = 9;
9561
- var GOAWAY_FRAME = 7;
9562
- function describeGoawayCode(code) {
9563
- const names = [
9564
- "NO_ERROR",
9565
- "PROTOCOL_ERROR",
9566
- "INTERNAL_ERROR",
9567
- "FLOW_CONTROL_ERROR",
9568
- "SETTINGS_TIMEOUT",
9569
- "STREAM_CLOSED",
9570
- "FRAME_SIZE_ERROR",
9571
- "REFUSED_STREAM",
9572
- "CANCEL",
9573
- "COMPRESSION_ERROR",
9574
- "CONNECT_ERROR",
9575
- "ENHANCE_YOUR_CALM",
9576
- "INADEQUATE_SECURITY",
9577
- "HTTP_1_1_REQUIRED"
9578
- ];
9579
- const name = names[code];
9580
- return name === void 0 ? `error code ${code}` : `${name} (${code})`;
9581
- }
9582
- function goawayNote(label, code) {
9583
- return code === void 0 ? "" : ` \xB7 ${label} ${describeGoawayCode(code)}`;
9584
- }
9585
- function watchSentGoaway(onError) {
9586
- let head = Buffer.alloc(0);
9587
- let want = FRAME_HEADER_BYTES;
9588
- let skip = 0;
9589
- return (chunk) => {
9590
- let at = 0;
9591
- while (at < chunk.length) {
9592
- if (skip > 0) {
9593
- const n = Math.min(skip, chunk.length - at);
9594
- skip -= n;
9595
- at += n;
9596
- continue;
9597
- }
9598
- const take = Math.min(want - head.length, chunk.length - at);
9599
- head = Buffer.concat([head, chunk.subarray(at, at + take)]);
9600
- at += take;
9601
- if (head.length < want) return;
9602
- const length = head.readUIntBE(0, 3);
9603
- if (want === FRAME_HEADER_BYTES && head[3] === GOAWAY_FRAME && length >= 8) {
9604
- want = FRAME_HEADER_BYTES + 8;
9605
- continue;
9606
- }
9607
- if (want > FRAME_HEADER_BYTES) {
9608
- const code = head.readUInt32BE(FRAME_HEADER_BYTES + 4);
9609
- if (code !== http2.constants.NGHTTP2_NO_ERROR) onError(code);
9610
- }
9611
- skip = length - (want - FRAME_HEADER_BYTES);
9612
- head = Buffer.alloc(0);
9613
- want = FRAME_HEADER_BYTES;
9614
- }
9615
- };
9616
- }
9617
- function writeStringsAsBuffers(stream) {
9618
- const own = stream._writev;
9619
- if (typeof own !== "function") return;
9620
- stream._writev = function(chunks, callback) {
9621
- const buffers = chunks.map(({ chunk, encoding }) => ({
9622
- chunk: typeof chunk === "string" ? Buffer.from(chunk, encoding) : chunk,
9623
- encoding: "buffer"
9624
- }));
9625
- buffers.allBuffers = true;
9626
- own.call(this, buffers, callback);
9627
- };
9628
- }
9629
- function serveSession(transport, services, opts = {}) {
9630
- const maxStreams = opts.maxStreams ?? MAX_OPEN_STREAMS;
9631
- let open = 0;
9632
- let served = 0;
9633
- let malformed = false;
9634
- let goawayCode;
9635
- transport.on("error", noop);
9636
- const watch = watchSentGoaway((code) => {
9637
- malformed = true;
9638
- goawayCode ??= code;
9639
- setImmediate(() => session.destroy());
9640
- });
9641
- const outbound = new Transform({
9642
- transform(chunk, _encoding, done) {
9643
- watch(chunk);
9644
- done(null, chunk);
9645
- }
9646
- });
9647
- outbound.on("error", noop);
9648
- outbound.pipe(transport);
9649
- const wire = Duplex.from({ readable: transport, writable: outbound });
9650
- wire.on("error", noop);
9651
- const session = http2.performServerHandshake(wire, {
9652
- settings: { initialWindowSize: STREAM_WINDOW, enablePush: false },
9653
- streamResetBurst: STREAM_RESET_BURST,
9654
- streamResetRate: STREAM_RESET_RATE
9655
- });
9656
- try {
9657
- session.setLocalWindowSize(SESSION_WINDOW);
9658
- } catch {
9659
- }
9660
- const ended = new Promise((resolve2) => {
9661
- session.on("error", (err) => {
9662
- if (typeof err.code === "string" && err.code.startsWith("ERR_HTTP2_")) malformed = true;
9663
- });
9664
- session.on("goaway", (code) => {
9665
- if (code !== http2.constants.NGHTTP2_NO_ERROR) goawayCode ??= code;
9666
- });
9667
- session.on("close", () => resolve2({ malformed, served, goawayCode }));
9668
- });
9669
- session.on("stream", (stream, headers) => {
9670
- stream.on("error", noop);
9671
- const target2 = headers[":method"] === "POST" ? targetOfPath(headers[":path"], opts.builtIns) : void 0;
9672
- if (target2 === void 0 || open >= maxStreams) {
9673
- stream.close(http2.constants.NGHTTP2_REFUSED_STREAM);
9674
- return;
9675
- }
9676
- open++;
9677
- stream.once("close", () => {
9678
- open--;
9679
- });
9680
- writeStringsAsBuffers(stream);
9681
- if (!services.accept(target2, stream)) {
9682
- stream.close(http2.constants.NGHTTP2_REFUSED_STREAM);
9683
- return;
9684
- }
9685
- served++;
9686
- if (!stream.headersSent && !stream.destroyed) stream.respond({ ":status": 200 });
9687
- });
9688
- return {
9689
- ended,
9690
- // A session the peer is closing gracefully waits for its open streams, which a stopped container never ends: destroy it whatever its state.
9691
- close: () => {
9692
- if (!session.destroyed) session.destroy();
9693
- }
9694
- };
9695
- }
9696
- var FIRST_BACKOFF_MS = 200;
9697
- var LONGEST_BACKOFF_MS = 5e3;
9698
- var JOINED_AFTER_MS = 2e3;
9699
- var EXIT_WAIT_MS = 5e3;
9700
- var SOCKET_NOT_READY = /\b(ENOENT|ECONNREFUSED)\b/;
9701
- function exitedWithin(stream, ms) {
9702
- let timer;
9703
- const late = new Promise((resolve2) => {
9704
- timer = setTimeout(() => resolve2(void 0), ms);
9705
- timer.unref();
9706
- });
9707
- return Promise.race([stream.exited, late]).finally(() => clearTimeout(timer));
9708
- }
9709
- function superviseRelay(input) {
9710
- const sleep = input.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
9711
- const exitWaitMs = input.exitWaitMs ?? EXIT_WAIT_MS;
9712
- const now = input.now ?? Date.now;
9713
- const startedAt = now();
9714
- let closed = false;
9715
- let fatal;
9716
- let running;
9717
- let wake;
9718
- const loop = (async () => {
9719
- let malformedInARow = 0;
9720
- let backoff = FIRST_BACKOFF_MS;
9721
- let failing = false;
9722
- while (!closed && fatal === void 0) {
9723
- const startedMs = Date.now();
9724
- const stream = input.execStream({
9725
- container: input.container,
9726
- user: RELAY_USER,
9727
- env: { literals: {}, passed: {} },
9728
- argv: ["outerlayer", "broker-relay", "join"],
9729
- interactive: true
9730
- });
9731
- stream.stdin.on("error", noop);
9732
- stream.stdout.on("error", noop);
9733
- const session = serveSession(Duplex.from({ readable: stream.stdout, writable: stream.stdin }), input.services, { builtIns: input.builtIns });
9734
- running = { stream, session };
9735
- void stream.exited.then(() => session.close());
9736
- const end = await session.ended;
9737
- stream.kill();
9738
- const status = await exitedWithin(stream, exitWaitMs);
9739
- running = void 0;
9740
- if (status === void 0) input.log?.(`the relay's exec into ${input.container} did not end when killed \xB7 going on without it`);
9741
- const joined = end.served > 0 || Date.now() - startedMs >= JOINED_AFTER_MS;
9742
- if (joined) {
9743
- backoff = FIRST_BACKOFF_MS;
9744
- failing = false;
9745
- if (!closed) input.log?.(`the session with ${input.container} ended \xB7 joining again${goawayNote("GOAWAY", end.goawayCode)}`);
9746
- }
9747
- if (!end.malformed && end.served > 0) malformedInARow = 0;
9748
- if (end.malformed) {
9749
- malformedInARow++;
9750
- if (malformedInARow >= MAX_MALFORMED_SESSIONS) {
9751
- fatal = MALFORMED_REASON;
9752
- input.log?.(`the session with ${input.container} broke HTTP/2 framing ${malformedInARow} times in a row${goawayNote("last GOAWAY", end.goawayCode)} \xB7 ending the build`);
9753
- input.onFatal?.(fatal);
9754
- return;
9755
- }
9756
- } else if (!joined && !failing) {
9757
- const reason = stream.stderrTail?.().trim() ?? "";
9758
- const starting = SOCKET_NOT_READY.test(reason) && now() - startedAt < JOIN_WAIT_MS;
9759
- if (!starting) {
9760
- failing = true;
9761
- input.log?.(`could not join the relay in ${input.container}${status === 0 || status === void 0 ? "" : ` (exec exited ${status})`}${reason === "" ? "" : `: ${reason}`} \xB7 trying again`);
9762
- }
9763
- }
9764
- if (closed) return;
9765
- await Promise.race([sleep(backoff), new Promise((resolve2) => wake = resolve2)]);
9766
- backoff = Math.min(backoff * 2, LONGEST_BACKOFF_MS);
9767
- }
9768
- })();
9769
- return {
9770
- fatal: () => fatal,
9771
- close: async () => {
9772
- closed = true;
9773
- wake?.();
9774
- running?.session.close();
9775
- running?.stream.kill();
9776
- await loop;
9777
- }
9778
- };
9779
- }
9780
10528
  function gitEnv(extra) {
9781
10529
  const env = {};
9782
10530
  for (const [name, value] of Object.entries(process.env)) if (!name.startsWith("GIT_")) env[name] = value;
@@ -10365,8 +11113,8 @@ async function engineNetworkHelper(host, runnerDir2, ensure = ensureNetworkHelpe
10365
11113
 
10366
11114
  // src/runner/container/hooks.ts
10367
11115
  var MIN_ENGINE_MAJOR = 26;
10368
- var RELAY_ATTEMPTS = 20;
10369
- var RELAY_WAIT_MS = 500;
11116
+ var RELAY_ATTEMPTS2 = 20;
11117
+ var RELAY_WAIT_MS2 = 500;
10370
11118
  var BUSY_IMAGE_WAIT_MS = 5e3;
10371
11119
  var VOLUME_REMOVE_ATTEMPTS = 4;
10372
11120
  function withTunnelLog(opts, log) {
@@ -10416,6 +11164,7 @@ function createContainerRuntime(opts = {}) {
10416
11164
  upstreams: opts.upstreams,
10417
11165
  agents: opts.agents,
10418
11166
  vm,
11167
+ sandbox: createSandboxPorts(opts.sandbox, opts.hostEnv ?? process.env),
10419
11168
  cliBuild: () => cli ?? currentCliBuild(),
10420
11169
  networkHelper: opts.networkHelper ?? ((dir) => engineNetworkHelper(host, dir)),
10421
11170
  ipv6: opts.ipv6 ?? kernelHasIpv6()
@@ -10481,7 +11230,7 @@ function gitRemoteFor(runtime, input) {
10481
11230
  ...input.readOnly === true ? { readOnly: true } : {}
10482
11231
  });
10483
11232
  }
10484
- var NO_ENV = { literals: {}, passed: {} };
11233
+ var NO_ENV2 = { literals: {}, passed: {} };
10485
11234
  function transportOf(state) {
10486
11235
  const recorded = state.transport;
10487
11236
  if (recorded === void 0 || recorded === "sockets") return "sockets";
@@ -10514,17 +11263,17 @@ function rejoinBuild(runtime, state, log) {
10514
11263
  if (services?.streams === void 0 || runtime.relays.has(state.buildId) || transportOf(state) !== "exec") return;
10515
11264
  joinBuild(runtime, state, { streams: services.streams }, log);
10516
11265
  }
10517
- var RELAY_PROBE = `const s=require("net").connect(${RELAY_PORT},"127.0.0.1");s.on("connect",()=>process.exit(0));s.on("error",()=>process.exit(1));setTimeout(()=>process.exit(1),2000)`;
10518
- async function waitForRelay(runtime, state) {
10519
- for (let attempt = 0; attempt < RELAY_ATTEMPTS; attempt++) {
11266
+ var RELAY_PROBE2 = `const s=require("net").connect(${RELAY_PORT},"127.0.0.1");s.on("connect",()=>process.exit(0));s.on("error",()=>process.exit(1));setTimeout(()=>process.exit(1),2000)`;
11267
+ async function waitForRelay2(runtime, state) {
11268
+ for (let attempt = 0; attempt < RELAY_ATTEMPTS2; attempt++) {
10520
11269
  const probe = await runtime.host.exec({
10521
11270
  container: state.container,
10522
11271
  user: relayUserOf(state),
10523
- env: NO_ENV,
10524
- argv: ["/opt/outerlayer/bin/node", "-e", RELAY_PROBE]
11272
+ env: NO_ENV2,
11273
+ argv: ["/opt/outerlayer/bin/node", "-e", RELAY_PROBE2]
10525
11274
  });
10526
11275
  if (probe.status === 0) return true;
10527
- await runtime.sleep(RELAY_WAIT_MS);
11276
+ await runtime.sleep(RELAY_WAIT_MS2);
10528
11277
  }
10529
11278
  return false;
10530
11279
  }
@@ -10568,7 +11317,9 @@ async function obtainImage(input) {
10568
11317
  if (err instanceof RecipeError) {
10569
11318
  log.error(`${tag} image build for ${repository} failed: ${err.code}: ${err.message}`);
10570
11319
  const says = err.code === "image_build_out_of_memory" || err.code === "image_build_out_of_disk" || err.code === "image_builder_unavailable" || err.code === "image_builder_failed";
10571
- return { ok: false, reason: says ? err.message : err.code };
11320
+ if (says) return { ok: false, reason: err.message };
11321
+ const line2 = err.code === "build_failed" ? failedStepLineOf(err.logPath) : void 0;
11322
+ return { ok: false, reason: line2 === void 0 ? err.code : `${err.code}: ${line2}` };
10572
11323
  }
10573
11324
  return { ok: false, reason: `the image build failed: ${describeCallFailure(err)}` };
10574
11325
  }
@@ -10813,7 +11564,7 @@ async function provisionContainerOnce(input, allowRestore, itemDiskFailed) {
10813
11564
  if (started.status !== 0) return dockerFailed("starting the build's container", started);
10814
11565
  joinBuild(runtime, state, services, (line2) => log.line(`${tag} ${line2}`));
10815
11566
  if (input.aborted()) return bail("", true);
10816
- if (!await waitForRelay(runtime, state)) return bail("the relay in the build's container did not start");
11567
+ if (!await waitForRelay2(runtime, state)) return bail("the relay in the build's container did not start");
10817
11568
  const ghDelivered = await deliverJobFiles(runtime, state, ["gh"], secrets);
10818
11569
  if (!ghDelivered.ok) return bail(ghDelivered.reason);
10819
11570
  keepGhConfigCurrent(tokens, buildDir2, (err) => log.error(`${tag} the read token could not be written for gh: ${describeCallFailure(err)}`), {
@@ -10823,14 +11574,14 @@ async function provisionContainerOnce(input, allowRestore, itemDiskFailed) {
10823
11574
  delivered: readToken,
10824
11575
  onFailure: (reason) => log.error(`${tag} ${reason}`)
10825
11576
  });
10826
- const agentUidProbe = await host.exec({ container: name, user: ADDED_USER, env: NO_ENV, argv: ["id", "-u", agentUser] });
11577
+ const agentUidProbe = await host.exec({ container: name, user: ADDED_USER, env: NO_ENV2, argv: ["id", "-u", agentUser] });
10827
11578
  const agentUid = agentUidOf(agentUidProbe);
10828
11579
  const changed = userIdChangedReason(plan.restore?.record.agentUid, agentUid);
10829
11580
  if (changed !== void 0) return giveUpState(changed);
10830
- const tools = await host.exec({ container: name, user: ADDED_USER, env: NO_ENV, argv: ["cat", "/opt/outerlayer/tools.json"] });
11581
+ const tools = await host.exec({ container: name, user: ADDED_USER, env: NO_ENV2, argv: ["cat", "/opt/outerlayer/tools.json"] });
10831
11582
  const agentVersion = agentVersionOf(tools.status === 0 ? tools.stdout : "", runtime.agents, input.job);
10832
11583
  environment.agentVersion = agentVersion;
10833
- const recorded = await judgeProgramRecord((argv) => host.exec({ container: name, user: ADDED_USER, env: NO_ENV, argv }), runtime.agents);
11584
+ const recorded = await judgeProgramRecord((argv) => host.exec({ container: name, user: ADDED_USER, env: NO_ENV2, argv }), runtime.agents);
10834
11585
  if (recorded !== void 0) state.judgeProgram = recorded;
10835
11586
  input.save(state, environment);
10836
11587
  const exec = async (argv, workdir, opts) => {
@@ -11006,7 +11757,7 @@ async function signalInContainer(runtime, state, pidfile, signal) {
11006
11757
  const { status } = await runtime.host.exec({
11007
11758
  container: state.container,
11008
11759
  user: state.agentUser ?? ADDED_USER,
11009
- env: NO_ENV,
11760
+ env: NO_ENV2,
11010
11761
  argv: ["/bin/sh", "-c", senderSignalScript(pidfile, signal)]
11011
11762
  });
11012
11763
  return status === 0;
@@ -11112,7 +11863,7 @@ async function runCliInContainer(input, argv, logName) {
11112
11863
  if (network !== void 0) return { ok: false, reason: network };
11113
11864
  await runtime.host.start(state.container);
11114
11865
  state.stopped = false;
11115
- if (!await waitForRelay(runtime, state)) return { ok: false, reason: "the relay did not start again" };
11866
+ if (!await waitForRelay2(runtime, state)) return { ok: false, reason: "the relay did not start again" };
11116
11867
  rejoinBuild(runtime, state, input.log);
11117
11868
  const delivered = await redeliver(runtime, state, input.jobDir);
11118
11869
  if (!delivered.ok) return { ok: false, reason: delivered.reason };
@@ -11155,7 +11906,7 @@ async function copyTranscriptsFromContainer(runtime, state, job) {
11155
11906
  } catch (err) {
11156
11907
  return { ok: false, reason: describeCallFailure(err) };
11157
11908
  }
11158
- return copyTranscripts((argv) => runtime.host.exec({ container: state.container, user: state.agentUser ?? ADDED_USER, env: NO_ENV, argv }), void 0, runtime.agents, job);
11909
+ return copyTranscripts((argv) => runtime.host.exec({ container: state.container, user: state.agentUser ?? ADDED_USER, env: NO_ENV2, argv }), void 0, runtime.agents, job);
11159
11910
  }
11160
11911
  async function ensureContainerRunning(runtime, state) {
11161
11912
  try {
@@ -11170,7 +11921,7 @@ async function ensureContainerRunning(runtime, state) {
11170
11921
  }
11171
11922
  }
11172
11923
  function sessionGuestOfContainer(runtime, state) {
11173
- const input = (argv) => ({ container: state.container, user: state.agentUser ?? ADDED_USER, env: NO_ENV, argv });
11924
+ const input = (argv) => ({ container: state.container, user: state.agentUser ?? ADDED_USER, env: NO_ENV2, argv });
11174
11925
  return {
11175
11926
  run: (argv) => runtime.host.exec(input(argv)),
11176
11927
  stream: (argv, io) => new Promise((resolve2, reject) => {
@@ -11207,7 +11958,7 @@ async function copyHookErrors2(runtime, state, jobDir) {
11207
11958
  const started = await runtime.host.start(state.container);
11208
11959
  if (started.status !== 0) return;
11209
11960
  }
11210
- const log = await runtime.host.exec({ container: state.container, user: state.agentUser ?? ADDED_USER, env: NO_ENV, argv: ["cat", HOOK_ERRORS_IN_CONTAINER] });
11961
+ const log = await runtime.host.exec({ container: state.container, user: state.agentUser ?? ADDED_USER, env: NO_ENV2, argv: ["cat", HOOK_ERRORS_IN_CONTAINER] });
11211
11962
  if (log.status === 0 && log.stdout !== "") writeFileSync(join(jobDir, "hook-errors.log"), log.stdout);
11212
11963
  } catch {
11213
11964
  }
@@ -11258,7 +12009,7 @@ function containerJudgeEnvironment(input) {
11258
12009
  const read = await runtime.host.exec({
11259
12010
  container: state.container,
11260
12011
  user,
11261
- env: NO_ENV,
12012
+ env: NO_ENV2,
11262
12013
  argv: ["/bin/sh", "-c", `[ -f ${file} ] && [ ! -L ${file} ] && head -c ${maxBytes + 1} ${file}`]
11263
12014
  }, { timeoutMs: REPORT_READ_TIMEOUT_MS });
11264
12015
  if (read.status > 1) throw new Error(`reading the judge's ${name} exited ${read.status}: ${firstLine(read.stderr)}`);
@@ -11273,13 +12024,13 @@ function containerJudgeEnvironment(input) {
11273
12024
  const started = await runtime.host.start(state.container);
11274
12025
  if (started.status !== 0) throw new Error(`the build's container could not be started again (exit ${started.status})`);
11275
12026
  state.stopped = false;
11276
- if (!await waitForRelay(runtime, state)) throw new Error("the relay in the build's container did not start again");
12027
+ if (!await waitForRelay2(runtime, state)) throw new Error("the relay in the build's container did not start again");
11277
12028
  rejoinBuild(runtime, state, input.log);
11278
12029
  const delivered = await redeliver(runtime, state, input.jobDir);
11279
12030
  if (!delivered.ok) throw new Error(delivered.reason);
11280
12031
  },
11281
12032
  hashProgram: async () => {
11282
- return await hashJudgeProgram((argv) => runtime.host.exec({ container: state.container, user: ADDED_USER, env: NO_ENV, argv }), runtime.agents);
12033
+ return await hashJudgeProgram((argv) => runtime.host.exec({ container: state.container, user: ADDED_USER, env: NO_ENV2, argv }), runtime.agents);
11283
12034
  },
11284
12035
  prepare: async (files, tree) => {
11285
12036
  if (filesAreCopied(state)) {
@@ -11311,7 +12062,7 @@ function containerJudgeEnvironment(input) {
11311
12062
  // The judge's files belong to the build's user, and Claude Code makes some of its folders private to it, so the runner's user cannot remove them from the
11312
12063
  // host. Every capability is dropped in the container, so root there could not either; the build's user removes its own, and the runner removes the rest.
11313
12064
  clear: async () => {
11314
- const removed = await runtime.host.exec({ container: state.container, user, env: NO_ENV, argv: ["find", JUDGE_DIR, "-mindepth", "1", "-user", user, "-delete"] });
12065
+ const removed = await runtime.host.exec({ container: state.container, user, env: NO_ENV2, argv: ["find", JUDGE_DIR, "-mindepth", "1", "-user", user, "-delete"] });
11315
12066
  if (removed.status !== 0) throw new Error(`find exited ${removed.status}: ${firstLine(removed.stderr)}`);
11316
12067
  if (!filesAreCopied(state)) return;
11317
12068
  const emptied = await clearJudgeFolder(runtime, state, secretsOf(runtime, input.jobDir));
@@ -11416,7 +12167,7 @@ async function startCheckContainer(input) {
11416
12167
  const started = await host.run(containerRunArgs({ ...runInput, network: state.network, home: state.home }, runtime.agents), { logPath });
11417
12168
  if (started.status !== 0) return dockerFailed("starting the check environment's container", started);
11418
12169
  if (transport === "exec") joinBuild(runtime, state, services, (line2) => log.line(`${tag} ${line2}`));
11419
- if (!await waitForRelay(runtime, state)) return fail("the relay in the check environment's container did not start");
12170
+ if (!await waitForRelay2(runtime, state)) return fail("the relay in the check environment's container did not start");
11420
12171
  const env = checkEnvironment({ config: claimCalls(config, job), item: job.item, repository, hostEnv: runtime.hostEnv, containerEnv: built.containerEnv ?? {} });
11421
12172
  const secrets = () => tokens.issuedTokens();
11422
12173
  let delivered = false;
@@ -11454,7 +12205,7 @@ async function startCheckContainer(input) {
11454
12205
  return false;
11455
12206
  }
11456
12207
  const again = await host.start(name);
11457
- if (again.status !== 0 || !await waitForRelay(runtime, state)) return false;
12208
+ if (again.status !== 0 || !await waitForRelay2(runtime, state)) return false;
11458
12209
  rejoinBuild(runtime, state, (line2) => log.line(`${tag} ${line2}`));
11459
12210
  if (delivered) {
11460
12211
  const again2 = await deliverInput();
@@ -11949,4 +12700,4 @@ async function runHostChecks(input) {
11949
12700
  }
11950
12701
  }
11951
12702
 
11952
- export { ADOPTED_FETCH_RETRY_WINDOW_MS, ALREADY_RELEASED, AttemptLogBook, EXIT_CODE_FILE, GUEST_USAGE_INTERVAL_MS, HELPER_ENV, KIND_LABEL, LEASE_SECONDS, MAX_CHECK_ITEMS_BYTES, MICROVM_COMMAND_DIR, MIN_ENGINE_MAJOR, PLACEHOLDER_MARKER, RENEW_INTERVAL_SECONDS, RunnerInitError, agentCredentialCheck, appendCommandLog, attemptNote, checksIn, claimPermissionProblem, commandItems, commandLogOffset, containerCommandExec, createContainerRuntime, createHousekeepingDocker, createLeaseChannel, currentSkillCommand, decideHostBuildSkill, deliverCommitHooks, deliverContainerHooks, deliverExecMaven, deliverJobFiles, describeHookEnd, describeMachineDocker, detectMachine, ensureFirecrackerAndJailer, ensureNetworkReady, ensureTunnel, execArgv, execCommandLine, fetchManagedBuildSettings, fetchManagedClaudeKey, filesAreCopied, finishJob, foldSample, formerSkillProblem, formerSkillQueues, freeItemDisksUntil, gitRemoteFor, helperFirecrackerNote, helperSocketPath, holdManagedBuildSettings, holdManagedClaudeKey, hookLimitsFor, hostCommandEnvironment, hostEnvironment, housekeepingDockerIfReachable, inTeardown, installTrust, isContainerTracked, isGroupAlive, isIdle, isJudgeCheck, isMicroVmTracked, isPlaceholderCommand, isReadable, isTimedOut, isTracked, isUnfinished, itemScope, itemTag, jobEnv, jobRecordsClaim, judgeProbe, keepGhConfigCurrent, leaseExpiresAtMs, leaseTimeLeftMs, lifecycleFailureReason, lifecycleSteps, listAdoptableJobs, listItemDisks, listTrackedJobs, listUnreadableJobs, listenOnBroker, makeRecorder, managedBuildSettingsFor, measureDisk, microVmArchSupported, microVmAssetsPinned, microVmCommandLine, microVmOomKills, missingPermissionFix, missingPermissionOf, modellessProblem, modellessQueues, needsAgentCredential, needsBuildSkill, needsRenew, outcomeFromExitCode, parseCpuList, permissionModeProblem, permissionModeProblems, placeholderProblem, placeholderQueues, prepareBranch, prepareResume, prepareRunnerInit, probeCommand, probeHelper, probeMicroVmCommand, provisionContainer, provisionEnvironment, provisionMicroVm, reachDockerStep, readConfigObject, readCpuUsec, readDefinitions, readProvisionOut, readRecords, recoverLostJobs, releaseLease, removeOldestUntil, renewLease, resolveHostBuild, restartSender, restoreSessionIntoContainer, restoreSessionIntoMicroVm, retryFailedReleases, runCommand, runHook, runHostChecks, runHousekeeping, runRunnerInit, runWithSpawn, sampleGuest, savedStatesDir, scrubReason, serveLease, setStage, setUpRunnerCgroup, shellQuote, startHostServices, startMicroVmCommand, startSender, startServicesFor, stopOrphanedMicroVms, stoppedHelperReason, stripTerminalControls, supportsContainerBuilds, supportsMicroVmBuilds, sweepImageBuilders, testProofIn, timeoutAfter, unfinishedJobs, usableCpus, vmAlive, withTunnelLog, workdirProblem, writeGuestGhConfig, writeRunnerInit };
12703
+ export { ADOPTED_FETCH_RETRY_WINDOW_MS, ALREADY_RELEASED, AttemptLogBook, EXIT_CODE_FILE, GUEST_USAGE_INTERVAL_MS, HELPER_ENV, KIND_LABEL, LEASE_SECONDS, MAX_CHECK_ITEMS_BYTES, MICROVM_COMMAND_DIR, MIN_ENGINE_MAJOR, PLACEHOLDER_MARKER, RENEW_INTERVAL_SECONDS, RunnerInitError, SandboxGoneError, agentCredentialCheck, appendCommandLog, attemptNote, checksIn, claimPermissionProblem, commandItems, commandLogOffset, containerCommandExec, createContainerRuntime, createHousekeepingDocker, createLeaseChannel, currentSkillCommand, decideHostBuildSkill, deliverCommitHooks, deliverContainerHooks, deliverExecMaven, deliverJobFiles, deliverSandboxHooks, describeHookEnd, describeMachineDocker, detectMachine, ensureFirecrackerAndJailer, ensureNetworkReady, ensureTunnel, execArgv, execCommandLine, fetchManagedBuildSettings, fetchManagedClaudeKey, filesAreCopied, finishJob, foldSample, formerSkillProblem, formerSkillQueues, freeItemDisksUntil, gitRemoteFor, helperFirecrackerNote, helperSocketPath, holdManagedBuildSettings, holdManagedClaudeKey, hookLimitsFor, hostCommandEnvironment, hostEnvironment, housekeepingDockerIfReachable, inTeardown, installTrust, isContainerTracked, isGroupAlive, isIdle, isIsolatedJob, isJudgeCheck, isMicroVmTracked, isPlaceholderCommand, isReadable, isSandboxTracked, isTimedOut, isTracked, isUnfinished, itemScope, itemTag, jobEnv, jobRecordsClaim, judgeProbe, keepGhConfigCurrent, keptCommitsLine, leaseExpiresAtMs, leaseTimeLeftMs, lifecycleFailureReason, lifecycleSteps, listAdoptableJobs, listItemDisks, listTrackedJobs, listUnreadableJobs, listenOnBroker, makeRecorder, managedBuildSettingsFor, measureDisk, microVmArchSupported, microVmAssetsPinned, microVmCommandLine, microVmOomKills, missingPermissionFix, missingPermissionOf, modellessProblem, modellessQueues, needsAgentCredential, needsBuildSkill, needsRenew, outcomeFromExitCode, parseCpuList, permissionModeProblem, permissionModeProblems, placeholderProblem, placeholderQueues, prepareBranch, prepareResume, prepareRunnerInit, probeCommand, probeHelper, probeMicroVmCommand, probeSandboxCommand, provisionContainer, provisionEnvironment, provisionMicroVm, provisionSandbox, reachDockerStep, readConfigObject, readCpuUsec, readDefinitions, readProvisionOut, readRecords, recoverLostJobs, releaseLease, removeOldestUntil, renewLease, resolveHostBuild, restartSender, restoreSessionIntoContainer, restoreSessionIntoMicroVm, retryFailedReleases, runCommand, runHook, runHostChecks, runHousekeeping, runRunnerInit, runWithSpawn, sampleGuest, savedStatesDir, scrubReason, serveLease, setStage, setUpRunnerCgroup, shellQuote, startHostServices, startMicroVmCommand, startSandboxCommand, startSender, startServicesFor, stopOrphanedMicroVms, stoppedHelperReason, stripTerminalControls, supportsContainerBuilds, supportsMicroVmBuilds, sweepImageBuilders, sweepSandboxes, testProofIn, timeoutAfter, unfinishedJobs, usableCpus, vmAlive, withTunnelLog, workdirProblem, writeGuestGhConfig, writeRunnerInit };