diff --git a/examples/cuda-fanout/gpu-worker.lsp b/examples/cuda-fanout/gpu-worker.lsp index 8eab693..07b27c8 100644 --- a/examples/cuda-fanout/gpu-worker.lsp +++ b/examples/cuda-fanout/gpu-worker.lsp @@ -215,22 +215,34 @@ ;; Pull a numeric value out of a parsed portal expression for telemetry. ;; Walks (a b c ...) looking for (name ); returns #f if missing. (define (portal-find-number form name) - (let loop ((rest (cdr form))) - (cond - ((null? rest) #f) - ((and (pair? (car rest)) (eq? (car (car rest)) name) - (pair? (cdr (car rest))) (number? (car (cdr (car rest))))) - (car (cdr (car rest)))) - (else (loop (cdr rest)))))) + ;; Guard: form may arrive as #f when read-from-string sees an empty + ;; or malformed portal file (demo_ops crashed mid-write, OOM, etc). + ;; A bare (cdr #f) here historically crashed the gpu-worker with + ;; "error: not a pair: #f", taking the port-8320 listener down. + (cond + ((not (pair? form)) #f) + (else + (let loop ((rest (cdr form))) + (cond + ((null? rest) #f) + ((not (pair? rest)) #f) + ((and (pair? (car rest)) (eq? (car (car rest)) name) + (pair? (cdr (car rest))) (number? (car (cdr (car rest))))) + (car (cdr (car rest)))) + (else (loop (cdr rest)))))))) ;; Walk through (timing-ms (cpu-total X) (gpu-kernel Y)) shape. (define (portal-timing form which) - (let loop ((rest (cdr form))) - (cond - ((null? rest) #f) - ((and (pair? (car rest)) (eq? (car (car rest)) 'timing-ms)) - (portal-find-number (car rest) which)) - (else (loop (cdr rest)))))) + (cond + ((not (pair? form)) #f) + (else + (let loop ((rest (cdr form))) + (cond + ((null? rest) #f) + ((not (pair? rest)) #f) + ((and (pair? (car rest)) (eq? (car (car rest)) 'timing-ms)) + (portal-find-number (car rest) which)) + (else (loop (cdr rest)))))))) (define (handle-cuda-sim-ops-bin args) (let* ((ops-path (car args))