Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@RobertAtNineMinds
Copy link
Contributor

Summary

  • schedule workflow execution to run after the surrounding admin transaction commits
  • keep action contexts on pooled connections so FK checks see committed execution rows before logging actions

Testing

  • not run (not requested)

@nine-minds-ai-code-reviewer-bot

🤖 AI Code Review

Great step toward making workflow runs independent of the caller’s DB transaction – this should remove the “can’t see my own inserts” race we’ve been debugging. 👍

Critical / must-fix

  1. Possible use of a closed connection
    createWorkflowContext receives the same knex (the one coming from the transaction wrapper).
    • When the outer transaction finishes the connection is released back to the pool. Because we now call executeWorkflow in a setImmediate, there is a real chance the trx is already committed/rolled-back and the connection object has been disposed when the workflow logic starts, leading to “Connection terminated” / “Transaction query already complete” errors under load.
    ➜ Use trx.afterCommit(() => …) (Knex API) or create a fresh tenant-scoped knex in the setImmediate callback so the workflow always runs on a valid connection.

Suggestions / questions
• Ordering guarantee – setImmediate fires after the current poll phase, but the underlying commit I/O may still be in flight. trx.afterCommit would give a stronger “fully flushed” guarantee and avoid subtle race conditions.
• Error propagation – we log the error, but callers have no visibility that the workflow failed. Consider pushing a failure record into workflow_executions so the UI can surface it.
• Unit test – could we add a small test that asserts executeWorkflow is NOT called until after trx.commit resolves? That would lock in the new behaviour.

Everything else looks good – no RBAC, Citus, or UI guideline regressions detected in this patch. Nice work moving us closer to truly async, transaction-safe workflows!


Generated by AI Code Review System | Review Configuration

@RobertAtNineMinds RobertAtNineMinds force-pushed the bugfix/workflow-knex-defer branch from ef580ae to c577aad Compare October 27, 2025 19:00
@nine-minds-ai-code-reviewer-bot

🤖 AI Code Review

This is an incremental review of new changes.

👋 Hi again!
It looks like the follow-up push didn’t include any file changes in the diff (the section after diff is empty), so I can’t see the new commits that should address the earlier feedback.

Because no code is visible:

  1. Previous concerns status
    • Impossible to verify whether the “closed connection” risk was fixed with trx.afterCommit or a fresh knex instance.
    • Can’t confirm ordering guarantees, error propagation, or tests.

  2. New code additions
    • None shown in the diff.

  3. Improvements noted
    • Unable to assess without the updated files.

Could you double-check that the most recent commit was pushed to the PR and re-generate the diff? Once the changes are visible I’ll be happy to do the full pass. 🙂


Generated by AI Code Review System | Review Configuration

@RobertAtNineMinds RobertAtNineMinds force-pushed the bugfix/workflow-knex-defer branch from c577aad to 66f38ca Compare October 27, 2025 19:21
@nine-minds-ai-code-reviewer-bot

🤖 AI Code Review

This is an incremental review of new changes.

🤖 AI Code Review – Follow-up Pass

Hi again! 👋
Unfortunately the PR diff is still empty, so I still can’t see any of the changes that should address the original feedback.

  1. Previous concerns
    • Still can’t verify the “closed connection” fix (trx.afterCommit, new knex instance, etc.)
    • Ordering / error-propagation guarantees remain uninspected.
    • No tests visible.

  2. New code additions
    • None present in the diff.

  3. Improvements noted
    • Can’t assess.

Possible reasons the diff is blank

  1. The branch exactly matches the base branch (was a force-push that deleted commits).
  2. The latest commits haven’t been pushed (git push origin <branch>).
  3. The PR target branch was changed to one with identical contents.
  4. The CI system filtered out file types (unlikely, but worth checking).

Next steps

  1. Verify you’re on the correct branch:
    git status
    git log --oneline -n 5
    
  2. Make sure the commits exist locally and are pushed:
    git push origin <branch>
    
  3. Re-open the PR diff in GitHub/GitLab to ensure files show up.
  4. If you did an interactive rebase / force-push, confirm nothing was squashed away inadvertently.

Once a non-empty diff appears I’ll do the full review right away. 😊


Generated by AI Code Review System | Review Configuration

@RobertAtNineMinds RobertAtNineMinds force-pushed the bugfix/workflow-knex-defer branch from 66f38ca to e0e819d Compare October 27, 2025 19:34
@nine-minds-ai-code-reviewer-bot

🤖 AI Code Review

This is an incremental review of new changes.

🤖 AI Code Review – Follow-up Pass #2

Hi again! 👋
It looks like the PR diff is still coming through as empty, so I’m unfortunately still unable to inspect any of the changes that should address the original feedback.

1 ️. Previous concerns

Because no code appears in the diff:

• I still can’t verify the “closed connection” fix (trx.afterCommit, creating a fresh knex instance, etc.).
• Ordering / error-propagation guarantees remain uninspected.
• No tests are visible.

2 ️. New code additions

None are present in the rendered diff.

3 ️. Improvements noted

Can’t assess yet.


Why is the diff blank?

Same root causes as last time are the most common culprits:

  1. Feature branch currently matches the base branch (force-push removed commits, or branch was retargeted).
  2. Latest commits exist only locally and haven’t been pushed.
  3. A PR filter (path, commit range) is hiding files.
  4. GitHub cache glitch (rare but can happen—re-open or hard-refresh).

Quick checklist to unblock the review

# 1. Make sure you’re on the expected branch
git status
git branch --show-current

# 2. Confirm your commits are still there
git log --oneline -n 5

# 3. Make sure they’re pushed
git push origin <branch-name>

