Skip to content

docs: pull our concurrent database guidance into STYLE_GUIDE.md - #4641

Open
chet wants to merge 1 commit into
NVIDIA:mainfrom
chet:gh-issue-4624
Open

docs: pull our concurrent database guidance into STYLE_GUIDE.md#4641
chet wants to merge 1 commit into
NVIDIA:mainfrom
chet:gh-issue-4624

Conversation

@chet

@chet chet commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

This continues the series from #4522 (and related to #4522), with more to come.

This is an attempt to capture the general NICo maintainer design principles and guidance around concurrent database updates for the codebase. This PR is derived from the pre-OSS review corpus as a whole -- years of MRs and tens of thousands of comments and discussions. As such, it leans into the guiding design decisions and principles used to define and grow the project into the product we have today.

The idea is to ensure we capture our core principles in STYLE_GUIDE.md. If any of those principles have changed, we should capture that too, ensuring we don't lose sight of why decisions were made as the codebase evolves with new contributors, human and agentic alike.

For this PR specifically, I focused on concurrent database work. The corpus search surfaced related conversations across multiple people related to:

  • Row updates
  • Version checking
  • Row locking
  • Optimistic locking
  • Atomic operations
  • Transaction lifetimes
  • Long running/work locks

This pulls out the recurring parts:

  • Assume database updates can run concurrently.
  • Protect read-modify-write behavior with the narrowest invariant that proves it safe.
  • Keep transactions short, and treat txn_held_across_await as design feedback rather than something to silence.
  • Use WorkLockManager when long-running work needs cross-process lease admission, and fence the database writes performed under that lease.
  • Remember that a WorkLock is an expiring lease, not a fencing token; repeated or overlapping external effects need their own protection.
  • Make a zero-row version-checked update explicit instead of reporting the mutation as applied.
  • Test concurrent updates when the contract promises stale-write rejection.

The current WorkLockManager contract also makes the lease and fencing boundaries explicit.

It also keeps the important exceptions that a row lock is not always the right answer and that a deliberately conditional API may return a clear not-applied result. A narrowly reviewed infrastructure boundary or test may have a real reason to allow txn_held_across_await, but that reason and its connection-pool cost need to remain visible next to the allowance. Task-local exclusion should use an in-process owner or mutex, and a work lock is appropriate only when old and new workers overlapping after lease expiry cannot make the operation unsafe. Atomic SQL expressions, narrow updates, constraints, and version predicates may already exclude the invalid interleaving, and a work lock does not replace them for writers that do not participate in the same work key.

Again, we can always adjust this now or later. The hope is that we don't lose the reasoning behind why we made certain decisions to get us where we are now, and can continue using that reasoning to help drive future decisions.

Related issues

This supports #4624

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

@chet
chet requested a review from a team as a code owner August 6, 2026 00:07
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@chet I will perform a complete review of the pull request. 🐇

✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Summary by CodeRabbit

  • Documentation
    • Expanded database transaction guidance, including asynchronous operations, transaction-held-across-await behavior, production remediation, infrastructure exceptions, and test allowances.
    • Added best practices for concurrent updates, including atomic writes, version checks, stale-write handling, conditional APIs, and concurrency testing.
    • Documented safe coordination of long-running work with short transactions, lock leases, renewal and expiry, cleanup, ownership loss, and protection against duplicate or outdated external side effects.

Walkthrough

STYLE_GUIDE.md expands database guidance for transaction lint findings, concurrent updates, and long-running work. It defines remediation requirements, stale-write handling, WorkLockManager usage, lease behavior, and safeguards for external side effects.

Changes

Database concurrency guidance

