Skip to content

fix(deploy): degrade a profile registry json.loads refuses outright - #32454

Merged
bolichen97 merged 1 commit into
mainfrom
fix/29089-registry-refused-json
Nov 7, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/29089-registry-refused-json

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A profiles.json that json.loads refuses 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 bad profiles.json cannot 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 caught json.JSONDecodeError and UnicodeDecodeError only. json.loads raises RecursionError on a file nested past the interpreter's limit, and a plain ValueError on a number past the integer digit limit, so either one escaped every reader as an HTTP 500. The locked writer _load_registry_for_update caught ValueError but not RecursionError, 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

  • Not changing how any decodable registry, or any wrong-shaped one, is read or written.
  • Not touching the other json.loads sites under deploy/, which parse AWS CLI output or a request body rather than the registry file.
  • Not adding a warning to the reader path: load_registry degrades 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.loads refuses these two files with a RecursionError and a plain ValueError, and the reader's list named only the two narrower ValueError subclasses (JSONDecodeError, UnicodeDecodeError). The writer already caught every ValueError but had no RecursionError arm.

Each of the three reads in load_registry catches ValueError and RecursionError instead 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 shape deploy/pending.py already uses for its own file. The load_registry docstring 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.py adds one test over the two refused files (nested past the decoder, over the digit limit): with all three registry files refused, load_registry still returns the empty default without raising. test/test_deploy_registry_unreadable_write.py adds 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 shared stray_line_helpers probe, 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=2 beside test/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_registry against 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

  • 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

Contribution License Agreement

Contributed under the Apache-2.0 license of this project.

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
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision b1cdab41e60cea87fc553f0c6a4aae1f686e7dca 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 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

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 json.loads refuses, matching the pattern deploy/pending.py already uses.

[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 .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

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of b1cdab41e60cea87fc553f0c6a4aae1f686e7dca — 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. 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

  • Item 3, undeclared: the sibling sweep names engine.py:560 but not engine.py:1027 (except json.JSONDecodeError:), which also parses AWS CLI output. It falls outside the registry-file cause, so nothing needs to change in this PR.

What this change ships

Inventory (4 items) — 4 justified

Intent: one bad profiles.json should cost one registry read, not every deploy route and profile save. This is a FIX.

  1. A registry nested past the recursion limit now degrades instead of returning HTTP 500 on deploy routes — justified
  2. A registry holding a number past the digit limit now degrades instead of returning 500 — justified
  3. A profile save over a too-deeply-nested registry now moves the file aside instead of raising — justified
  4. The load_registry docstring now names both refused exception kinds — justified

[FIRST-PRINCIPLES-REVIEWED] b1cdab4

Description read

[DESCRIPTION-READ] 941d67c8d1b90bdf36a154e0bab9074b805d23cd12d45863381b5ef5fe3c975c

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

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] b1cdab4

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

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

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] b1cdab4

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

@bolichen97
bolichen97 enabled auto-merge (squash) November 7, 2026 16:14
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 7, 2026

@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 deploy profile registry treats a ValueError or RecursionError from json.loads as an unreadable file and falls back, instead of raising.

@bolichen97
bolichen97 merged commit 32ce0d8 into main Nov 7, 2026
95 of 98 checks passed
@bolichen97
bolichen97 deleted the fix/29089-registry-refused-json branch November 7, 2026 17:08
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 7, 2026
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)
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.

fix(deploy): a profile registry json.loads refuses still 500s every deploy route

2 participants