Cancel software install records instead of deleting when an installer is deleted - #48127
Conversation
Deleting, editing, or batch-replacing a software installer hard-deleted pending host_software_installs rows. A late install result from orbit then 500'd in CreateIntermediateInstallFailureRecord ("no rows in result set"). Pending installs are now marked canceled (preserved, software_installer_id nulled by the FK) instead of deleted, so a late result can still be recorded; completed installs are still marked removed.
For #47348.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #48127 +/- ##
=======================================
Coverage 67.32% 67.32%
=======================================
Files 3657 3657
Lines 231248 231242 -6
Branches 12099 12099
=======================================
+ Hits 155689 155691 +2
+ Misses 61590 61586 -4
+ Partials 13969 13965 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThis PR fixes a 500 error on 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
server/datastore/mysql/software_installers.go (1)
1232-1233: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUpdate the comment to say these rows are canceled, not removed.
Line 1233 still describes “remove” even though the new behavior preserves
host_software_installsrows and setscanceled = 1.Proposed wording
-// deleted to remove any pending software installs +// deleted to cancel any pending software installs while preserving result rows.🤖 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 `@server/datastore/mysql/software_installers.go` around lines 1232 - 1233, Update the comment for the deletePendingSoftwareInstallsForPolicy function to accurately reflect the current behavior. Instead of describing the operation as "remove any pending software installs", change the comment to indicate that the function cancels pending software installs by setting the canceled flag to 1 while preserving the host_software_installs rows.
🤖 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.
Inline comments:
In `@server/service/integration_mdm_setup_experience_test.go`:
- Around line 5565-5571: The assertion query in the host_software_installs check
is not specific enough to prove a separate intermediate failure row was created.
Modify the SQL query WHERE clause to include a filter for execution_id that is
not equal to echoInstallUUID, ensuring we are checking a different record than
the original canceled row. Additionally, add filters for the expected
denormalized installer details to the query to tighten the scope and prevent the
test from passing if the original row were accidentally updated instead of a new
row being created.
---
Nitpick comments:
In `@server/datastore/mysql/software_installers.go`:
- Around line 1232-1233: Update the comment for the
deletePendingSoftwareInstallsForPolicy function to accurately reflect the
current behavior. Instead of describing the operation as "remove any pending
software installs", change the comment to indicate that the function cancels
pending software installs by setting the canceled flag to 1 while preserving the
host_software_installs rows.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 944ec47f-9bdb-498f-a7a2-cc9d694df6ea
📒 Files selected for processing (6)
changes/47348-dont-delete-host_software_installs-rowsserver/datastore/mysql/scripts.goserver/datastore/mysql/software.goserver/datastore/mysql/software_installers.goserver/datastore/mysql/software_test.goserver/service/integration_mdm_setup_experience_test.go
| waitBatchSetSoftwareInstallersCompleted(t, &s.withServer, teamName, batchResp.RequestUUID) | ||
|
|
||
| // EchoApp SE row gone, hsi cleaned up too | ||
| // EchoApp SE row gone; its running install is canceled with its installer id nulled, so it's |
Related issue: Resolves #47348
Does two things:
It also updates some comments.
deletePendingSoftwareInstallsForPolicyhad a comment that said it should be called after deleting a policy, but that seems wrong and was not actually reflected in the code even when it was originally added. It should be called before deleting the policy so that the siua.policy_id column is still available before it gets set to null by the FK constraint. Same fordeletePendingHostScriptExecutionsForPolicy.Also removes the
NOTE(mna): ...comment, because it seems like the code works as intended and only the comments were wrong.Checklist for submitter
If some of the following don't apply, delete the relevant line.
Changes file added for user-visible changes in
changes/,orbit/changes/oree/fleetd-chrome/changes.See Changes files for more information.
Input data is properly validated,
SELECT *is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters.Timeouts are implemented and retries are limited to avoid infinite loops
If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes
Testing
Added/updated automated tests
Where appropriate, automated tests simulate multiple hosts and test for host isolation (updates to one hosts's records do not affect another)
QA'd all new/changed functionality manually
Summary by CodeRabbit