Skip to content

Live run logs via SSE log-watch - #325

Merged
mxschmitt merged 2 commits into
mainfrom
cursor/live-log-streaming-aaa9
Sep 4, 2026
Merged

Live run logs via SSE log-watch#325
mxschmitt merged 2 commits into
mainfrom
cursor/live-log-streaming-aaa9

Conversation

@mxschmitt

@mxschmitt mxschmitt commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Summary

Runs can now stream worker stdout/stderr while the process is still executing.

  • Workers publish AMQP log events (line-buffered, stdbuf/PYTHONUNBUFFERED/python -u) then a done payload with files as before.
  • POST /service/control/run with Accept: text/event-stream returns 202 { id } immediately (Firefox first-byte / no held POST).
  • GET /service/control/run/:id/log-watch is SSE (: connected, event: log, event: done). Late subscribers get a replay.
  • Clients that do not send Accept: text/event-stream still wait for the existing JSON body (success, output, files, version, duration), so current API e2e keeps working.
  • Frontend uses EventSource and paints logs as they arrive.

No Redis and no worker self-registration; one-shot pods and RabbitMQ stay as they are.

Test plan

  • gofmt; go test ./...; go build ./...
  • frontend: npm run build; Playwright CT chromium
  • k3s (local images live-logs): JSON POST /run still returns "output":"2"; SSE log-watch emits early then done (~3s); POST TTFB ~160ms for 202
  • e2e --project=api against port-forwarded frontend: 9 passed including live-logs
  • Chromium UI: share Run shows console text; example 5 eventually passed (wait is now the duration line)

Refs #320 #321

Open in Web Open in Cursor 

cursoragent and others added 2 commits September 3, 2026 22:11
POST /run can return 202 {id} for Accept: text/event-stream; GET
/run/:id/log-watch streams stdout as SSE. Workers emit AMQP log events
while the process runs, then a done payload. JSON clients still wait
for the existing response body.

Co-authored-by: Max Schmitt <max@schmitt.mx>
Restore the truncated C# API example, avoid template-literal parsing
issues in the new SSE test, and wait for the duration line instead of
EventSource finished() so visual runs are not racy with one worker.

Co-authored-by: Max Schmitt <max@schmitt.mx>
@mxschmitt
mxschmitt marked this pull request as ready for review September 4, 2026 05:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T05:12:17.145760Z b2b2e5a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@mxschmitt
mxschmitt merged commit 758d265 into main Sep 4, 2026
12 checks passed
@mxschmitt
mxschmitt deleted the cursor/live-log-streaming-aaa9 branch September 4, 2026 05:09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2b2e5ace3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread control-service/runs.go
Comment on lines +52 to +54
s.mu.Lock()
s.logs = append(s.logs, line)
subs := append([]chan runEvent(nil), s.subs...)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bound retained run logs

Bound the replay history by bytes or lines before appending here. A user-controlled snippet can continuously print output for the full execution window, and the shared control-service now retains every line in memory until the session TTL in addition to the worker's output buffer; unlike before, the control process receives this data incrementally even if the disposable worker later exhausts its own 1 GiB limit, so one or several noisy runs can exhaust the control service or node.

Useful? React with 👍 / 👎.

Comment thread control-service/runs.go
Comment on lines +80 to +84
for _, ch := range subs {
ch <- ev
close(ch)
}
s.markFinished()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid blocking completion on slow subscribers

Make terminal delivery nonblocking or mark the session finished before notifying subscribers. If an SSE client stops consuming while its 256-entry channel is full, this send blocks after s.done has been set but before finished is closed; the timeout path then sees the existing result and returns without closing finished, so worker cleanup and replacement never run and repeated slow clients can exhaust the worker pool.

Useful? React with 👍 / 👎.

Comment thread control-service/runs.go
Comment on lines +118 to +120
for _, line := range s.logs {
ch <- runEvent{Type: workertypes.WorkerEventLog, Line: line}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent replay from blocking under the session mutex

Do not synchronously enqueue an unbounded replay into this fixed 256-entry channel. When a run emits more than 256 lines before the browser attaches—or when a completed run with that history is opened—the 257th send blocks while s.mu is held, preventing Complete or Fail from acquiring the mutex; the SSE request never starts draining the channel, and the associated worker is never cleaned up or replaced.

Useful? React with 👍 / 👎.

Comment thread internal/worker/worker.go
Comment on lines +180 to +184
scanner := bufio.NewScanner(pr)
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
for scanner.Scan() {
w.emitLog(scanner.Text())
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep draining output after oversized log lines

Handle scanner token overflow without abandoning the pipe reader. For a snippet that writes a line longer than 1 MiB (for example, a large serialized value without a newline), Scanner.Scan stops with ErrTooLong; because pr is left open and its error is ignored, the command's stdout-copy goroutine remains blocked writing to pw, causing c.Run() to wait indefinitely and turning an otherwise finite execution into the 60-second timeout.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants