Skip to content

Adding debug for containers in IDEs#1106

Merged
anthonygego merged 9 commits intoINGInious:mainfrom
AlexandreDoneux:remote_container_debugging
Apr 17, 2026
Merged

Adding debug for containers in IDEs#1106
anthonygego merged 9 commits intoINGInious:mainfrom
AlexandreDoneux:remote_container_debugging

Conversation

@AlexandreDoneux
Copy link
Copy Markdown
Contributor

@AlexandreDoneux AlexandreDoneux commented Apr 8, 2026

This PR aims to add the possibility of interactive debug inside the containers running jobs.

Steps :

  • Pycharm debug for the INGInious script and the scripts inside inginious_container_api (using the pydevd_pycharm python package)
  • Broader usage for all IDEs using the Debug Adapter Protocol (DAP) => for future PR

Do you think debug capabilities for the run files is an interesting addition ?

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 8, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@AlexandreDoneux AlexandreDoneux force-pushed the remote_container_debugging branch from bc14a1d to a953b4a Compare April 8, 2026 13:23
Copy link
Copy Markdown
Member

@anthonygego anthonygego left a comment

Choose a reason for hiding this comment

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

Maybe we should enable this only on demand/when needed. Either passing an environment variable from PyCharm and frowarding it from the agent to the container, or rely on the existing debug flag.

If this fails silently if the server is not listening, this could be OK, but I guess in this case it would triy and time out. This is not a wanted behaviour as this would severly impact the execution time

A nice addition (not for this PR) would be to allow the user to specify the hostname and port of the debug server and keep those as default. If the docker stack is located on another host, the host-gateway IP won't match the debug server one. Besides, the hardcoded port may not be available on the developer host if it is already used by another service.

Comment thread inginious/agent/docker_agent/_docker_interface.py Outdated
Comment thread base-containers/base/bin/INGInious Outdated
@AlexandreDoneux AlexandreDoneux changed the title Adding remote debug for containers in IDEs Adding debug for containers in IDEs Apr 10, 2026
@AlexandreDoneux
Copy link
Copy Markdown
Contributor Author

The existing debug_mode is defined for each job separately and is given by the BackendNewJob message to the docker agent. So it is best to use a new environment variable to indicate if debug through the IDE is wanted. Any suggestions for a good variable name so it isn't confused for a parameter for the remote ssh debug ?

For a future PR for remote debugging :
As suggested we might want to use debug_host and debug_ports to specify the remote agent used and allow debug on the containers on that agent. However it is indicated that those configuration parameters are only to be used is the backend is on local. Does that mean we currently can't do remote ssh debugging if the backend is on a remote machine ?

# Only for backend: local
local-config:
    # debug_host: localhost  # host that will be indicated to users when they want to use the task remote debug feature. Automatically guessed by
                             # default
    debug_ports: 64000-64100 #port range use for remote debug feature

@anthonygego
Copy link
Copy Markdown
Member

Any suggestions for a good variable name so it isn't confused for a parameter for the remote ssh debug ?

ide_debug or simply debugger

Actually it might be more productive to directly add the options in the webapp config file and the docker agent CLI arguments.

Does that mean we currently can't do remote ssh debugging if the backend is on a remote machine ?

If the docker agent is used on another host, the args are passed in the CLI. This local-config feature is used for small deployments and development.

In conclusion, debugger_host and debugger_port seems two good new options to add to local-config and docker agent CLI.

@AlexandreDoneux
Copy link
Copy Markdown
Contributor Author

A message is now added to stderr if the debug server is not available. It does not fail the job anymore.

I have also fixed the time limit for a job to half an hour if the container debugging is enabled. Without it the job just stops after the set limit and debugging is not possible. Should I add that fixed limit as a config parameter ?

Comment thread inginious/agent/docker_agent/__init__.py Outdated
Comment thread doc/teacher_doc/testing.rst Outdated
Comment thread doc/admin_doc/install_doc/config_reference.rst Outdated
Comment thread doc/admin_doc/install_doc/config_reference.rst Outdated
Comment on lines +37 to +39
except Exception as e:
print("Failed to connect to pycharm debugger: {}".format(e))
debug_server_unavailable = True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems it already prints a stack trace so maybe there already is a try/except behind this one which becomes unecessary. But not sure...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is indeed a stack trace :

Could not connect to host.docker.internal: 5678
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/_pydevd_bundle/pydevd_comm.py", line 443, in start_client
    s.connect((host, port))
ConnectionRefusedError: [Errno 111] Connection refused

But I don't get wan't you want me to do. Should I remove the print ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is no need for duplicate messages. Either catch the first exception if possible, or simply remove the second if it this not stop execution.

@anthonygego anthonygego marked this pull request as ready for review April 16, 2026 07:26
Comment thread doc/teacher_doc/testing.rst Outdated
@AlexandreDoneux AlexandreDoneux force-pushed the remote_container_debugging branch from 4304216 to cb3f031 Compare April 17, 2026 13:10
@anthonygego
Copy link
Copy Markdown
Member

LGTM.

@anthonygego anthonygego merged commit 4cc5437 into INGInious:main Apr 17, 2026
5 checks passed
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