Skip to content

LCORE-1869: Add graceful teardown and automatic cleanup for llama-stack container#1802

Open
anik120 wants to merge 1 commit into
lightspeed-core:mainfrom
anik120:container-cleanup-routine
Open

LCORE-1869: Add graceful teardown and automatic cleanup for llama-stack container#1802
anik120 wants to merge 1 commit into
lightspeed-core:mainfrom
anik120:container-cleanup-routine

Conversation

@anik120
Copy link
Copy Markdown
Contributor

@anik120 anik120 commented May 26, 2026

Description

Key Changes:

  • Auto-stop container when exiting make run (Ctrl+C) via trap handler
  • Graceful shutdown with 10s timeout before force-kill
  • Preserve logs to /tmp/llama-stack-*.log on shutdown/removal

Developer Experience:

  • No manual cleanup needed - just Ctrl+C
  • Logs preserved after container removal
  • Clearer feedback during shutdown

Signed-off-by: Anik Bhattacharjee anbhatta@redhat.com

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement
  • Benchmarks improvement

Tools used to create PR

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: (e.g., Claude, CodeRabbit, Ollama, etc., N/A if not used)
  • Generated by: (e.g., tool name and version; N/A if not used)

Related Tickets & Documents

  • Related Issue #
  • Closes #

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

  • Chores
    • Improved container lifecycle management with graceful shutdown handling and signal trapping on exit, interrupt, or termination.
    • Enhanced container failure diagnostics by capturing logs to persistent files for troubleshooting.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Walkthrough

Makefile updates add a trap in run to call stop-llama-stack-container on EXIT/INT/TERM, introduce stop-llama-stack-container for a 10s graceful stop with log capture and force-kill fallback, and change remove-llama-stack-container to save container logs before removal.

Changes

Container Lifecycle Management

Layer / File(s) Summary
Signal handling and lifecycle declarations
Makefile
.PHONY targets expanded to include stop-llama-stack-container; run target registers an EXIT/INT/TERM trap that calls the stop target.
Container graceful shutdown and cleanup
Makefile
Added stop-llama-stack-container implementing a 10s graceful stop, fallback log capture to /tmp/llama-stack-failure.log, and force-kill; updated remove-llama-stack-container to save logs to /tmp/llama-stack-last-run.log before removal, both guarded by the container-exists check.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • tisnik
  • radofuchs
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding graceful teardown and automatic cleanup for the llama-stack container, which aligns directly with the PR's core objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…ck container

**Key Changes:**
- Auto-stop container when exiting `make run` (Ctrl+C) via trap handler
- Graceful shutdown with 10s timeout before force-kill
- Preserve logs to `/tmp/llama-stack-*.log` on shutdown/removal

**Developer Experience:**
- No manual cleanup needed - just Ctrl+C
- Logs preserved after container removal
- Clearer feedback during shutdown

Signed-off-by: Anik Bhattacharjee <anbhatta@redhat.com>
@anik120 anik120 force-pushed the container-cleanup-routine branch from b180b20 to 0b2ff52 Compare May 27, 2026 18:58
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Makefile (1)

15-15: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make E2E container name match LLAMA_STACK_CONTAINER_NAME

  • Makefile sets LLAMA_STACK_CONTAINER_NAME ?= lightspeed-llama-stack, but E2E scripts hardcode the Docker container name "llama-stack" when calling docker inspect/stop/start (e.g., tests/e2e/features/steps/health.py, tests/e2e/features/environment.py) and don’t reference LLAMA_STACK_CONTAINER_NAME.
  • Fix by updating E2E to use LLAMA_STACK_CONTAINER_NAME (via a shared helper/config/env var) or by ensuring make run starts the container with the "llama-stack" name.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` at line 15, E2E scripts hardcode the Docker name "llama-stack"
while the Makefile defines LLAMA_STACK_CONTAINER_NAME; update the E2E code
(e.g., in tests/e2e/features/steps/health.py and
tests/e2e/features/environment.py) to read the container name from the
environment variable LLAMA_STACK_CONTAINER_NAME (use
os.environ.get('LLAMA_STACK_CONTAINER_NAME', 'llama-stack')) and use that value
for all docker inspect/stop/start invocations so the tests follow the
Makefile-controlled container name.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@Makefile`:
- Line 15: E2E scripts hardcode the Docker name "llama-stack" while the Makefile
defines LLAMA_STACK_CONTAINER_NAME; update the E2E code (e.g., in
tests/e2e/features/steps/health.py and tests/e2e/features/environment.py) to
read the container name from the environment variable LLAMA_STACK_CONTAINER_NAME
(use os.environ.get('LLAMA_STACK_CONTAINER_NAME', 'llama-stack')) and use that
value for all docker inspect/stop/start invocations so the tests follow the
Makefile-controlled container name.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 984d99d4-8f79-40fb-89cc-a77c41f14088

📥 Commits

Reviewing files that changed from the base of the PR and between b180b20 and 0b2ff52.

📒 Files selected for processing (1)
  • Makefile
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: spectral
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: build-pr
  • GitHub Check: Pylinter
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
  • GitHub Check: E2E: library mode / ci / group 1
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: E2E: server mode / ci / group 1
  • GitHub Check: E2E: library mode / ci / group 2
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
🧰 Additional context used
🪛 checkmake (0.3.2)
Makefile

[warning] 21-21: Required target "all" is missing from the Makefile.

(minphony)


[warning] 21-21: Required target "clean" is missing from the Makefile.

(minphony)


[warning] 21-21: Required target "test" is missing from the Makefile.

(minphony)


[warning] 35-35: Target body for "stop-llama-stack-container" exceeds allowed length of 5 lines (11).

(maxbodylength)


[warning] 48-48: Target body for "remove-llama-stack-container" exceeds allowed length of 5 lines (7).

(maxbodylength)

🔇 Additional comments (4)
Makefile (4)

20-20: LGTM!


24-25: LGTM!


35-46: LGTM!


48-55: LGTM!

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.

1 participant