fix(workflow): validate declared input and output schemas at publish and run boundaries (issue #274) #359
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.47) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 494 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.371
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #359"
general
weight: 0.35
yuluo-yx
Describe what this PR does / why we need it
Issue #274 reported that
WorkflowDefinitionexposesinputSchema/outputSchema, but the validator only rejected blank strings and the runner never read either field — an illegal schema could be published, a run missing a required input still executed its tools, and the outcome came back COMPLETED. This PR makes the declared schemas real contracts at both the publish and the run boundary, using the same JSON Schema capability the agent layer already ships (networknt, draft 2020-12, version managed by the root pom), so no competing validation stack is introduced and no public API changes.What is delivered
Publish and instantiation
WorkflowDefinitionValidatornow parses every non-blank declared schema with the networknt registry (draft 2020-12) and rejects malformed ones with an error naming the field and the dialect. Blank schemas keep their existing rejection; definitions without schemas keep their existing behavior untouched.Input boundary, before any side effect
On a fresh run,
WorkflowAgentvalidates the request inputs against the declared input schema before the first step executes — the issue's reproduction (missing required input, tool executed, COMPLETED) now fails with zero tool executions. The failure is aWorkflowValidationExceptioncarrying one structured issue per violating location, reusingAgentResult.OutputValidationIssue(errorCode, fieldPath, message)and the existingSCHEMA_MALFORMED/SCHEMA_VIOLATIONerror codes.Output boundary, no COMPLETED for a violating output
Before the COMPLETED outcome is delivered — on the single completion path shared by fresh runs and resumes — the output snapshot is validated against the declared output schema. A violation terminates the stream with the same structured exception, which matches the existing contract that errors terminate the stream exceptionally;
AgentOutcomeitself is unchanged.Documented boundaries
Resumes do not re-validate inputs: the continuation owns the state and a resume request often carries no inputs, so re-validating would make suspended workflows impossible to finish — output acceptance still applies on resume. Subflows share the parent run's inputs, so a nested definition's input schema is a publish-time contract for its own callers and is not applied again inside the parent run. Both boundaries are covered by tests.
Two pre-existing bugs on the resume path, fixed
The workflow module had no suspend/resume tests, and the issue's acceptance criteria ask for that coverage — writing the tests surfaced two latent bugs. First,
ExecutionResult.continueWithwrapped a suspension in a result whosedatawas null while the suspended-outcome construction reads that data, so any suspension NPE'd immediately; the wrapper now keeps the suspension-point snapshot. Second, resuming invoked the wrapped agent continuation twice (once insidecontinueWith, once again in the composed step lambda ofexecuteSteps/Loop) — a real agent rejects a second call carrying the same resume token. The composed step now receives the resumed result instead of re-resuming, and the resume tests assert that the agent is invoked exactly once per resume.Testing
New
WorkflowSchemaContractTestwith 10 cases: malformed input and output schemas rejected at publish, blank-schema regression, unchanged behavior without schemas, missing required input rejected with zero tool executions, type mismatch reporting the field path, valid input and output completing, output violation failing instead of completing, resume completing without input re-validation, resume output violation still failing, and subflow schema validation at publish without gating parent runs. Run against the unmodified code the suite fails 5F+2E (red, including the issue's reproduction); with the fix the whole argi-workflow-core module is 48/48 green, checkstyle clean.Fixes #274