Skip to content

feat(serve): stream per-iteration usage events for live context gauges - #127

Merged
jkyberneees merged 3 commits into
mainfrom
feat/serve-usage-events
Jul 29, 2026
Merged

feat(serve): stream per-iteration usage events for live context gauges#127
jkyberneees merged 3 commits into
mainfrom
feat/serve-usage-events

Conversation

@jkyberneees

Copy link
Copy Markdown
Contributor

Summary

odek serve previously reported token economics only on the done event (once per user prompt), so WebSocket clients like bodek could only refresh their header context gauge at the end of a run. This PR streams a usage event after every LLM turn, plus two pre-existing test-suite fixes that were blocking a green run.

Changes

  • feat(serve): stream per-iteration usage eventsIterationCallback in cmd/odek/serve.go now emits {"type":"usage","contextTokens","outputTokens"} (cumulative for the run) after every LLM turn, alongside the existing thinking streaming. Documented in the Server → Client event table in docs/WEBUI.md.
  • test(browser): auto-approve network egress in hermetic testsTestBrowser_Navigate blocked forever on an interactive TTY approval prompt ([A]pprove [D]eny [T]rust session:) because newTestBrowserTool set NonInteractive: allow, which ActionFor never consults. Now allows the network_egress and system_write (loopback httptest URLs) risk classes directly, matching the allowAllDanger idiom. go test ./cmd/odek/ completes non-interactively again.
  • test(config): scrub ODEK_ env leakage via TestMain* — 8 TestLoadConfig_* tests failed when the developer's shell exported ODEK_* vars (ODEK_MODEL, telegram vars, …), which leak into LoadConfig through os.Getenv. A TestMain scrubs ODEK_* (and legacy DEEPSEEK_API_KEY/OPENAI_API_KEY) before the run; per-test t.Setenv calls are unaffected.

Testing

  • go vet ./... — clean
  • go test -race -count=1 -run 'TestServe_E2E_(UsageEvents|TokenStats|LiveToolEvents)' ./cmd/odek/ — ok (new TestServe_E2E_UsageEvents asserts ≥2 usage events arrive before done: 100/20, then 300/60 cumulative)
  • make test (internal packages) — ok
  • go test -short -count=1 ./cmd/odek — ok (27s, no hang)
  • golangci-lint run ./cmd/odek/... ./internal/config/... — 0 issues
  • internal/config verified green with both a polluted shell (ODEK_MODEL=k3 ODEK_TELEGRAM_BOT_TOKEN=x …) and a clean one

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
odek 2eea9a3 Commit Preview URL

Branch Preview URL
Jul 29 2026, 01:12 PM

@jkyberneees
jkyberneees merged commit 5bcfd33 into main Jul 29, 2026
10 checks passed
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.

1 participant