# 4. Double-check the PR target branch and re-open the “Files changed” tab

If everything looks correct locally but GitHub still shows an empty diff, try closing/re-opening the PR or pushing a no-op commit:

git commit --allow-empty -m "chore: trigger diff refresh"
git push

That usually forces GitHub to regenerate the comparison view.


📣 Ping me once the diff shows up—happy to jump right back in and do the full technical review! 😊


Generated by AI Code Review System | Review Configuration

@RobertAtNineMinds RobertAtNineMinds force-pushed the bugfix/workflow-knex-defer branch from e0e819d to 88106c9 Compare October 27, 2025 22:27
@nine-minds-ai-code-reviewer-bot

🤖 AI Code Review

This is an incremental review of new changes.

🤖 AI Code Review – Follow-up Pass #3

Hi again! 👋
Unfortunately, the PR diff is still rendering as empty, so I can’t see any of the commits that should address the outstanding feedback.

1. Previous concerns

Because no code is visible, the earlier items remain unverifiable:

• “Closed connection” fix (trx.afterCommit, fresh Knex instance)
• Guaranteed ordering / error-propagation around the workflow trigger
• New tests that cover the deferred-execution path

2. New code additions

None appear in the diff.

3. Improvements noted

Unable to assess yet.


Possible reasons the diff is blank (again)

  1. The feature branch currently matches the base branch (force-push or retarget).
  2. Commits haven’t been pushed.
  3. A PR file-filter is hiding everything.
  4. GitHub cache hiccup (rare, but a close/re-open or a hard refresh can fix).

Quick checklist to unblock the review

# 1. Ensure you’re on the correct branch
git status
git branch --show-current

# 2. Verify the commits exist locally
git log --oneline -n 5

# 3. Push if needed
git push origin <branch-name>

# 4. Re-open the “Files changed” tab (or close/re-open the PR)

If everything looks correct locally but the PR is still empty, push a no-op commit to force GitHub to regenerate the diff:

git commit --allow-empty -m "chore: trigger diff refresh"
git push

That usually does the trick.


📣 Ping me once the diff shows up—happy to dive straight into the real code review! 😊


Generated by AI Code Review System | Review Configuration

@nine-minds-ai-code-reviewer-bot

🤖 AI Code Review

This is an incremental review of new changes.

🤖 AI Code Review – Follow-up Pass #4

Hi again! 👋 Thanks for pushing a new commit. I can finally see a non-empty diff, but it’s just a single-line change inside shared/models/ticketModel.ts. Below is a quick pass that covers:

  1. Whether the outstanding concerns from the previous review are now addressed
  2. The new code that was added/modified
  3. Any improvements noted

1 | Outstanding concerns from the last review

Topic Status Notes
“Closed connection” fix (fresh Knex instance + trx.afterCommit) No new code related to afterCommit or fresh Knex instantiation appears in the diff, so I still can’t verify the fix.
Guaranteed ordering / error-propagation around the deferred workflow trigger Same as above—no visibility yet.
Tests covering the deferred-execution path No new tests are shown.

👉 Action: If these changes exist on your branch, they aren’t showing up in the PR diff. Double-check the branch, push any missing commits, or do a quick empty commit to force a GitHub diff refresh (git commit --allow-empty -m "chore: refresh diff").


2 | Review of the new code

if (!locationResult.valid && locationResult.error) {
  // Remove invalid location instead of failing validation
  console.warn(`[TICKET_MODEL] ${locationResult.error}. Removing location from ticket creation.`);
  input.location_id = undefined;
}

What changed?

• Instead of pushing the validation error into errors (which ultimately aborts the ticket create flow), we now:

  1. Log a warning
  2. Strip the invalid location_id
  3. Allow the ticket to be created with no location

Pros

  1. Reduces “false negative” creation failures when the only problem is an invalid / missing location.
  2. End-users can finish creating their ticket instead of getting a 400.

Potential concerns / suggestions

  1. Silent data loss / hidden errors
    • Users won’t know their selected location was dropped.
    • Consider surfacing a user-visible message (e.g., “The selected location was invalid and has been cleared.”) so they can fix it later.

  2. Referential-integrity mismatch
    • If the location is invalid because it doesn’t belong to the ticket’s company, silently dropping it may hide a deeper permissions issue.
    • At minimum, we should emit a structured warning to the app’s logger (logger.warn) instead of console.warn, so we can monitor recurring issues.

  3. Side-effects on the input object
    • Mutating input directly inside validation makes the function impure and can surprise callers if they reuse the object.
    • Safer pattern: clone input or return a sanitized copy.

  4. Tests needed
    • Please add a test that feeds an invalid location, asserts the ticket is still created, and verifies location_id is NULL in the DB.
    • Also assert that a warning log was fired (you can stub the logger).


3 | Improvements noted

• The ticket-creation UX should feel more forgiving because a single bad location no longer blocks the entire operation.
• The warning message is at least something—better than failing with a vague validation error.


✅ Quick next steps

  1. Push (or re-push) the commits that add the afterCommit/Knex-instance fix and the new tests, or let me know if they’re in another PR.
  2. Consider the logging / user-feedback refinements above.
  3. Add a unit/integration test for the “invalid location is stripped” path.

Ping me once the full diff is visible—happy to continue! 😊


Generated by AI Code Review System | Review Configuration


Generated by AI Code Review System | Review Configuration

@openhands-ai
Copy link

openhands-ai bot commented Oct 27, 2025

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • E2E Fresh Install Tests

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #1192 at branch `bugfix/workflow-knex-defer`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

@CLAassistant
Copy link

CLAassistant commented Nov 10, 2025

CLA assistant check
All committers have signed the CLA.

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.

3 participants