Repository navigation
fix(deploy): degrade a profile registry json.loads refuses outright - #32454
Conversation
load_registry promises that one bad profiles.json cannot 500 every route that reads the registry. Its three reads caught json.JSONDecodeError and UnicodeDecodeError only, so a file nested past the interpreter's recursion limit (RecursionError) or holding a number past the integer digit limit (a plain ValueError) escaped every reader. The locked writer caught ValueError but not RecursionError, so a nested file raised out of a profile save instead of being moved aside. Each read now catches ValueError and RecursionError, and the locked writer sets a nested file aside to <name>.corrupt-<utc> before the save, as it already does for truncated JSON. Builds on #29252. Closes #29089
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. This is a narrow fix that widens the exception lists so the existing fallback and set-aside paths now cover the two inputs [DESIGN-REVIEWED] b1cdab4 Description read[DESCRIPTION-READ] d1958f971da5242efde33850bc66ef454dff79cc6a5cb98fbcb0efde582e2f8e 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. This is a widened exception list in the three reads and one write that already promise to degrade an unreadable registry, and it is backed by #29089 and by tests that fail on base. Notes
What this change shipsInventory (4 items) — 4 justifiedIntent: one bad
[FIRST-PRINCIPLES-REVIEWED] b1cdab4 Description read[DESCRIPTION-READ] 941d67c8d1b90bdf36a154e0bab9074b805d23cd12d45863381b5ef5fe3c975c That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
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 deploy profile registry treats a ValueError or RecursionError from json.loads as an unreadable file and falls back, instead of raising.
…32454) load_registry promises that one bad profiles.json cannot 500 every route that reads the registry. Its three reads caught json.JSONDecodeError and UnicodeDecodeError only, so a file nested past the interpreter's recursion limit (RecursionError) or holding a number past the integer digit limit (a plain ValueError) escaped every reader. The locked writer caught ValueError but not RecursionError, so a nested file raised out of a profile save instead of being moved aside. Each read now catches ValueError and RecursionError, and the locked writer sets a nested file aside to <name>.corrupt-<utc> before the save, as it already does for truncated JSON. Builds on #29252. Closes #29089 (cherry picked from commit 32ce0d8)
…32454) load_registry promises that one bad profiles.json cannot 500 every route that reads the registry. Its three reads caught json.JSONDecodeError and UnicodeDecodeError only, so a file nested past the interpreter's recursion limit (RecursionError) or holding a number past the integer digit limit (a plain ValueError) escaped every reader. The locked writer caught ValueError but not RecursionError, so a nested file raised out of a profile save instead of being moved aside. Each read now catches ValueError and RecursionError, and the locked writer sets a nested file aside to <name>.corrupt-<utc> before the save, as it already does for truncated JSON. Builds on #29252. Closes #29089 (cherry picked from commit 32ce0d8)
Problem / Motivation
Goal: A
profiles.jsonthatjson.loadsrefuses outright costs one registry read, not every deploy route and every profile save.Builds on #29252 by @dimwael.
load_registry(src/kiro_crew/deploy/profiles.py) promises that one badprofiles.jsoncannot 500 every route that reads the registry: it falls back to the legacy registry, then the v1 config, then an empty registry. Its three reads caughtjson.JSONDecodeErrorandUnicodeDecodeErroronly.json.loadsraisesRecursionErroron a file nested past the interpreter's limit, and a plainValueErroron a number past the integer digit limit, so either one escaped every reader as an HTTP 500. The locked writer_load_registry_for_updatecaughtValueErrorbut notRecursionError, so a nested file raised out of a profile save instead of being moved aside.Why it matters
The registry is agent-writable and operator-editable. Every deploy route reads it, so one such file blanks the whole deploy surface, and adding or editing a profile on top of it fails instead of moving the file aside the way truncated JSON already is.
Not a goal
json.loadssites underdeploy/, which parse AWS CLI output or a request body rather than the registry file.load_registrydegrades silently for every unreadable file today, and the writer's set-aside already logs the move.What changed (motivation → approach → change)
A registry file nested thousands of levels deep, or holding a 5000-digit number, now reads like any other unreadable file instead of crashing every deploy page, and a profile save moves the nested file to
<name>.corrupt-<utc>before it writes.The cause was the exception list.
json.loadsrefuses these two files with aRecursionErrorand a plainValueError, and the reader's list named only the two narrowerValueErrorsubclasses (JSONDecodeError,UnicodeDecodeError). The writer already caught everyValueErrorbut had noRecursionErrorarm.Each of the three reads in
load_registrycatchesValueErrorandRecursionErrorinstead of the two subclasses, so these files take the fallback chain the function already has. The writer catches the same pair before it sets the file aside. This is the shapedeploy/pending.pyalready uses for its own file. Theload_registrydocstring names both exceptions.Backwards compatibility
Compatible: every file that read or saved before reads and saves the same; only a file that raised now degrades, or is set aside on a save.
Removes nothing: no route, key, setting or public function is removed.
Tests
test/test_deploy_registry_shape.pyadds one test over the two refused files (nested past the decoder, over the digit limit): with all three registry files refused,load_registrystill returns the empty default without raising.test/test_deploy_registry_unreadable_write.pyadds the nested file to the moved-aside cases: the save lands, the original bytes sit in<name>.corrupt-<utc>, and the warning names it. The nested text comes from the sharedstray_line_helpersprobe, and both tests hold the cyclic GC off for the walk, as testing-conventions asks of a recursion-limit test.Proof: PROVEN test/test_deploy_registry_shape.py::test_registry_files_json_loads_refuses_read_as_empty[nested-past-the-decoder], test/test_deploy_registry_shape.py::test_registry_files_json_loads_refuses_read_as_empty[over-digit-limit] (head b1cdab4)
Determinism: the two test files pass 10/10 at
-n0, 5/5 at-n 4 --dist loadgroup --max-worker-restart=2besidetest/test_deploy_web_profiles.py, and in a shuffled order (seed 29089, 24 node ids).Manual verification
N/A — unit coverage sufficient: each test drives the real
load_registry/locked_registryagainst a temp file; no UI or external service is involved.Related Issues
Closes #29089
Sibling sweep
Swept: git grep -nA3 "json.loads(" -- src/kiro_crew/deploy/
Sibling: src/kiro_crew/deploy/profiles.py -- changed here
Sibling: src/kiro_crew/deploy/pending.py -- not affected -- both reads already catch (ValueError, RecursionError), and its writer sets the file aside
Sibling: src/kiro_crew/deploy/handlers.py:828 -- not affected -- parses the request's own body, already catches (ValueError, RecursionError)
Sibling: src/kiro_crew/deploy/engine.py:560 -- not affected -- parses AWS CLI output the CLI itself serialized, not an operator-editable file
Sibling: src/kiro_crew/deploy/iam.py:844 -- not affected -- parses AWS CLI output the CLI itself serialized, not an operator-editable file
Pattern harvest
Rule candidate: semgrep
Pattern: json.loads(...) of an operator-editable file inside except JSONDecodeError (or ValueError) with no RecursionError, in a reader that promises to degrade an unreadable file
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the Apache-2.0 license of this project.