Skip to content

fix(analysis): fail a refused engine write without waiting the whole timeout - #2601

Open
HuiJun wants to merge 4 commits into
developfrom
fix/engine-failed-write-no-full-timeout
Open

HuiJun wants to merge 4 commits into
developfrom
fix/engine-failed-write-no-full-timeout

Conversation

@HuiJun

@HuiJun HuiJun commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

When an external analysis engine's pipe refuses a request, session.unwritable waits for the reader to report the process's end so the caller gets the real exit rather than a bare pipe error. If the engine has stopped reading its input but keeps its output open, the reader never reports an end, and the wait ran for the session's whole timeout before the request failed.

The wait is now bounded by unwritableGrace (one second, or the session timeout when that is shorter). After it, the session is ended with an EngineExitedError carrying the process's exit status when the exit was already collected (an engine that exited while a helper still holds its output open), and the write's own error otherwise.

Part of #2445.

How it was verified

  • New TestSessionRefusedWriteDoesNotWaitTheTimeout, driven by a new stdin-closed mode of the engine stand-in (it answers describe, then closes its standard input and keeps its output open). Without the change to session.go the test fails after the full one-minute timeout (the refused write took 1m0.001864804s under a one-minute timeout); with it, it passes.
  • New TestSessionRefusedWriteReportsTheCollectedExit, driven by a new exit-holding-output mode (the stand-in exits with status 7 while a helper keeps its standard output open for five seconds). Without the collected-exit branch the request fails with the write error; with it, with exit status 7.
  • go test -count=1 -race -run TestSessionRefusedWrite ./internal/exec/analysis, go test -count=1 ./internal/exec/analysis, go vet ./internal/exec/analysis/... and gofmt -l internal/exec/analysis are clean.
  • The full make test and make lint were not run locally.

Checklist

  • make test and make lint pass locally
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (see CONTRIBUTING.md)
  • Changelog entry added as changes/unreleased/<slug>.<section>.md, not as an edit to CHANGELOG.md
  • baselines regenerated and make docs-counts run if a gate count moved (compliance rows need nothing: the census is counted at docs build)
  • No internal work-item labels (waves, slices, F4, K5) in the body, docs, or changelog

Release Management opened this PR for Jason
Implemented in session Fix issue 2445 before the 0.13.0 cut
Review with Devin · Open in Devin Desktop


…timeout

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

…helper still holds

Co-Authored-By: jason.han <hanhuijun@gmail.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 finding. Devin automatically fixed it.

Fixed by Devin (1)
  • Lost exit status after refused writes — After the grace, unwritable now reports the collected exit status when the process has already been waited; covered by TestSessionRefusedWriteReportsTheCollectedExit.

View findings in Devin Review · Follow Devin's work

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

QA: pass, with one failure in the same area that is also on develop

Compared develop at 69213de01c with head 0bd203b61f through the CLI, the REPL and the gRPC service (Python client), driving an external engine from an OPENSYSML_ENGINES manifest. Engines not run: MATLAB and Octave are not installed here, so the engine was the repository's stand-in (internal/exec/analysis/testdata/enginestandin); tool:fmi was listed as unavailable and not exercised.

Recording of the run

Model: an action with a fork checked against a property, -engine all, so the built-in engines answer beside the external one. Times are wall-clock seconds, base → head.

Check Verdict Base → head Observed
Refused write, engine closed its stdin, OPENSYSML_TOOL_TIMEOUT=20s, CLI Pass 20.1 → 1.7 Both: standin refused (engine "standin" at … exited during a request (write |1: broken pipe))
Same, REPL (%engine all, %action) Pass 20.1 → 2.0 Same message
Same, gRPC CheckBehavior with -serve-external-engines standin Pass 20.1 → 1.7 Same result returned to the client
Same with OPENSYSML_TOOL_TIMEOUT=500ms Pass 1.8 → 1.8 Same message
Normal analysis (CLI, REPL, gRPC) Pass 1.8 → 1.8 Output identical: standin violated (witnessed)
Slow engine answering after 6s, timeout 20s Pass 6.1 → 6.2 Full answer kept, not cut at the 1s grace
Engine crashes during run Pass 1.8 → 1.8 exit 11: segmentation fault (stand-in)
Engine exits at start / after describe / after answering Pass same did not start (exit 2: …), exited during a request (exit 0), answer kept
describe never answered, timeout 4s Pass 4.1 → 4.1 did not answer describe within 4s (OPENSYSML_TOOL_TIMEOUT)
run past -check-timeout 3s; cancel ignored with 4s grace Pass 3.1 → 3.1; 7.1 → 7.1 cancelled at deadline; ended after the grace
Engine exits with status 7 while a helper holds its output Pass, no visible change 5.1 → 5.1 Both exited during a request (exit 7) once the helper let go; see note 2
Engine stops reading but leaves the pipe open, timeout 5s Fail on both 30 (cap) → 30 (cap) No error; the command never returns

Every scenario's output is the same on base and head apart from the time taken.

The failure (not introduced here)

An engine that answers describe and then never reads another request, without closing its stdin, hangs the analysis for good on both builds: covers is written into the pipe, nothing refuses it, and nothing bounds the wait. docs/reference/external-engines.md says describe and covers must answer within OPENSYSML_TOOL_TIMEOUT, and only describe does (session.describe wraps its context in the timeout; session.call for covers waits on the caller's context, which has no deadline without -check-timeout).

Both builds run into the 30s cap with a 5s timeout

To reproduce: a manifest entry whose command is a script that reads one line, prints the describe answer and sleeps; then OPENSYSML_TOOL_TIMEOUT=5s sysml -engine all -instantiate Plant::tank -action "Plant::Tank::fill Plant::tank" -check-property Plant::Tank::low tank.sysml.

Two things follow for this change:

  1. The prompt failure depends on the write being refused. In one of about eight head runs of the closed-stdin case, made while the machine was busy with a test run, the covers write reached the pipe before the stand-in closed it, and that run hung (stopped by hand after 572s; the goroutine dump shows session.call waiting at its first select for covers). It did not recur in five quiet runs. Base has the same window.
  2. The second commit's case is not reachable this way from the CLI: covers is written before the engine's exit is collected, so the write succeeds and both builds wait for the helper to release the output (bounded by the timeout). The new unit test covers it by waiting for the exit first.

Past fixes in the touched area

The 32 analysis, engine and subprocess rows of the regression inventory map to these packages, all passing on head: internal/exec/analysis/... (also the session, engine and tool tests under -race, and TestSessionRefusedWrite* 20 times), internal/exec/solve/..., internal/exec/runtime, internal/frontend/repl/..., internal/frontend/grpc/..., cmd/sysml (engine, tool, check, external, pipe and timeout tests), cmd/sysml-grpc/..., tests/grpc/..., client/opensysml/.... go vet and gofmt are clean on internal/exec/analysis.

@HuiJun
HuiJun added this pull request to the merge queue Nov 26, 2026
@devin-ai-integration
devin-ai-integration Bot removed this pull request from the merge queue due to a manual request Nov 26, 2026

This branch has not been deployed

No deployments
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