RolebookDocs

What happens when

Scenario by scenario, what Rolebook does when an answer is lost, two writers collide, a receiver is down or the console and your application disagree.

This page walks through the situations that matter when something goes wrong in the middle of a change: a lost answer, a crash, two writers at once, a receiver that is down. Each entry says what Rolebook does and what is left for you to do. It restates the reference pages and adds nothing to them; each section links to the page with the exact rules and their limits.

Three principles run through every table:

  • A committed change is not applied a second time. While its idempotency record is kept, a retry of the same command answers from that record. The connector calls Sharing at most once for each change the console sends.
  • An unproven outcome is reported as unknown. When Rolebook cannot tell whether a change committed, it says so instead of guessing either way.
  • A refused sharing change or role set writes no access state. Memberships and custom roles either change as a whole or stay as they were. Bookkeeping can remain: the connector keeps a record of every command it refused, and a console policy publish refused part-way keeps its reserved number and any saved draft.

A sharing change whose answer was lost

For code that calls execute itself. See Idempotency and Looking up an outcome. The connector builds on the same idempotency record and lookupExecution, but never calls execute a second time; its own table is further down.

SituationWhat Rolebook doesWhat you do
Your process stopped, or gave up waiting, after calling execute.The change committed together with its idempotency record, in one transaction, or has not committed. A call you stopped waiting for may still be running and commit later.Retry the same command with the same idempotencyKey, or call lookupExecution with the same command to read the outcome without running anything.
You retry the same command with the same key.While the record is kept, it answers ALREADY_APPLIED with the revision of the original commit, and nothing is applied again. On createSharing() the retry is authorized against current state first, so an actor that lost access since can be refused (with two exceptions for commands that remove the actor’s own access). On createVersionedSharing() the actor’s own committed key replays before authorization.Treat ALREADY_APPLIED as success.
You reuse the key for a different command, or another actor uses it.CONFLICT, without retries, once the command is otherwise authorized.Use a new key for a new command.
lookupExecution answers committed.The record proves that exact command committed. The result is what a replay would answer.Treat it as success.
lookupExecution answers not_found.Nothing is proven. This is also the answer after the record was pruned by retention, after the resource was deleted or moved to another tenant, and while the command may still be running.Read the resource’s current access, and send the command again if it is still needed.
lookupExecution answers different_command.The key holds another command now, or this command by another actor. It does not prove your command never committed: its record may have been pruned and the key reused. An actor without access to the resource gets not_found instead, so the lookup does not reveal that the resource exists.Do not reuse that key. Read the resource’s current access.
lookupExecution answers refused.Nothing was read. The command is malformed, the resource type is unknown, the actor is not a tenant member, the policy could not be loaded, or the tenant’s hierarchy enrollment has started (HIERARCHY_UNAVAILABLE).Fix the cause. For a tenant whose enrollment has started, the outcome cannot be read without executing: a retry with the same key replays a commit, but applies the command if it had not committed.
The retry arrives after the record was pruned.It runs as a new command, authorized against current state.Keep retention longer than every client’s retry window. See Retention.

lookupExecution is part of TenantSharing; the HTTP API does not expose it.

Two writers change the same resource

See Conflict retries.

SituationWhat Rolebook doesWhat you do
Another change commits while yours is being authorized.execute re-reads, re-authorizes and tries again, up to mutationRetries more times, then answers CONFLICT.Retry later, or show the current state.
You showed someone the access list, and it changed before they confirmed.With expectedSharingRevision, the command answers SHARING_REVISION_CHANGED instead of applying to a state nobody reviewed.Read the access again and ask again.
A member is revoked while a change of theirs is in flight.A mutation is conditional on the sharing revision it was authorized against. The revocation moves that revision, so their change is authorized again against the new state and refused.Nothing.

Custom roles, one at a time or as a set

See Custom roles and CustomRoleAdministration.

SituationWhat Rolebook doesWhat you do
You replace a tenant’s roles with customRoles.set.Every role gets the checks a single define makes, the limits are counted on the result, roles the set does not name are removed, and everything commits in one transaction with one revision bump and one audit event per change.Nothing.
One role in the set is invalid.The whole set is refused. Nothing is written.Fix that role and send the set again.
The set is already in place.UNCHANGED. Nothing is written, and no fence is held: a change committed right after that read is not reported.Nothing.
A define, remove or another set commits first.REVISION_CONFLICT. Nothing is written.List the roles again and resend against the new revision.
A policy is published while the set is in flight.GENERATION_CONFLICT. Nothing is written. Pass expectedGeneration from your listing to get this answer even when the publish went through another instance of your application.List again and resend.
A stored role row does not decode.Every set is refused with CUSTOM_ROLE_UNREADABLE, naming the row, because Rolebook cannot tell whether that role is live or retired.Repair the row in the database.
A role’s template was narrowed by a later policy.The role’s status becomes exceeds_template and it is left out of evaluation. Rolebook does not clamp the role.Redefine the role within its template, or remove it.
A membership names a role that is no longer available.The binding fails closed. New grants, changes and invitations to that role are ROLE_NOT_ALLOWED; accepting an invitation to it is INVITATION_UNAVAILABLE.Only the owner’s recovery path can change or revoke that membership.
A role is removed, then defined again under the same name.CUSTOM_ROLE_NAME_RETIRED: a removed name cannot be reused.Choose another name.
A set at the 32-role limit removes one role and adds another.It applies: the limit is counted on the result.Nothing.

A policy is published

See Versioned sharing.

SituationWhat Rolebook doesWhat you do
A new version is published while changes are running.With fenced adapters (fencePolicy), every mutation re-reads the active generation and the tenant’s custom-role revision inside its transaction. A change that started under the old policy answers POLICY_GENERATION_CHANGED or TENANT_ROLES_CHANGED and writes nothing.Send the change again.
Two publishes race.publish activates a version only if the generation still matches. One wins; the other answers GENERATION_CONFLICT.Publish again from the new active version if it is still wanted.
Another instance has not seen the new version yet.A read there may decide under the previous generation for at most refreshIntervalMs plus its own duration. Writes are not affected: the fence reads the stored generation in the write’s transaction.Choose a refresh interval you can accept. There is no strong-read mode.
An instance is told its generation is no longer active.It decides nothing under that generation, or an older one, until a fresh read of the active pointer confirms it or installs a later one. The refresh interval does not apply.Nothing.
The policy store is unreachable.A cached policy serves until maxStalenessMs. After that, reads reject with PolicyUnavailableError and execute answers POLICY_UNAVAILABLE.Restore the store.
The active pointer goes backwards, changes digest at the same generation, or does not decode.The failure is sticky for that instance (POINTER_REGRESSED, POINTER_DIGEST_MISMATCH, POINTER_INVALID, VERSION_INVALID).Restoring an older generation requires restarting every instance.
One process still runs an unfenced adapter.It can commit under a superseded policy, and Rolebook cannot detect it.Run fenced adapters in every process that writes sharing state before the first publish.

The console sends a change through the connector

See Connect to Rolebook Console, especially its Failure behaviour and Limits. The last column says what the console is expected to do with each answer.

