-
Notifications
You must be signed in to change notification settings - Fork 6
docs: document PRAISONAI_RUN_SYNC_TIMEOUT and shutdown() API (fixes #227) #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -337,6 +337,21 @@ session_config = SessionConfig( | |
|
|
||
| --- | ||
|
|
||
| ## Graceful Shutdown | ||
|
|
||
| Long-running servers can stop the wrapper's background async loop explicitly: | ||
|
|
||
| ```python | ||
| from praisonai._async_bridge import shutdown | ||
|
|
||
| # On SIGTERM / server stop | ||
| shutdown() | ||
| ``` | ||
|
|
||
| `shutdown()` is also registered via `atexit`, so it runs automatically on interpreter exit. Call it manually when you need deterministic cleanup (flushing telemetry exporters, closing async HTTP/DB clients) before the process exits. | ||
|
Comment on lines
+345
to
+351
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| --- | ||
|
Comment on lines
+340
to
+353
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Locate the async bridge module and inspect for shutdown() + atexit registration.
fd -t f '_async_bridge.py'
fd -t f '_async_bridge.py' --exec cat {}
echo "---- symbol search ----"
rg -nP '\b(def\s+shutdown|atexit\.register|__all__)\b' -C2Repository: MervinPraison/PraisonAIDocs Length of output: 50383 Remove the "Graceful Shutdown" section or correct the API reference. The code snippet imports 🤖 Prompt for AI Agents |
||
|
|
||
| ## CLI Commands | ||
|
|
||
| ```bash | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,6 +104,8 @@ unset PRAISONAI_ALLOW_LOCAL_TOOLS | |
| - Agent API calls | ||
| - Real-time UI interactions | ||
|
|
||
| As of recent PraisonAI versions, the `PRAISONAI_ALLOW_LOCAL_TOOLS` gate is enforced consistently across the CLI (`praisonai run`), YAML workflows, and Python (`AgentsGenerator`) entry points. Previously it was only enforced on one path. | ||
|
|
||
| **Usage Example**: | ||
| ```python | ||
| from praisonaiagents import Agent | ||
|
|
@@ -185,6 +187,22 @@ server = BrowserServer(host="0.0.0.0", port=8080) | |
| server.start() | ||
| ``` | ||
|
|
||
| ### PRAISONAI_RUN_SYNC_TIMEOUT | ||
|
|
||
| Default maximum seconds the wrapper's sync-to-async bridge will wait for a coroutine to complete. | ||
|
|
||
| **Default:** `300` (5 minutes) | ||
|
|
||
| ```bash | ||
| # Tighten for latency-sensitive servers | ||
| export PRAISONAI_RUN_SYNC_TIMEOUT=30 | ||
|
|
||
| # Loosen for long-running batch jobs | ||
| export PRAISONAI_RUN_SYNC_TIMEOUT=3600 | ||
| ``` | ||
|
|
||
| Applies to every `praisonai` CLI entry and wrapper-based server (gateway, a2u, mcp_server, scheduler). The SDK (`praisonaiagents`) uses a separate bridge — see [Async Bridge](/docs/features/async-bridge). | ||
|
Comment on lines
+190
to
+204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Comment on lines
+190
to
+204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Verify PRAISONAI_RUN_SYNC_TIMEOUT is consumed by wrapper entry points
# and that the public shutdown() hook exists.
set -euo pipefail
echo "Checking timeout env var usage and run_sync call sites..."
rg -n -C3 'PRAISONAI_RUN_SYNC_TIMEOUT|run_sync\s*\(' --glob '!docs/**'
echo
echo "Checking shutdown API definition..."
rg -n -C3 'def\s+shutdown\s*\(' --glob '!docs/**'Repository: MervinPraison/PraisonAIDocs Length of output: 42789 🏁 Script executed: # Check the _async_bridge.py implementation for timeout handling and shutdown
cat -n praisonai/_async_bridge.py | head -100Repository: MervinPraison/PraisonAIDocs Length of output: 2512 🏁 Script executed: # Search for where PRAISONAI_RUN_SYNC_TIMEOUT might be read/set
rg -n "RUN_SYNC_TIMEOUT|getenv.*timeout|environ.*timeout" --glob '!docs/**'Repository: MervinPraison/PraisonAIDocs Length of output: 53 🏁 Script executed: # Search for wrapper entry points (gateway, a2u, mcp_server, scheduler)
fd -e py -type f | xargs rg -l "gateway|a2u_server|mcp_server|scheduler" --glob '!docs/**' | head -5Repository: MervinPraison/PraisonAIDocs Length of output: 440 🏁 Script executed: # Check if any wrapper code tries to read PRAISONAI_RUN_SYNC_TIMEOUT or pass timeout to run_sync
rg -n "run_sync\(" praisonai/endpoints/ praisonai/integrations/ --glob '!docs/**' -A2 -B2 | head -80Repository: MervinPraison/PraisonAIDocs Length of output: 3272 🏁 Script executed: # Confirm there is no shutdown in _async_bridge
wc -l praisonai/_async_bridge.py
tail -20 praisonai/_async_bridge.pyRepository: MervinPraison/PraisonAIDocs Length of output: 690 Document PRAISONAI_RUN_SYNC_TIMEOUT environment variable contract accurately or remove unsupported claims. The documented environment variable is not consumed by the codebase:
Either implement support for the environment variable (parse it in wrappers, pass it to Suggested documentation revision ### PRAISONAI_RUN_SYNC_TIMEOUT
Default maximum seconds the wrapper's sync-to-async bridge will wait for a coroutine to complete.
+**Type:** float seconds
**Default:** `300` (5 minutes)
+**Recommended range:** use `30`-`300` for interactive servers; use larger values only for known long-running batch workloads.
```bash
# Tighten for latency-sensitive servers
export PRAISONAI_RUN_SYNC_TIMEOUT=30
# Loosen for long-running batch jobs
export PRAISONAI_RUN_SYNC_TIMEOUT=3600
+
+# Restore the default behavior
+unset PRAISONAI_RUN_SYNC_TIMEOUT-Applies to every Verify each finding against the current code and only fix it if needed. In |
||
|
|
||
| --- | ||
|
|
||
| ## Common Patterns | ||
|
|
@@ -196,6 +214,7 @@ server.start() | |
| export PRAISONAI_ALLOW_LOCAL_TOOLS=true | ||
| export PRAISONAI_ALLOW_JOB_WORKFLOWS=true | ||
| export PRAISONAI_BROWSER_ALLOW_REMOTE=true | ||
| export PRAISONAI_RUN_SYNC_TIMEOUT=30 | ||
|
|
||
| # Add to ~/.bashrc or ~/.zshrc for persistence | ||
| echo 'export PRAISONAI_ALLOW_LOCAL_TOOLS=true' >> ~/.bashrc | ||
|
|
@@ -208,13 +227,15 @@ echo 'export PRAISONAI_ALLOW_LOCAL_TOOLS=true' >> ~/.bashrc | |
| unset PRAISONAI_ALLOW_LOCAL_TOOLS | ||
| unset PRAISONAI_ALLOW_JOB_WORKFLOWS | ||
| unset PRAISONAI_BROWSER_ALLOW_REMOTE | ||
| export PRAISONAI_RUN_SYNC_TIMEOUT=300 | ||
|
|
||
| # Or use systemd service with secure environment | ||
| # /etc/systemd/system/praisonai.service | ||
| [Service] | ||
| Environment="PRAISONAI_ALLOW_LOCAL_TOOLS=false" | ||
| Environment="PRAISONAI_ALLOW_JOB_WORKFLOWS=false" | ||
| Environment="PRAISONAI_BROWSER_ALLOW_REMOTE=false" | ||
| Environment="PRAISONAI_RUN_SYNC_TIMEOUT=300" | ||
| ``` | ||
| </Tab> | ||
|
|
||
|
|
@@ -258,6 +279,7 @@ Check if you use any of these features: | |
| export PRAISONAI_ALLOW_LOCAL_TOOLS=true # If you use tools.py | ||
| export PRAISONAI_ALLOW_JOB_WORKFLOWS=true # If you use job workflows | ||
| export PRAISONAI_BROWSER_ALLOW_REMOTE=true # If you bind browser to 0.0.0.0 | ||
| export PRAISONAI_RUN_SYNC_TIMEOUT=300 # Adjust timeout as needed | ||
| ``` | ||
| </Step> | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Narrow the timeout description to the wrapper bridge.
Line 45 currently reads like this controls all async operations. The PR objective scopes it to the wrapper sync-to-async bridge, so the CLI table should avoid over-promising.
Suggested wording
📝 Committable suggestion
🤖 Prompt for AI Agents