@@ -29,28 +29,43 @@ import { encryptExistingSecrets } from './utils/encrypt-existing-secrets.js'
2929const host = getHost ( )
3030const port = getPort ( )
3131
32+ const logStartupError = ( scope : string , error : unknown ) : void => {
33+ getLogger ( injector )
34+ . withScope ( scope )
35+ . error ( {
36+ message : `Background startup task failed: ${ error instanceof Error ? error . message : String ( error ) } ` ,
37+ data : { error } ,
38+ } )
39+ . catch ( ( ) => console . error ( `Background startup task failed (logger unavailable) [${ scope } ]` , error ) )
40+ }
41+
3242const setupRestApis = async ( ) => {
3343 await setupDataStore ( injector )
3444 await setupLogStore ( injector )
3545 await setupPatcher ( injector )
3646
3747 injector . get ( ExternalGitChangeListener ) . start ( )
3848
49+ // Stale-state cleanup and secret re-encryption don't gate REST availability — run them
50+ // in the background so HTTP can start accepting requests sooner.
3951 const processManager = injector . get ( ProcessManager )
40- await processManager . reconcileStaleStates ( )
52+ void processManager . reconcileStaleStates ( ) . catch ( ( error ) => logStartupError ( 'StaleStateReconciler' , error ) )
4153
42- await usingAsync ( useSystemIdentityContext ( { injector } ) , async ( elevated ) => {
54+ void usingAsync ( useSystemIdentityContext ( { injector } ) , async ( elevated ) => {
4355 await encryptExistingSecrets ( elevated )
44- } )
56+ } ) . catch ( ( error ) => logStartupError ( 'EncryptExistingSecrets' , error ) )
4557
46- await setupInstallRestApi ( injector )
47- await setupIdentityRestApi ( injector )
48- await setupStacksRestApi ( injector )
49- await setupServicesRestApi ( injector )
50- await setupGitHubReposRestApi ( injector )
51- await setupPrerequisitesRestApi ( injector )
52- await setupTokensRestApi ( injector )
53- await setupSystemRestApi ( injector )
58+ // Each module registers its own route group independently, so they can be set up concurrently.
59+ await Promise . all ( [
60+ setupInstallRestApi ( injector ) ,
61+ setupIdentityRestApi ( injector ) ,
62+ setupStacksRestApi ( injector ) ,
63+ setupServicesRestApi ( injector ) ,
64+ setupGitHubReposRestApi ( injector ) ,
65+ setupPrerequisitesRestApi ( injector ) ,
66+ setupTokensRestApi ( injector ) ,
67+ setupSystemRestApi ( injector ) ,
68+ ] )
5469
5570 const wsService = injector . get ( WebsocketService )
5671 await wsService . init ( injector )
0 commit comments