Layer / File(s) Summary
Transaction and concurrent-update guidance
STYLE_GUIDE.md
Documents txn_held_across_await, production remediation, scoped exceptions, atomic or version-checked writes, stale-write outcomes, conditional APIs, and concurrency tests.
Long-running work coordination
STYLE_GUIDE.md
Defines WorkLockManager usage, short fenced transactions, lease renewal and expiry, cleanup semantics, ownership loss, and fencing or idempotency for external work.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the documentation change and names the updated file.
Description check ✅ Passed The description directly explains the concurrent database guidance added to STYLE_GUIDE.md.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@STYLE_GUIDE.md`:
- Around line 404-407: Update the `txn_held_across_await` guidance in
STYLE_GUIDE.md to replace the ambiguous phrase “a nested transaction derived
from it” with wording that explicitly says “a nested transaction derived from
that transaction,” while preserving the surrounding exception and responsibility
guidance.
- Around line 431-446: Expand the “Long-running work locks” documentation to
describe all WorkLock failure transitions: the keepalive loop retries Database,
WorkLockManagerSend, and WorkLockManagerReply errors but exits on LockLost;
release() can return dispatch, database, and reply errors; and Drop queues
release without waiting, so the lease may expire if cleanup fails. State that
successful release does not permit continuing protected work, while retaining
the existing fence_transaction and external fencing, idempotency, or
reconciliation requirements.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 85fbbf23-5fd6-4c2f-9d5f-4c6ff80637c2

📥 Commits

Reviewing files that changed from the base of the PR and between 9707667 and 35d979b.

📒 Files selected for processing (1)
  • STYLE_GUIDE.md

Comment thread STYLE_GUIDE.md Outdated
Comment thread STYLE_GUIDE.md
@chet chet changed the title docs: pull our concurrent-update guidance into STYLE_GUIDE.md docs: pull our concurrent database guidance into STYLE_GUIDE.md Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@chet I will perform a complete review of this pull request.

ᕱᕱ

✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@STYLE_GUIDE.md`:
- Around line 421-426: Expand the version-checked update guidance to require one
atomic statement that writes the requested values and advances or replaces the
version token, preventing reuse of the expected version. Define zero affected
rows explicitly: map them to ConcurrentModificationError only when the statement
or transaction distinguishes stale versions from missing or soft-deleted
targets; otherwise return NotFoundError or document the chosen conflict policy.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2da8202d-6295-422d-921f-a6bb3631c7b4

📥 Commits

Reviewing files that changed from the base of the PR and between 0ce16a7 and eacdcbc.

📒 Files selected for processing (1)
  • STYLE_GUIDE.md

Comment thread STYLE_GUIDE.md Outdated
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@chet I will perform a complete review of this pull request.

ᕱᕱ

✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@STYLE_GUIDE.md`:
- Around line 427-432: Clarify the no-match contract in the version-checked
predicate guidance by defining the outcome for targets that still exist but are
soft-deleted or otherwise ineligible. Assign these cases an explicit error or
not-applied result, or explicitly include them in the documented combined
missing/ineligible policy, while preserving the existing handling for proven
staleness and absence.
- Around line 444-445: Update the STYLE_GUIDE.md guidance for work-lock database
updates to explicitly require WorkLock::fence_transaction and all protected
writes to execute within the same short transaction, with the fence called
before the writes; document this ordering and transaction-scope contract
clearly.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 976ff8bb-bd07-4104-ba16-92e356bb4dc5

📥 Commits

Reviewing files that changed from the base of the PR and between 0ce16a7 and fbd9143.

📒 Files selected for processing (1)
  • STYLE_GUIDE.md

Comment thread STYLE_GUIDE.md Outdated
Comment thread STYLE_GUIDE.md Outdated
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@chet

chet commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@chet I will perform a complete review of pull request #4641.

ᕱᕱ

✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@chet

chet commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@chet I will perform a complete review of pull request #4641.

ᕱᕱ

✅ Action performed

Full review finished.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@STYLE_GUIDE.md`:
- Around line 449-453: Update the keepalive-loop documentation to define the
caller transition after the manager reports ownership loss: stop issuing new
protected writes or external side effects, perform the documented cleanup or
reconciliation path, and reacquire the work key before resuming protected work.
Preserve the existing distinction between Drop and release() cleanup behavior
and document that cleanup errors do not preserve ownership.
- Around line 421-425: Update the concurrency guidance around `SELECT ... FOR
UPDATE` to require that lock acquisition, the dependent write, and commit occur
within the same transaction, in that order. State that the write must happen
before committing the transaction so the row lock remains held through the
update.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 42c78b37-9f18-4a95-b9f1-0f6f6241a8e2

