fix(policy): advance sandbox resource version on every policy revision - #4108
Closed
jayasri-88 wants to merge 1 commit into
Closed
jayasri-88 wants to merge 1 commit into
jayasri-88 wants to merge 1 commit into
Conversation
put_policy_revision_atomic skipped the sandbox row update whenever the policy projection was a no-op, leaving resource_version unchanged even though a new revision was committed. Callers pass resource_version as the optimistic concurrency precondition on the next write, so a stale holder of the pre-revision value could still commit policy content derived from a read that had already been superseded. Both the SQLite and PostgreSQL implementations now always perform the CAS-guarded sandbox update, so every committed revision bumps resource_version and updated_at_ms. expected_resource_version = 0 still skips the precondition check while still advancing the version. Closes NVIDIA#4062 Signed-off-by: jayasri-88 <jayasrimunnaluri@gmail.com>
jayasri-88
requested review from
a team,
derekwaynecarr,
mrunalp and
sjenning
as code owners
October 2, 2026 07:46
|
All contributors have signed the DCO ✍️ ✅ |
|
Thank you for your interest in contributing to OpenShell, @jayasri-88. This project uses a vouch system for first-time contributors. Before submitting a pull request, you need to be vouched by a maintainer. To get vouched:
See CONTRIBUTING.md for details. |
Author
|
I have read the DCO document and I hereby sign the DCO. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
put_policy_revision_atomiccommitted a new policy revision without advancing the sandbox'sresource_versionwhenever the projection was a no-op (unchanged annotations, no backfill, or identical policy content). Becauseexpected_resource_versionis the optimistic-concurrency precondition, a later writer holding the pre-revision value could still commit policy content derived from an already-superseded read. Both backends now always perform the CAS-guarded sandbox row update, so every committed revision invalidates any earlier resource-version precondition.Related Issue
Closes #4062
Changes
crates/openshell-server/src/persistence/sqlite.rs:put_policy_revision_atomicalways runs theWHERE resource_version = ?4CAS-guarded update, incrementingresource_versionand refreshingupdated_at_ms, and returnsPersistenceError::Conflicton zero affected rows.crates/openshell-server/src/persistence/postgres.rs: equivalent unconditional CAS-guarded update on theFOR UPDATE-locked row.expected_resource_version = 0still skips the precondition comparison, but now also advances the version.put_policy_revisionand global policy-revision behavior are untouched.Testing
Verification performed on Windows with Rust 1.95.0:
cargo fmt --all -- --check— clean.cargo test -p openshell-server --lib --features prebuilt-z3— 1871 passed, 0 failed, 8 ignored.cargo clippy -p openshell-server --lib --tests --features prebuilt-z3— exit 0, no findings inpersistence/. The remaining warnings are pre-existing Windows-only lints incredentials.rs,compute/mod.rs, andopenshell-extension-core, and are unrelated to this change.Regression tests added in
crates/openshell-server/src/persistence/tests.rs, one per acceptance criterion:policy_atomic_write_advances_resource_version_without_projection_change— empty policy, no backfill, empty annotations still bumps the version and refreshesupdated_at_ms.policy_atomic_write_advances_resource_version_with_identical_backfill_policy— re-submitting the policy the sandbox is already running still bumps the version.policy_atomic_write_with_zero_expected_version_still_advances— unconditional write (expected_resource_version = 0) still bumps the version.policy_atomic_write_rejects_stale_expected_resource_version— a second writer using the previous nonzero version getsConflict.policy_atomic_write_succeeds_after_rereading_resource_version— re-reading permits a legitimate retry.policy_atomic_write_rolls_back_sandbox_when_revision_insert_conflicts— extended to assert the sandbox version, the latest policy revision, and the absent conflicting policy row are all rolled back.All five version-advancement tests were confirmed to fail against the unpatched implementation and pass with the fix.
PostgreSQL was updated for semantic parity but, as in the issue report, was not exercised against a live PostgreSQL instance; the test suite here runs on in-memory SQLite.
Checklist
ABORTEDon a version mismatch)