MCPcopy Create free account
hub / github.com/Noumena-Network/code / ensureSocketInitialized

Function ensureSocketInitialized

src/utils/tmuxSocket.ts:211–249  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

209 * Bash commands will run without tmux isolation.
210 */
211export async function ensureSocketInitialized(): Promise<void> {
212 // Already initialized
213 if (isSocketInitialized()) {
214 return
215 }
216
217 // Check if tmux is available before trying to use it
218 const available = await checkTmuxAvailable()
219 if (!available) {
220 return
221 }
222
223 // Another call is already initializing - wait for it but don't propagate errors
224 // The original caller handles the error and sets up graceful degradation
225 if (isInitializing && initPromise) {
226 try {
227 await initPromise
228 } catch {
229 // Ignore - the original caller logs the error
230 }
231 return
232 }
233
234 isInitializing = true
235 initPromise = doInitialize()
236
237 try {
238 await initPromise
239 } catch (error) {
240 // Log error but don't throw - graceful degradation
241 const err = toError(error)
242 logError(err)
243 logForDebugging(
244 `[Socket] Failed to initialize tmux socket: ${err.message}. Tmux isolation will be disabled.`,
245 )
246 } finally {
247 isInitializing = false
248 }
249}
250
251/**
252 * Kills the tmux server for NCode's isolated socket.

Callers 3

runFunction · 0.85
callFunction · 0.85
getEnvironmentOverridesFunction · 0.85

Calls 6

isSocketInitializedFunction · 0.85
checkTmuxAvailableFunction · 0.85
doInitializeFunction · 0.85
toErrorFunction · 0.70
logErrorFunction · 0.70
logForDebuggingFunction · 0.70

Tested by

no test coverage detected