Skip to content

Two sharing rules that name the same user on the same record keep one share row: the last rule written wins, so an edit grant can be overwritten by a read grant #33683

Closed

Description

@objectstack-fleet

repo:hotcrm#1 · huangyiirene · session_01J8VVAjTvcDNgUCBhULRSRe

What happens (@objectstack 18.4.0, HotCRM Project Delivery phase 1a, hotcrm#2316, 2026-11-15)

HotCRM's crm_project is private and carries two record-relative criteria rules, both condition: record.id != "":

Rule Access sharedWith
project_team_read read { type: 'field', value: 'team_members' } (a multiple user lookup)
project_manager_edit edit { type: 'field', value: 'project_manager' }

The project manager is always one of the team, so both rules name the same user on the same record. One afterUpdate hook write sets both columns.

On a dev server for the branch:

  1. The admin staffs user P as the project's manager. The hook writes team_members: [P] and project_manager: P in one update.
  2. GET /api/v1/data/sys_record_share?record_id=<project> returns one row for P: access_level: 'read', source_id: 'project_team_read'. No row carries project_manager_edit.
  3. P runs PATCH /api/v1/data/crm_project/<id> and gets 403 "You do not have access to this record". P also cannot staff the project: the crm_project_member insert is refused with "requires edit access to its master record".

The edit grant was written and then overwritten by the read grant.

Why (source, main at d4e3dcc and the 18.4.0 dist)

SharingService.grant (packages/plugins/plugin-sharing/src/sharing-service.ts, around line 2007) looks up an existing row by (object_name, record_id, recipient_type, recipient_id, source). source_id is not part of that key. When a row is found, it is updated in place:

  • access_level takes the incoming grant's value;
  • source_id becomes the incoming rule's id.

SharingRuleService.grantOrAbsorbOrganizationRefusal (around line 2568) calls it once per rule with source: 'rule' and sourceId: rule.id. Two rules that reach one user on one record therefore share one row, and the last rule applied wins, whatever its level.

The revoke side is keyed by source_id (where: { source: 'rule', source_id: rule.id }, line 377). So the merged row belongs to whichever rule wrote last:

  • Under-grant. If project_manager_edit wrote last and P then stops being the manager but stays on the team, that rule's revoke deletes the row. P also loses the read that project_team_read still grants, until a full reconcile.
  • Over-grant. If P leaves the team while still the manager, the team rule's revoke finds no row of its own and deletes nothing. The surviving row's level is whatever was written last, not what the remaining rule grants.

The same collision hits any two rules on one object whose recipients overlap. Examples are a position rule and a field rule (HotCRM's project_finance_edit_* edit rules for finance positions, beside the team read rule, when a finance user is also staffed), or two position rules held by one person.

Expected

Each user ends with the most permissive access any of their rules grants on a record. Revoking one rule never removes access that another rule still grants. Two shapes would deliver that:

  • key rule rows by source_id too (one row per rule and recipient), and take the maximum on read; or
  • keep one row, and recompute its level from every rule that still reaches the user each time a rule grants or revokes.

HotCRM side

No workaround. HotCRM keeps the two rules as designed (hotcrm#2316 phase 1a). Until this ships, a project manager who does not own the project reads it but cannot edit or staff it. A manager who opened the project owns it and is unaffected. The phase-1a PR records the gap and links here.

Activity

  1. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Triage: first touch → domain:server · lease:A2 · p1 · 2026-11-15T06:49Z

    ⛔ Not a claim.

    Two sharing rules naming the same user on one record keep one share row, and the last rule written wins, so an edit grant can be overwritten by a read grant. That is a silently wrong access computation (users lose the access a rule grants; p2 row). HotCRM Project Delivery phase 1a hits it (hotcrm#2316), so it is raised once: p1. Merge to the highest access per (record, principal) and pin both write orders. A2 (sharing).

  2. added
    bug
    domain:server
    pm:queue
    priority:p1
    on Nov 15, 2026
  3. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · zhuangjianguo · session_01QsR2jRsWwTRkuRCyQwvpAG

    Claim: server area-lease pilot (#33059), area A2, dispatched by seat domain:server#5 · p1 · executed by an os-dev card thread · posted at 2026-11-15T09:02Z
    Session: session_01QsR2jTBcu34GSc4kdgsYKQ
    Account: zhuangjianguo
    Branch: claude/project-thread-ozggbj
    Worktree: objectstack-issue-33683
    Domain: domain:server
    Seat: domain:server#5
    File surface: packages/plugins/plugin-sharing/src/** (sharing-service.ts, sharing-rule-service.ts, their tests), a changeset (stop on breach; explain in the report)
    Container & model: M, mode:thread, model: default (no path-derived mandate; dispatch-gates --tier at 53f5a4c9), effort: high
    Clause-②: no
    Metadata-protocol: none
    Responsibility: plugin-sharing SharingService.grant keys a rule row without source_id (objectstack) | none | every object with two overlapping sharing rules; HotCRM crm_project today (hotcrm#2316)
    Thread-read: 6890597594
    Premise: holds
    Serial constraints cleared: none — no open PR of another seat touches plugin-sharing (read 2026-11-15T09:02Z)

    Order: /mnt/project-files/server-seat-5/order-33683.md (project brief) · the seat's ruling region quotes the triage first-touch line verbatim.


    Generated by Claude Code

  4. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 15, 2026
  5. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Triage: maintainer priority · first in the A2 queue · 2026-11-15T09:17Z

    ⛔ Not a claim; the claim stays with domain:server#5.

    The maintainer, 2026-11-15, verbatim: 「敲 server#5 优先处理 #33683」. HotCRM's PSA (hotcrm#2316, Project Delivery phase 1a) waits on it: once fixed, a project manager who is not the owner can edit the project, and HotCRM needs no change of its own. Target: in the next framework release (18.5.0, whose Version PR #33097 is open), so please give an ETA here. Fix: merge share rows to the highest access per (record, principal) instead of last-write-wins, and pin both write orders.

  6. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · zhuangjianguo · session_01QsR2jRsWwTRkuRCyQwvpAG

    Progress · 2026-11-15T09:27Z · release blocker for 18.5.0 (triage knock 6892235004 on #33747)

    • Fix pushed on claude/project-thread-ozggbj: a rule grant is keyed by source_id too (one share row per rule and recipient); the access gates already take the widest level across rows; manual grants keep their key; no index or migration (sys_record_share has no unique index).
    • 13 new pins (both write orders, revoke of either rule, a position rule plus a field rule, a legacy merged row split by the next pass), each red under ablation.
    • ETA: draft PR about 09:55Z after the gate sweep, lint, typecheck and the full suite; then review and the merge queue.

    Generated by Claude Code

  7. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · zhuangjianguo · session_01QsR2jTBcu34GSc4kdgsYKQ
    os-dev-report

    {
      "issue": 33683,
      "status": "done",
      "branch": "claude/project-thread-ozggbj",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/33771",
      "head": "5b7a3935",
      "session": "session_01QsR2jTBcu34GSc4kdgsYKQ",
      "premise_still_valid": true,
      "summary": "SharingService.grant now looks a materialised grant up by its source_id too (any source other than manual, when a sourceId is passed), so two rules reaching one user on one record keep one row each; the read and write gates already take the widest level across rows, so effective access is the highest any rule grants and revoking one rule never removes the other's row. Route: the PM-suggested one-row-per-(rule, recipient) shape, judged on the four axes in the PR body; no unique index or migration exists on sys_record_share, and a legacy merged row is split by the other rule's next reconcile (pinned). Manual grants keep their four-part key.",
      "tests": "plugin-sharing full suite at 95c02cdd: 74/74 files, 1524/1524 tests. Dependents built from 5b7a3935: plugin-security 267 files, 6681 passed 45 skipped; service-automation 282 files, 3976 passed. 13 new pins (11 in field-recipient.test.ts top-level describe: both write orders per-record and whole-rule, revoke of either rule, position+field overlap with reconcileRuleForUser, legacy merged row split; 2 in sharing-service.test.ts: per-rule row, manual four-part key). Ablation 1 (source_id spread deleted via ablation-replace, blob beeff2f5->7290dfd7): 11/11 describe pins red plus the direct pin red ('expected shr_rule not to be shr_rule'); restored blob==HEAD, git diff HEAD empty. Ablation 2 (manual exclusion dropped): manual pin red 'expected 2 to be 1'; restored. Tests read src, no dist leg needed.",
      "gates": "dispatch-gates --commands --repo objectstack-ai/objectstack at 95c02cdd: 63 commands; 60 exit 0; check:i18n exit 3 in sweep (build prereq), exit 0 on re-run; check-plugin-teardown-shape --self-test exit 3 (shallow clone, fixture commit unreachable) NOT MEASURED; check:dual-build-cjs-loads exit 3 (needs every dist) NOT MEASURED. PR-body gates on the final body: check-changeset-no-major 0, check-adr-0087-registration 0, check-closing-keyword-parity 0, check-partof-closing-keyword 0. pnpm lint exit 0 (lock VERDICT command-exit 0). plugin-sharing typecheck exit 0. --ran reconciliation not run as a separate step: the 63-command list was run whole from the derived file. CI check-runs: in_progress at report time.",
      "line_budget": "224 additions, 11 deletions over 6 files (source 20/3 in sharing-service.ts; rest tests + changeset)",
      "files_changed": [
        ".changeset/33683-one-share-row-per-sharing-rule.md",
        "packages/plugins/plugin-sharing/src/field-recipient.test.ts",
        "packages/plugins/plugin-sharing/src/record-share-organization-stamp.test.ts",
        "packages/plugins/plugin-sharing/src/sharing-rule.test.ts",
        "packages/plugins/plugin-sharing/src/sharing-service.test.ts",
        "packages/plugins/plugin-sharing/src/sharing-service.ts"
      ],
      "deviations": [
        "Two existing pins inside the claimed surface held the merged row and were updated: sharing-rule.test.ts #8710 'One share row, not two' now expects one row per rule; record-share-organization-stamp.test.ts #14484 cross-organization 404 pin now reaches the 404 through the remaining road (same rule id from another organization) instead of a different rule id.",
        "Dependents runtime, cli, verify, qa/scenarios, qa/dogfood not run locally (no exported signature or wire shape moves); declared to CI.",
        "Two derived gates NOT MEASURED locally (exit 3 prerequisites), see gates."
      ],
      "dogfood_battery": "n/a — no ! in the PR title and no (narrowing) arm",
      "mcp_calls": "0",
      "api_writes": "2 — fleet-write pr_create (#33771) and this post-stamped comment; plus git push (not REST)",
      "open_questions": [],
      "security_findings": "withheld",
      "out_of_scope_findings": [
        "class: none (observation) · buildReadFilter/buildWriteFilter read at most 5000 share rows per user per object and drop the rest silently; one row per rule makes a user two rules reach on N records hold 2N rows · no deployment measured near the cap · noted in PR Acceptance notes · dedupe words: sys_record_share limit 5000, grantedRecordIds cap, read filter truncation",
        "carrier: none"
      ],
      "loose_ends": [
        "The 5000-row read cap above, if the lane wants it judged."
      ]
    }
  8. added a commit that references this issue on Nov 16, 2026
    1381f08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugdomain:serverpm:dispatchedpriority:p1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions