Skip to content

Cancel software install records instead of deleting when an installer is deleted - #48127

Merged
jkatz01 merged 6 commits into
mainfrom
47348-software-install-result-500
Jun 24, 2026
Merged

Cancel software install records instead of deleting when an installer is deleted#48127
jkatz01 merged 6 commits into
mainfrom
47348-software-install-result-500

Conversation

@jkatz01

@jkatz01 jkatz01 commented Jun 23, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #47348
Does two things:

  • Removes the software_installers and software_titles joins. These could be null, but we would still want to create software install records for these installs even if the installer or title were deleted.
  • Changes every case where a host_software_installs is deleted into setting the canceled flag to 1 on that row.

It also updates some comments. deletePendingSoftwareInstallsForPolicy had 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 for deletePendingHostScriptExecutionsForPolicy.

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/ or ee/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

Summary by CodeRabbit

  • Bug Fixes
    • Prevented a 500 error when late software installation results are reported after the related installer has been deleted.
    • Pending software install entries are now preserved as canceled (instead of being deleted) during installer, policy, and batch update flows, keeping results consistent.
    • Improved correctness of intermediate failure recording and setup-experience deletion behavior, including distinguishing canceled vs removed installs.

jkatz01 and others added 5 commits June 22, 2026 14:56
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

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.41935% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.32%. Comparing base (3900de5) to head (679283b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
server/datastore/mysql/software_installers.go 74.07% 5 Missing and 2 partials ⚠️
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     
Flag Coverage Δ
backend 68.94% <77.41%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jkatz01
jkatz01 marked this pull request as ready for review June 23, 2026 21:25
@jkatz01
jkatz01 requested a review from a team as a code owner June 23, 2026 21:25

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 369b1793-ef49-46e6-843e-84d9ea62b3bb

📥 Commits

Reviewing files that changed from the base of the PR and between b2f8772 and 679283b.

📒 Files selected for processing (2)
  • server/datastore/mysql/software_installers.go
  • server/service/integration_mdm_setup_experience_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • server/datastore/mysql/software_installers.go
  • server/service/integration_mdm_setup_experience_test.go

Walkthrough

This PR fixes a 500 error on /api/fleet/orbit/software_install/result that occurred when a host reported a software install result after the corresponding installer had been deleted. The fix has two parts: CreateIntermediateInstallFailureRecord now reads title and filename fields directly from host_software_installs (where they are denormalized) instead of joining software_installers and software_titles, which may no longer exist. Across all cleanup paths—policy deletion, installer metadata updates, and BatchSetSoftwareInstallers empty-input and not-in-list branches—pending host_software_installs rows are now soft-canceled (canceled = 1) rather than physically deleted, preserving the rows for late result reporting. The removed flag updates are narrowed to exclude already-canceled rows.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: converting deleted software install records to canceled status when an installer is deleted.
Description check ✅ Passed The description explains the root cause, the fix approach, related testing, and completed checklist items. It references the linked issue and covers both main changes (removing joins and implementing the canceled flag).
Linked Issues check ✅ Passed The PR directly addresses issue #47348 by removing joins that could fail when records are deleted and preserving pending installs as canceled instead of deleting them, allowing late install results to be recorded.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the root cause: removing joins in the query, implementing the canceled flag for pending installs, updating comments about policy deletion timing, and adding comprehensive tests.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 47348-software-install-result-500

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
server/datastore/mysql/software_installers.go (1)

1232-1233: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Update the comment to say these rows are canceled, not removed.

Line 1233 still describes “remove” even though the new behavior preserves host_software_installs rows and sets canceled = 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3900de5 and b2f8772.

📒 Files selected for processing (6)
  • changes/47348-dont-delete-host_software_installs-rows
  • server/datastore/mysql/scripts.go
  • server/datastore/mysql/software.go
  • server/datastore/mysql/software_installers.go
  • server/datastore/mysql/software_test.go
  • server/service/integration_mdm_setup_experience_test.go

Comment thread server/service/integration_mdm_setup_experience_test.go Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@jkatz01
jkatz01 merged commit b784de8 into main Jun 24, 2026
45 checks passed
@jkatz01
jkatz01 deleted the 47348-software-install-result-500 branch June 24, 2026 14:00
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.

5XX on /api/fleet/orbit/software_install/result

2 participants