Skip to content

feat(api): Workflow.check(), and a when that cannot give a boolean - #585

Merged
vjaganat90 merged 7 commits into
PolusAI:masterfrom
vjaganat90:feat/checks-before-writing
Nov 13, 2026
Merged

vjaganat90 merged 7 commits into
PolusAI:masterfrom
vjaganat90:feat/checks-before-writing

Conversation

@vjaganat90

@vjaganat90 vjaganat90 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Stacked on #584 (feat/nextflow-step-only-inputs). Merge that first; this PR's own changes are the commits above it.

What

  • Workflow.check(target=...) is the Python form of sophios --check: it compiles, lowers for the target and runs the same pre-flight run() runs (the container engine, the input paths, the directories Sophios writes, the programs it calls; under Nextflow, nextflow and a Java it can run), writes nothing, prints nothing, and returns every diagnostic. What this machine lacks raises SophiosError, as run() does. Until now only the command line could do this.
    from sophios.api.python.nextflow import NotLowered
    notes = flow.check()                    # the CWL target's notes
    try:
        flow.check(target="nextflow")
    except NotLowered as refused:
        print(refused)                      # every refusal, at its line
  • One check over the resolved view, for every target: a when must be able to give true or false. It finds a when that is text rather than one $(…) or ${…} expression, or one that computes a number, a string or null, such as $(inputs.count) for an int input. On the CWL target that is a note, wic056, at the step: it refuses nothing and changes no emitted CWL. On the Nextflow target it is the refusal it already was, now from the shared check.
  • Partial failure from Python: policy=RunPolicy(partial_failure=True, success_codes=(0, 1, 2)) on compile, run, start, run_async and check writes the CWL that --partial_failure_enable and the success-code flags write for the .wic twin. The Nextflow target refuses the policy.
  • New exports: RunPolicy from sophios.api.python.workflow; NotLowered, Refusal and Construct from sophios.api.python.nextflow.

What changes for callers

  • sophios.compiler.compile_source(..., testing=...) is now compile_source(..., quiet=...): the flag only leaves out the lines that say a compile started and finished, and a quiet compile now holds back its plain warnings too, so check() prints nothing. No docs example or corpus script calls it.
  • The warning for a when that reads an input its process does not declare now says what happens: it has no value there, and cwltool stops the run at a when that gives anything but true or false.

Why
A Python user could not check a workflow without compiling it to disk, could not ask for partial failure at all, and a when that cannot give a boolean was found only when cwltool stopped the run.

@vjaganat90
vjaganat90 force-pushed the feat/checks-before-writing branch 2 times, most recently from c66089c to 4c7f029 Compare November 9, 2026 07:06
@vjaganat90
vjaganat90 force-pushed the feat/checks-before-writing branch 9 times, most recently from 89fda55 to a96cf4a Compare November 9, 2026 23:12
@vjaganat90
vjaganat90 force-pushed the feat/checks-before-writing branch 14 times, most recently from 342d0fa to ff4d0c4 Compare November 12, 2026 20:53

@darkclad darkclad left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed this PR's own commits (50834366..ff4d0c4c, on top of #584 at f3bab3d4). I also ran tests/core on head and on base. The RunPolicy plumbing, the shared boolean_problem check, and moving the partial-failure refusal ahead of the other findings all look right. I have one substantive comment, about check() missing the undeclared-input when warning, plus two smaller ones inline.

result = compile_workflow_result(workflow, tool_registry=options.tool_registry, inference=options.inference)
report(result.diagnostics)
result = compile_workflow_result(workflow, tool_registry=options.tool_registry, inference=options.inference,
policy=options.policy, lang_version=options.lang_version, quiet=check)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

quiet=check makes check() drop the one when problem it exists to catch. compile_source now gates _when_notes on quiet, and that warning is a printed line, not a Diagnostic, so check() neither returns nor prints it. Your own _warned_on_cwl test shows this: step 3's when: $(inputs.nope) shows up only in compile()'s stderr, and check() returns [wic043, wic056] with nothing for it. non_boolean_whens doesn't catch it either, because the subset can't type an unbound read, so boolean_problem returns None.

That when evaluates to null, which the new scatter-and-conditions.md text says "stops the run too". So check() comes back clean for a workflow that cwltool will stop at that step, while the docstring says it returns every note compile() would show. Could the undeclared-input case become a Diagnostic (a wic056 note, or its own code) so check() returns it? Keeping it a plain line that only a non-quiet compile prints means the Python check can't see it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right: check() missed the one when problem it exists to catch. I made the undeclared-input when a wic056 note in the compile's diagnostics instead of a printed line. It no longer depends on quiet. check() returns it, and compile() and the CLI print it through the normal diagnostics report. It is raised on both targets, since a null when is a problem for both. The tests now assert that check() returns the inputs.nope note and that a check() followed by a compile() show the same notes.

