bend: handler returns formatted string + http-listener ships strings raw

The previous attempt to ship a pretty summary via an (summary "...")
field inside the structured response broke on the asm (WAT) tier
because read-from-string isn't a primitive there — the demo
extraction fell through to the raw fallback and dumped the entire
escaped S-expression.

Two-part fix that works on all three tiers:

  http-listener (gpu-worker.lsp:1103-1116) — POST response builder
  now checks if the handle-request return value is a string and
  ships it as the raw HTTP body in that case. S-expression returns
  still go through write-to-string. One-line guard, no impact on
  ping/health/cuda-shake-fanout/cuda-sim-ops-bin which all keep
  returning structured S-exps.

  handle-cuda-secp256k1-bench — returns the formatted summary
  string directly instead of an (ok ... (summary ...)) wrapping.
  Drops the now-redundant structured fields; every number lives
  inside the human-readable text already. asm / c / python demo
  just calls (display (bend!-call "(cuda-secp256k1-bench N)")) and
  the formatted output panel renders identically on all tiers.

Demo simplified accordingly: three (display (bend!-call …)) calls
with newlines between, no read-from-string / assoc / pair? dance.
This commit is contained in:
russell@unturf.com 2026-06-14 20:15:37 -04:00
parent 8edb752382
commit 036fab47fa
No known key found for this signature in database
3 changed files with 31 additions and 40 deletions

View file

@ -450,15 +450,12 @@
(display count) (display count)
(display " gpu-ms=") (display gpu-ms) (display " gpu-ms=") (display gpu-ms)
(display " mkeys-s=") (display gpu-rate) (newline) (display " mkeys-s=") (display gpu-rate) (newline)
(list 'ok ;; Return the formatted summary string directly
(list 'n count) ;; (caught by http-listener's string? guard, sent
(list 'gen-ms gen-ms) ;; raw — no S-exp escape soup in the playground
(list 'gpu-ms gpu-ms) ;; output). The structured fields all live inside
(list 'gpu-mkeys-per-sec gpu-rate) ;; the human text.
(list 'cpu-rate-mkeys-per-sec cpu-rate) summary)))))))))))
(list 'cpu-est-sec cpu-est-sec)
(list 'speedup-est speedup)
(list 'summary summary)))))))))))))
;; Format a non-negative integer with thousand-separator commas. ;; Format a non-negative integer with thousand-separator commas.
;; (with-commas 100000000) → "100,000,000". ;; (with-commas 100000000) → "100,000,000".
@ -1103,7 +1100,15 @@
((string=? method "POST") ((string=? method "POST")
(let* ((sexp (read-from-string body)) (let* ((sexp (read-from-string body))
(resp (handle-request sexp)) (resp (handle-request sexp))
(resp-text (write-to-string resp))) ;; Pre-formatted text responses (e.g. the bench's
;; pretty summary) come back as a string; send raw
;; so the browser sees clean multi-line text
;; instead of an escape-quoted "\"...\\n...\"".
;; Structured S-exp responses still get
;; write-to-string.
(resp-text (cond
((string? resp) resp)
(else (write-to-string resp)))))
(write-http-response client 200 resp-text (write-http-response client 200 resp-text
"text/plain; charset=utf-8") "text/plain; charset=utf-8")
(tcp-close client))) (tcp-close client)))

View file

@ -12,29 +12,22 @@
; on a single CPU core (libsecp256k1 ~50K keys/s) the same workload ; on a single CPU core (libsecp256k1 ~50K keys/s) the same workload
; would take more than half an hour. ; would take more than half an hour.
; ;
; The output panel shows the formatted result the worker built for ; The bench op returns a pre-formatted multi-line string (the http
; us. read-from-string + assoc are portable across all three tiers ; listener detects string responses and ships them raw, no S-exp
; so this same source file runs identically under asm / c / python. ; escape soup) so the playground output panel shows clean prose on
; every tier — asm / c / python all use the same demo source.
(display ";; 1. probe round-trip ...") (newline) (display ";; 1. probe round-trip ...") (newline)
(define r1 (bend!-call "(ping)")) (display " (ping) → ") (display (bend!-call "(ping)")) (newline)
(display " (ping) → ") (display r1) (newline)
(newline) (newline)
(display ";; 2. worker telemetry ...") (newline) (display ";; 2. worker telemetry ...") (newline)
(define r2 (bend!-call "(health)")) (display " (health) → ") (display (bend!-call "(health)")) (newline)
(display " (health) → ") (display r2) (newline)
(newline) (newline)
(display ";; 3. heavy GPU compute ...") (newline) (display ";; 3. heavy GPU compute — sit tight, this is real math") (newline)
(display ";; sit tight — this is real math, not a mock") (newline)
(newline) (newline)
(define r3 (bend!-call "(cuda-secp256k1-bench 100000000)")) (display (bend!-call "(cuda-secp256k1-bench 100000000)")) (newline)
(define parsed (read-from-string r3))
(define summary-pair (assoc 'summary (cdr parsed)))
(cond
((pair? summary-pair) (display (car (cdr summary-pair))) (newline))
(else (display "raw response: ") (display r3) (newline)))
(newline) (newline)
(print "(your laptop never did the math — it just watched it complete)") (print "(your laptop never did the math — it just watched it complete)")

View file

@ -12,29 +12,22 @@
; on a single CPU core (libsecp256k1 ~50K keys/s) the same workload ; on a single CPU core (libsecp256k1 ~50K keys/s) the same workload
; would take more than half an hour. ; would take more than half an hour.
; ;
; The output panel shows the formatted result the worker built for ; The bench op returns a pre-formatted multi-line string (the http
; us. read-from-string + assoc are portable across all three tiers ; listener detects string responses and ships them raw, no S-exp
; so this same source file runs identically under asm / c / python. ; escape soup) so the playground output panel shows clean prose on
; every tier — asm / c / python all use the same demo source.
(display ";; 1. probe round-trip ...") (newline) (display ";; 1. probe round-trip ...") (newline)
(define r1 (bend!-call "(ping)")) (display " (ping) → ") (display (bend!-call "(ping)")) (newline)
(display " (ping) → ") (display r1) (newline)
(newline) (newline)
(display ";; 2. worker telemetry ...") (newline) (display ";; 2. worker telemetry ...") (newline)
(define r2 (bend!-call "(health)")) (display " (health) → ") (display (bend!-call "(health)")) (newline)
(display " (health) → ") (display r2) (newline)
(newline) (newline)
(display ";; 3. heavy GPU compute ...") (newline) (display ";; 3. heavy GPU compute — sit tight, this is real math") (newline)
(display ";; sit tight — this is real math, not a mock") (newline)
(newline) (newline)
(define r3 (bend!-call "(cuda-secp256k1-bench 100000000)")) (display (bend!-call "(cuda-secp256k1-bench 100000000)")) (newline)
(define parsed (read-from-string r3))
(define summary-pair (assoc 'summary (cdr parsed)))
(cond
((pair? summary-pair) (display (car (cdr summary-pair))) (newline))
(else (display "raw response: ") (display r3) (newline)))
(newline) (newline)
(print "(your laptop never did the math — it just watched it complete)") (print "(your laptop never did the math — it just watched it complete)")