-
Notifications
You must be signed in to change notification settings - Fork 4
docs: Add debugging instructions for gym servers. #341
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
Open
ffrujeri
wants to merge
5
commits into
main
Choose a base branch
from
ffrujeri/cursor-debugging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+378
−5
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| # Debugging Servers | ||
|
|
||
| This guide shows you how to debug NeMo Gym servers using VS Code's debugger. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Make sure you have the dev dependencies installed: | ||
|
|
||
| ```bash | ||
| pip install -e ".[dev]" | ||
| ``` | ||
|
|
||
| This includes `debugpy`, which is required for remote debugging. | ||
|
|
||
| ## VS Code Configuration | ||
|
|
||
| Add these configurations to your `.vscode/launch.json`: | ||
|
|
||
| ```json | ||
| { | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "📎 Attach: Server Port 5678", | ||
| "type": "debugpy", | ||
| "request": "attach", | ||
| "connect": { | ||
| "host": "localhost", | ||
| "port": 5678 | ||
| }, | ||
| "pathMappings": [ | ||
| { | ||
| "localRoot": "${workspaceFolder}", | ||
| "remoteRoot": "${workspaceFolder}" | ||
| } | ||
| ], | ||
| "justMyCode": false | ||
| }, | ||
| { | ||
| "name": "📎 Attach: Server Port 5679", | ||
| "type": "debugpy", | ||
| "request": "attach", | ||
| "connect": { | ||
| "host": "localhost", | ||
| "port": 5679 | ||
| }, | ||
| "pathMappings": [ | ||
| { | ||
| "localRoot": "${workspaceFolder}", | ||
| "remoteRoot": "${workspaceFolder}" | ||
| } | ||
| ], | ||
| "justMyCode": false | ||
| }, | ||
| { | ||
| "name": "📎 Attach: Server Port 5680", | ||
| "type": "debugpy", | ||
| "request": "attach", | ||
| "connect": { | ||
| "host": "localhost", | ||
| "port": 5680 | ||
| }, | ||
| "pathMappings": [ | ||
| { | ||
| "localRoot": "${workspaceFolder}", | ||
| "remoteRoot": "${workspaceFolder}" | ||
| } | ||
| ], | ||
| "justMyCode": false | ||
| }, | ||
| { | ||
| "name": "📎 Attach: Server Port 5681", | ||
| "type": "debugpy", | ||
| "request": "attach", | ||
| "connect": { | ||
| "host": "localhost", | ||
| "port": 5681 | ||
| }, | ||
| "pathMappings": [ | ||
| { | ||
| "localRoot": "${workspaceFolder}", | ||
| "remoteRoot": "${workspaceFolder}" | ||
| } | ||
| ], | ||
| "justMyCode": false | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| :::{note} | ||
| If you already have a `launch.json`, just add these configurations to your existing `"configurations"` array. | ||
| ::: | ||
|
|
||
| ## Debugging Workflow | ||
|
|
||
| ### Step 1: Start Servers with Debug Mode | ||
|
|
||
| In your terminal, enable debug mode and start your servers: | ||
|
|
||
| ```bash | ||
| # Enable subprocess debugging | ||
| export NEMO_GYM_DEBUG_SUBPROCESS=1 | ||
| export NEMO_GYM_DEBUG_PORT=5678 | ||
|
|
||
| # Start your servers (adjust config paths as needed) | ||
| ng_run "+config_paths=[resources_servers/example_simple_weather/configs/simple_weather.yaml,responses_api_models/openai_model/configs/openai_model.yaml]" | ||
| ``` | ||
|
|
||
| You'll see output like: | ||
| ``` | ||
| 🐛 Subprocess debug mode enabled - servers will use ports starting from 5678 | ||
| [openai_model] listening for debugger on port 5678 | ||
| [weather_server] listening for debugger on port 5679 | ||
| ``` | ||
|
|
||
| The servers are now running and waiting for debugger attachment. | ||
|
|
||
| ### Step 2: Attach VS Code Debugger | ||
|
|
||
| 1. **Set your breakpoints** in the server code (e.g., `responses_api_models/openai_model/app.py`) | ||
|
|
||
| 2. **Attach the debugger:** | ||
| - Press `F5` or `Ctrl+Shift+D` (Cmd+Shift+D on Mac) | ||
| - Select **"📎 Attach: Server Port 5678"** (for the first server) | ||
| - Or select the port corresponding to the server you want to debug | ||
|
|
||
| 3. You'll see the debugger attach successfully in VS Code's debug panel. | ||
|
|
||
| ### Step 3: Trigger Your Code | ||
|
|
||
| Run your client or test to trigger requests to the servers: | ||
|
|
||
| ```bash | ||
| python responses_api_agents/simple_agent/client.py | ||
| ``` | ||
|
|
||
| Your breakpoints will now hit! 🎉 | ||
|
|
||
| ## Quick Reference | ||
|
|
||
| ### Environment Variables | ||
|
|
||
| | Variable | Description | | ||
| |----------|-------------| | ||
| | `NEMO_GYM_DEBUG_SUBPROCESS` | Set to `1` to enable debug mode for subprocesses | | ||
| | `NEMO_GYM_DEBUG_PORT` | Base port number (default: 5678). Each server gets sequential ports | | ||
|
|
||
| ### Port Assignment | ||
|
|
||
| When debug mode is enabled, servers are assigned sequential ports: | ||
| - First server: 5678 (base port) | ||
| - Second server: 5679 (base + 1) | ||
| - Third server: 5680 (base + 2) | ||
| - And so on... | ||
|
|
||
| ### Debugging Multiple Servers | ||
|
|
||
| You can attach to multiple servers simultaneously: | ||
|
|
||
| 1. Attach to port 5678 (press F5 → select port 5678) | ||
| 2. Attach to port 5679 (press F5 again → select port 5679) | ||
| 3. Both servers are now being debugged! | ||
|
|
||
| VS Code will show multiple debug sessions in the Call Stack panel. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### "Failed to attach" | ||
|
|
||
| - Make sure servers are running with `ng_run` | ||
| - Check the port numbers in the terminal output | ||
| - Verify `NEMO_GYM_DEBUG_SUBPROCESS=1` is set | ||
|
|
||
| ### Breakpoints not hitting | ||
|
|
||
| - Verify you attached to the correct port | ||
| - Make sure you're triggering the right endpoint | ||
| - Check that the request is actually reaching the server | ||
| - Ensure breakpoints are set before the code executes | ||
|
|
||
| ### "debugpy not found" | ||
|
|
||
| Install dev dependencies: | ||
| ```bash | ||
| pip install -e ".[dev]" | ||
| ``` | ||
|
|
||
| ## How It Works | ||
|
|
||
| When `NEMO_GYM_DEBUG_SUBPROCESS=1` is set, the CLI automatically starts each server subprocess with: | ||
|
|
||
| ```bash | ||
| python -m debugpy --listen 0.0.0.0:PORT app.py | ||
| ``` | ||
|
|
||
| This enables remote debugging without modifying your application code. VS Code connects to these debug ports using the attach configurations. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffrujeri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| """ | ||
| Entry point for running nemo_gym as a module: python -m nemo_gym | ||
|
|
||
| This allows debugging with: python -m nemo_gym | ||
| """ | ||
|
|
||
| if __name__ == "__main__": | ||
| from nemo_gym.cli import run | ||
| run() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.