Optionally Disable Expansion if Constraints Violated#1837
Conversation
| simulationDatasetId: Int!, | ||
| modelId: Int! | ||
| modelId: Int!, | ||
| bypassConstraints: Bool, // (optional) |
There was a problem hiding this comment.
this comment seems to be preventing successful compilation
There was a problem hiding this comment.
And shouldn't it be Boolean?
|
|
||
| // 0. Extract stuff from request | ||
| // needed to uniquely identify sequence templates, along with activity type | ||
| const bypassConstraints = req.body.bypass !== undefined ? req.body.bypass as boolean : true; |
There was a problem hiding this comment.
Should this be req.body.input. bypassConstraints?
There was a problem hiding this comment.
And should it default to true or false? Opt-in vs opt-out?
|
Any reason not to also have this gating on non-template expansion? |
| }, | ||
| ); | ||
|
|
||
| console.log(simulationDatasetId, JSON.stringify(constraint_run), "\n", constraint_run.at(constraint_run.length-1), "\n", constraint_run.at(constraint_run.length-1)?.results.results.violations); |
| if (constraint_run.at(constraint_run.length-1)?.results.results.violations.length) { | ||
| const numViolations = constraint_run.at(constraint_run.length-1)?.results.results.violations.length; | ||
| throw new Error( | ||
| `POST /command-expansion/expand-all-sequence-templates: Expansion for simulation dataset ${simulationDatasetId} failed, as there ${numViolations ?? 0 > 1 ? "are" : "is"} still ${numViolations} violation${numViolations ?? 0 > 1 ? "s" : ""}.` |
There was a problem hiding this comment.
Think you need parens around this clause:
(numViolations ?? 0) > 1
| // not checking if simulation is out of date, as that leads to a lot of extra Hasura calls and processing here, and this expansion call is for a specific simulation dataset. | ||
| // additionally, not checking unchecked cosntraints, as we shouldn't throw an error if anything is unchecked. | ||
| // we only care about if there are violated constraints: | ||
| const { constraint_run } = await graphqlClient.request<{ |
There was a problem hiding this comment.
So each constraint has an independent run (scoped to a sim dataset) so we need to check validation status of all constraint runs for the latest constraint request. Something like this ish:
// 0b. [OPTIONAL] Verify constraints are satisfied for the given simulationDatasetId.
if (!bypassConstraints) {
// We only block on *violations*. We intentionally don't fail on stale sims,
// unchecked constraints, or constraint errors — only on confirmed violations
// in the most recent constraint request for this simulation dataset.
const { constraint_request } = await graphqlClient.request<{
constraint_request: {
constraints_run: {
results: {
results: { gaps: object[]; violations: object[] };
};
}[];
}[];
}>(
gql`
query GetLatestConstraintViolations($simulationDatasetId: Int!) {
constraint_request(
where: { simulation_dataset_id: { _eq: $simulationDatasetId } }
order_by: { requested_at: desc }
limit: 1
) {
constraints_run {
results {
results
}
}
}
}
`,
{ simulationDatasetId },
);
const latestRequest = constraint_request[0];
if (latestRequest === undefined) {
throw new Error(
`POST /command-expansion/expand-all-sequence-templates: Expansion for simulation dataset ${simulationDatasetId} failed, as constraints haven't been checked yet.`,
);
}
const numViolations = latestRequest.constraints_run.reduce(
(total, run) => total + (run.results?.results?.violations?.length ?? 0),
0,
);
if (numViolations > 0) {
throw new Error(
`POST /command-expansion/expand-all-sequence-templates: Expansion for simulation dataset ${simulationDatasetId} failed, as there ${
numViolations > 1 ? 'are' : 'is'
} still ${numViolations} violation${numViolations > 1 ? 's' : ''}.`,
);
}
}
|


Description
The issue in question involves adding a warning to the UI to notify planners when there are violations on their plan before expansion.
Here, a 'headless' analogue was added, which throws an error when there are constraint violations during a call to
expandAllTemplatesif they are not explicitly bypassed.The default is to bypass this check, so as to avoid interference with past behavior.
Currently, erroring is only thrown when there are violations for a given simulation ID. Checks that are made on the UI side, like the simulation being up to date, unchecked constraints, and the like, are not done here as erroring for those other issues is not considered necessary.
Verification
They were tested locally, both with and without the UI updates (where removal of the UI update and explicitly setting
bypassConstraintsto false activated this feature).Documentation
None.
Future work
None anticipated.