Skip to content

fix: an API exception message does not double the server's closing period - #975

Merged
Blind-Striker merged 2 commits into
masterfrom
fix/api-exception-message-period
Nov 22, 2026
Merged

Blind-Striker merged 2 commits into
masterfrom
fix/api-exception-message-period

Conversation

@Blind-Striker

Copy link
Copy Markdown
Collaborator

📝 Description

What does this PR do?

Since opencode 2.3.2, a handler defect gets a readable 500 instead of an empty one (packages/server/src/middleware/defect-response.ts at the pin):

{"_tag":"UnknownError","message":"Server failed to handle the request. Check server logs for details.","ref":"err_…"}

The SDK already reads that body. OpenCodeApiException builds its message from the status, the tag and the server's message, but it always appended a period. Because the server's message already ends in one, every readable 500 read "… Check server logs for details..".

The fix (OpenCodeErrorReader.CreateApiException): the period is appended only when the server's message doesn't already end in ., ! or ?. Every other message keeps its current text.

New contract rows (OpenCodeClientContractTests):

  • On session.message.get, whose 500 is undeclared, the defect body becomes UnknownOpenCodeError("UnknownError") with the message "The opencode API returned status 500 ('UnknownError'): Server failed to handle the request. Check server logs for details." The raw body keeps the ref.
  • An empty 500, the shape before 2.3.2, keeps "The opencode API returned status 500." with no error data.
  • On session.message.list, which declares the 500, the body reads as the typed UnknownError, with its Message and Ref.

Related Issue(s):

None. The finding came from the 2.3.2 refresh review. The rule appends the period only when the message has no sentence ending, so every existing contract row stays unchanged, including the one whose message ends in "! " (with a trailing space).

Other places that build a sentence from server text:

  • The terminal close messages (PTY, persistent PTY) and the client-hosted MCP close message wrap the server's close reason in parentheses, as in "… closed abnormally with status 1012 (location shut down).". A reason that ends in a period reads ".)." there, never "..".
  • The RPC path builds its message through the same CreateApiException, so this fix covers it.
  • A grep found no other site that appends a period directly after server text.

🔄 Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

🎯 Protocol & API Surface

  • No public API change. Only the text of OpenCodeApiException.Message changes, and only when the server's message already ends a sentence.
  • No generated output changed
  • The pinned snapshot (spec/) is untouched
  • Nothing under external/ was hand-edited

🧪 Testing

  • Contract tests added (three rows, above).
  • Red proof: on the unfixed code, the undeclared-500 row fails at its Message assertion: the actual message ends in "details..". With the fix, it passes on net10.0, net11.0 and net472.
  • Every existing class that asserts an OpenCodeApiException message passes unchanged.

✅ Completion Gate

  • The local check in quality-gates.md passes on the head rebased onto master: whitespace, format/style, clones, slopwatch, the release build, all test projects, the API snapshots, generate --verify, the fixed point, Extensions and Native AOT.

📚 Documentation

  • CHANGELOG.md entry added under [Unreleased] (🐛 Fixes)

✅ Code Quality Checklist

  • No new analyzer warnings, and no new suppressions
  • No tests skipped or weakened; no existing test changed
  • Branch is up to date with the target branch, no merge conflicts
  • Commit messages carry no AI-attribution trailers

🔍 Additional Notes

Breaking Changes: none. Dependencies: none.

…riod

The default message in packages/server/src/middleware/defect-response.ts at the opencode v2.3.2 pin already ends in a period. Preserve closing periods, exclamation marks and question marks when composing the API exception message.

Add GetMessageAsync_Should_Read_The_Readable_500_On_An_Undeclared_Status, GetMessageAsync_Should_Keep_The_Bare_Status_Sentence_For_An_Empty_500, and ListMessages_Should_Read_The_Readable_500_As_The_Declared_UnknownError contract rows.
@Blind-Striker
Blind-Striker added this pull request to the merge queue Nov 22, 2026
Merged via the queue into master with commit ff26de0 Nov 22, 2026
17 checks passed
@Blind-Striker
Blind-Striker deleted the fix/api-exception-message-period branch November 22, 2026 15:54
@Blind-Striker Blind-Striker mentioned this pull request Nov 24, 2026
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.

1 participant