Skip to content

fix: exit non-zero when system caches delete task fails - #876

Open
pcbeingused333 wants to merge 2 commits into
posit-dev:mainfrom
pcbeingused333:fix/system-caches-delete-exit-code
Open

pcbeingused333 wants to merge 2 commits into
posit-dev:mainfrom
pcbeingused333:fix/system-caches-delete-exit-code

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Oct 21, 2026 •

Copy link
Copy Markdown

Related to #746 (the exact example there also needs changes on Connect).

What

rsconnect system caches delete now exits with status 1 when the Connect task that deletes the runtime cache finishes with a non-zero code or an error. Before, it printed nothing useful and exited 0, so scripts and CI could not tell that the cache had not been deleted.

Why

RSConnectExecutor.delete_runtime_cache waits for the task with raise_on_error=False and returns (result, task), but system_caches_delete in rsconnect/main.py dropped the return value. A failed task therefore never reached cli_feedback.

RSConnectExecutor.delete_runtime_cache no longer passes raise_on_error=False, so wait_for_task raises RSConnectException on a non-zero task code, which cli_feedback already turns into an error message and exit code 1. A dry run returns (result, None) and is unchanged.

Tests

Added to tests/test_main_system_caches.py (using the existing httpretty setup):

  • test_system_caches_delete_task_failed: the task finishes with code: 1 and an error; expects exit code 1 and Task exited with status 1. in the output. It fails on main (exit code 0) and passes with this change.
  • test_system_caches_delete_dry_run: no task, exit code 0 (covers the unchanged path).

tests/test_main_system_caches.py passes (9 tests), and ruff check and ruff format --check are clean. The failure path is exercised with httpretty; the change was not run against a live Connect server. The rest of the suite passes (1695 passed in one environment); the only failures seen were environment-dependent and unrelated to this change (test_quickstart.py::test_quickstart_requires_writable_cwd when running as root, which fails the same way on main, and in another environment test_environment.py::test_uv_lock_export and one test in tests/test_agent_cli_e2e.py).

This change was made with Claude Code.

🤖 Generated with Claude Code

The runtime cache deletion runs as a Connect task that is waited on with
raise_on_error=False, and the CLI discarded the returned task, so a task
that finished with a non-zero code or an error still produced exit code 0.
Raise an RSConnectException in that case so cli_feedback exits with 1.
Dry runs return no task and are unaffected.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@karawoo karawoo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the contribution @pcbeingused333. I think this doesn't exactly resolve the specific example in #746 but doing so would require some changes on Connect. For other cases where deletion fails and Connect reports an error, this change would catch it appropriately, however I think we should move handling to delete_runtime_cache.

Comment thread rsconnect/main.py Outdated
Comment on lines +5924 to +5927
_, task = ce.delete_runtime_cache(language, version, image_name, dry_run)
if task is not None and (task["code"] != 0 or task.get("error")):
reason = task.get("error") or "task exited with status %d" % task["code"]
raise RSConnectException("Failed to delete the runtime cache: %s" % reason)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Instead of handling this here could we instead make the change in delete_runtime_cache? I think we just need to remove raise_on_error=False

(_, task) = self.client.wait_for_task(result["task_id"], connect_logger.info, raise_on_error=False)

Remove raise_on_error=False so wait_for_task raises on a non-zero exit
code, and drop the duplicate check from system_caches_delete.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused333

Copy link
Copy Markdown
Author

Makes sense, thanks. Pushed a follow-up: delete_runtime_cache no longer passes raise_on_error=False, so wait_for_task raises on a non-zero task code, and the extra check in system_caches_delete is removed. The CLI test now expects Task exited with status 1. and exit code 1. Agreed this doesn't cover the exact example in #746 without Connect changes; I've reworded the description accordingly.

This branch has not been deployed

No deployments
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.

3 participants