Skip to content

Optionally Disable Expansion if Constraints Violated#1837

Open
pranav-super wants to merge 2 commits into
developfrom
feature/disable-expansion-on-constraint-viol
Open

Optionally Disable Expansion if Constraints Violated#1837
pranav-super wants to merge 2 commits into
developfrom
feature/disable-expansion-on-constraint-viol

Conversation

@pranav-super

Copy link
Copy Markdown
Contributor
  • Tickets addressed: N/A; LRO MOT Request
  • Review: By commit
  • Merge strategy: Merge (no squash)

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 expandAllTemplates if 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 bypassConstraints to false activated this feature).

Documentation

None.

Future work

None anticipated.

Comment thread sequencing-server/src/routes/command-expansion.ts Fixed
@pranav-super pranav-super added the publish Tells GH to publish docker images for this PR label Jun 26, 2026
simulationDatasetId: Int!,
modelId: Int!
modelId: Int!,
bypassConstraints: Bool, // (optional)

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.

this comment seems to be preventing successful compilation

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.

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;

@AaronPlave AaronPlave Jun 30, 2026

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.

Should this be req.body.input. bypassConstraints?

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.

And should it default to true or false? Opt-in vs opt-out?

@AaronPlave

Copy link
Copy Markdown
Contributor

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);

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.

leftover log?

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" : ""}.`

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.

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<{

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.

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' : ''}.`,
    );
  }
}

@sonarqubecloud

sonarqubecloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)
92.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

publish Tells GH to publish docker images for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants