Commit 1d507fd
fix: skip false-positive fork detection after pickle in BQ analytics plugin
When the plugin is deployed via Vertex AI Agent Engine, it is pickled
for transport and unpickled on the server. __getstate__ sets
_init_pid = 0 as a pickle sentinel. On the server, _ensure_started()
checks os.getpid() != self._init_pid, which always evaluates to True
since os.getpid() is never 0. This triggers _reset_runtime_state()
on every cold start even though no fork happened, producing a
misleading "Fork detected (parent PID 0, child PID xx)" warning and
adding unnecessary startup latency from tearing down and re-creating
gRPC state that was already clear.
The fix distinguishes "unpickled, never initialized" (_init_pid == 0)
from "forked from a different process" (_init_pid != 0 and
_init_pid != os.getpid()). Real forks are still detected by both
os.register_at_fork (line 108) and this PID check.
Related: haiyuan-eng-google/BigQuery-Agent-Analytics-SDK#86
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 3e282d2 commit 1d507fd
2 files changed
Lines changed: 80 additions & 1 deletion
File tree
- src/google/adk/plugins
- tests/unittests/plugins
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2653 | 2653 | | |
2654 | 2654 | | |
2655 | 2655 | | |
2656 | | - | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
| 2660 | + | |
| 2661 | + | |
| 2662 | + | |
| 2663 | + | |
2657 | 2664 | | |
2658 | 2665 | | |
2659 | 2666 | | |
| |||
Lines changed: 72 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7408 | 7408 | | |
7409 | 7409 | | |
7410 | 7410 | | |
| 7411 | + | |
| 7412 | + | |
| 7413 | + | |
| 7414 | + | |
| 7415 | + | |
| 7416 | + | |
| 7417 | + | |
| 7418 | + | |
| 7419 | + | |
| 7420 | + | |
| 7421 | + | |
| 7422 | + | |
| 7423 | + | |
| 7424 | + | |
| 7425 | + | |
| 7426 | + | |
| 7427 | + | |
| 7428 | + | |
| 7429 | + | |
| 7430 | + | |
| 7431 | + | |
| 7432 | + | |
| 7433 | + | |
| 7434 | + | |
| 7435 | + | |
| 7436 | + | |
| 7437 | + | |
| 7438 | + | |
| 7439 | + | |
| 7440 | + | |
| 7441 | + | |
| 7442 | + | |
| 7443 | + | |
| 7444 | + | |
| 7445 | + | |
| 7446 | + | |
| 7447 | + | |
| 7448 | + | |
| 7449 | + | |
| 7450 | + | |
| 7451 | + | |
| 7452 | + | |
| 7453 | + | |
| 7454 | + | |
| 7455 | + | |
| 7456 | + | |
| 7457 | + | |
| 7458 | + | |
| 7459 | + | |
| 7460 | + | |
| 7461 | + | |
| 7462 | + | |
| 7463 | + | |
| 7464 | + | |
| 7465 | + | |
| 7466 | + | |
| 7467 | + | |
| 7468 | + | |
| 7469 | + | |
| 7470 | + | |
| 7471 | + | |
| 7472 | + | |
| 7473 | + | |
| 7474 | + | |
| 7475 | + | |
| 7476 | + | |
| 7477 | + | |
| 7478 | + | |
| 7479 | + | |
| 7480 | + | |
| 7481 | + | |
| 7482 | + | |
0 commit comments