Skip to content

feat(harbor): job-level Compose overlay, MCP entries and prompt template (M30) - #4863

Merged
adil-a merged 1 commit into
mainfrom
adasif/harbor-m30-compose-overlay
Oct 28, 2026
Merged

adil-a merged 1 commit into
mainfrom
adasif/harbor-m30-compose-overlay

Conversation

@adil-a

@adil-a adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Job-level Compose overlay for the Harbor environment server (RFC row M30): the run config names extra Compose
files, MCP server entries and a prompt template, the way Harbor's job config names extra_docker_compose,
agents[].mcp_servers and an agent's prompt_template_path. The overlay is merged onto every task's Compose
group at prepare and at seed, a task that declares only an image gets Harbor's one-service group first, the
overlay's MCP entries reach the harness merged by name with the task's own, and the template is rendered around
the instruction of the episode's first turn. No task file changes; swapping the block swaps the backend (the
memory team's Redis and Hindsight stacks were the acceptance).

What changes

  • nemo_gym/tasks/harbor/compose_overlay.py (new): the compose_overlay block model (files, mcp_servers,
    prompt_template, every path checked when the block is read, as Harbor refuses a missing extra Compose file);
    a YAML loader for Compose's !reset and !override tags; merge_compose, which merges a later file onto the
    document the way compose-go merges -f files (mappings key by key; sequences appended, ports, volumes,
    expose, cap_add, env_file, ... unique on their key with the later entry winning; environment,
    labels, extra_hosts, sysctls, build.args as mappings in either written form; depends_on and a
    service's networks as mappings; command, entrypoint, healthcheck.test replaced whole; a key written
    with no value keeps the earlier file's value, as compose-go keeps it; !reset removes the attribute or one
    environment variable, !override replaces instead of merging; top-level x-* dropped as Compose ignores
    them); per-file interpolation that keeps the markers; each file's relative paths resolved against the Compose
    project directory, the task's environment folder, as Compose resolves every -f file's and Harbor's
    --project-directory names it, never against the overlay file's own folder (its env_file entries, any
    readable file since the overlay is the operator's, made absolute against it before the merge; its bind sources
    left to the volume planner, which resolves them against the same folder as the task's), the env
    files of the merged document read once after it with the merged environment winning, as Compose reads them
    (compose_variables.resolve_env_files / env_file_paths, inline_env_files(document, None, ...)); overlay
    errors that name a field's path and the value's type, or a YAML error's line and column, never a value;
    synthesized_group() (main alone) for image-only tasks;
    merged_mcp_servers with Harbor's trial.py rule (task entries first, a job entry replaces a task entry of
    the same name); compile_prompt_template / render_compiled_template / wrap_first_instruction mirroring
    Harbor's utils/templating.py (Jinja2, StrictUndefined, {{ instruction }} required), the block compiling
    its template once when it is read and rendering the compiled one per episode (render_instruction).
  • nemo_gym/tasks/harbor/image_configs.py: load_compose_document(task, overlay=...) merges the overlay files
    after the task's file with the same variables (and the deployment's compose_variables at seed), or onto the
    synthesized group when the task has no Compose file, and refuses a merged document without a services
    mapping; record_compose_images(..., overlay=...) records the overlay's images (and an image-only task's own,
    now main of a group) with the tasks'. A field, bind source or service the group cannot run is reported
    naming the task's Compose file and the overlay files merged onto it (compose_source), since it may come from
    any of them.
  • nemo_gym/tasks/harbor/cli.py: compose_overlay_from_overrides reads
    harbor_environment_server.environment_servers.harbor.compose_overlay from the configuration the command names
    (like builds: and the provider blocks); prepare_target, validate_target, run_target and run_images
    take it, so prepare checks the merge per task and lists the overlay's images for pre-pulling.
  • environment_servers/harbor/app.py, sandboxes.py, session.py: the compose_overlay config field; a
    task is a Compose group when it ships a file or the overlay names files (_uses_compose); the seed's
    precheck, _compose_document and the private per-episode document (an overlay carries the operator's
    values) take the overlay, and the precheck refuses terminally (422) a group whose images prepare did not
    record for this deployment (_check_compose_images: no compose-images.json, or a merged service whose
    entry is missing or not reusable by prepare's own rule, image_configs.reusable_record: another platform or
    an old record version; the usual signs of a dataset prepared without this block or on another architecture,
    named in the reason) and a merged document the deployment cannot run
    (_check_compose_group: every check prepare ran, factored out of _compose_document: the field check, the
    volume planner, the services the task's artifacts and [[verifier.collect]] hooks name present in the merged
    document (image_configs.check_task_compose_services, new, run by prepare too: an overlay kafka: !reset
    against a hook in kafka used to pass prepare and both prechecks and fail inside the group's start) and no
    extra_hosts on a sidecar whose recorded image runs as a non-root user
    (image_configs.check_task_sidecar_extra_hosts, the record file the seed already read handed in), so an overlay
    changed since prepare fails with prepare's reason instead of being retried every episode); the merged MCP list
    (_task_mcp_servers) is what /tmp/.nemo-gym/task.json,
    the task_mcp_grants grant list and the supports_task_tool_context refusal use (an overlay entry that cannot
    be granted, an sse one, is warned about once per run by name, a task's own at every seed as before);
    _with_prompt_template
    renders the template around the first turn's user message before anything is provisioned, so the harness,
    the first turn's ATIF transcript and a single-turn result carry the rendered instruction (a multi-step
    result records the last turn's params, as the M34 record does; a template that does not render is a
    terminal seed failure with no sandbox; the rendered turn is sent with the row's own keys only, since the
    template round trip dumps the set fields); one INFO line per episode names the merged group's services and MCP
    names (the servers log at WARNING by default). configs/harbor.yaml documents the block; requirements.txt adds jinja2>=3.1 (already vetted
    in the ray extra; the import is lazy, so harnesses that import the module need no Jinja).
  • README "Job-level Compose overlay" section and the "Where settings live" table; Harbor tasks docs page section.

Parked (noted in the README): wrapping every turn of a multi-step task with the template, and recording each
turn's responses_create_params on the turn result so a multi-step rollout shows the rendered first turn; Compose secrets:
(the adapter has none, so the memory team's Redis stack needs a third glue file that resets the secret and sets
the variable instead; configs: likewise); build: on an overlay service.

Test plan

  • tests/unit_tests/test_harbor_compose_overlay.py (39): the memory team's shape merged onto a
    multi-service task group and onto an image-only task; mapping, sequence, keyed-sequence, command,
    depends_on/networks, extra_hosts/labels rules; !reset (and setting the key again later), a
    per-variable !reset through two overlay files, a bare re-declaration keeping the earlier value, !override; host substitution per file with defaults and :?; markers kept through interpolation; YAML
    shape errors; MCP merge by name with Harbor's order; the block's validation; template rendering, the
    missing-instruction and StrictUndefined refusals, first-user-message wrapping; load_compose_document
    with and without a task file, overlay env_file and bind sources resolved against the project directory (an
    overlay's ./api.env is the task's environment/api.env, a same-named file beside the overlay not read; ./conf
    and a long-syntax source: conf uploaded from the task's environment/, a ../ that leaves the task a foreign
    source, ~ the home directory, a bare name a named volume, a missing ./conf "which the task folder does not
    contain"); shape and YAML errors naming the path and the kind, never a secret-looking value; env files read once after the merge with
    the merged environment winning, env_file: !reset [] / !override / append on the task's list,
    environment: !override [...] replacing, an overlay env_file anywhere (absolute, or relative leaving the task)
    read and a task's escaping one refused; record_compose_images, run_images and prepare_target recording the overlay's images; a
    privileged field, a secrets: block, a build:, a foreign bind source and a relative one the task lacks in an overlay skipping the task
    with a reason that names the overlay files (and the task's file when it has one); services: !reset refused
    with a reason; an overlay that resets a service the task's collect hook runs in skipped naming the overlay files
    and the service (and a task's own file lacking a hook's service skipped naming that file); the block compiling its template once (no file read per render, an edit not seen until the
    block is read again); compose_overlay_from_overrides through a --config file with the block swapped by
    one value.
  • environment_servers/harbor/tests/test_compose_overlay.py (21): an image-only task resolves to main
    plus the overlay's services with !reset, the extra network and the named volume honoured; the episode
    seeds the group and stops it; the merged document stays private; overlay MCP entries merged with the task's
    in task.json and the grant list (overlay wins on a name, sse stays in the context file); overlay-only MCP
    entries refuse a harness without supports_task_tool_context; the template wraps the first turn of a
    single-turn and of a three-step task only, the posted bodies carrying the rows' own keys with the rendered
    content (the latter's result recording the last turn's params as written);
    a template that does not render fails before any sandbox; an overlay image prepare did not record, a record of
    another platform or an old record version, or no record file at all, is a terminal seed refusal naming the
    services (and what was recorded) before any group starts; an overlay field the group cannot run, a foreign bind
    source no volume_sources entry maps, a relative bind source the task folder lacks, a removed services
    mapping and extra_hosts on the non-root overlay sidecar are terminal seed refusals naming the overlay file,
    with no group started, each with the reason prepare's skipped records for the same overlay; an overlay that
    resets the service a collect hook runs in is refused the same way with prepare's exact reason; a job-level sse
    entry is warned about once over three episodes while the task's own sse entry is warned about at each.
  • environment_servers/harbor/tests -k "not partial_eval and not buildah and not validate_ and not real_image":
    430 passed (409 on the base + 21 new); responses_api_agents/harbor_oracle_agent/tests: 22 passed; the
    touched core unit test files together (test_harbor_compose_*, test_harbor_image_*,
    test_harbor_validation): 268 passed (plus the two test_harbor_validation tests that read a local
    env.yaml, unrelated); ruff check, ruff format --check, pre-commit run --files clean.
  • Live: gym dataset validate of MemoryArenaBundledShopping 0000-baking-item-0 (six steps) on
    OpenSandbox with the oracle, the memory team's Redis overlay (sse) attached, then the same command with
    ++memory_backend=hindsight (their Hindsight overlay, streamable-http). See REPORT.md in the group folder.

🤖 Generated with Claude Code

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a338b16

@adil-a
adil-a added this pull request to stack #4793 October 21, 2026 16:26
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 21, 2026 16:31
@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Oct 21, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a78e40f

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6264b5d

@adil-a

adil-a commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test dd0bc45

@adil-a

adil-a commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test fd0e0ae

@adil-a

adil-a commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f599aee

@adil-a

adil-a commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 70a3914

@ffrujeri ffrujeri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the thorough follow-ups. I rechecked all ten earlier threads against 70a3914 and each fix is in place with a covering test; the focused suites pass locally. Required CI is green; the only red check is the non-blocking kilocode conformance probe. One open question is about trust: task-supplied variables and services can currently override operator-owned values in the job-level overlay. It would be good to either change the precedence or document it before this lands.

Comment thread nemo_gym/tasks/harbor/image_configs.py Resolved
Comment thread nemo_gym/tasks/harbor/image_configs.py Resolved
@adil-a

adil-a commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 9161c61

@adil-a

adil-a commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6866650

@adil-a

adil-a commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4c3b0f5

@adil-a

adil-a commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3de0d68

@adil-a

adil-a commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5effc9d

@yuhezhang-ai

Copy link
Copy Markdown
Contributor

Rechecked 5effc9d9 against parent 890edb2f: 191 focused checks passed, including the original review reproductions.

The image replacement, scalar !override, removed env-file, mixed tmpfs, and IPv6 findings are addressed. The preflight work now runs off the event loop, context hashing is reused, and the Jinja installation and preparation-variable guidance address the two documentation comments. The private-document cleanup fix is included in the parent and passes the original reproduction.

The cleared-entrypoint reproduction also passes. My remaining concern is the startup user/directory difference described in that thread.

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2620d78

ffrujeri
ffrujeri previously approved these changes Oct 26, 2026

@ffrujeri ffrujeri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks.

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f419385

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 9ea1b8f

ffrujeri
ffrujeri previously approved these changes Oct 26, 2026

@ffrujeri ffrujeri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 11e9a05

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e2df80a

@adil-a

adil-a commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 19ff5a5

@adil-a

adil-a commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 13713d9

ffrujeri
ffrujeri previously approved these changes Oct 27, 2026

@ffrujeri ffrujeri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/40534927560

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/40540771458

…ate (M30)

The run config can attach services and tools to every task of a run without
touching the tasks, as Harbor's job config does with `extra_docker_compose`,
`agents[].mcp_servers` and an agent's `prompt_template_path`. One block of the
Harbor environment server's configuration, `compose_overlay`, holds the three:

- `files`: Compose files merged, in order, onto every task's Compose document
  after the task's own file, the way Compose merges `-f` files (mappings key by
  key, sequences appended with the keyed ones unique on their key, environment
  and labels as mappings, depends_on and networks as mappings, command,
  entrypoint and healthcheck.test replaced whole, a key written with no value
  keeping the earlier file's value, `!reset` removing an earlier attribute or
  one environment variable and `!override` replacing instead of merging). Each
  file is interpolated with the task's variables; its relative paths resolve
  against the Compose project directory, the task's environment folder, as
  Compose resolves every -f file's and Harbor's --project-directory names it
  (never against the overlay file's own folder): its env_file entries (any
  readable file, the overlay being the operator's) are made absolute against it
  before the merge, its bind sources are left to the volume planner, which
  resolves them against the same folder as the task's, and the env files of the
  merged document are read once after it with the merged environment winning,
  as Compose reads them. A task that declares only an image gets Harbor's
  one-service group (`main`) first. The merged document goes through the same
  field check, volume planner and image resolution as a task's file, and must
  keep a services mapping; anything the group cannot run is reported naming the
  task's Compose file and the overlay files merged onto it, since the service
  or field may come from any of them; an overlay error names the field's path
  and the value's kind, or the YAML error's line and column, never a value,
  since overlay files carry the deployment's keys. The overlay's services start with the
  task's group and stop with it. Prepare reads the same block from the
  configuration the command names, records the overlay's images with the tasks'
  and checks the merge per task; a server run with an overlay the dataset was
  not prepared with (no record of an image, or a record of another platform or
  record version, by prepare's own reuse rule), or whose merged document the
  deployment cannot run (the seed runs every check prepare ran: the field
  check, the volume planner, the services the task's artifacts and collect
  hooks name present in the merged document, no extra_hosts on a sidecar whose
  recorded image runs as a non-root user), is refused at seed, terminally, with
  the reason prepare gives. The merged document is private per episode.
- `mcp_servers`: merged by name with the task's `[[environment.mcp_servers]]`
  as Harbor's trial merges the job's with the task's (the overlay's entry
  replaces a task entry of the same name); the merged list reaches the harness
  in /tmp/.nemo-gym/task.json and in the one grant list of its session seed (an
  overlay entry that cannot be granted, an `sse` one, is warned about once per
  run, a task's own at every seed as before).
- `prompt_template`: a Jinja file with `{{ instruction }}`, read and compiled
  once when the block is read, rendered with StrictUndefined around the
  instruction of the episode's first turn before anything is provisioned, so
  the harness, the first turn's transcript and a single-turn result carry the
  rendered instruction (a multi-step result records the last turn's params);
  the rendered turn is sent with the row's own keys only. Later turns are sent
  as written (parked).

No task file changes. Documented in the server README and the Harbor tasks
page; the shipped harbor.yaml names the block.

Signed-off-by: Adil Asif <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@adil-a

adil-a commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0678258

@yuhezhang-ai yuhezhang-ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving 0678258329d88e30ec525d5b3d4fbb6d5e227968 with one explicit, non-blocking follow-up. The startup user/directory bug remains reproducible and still needs a fix. This approval accepts that work in a follow-up PR; it does not mark the issue resolved.

Adding job-level Compose files to an image-only task can change the user and working directory used by its startup script:

  • With RUN useradd -m app, USER app, and WORKDIR /home/app/work, the script starts as app in /home/app/work without the job overlay, but as root in the base image's /srv with it.
  • With [agent].user = "other", a separate case changes the startup user from app to other.

This can break initialization, file ownership, and relative paths. Subsequent agent commands use the intended user and directory. The new exposure requires opting into the job-level Compose files, so I am treating this as a scoped follow-up rather than holding this PR. The reproduction and earlier discussion are in #4863 (comment).

Work still required in the follow-up:

  1. Preserve the task's effective startup user and directory after setup completes, or explicitly reject unsupported combinations before running the task.
  2. Add regression coverage comparing startup with and without job overlays for both cases above, while preserving directory ownership during setup.
  3. Document the limitation for users and link the follow-up issue or PR in the existing thread. Tasks whose initialization depends on these settings need the fix or explicit rejection before relying on this feature.

Validation at this head: 191 focused checks passed, including the original review reproductions. The two additional startup comparisons still fail through the real adapter with fake providers; no live containers were launched for those comparisons. The other earlier findings are addressed. Main CI and the unit/server suites pass; the explicitly non-blocking Kilocode conformance check remains red.

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/40609233979

This branch was previously deployed

1 inactive deployment
public — 06782583 Deployed Oct 27, 2026 by copy-pr-bot[bot] via release / finalize / notify #7653
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer QA_verified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants