Skip to content

fix(api): return 200 with embedded log on SAS session failure instead… - #392

Merged
allanbowe merged 1 commit into
mainfrom
issue-388-fix
Jul 15, 2026
Merged

fix(api): return 200 with embedded log on SAS session failure instead…#392
allanbowe merged 1 commit into
mainfrom
issue-388-fix

Conversation

@YuryShkoda

@YuryShkoda YuryShkoda commented Jul 15, 2026

Copy link
Copy Markdown
Member

Issue

Follow-up to #388. #388 stopped a SAS session failure (e.g. %abort;) from hanging the request forever, but did so by throwing, which surfaced as an HTTP 400 with a bespoke JSON error shape. In production this broke the Studio frontend: instead of showing the log in the LOG tab like every other run, it popped up a raw-JSON "Abort" modal, because the frontend only parses/renders the log on a 2xx response.

Intent

A failed session (SAS %abort;, or a non-zero JS/PY/R exit) is a normal outcome of running arbitrary user code, not a request-shape or server problem. The response should:

  1. Be a 200, not a 400 - the request itself was valid.
  2. Have the same shape as a successful run, with the log surfaced as text in the LOG tab, not a separate error popup.

Implementation

  • Aligned the SAS branch of processProgram with the pre-existing JS/PY/R behaviour: it now resolves instead of throwing when session.state becomes failed, just stopping its poll loop.
  • Removed Execution.ts's SessionExecutionError class and the try/catch wrapper around processProgram() - both became dead code once the SAS branch stopped throwing. Execution.ts already knew how to fold session.failureReason into a normal 200 response (it's the same logic that already handled JS/PY/R failures and debug-mode logs); it just couldn't be reached for SAS before.
  • Removed the now-unnecessary log field from the code.ts/stp.ts catch blocks.
  • Updated mockSas.js to write abort errors into the log file itself (not just stderr), matching real SAS behaviour, so tests assert on what the API actually returns.
  • Updated tests (TDD): processProgram.spec.ts, Execution.spec.ts, and the end-to-end code.spec.ts now assert the failed-session path resolves with a 200 and the log embedded in the response, instead of throwing/400.
  • Updated all 4 diagrams in api/docs/diagrams/ to reflect the new resolve-not-throw behaviour and corrected line-number references.

Checks

  • Code is formatted correctly (npm run lint:fix).
  • Any new functionality has been unit tested.
  • All unit tests are passing (npm test).
  • All CI checks are green.
  • Reviewer is assigned.

… of 400

A failed session (e.g. SAS %abort;, or a non-zero JS/PY/R exit) is a
normal outcome of running arbitrary user code, not a request-shape or
server problem. The #388 fix stopped processProgram() from hanging
forever on a failed SAS session, but did so by throwing a
SessionExecutionError, which surfaced as an HTTP 400 with a bespoke
JSON shape - breaking Studio's log tab, which only renders on 2xx.

Align the SAS branch with the pre-existing JS/PY/R behaviour: resolve
instead of throwing, and let Execution.ts fold session.failureReason
into the log the same way it already does for a debug-mode run. This
removes the now-dead SessionExecutionError class and its try/catch
wrapper entirely.

Update the diagrams in api/docs/diagrams/ to match.
@YuryShkoda YuryShkoda self-assigned this Jul 15, 2026
// successful run (200, same body shape, no hang), with the log simply
// reflecting what happened. Regression test for #388's follow-up: the
// original #388 fix stopped the hang but over-corrected into a 400
// with a bespoke error shape, which broke Studio's log-tab rendering.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add something to the CONTEXT.md to stop the AI writing comments that refer to previous tickets? They're useful for pull request reviews but the comment will be stale almost immediately

@allanbowe
allanbowe merged commit bf0ddc9 into main Jul 15, 2026
3 checks passed
@allanbowe
allanbowe deleted the issue-388-fix branch July 15, 2026 13:14
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.39.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants