Skip to content

Add transactional completion #job_complete_tx(job) for Ruby - #1490

Merged
brandur merged 1 commit into
masterfrom
brandur-job-complete-tx
Oct 24, 2026
Merged

brandur merged 1 commit into
masterfrom
brandur-job-complete-tx

Conversation

@brandur

@brandur brandur commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

An omission on the Ruby implementation is that a transactional
completion path never made it in.

Here, correct the oversight by adding #job_complete_tx. The naming is
close to Rust's job_complete_tx and TypeScript's completeTx.

@brandur
brandur force-pushed the brandur-job-complete-tx branch 2 times, most recently from 521db84 to b4e1751 Compare October 10, 2026 04:03
@brandur
brandur requested a review from bgentry October 10, 2026 04:04
@brandur
brandur force-pushed the brandur-job-complete-tx branch from b4e1751 to 792a22a Compare October 10, 2026 05:07
@brandur

brandur commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

@bgentry Hey, can you take a look at this one?

@bgentry

bgentry commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T16:49:37.147488Z 45203ac Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 792a22a04d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ruby/lib/client_runtime.rb Outdated
Comment on lines +421 to +422
completed = @driver.job_get_by_id(job.row.id)
return false unless completed && completed.state == JOB_STATE_COMPLETED

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent old workers from finalizing replacement attempts

When job_retry runs after the transaction commits but before the original worker or its middleware returns, this lookup can observe the row as available or already running in a replacement attempt. Returning false then sends the old execution through normal finalization; if the replacement has been claimed, line 320 can complete it using the old attempt's metadata while its worker is still executing (and a delete finalizer can similarly delete it). Reconciliation must detect that the attempt changed and avoid finalizing the replacement.

Useful? React with 👍 / 👎.

@brandur
brandur force-pushed the brandur-job-complete-tx branch from 792a22a to d289477 Compare October 24, 2026 16:28
@brandur

brandur commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d289477aa2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ruby/lib/client.rb Outdated
# persisted state because the caller may still roll back this transaction.
job.__completion_attempted = true
now = @time_now_utc.call
completed = @driver.job_complete(id: job.row.id, finalized_at: now, metadata: job.metadata_updates, now: now)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bind transactional completion to the supplied attempt

When the supplied Job belongs to an old worker whose attempt has been rescued or manually retried and the replacement is already running, this update matches the replacement because job_complete predicates only on the ID and state = 'running'. The stale worker can therefore complete the replacement and merge its own metadata into it. Include the original attempt identity (such as attempt and attempted_at) in the atomic completion predicate rather than checking identity only later during runtime finalization.

Useful? React with 👍 / 👎.

Comment thread ruby/lib/client_runtime.rb Outdated
Comment on lines +421 to +422
completed = @driver.job_get_by_id(job.row.id)
return false unless completed

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain committed completion when the row disappears

When completed-job retention is configured to zero, or application code deletes the completed row while the worker continues after committing job_complete_tx, this lookup can return nil. Returning false then treats the committed completion like a rollback: normal finalization hooks run and the promised job_completed event is omitted. Preserve the completed snapshot returned by job_complete_tx (while distinguishing calls that failed before completion) so deletion before this lookup follows the same committed-completion path already handled for deletion during the later metadata merge.

Useful? React with 👍 / 👎.

@brandur
brandur force-pushed the brandur-job-complete-tx branch from d289477 to 43efc0d Compare October 24, 2026 16:38
@brandur

brandur commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 43efc0d5be

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


# Runs the callback only if this transaction and its savepoints commit.
def after_commit(&block)
@db.after_commit(savepoint: true, &block)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require Sequel 5.20 for savepoint-aware hooks

When an application resolves Sequel older than 5.20, which the unchanged sequel > 0 gemspec constraint still permits, after_commit accepts this hash but ignores savepoint: true because savepoint-aware transaction hooks were only added in 5.20 (Sequel changelog). If job_complete_tx is called in a nested savepoint that rolls back while the outer transaction commits, this callback therefore retains a completion snapshot that never committed; if the running row is deleted before the worker returns, finish_transactional_completion can publish a false completion event from that snapshot. Raise the Sequel dependency floor to a version that implements the required hook semantics.

Useful? React with 👍 / 👎.

An omission on the Ruby implementation is that a transactional
completion path never made it in.

Here, correct the oversight by adding `#job_complete_tx`. The naming is
close to Rust's `job_complete_tx` and TypeScript's `completeTx`.
@brandur
brandur force-pushed the brandur-job-complete-tx branch from 43efc0d to 45203ac Compare October 24, 2026 16:45
@brandur

brandur commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 45203ac819

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@brandur
brandur merged commit 928c04a into master Oct 24, 2026
33 checks passed
@brandur
brandur deleted the brandur-job-complete-tx branch October 24, 2026 16:52
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