Skip to content

AI-2137: make linear_comment() resilient to non-JSON / partial Linear responses#6

Open
RachelXiaolan wants to merge 1 commit into
mainfrom
linear/ai-2137-sync-comment-error-handling
Open

AI-2137: make linear_comment() resilient to non-JSON / partial Linear responses#6
RachelXiaolan wants to merge 1 commit into
mainfrom
linear/ai-2137-sync-comment-error-handling

Conversation

@RachelXiaolan

Copy link
Copy Markdown
Owner

Summary

scripts/sync_comment.py linear_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

  1. Empty stdout (network failure, curl can't reach Linear) → json.loads('')JSONDecodeError
  2. Non-JSON body (5xx HTML error page from Linear's edge) → json.loads('<html>...')JSONDecodeError
  3. Auth failure with {"data": null} and no errors keydata["data"]["commentCreate"]...TypeError: 'NoneType' object is not subscriptable

Result before: agents silently lose the Linear-side progress comment whenever the API hiccups.

Fix

  • Guard json.loads with JSONDecodeError + tolerate empty stdout
  • Use chained .get() on data → commentCreate → comment → id so a null or malformed field never crashes
  • Always return None on any unexpected shape, with a clear stderr message

Tests

tests/test_sync_comment.py covers all three failure shapes plus the happy path:

5 passed, 0 failed

Smoke-tested against the real Linear API as well: the fix returns a real comment id on success.

Linear

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

2 participants