Skip to content

[T-096b] GazeboNav2Backend: subprocess lifecycle, process-group teardown, orphan check, InfraCheck mapping #202

Open

Description

@CodewithJha

Task T-096b · Milestone M9 — Gazebo backend · Size M · Priority P0 · Epic #9

Implements FR-SIM-003 · FR-RUN-005

Branch feat/t-096b-gazebonav2backend-subprocess-lifecycle-process-group — one task = one branch = one PR (doc 32 §6)

Summary

Implement backends/gazebo_nav2/backend.py: start ros2 launch in its own process group with episode env, wall timeout, SIGINT → grace → SIGTERM → SIGKILL group, pgrep orphan check (unhealthy worker on leftovers), read episode_done.json/trace, map exit codes to infra failures, entry point gazebo_nav2.

Context / motivation

Doc 10 §5, §9; pass the backend contract suite (sim marker).

Scope

In scope

  • Capabilities declaration (supported params, determinism level).

Implementation guidance

  • backends/gazebo_nav2/backend.py: class GazeboNav2Backend(SimulatorBackend) implementing the T-035a port: capabilities(), materialize(...) (delegates to T-096a), run_episode(req: EpisodeRequest) -> EpisodeResult, cancel(run_id).
  • process.py EpisodeProcess: subprocess.Popen(["ros2", "launch", launch_package, launch_file, f"workdir:={workdir}"], env=episode_env, start_new_session=True, stdout=log, stderr=STDOUT); wall timeout = time_limit_s / expected_rtf + startup_timeout_s + backends.gazebo_nav2.wall_margin_s (new).
  • Teardown (doc 10 §9): os.killpg(pgid, SIGINT) → wait teardown_grace_s → SIGTERM → wait teardown_term_wait_s (new, default 5) → SIGKILL; then scan with psutil for leftover gz, ros2, parameter_bridge processes of the slot; leftovers ⇒ raise WorkerUnhealthy so the worker exits and Docker restarts it.
  • Result mapping: read episode_done.json + trace.parquet; exit codes 10/11/12 or missing files ⇒ EpisodeResult(infra_failure=InfraReason.…), which InfraCheck (T-036a) turns into INVALID — never FAIL.
  • Entry point roboprobe.backends: gazebo_nav2 = roboprobe.backends.gazebo_nav2.backend:GazeboNav2Backend (append-only pyproject edit).
  • Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff PLR2004); public APIs typed (mypy strict) and documented.

Configuration keys

From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).

  • backends.gazebo_nav2.launch_package
  • backends.gazebo_nav2.startup_timeout_s
  • backends.gazebo_nav2.teardown_grace_s
  • backends.gazebo_nav2.wall_margin_s (new)
  • backends.gazebo_nav2.teardown_term_wait_s (new)

Acceptance criteria

  • Contract suite passes with --backend gazebo_nav2 (sim marker).
  • Teardown leaves no processes (test).
  • Killing gz mid-episode ⇒ INVALID with reason; the worker stays healthy when teardown is clean.
  • cancel() terminates within grace + term wait.
  • Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
  • Docs, config reference and CHANGELOG Unreleased updated where behaviour, keys or interfaces changed.
  • Definition of Done (doc 32 §3) satisfied.

Tests required

  • tests/sim/test_gazebo_backend.py.

Dependencies

Blocked by: #201 (T-096a), #200 (T-095), #48 (T-035a)

Blocks: #203 (T-097a), #204 (T-097b)

Parallelization notes

Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:

  • backend/src/roboprobe/backends/gazebo_nav2/backend.py
  • backend/src/roboprobe/backends/gazebo_nav2/process.py

Independent of other backends.

Definition of Done

Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-096b (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.

References

Design docs: doc 10 §5 · doc 10 §9 · doc 05 §4 · doc 30 §RB-04

Requirements: FR-SIM-003 · FR-RUN-005 (traceability: doc 28)

External:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:simulatorSimulator backends (kinematic2d, Gazebo adapter)milestone:M9M9 — Gazebo backendpriority:P0Critical path / blocks otherssize:M1-3 daystaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions