OpenFn / OpenFn/lightning

Delete the unreachable branch that prefers Apollo's error text over ours

Open Beginner friendly
#5,083 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Elixir
Stars
296
Forks
86
Avg merge
1d 13h
Merged PRs (30d)
50

Description

handle_error_response/2 in lib/lightning/ai_assistant/ai_assistant.ex still prefers Apollo's own body["message"] over a sentence of ours when a request comes back with a non-success status. error_message_from_body/1 is what reads it.

That is left over from when the assistant was not streaming. Showing Apollo's message to the user goes back to #2787 in December 2024, where it was read straight off the body with no guard and no fallback. #4969 later narrowed it, adding both, because a streamed body is a lazy stream rather than a decoded map and could not be indexed.

Now that every call streams, the clause that would index the body never matches, so the user always gets our own "AI server returned an error (HTTP ...)" instead. In other words we stopped showing Apollo's text by accident rather than on purpose, and what is left is a branch that cannot run.

Worth deleting rather than leaving. Two reasons.

It reads as if it is live, so anyone working in here has to trace all three callers to convince themselves it is not, which is a small tax every time.

And if a non-streaming call is ever added back, it quietly comes to life. Apollo wraps an unhandled exception as str(e), so its message is not written for a person to read. The rest of the assistant now deliberately keeps Apollo's words in the log and shows the user a sentence of ours; this branch would do the opposite. It would also stick, rather than pass by, since failure reasons are stored on the message now and re-sent to the client on every channel join.

So: drop error_message_from_body/1, always use our own status sentence for the user, and keep logging Apollo's text as we already do.

Noticed while reviewing the AI streaming stack (#5079 and the PRs above it). Deliberately not changed there, since that stack does not otherwise touch these lines.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/lightning/ai_assistant/ai_assistant.ex at handle_error_response/2 and error_message_from_body/1, then inspect the three callers mentioned in the issue to confirm the body is always streamed. Remove the unreachable preference branch while preserving Apollo's text in logs and the assistant's own HTTP status sentence for users.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
ai, backend
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.