Repository navigation
Conversation
load_registry promises that one bad profiles.json cannot 500 every route that reads the registry, and degrades to the legacy fallbacks and then an empty registry. Its three reads caught json.JSONDecodeError and UnicodeDecodeError only. json.loads raises RecursionError on a file nested past the interpreter limit, and a plain ValueError on a number past the integer digit limit; neither is a JSONDecodeError, so either escaped every reader. The locked writer caught ValueError but not RecursionError, so a nested file raised out of a profile save instead of being set aside. Each read now catches ValueError (which covers JSONDecodeError and UnicodeDecodeError) and RecursionError, so such a file takes the same fallback ladder as truncated JSON, and the locked writer moves it to <name>.corrupt-<utc> before the save, as it does for truncated JSON. Closes kirodotdev#29089
5 tasks done
Contributor
|
[operator: bolichen97] Continuing this in #32454; thanks for the start. |
bolichen97
added a commit
that referenced
this pull request
Nov 7, 2026
…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
buluoray
pushed a commit
that referenced
this pull request
Nov 8, 2026
…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)
buluoray
pushed a commit
that referenced
this pull request
Nov 8, 2026
…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)
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Motivation
Goal: A
profiles.jsonthatjson.loadsrefuses outright costs one registry read, not every deploy route and every profile save.load_registry(src/kiro_crew/deploy/profiles.py) promises that one badprofiles.jsoncannot 500 every route that reads the registry, and degrades to the legacy fallbacks and then an empty registry. Its three reads caughtjson.JSONDecodeErrorandUnicodeDecodeErroronly.json.loadsraisesRecursionErroron a file nested past the interpreter limit, and a plainValueErroron a number past the integer digit limit; neither is aJSONDecodeError, so either escaped out of 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 set aside.Why it matters
The registry is agent-writable and operator-editable. Every deploy route, the AWS Control account resolver and the consent card read it, so one such file blanks the whole deploy surface, and a profile add or edit on top of it fails instead of moving the file aside the way it already does for truncated JSON.
Not a goal
load_registrydegrades silently for every unreadable shape today, and the locked writer's_set_asidealready logs the move.json.loadssites underdeploy/, which parse AWS CLI output or a request body rather than the registry file.What changed (motivation → approach → change)
Symptom: a
profiles.jsonholding[[[[...]]]]past the decoder depth, or{"default": 999...9}with 5000 digits, makesload_registry()raise, andlocked_registry()raises on the nested one. Cause: the except tuples namejson.JSONDecodeErrorandUnicodeDecodeError, andRecursionErroris not aValueErrorat all. Change: each of the three reads catchesValueError(which covers both named exceptions and the digit-limit one) andRecursionError, the same(ValueError, RecursionError) # past the nesting limitshapedeploy/pending.pyand the readers in #29058 and #29059 use, so such a file takes the fallback ladder the function already implements. The locked writer catches the same pair, so the file is moved to<name>.corrupt-<utc>before the save. Theload_registrydocstring names the two 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.
Removes nothing: no route, key, setting or public function is removed.
Tests
test/test_deploy_registry_shape.pygains two parametrized tests over the two refused shapes (nested past the decoder, over the digit limit): all three registry files refused still end at the empty default without raising, and a refused primary still falls through to the legacy registry.test/test_deploy_registry_unreadable_write.pyadds the same two shapes to the moved-aside parametrization: the write lands, the original bytes sit in<name>.corrupt-<utc>, and the warning names it. The nested text comes from the sharedstray_line_helpers.too_deep_to_decode()probe; the writer's over-digit case already passed and stays as a control.Proof: PROVEN test/test_deploy_registry_shape.py::test_a_registry_json_loads_refuses_reads_as_empty_at_every_step[nested-past-the-decoder], test/test_deploy_registry_shape.py::test_a_registry_json_loads_refuses_reads_as_empty_at_every_step[over-digit-limit] (head 15f3e45)
Determinism: the two test files pass 20/20 at
-n0, 10/10 at-n 4 --dist loadgroup --max-worker-restart=2besidetest_deploy_web_profiles.pyandtest_deploy_round37_fixes.py, and in a shuffled order (seed 29089, 27 node ids). With the production hunk reverted, 5 of the 27 fail (both reader tests for both shapes, and the writer's nested case).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 the writer's sets the file aside
Sibling: src/kiro_crew/deploy/handlers.py:828 -- not affected -- parses the request's own body, not a shared file; a refused body fails that one request, not every route
Sibling: src/kiro_crew/deploy/engine.py:481 -- 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.