📥 Commits

Reviewing files that changed from the base of the PR and between 9d296f6 and 8542592.

📒 Files selected for processing (1)
  • STYLE_GUIDE.md

Comment thread STYLE_GUIDE.md
Comment thread STYLE_GUIDE.md Outdated
This is an attempt to capture the general NICo maintainer design principles and guidance around concurrent database updates for the codebase. This change is derived from the pre-OSS review corpus as a whole -- years of MRs and tens of thousands of comments and discussions. As such, it leans into the guiding design decisions and principles used to define and grow the project into the product we have today.

The idea is to ensure we capture our core principles in `STYLE_GUIDE.md`. If any of those principles have changed, we should capture that too, ensuring we don't lose sight of why decisions were made as the codebase evolves with new contributors, human and agentic alike.

For this change specifically, I focused on concurrent database work. The search surfaced related full-row-update, version-check, row-lock, atomic-operation, transaction-lifetime, and long-running work-lock conversations throughout the corpus and across multiple participants. The current `WorkLockManager` contract also makes the lease and fencing boundaries explicit.

This pulls out the recurring parts:

- Assume database updates can run concurrently.
- Protect read-modify-write behavior with the narrowest invariant that proves it safe.
- Keep transactions short, and treat `txn_held_across_await` as design feedback rather than something to silence.
- Use `WorkLockManager` when long-running work needs cross-process lease admission, and fence the database writes performed under that lease.
- Remember that a `WorkLock` is an expiring lease, not a fencing token; repeated or overlapping external effects need their own protection.
- Make a zero-row version-checked update explicit instead of reporting the mutation as applied.
- Test concurrent updates when the contract promises stale-write rejection.

It also keeps the important exceptions that a row lock is not always the right answer and that a deliberately conditional API may return a clear not-applied result. A narrowly reviewed infrastructure boundary or test may have a real reason to allow `txn_held_across_await`, but that reason and its connection-pool cost need to remain visible next to the allowance. Task-local exclusion should use an in-process owner or mutex, and a work lock is appropriate only when old and new workers overlapping after lease expiry cannot make the operation unsafe. Atomic SQL expressions, narrow updates, constraints, and version predicates may already exclude the invalid interleaving, and a work lock does not replace them for writers that do not participate in the same work key.

Again, we can always adjust this now or later. The hope is that we don't lose the reasoning behind why we made certain decisions to get us where we are now, and can continue using that reasoning to help drive future decisions.

This supports NVIDIA#4624

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@chet

chet commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@chet I will perform a complete review of pull request #4641.

ᕱᕱ

⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 5 minutes.

@chet

chet commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@chet I will perform a complete review of pull request #4641.

ᕱᕱ

⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 17 seconds.

@chet

chet commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@chet I will perform a complete review of pull request #4641.

ᕱᕱ

✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@STYLE_GUIDE.md`:
- Around line 443-460: Extend the WorkLockManager guidance to document all
caller-visible acquisition outcomes, including retrying WorkAlreadyLocked,
exiting on cancellation, releasing after post-acquisition cancellation,
successful completion, releasing after marker-check errors, and propagating
other acquisition errors. Also specify the required caller action for every
fence_transaction error that does not prove ownership loss, including when to
abort, retry, reconcile external work, release, or reacquire, while preserving
the existing ownership-loss behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c30d208c-a19c-4ac9-8b51-b3d670da9cb3

📥 Commits

Reviewing files that changed from the base of the PR and between 9d296f6 and 1320f64.

📒 Files selected for processing (1)
  • STYLE_GUIDE.md

Comment thread STYLE_GUIDE.md
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.

5 participants