Fixed in 5bd03ef.

Comment thread src/sophios/realtime.py
try:
bundle = frontdoor.bundle_from_source(source, f'{Path(declaration.analysis).stem}_only', yml_paths, tools)
result = compiler.compile_source(bundle, compiler_options, testing=True)
result = compiler.compile_source(bundle, compiler_options, quiet=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Before this PR, testing=True here only hid the start and finish lines. quiet=True now also hides _authored_spelling_notes and _when_notes for every real-time analysis compile. So sophios --yaml ... --run_local no longer warns about a duplicate-id outputSource or an undeclared-input when inside an analysis .wic, while the same document compiled on its own still gets the warning. If that's intended, it's worth a line in the PR's "What changes for callers". If not, this call site might want to keep the old split between hiding progress lines and hiding warnings.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed on the narrowing. quiet=True here now hides the authored-spelling line (duplicate-id outputSource) for analysis compiles, and I'm leaving that as it is. The when problem is no longer part of it, because it is now a diagnostic rather than a printed line. But the analysis compile discards its diagnostics, so that note is still not shown for an analysis .wic. The PR's "What changes for callers" should say so, and I'll add the line there.

Comment thread tests/core/test_python_api_workflow.py Outdated
with pytest.raises(SophiosError) as error:
workflow.check(target=target)
problem, = error.value.diagnostics
assert str(problem.code) == "wic016" and f"'{tmp_path / 'absent.txt'}', which does not exist" in problem.message

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: this fails on Windows, in both parametrizations. The wic016 message formats the path with !r, so backslashes come out doubled ('C:\\Users\\...'), and f"'{tmp_path / 'absent.txt'}'" never matches. CI's Windows lane only runs test_compile_python_workflows from this file, so CI won't catch it. Matching on {str(tmp_path / 'absent.txt')!r} would work on every OS. These two are the only failures in tests/core that are new against #584's head on my Windows box. The other 123 failures there are environmental and fail on the base too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed. The test now matches str(path)!r, so the doubled backslashes on Windows match. I couldn't run it on Windows here, so that part is unverified.

Fixed in 1e01d2b.

It only leaves out the lines that say a compile started and finished,
so the flag says that rather than who passes it.
One check over the resolved view finds a when the subset types as a
number, a string or null, or one that is not one expression. The CWL
target notes it as wic056, and the Nextflow target refuses it.
Workflow.check(target=...) is the Python form of --check: it compiles, lowers for the target and runs run()'s pre-flight on this machine, writes nothing, and returns every note. What the machine lacks raises SophiosError, as run() does.
The tools the view carries are written for the policy, so what the
target would refuse in them is the policy's, not their author's.
policy=RunPolicy(...) on compile, run, start, run_async and check
writes the CWL the partial-failure flags write for the .wic twin.
The Nextflow target refuses the policy alone.
@vjaganat90
vjaganat90 force-pushed the feat/checks-before-writing branch from ff4d0c4 to 2700177 Compare November 13, 2026 16:22
An undeclared input read in a when was a plain line only a printing
compile showed, so check() came back clean for a run cwltool stops.
It is now a wic056 note in the compile's diagnostics on either target.
The message formats the path with !r, which doubles backslashes.
@vjaganat90

Copy link
Copy Markdown
Member Author

Thanks for the review. The check() gap is fixed by making the undeclared-input when note a wic056 diagnostic that check() returns. The Windows path match is fixed too. The realtime.py quiet=True narrowing is deliberate, and I'm noting it in the PR text.

Fixed in 5bd03ef, 1e01d2b.

@darkclad darkclad left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. 5bd03ef makes the undeclared-input when a wic056 diagnostic, so check() now returns it, and 1e01d2b fixes the Windows path match. I ran tests/core on Windows against #584's head, and nothing new fails; the two wic016 path tests pass there now. One small follow-up: the "What changes for callers" line about real-time analyses losing these notes isn't in the PR text yet.

@vjaganat90
vjaganat90 merged commit e0ce62d into PolusAI:master Nov 13, 2026
3 checks passed
@vjaganat90
vjaganat90 deleted the feat/checks-before-writing branch November 13, 2026 17:30
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.

2 participants