Skip to content

fix(py): write Dev UI runtime files at the project root and bring reflection v1/v2 to parity - #53

Merged
huangjeff5 merged 8 commits into
mainfrom
fix/py-1.0-pr6-devui-middleware-mcp
Nov 12, 2026
Merged

huangjeff5 merged 8 commits into
mainfrom
fix/py-1.0-pr6-devui-middleware-mcp

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Four things broke the local dev loop. An app started with genkit start from a subdirectory never showed up in the Dev UI. Large payloads such as screenshots dropped the reflection v2 connection. Re-running a notebook cell failed on duplicate value/schema registration and on run_main() inside Jupyter. Default logs went to stdout, which corrupted output piped from the CLI.

# $ cd services/menu && genkit start -- uv run python main.py
# (repo root has pyproject.toml)

# before
# => runtime file written to services/menu/.genkit/runtimes; the CLI never sees the app
# after
# => runtime file written to <repo>/.genkit/runtimes; the Dev UI connects

# Inside Jupyter
ai.run_main(main())
# before
# => RuntimeError: asyncio.run() cannot be called from a running event loop
#    RuntimeWarning: coroutine 'main' was never awaited
# after
# => RuntimeError: ai.run_main() cannot be called from a running event loop (Jupyter, IPython, or an async framework). Use `await main()` instead.

Changes

  • Runtime files land at the project root: RuntimeManager wrote to cwd/.genkit/runtimes, so an app launched from a subdirectory was invisible to the CLI. It now walks up to the nearest project marker (pyproject.toml, package.json, go.mod, requirements.txt, and others), the same way the CLI does. On exit it removes only directories this process created, and only if empty, so genkit start keeps watching the directory across restarts.
  • Reflection v1 and v2 match what the CLI expects: v1 flushes the root span before answering /api/runAction, so the trace is complete when the Dev UI fetches it, puts the Python traceback in error.details.stack, returns 503 on /api/__health?id= for a stale runtime file, enables log export and CLI version warnings on /api/notify, and returns 400 when key is missing instead of a 500. v2 raises the WebSocket message cap from 1 MiB to 100 MiB and sends pid and reflectionApiSpecVersion as integers.
  • Notebook re-runs overwrite instead of failing: define_value and define_schema raised ValueError when a cell ran twice. Re-registering now replaces the entry, like @ai.flow and @ai.tool already do.
  • Default logs go to stderr: When the app hasn't configured structlog, Genkit's logs now go to sys.stderr, so piped stdout stays clean. An app that configures structlog itself keeps its own setup.
  • Actionable errors for run_main() and port exhaustion: run_main() inside a running loop closes the coroutine and points to await main(). Running out of reflection ports (each dev-mode Genkit() holds one) says so and suggests reusing one instance, instead of a bare no available port error.

Breaking changes

None.

Cross-SDK

Reflection responses now match what the Genkit CLI already expects. The CLI, JS, Go, and Dart owners need no changes.

// v1 POST /api/runAction without "key"
// before: 500
// after: 400
{"error": "key is required"}

// v2 "register" JSON-RPC params
// before: {"pid": 48210.0, ...}
// after:
{"pid": 48210, "reflectionApiSpecVersion": 1, ...}

