Repository navigation
fix: answer 4xx instead of 500 for bad KV paths and unknown-automation tokens - #741
Conversation
…n tokens
- GET /v1/kv/{key}?path= with malformed syntax (unclosed bracket) now
answers 400 invalid_path, like PATCH, instead of an uncaught ValueError.
- set_nested_value rejects a path that names no field ("", "."), so PATCH
answers 400 invalid_path and a batch patch 400 operation_failed instead
of an IndexError 500.
- KV JWT auth checks the token's automation exists: a token whose
automation has no row gets 404 "Automation not found" on every route,
matching user auth for an unknown automation_id, instead of empty reads
and a foreign-key 500 on the first write. Soft-deleted automations keep
their row, so their tokens keep working as user auth does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013ArwwM9ABBZYP9fcggw4R8
|
Warning Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it. |
This comment has been minimized.
This comment has been minimized.
Mark it as a detail string in the design doc's error-code table, and note in the client guide that a soft-deleted automation's token keeps working. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwM9ABBZYP9fcggw4R8
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope: In-repo change. The KV store API (kv_router.py/kv_helpers.py) is owned by this repository per AGENTS.md, and linked issue #736 (open, bug + ready-for-dev, priority:medium) describes exactly these three client-error 500s. No repository move or maintainer decision needed.
Review summary — no material findings.
All three fixes were verified against this head (0602bd4):
- GET
?path=a[b→ 400 —get_valuenow catches theValueErrorfromparse_pathand answers400 invalid_path: ..., matching PATCH. I reproduced this live through the real ASGI app:400 invalid_path: Invalid path: unclosed bracket in 'a[b'. The depth-limitValueErrorfromparse_pathalso lands on this 400 path, which is correct client-error semantics. - Empty/segmentless PATCH path → 400 —
set_nested_valueraisesValueErrorbefore theparts[-1]IndexError; single PATCH maps it to 400invalid_path: ...and batchpatchmaps it throughKVOperationErrorto 400operation_failed. VerifiedValueError: Invalid path: '' names no fieldon this head;tests/test_kv_helpers.py,tests/test_kv_batch.py,tests/test_kv_router.pycover"",".","..", and"a[b". - Ghost KV token → 404 —
get_kv_auth_contextnow verifies the claim's automation row exists (_require_automation_exists), so every KV route answers404 Automation not foundinstead of empty reads plus a first-write FK 500. Verified live: ghost-token list and PUT both answer404 Automation not found. All 15 KV routes depend onget_kv_auth_context, so coverage is complete. The check ignoresdeleted_at, which I confirmed matches the user-auth path (_verify_automation_accesshas nodeleted_atfilter;DELETE /v1/{id}is a soft delete that keeps the row) — and I verified a soft-deleted automation's token still reads200on this head.
Auth ordering is sound: signature verification happens before the existence check, so callers without a validly signed token cannot probe automation-id existence (they still get 401). The extra primary-key lookup per JWT request mirrors what user auth already does and is disclosed in the PR notes. Docs (F12-kv-store.md, docs/kv-store-design.md, docs/kv-store-client-guide.md) were updated consistently with the new behavior, including the deliberate reordering of the F12.jwt-unknown-automation recipe so it reproduces on baseline and passes on the fix.
Acceptance evidence: the PR's GitHub Actions checks on this exact head are all green (unit-tests, backend, windows-tests, image builds). Locally, the SQLite-based suites covering the new tests pass: tests/test_kv_helpers.py + tests/test_kv_batch.py + tests/test_kv_user_auth.py → 170 passed (incl. all 9 ghost-token route cases and the soft-delete case); the Postgres-testcontainer router tests cannot run in this sandbox (no Docker daemon), so I verified those behaviors live against the app instead as described above.
One pre-existing, out-of-scope nit (not blocking): docs/kv-store-design.md still lists 403 token_expired while the code answers 401 Invalid or expired KV token — this discrepancy predates the PR and is already flagged by the F12 gotcha.
✅ APPROVED
The error table documented an {error, message} body and codes such as
unauthorized and token_expired that the router never sends. List the
real {detail} strings and structured details from kv_router.py and
kv_helpers.py.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013ArwwM9ABBZYP9fcggw4R8
|
🚀 Released in 1.33.0. |
Requested by Engel · project thread
I'm an AI agent based on Opus 5.5, helping Engel Nyst (@enyst) with project maintenance.
Summary
Three client mistakes on the KV store reached the server as unhandled exceptions (500). A malformed
?path=on GET (a[b) raised an uncaughtValueError; a PATCH path naming no field ("",.) hitparts[-1]inset_nested_value(IndexError); and a validly signed KV JWT whose automation has no row was accepted, read as empty, and failed theautomation_kv_metaforeign key on its first write. All three now answer 4xx.Issue Number
Fixes #736
Changes
kv_router.get_value: aValueErrorfromparse_pathmaps to 400invalid_path: ..., the same answer PATCH already gives.kv_helpers.set_nested_value: a path with no segments raisesValueError, so single PATCH answers 400invalid_path: ...and batchpatchanswers 400operation_failed(the batch path had the sameIndexError).kv_router.get_kv_auth_context: on the JWT path, check the claim's automation row exists (_require_automation_exists); otherwise 404Automation not foundon every KV route, which is exactly what user auth answers for an unknown?automation_id=. The check ignoresdeleted_at, so a soft-deleted automation's token keeps working, as user auth already does for soft-deleted automations. A hard-deleted automation's token is now 404 instead of empty reads and a 500 on write.tests/test_kv_router.py,tests/test_kv_helpers.py,tests/test_kv_batch.py,tests/test_kv_user_auth.py(ghost token across list/get/put/patch/delete/incr/rpush/len/batch answers 404 and stores nothing; soft-deleted automation's token still reads and writes).F12-kv-store.md: dropped the three# bug:markers and "known bug" wording; updated the Gotchas (the token claim is now checked against the database). TheF12.jwt-unknown-automationrecipe changed beyond the marker: the two ghost-token GETs that ran before the PUT expected 200total:0and 404key_not_found; they now expect 404Automation not foundand run after the PUT (so the same recipe reproduces on baseline and passes on the fix), plus a SQL check that noautomation_kv_metarow was created.F12.soft-deleted-automationgained a JWT read of the soft-deleted automation.docs/kv-store-design.md,docs/kv-store-client-guide.md: error tables list the empty-path 400 and theAutomation not found404.Evidence
uv run pytest -q tests/: 2905 passed, 7 skipped.uv run pytest -q tests/test_verify_automation_skill.py: 59 passed.pre-commit run --files <changed files>: ruff format/lint, pycodestyle, pyright pass.map run --file F12 --only <id> --fresh --repeat 2 --checkout <baseline>):F12.get-path-malformed,F12.patch-empty-path,F12.jwt-unknown-automationeach xfail ×2.control-automation map run --file F12 --fresh: 31 pass, 0 fail, 0 xfail, 0 xpass.Notes
key_not_found; they now answer 404Automation not found.SELECT automations.id, the same on PostgreSQL.Generated by Claude Code