Skip to content

fix(examples): tool closures failing to pickle across spawned worker processes - #477

Merged
kowser-orkes merged 1 commit into
mainfrom
fix/agent-examples-nested-tool-pickling
Aug 14, 2026
Merged

fix(examples): tool closures failing to pickle across spawned worker processes#477
kowser-orkes merged 1 commit into
mainfrom
fix/agent-examples-nested-tool-pickling

Conversation

@kowser-orkes

@kowser-orkes kowser-orkes commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Pull Request type

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • WHOSUSING.md
  • Other (please describe):

Changes in this PR

Describe the new behavior from this PR, and why it's needed

  • Tools defined as nested functions can't pickle to their own spawned worker process — each @tool
    runs in a separate OS process under the SDK's default spawn multiprocessing method
  • Moved affected tools to module level across 16k_credentials_google_adk.py,
    79_agent_message_bus.py, 80_live_dashboard.py, 81_chat_repl.py, 82_coding_agent.py,
    82b_coding_agent_tui.py — runtime-only values (execution ids, working dir, shell timeout, IPC
    paths) now cross via environment variables instead of closures
  • Background-process tools in 82b_coding_agent_tui.py also shared an in-memory registry across
    four separate worker processes — replaced with a file-based registry keyed by process id, status
    via PID probing
  • 80_live_dashboard.py, 81_chat_repl.py, subscription-agent.py ran orchestration as
    unconditional top-level code, so every spawned worker re-executed it and crashed trying to spawn
    its own workers — wrapped in if __name__ == "__main__":
  • 39c_serverless_code_execution.py _start_mock_server(port=9753) ran at module level, so every worker re-bound the port. The example hung indefinitely (>6m40s with no output past its header). Moved inside main. Verified: now completes with 2**100 = 1267650600228229401496703205376, Tool calls: 1, FinishReason.STOP.
  • Updated a deprecated Gemini model in the ADK credentials example

Alternatives considered

None

@kowser-orkes
kowser-orkes marked this pull request as draft August 13, 2026 01:21
@ling-senpeng13
ling-senpeng13 marked this pull request as ready for review August 13, 2026 16:18
@ling-senpeng13
ling-senpeng13 marked this pull request as draft August 13, 2026 16:18
@mp-orkes
mp-orkes self-requested a review August 14, 2026 01:25
@kowser-orkes
kowser-orkes marked this pull request as ready for review August 14, 2026 01:30
- tool functions closing over local state can't pickle to their own spawned worker process, moved them to module level
- background-process registry, missing main guards, and shared temp dirs also broke across worker processes, fixed those too
- swapped a deprecated gemini model in the ADK credentials example
@kowser-orkes
kowser-orkes force-pushed the fix/agent-examples-nested-tool-pickling branch from deb0739 to a896f12 Compare August 14, 2026 01:31

@mp-orkes mp-orkes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - But I'm going to review, test and probably change a few things in the WMQ & Agents examples.

@kowser-orkes
kowser-orkes merged commit eba5477 into main Aug 14, 2026
6 checks passed
@kowser-orkes
kowser-orkes deleted the fix/agent-examples-nested-tool-pickling branch August 14, 2026 05:05
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