@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from 5d5d513 to 6272f6f Compare November 9, 2026 19:08
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from 6272f6f to 8a1c997 Compare November 9, 2026 19:58
@huangjeff5
huangjeff5 changed the base branch from main to fix/py-1.0-pr6-middleware-sandbox November 9, 2026 19:58
@huangjeff5
huangjeff5 added this pull request to stack #59 November 9, 2026 19:58
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-middleware-sandbox branch from c23d2da to 6843c66 Compare November 9, 2026 20:02
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from 8a1c997 to 4cc0b5b Compare November 9, 2026 20:02
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-middleware-sandbox branch from 6843c66 to 3eccbe6 Compare November 9, 2026 20:21
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from 4cc0b5b to 5d97da9 Compare November 9, 2026 20:21
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-middleware-sandbox branch from 3eccbe6 to 597b801 Compare November 9, 2026 21:23
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from 5d97da9 to 0969d89 Compare November 9, 2026 21:23
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-middleware-sandbox branch from 597b801 to ef6c441 Compare November 9, 2026 21:28
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from 0969d89 to e323e58 Compare November 9, 2026 21:28
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-middleware-sandbox branch from ef6c441 to 2b13e02 Compare November 9, 2026 21:53
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch 2 times, most recently from 306937a to 929a635 Compare November 9, 2026 22:03
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-middleware-sandbox branch 2 times, most recently from 3c47f6b to a211f0f Compare November 9, 2026 23:19
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from 7d48dd9 to 5d35f82 Compare November 9, 2026 23:34
@huangjeff5 huangjeff5 changed the title fix(py): plugin action key prefixing, Dev UI runtime paths, middleware exports fix(py): prefix plugin action keys and resolve Dev UI runtime paths from project root Nov 10, 2026
@huangjeff5
huangjeff5 requested a review from hilariie November 10, 2026 04:08
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-middleware-sandbox branch from a211f0f to 048d352 Compare November 10, 2026 07:44
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from 5d35f82 to 0db5e13 Compare November 10, 2026 07:44
@huangjeff5 huangjeff5 changed the title fix(py): prefix plugin action keys and resolve Dev UI runtime paths from project root fix(py): Dev UI runtime discovery, reflection parity, and middleware instance fixes Nov 10, 2026
@huangjeff5
huangjeff5 removed this pull request from stack #59 November 10, 2026 18:16
@huangjeff5
huangjeff5 added this pull request to stack #75 November 10, 2026 18:16
@huangjeff5
huangjeff5 removed this pull request from stack #75 November 10, 2026 18:16
@huangjeff5
huangjeff5 added this pull request to stack #76 November 10, 2026 18:17
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-middleware-sandbox branch from 048d352 to e7b93f7 Compare November 10, 2026 18:37
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from 0db5e13 to 8d08a6e Compare November 10, 2026 18:37
@huangjeff5
huangjeff5 removed this pull request from stack #82 November 11, 2026 02:36
@huangjeff5 huangjeff5 changed the title fix(py): Dev UI runtime discovery, reflection parity, and middleware instance fixes fix(py): write Dev UI runtime files at the project root and bring reflection v1/v2 to parity Nov 11, 2026
@huangjeff5
huangjeff5 added this pull request to stack #88 November 11, 2026 02:37
@huangjeff5
huangjeff5 removed this pull request from stack #88 November 11, 2026 06:22
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-middleware-sandbox branch from 65ba206 to aba2bcd Compare November 11, 2026 06:22
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from 6da52b6 to b158d03 Compare November 11, 2026 06:22
@huangjeff5
huangjeff5 added this pull request to stack #89 November 11, 2026 06:23
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-middleware-sandbox branch from aba2bcd to d7b803f Compare November 11, 2026 16:21
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from b158d03 to 4415b04 Compare November 11, 2026 16:21
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-middleware-sandbox branch from d7b803f to a3d8c7b Compare November 11, 2026 17:31
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from 4415b04 to d4713c2 Compare November 11, 2026 17:31
@huangjeff5
huangjeff5 removed this pull request from stack #89 November 11, 2026 18:06
@huangjeff5
huangjeff5 changed the base branch from fix/py-1.0-pr6-middleware-sandbox to fix/py-1.0-pr5-web-serving November 11, 2026 18:06
RuntimeManager wrote .genkit/runtimes to cwd while the CLI reads it from
findProjectRoot(). From a subdirectory the Dev UI showed 0 actions. Walk
ancestors with the CLI's marker list; fall back to cwd.
- /api/runAction awaits flush_instrumentations() before answering, as v2
  and JS do, so the root span is exported when the response lands.
- Error details.stack carries the Python traceback when empty, so
  genkit flow:run prints Python frames (matches v2).
- /api/notify also enables log export and warns on spec-version
  mismatch; /api/__health?id= answers 503 for another runtime; a
  missing runAction key is 400, not a KeyError 500.
websockets defaults max_size to 1 MiB; a runAction with one screenshot
closed the socket with 1009. Match the CLI's 100 MiB. register now
sends pid and reflectionApiSpecVersion as integers.
structlog's default factory printed to stdout, breaking
`python cli.py | jq .`. Default to stderr unless the app set a factory.
define_value / define_schema now overwrite on re-registration, like
flows, tools, and prompts, so re-running a Jupyter cell works.
…untime dirs

- ai.run_main() under Jupyter/IPython raises a RuntimeError that points
  to `await main()` and closes the coroutine (no unawaited warning).
- The reflection port-range error was unreachable; instance #101 got a
  bare EADDRINUSE. Name the cause and the fix.
- RuntimeManager removes .genkit/runtimes and .genkit when it leaves
  them empty.
genkit start creates and watches .genkit/runtimes before it spawns the
app. Removing that directory on exit and recreating it on the next start
leaves the CLI's chokidar 4 watcher blind to the new runtime file, so a
restarted app never shows up in the Dev UI. Track which directory levels
RuntimeManager created and remove only those.
@huangjeff5
huangjeff5 changed the base branch from fix/py-1.0-pr5-web-serving to main November 11, 2026 18:37
@huangjeff5
huangjeff5 force-pushed the fix/py-1.0-pr6-devui-middleware-mcp branch from d4713c2 to 2f69a27 Compare November 11, 2026 18:38
- Keep duplicate checks on Registry.register_value by default and opt in
  from define_value only, so duplicate middleware or format names still
  raise ValueError.
- Flush flush_developer_ui_collector instead of flush_instrumentations in
  reflection v1 outside the action try/except, isolating remote OTel
  exporters and preventing collector errors from failing completed runs.
- Route Genkit's unconfigured console logs to dynamic sys.stderr on
  ExportTee without mutating structlog's global logger_factory.
@huangjeff5
huangjeff5 merged commit 78a967c into main Nov 12, 2026
20 checks passed
@huangjeff5
huangjeff5 deleted the fix/py-1.0-pr6-devui-middleware-mcp branch November 12, 2026 04:12
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