# Roblox Profile Lifecycle And Session Ownership

Design server-authoritative player profile loading, exclusive session ownership, lease renewal, and safe release to prevent simultaneous writable profile sessions and stale-server overwrites.

**Canonical URL:** https://skillshunter.net/skills/discovered-257d2dbf081b3af2f7c65759297863e9aa3a473431c85d6f

**JSON URL:** https://skillshunter.net/api/public/v1/skills/discovered-257d2dbf081b3af2f7c65759297863e9aa3a473431c85d6f

**Markdown URL:** https://skillshunter.net/skills/discovered-257d2dbf081b3af2f7c65759297863e9aa3a473431c85d6f.md

**Instructions download URL:** https://skillshunter.net/skills/discovered-257d2dbf081b3af2f7c65759297863e9aa3a473431c85d6f/download

**Category:** Software & Development

**Source URL:** https://github.com/Aziz24666/Codex_Roblox_skills/blob/eb2be117f63d6442c0f9b6d9d38bbdd7adf9374c/v40/skills/roblox-profile-lifecycle-and-session-ownership/SKILL.md

**Source commit:** eb2be117f63d6442c0f9b6d9d38bbdd7adf9374c

**Listing approved at:** 2026-11-30

**Created at:** 2026-11-29T11:08:36.000000Z

**Updated at:** 2026-11-30T06:52:12.000000Z

## Catalog information

The following descriptions are catalog information. Listing approval does not mean the skill has been tested or is safe for every environment.

### Editor's note

Implement a unique server-session token, not a client-provided identifier. Before saving or releasing, verify the owner token still matches to prevent stale server overwrites. Use a custom wrapper or adapt Roblox's `SessionLockedDataStoreWrapper` with thorough testing.

### When to use it

- Implementing server-authoritative player profile loading with lease renewal
- Designing exclusive session ownership to prevent simultaneous writes
- Creating a safe release mechanism for profile sessions
- Testing race conditions and lease expiration policies

## Skill instructions

---
name: roblox-profile-lifecycle-and-session-ownership
description: Design server-authoritative player profile loading, exclusive session ownership, lease renewal, and safe release.
---

# Roblox profile lifecycle and session ownership

## Goal
Prevent simultaneous writable profile sessions, stale-server overwrites, and unsafe loading after an ambiguous lock result.

## Lifecycle
1. Review Roblox's current `DataStoreWrapper` and `SessionLockedDataStoreWrapper` reference implementation first. It demonstrates per-key request ordering/retries and session locks. The Creator Hub warns that its sample has not been proven at scale; do not copy it unchanged. Adapt and test it thoroughly, or implement the same ownership invariants in a reviewed custom wrapper.
2. Define one profile owner service and one well-defined profile state machine: unloaded, loading, active, saving, releasing, failed.
3. Acquire the session lease through an UpdateAsync transform using a unique owner token and bounded expiry.
4. Never make a profile writable unless both its data and session ownership are confirmed.
5. On contention, wait with a bounded policy or fail closed. Do not load a second copy and continue saving.
6. Refresh the lease with a non-yielding transform that verifies the current owner token.
7. Before save/release, verify the owner token still matches. A stale server must never clear or overwrite a newer session.
8. On PlayerRemoving, save and release only that session's lock.
9. On BindToClose, flush active profiles concurrently within a bounded shutdown budget and stop accepting new mutations.

## Failure cases
Specify behavior for timeouts, ambiguous reads, expired leases, server crashes, duplicate joins, teleports, and lock-renewal failures. If ownership becomes uncertain, freeze mutations and use a safe recovery flow instead of guessing.

## Required deliverables
Profile state machine, lock record contract, ownership invariants, stale lease policy, retry policy, reconnect behavior, and race-condition test matrix.

## Non-negotiable safeguards
- Server owns all persistent mutations.
- Use a unique server-session token, not a client-provided identifier.
- Release only a lock owned by the current session.
- Keep per-key writes serialized.
- Test with multiple servers in a separate test experience.

