@@ -7,14 +7,24 @@ import { assertRuntimeBundle, resolvePlatformPackage } from './platform.mjs';
77import { ensureFile , isPidRunning , openExternal , spawnBackground , spawnForeground , terminateProcess , waitForProcessExit } from './process-utils.mjs' ;
88import { buildRuntimeState , clearRuntimeState , ensureStateDirs , readPackageVersion , readRuntimeState , readLogTail , writeRuntimeState } from './state.mjs' ;
99
10+ const DEFAULT_START_TIMEOUT_MS = 15000 ;
11+
12+ function resolveStartTimeout ( input , env ) {
13+ const candidate = input ?? env ?. CODER_STUDIO_START_TIMEOUT_MS ;
14+ const timeout = Number ( candidate ) ;
15+ return Number . isFinite ( timeout ) && timeout > 0 ? timeout : DEFAULT_START_TIMEOUT_MS ;
16+ }
17+
1018function resolveOptions ( input = { } ) {
1119 const stateDir = input . stateDir || resolveStateDir ( input . env ) ;
20+ const env = input . env || process . env ;
1221 const host = input . host || DEFAULT_HOST ;
1322 const port = Number ( input . port ?? DEFAULT_PORT ) ;
1423 const endpoint = input . endpoint || buildEndpoint ( host , port ) ;
15- const dataDir = input . dataDir || resolveDataDir ( stateDir , input . env ) ;
24+ const dataDir = input . dataDir || resolveDataDir ( stateDir , env ) ;
1625 const logPath = input . logPath || resolveLogPath ( stateDir ) ;
1726 const tailLines = Number ( input . tailLines ?? DEFAULT_LOG_TAIL_LINES ) ;
27+ const timeoutMs = resolveStartTimeout ( input . timeoutMs , env ) ;
1828 return {
1929 ...input ,
2030 stateDir,
@@ -23,9 +33,10 @@ function resolveOptions(input = {}) {
2333 endpoint,
2434 dataDir,
2535 logPath,
36+ timeoutMs,
2637 tailLines : Number . isFinite ( tailLines ) && tailLines > 0 ? tailLines : DEFAULT_LOG_TAIL_LINES ,
2738 openCommand : input . openCommand || null ,
28- env : input . env || process . env
39+ env
2940 } ;
3041}
3142
@@ -192,7 +203,7 @@ export async function startRuntime(input = {}) {
192203 const errorPromise = once ( child , 'error' ) . then ( ( [ error ] ) => { throw error ; } ) ;
193204
194205 await Promise . race ( [
195- waitForReady ( options . endpoint , child . pid , options . timeoutMs ?? 15000 ) ,
206+ waitForReady ( options . endpoint , child . pid , options . timeoutMs ) ,
196207 exitPromise . then ( ( ) => {
197208 throw new Error ( 'runtime_exited_early' ) ;
198209 } ) ,
@@ -250,7 +261,7 @@ export async function startRuntime(input = {}) {
250261
251262 try {
252263 await Promise . race ( [
253- waitForReady ( options . endpoint , child . pid , options . timeoutMs ?? 15000 ) ,
264+ waitForReady ( options . endpoint , child . pid , options . timeoutMs ) ,
254265 exitPromise . then ( ( ) => {
255266 throw new Error ( 'runtime_exited_early' ) ;
256267 } ) ,
0 commit comments