agents/docker: Refactor Docker agent.#1119
Draft
nrybowski wants to merge 9 commits into
Draft
Conversation
- Deprecate communication through std{in,out} channels in favor of simple TCP connection.
- Leverage formalised messages rather than dictionnaries built on the fly.
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| BestPractice | 1 minor |
| ErrorProne | 1 critical 1 high |
| Security | 2 medium 19 high |
| Complexity | 4 medium |
🟢 Metrics 148 complexity · 0 duplication
Metric Results Complexity 148 Duplication 0
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
nrybowski
commented
Jul 9, 2026
Comment on lines
+690
to
+697
| attrs = self._docker.sync._docker.containers.get(info.container_id).attrs | ||
| try: | ||
| reader_stream, write_stream = await asyncio.open_connection(sock=sock._sock) | ||
| ip = attrs['NetworkSettings']['Networks']['bridge']['IPAddress'] | ||
| except KeyError: | ||
| self._logger.exception("Failed to fetch grading container IP from container attributes.") | ||
| return None | ||
| try: | ||
| reader_stream, write_stream = await asyncio.open_connection(ip, GRADING_CONTAINER_TCP_PORT) |
Member
Author
There was a problem hiding this comment.
Replace with TCP server instead, grading containers will connect to the agent when they are ready.
nrybowski
commented
Jul 9, 2026
| # ==== Common types ==== | ||
|
|
||
| class MsgType(IntEnum): | ||
| AgentInitMsg = 1 |
Member
Author
There was a problem hiding this comment.
Rename in AgentInitGrading
nrybowski
commented
Jul 9, 2026
| @staticmethod | ||
| def from_dict(o: dict): | ||
| if (msg_type := o.get('type')) is not None: | ||
| if msg_type == MsgType.AgentInitMsg: |
nrybowski
commented
Jul 9, 2026
| elif msg_type == MsgType.GradingError: | ||
| return GradingError(**o) | ||
| else: | ||
| raise ValueError |
Member
Author
There was a problem hiding this comment.
Add explicit error message.
nrybowski
commented
Jul 9, 2026
| else: | ||
| raise ValueError | ||
| else: | ||
| raise KeyError |
nrybowski
commented
Jul 9, 2026
| def deserialize(o: bytes): | ||
| o = msgpack.loads(o) | ||
| if not isinstance(o, dict): | ||
| raise TypeError |
nrybowski
commented
Jul 9, 2026
| envtypes: dict | ||
| run_cmd: str | ||
| run_as_root: bool = False | ||
| shared_kernel: bool = True |
- Deprecate kata-runtime related code, i.e., shared_kernel and both_docker switches. - Leverage formalized Agent messages when proxied through the grading container.
- Deprecate kata-runtime related code. - Connect to Agent TCP server. - Leverage formalized Agent messages.
…iner. This commit adds a mock of the Docker agent to test the behavior of the grading / students container w.r.t. the new I/O scheme, as well as some simple test cases.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR is a major refactor of the Docker agent which focuses on two main points: (i) deprecating the kata-runtime as it is unused and adds a lot of unnecessary complexity and, (ii) implementing a robust communication scheme between the agent, the grading containers and the student containers.
Regarding to the first point, we experimented a few years ago with launching custom kernels within student container (#949). This is a solid alternative to the kata-runtime for running student code as root, e.g., for networking exercises, without compromising INGInious security. This feature has been blocked since then because of the way the Docker agent exposes its capabilities, which in turns impacts the way jobs are distributed among available agents.
Regarding to the second point, the Docker agent communicates with grading and student containers through their std{in,out} interfaces which is quite fragile and blocks a current effort of removing the Docker dependency (see #1115, #1116) in favor of generic OCI compatibility. Also, when the kata-runtime is used, the Docker agent serves as a proxy between the grading and student containers while they can communicate directly when both of them run on the same kernel. This is not required by #949.
The Docker agent also relies on the ZMQ framework for communications. This is an heavy framework whose advanced features are not used. We deprecate it in favor of a simpler and lower level approach based on simple bytestreams over TCP and Unix sockets which is already in use in the existing code. By leveraging the Transport and Protocol features of the asyncio framework, we also can get rid of the custom buffering that has been implemented. The goal here is to mainly rely on features of the standard python library and simplify the code base.
Furthermore, the messages sent between each element are not formally described and are encoded with dictionaries built-on the fly. This approach is not reliable and makes the messages hard to correctly extend.
The kata-runtime is so intermingled with the Docker agent I/O that it is nearly impossible to deprecate it without refactoring the whole Docker agent I/O.
This PR is an effort in the continuity of #1115 and #1116, and should be a cleaner basis for #949.
It implements on the following changes:
Note: This PR is WIP, the git history will be squashed and rewritten before opening it for merge request.