Skip to content

feat(sdk): approvals a settled deletion needs of a team, empty seats documented - #5245

Closed
QuantumExplorer wants to merge 1 commit into
v5.0-devfrom
claude/approval-deadlock-empty-seats-00c155
Closed

QuantumExplorer wants to merge 1 commit into
v5.0-devfrom
claude/approval-deadlock-empty-seats-00c155

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

A seated moderation team can delete a settled document (one past its deleteWithin window) only when enough members approve. The number they need is fixed by the team's seats, not by who is on the team right now. A removed member keeps their seat, so removing people never lowers the bar. That stops a leader from removing everyone who would say no and then deleting alone.

The downside is that a team can get stuck. If too many elected members are gone for good (removed, lost their keys, or stopped answering), the team can never reach the number again, because nobody else can take an elected member's seat. This PR does not change that rule. It writes the trade-off down where contract authors and client developers will see it, and it adds an SDK read that gives a client the number a team needs.

Issue being fixed or feature implemented

A review found that needed = min(approvals, seats) counts empty seats and removed members, so a team that shrinks can deadlock its settled deletions. The review asked for either of two fixes:

  1. cap needed by the people who can approve right now, or
  2. document this and expose needed in the team read.

This PR does option 2. Option 1 would let the leader remove members until it can approve alone, which defeats the point of a rule like "the leader and two others".

The review's first example is milder than it reads. With a leader, 2 elected members and maxAddedModerators: 2 (5 seats, 3 needed), removing one member leaves 2 people, but the leader can still add 2 members from the proposal's join requests, or delete the removal. Settled deletions stay stuck only until the leader does one of those. The second example does hold: on a team of exactly approvals people with no additions allowed (maxAddedModerators: 0, the default), one elected member who can't approve stops every settled deletion for good, because a seat is never contested again in protocol version 14.

What was done?

  • rs-sdk ModerationTeam::settled_deletion_approvals_needed(rule, max_added_moderators) returns what a settled deletion needs of the team. It calls SettledDeletionRule::approvals_needed over seats, the same count consensus uses.
  • wasm-sdk / evo-sdk ModerationTeam.settledDeletionApprovalsNeeded(approvals, maxAddedModerators) is the same in JavaScript. A u16_argument helper now validates both numbers and seats().

Before, a client had to know the rule:

const team = await sdk.moderationCharters.team(contractId);
const needed = Math.min(approvals, team.seats(maxAddedModerators));

After:

const team = await sdk.moderationCharters.team(contractId);
const needed = team.settledDeletionApprovalsNeeded(approvals, maxAddedModerators);
if (team.members.length + 1 < needed) {
  // stuck until the leader adds members or deletes a removal
}
  • Docs: a new "A team that falls short" bullet in the book's deleteSettled section, a note for authors under "Rules at registration" to leave room for members lost for good, and the same trade-off in SettledDeletionRule::approvals, ElectedCharter::seats, the drive-abci approval comment and the evo-sdk team() doc.
  • Fixed a stale book line: maxAddedModerators caps the additions that exist at a time (deleting one frees its slot), not every addition ever filed. Consensus already counts it this way (count_added_moderators), and the same chapter says so further down.

How Has This Been Tested?

  • cargo test -p dash-sdk --lib moderation_charters::team, including a new test: 5 seats with a rule of 3 needs 3, and still needs 3 after the leader removes a member and only 2 people are left. A rule of 31 needs every seat.
  • cargo check -p wasm-sdk --target wasm32-unknown-unknown and cargo check -p drive-abci (dpp builds under both), cargo clippy -p dash-sdk --lib clean.

Breaking Changes

None. No consensus change: the new code is SDK read helpers, and everything else is comments and docs.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 2257ee5

  • Bots — coderabbitai ✓ · thepastaclaw ✓
  • Self-review — post /self-reviewed
  • Reviewer requests paused — your 5 review slots are occupied; this PR is excluded from reviewers' queues. Required approvals still count without a slot.
  • Build green
  • Approvals
    • files with no dedicated owner — you own it
    • js-wasm-sdk (packages/js-evo-sdk/src/moderation-charters/facade.ts, packages/wasm-sdk/src/moderation_charters.rs) — shumkov
    • dpp — you own it
    • rs-drive-abci — you own it
    • rust-sdk (packages/rs-sdk/src/platform/moderation_charters/team.rs) — lklimek or shumkov

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • New Features

    • Added SDK helpers to calculate the approvals required for a settled deletion based on a moderation team’s seats and the configured added-moderator capacity.
  • Documentation

    • Clarified that removed elected members retain their seats, so removing them does not reduce the approval threshold. If too few elected members remain able to approve, the threshold may be impossible to meet.
    • Explained that added-moderator seats can be reused when an addition is deleted, while elected-member seats cannot be reassigned. Approval limits are based on declared team capacity, including the leader.

…documented

A settled deletion needs min(approvals, seats) approvals, and a removed
elected member keeps its seat, so the leader can not lower the bar by
removing members who would not approve. The price is liveness: nobody
else takes an elected member's seat, so a team that loses too many
elected members for good never meets the rule again. The rule stays;
this writes the trade-off down and lets clients read the count.

- rs-sdk ModerationTeam::settled_deletion_approvals_needed and
  wasm/evo settledDeletionApprovalsNeeded, over SettledDeletionRule's
  approvals_needed and the team's seats, as consensus counts
- book: "A team that falls short" under deleteSettled, an authors'
  note at registration, and the stale "additions ever filed" line
  fixed (the cap counts the additions that exist now)
- dpp, drive-abci and evo-sdk docs carry the same trade-off

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added this to the v5.0.0 milestone Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

📖 Book Preview built successfully.

Download the preview from the workflow artifacts.
To view locally: download the artifact, unzip, and open index.html.

Updated at 2026-10-02T00:52:10.086Z

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 2, 2026
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: dashpay/platform/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 6df9a772-39a8-4711-b5f0-457139fde280

📥 Commits

Reviewing files that changed from the base of the PR and between e1efd2a and 2257ee5.

📒 Files selected for processing (8)
  • book/src/contract-keywords/deletion.md
  • book/src/data-model/contract-moderation.md
  • packages/js-evo-sdk/src/moderation-charters/facade.ts
  • packages/rs-dpp/src/data_contract/config/moderation/settled_deletion.rs
  • packages/rs-dpp/src/moderation_charter/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/state/v0/mod.rs
  • packages/rs-sdk/src/platform/moderation_charters/team.rs
  • packages/wasm-sdk/src/moderation_charters.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The changes clarify how declared team seats determine settled-deletion approval requirements. They add an approval-count helper to the Rust SDK and expose the calculation in the WebAssembly SDK with numeric argument validation.

Changes

Settled-deletion approval seats

Layer / File(s) Summary
Document seat and approval rules
book/src/contract-keywords/deletion.md, book/src/data-model/contract-moderation.md, packages/rs-dpp/src/data_contract/config/moderation/settled_deletion.rs, packages/rs-dpp/src/moderation_charter/mod.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/state/v0/mod.rs, packages/js-evo-sdk/src/moderation-charters/facade.ts
Clarifies that removed elected members retain seats and can leave approval requirements unmet. Documents that deleting an added member frees an addition slot.
Calculate required approvals in the Rust SDK
packages/rs-sdk/src/platform/moderation_charters/team.rs
Adds settled_deletion_approvals_needed, which caps the required approvals at the team’s seat count. Tests cover capped and uncapped counts and removal of an elected member.
Expose approval calculation in the WebAssembly SDK
packages/wasm-sdk/src/moderation_charters.rs
Adds settledDeletionApprovalsNeeded and validates its numeric arguments as integers from 0 through 65535. Updates seats to use the shared numeric validation helper.

Priority: ➖ Normal

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

Change: Feature

Merge Risk: ⚪ Minimal · up to 2257e

The SDK helpers expose the existing approval threshold without changing deletion rules. No actionable merge-blocking risk is identified; merge after normal checks.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to 2257e

The new methods calculate approval counts without authorizing or executing deletions. Existing approval and leader checks remain authoritative. The documented possibility of a team permanently losing its ability to approve deletions predates this PR.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — For the inspected new entrypoints, attacker-controlled numeric parameters can affect the returned advisory count but do not grant document-deletion authority. Incorrect or stale parameters can mislead the calling client; the authoritative deletion path does not consume this calculated result.

Trust Boundaries and Controls

  • observed — The inspected initial-proposal and subsequent-approval paths retain independent checks of moderation authority, team participation, document eligibility, and the actual settled-deletion rule before execution. The new read helper does not replace these controls.

Resilience and Maintainability Implications

  • inferred — Retaining elected seats prevents member removal alone from reducing the approval threshold, preserving the existing resistance to quorum manipulation. Its associated loss-of-quorum risk remains an unchanged policy trade-off, not a newly introduced PR concern.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately identifies the SDK approval-count feature and the documentation of empty seats, which are the main changes in the pull request.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 6 files. (2 skipped: 2…
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 docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@thepastaclaw

thepastaclaw commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 2257ee5) · triage: low

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Final validation — Phase 1 + Phase 2

Verified the supplied findings against head 2257ee5. The SDK helper matches the existing consensus threshold calculation, and the consensus-adjacent edits are comments only; one non-blocking test-coverage suggestion remains. This was a static review: the supplied CI snapshot shows successful SDK/WASM checks and builds, with Rust workspace tests and two platform test suites still running.

🟡 1 suggestion(s)

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: glm-5.3-flash (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — This is a small, well-contained SDK/API and documentation change that mirrors existing consensus calculations without modifying consensus behavior, funds, cryptography, networking, or storage.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer, glm-5.3-flash — rust-quality (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 100% left, weekly 71% left; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 69% left, 5h 11% left)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/wasm-sdk/src/moderation_charters.rs`:
- [SUGGESTION] packages/wasm-sdk/src/moderation_charters.rs:180-196: Add tests for the new approval-count binding and its numeric arguments
  The new binding validates two JavaScript numbers before converting them to u16, but neither it nor the extracted u16_argument helper has test coverage. The new dash-sdk test exercises the seat-based arithmetic, while the existing wasm-sdk moderation-charter tests cover page queries, not this method. Add local tests covering fractional, negative, oversized, NaN and infinite arguments, accepted boundaries 0 and 65535, and a valid binding call that preserves the threshold after an elected member is removed. The validation is currently correct; these tests would pin the new API's documented rejection behavior independently of the SDK arithmetic. The pure numeric helper can be tested on the host without introducing JsValue operations, and binding behavior can use the crate's existing wasm32 test harness.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Consolidate numeric-argument validation across wasm crates — Routine adjacent cleanup outside the PR's scope. The cited helpers intentionally have different input types and accepted-input contracts, and the new helper preserves the previous seats() validation. No concrete correctness problem warrants retaining a cross-crate consolidation follow-up.
    • Follow-up: Consider creating a separate issue or author/maintainer-requested PR for this.

Comment on lines +180 to 196
pub fn settled_deletion_approvals_needed(
&self,
approvals: f64,
#[wasm_bindgen(js_name = "maxAddedModerators")] max_added_moderators: f64,
) -> Result<u32, WasmSdkError> {
// The count does not depend on whether the leader must be among the approvals
let rule = SettledDeletionRule {
leader: false,
approvals: u16_argument(approvals, "approvals")?,
};
let needed = self.0.settled_deletion_approvals_needed(
&rule,
u16_argument(max_added_moderators, "maxAddedModerators")?,
);
// At most `approvals`, a u16
Ok(needed as u32)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟡 Suggestion: Add tests for the new approval-count binding and its numeric arguments

The new binding validates two JavaScript numbers before converting them to u16, but neither it nor the extracted u16_argument helper has test coverage. The new dash-sdk test exercises the seat-based arithmetic, while the existing wasm-sdk moderation-charter tests cover page queries, not this method. Add local tests covering fractional, negative, oversized, NaN and infinite arguments, accepted boundaries 0 and 65535, and a valid binding call that preserves the threshold after an elected member is removed. The validation is currently correct; these tests would pin the new API's documented rejection behavior independently of the SDK arithmetic. The pure numeric helper can be tested on the host without introducing JsValue operations, and binding behavior can use the crate's existing wasm32 test harness.

source: glm-5.3-flash (phase1-reviewer: general, rust-quality)

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants