← Back to Pull requests

fix(api): refuse writes whose namespace was released while they waited #380

Closed
unknown closed this pull request without merging on Nov 13, 2026 04:49 UTC
View on GitHub
unknown unknown commented on Nov 12, 2026 21:46 UTC
Author

Summary

A write authorizes against the namespace registry before it takes the mutation lock. A branch deletion can release a provisional namespace row in that gap. The write then lands an entity in a namespace that has no row, and the next writer of any owner claims that namespace and its entity.

Example: owner acme writes acme-orders on branch @acme:draft, which claims a provisional row. Next, acme starts a baseline PutEntity into acme-orders, and the authorization passes. Before the write gets the lock, DeleteBranch @acme:draft releases the row, because baseline is still empty. Before this change, the write then landed with no row.

Change

  • Add require_targets_still_registered. It reads the registry under the mutation lock and returns FAILED_PRECONDITION with a retry message when a target row is gone.

  • PutEntity, BatchMutate, RevertChangeset and ResolveBranchEntry call it first after they take the lock.

  • Dry runs and writes with no principal skip the check, because they never claim a row.

  • MergeBranch, source runs and artifact uploads already authorize under the lock, so they do not change.
  • DeleteNamespace (#377) relies on this check, because it removes rows under the same lock.

    Tests

  • tests/namespace_release_race.rs pauses a baseline write after its authorization, deletes the branch, and then expects FAILED_PRECONDITION and no stored entity. It fails on main.

  • namespace_ownership, handler_tests, branching, changesets, branch_namespace_tenure, namespace_scope, dry_run_side_effects, authorization_freshness, message_claims_acceptance and artifact_namespace_authority pass. fmt and clippy -D warnings pass.
  • <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Touches core mutation paths and namespace ownership checks under the global lock; failures are explicit retries but behavior changes for concurrent branch/namespace lifecycle operations.

    > Overview

    Fixes a race where writes authorize against the namespace registry before taking the mutation lock, so a branch delete or ownership change in between could let a write land in a namespace that no longer matches the prior authorization.

    > Adds require_targets_still_registered, which re-reads the registry under the lock and returns FAILED_PRECONDITION (with a retry hint) when a target namespace row is gone or a bound principal no longer has write access. PutEntity, BatchMutate, RevertChangeset, and ResolveBranchEntry call it immediately after acquiring the lock; dry runs and principal-less persists skip it. RevertChangeset also settle_not_applied on that refusal so the operation_id can be retried.

    > New integration tests in namespace_release_race.rs pause authorization, simulate release/adoption, and assert refusal with no landed data.

    > <sup>Reviewed by Cursor Bugbot for commit f318209620714580cce3771ea816e801c72d185f. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    Diff: 394 lines (+295 / -99) across 4 files Reviewer: yordis Review duration: 423m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 394 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.358
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #380"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.2% (MEDIUM) · Higher = larger blast radius
    43.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.1% · Safe to merge
    17.1%