Skip to content

fix(agents): merge a resources patch element-wise onto the freshly-read spec - #13624

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/agents-resources-patch-11924
Sep 25, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/agents-resources-patch-11924

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Supersedes #11924, original author @rnoack1. In-repo replacement branch so the AI review lanes (which errored "review incomplete" on the fork — infrastructure, not a code finding) can re-run. Cherry-pick of the original change; authorship credited via Co-authored-by: rnoack1.

Problem / Motivation

api_agent_detail PATCH suffers a lost update. The document written back to the agent spec is built from a snapshot taken before the spec lock is acquired. Assigning that snapshot's resources list wholesale therefore drops any resource URI a concurrent writer added between the read and the lock.

Why it matters

Two overlapping edits to an agent's resources silently lose one writer's additions — a data-loss bug that is timing-dependent and hard to notice. Anyone editing an agent's resources while another writer (another tab, another client, an app) touches the same spec can have their addition erased.

What changed (motivation → approach → change)

  • Symptom: a resource URI added by a concurrent writer disappears after a PATCH that did not name it.
  • Root cause: the PATCH assigned a pre-lock resources snapshot whole, overwriting whatever landed under the lock.
  • Change: under the lock, merge only the resources delta the request itself named element-wise onto the freshly-read spec, instead of assigning the stale snapshot. A PATCH that names no resource change now leaves an existing (even malformed) resources value untouched rather than normalising a key it never read.

Not a product-shape change — no default, command, or user-facing capability changes. No RFC required.

Backwards compatibility

Compatible: the endpoint's request/response contract is unchanged; this only narrows what a PATCH writes back to the delta it named, fixing a lost-update rather than changing any accepted shape.

Tests

test/test_agent_detail_model_managed.py (+176) locks in:

  • a PATCH merge preserves a concurrent writer's added resource URI;
  • a PATCH naming no resource change leaves a malformed resources value alone;
  • clearing/setting the managed model resumes/stops tracking correctly;
  • the patch write stays governance-sanitized and lifts stale bookkeeping keys.

All 9 pass locally; the broader agent-handler suite (test_agent_config_merge_on_write.py, 54 tests) also passes.

Manual verification

N/A — unit coverage sufficient: the lost-update is reproduced deterministically by the concurrent-writer test.

Related Issues

Supersedes #11924.

Pattern harvest

Rule candidate: review-prompt
Pattern: mutating state assigned from a snapshot read before the lock, rather than merging the named delta onto the value re-read under the lock (read-modify-write outside the critical section).

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) — N/A, no user-facing docs affected
  • No secrets, credentials, or internal references in the diff

…ad spec

The document a PATCH writes back is built from a snapshot taken before the spec lock, so assigning its `resources` list whole dropped any URI a concurrent writer had added in between; only the URIs this patch itself named may move.
A patch that names no resource change now leaves a malformed `resources` value untouched rather than normalising a key it never read.

Co-authored-by: rnoack1 <69695077+rnoack1@users.noreply.github.com>
@iamwhatever
iamwhatever requested review from a team and buluoray September 25, 2026 01:29
@iamwhatever iamwhatever added the drive-to-green PR claimed by drive-to-green pipeline label Sep 25, 2026
@iamwhatever iamwhatever self-assigned this Sep 25, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of f62936a485b559b267b8dd0b88e201372eb4df12 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify the delta-merge assumption holds: resources is only ever written via skill mapping — if resources ever joins TEMPLATE_DEFINITION_KEYS, a direct set would silently become a merge.

[DESIGN-REVIEWED] f62936a

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of f62936a485b559b267b8dd0b88e201372eb4df12 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f62936a

False positive or not applicable? A repository writer can comment:
/ai-review override gpt f62936a485b559b267b8dd0b88e201372eb4df12: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of f62936a485b559b267b8dd0b88e201372eb4df12 — 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

Confirm test_a_skills_patch_keeps_a_uri_a_concurrent_writer_added fails on base — the lost-update defect's provenance rests on that reproduction, not the description.

What this change ships

Inventory (5 items) — 5 justified

Intent: FIX — stop an agent-detail PATCH from erasing a resource URI a concurrent writer added between the pre-lock snapshot and the locked write.

  1. A concurrent writer's added resource URI now survives an overlapping PATCH — justified
  2. A PATCH naming no resource change no longer rewrites a malformed resources value — justified
  3. Non-string resources entries survive a skills PATCH instead of being dropped — justified
  4. An empty merged resource list drops the key rather than writing [] — justified
  5. Four regression tests, including a deterministic concurrent-writer reproduction — justified

Notes for the audit trail: _merge_resources_delta has exactly one consumer (agents.py:3788, private helper, no generalized surface — grepped _merge_resources_delta, 1 call site). Item 4 carries the documented kiro-cli constraint at _shared.py:2541-2545 (empty list suppresses shipped steering defaults), so it is derived, not symmetry. No sibling lost-update key exists in this handler: resources is the only key derived from a pre-lock snapshot rather than named whole by the request; the key-level merge loop (pinned by pre-existing test_patch_merge_preserves_concurrent_writer_changes) already covers every other key. No pins deleted; diff is purely additive.

[FIRST-PRINCIPLES-REVIEWED] f62936a

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] f62936a

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable f62936a485b559b267b8dd0b88e201372eb4df12: <one-sentence reason>

@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 Sep 25, 2026
@chenmingwei23
chenmingwei23 merged commit 15a4277 into main Sep 25, 2026
145 of 163 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/agents-resources-patch-11924 branch September 25, 2026 05:39
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 25, 2026
@dwu96 dwu96 removed the drive-to-green PR claimed by drive-to-green pipeline label Sep 25, 2026
wknight1 pushed a commit to wknight1/KiroCrew that referenced this pull request Oct 5, 2026
…ad spec (kirodotdev#13624)

The document a PATCH writes back is built from a snapshot taken before the spec lock, so assigning its `resources` list whole dropped any URI a concurrent writer had added in between; only the URIs this patch itself named may move.
A patch that names no resource change now leaves a malformed `resources` value untouched rather than normalising a key it never read.

Co-authored-by: kirocrew-worker <worker@kirocrew.local>
Co-authored-by: rnoack1 <69695077+rnoack1@users.noreply.github.com>
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