fix: two long-standing papercuts in the migration CLI and agent import - #87
Open
antiv wants to merge 1 commit into
Open
fix: two long-standing papercuts in the migration CLI and agent import#87antiv wants to merge 1 commit into
antiv wants to merge 1 commit into
Conversation
Both surfaced while working on #79/#82/#83. Neither is a regression; both have been there since the code was written. 1. `python shared/migrate.py run` — the form documented in CLAUDE.md, README.md and CONTRIBUTING.md — has never worked. The module imports its dependency relatively while being invoked as a script, so every command died on ImportError before doing anything. The `sys.path.append(parent)` already at the top of the file shows script invocation was the intent, so the import is what is wrong, not the docs. An absolute import makes both `python shared/migrate.py` and `python -m shared.migrate` work. 2. `POST /dashboard/api/agents/import` raised its own HTTPException inside a try whose `except Exception` then swallowed and rewrapped it, so every import failure reached the dashboard as "Invalid JSON data: 400: <real reason>" — blaming the request body for a failure that had nothing to do with parsing it. Seventeen other handlers in the same file already re-raise HTTPException first; this one was the outlier. The except branch still handles a genuinely unparseable body. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Two one-line fixes, both surfaced while working on #79/#82/#83. Neither is a regression — both have been there since the code was written.
1.
python shared/migrate.pyhas never workedshared/migrate.pyimports its dependency relatively (from .utils.migration_system import ...) while being invoked as a script, so every command dies onImportError: attempted relative import with no known parent packagebefore doing anything.That form is documented in three places — CLAUDE.md:46-49, README.md:256-259, CONTRIBUTING.md:101 — and the
sys.path.append(parent)already at the top of the file (line 18) shows script invocation was the intent all along. So the import is what is wrong, not the docs.An absolute import makes both invocation styles work:
2.
agents/importblamed the wrong thing for its failuresThe handler raised its own
HTTPExceptioninside atrywhoseexcept Exceptionthen swallowed and rewrapped it. Every import failure reached the dashboard as:— naming the request body as the cause of a failure that had nothing to do with parsing it. The status code stayed 400 by coincidence; the message did not.
Seventeen other handlers in the same file already re-raise
HTTPExceptionfirst. This one was the outlier. Theexcept Exceptionbranch keeps its real job: a genuinely unparseable body still reports "Invalid JSON data".Tests
shared/test/test_migrate_cli.py(3 tests) — drives the CLI as a subprocess in both invocation styles. Invoked with no arguments it prints usage and exits before constructingMigrationSystem, so the tests never touch a database.shared/test/test_import_error_message.py(3 tests) — a rejected import reports its own reason; an unparseable body still says so; a successful import is unaffected.Verified the tests fail against the unpatched code (3 of 6 fail). Full suite: 731 tests, all passing.
Merges cleanly with #85, which touches the same handler — checked; the combined result keeps both the audit call and the re-raise.
🤖 Generated with Claude Code