# P1-2: Host Resource Requirement Select — Investigation ## Status - **C layer (P1-2a): COMPLETE** — `eval_select_simple` wired in `xce_select.c` (PEG grammar → AST → CSE, memoized eval). Scheduler integration (Phase 6) done. See `src/docs/resreq-ast-cse-design.md` for architecture reference. - **Go bridge (P1-2b): PENDING** — `EvalSelectForHost` remains a stub returning `errNoCGO`. CGO boundary, resource value lookup from in-memory store, and `FilterHostByResReqSelect` are still to implement. --- ## Background The `select` field in an LSF-style resource requirement string (e.g. `select[mem>4096 && type==X86_64]`) filters candidate hosts before slot allocation. Currently `EvalSelectForHost` is a no-CGO stub that always returns `errNoCGO`. The full feature requires two layers: 1. **C parser + evaluator** — parse the boolean select expression into an AST and evaluate it against a host's resource values. 2. **Go bridge** — call the C evaluator via CGO and wire it into `FilterHostByResReqSelect` in the controllers layer. --- ## Sub-tasks ### #11 P1-2a: C select expression parser (PEG + eval) ✓ COMPLETE **Files implemented:** - `include/resreq.h` — expression-tree types, enums, `extern` declarations. - `lib/xce_select.peg` — PEG grammar for select boolean expressions. - `lib/xce_select.c` — `parse_select()`, `eval_select_simple()`, CSE tree. - `lib/meson.build` — `xce_select.peg` in build. ### #12 P1-2b: Go EvalSelectForHost + FilterHostByResReqSelect (remaining) **Files to touch:** - `backend/clib.go` — Implement `EvalSelectForHost(hostname, selectExpr string) error` using `cgo.Handle` for callback context; add `#include "resreq.h"`, extern C declarations, `xce_select_destroy` helper. - `controllers/hosts.go` — Implement `FilterHostByResReqSelect(hosts []models.HostInfo, expr string)`, update `preCheckHostRequest()` limit from 4094 → 1024 bytes. **Open questions:** - Does `EvalSelectForHost` look up live resource values from the in-memory store, or are values passed directly from C? - `cgo.Handle` usage pattern — per-call or session-level? - Input validation: max expression length (1024 bytes), allowed characters.