SituationWhat the connector doesWhat the console does
The console is unreachable.Your application keeps working: local reads and writes do not go through the connector. It reconnects with a growing delay, up to 60 seconds. Nothing is applied while disconnected.Delivers again after the connection is back.
The console refuses the connection (wrong key, wrong environment, replaced, wrong protocol version).It stops reconnecting and emits halted.Nothing: no command reaches the connector until it is started again.
A command has a bad signature, another environment, or an unknown key.It is refused before anything is recorded.The command fails.
A change that was never started arrives after its signed expiry.COMMAND_EXPIRED. It never ran.Issues a new command if the change is still wanted.
A change whose Sharing call was already started or finished is delivered again after its expiry.It answers from the recorded outcome (ALREADY_APPLIED, the recorded refusal, Outcome unknown or BUSY), not COMMAND_EXPIRED.Records that outcome.
The console is not enabled for that tenant.TENANT_NOT_ENABLED.Nothing until your application enables the tenant.
The same change is delivered twice.Sharing is called at most once per change. The exact envelope that delivered it gets APPLIED again from the same process within 10 minutes; any other delivery gets ALREADY_APPLIED. A duplicate that arrives while the first is still running answers BUSY.Records the change as applied once.
The same command ID arrives with different parameters.DUPLICATE_MISMATCH.The command fails.
The connection drops after Sharing committed, before the answer was sent.A redelivery answers from the cached result or the recorded outcome: APPLIED or ALREADY_APPLIED.Redelivers the same command and records the answer.
The Sharing call fails.The change is recorded unknown and Sharing’s own record is read at once: if it proves the commit, the answer is ALREADY_APPLIED; otherwise Outcome unknown. The change is never run again to find out.Redelivers the same command ID, which reads Sharing’s record again. If it stays unknown, the membership is checked and a new command issued if still needed.
The process stops in the middle of the Sharing call.Redeliveries answer BUSY while the call’s owner could still be waiting. A sweep then records the change unknown, and from then each delivery reads Sharing’s record as above.Retries, then as above.
The Sharing call takes longer than commandTimeoutMs.The connector stops waiting and answers Outcome unknown. The call can still commit, even after a change with a higher sequence ran; a late commit is recorded and replaces unknown.As for a failed call.
An outcome can never be proven.It stays unknown when the record was pruned, the resource was deleted or moved to another tenant, the key holds another command, the console principal changed or no longer resolves, the tenant’s hierarchy enrollment has started, or Sharing has no lookupExecution. command.lookup reads only the connector’s own receipts and never says a change did not commit.Checks the membership and issues a new command with a new ID if the change is still needed.
Sharing refuses the change (not allowed, role unknown, and so on).The refusal is recorded and every later delivery gets the same refusal.A new attempt is a new command ID.
Sharing refuses for a reason that would pass on a retry (POLICY_GENERATION_CHANGED, TENANT_ROLES_CHANGED, POLICY_UNAVAILABLE, HIERARCHY_UNAVAILABLE, DELEGATION_UNAVAILABLE).The answer is INTERNAL with that code as its message, and it is final for that command ID.Issues a new command ID to try again.
An earlier change has no final state yet.Later changes answer BUSY until it has one: a change starts only after every lower sequence has a final state.Retries.
Too many commands at once.Reads beyond 16 at a time answer BUSY. A connection that exceeds its pending limits is closed with code 4429.Retries; commands dropped with the closed connection are redelivered.
The tenant is disabled after a change committed.The commit stays recorded, but its result is not released: TENANT_NOT_ENABLED.Cannot confirm the change until the tenant is enabled again.
An invitation is issued and token export is off.UNSUPPORTED_COMMAND (reason INVITATION_TOKENS_NOT_EXPORTED), before anything is recorded. An invitation admitted by an instance with the option on answers BUSY with that reason on an instance with it off.Invitations are unavailable for that application.

The console publishes a policy or sets custom roles

These need authorizeAdministration in your application. Without it, the connector does not advertise either capability.

