Skip to content

fix(update): copy memory before the unattended policy-provider apply - #23760

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/21898-policy-update-memory-copy
Oct 24, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/21898-policy-update-memory-copy

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The gateway's unattended policy-provider update takes a fresh copy of every memory store before it rewrites the install, and skips the update when that copy fails.

On a host whose security policy sets an apply_command, _check_for_updates_via_provider runs provider.apply() for the mandatory min_version floor and for voluntary auto-update. Neither call takes the pre-update memory copy that kirocrew update, the dashboard apply button and the git auto-update take. So the gateway can rewrite the install with no fresh copy of any memory store.

Why it matters

Memory stores are the one thing nothing else can rebuild. A policy-managed host updates itself with nobody watching, so a bad update there could leave the user with no recent copy to restore from.

Not a goal

  • Moving the copy into the shared seam (update_provider.apply_policy_update / the provider's apply()) and removing the caller-side copies in the dashboard and CLI. See "Decision" below.
  • Any change to the dashboard, CLI, git or managed-venv update paths.

What changed (motivation → approach → change)

Symptom: the policy-provider applier was the one unattended applier with no pre-update memory copy. Cause: the copy lives at each caller, and this caller never got one.

Change: before each of the two provider.apply() calls, the gateway runs wheel_apply.snapshot_memory_before_update. If it fails, the update is skipped the same way the git auto-update skips it: a warning in the log, one dashboard notice, and a failed progress line built by wheel_apply.snapshot_refusal. It never applies blind and never exits the gateway; the next check tries again. The apply slot is still released. The failure text is redacted and capped at 500 characters before it is shown, like the git path.

The placement test (test/test_update_memory_copy_placement.py) now scans slack/gateway_runtime/update_schedule.py and counts provider.apply() as a rewrite. A nested copy helper's own body does not count as a copy site, so each provider.apply() needs its own call to the helper.

Decision. The issue lists two levels. This PR takes the caller-side one, matching how #21873 covered the dashboard and git appliers. It is the smaller change, it touches only the unattended path, and each caller keeps its own way of reporting a refusal (the CLI exits, the dashboard returns 500, the gateway posts a notice). The seam move changes the CLI and dashboard paths too, and the seam has no caller-neutral way to report a refusal, so it is left for a maintainer to rule on.

Backwards compatibility

Compatible: an update that copies memory successfully applies exactly as before; only an update whose copy fails is now skipped instead of applied.

Removes nothing: no key, path, record or public function is removed; the only new behaviour is a skip when the memory copy fails.

Tests

  • test/test_slack_gateway_update_provider_snapshot.py: for both sites (min_version floor and auto-update), the copy runs before provider.apply(); a failed copy skips the apply, skips the restart, releases the apply slot, and posts the notice and the failed progress line.
  • test/test_update_memory_copy_placement.py: pins _check_for_updates_via_provider as a known applier. Removing either helper call fails it.

Proof: PROVEN test/test_slack_gateway_update_provider_snapshot.py::test_the_memory_copy_runs_before_the_provider_apply[min_version-floor], test/test_slack_gateway_update_provider_snapshot.py::test_the_memory_copy_runs_before_the_provider_apply[auto-update], test/test_slack_gateway_update_provider_snapshot.py::test_a_failed_copy_skips_the_apply_and_says_so[min_version-floor], test/test_slack_gateway_update_provider_snapshot.py::test_a_failed_copy_skips_the_apply_and_says_so[auto-update], test/test_update_memory_copy_placement.py::test_every_rewrite_is_preceded_by_the_memory_copy[slack/gateway_runtime/update_schedule.py::_check_for_updates_via_provider] (head 7de4bc3)

Mutant check: replacing either if not await _snapshot_memory_or_skip(result): with if False: fails the behaviour test for that site and the placement test.

Manual verification

N/A — unit coverage sufficient: both call sites and the refusal path are driven directly with a real CommandProvider and a stubbed copy step.

Related Issues

Closes #21898

Sibling sweep

Swept: git grep -nE "provider.apply(|apply_policy_update(" -- src/
Sibling: src/kiro_crew/cli_server_update.py:109 -- not affected -- _update runs _snapshot_memory_or_exit before apply_policy_update
Sibling: src/kiro_crew/dashboard/handlers/updates_apply.py -- not affected -- api_update_apply runs _snapshot_memory_or_refuse before the tracked policy apply
Sibling: src/kiro_crew/platform/update_provider.py:561 -- not affected -- the seam itself; its two callers above copy first
Sibling: src/kiro_crew/slack/gateway_runtime/update_schedule.py -- changed here

Pattern harvest

Rule candidate: lint
Pattern: a call that rewrites the install with no memory copy since the previous rewrite; the placement test already enforces this, and this PR adds the provider path to its scan.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 7de4bc3cf132f8897bae13b4bfc19f3d067b4c43 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 7de4bc3cf132f8897bae13b4bfc19f3d067b4c43 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change adds the same copy-or-skip step the other appliers already take to the one unattended applier that lacked it, and the placement test now enforces it.

Notes

  • When the memory copy fails, the mandatory min_version update is now skipped, so the host stays below the policy minimum and retries on every check. A copy that fails every time (disk full, a store that can't be read) keeps the host out of compliance indefinitely, and the only signal is a notice shown once. It is worth deciding whether the enterprise administrator should see that outcome somewhere they will look.

[DESIGN-REVIEWED] 7de4bc3

Description read

[DESCRIPTION-READ] 0c6f59cbc41ed93744fbd90029dfddfc0c899823d06763657d47db157a41ab58

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 7de4bc3cf132f8897bae13b4bfc19f3d067b4c43 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The gap comes from issue #21898 and is pinned by the placement test. One note: the refusal block is now written out twice.

Notes

  • Item 3 — duplicate of slack/gateway_runtime/update_apply.py:647-663: the new _snapshot_memory_or_skip body repeats that inline block step for step: redact_exfiltration_urls, redact_credentials, [:500], the same "Auto-update skipped: pre-update memory snapshot failed: %s" warning, _notice_wheel_update_once, push_update_progress("failed", …) and push_refresh("update_available"). That is 2 gateway sites with one sequence, and they will drift apart. Subtraction: replace the inline block in update_apply.py with a call to the one helper, so the gateway has a single copy-or-skip spelling.

What this change ships

Inventory (6 items) — 5 justified

Intent: a policy-managed host updating itself unattended always has a fresh memory copy to restore from. FIX.

  1. The mandatory min_version provider update copies memory before it rewrites the install — justified
  2. The voluntary provider auto-update copies memory before it rewrites the install — justified
  3. When the copy fails, the update is skipped with a log warning, one dashboard notice and a failed progress line — duplicate of the update_apply.py:647-663 inline block
  4. A host below the policy floor stays below it while the copy keeps failing, and the next check retries — justified
  5. The placement test now scans update_schedule.py and counts provider.apply() as a rewrite — justified
  6. The placement test no longer counts a nested copy helper's own body as a copy site — justified

[FIRST-PRINCIPLES-REVIEWED] 7de4bc3

Description read

[DESCRIPTION-READ] 1e144f3236c3d3137fc25387fb8cc0a7f642f0a967a82f680fb70d4bc34b00ee

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 7de4bc3cf132f8897bae13b4bfc19f3d067b4c43 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 7de4bc3

Verdict parsed from the review's SHA-scoped output markers for commit 7de4bc3cf132f8897bae13b4bfc19f3d067b4c43.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 7de4bc3cf132f8897bae13b4bfc19f3d067b4c43 false-positive: <reason, 20 to 500 characters>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 7de4bc3cf132f8897bae13b4bfc19f3d067b4c43 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 7de4bc3

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 7de4bc3cf132f8897bae13b4bfc19f3d067b4c43 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 24, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Review-ready at head 7de4bc3.

  • pr_status.py: exit 0, readiness: passed, 105 checks, 0 failing, 0 running.
  • green_age.py: FRESH (main has not moved in this PR's files).
  • GPT 6.1 and Opus 5.5: no findings. Design and First Principles: PASS. UX: skipped (no user-facing surface).
  • Mergeable, one commit, no open threads.

The First Principles note (the skip block repeats the one in update_apply.py) is a non-blocking note. I left it so this PR stays the same shape as #21873's git path.

Waiting on a maintainer review. I will not merge, approve or arm auto-merge.

🤖 AI-assisted comment 🤖

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 24, 2026 16:02

@KiroCrewCaptain KiroCrewCaptain 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.

Tier 1 auto-approve: fix (3 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: the unattended policy-provider update path now takes the same pre-update memory copy as the other update paths, and skips the apply when the copy fails; one source file plus tests.

@KiroCrewCaptain
KiroCrewCaptain merged commit 1b0a9e1 into main Oct 24, 2026
106 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/21898-policy-update-memory-copy branch October 24, 2026 16:03
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 24, 2026
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.

The unattended policy-provider update applies with no pre-update memory copy

2 participants