@akanjs/devkit 3.2.0-rc.9 → 3.3.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -516
- package/DEV_RUNTIME_KNOBS.md +4 -3
- package/README.ko.md +3 -2
- package/README.md +4 -2
- package/akanApp/BackendImportGraph.test.ts +1 -1
- package/akanApp/akanApp.host.test.ts +132 -3
- package/akanApp/akanApp.host.ts +146 -1216
- package/akanApp/akanApp.host.wiring.test.ts +727 -0
- package/akanApp/builderGap.ts +68 -0
- package/akanApp/builderRequestRelay.test.ts +93 -0
- package/akanApp/builderRequestRelay.ts +100 -0
- package/akanApp/builderRssRecycler.ts +182 -0
- package/akanApp/devBackend.ts +392 -0
- package/akanApp/devBuildStatusBoard.ts +128 -0
- package/akanApp/devBuilder.ts +196 -0
- package/akanApp/devIdleSuspend.test.ts +221 -0
- package/akanApp/devIdleSuspend.ts +192 -0
- package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
- package/akanApp/devRecycler.test.ts +66 -0
- package/akanApp/devRecycler.ts +305 -0
- package/akanApp/processRss.ts +61 -0
- package/akanConfig/akanConfig.test.ts +45 -17
- package/akanConfig/akanConfig.ts +10 -10
- package/akanConfig/akanWorkspaceConfig.ts +1 -1
- package/akanConfig/productionLockfile.ts +1 -1
- package/apiReport/apiReport.test.ts +34 -3
- package/apiReport/apiReportDiff.ts +35 -1
- package/apiReport/apiReportPolicy.ts +3 -2
- package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
- package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
- package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
- package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
- package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
- package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
- package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
- package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
- package/artifact/implicitRootLayout.test.ts +71 -3
- package/artifact/implicitRootLayout.ts +9 -3
- package/artifact/implicitRootLayoutRender.test.tsx +297 -0
- package/biome.base.json +2 -1
- package/cloud/cloudApi.test.ts +1 -1
- package/cloud/configLock.test.ts +1 -1
- package/cloud/globalConfig.test.ts +1 -1
- package/cloud/globalConfig.ts +1 -1
- package/cloud/updatePackUpload.test.ts +1 -1
- package/codeAgent/agent/AkanCodeEnv.ts +1 -1
- package/codeAgent/agent/AkanCodeServices.ts +23 -0
- package/codeAgent/agent/akanCodePaths.ts +1 -1
- package/codeAgent/agent/akanCodeServices.test.ts +54 -0
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +1 -1
- package/codeAgent/skills/akan-debug/SKILL.md +8 -5
- package/codeAgent/skills/akan-err/SKILL.md +7 -0
- package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
- package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
- package/codeAgent/skills/akan-validate/SKILL.md +3 -3
- package/codeAgent/tools/AkanCli.ts +1 -1
- package/codeAgent/tools/AkanToolPack.ts +2 -2
- package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
- package/commandDecorators/command.ts +35 -6
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +107 -6
- package/commandDecorators/targetMeta.ts +2 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
- package/commandDecorators/workspaceVersionCheck.ts +64 -14
- package/context/akanContext.ts +576 -0
- package/context/akanContextInspection.ts +296 -0
- package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
- package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
- package/context/doctor/agentGuideCheck.ts +81 -0
- package/context/doctor/configLeftoverCheck.ts +35 -0
- package/context/doctor/doctorFindings.ts +70 -0
- package/context/doctor/generatedFreshness.ts +56 -0
- package/context/doctor/moduleShapeCheck.ts +88 -0
- package/context/doctor/recipeDuplicateCheck.ts +42 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
- package/context/safeRead.ts +9 -0
- package/csrE2e/csrE2eHarness.fixture.ts +1 -1
- package/devkitUtils.test.ts +39 -5
- package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
- package/{apiReference.ts → docs/apiReference.ts} +2 -2
- package/docs/errorCodeReference.test.ts +282 -0
- package/docs/errorCodeReference.ts +71 -0
- package/docs/errorCodeScan.ts +551 -0
- package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
- package/executors/appExecutor.ts +448 -0
- package/executors/commandExecutionError.ts +53 -0
- package/executors/executor.ts +527 -0
- package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
- package/{executors.test.ts → executors/executors.test.ts} +76 -15
- package/executors/index.ts +8 -0
- package/executors/libExecutor.ts +23 -0
- package/executors/moduleExecutor.ts +18 -0
- package/executors/pkgExecutor.ts +129 -0
- package/executors/sysExecutor.ts +301 -0
- package/executors/workspaceExecutor.ts +277 -0
- package/frontendBuild/allRoutesBuilder.test.ts +1 -1
- package/frontendBuild/autoImportSync.test.ts +1 -1
- package/frontendBuild/autoImportSync.ts +1 -1
- package/frontendBuild/buildRouteClient.test.ts +1 -1
- package/frontendBuild/clientEntriesBundler.test.ts +1 -1
- package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
- package/frontendBuild/csrDevArtifactWriter.ts +1 -1
- package/frontendBuild/cssCompiler.test.ts +3 -2
- package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
- package/frontendBuild/devGeneratedIndexSync.ts +7 -38
- package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
- package/frontendBuild/fontOptimizer.test.ts +1 -1
- package/frontendBuild/fontPruner.test.ts +1 -1
- package/frontendBuild/frontendBuild.test.ts +3 -3
- package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
- package/frontendBuild/hmrWatcher.test.ts +1 -1
- package/frontendBuild/hmrWatcher.ts +22 -1
- package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
- package/frontendBuild/mcpAppViewBuilder.ts +1 -1
- package/frontendBuild/nativeCore.test.ts +1 -1
- package/frontendBuild/optionalPeers.test.ts +36 -8
- package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
- package/frontendBuild/pagesBundleBuilder.ts +1 -1
- package/frontendBuild/precompressArtifacts.test.ts +1 -1
- package/frontendBuild/precompressArtifacts.ts +19 -6
- package/frontendBuild/serverGraphFile.ts +1 -1
- package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
- package/frontendBuild/ssrDevBundler.test.ts +1 -1
- package/frontendBuild/vendorImportScanner.test.ts +1 -1
- package/frontendBuild/vendorNarrowing.test.ts +1 -1
- package/frontendBuild/watchRootResolver.test.ts +1 -1
- package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
- package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
- package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
- package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
- package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
- package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
- package/{prompter.ts → guideline/prompter.ts} +2 -3
- package/incrementalBuilder/buildBatch.proc.ts +14 -4
- package/incrementalBuilder/buildBatchProtocol.ts +2 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
- package/incrementalBuilder/buildBatchRunner.ts +17 -4
- package/incrementalBuilder/builderBoot.ts +106 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.test.ts +1 -1
- package/incrementalBuilder/builderChannel.ts +11 -0
- package/incrementalBuilder/builderGraphPayloads.ts +3 -3
- package/incrementalBuilder/builderLanes.ts +157 -0
- package/incrementalBuilder/builderWatch.ts +213 -0
- package/incrementalBuilder/csrRegistry.ts +234 -0
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +101 -7
- package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
- package/incrementalBuilder/ssrRegistry.ts +282 -0
- package/index.ts +22 -22
- package/integration/devStability.integration.test.ts +62 -56
- package/integration/devStabilityHarness.test.ts +1 -1
- package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
- package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
- package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
- package/lint/gritRules.test.ts +1 -1
- package/{linter.test.ts → lint/linter.test.ts} +1 -1
- package/lint/no-import-common-err.grit +31 -0
- package/lint/no-init-fetch-in-client.grit +1 -1
- package/mobile/desktopBin.test.ts +1 -1
- package/mobile/desktopRelease.test.ts +1 -1
- package/mobile/desktopServerStage.test.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -1
- package/mobile/nativeApi.test.ts +1 -1
- package/mobile/nativeApp.test.ts +1 -1
- package/mobile/nativeConfig.test.ts +1 -1
- package/mobile/nativePluginFolders.test.ts +1 -1
- package/mobile/nativePublicEnv.test.ts +1 -1
- package/mobile/nativeWebDir.test.ts +1 -1
- package/mobile/serverBundleSecrets.test.ts +1 -1
- package/mobile/tarWriter.test.ts +1 -1
- package/mobile/updatePackFolder.test.ts +1 -1
- package/package.json +173 -9
- package/packageExports.test.ts +20 -2
- package/piDependencyPins.test.ts +1 -1
- package/pipeline/PipelineDefinition.ts +1 -1
- package/platformTest/IdleWatchedProcess.test.ts +1 -1
- package/platformTest/LinuxDockerTarget.ts +1 -1
- package/platformTest/PlatformTestRun.test.ts +1 -1
- package/platformTest/TestSnapshot.test.ts +1 -1
- package/platformTest/WindowsSshTarget.ts +1 -1
- package/preview/previewView.test.ts +23 -1
- package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
- package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
- package/quality/bareErrorScanner.ts +126 -0
- package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
- package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
- package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
- package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
- package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
- package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
- package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
- package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
- package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
- package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
- package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
- package/quality/workspaceSourceFiles.ts +82 -0
- package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
- package/{subspace.ts → subspace/subspace.ts} +5 -5
- package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
- package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
- package/{testHelpers.ts → test/testHelpers.ts} +37 -1
- package/transforms/barrelAnalyzer.ts +31 -10
- package/transforms/browserDirnamePlugin.test.ts +1 -1
- package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
- package/transforms/mcpAppPageTrimmer.test.ts +1 -1
- package/transforms/pureLazyMarker.test.ts +1 -1
- package/transforms/serverEnvPlugin.test.ts +1 -1
- package/transforms/serverEnvProfile.test.ts +1 -1
- package/transforms/sideEffectImportOrder.test.ts +1 -1
- package/transforms/transforms.test.ts +52 -2
- package/transforms/tsconfigPackageResolver.test.ts +1 -1
- package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
- package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
- package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
- package/typecheck/projectTypecheck.test.ts +23 -1
- package/typecheck/projectTypecheck.ts +10 -2
- package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
- package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
- package/typecheck/typecheck.proc.ts +6 -2
- package/typecheck/typecheckFailure.ts +1 -1
- package/util/errorReport.ts +66 -0
- package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
- package/workflow/constantSource.ts +187 -0
- package/workflow/dictionarySource.ts +184 -0
- package/workflow/executor.ts +6 -9
- package/workflow/fieldExpression.ts +153 -0
- package/workflow/fieldLabel.ts +61 -0
- package/workflow/fieldOrder.ts +117 -0
- package/workflow/fieldType.ts +2 -1
- package/workflow/guardCatalog.test.ts +1 -1
- package/workflow/keyRename.ts +1 -1
- package/workflow/moduleIndex.test.ts +2 -2
- package/workflow/moduleIndex.ts +2 -2
- package/workflow/modulePaths.ts +27 -0
- package/workflow/mutationScaffold.ts +7 -15
- package/workflow/mutationSource.ts +2 -1
- package/workflow/plan.ts +2 -1
- package/workflow/primitiveReport.ts +78 -0
- package/workflow/rolloutGate.test.ts +1 -1
- package/workflow/rolloutGate.ts +1 -1
- package/workflow/serviceSource.ts +33 -0
- package/workflow/signalSource.ts +96 -0
- package/workflow/source.ts +50 -1100
- package/workflow/sourceAst.ts +30 -0
- package/workflow/sourceImports.ts +105 -0
- package/workflow/sourceText.ts +13 -0
- package/workflow/templateSource.ts +30 -0
- package/workflow/testSource.ts +31 -0
- package/workflow/types.ts +1 -1
- package/workflow/uiPolicy.ts +1 -1
- package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
- package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
- package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
- package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
- package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
- package/{envSeed.ts → workspace/envSeed.ts} +1 -1
- package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
- package/{libSource.ts → workspace/libSource.ts} +1 -1
- package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
- package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
- package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
- package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
- package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
- package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
- package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
- package/akanContext.ts +0 -1083
- package/executors.ts +0 -1749
- /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
- /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
- /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
- /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
- /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
- /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
- /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
- /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
- /package/{linter.ts → lint/linter.ts} +0 -0
- /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
- /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
- /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
- /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
- /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
- /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
- /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
- /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
- /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
- /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
- /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
- /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
- /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
- /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
- /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
- /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
- /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
- /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
- /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
- /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
- /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
- /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
- /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
- /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
- /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
- /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
- /package/{storeSource.ts → quality/storeSource.ts} +0 -0
- /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
- /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
- /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
- /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
- /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
- /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
- /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
- /package/{writePath.ts → quality/writePath.ts} +0 -0
- /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
- /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
- /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
- /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
- /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
- /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
- /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
- /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
- /package/{fileSys.ts → util/fileSys.ts} +0 -0
- /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
- /package/{selectModel.ts → util/selectModel.ts} +0 -0
- /package/{semver.test.ts → util/semver.test.ts} +0 -0
- /package/{semver.ts → util/semver.ts} +0 -0
- /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
- /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
- /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
- /package/{spinner.ts → util/spinner.ts} +0 -0
- /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
- /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
- /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
- /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
- /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
- /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
- /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
- /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
- /package/{types.ts → workspace/types.ts} +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Logger } from "akanjs/common";
|
|
2
|
+
import type { BackendImportGraph } from "./BackendImportGraph";
|
|
3
|
+
import type { DevBackend } from "./devBackend";
|
|
4
|
+
import { filesChangedSince, type SourceFingerprints } from "./devHostPolicy";
|
|
5
|
+
|
|
6
|
+
export class BuilderGap {
|
|
7
|
+
readonly #graph: BackendImportGraph;
|
|
8
|
+
readonly #backend: DevBackend;
|
|
9
|
+
readonly #logger: Logger;
|
|
10
|
+
#stamp: Promise<SourceFingerprints | null> | null = null;
|
|
11
|
+
|
|
12
|
+
constructor({ graph, backend, logger }: { graph: BackendImportGraph; backend: DevBackend; logger: Logger }) {
|
|
13
|
+
this.#graph = graph;
|
|
14
|
+
this.#backend = backend;
|
|
15
|
+
this.#logger = logger;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Until a builder is back nothing watches (Bun's `fs.watch` drops events, a new builder primes from disk), so
|
|
19
|
+
// stamp the backend graph now. Earliest open wins: over-reporting costs a restart, under-reporting stale code.
|
|
20
|
+
open(reason: string): void {
|
|
21
|
+
if (this.#stamp) return;
|
|
22
|
+
if (!this.#graph.ready) {
|
|
23
|
+
this.#logger.verbose(`[builder-gap] no backend graph yet; a save during this ${reason} goes unnoticed`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.#stamp = this.#graph
|
|
27
|
+
.fingerprint()
|
|
28
|
+
.then((stamps) => {
|
|
29
|
+
this.#logger.verbose(`[builder-gap] stamped ${stamps.size} backend file(s) (${reason})`);
|
|
30
|
+
return stamps;
|
|
31
|
+
})
|
|
32
|
+
.catch((err) => {
|
|
33
|
+
this.#logger.warn(
|
|
34
|
+
`[builder-gap] could not stamp the backend files: ${err instanceof Error ? err.message : String(err)}`,
|
|
35
|
+
);
|
|
36
|
+
return null;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async take(): Promise<string[]> {
|
|
41
|
+
const stamping = this.#stamp;
|
|
42
|
+
this.#stamp = null;
|
|
43
|
+
const before = stamping ? await stamping : null;
|
|
44
|
+
if (!before) return [];
|
|
45
|
+
const moved = filesChangedSince(before, await this.#graph.fingerprint());
|
|
46
|
+
if (moved.length === 0) {
|
|
47
|
+
this.#logger.verbose(`[builder-gap] none of the ${before.size} stamped backend file(s) moved`);
|
|
48
|
+
return moved;
|
|
49
|
+
}
|
|
50
|
+
this.#logger.info(
|
|
51
|
+
`[builder-gap] ${moved.length} backend file(s) changed while the builder was away; the backend is running the old ones`,
|
|
52
|
+
);
|
|
53
|
+
return moved;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// A baseline left open is compared against the next gap, where everything saved since reads as changed.
|
|
57
|
+
discard(reason: string): void {
|
|
58
|
+
if (!this.#stamp) return;
|
|
59
|
+
this.#stamp = null;
|
|
60
|
+
this.#logger.verbose(`[builder-gap] stamps dropped (${reason})`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async restartBackendForChanges(): Promise<void> {
|
|
64
|
+
const moved = await this.take();
|
|
65
|
+
if (moved.length === 0) return;
|
|
66
|
+
this.#backend.scheduleRestart({ files: moved, roles: [] });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { Logger } from "akanjs/common";
|
|
3
|
+
import type { BuilderMessage, BuilderResponse } from "akanjs/server";
|
|
4
|
+
import type { IncrementalBuilderHost } from "../incrementalBuilder";
|
|
5
|
+
import { BuilderRequestRelay } from "./builderRequestRelay";
|
|
6
|
+
|
|
7
|
+
const logger = { verbose: () => undefined, warn: () => undefined } as unknown as Logger;
|
|
8
|
+
|
|
9
|
+
const graphRequest = (id: number) => ({ type: "build-graph", id }) as BuilderMessage;
|
|
10
|
+
|
|
11
|
+
const graphAnswer = (id: number, error: string) =>
|
|
12
|
+
({ type: "build-graph-res", id, ok: false, error, kind: "unavailable" }) as BuilderResponse;
|
|
13
|
+
|
|
14
|
+
const relayWith = ({ status = "ready", accepts = true }: { status?: string; accepts?: boolean } = {}) => {
|
|
15
|
+
const sent: BuilderMessage[] = [];
|
|
16
|
+
const answered: BuilderMessage[] = [];
|
|
17
|
+
const wakes: string[] = [];
|
|
18
|
+
const state = { away: false, activity: 0 };
|
|
19
|
+
const builder = {
|
|
20
|
+
status,
|
|
21
|
+
send: (message: BuilderMessage) => {
|
|
22
|
+
if (accepts) sent.push(message);
|
|
23
|
+
return accepts;
|
|
24
|
+
},
|
|
25
|
+
} as unknown as IncrementalBuilderHost;
|
|
26
|
+
const relay = new BuilderRequestRelay(
|
|
27
|
+
{ logger, env: {} },
|
|
28
|
+
{
|
|
29
|
+
builder: () => builder,
|
|
30
|
+
toBackend: (message) => answered.push(message),
|
|
31
|
+
markActivity: () => {
|
|
32
|
+
state.activity += 1;
|
|
33
|
+
},
|
|
34
|
+
away: () => state.away,
|
|
35
|
+
wake: (reason) => wakes.push(reason),
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
return { relay, sent, answered, wakes, state };
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
describe("BuilderRequestRelay", () => {
|
|
42
|
+
test("renumbers a request, and settles its answer under the backend's own id", () => {
|
|
43
|
+
const { relay, sent } = relayWith();
|
|
44
|
+
relay.startGeneration();
|
|
45
|
+
relay.send(graphRequest(1));
|
|
46
|
+
relay.send(graphRequest(1));
|
|
47
|
+
const [first, second] = sent as { id: number }[];
|
|
48
|
+
expect(first.id).not.toBe(second.id);
|
|
49
|
+
expect(relay.settle(graphAnswer(second.id, "answer"))).toEqual(graphAnswer(1, "answer"));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("a new generation drops the old one's answers", () => {
|
|
53
|
+
const { relay, sent } = relayWith();
|
|
54
|
+
relay.startGeneration();
|
|
55
|
+
relay.send(graphRequest(1));
|
|
56
|
+
relay.startGeneration();
|
|
57
|
+
expect(relay.settle(graphAnswer((sent[0] as { id: number }).id, "stale"))).toBeNull();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("holds a request while the builder is away, wakes it, and replays it on flush", () => {
|
|
61
|
+
const { relay, sent, wakes, state } = relayWith();
|
|
62
|
+
state.away = true;
|
|
63
|
+
relay.send(graphRequest(4));
|
|
64
|
+
expect(sent).toEqual([]);
|
|
65
|
+
expect(wakes).toEqual(["build-graph arrived while suspended"]);
|
|
66
|
+
expect(state.activity).toBe(1);
|
|
67
|
+
state.away = false;
|
|
68
|
+
relay.flush();
|
|
69
|
+
expect(sent).toHaveLength(1);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("discards held requests unanswered, and fails them with an answer", () => {
|
|
73
|
+
const { relay, sent, answered, state } = relayWith();
|
|
74
|
+
state.away = true;
|
|
75
|
+
relay.send(graphRequest(4));
|
|
76
|
+
relay.discard("the backend restarted");
|
|
77
|
+
state.away = false;
|
|
78
|
+
relay.flush();
|
|
79
|
+
expect(sent).toEqual([]);
|
|
80
|
+
expect(answered).toEqual([]);
|
|
81
|
+
|
|
82
|
+
state.away = true;
|
|
83
|
+
relay.send(graphRequest(5));
|
|
84
|
+
relay.fail("builder failed to start");
|
|
85
|
+
expect(answered).toEqual([graphAnswer(5, "builder failed to start")]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("answers a request no builder took under the backend's own id", () => {
|
|
89
|
+
const { relay, answered } = relayWith({ status: "stopped", accepts: false });
|
|
90
|
+
relay.send(graphRequest(9));
|
|
91
|
+
expect(answered).toEqual([graphAnswer(9, "builder is stopped; reload after the builder is ready")]);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { Logger } from "akanjs/common";
|
|
2
|
+
import type { BuilderMessage, BuilderResponse } from "akanjs/server";
|
|
3
|
+
import type { IncrementalBuilderHost } from "../incrementalBuilder";
|
|
4
|
+
import { BuilderRequestRouter } from "../incrementalBuilder/builderRequestRouter";
|
|
5
|
+
import { shouldHoldForReturningBuilder } from "./devHostPolicy";
|
|
6
|
+
|
|
7
|
+
interface BuilderRequestRelayLinks {
|
|
8
|
+
builder: () => IncrementalBuilderHost | null;
|
|
9
|
+
toBackend: (message: BuilderMessage) => void;
|
|
10
|
+
markActivity: () => void;
|
|
11
|
+
away: () => boolean;
|
|
12
|
+
wake: (reason: string) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class BuilderRequestRelay {
|
|
16
|
+
readonly #logger: Logger;
|
|
17
|
+
readonly #env: Record<string, string>;
|
|
18
|
+
readonly #links: BuilderRequestRelayLinks;
|
|
19
|
+
readonly #requests = new BuilderRequestRouter();
|
|
20
|
+
#held: BuilderMessage[] = [];
|
|
21
|
+
|
|
22
|
+
constructor({ logger, env }: { logger: Logger; env: Record<string, string> }, links: BuilderRequestRelayLinks) {
|
|
23
|
+
this.#logger = logger;
|
|
24
|
+
this.#env = env;
|
|
25
|
+
this.#links = links;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
startGeneration(): void {
|
|
29
|
+
this.#requests.startGeneration();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
settle<T extends BuilderResponse>(message: T): T | null {
|
|
33
|
+
return this.#requests.settle(message);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
send(message: BuilderMessage): void {
|
|
37
|
+
this.#links.markActivity();
|
|
38
|
+
if (this.#links.away()) {
|
|
39
|
+
this.#held.push(message);
|
|
40
|
+
this.#links.wake(`${message.type} arrived while suspended`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// In `env`, which every builder spawn re-reads, so a restarted builder stays armed for a mobile dev session. A view's
|
|
44
|
+
// shell is asked for per read, so it arms nothing.
|
|
45
|
+
if (message.type === "build-csr" && !message.shell && this.#env.AKAN_DEV_CSR_REBUILD !== "1") {
|
|
46
|
+
Object.assign(this.#env, { AKAN_DEV_CSR_REBUILD: "1" });
|
|
47
|
+
this.#logger.verbose(`[csr] armed dev CSR rebuilds (${message.reason})`);
|
|
48
|
+
}
|
|
49
|
+
const builder = this.#links.builder();
|
|
50
|
+
// Renumbered per backend generation; the failure replies below use that backend's own `message.id`.
|
|
51
|
+
if (message.type === "build-route" || message.type === "build-csr" || message.type === "build-graph") {
|
|
52
|
+
const outgoing = this.#requests.issue(message);
|
|
53
|
+
if (builder?.send(outgoing)) return;
|
|
54
|
+
this.#requests.withdraw(outgoing.id);
|
|
55
|
+
} else if (builder?.send(message)) return;
|
|
56
|
+
const status = builder?.status ?? "stopped";
|
|
57
|
+
// A returning builder is a gap, not a failure: hold the request (`BuilderRpc`'s timeout still bounds it).
|
|
58
|
+
if (shouldHoldForReturningBuilder({ status, heldCount: this.#held.length })) {
|
|
59
|
+
this.#held.push(message);
|
|
60
|
+
const request = message.type === "build-route" ? `build-route ${message.routeId}` : message.type;
|
|
61
|
+
this.#logger.verbose(`[builder] holding ${request} until the builder is ready (${this.#held.length} waiting)`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (this.#failRequest(message, `builder is ${status}; reload after the builder is ready`)) return;
|
|
65
|
+
this.#logger.warn("akanAppHost builder is not running");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
flush(): void {
|
|
69
|
+
const pending = this.#held.splice(0);
|
|
70
|
+
if (pending.length === 0) return;
|
|
71
|
+
this.#logger.verbose(`[builder] replaying ${pending.length} request(s) held while the builder was away`);
|
|
72
|
+
for (const message of pending) this.send(message);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Held requests carry the departing backend's ids, which the new one reissues from 1, so a replay would
|
|
76
|
+
// misdeliver answers; nothing is answered because the old backend is already stopped.
|
|
77
|
+
discard(reason: string): void {
|
|
78
|
+
const held = this.#held.splice(0);
|
|
79
|
+
if (held.length === 0) return;
|
|
80
|
+
this.#logger.verbose(`[builder] dropped ${held.length} held builder request(s): ${reason}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fail(reason: string): void {
|
|
84
|
+
const held = this.#held.splice(0);
|
|
85
|
+
if (held.length === 0) return;
|
|
86
|
+
this.#logger.warn(`failing ${held.length} held builder request(s): ${reason}`);
|
|
87
|
+
for (const message of held) this.#failRequest(message, reason);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#failRequest(message: BuilderMessage, error: string): boolean {
|
|
91
|
+
if (message.type === "build-route")
|
|
92
|
+
this.#links.toBackend({ type: "build-route-res", id: message.id, ok: false, error, kind: "unavailable" });
|
|
93
|
+
else if (message.type === "build-csr")
|
|
94
|
+
this.#links.toBackend({ type: "build-csr-res", id: message.id, ok: false, error, kind: "unavailable" });
|
|
95
|
+
else if (message.type === "build-graph")
|
|
96
|
+
this.#links.toBackend({ type: "build-graph-res", id: message.id, ok: false, error, kind: "unavailable" });
|
|
97
|
+
else return false;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { Logger } from "akanjs/common";
|
|
2
|
+
import type { BuilderMetrics } from "akanjs/server";
|
|
3
|
+
import { IncrementalBuilderHost } from "../incrementalBuilder";
|
|
4
|
+
import type { DevBuildStatusBoard } from "./devBuildStatusBoard";
|
|
5
|
+
import {
|
|
6
|
+
BUILDER_MIN_RSS_RECYCLE_INTERVAL_MS,
|
|
7
|
+
decideBuilderRssRecycle,
|
|
8
|
+
decideBuilderRssSettle,
|
|
9
|
+
isRssCeilingUnreachable,
|
|
10
|
+
shouldWarnBuilderRssCeilingTight,
|
|
11
|
+
} from "./devHostPolicy";
|
|
12
|
+
import { ProcessRss } from "./processRss";
|
|
13
|
+
|
|
14
|
+
const asMib = (bytes: number) => Math.round(bytes / 1024 / 1024);
|
|
15
|
+
|
|
16
|
+
// Recycling mid-burst of saves would drop watcher events still on their way to the builder.
|
|
17
|
+
const BUILDER_RSS_RECYCLE_QUIET_MS = 750;
|
|
18
|
+
|
|
19
|
+
// Linux returns about half of the bundler arenas after ~10-15s idle (macOS none), so re-read the peak before recycling.
|
|
20
|
+
const BUILDER_RSS_SETTLE_MS = 20_000;
|
|
21
|
+
|
|
22
|
+
interface BuilderRssRecyclerLinks {
|
|
23
|
+
builder: () => IncrementalBuilderHost | null;
|
|
24
|
+
away: () => boolean;
|
|
25
|
+
restartQueued: () => boolean;
|
|
26
|
+
onRecycle: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class BuilderRssRecycler {
|
|
30
|
+
readonly #logger: Logger;
|
|
31
|
+
readonly #statuses: DevBuildStatusBoard;
|
|
32
|
+
readonly #links: BuilderRssRecyclerLinks;
|
|
33
|
+
#timer: ReturnType<typeof setTimeout> | null = null;
|
|
34
|
+
#reason: string | null = null;
|
|
35
|
+
#lastRecycleAtMono: number | null = null;
|
|
36
|
+
#ceilingTightReports = 0;
|
|
37
|
+
#ceilingTightWarned = false;
|
|
38
|
+
#settleToken = 0;
|
|
39
|
+
#over: { rssBytes: number; ceilingBytes: number } | null = null;
|
|
40
|
+
#ceilingAbandoned = false;
|
|
41
|
+
|
|
42
|
+
constructor({ logger, statuses }: { logger: Logger; statuses: DevBuildStatusBoard }, links: BuilderRssRecyclerLinks) {
|
|
43
|
+
this.#logger = logger;
|
|
44
|
+
this.#statuses = statuses;
|
|
45
|
+
this.#links = links;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get armed(): boolean {
|
|
49
|
+
return !!this.#reason;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
handleMetrics(metrics: BuilderMetrics): void {
|
|
53
|
+
if (this.#ceilingAbandoned) return;
|
|
54
|
+
const ceilingBytes = IncrementalBuilderHost.maxRssBytes();
|
|
55
|
+
const decision = decideBuilderRssRecycle({
|
|
56
|
+
rssBytes: metrics.rssBytes,
|
|
57
|
+
ceilingBytes,
|
|
58
|
+
buildFailed: this.#statuses.failedAt(metrics.generation),
|
|
59
|
+
msSinceLastRecycle: this.#lastRecycleAtMono === null ? null : performance.now() - this.#lastRecycleAtMono,
|
|
60
|
+
});
|
|
61
|
+
if (decision === "below-ceiling") {
|
|
62
|
+
this.#ceilingTightReports = 0;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (decision === "unbounded") return;
|
|
66
|
+
if (decision === "build-failed") {
|
|
67
|
+
this.#logger.verbose(
|
|
68
|
+
`[builder-recycle] deferred: generation=${metrics.generation} has a failing build, so a replacement would hit the same error`,
|
|
69
|
+
);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (decision === "too-soon") {
|
|
73
|
+
this.#ceilingTightReports += 1;
|
|
74
|
+
if (this.#ceilingTightWarned || !shouldWarnBuilderRssCeilingTight(this.#ceilingTightReports)) return;
|
|
75
|
+
this.#ceilingTightWarned = true;
|
|
76
|
+
// Warn only: the per-interval recycle is the one bound between the bundler's arenas and the sandbox limit.
|
|
77
|
+
this.#logger.warn(
|
|
78
|
+
`[builder-recycle] the builder is back at ${asMib(metrics.rssBytes)}MiB within ${Math.round(BUILDER_MIN_RSS_RECYCLE_INTERVAL_MS / 1000)}s of a recycle, so the ${asMib(ceilingBytes ?? 0)}MiB ceiling costs about one boot build per interval while you keep building. Raise AKAN_BUILDER_MAX_RSS_MB if that trade is wrong for this app, or set it to 0 to leave the builder unbounded.`,
|
|
79
|
+
);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.#arm(`rss=${asMib(metrics.rssBytes)}MiB>=${asMib(ceilingBytes ?? 0)}MiB after ${metrics.workCount} build(s)`, {
|
|
83
|
+
rssBytes: metrics.rssBytes,
|
|
84
|
+
ceilingBytes: ceilingBytes ?? 0,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Read from the OS at ready: a metrics report arrives only after a build, measuring the work, not the floor.
|
|
89
|
+
async checkRecycledFloor(): Promise<void> {
|
|
90
|
+
if (this.#ceilingAbandoned || this.#lastRecycleAtMono === null) return;
|
|
91
|
+
const ceilingBytes = IncrementalBuilderHost.maxRssBytes();
|
|
92
|
+
const pid = this.#links.builder()?.pid;
|
|
93
|
+
if (!ceilingBytes || !pid) return;
|
|
94
|
+
const freshRssBytes = await ProcessRss.bytesOf(pid);
|
|
95
|
+
if (!isRssCeilingUnreachable(freshRssBytes, ceilingBytes)) return;
|
|
96
|
+
this.#ceilingAbandoned = true;
|
|
97
|
+
this.#logger.error(
|
|
98
|
+
`[builder-recycle] a freshly recycled builder is already at ${asMib(freshRssBytes ?? 0)}MiB with nothing built on demand, so the ${asMib(ceilingBytes)}MiB ceiling cannot be met for this app; no longer enforcing it this session. Raise AKAN_BUILDER_MAX_RSS_MB, or set it to 0 to leave the builder unbounded.`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
rearm(): void {
|
|
103
|
+
if (this.#reason) this.#arm(this.#reason);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
cancel(): void {
|
|
107
|
+
this.#reason = null;
|
|
108
|
+
this.#over = null;
|
|
109
|
+
// Also drops any settle check already waiting, which would otherwise recycle after the cancel.
|
|
110
|
+
this.#settleToken += 1;
|
|
111
|
+
if (!this.#timer) return;
|
|
112
|
+
clearTimeout(this.#timer);
|
|
113
|
+
this.#timer = null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#arm(reason: string, over?: { rssBytes: number; ceilingBytes: number }): void {
|
|
117
|
+
if (this.#reason !== reason)
|
|
118
|
+
this.#logger.verbose(`[builder-recycle] armed (${reason}); replacing the builder once it stays quiet`);
|
|
119
|
+
this.#reason = reason;
|
|
120
|
+
// A field, not the closure: `rearm` re-arms with the reason alone and must keep the sample.
|
|
121
|
+
if (over) this.#over = over;
|
|
122
|
+
if (this.#timer) clearTimeout(this.#timer);
|
|
123
|
+
this.#timer = setTimeout(() => {
|
|
124
|
+
this.#timer = null;
|
|
125
|
+
const pendingReason = this.#reason;
|
|
126
|
+
const pendingOver = this.#over;
|
|
127
|
+
this.#reason = null;
|
|
128
|
+
this.#over = null;
|
|
129
|
+
if (!pendingReason) return;
|
|
130
|
+
if (!pendingOver) {
|
|
131
|
+
this.#recycle(pendingReason);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
void this.#recycleWhenStillOver(pendingReason, pendingOver);
|
|
135
|
+
}, BUILDER_RSS_RECYCLE_QUIET_MS);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async #recycleWhenStillOver(
|
|
139
|
+
reason: string,
|
|
140
|
+
{ rssBytes, ceilingBytes }: { rssBytes: number; ceilingBytes: number },
|
|
141
|
+
): Promise<void> {
|
|
142
|
+
if (decideBuilderRssSettle({ rssBytes, ceilingBytes }) === "recycle-now") {
|
|
143
|
+
this.#recycle(reason);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const pid = this.#links.builder()?.pid;
|
|
147
|
+
if (!pid) {
|
|
148
|
+
this.#recycle(reason);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
this.#settleToken += 1;
|
|
152
|
+
const token = this.#settleToken;
|
|
153
|
+
this.#logger.verbose(
|
|
154
|
+
`[builder-recycle] holding ${Math.round(BUILDER_RSS_SETTLE_MS / 1000)}s to see whether the allocator returns it (${reason})`,
|
|
155
|
+
);
|
|
156
|
+
await Bun.sleep(BUILDER_RSS_SETTLE_MS);
|
|
157
|
+
if (token !== this.#settleToken || this.#links.builder()?.pid !== pid || this.#links.away()) {
|
|
158
|
+
this.#logger.verbose("[builder-recycle] settle check abandoned; the builder moved on");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const settledBytes = await ProcessRss.bytesOf(pid);
|
|
162
|
+
if (settledBytes !== null && settledBytes < ceilingBytes) {
|
|
163
|
+
this.#logger.info(
|
|
164
|
+
`[builder-recycle] skipped: the builder fell to ${asMib(settledBytes)}MiB (ceiling ${asMib(ceilingBytes)}MiB) on its own, so a recycle would have cost a boot build for nothing`,
|
|
165
|
+
);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
this.#recycle(settledBytes === null ? reason : `${reason}; still ${asMib(settledBytes)}MiB after settling`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
#recycle(reason: string): void {
|
|
172
|
+
// Dropping the recycle costs nothing: the next build re-reports an over-ceiling rss and re-arms it.
|
|
173
|
+
if (this.#links.restartQueued()) {
|
|
174
|
+
this.#logger.verbose(`[builder-recycle] skipped (${reason}); a dev restart is already pending`);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (!this.#links.builder()?.recycle(reason)) return;
|
|
178
|
+
this.#lastRecycleAtMono = performance.now();
|
|
179
|
+
// Stamped at the request, not the exit: a draining builder has already stopped taking work.
|
|
180
|
+
this.#links.onRecycle();
|
|
181
|
+
}
|
|
182
|
+
}
|