SituationWhat the connector doesWhat the console does
authorizeAdministration says no.UNSUPPORTED_COMMAND (reason NOT_AUTHORIZED). Nothing is published and no role is written. A policy refused part-way keeps its reserved number and, if it was already saved, its draft and audit row.The command fails.
The administration check times out or throws.BUSY for a timeout or a lost database race; otherwise INTERNAL, retryable.Retries.
The console sets a tenant’s roles.One customRoles.set call: all of it or none of it. Roles the console does not list stay exactly as they are.Records the set.
The role-set call fails or is given up on.Role set outcome unknown, retryable. Sharing applied all of it or none of it.Retries the same set.
The set committed but could not be recorded.Role set applied, not recorded, retryable. The retry finds the set in place and records it.Retries the same set.
A local role change lands after a set whose commit may have been lost.The retry cannot tell its own commit from the local change, so it answers STALE (ROLES_CHANGED) unless the set is exactly in place. The local change is never overwritten.Issues a new set revision.
An older set revision arrives after a newer one.STALE.Nothing: the newer one stands.
A local role change or policy publish commits between the connector’s read and its call.BUSY. Nothing is written.Retries the same set.
A role the console did not list is no longer valid under the active policy.The set is refused, naming the role.Lists that role (valid, or as unavailable so it is removed), or it is fixed locally.
Two executors run the same set revision and both are refused cleanly.Later retries of that set revision can answer STALE (ROLES_CHANGED) although nothing of it committed. It fails closed.Issues a new set revision.
A policy number below the active one, or below a reserved one, arrives.Below the recorded active number: STALE without details. Otherwise, below a reserved number: STALE (NEWER_POLICY). The older policy is never published, even if the newer one was only reserved.Nothing.
Another hash arrives under a reserved policy number.STALE (NUMBER_RESERVED).The command fails.
Another publish won the generation.STALE (GENERATION_CONFLICT). The publish never overwrites a policy published after its reservation.Publishes again if intended.
The publish call fails or is given up on.Outcome unknown.Retries the same command, which confirms the policy if it is active.
The policy was published but could not be recorded.Policy published, not recorded, retryable. The retry finds it active and records it.Retries the same publish.
A policy was published locally after the console’s.A repeat of the console’s publish answers STALE (POLICY_CHANGED).Publishes again if intended.
Your application’s schema says policySource: "code".POLICY_SOURCE_CODE.Console publishing is unavailable for that application.
Two connector versions run against one state store.Not supported: an older role set can be applied after a newer one. Stop the previous version’s processes before starting the new one.Nothing.

Audit copies

See Audit copies.

SituationWhat the connector does
An audit event names a tenant the console is not enabled for.It is quarantined and is not sent, also if the tenant is enabled later.
An event is sent and the acknowledgement is lost.It is sent again: delivery is at least once.

An access change is announced by webhook

See Access-change webhooks.

SituationWhat Rolebook doesWhat you do
A grant, role change, revocation, ownership transfer, or an invitation issued or accepted commits.At least one signed request is sent to each endpoint, after the transaction committed.Verify the signature and act on it.
An invitation is revoked, or a resource is initialized, deleted or moved.Nothing is sent: these audit actions have no webhook.Use the audit log for them.
A change is rolled back.Nothing is sent.Nothing.
A change was committed before the delivery migrations ran.It is never sent. Delivery starts with the first change committed after them.Nothing.
The receiver answers anything other than 2xx, redirects, times out or is unreachable.The delivery is retried with a growing delay: 1 s, 2 s, 4 s, up to 5 minutes, for 300 attempts by default, about a day.Fix the receiver.
The receiver processed a request but its acknowledgement was lost.The same request is sent again with the same rolebook-webhook-id.Drop duplicates by that ID.
A delivery runs out of attempts.It becomes a dead letter. Later changes of that resource wait behind it; other resources are not affected.List dead letters, then requeue one after fixing the receiver, or discardDeadLetter to skip that change for good.
Two changes to one resource commit close together.They are delivered one at a time, in commit order.Nothing.
Changes to different resources commit close together.They are delivered independently and can arrive in either order.Do not rely on an order across resources.
A worker crashes after claiming a delivery.The lease expires and the delivery is claimed again. Nothing is lost.Nothing.
A long-running or prepared transaction is open anywhere in the PostgreSQL cluster.Deliveries of every later change wait until it ends, so nothing can be skipped.Watch for old transactions.
The database was upgraded with pg_upgrade and the cluster’s identity changed.New changes are not queued (foreign-cluster); entries already queued are still delivered.Run adoptCluster().
The database was restored with pg_dump and pg_restore, or moved by logical replication.New changes are not queued (foreign-cluster); entries already queued are still delivered.Run rebaseline() after the restore and before the application writes anything.
An endpoint ID is reused for another tenant.The drain is refused. The first tenant’s changes are never sent to the other.Use one endpoint ID per tenant.