AI-2137: make linear_comment() resilient to non-JSON / partial Linear responses#6
Open
RachelXiaolan wants to merge 1 commit into
Open
AI-2137: make linear_comment() resilient to non-JSON / partial Linear responses#6RachelXiaolan wants to merge 1 commit into
RachelXiaolan wants to merge 1 commit into
Conversation
… responses
Previously linear_comment() in scripts/sync_comment.py would raise out of
the function on three real-world failure shapes, breaking the whole
sync_comment flow:
1. Empty stdout (network failure, curl unable to reach host):
json.loads('') -> JSONDecodeError
2. Non-JSON body (5xx HTML error page from Linear's edge):
json.loads('<html>...') -> JSONDecodeError
3. Auth failure: {'data': null} with no 'errors' key
data['data']['commentCreate']... -> TypeError: 'NoneType' is not subscriptable
The function is wrapped by main() in a fire-and-forget script run by agents,
so an unhandled exception aborts the whole progress-comment posting and
the Linear-side update is silently lost.
Fix: guard json.loads with JSONDecodeError, tolerate empty stdout,
and use chained .get() on data->commentCreate->comment->id so a null or
malformed data field never crashes the function. Always return None on
any unexpected shape and log a clear error to stderr.
Tests: tests/test_sync_comment.py covers all three failure shapes plus
the happy path. Before the fix: 3/5 failing. After: 5/5 passing.
Refs: AI-2137
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.
Summary
scripts/sync_comment.pylinear_comment()raised out of the function on three real-world Linear response shapes, breaking the entire sync_comment flow (the function is called by agents in a fire-and-forget progress-comment script).Bugs fixed
json.loads('')→JSONDecodeErrorjson.loads('<html>...')→JSONDecodeError{"data": null}and noerrorskey →data["data"]["commentCreate"]...→TypeError: 'NoneType' object is not subscriptableResult before: agents silently lose the Linear-side progress comment whenever the API hiccups.
Fix
json.loadswithJSONDecodeError+ tolerate empty stdout.get()ondata → commentCreate → comment → idso a null or malformed field never crashesNoneon any unexpected shape, with a clear stderr messageTests
tests/test_sync_comment.pycovers all three failure shapes plus the happy path:Smoke-tested against the real Linear API as well: the fix returns a real comment id on success.
Linear