Skip to content

feat: one table of targets, and nf-s codes for Nextflow refusals - #586

Merged
vjaganat90 merged 6 commits into
PolusAI:masterfrom
vjaganat90:feat/one-target-table
Nov 13, 2026
Merged

vjaganat90 merged 6 commits into
PolusAI:masterfrom
vjaganat90:feat/one-target-table

Conversation

@vjaganat90

Copy link
Copy Markdown
Member

Stacked on #585 (feat/checks-before-writing). Merge that first; this PR's own changes are the commits above it.

What

  • One table of targets, sophios.targets, read by every entry point: the command line (--target, --check, --run_local, --generate_run_script, the raw-CWL pass-through), Workflow.compile, run, start, run_async and check, and run_local. Each row holds the target's contract (what it refuses, how it lowers and writes, whether it takes plain CWL as is) and its runners. An unknown target is reported from one place, before anything compiles. --target and the Python API's target: Literal["cwl", "nextflow"] are unchanged, and one test keeps the table's names, the Literal and --target's choices equal.

  • CWL answers the same contract as Nextflow: it refuses nothing, and its lowering is today's emitter, unchanged.

  • Every Nextflow refusal has a code, nf-s001 to nf-s055 ("Nextflow support"):

    • one code per reason, each reached from a real workflow by a test case, with a row in docs/error_codes.md that sophios --explain nf-s010 prints;
    • a new kind, target: nothing is wrong with the workflow, this target cannot run it yet, so the fix names the construct to change, or --target cwl. Three are kind document: a source that names no step or port, a path reference, and invalid CWL;
    • two reasons that are not Nextflow's keep their codes, as errors: wic012, an explicit null for a required input, and wic056, a when that cannot give a boolean, which stays a note on CWL;
    • numbered by construct and never reused. When the target learns a construct, its code is retired as supported since that release, so the list is the target's support table.
  • A refusal is an ordinary diagnostic. For sophios --yaml refused.wic --target nextflow, a step whose when is $(inputs.message < "27"):

    • before: stdout says Failed to generate Nextflow artifacts. See error_refused.txt., and the refusal is only in that file, written to the working directory whatever --basepath says;
    • after, on stderr, exit 1, no file:
      Failed to compile refused.wic
      refused.wic:2:3: error [nf-s010] when: '$(inputs.message < "27")' is outside the safe JavaScript subset: < requires number operands, not string (step 'echo')
      

    --diagnostics json prints it as one object with "kind": "target" and the fix. From Python, Workflow.check(target="nextflow") returns the refusals among the other diagnostics; compile(), run() and start() raise NotLowered, whose text is the same diagnostic lines.

  • A run lowers once: the backend's prepare takes the lowered model.

What changes for callers

  • On the command line a Nextflow refusal is on stderr. error_<stem>.txt is written only for a crash, as for the CWL target.
  • Workflow.check(target="nextflow") returns refusals instead of raising. Refusal gains its code, and NotLowered no longer takes a target name or prints a "capability analysis failed" header. All three are new since 0.7.0.
  • --target nextflow --allow_raw_cwl plain.cwl says on stderr that the file is compiled as a Sophios document, which it already did silently.

Deleted

  • The two catch-alls that turned any ValueError raised while lowering for Nextflow into an uncoded refusal. They gave a refusal no code and hid a bug as a refusal. Every path they covered is now a coded refusal checked before the pipeline model is built, through the same predicate the model's own validation uses where both check one thing; a bounded property generates tool and workflow shapes and holds the lowering to three outcomes: a pipeline, a coded refusal, or a compile error. An error nobody foresaw now goes to the crash handler, as anywhere else in Sophios.
  • backends.BACKENDS and the hand-written target branches in main.py, run_local.py, api/python/workflow.py and api/python/_workflow_runtime.py: the table replaces them.

Emitted CWL and every generated Nextflow file are byte-identical over the docs examples, the test cases and both corpora, and every workflow refused before is still refused, now with a code. CI does not check either, so I did.

Why
Nextflow was chosen by hand-written branches and explained its refusals in its own uncoded layout; a target is first class when it is chosen, checked and explained the way every target is, whatever it supports.

@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 the five commits above #585. The target table, the coded refusals and the Python API changes behave as the description says: --target nextflow on a refused workflow prints coded errors on stderr, exits 1 and writes no error_*.txt; --diagnostics json carries "kind": "target"; --explain nf-s010 works; check(target="nextflow") returns the refusals while compile() and run() raise NotLowered; and an unknown target is reported before anything compiles. tests/core shows no new failures against #585's head (Nextflow and Docker runtime tests not exercised here), and pylint improves on the base.

