Conversation
…session fails
The SAS-runtime poll loop in processProgram only checked for
SessionState.completed, so a session that failed (e.g. via %abort;)
left the loop spinning on delay(50) forever - the request never
resolved, even though the SAS log had already been written. Split a single completed-on-either-outcome
flag into separate completed/failed states without updating this loop.
- processProgram now throws when session.state becomes 'failed'
- Execution.ts catches that, reads the complete log (guaranteed
complete since the session's process has already exited by then),
and throws a SessionExecutionError carrying it
- stp.ts/code.ts surface { ..., log } in the HTTP error response
- add unit tests for the poll loop and the log-enrichment logic, plus
a mock SAS executable + end-to-end test exercising the real
session/process pipeline without needing a SAS install
- add docs/diagrams covering the session lifecycle and the SAS
execution handshake mechanism, for future context
allanbowe
approved these changes
Jul 13, 2026
- wrap the file read/write in a small retry() helper instead of letting an uncaught exception (e.g. a rename racing an existsSync check) crash the process with a non-zero exit indistinguishable from a genuine SAS failure - bump the internal give-up deadline from 1500ms to 8000ms - bump the corresponding Jest test timeouts from 15000ms to 30000ms to match
|
🎉 This PR is included in version 0.39.5 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
Issue
Closes #388.
Stored Programs / code execution requests never respond when the underlying
SAS session fails (e.g.
%abort;). The log file gets written up to thepoint of failure, but the HTTP request just hangs forever — no crash, no
timeout, no response.
Intent
Make execution requests always resolve, whether the submitted code
completes normally or the session fails abnormally — surfacing a prompt
error response (with the complete SAS log attached) instead of hanging.
Implementation
Root cause: the SAS-runtime poll loop in
processProgram.tsonlychecked for
SessionState.completed:It never checked for
SessionState.failed, so once a session failed theloop spun on
delay(50)forever and the request never resolved.Fix:
processProgram.ts— throws whensession.statebecomesfailed.Execution.ts— catches that around theprocessProgramcall, reads thelog (guaranteed complete at that point, since the session's process has
already exited by the time
failedis observable), and throws a newSessionExecutionError { message, log }.stp.ts/code.ts— both existing error-response catch blocks nowinclude
login the HTTP error body alongside the pre-existing{ code: 400, status: 'failure', message, error }shape.Tests (no SAS runtime available, so built around a mock in place of one):
processProgram.spec.ts— unit test on the poll loop directly. Genuinelyreproduced the bug pre-fix: the "abort" case hit Jest's per-test timeout,
and because the (buggy) loop keeps scheduling fresh timers, the whole
Jest worker never exited on its own.
Execution.spec.ts— unit test for the log-enrichment/error-wrappinglogic (mocks
processProgram, matches this repo's existing mockingconvention from
stp.spec.ts).routes/api/spec/files/mockSas.js— a minimal fake "SAS executable"(plain Node script) that fulfills just the SYSIN/AUTOEXEC filesystem
handshake
Session.tsrelies on, without interpreting real SAS syntax.Validated directly via
execFilebefore use.code.spec.ts— end-to-end test againstPOST /SASjsApi/code/execute(the endpoint Studio's "run code" hits) using the real, unmocked
SASSessionController+processProgrampipeline wired to the mockexecutable. Covers both the happy path (200) and the regression case
(
%abort;→ prompt 400 with the complete log, not a hang).Full suite: 14/14 test suites, 242/242 tests passing.
tsc --noEmitclean.Docs: added
api/docs/diagrams/— Mermaid diagrams of the sessionlifecycle, the SAS SYSIN/AUTOEXEC execution handshake, and the end-to-end
request flow, with embedded
file:linereferences. Written for fastcontext-loading (by humans or AI agents) on this otherwise non-obvious
subsystem; not specific to this bug.
Checks
npm run lint:fix).npm test).