(params: {
req: DaemonRequest;
sessionStore: SessionStore;
leaseRegistry: LeaseRegistry;
})
| 76 | | { type: 'response'; response: DaemonResponse }; |
| 77 | |
| 78 | export async function createRequestExecutionScope(params: { |
| 79 | req: DaemonRequest; |
| 80 | sessionStore: SessionStore; |
| 81 | leaseRegistry: LeaseRegistry; |
| 82 | }): Promise<RequestExecutionScope> { |
| 83 | const { sessionStore, leaseRegistry } = params; |
| 84 | let scopedReq = applyRequestCommandDefaults(scopeRequestSession(params.req)); |
| 85 | |
| 86 | const command = scopedReq.command; |
| 87 | const sessionName = resolveEffectiveSessionName(scopedReq, sessionStore); |
| 88 | const diagnosticsMeta = getDiagnosticsMeta(); |
| 89 | const sessionDir = sessionStore.resolveSessionDir(sessionName); |
| 90 | const requestLogPath = resolveSessionRequestLogPath( |
| 91 | sessionDir, |
| 92 | scopedReq.meta?.requestId ?? diagnosticsMeta.requestId, |
| 93 | ); |
| 94 | const runnerLogPath = resolveSessionRunnerLogPath(sessionDir); |
| 95 | updateDiagnosticsScope({ |
| 96 | session: sessionName, |
| 97 | logPath: requestLogPath, |
| 98 | }); |
| 99 | emitDiagnostic({ |
| 100 | level: 'info', |
| 101 | phase: 'request_start', |
| 102 | data: { |
| 103 | publicSession: scopedReq.session, |
| 104 | effectiveSession: sessionName, |
| 105 | command: scopedReq.command, |
| 106 | tenant: scopedReq.meta?.tenantId, |
| 107 | isolation: scopedReq.meta?.sessionIsolation, |
| 108 | requestLogPath, |
| 109 | runnerLogPath, |
| 110 | }, |
| 111 | }); |
| 112 | assertLockedLeaseAdmissionPreflight(scopedReq); |
| 113 | const executionLockKeys = shouldLockSessionExecution(command) |
| 114 | ? await resolveRequestExecutionLockKeys({ req: scopedReq, sessionName, sessionStore }) |
| 115 | : []; |
| 116 | const executionLocks = getLeaseRegistryExecutionLocks(leaseRegistry); |
| 117 | |
| 118 | const scope: RequestExecutionScope = { |
| 119 | req: scopedReq, |
| 120 | command, |
| 121 | sessionName, |
| 122 | requestLogPath, |
| 123 | runnerLogPath, |
| 124 | throwIfCanceled: () => throwIfRequestCanceled(scopedReq.meta?.requestId), |
| 125 | runAdmitted: async (task) => { |
| 126 | throwIfRequestCanceled(scopedReq.meta?.requestId); |
| 127 | await cleanupExpiredLeasedSession({ |
| 128 | sessionName, |
| 129 | sessionStore, |
| 130 | leaseRegistry, |
| 131 | teardownSession: teardownSessionResources, |
| 132 | }); |
| 133 | scopedReq = admitRequestLeaseForLockedScope({ |
| 134 | req: scopedReq, |
| 135 | sessionName, |
no test coverage detected