Skip to content

hydra-evaluator: Rewrite in Rust - #1608

Open
Ericson2314 wants to merge 1 commit into
masterfrom
no-c-plus-plus
Open

hydra-evaluator: Rewrite in Rust#1608
Ericson2314 wants to merge 1 commit into
masterfrom
no-c-plus-plus

Conversation

@Ericson2314

Copy link
Copy Markdown
Member

Port hydra-evaluator from C++ to Rust, removing the last C++ executable from the project. The new implementation uses sqlx and tokio, matching the async patterns already established by hydra-queue-runner and hydra-builder.

Build/packaging changes:

  • Remove all C++ dependencies from subprojects/hydra/meson.build
  • Move Rust packaging from hydra-queue-runner/package.nix to subprojects/rust-package.nix with named outputs (queue_runner, builder, evaluator)
  • Add evaluatorExecutable option to the NixOS web-app module, matching how the queue runner and builder are discovered via their own modules
  • Clean up stale references in hydra-tests/meson.build and dev-shell.nix

Eveeifyeve

This comment was marked as low quality.

@Ericson2314
Ericson2314 force-pushed the no-c-plus-plus branch 7 times, most recently from 2a1c3e0 to dc93afe Compare May 6, 2026 17:49
Comment thread subprojects/hydra-evaluator/src/config.rs Outdated
@Ericson2314
Ericson2314 force-pushed the no-c-plus-plus branch 2 times, most recently from 113b25e to 516add8 Compare August 4, 2026 15:58
#![forbid(unsafe_code)]
#![deny(
clippy::all,
clippy::pedantic,

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.

This list could be a shorter

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Conni2461 Have an opinion? The LLM was imitating what you had done in the other crates :) (if I am interpreting the 7d9f536 squash correctly)

@Ericson2314
Ericson2314 force-pushed the no-c-plus-plus branch 3 times, most recently from 502f3bb to bc2d021 Compare August 5, 2026 22:01
Port hydra-evaluator from C++ to Rust, removing the last C++ executable
from the project. The new implementation uses `sqlx` and `tokio`,
matching the async patterns already established by hydra-queue-runner
and hydra-builder.

The scheduling logic is a fairly direct port; what gets explicit
treatment is the error-recovery story, which did not survive
translation on its own. The C++ evaluator leaned on pqxx throwing on a
broken connection and the process exiting into systemd's
`Restart=always`, which resynced all state; `sqlx`'s conveniences
paper over connection loss instead. So the `db` crate's listener now
disables `sqlx`'s eager reconnect so that connection loss surfaces as
a stream error (see the comment there — silently dropped NOTIFYs would
otherwise strand user-triggered evaluations), and both the main loop
and the DB monitor exit for a supervisor restart on a broken
connection. Other behaviors deliberately carried over from the C++:
forgetting a disabled or deleted jobset kills its in-flight
`hydra-eval-jobset` (the C++ `Pid` destructor did this), a failed
spawn runs the same cleanup as a failed eval so `startTime` cannot
stick forever, and the reaper holds the scheduler lock across its
cleanup transaction so a freshly restarted eval cannot have its
`startTime` clobbered.

The SQL lives in `src/queries.rs` as compile-time-checked
`sqlx::query!` macros on an extension trait over `db::Connection` —
kept in this crate rather than the shared `db` crate because this
slice of the schema only matters to the evaluator. The `db` crate
contributes pooled acquisition (`Database::from_env`, reading
`HYDRA_DATABASE_URL` via shared constants the queue runner now also
uses) and a `raw()` escape hatch for exactly this pattern. Timestamps
are `i32` to match the schema's `INT4` (see the comment on
`JobsetSchedulingInfo`). Regenerating the `.sqlx` cache also uncovered
a latent bug in the db crate: `get_drv_path_from_build_step` treated
`drvPath` as nullable, but the schema declares it `not null`.

Build/packaging: the C++ build is removed from
`subprojects/hydra/meson.build`; the new
`subprojects/hydra-evaluator/package.nix` follows the same per-binary
pattern as `hydra-queue-runner` and `hydra-builder` (properly sharing
the dep crates between these builds is left for later); the NixOS
web-app module gains an `evaluatorExecutable` option matching how the
queue runner and builder are discovered via their own modules; and
stale references in `hydra-tests/meson.build` and `dev-shell.nix` are
cleaned up.

Co-authored-by: Jörg Thalheim <joerg@thalheim.io>
Co-authored-by: Claude <noreply@anthropic.com>
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.

4 participants