One blocker: mypy fails on this branch (inline). The lint lane did not run on this PR, so CI has not caught it.

Comment thread src/sophios/run_setup.py Outdated
from sophios.runtime_inputs import normalize_artifact_job_inputs
from sophios.utils_nf import local_locations_as_paths

ModelT_co = TypeVar('ModelT_co', covariant=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.

mypy (2.3.1, the project config) fails here: run_setup.py:53: error: Cannot use a covariant type variable as a parameter [misc], at model: ModelT_co in the frozen dataclass Lowered. #585's head is clean, and CI's lint lane runs bare mypy, so this would fail it. An invariant TypeVar (TypeVar('ModelT')) clears it, and every changed source file passes with that one change, since every caller uses Lowered[Any] or the exact model type.

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. A covariant TypeVar can't be used as a parameter type, and the frozen dataclass Lowered has model as a field. I switched to an invariant ModelT. mypy over src/, examples/ and tests/ is now clean, and the fast core tests pass.

Fixed in c237465.

@vjaganat90

Copy link
Copy Markdown
Member Author

Thanks for the review. The one blocker, the mypy failure on Lowered, is fixed by making its TypeVar invariant. mypy is clean over src/, examples/ and tests/, and the fast core tests pass.

Fixed in c237465.

@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.

The mypy fix in c237465 is the invariant TypeVar, and with it mypy is clean over the changed files.

One thing left: this branch still sits on #585's old head (ff4d0c4), and #585 has since been rewritten (now 1e01d2b). Replaying this PR's own commits onto the new #585 conflicts in src/sophios/utils_nf.py at _refusal, and the conflict is semantic, not textual. The new #585 adds _unbound_output_findings (a workflow output relaying a nested input nothing binds, with cases in rejected/calls.yaml), and it returns plain-string findings. This PR makes every finding a _Finding with a code, so once restacked, that refusal needs an nf-s code (an existing one such as nf-s016, or a new one), an error_codes.md row, and codes: on its cases. Otherwise it is the one uncoded refusal, which the description says no longer exists.

We pick a target in hand-written branches at each entry point, and a
Nextflow refusal is the one problem we report without a code. This sets
out one table of targets that every entry point reads, and the nf-sNNN
codes that make each refusal an ordinary diagnostic.
Each reason a Nextflow refusal has gets a rejected case naming its code,
and we pin what D promises: refusals print as ordinary diagnostics from
the CLI and Python, check() returns them, --explain knows nf-s codes, an
unknown target is one message, and the table, --target and the
Literal agree. They fail until D lands.
Every reason the Nextflow target refuses a workflow gets an nf-sNNN code
of a new kind, target, carried from the lowering, the support table and
the model's checks into each refusal, which now prints as any Sophios
error. The catch-alls that turned any ValueError into an uncoded
refusal go, so a crash is reported as one.
Every entry point finds its target in sophios.targets, which holds each
target's lowering, writing and runners, so an unknown target is one
message and the run path lowers once. CWL answers the same contract as
Nextflow; the command line and check() report refusals as diagnostics.
The field table shows the code each rejected field is refused with,
the limits point at the nf-s list, and check() is described as
returning the target's refusals.
mypy rejects a covariant TypeVar as a parameter of the frozen dataclass.
Every caller uses Lowered[Any] or the exact model type, so invariance fits.
@vjaganat90
vjaganat90 force-pushed the feat/one-target-table branch from c237465 to e7d48d3 Compare November 13, 2026 17:30
@vjaganat90

Copy link
Copy Markdown
Member Author

On this branch the refusal you mention is already coded. _unbound_output_findings returns _Finding(NF_FORWARDED_INPUT), which is nf-s025. It has a row in error_codes.md, and the first case in rejected/calls.yaml carries codes: [nf-s025]. So nothing needs adding here. Replaying onto #585's new head is a carry. When I do it, I resolve the _refusal conflict in utils_nf.py by keeping the _Finding form and the nf-s025 code on the new #585's _unbound_output_findings, and by adding codes: to any new cases in rejected/calls.yaml. I'm not changing this branch for that.

@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. The rebase onto master carries the unbound relayed-input refusal as nf-s025 with its case coded, mypy is clean, and tests/core shows no new failures.

@vjaganat90
vjaganat90 merged commit 85ec0d1 into PolusAI:master Nov 13, 2026
3 checks passed
@vjaganat90
vjaganat90 deleted the feat/one-target-table branch November 13, 2026 17:44
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