agentleFS
blushneybusiness-glitchblushneybusiness-glitch/roblox-omniskills/skills/rbx-data-sessionlock/SKILL.md

rbx-data-sessionlock

Skill0 starsChanged 3 months agoMITView on GitHub

The dupe firewall: session locking so exactly one server owns a player's save at a time, plus the two places it gets violated in practice — trades and shutdowns. Use when the user reports "items duped", "data rolled back", "saved on two servers", "coins vanish on rejoin", or when trading or teleporting touches saved data. Do not use for base save-system setup — load rbx-data-profilestore instead — or for the trade UI and scam flow — load rbx-trading-antiscam.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    After the async load, check the player is still in Players.

    line 49
  2. Distinctive:

    Never grant a trade result to an offline player by writing their key directly — that write fights their next session's lock.

    line 61

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

rbx-data-sessionlock

When to load

Any dupe or rollback report, any system where two servers could plausibly touch one save (trades, teleports, soft shutdowns, rejoin-fast exploits), and every review of a save system — no lock, no ship is rbx-data law.

The race the lock kills

  • t=0 — player leaves Server A; PlayerRemoving fires; A's save begins.
  • t=1 — player joins Server B before A's write lands; B loads the stale value.
  • t=2 — A's save completes with the newest data.
  • t=3 — B plays on stale data and eventually saves it, overwriting A's write.

Result: rolled-back progress — and if the player traded items away on A first, those items now exist twice. Exploiters trigger this on purpose by trading then rejoining fast.

How the lock works

The lock is a field inside the DataStore entry itself, written with UpdateAsync: the owning server's game.JobId plus a timestamp, refreshed by every 30-second auto-save. A second server loading the key sees a fresh lock and waits; a lock not refreshed for several cycles is treated as a crashed server and stolen. ProfileStore implements all of this: StartSessionAsync blocks until it owns the lock, and OnSessionEnd fires if another server steals it — your handler kicks the player ("Data loaded on another server — rejoin.") and drops every reference. The kick is not optional: a live session without its lock will still auto-save over the new owner.

Rules that keep the lock honest:

  • One writer path. Every mutation goes through the profile of the locked session. No side script calling SetAsync on the same key "just this once".
  • After the async load, check the player is still in Players; end the session if they left mid-load, or the lock leaks until steal-timeout.
  • Teleports: end the session (flushes the save, releases the lock) before TeleportAsync; the destination server's StartSessionAsync then waits the seconds until the release lands instead of stealing stale data. rbx-platform-teleport owns the flow.

Trades under the lock

A trade is a two-profile transaction. Law: both players' profiles session-locked on the same server, both mutations applied back-to-back in one synchronous block — remove from A, add to B, no yield between them — then one log line with both uuids (rbx-data-schema uuids exist for exactly this). If either player's profile is missing or released, the trade aborts whole. Never grant a trade result to an offline player by writing their key directly — that write fights their next session's lock. Queue it (ProfileStore GlobalUpdates or a pending-gifts key of its own) and apply it inside their next locked session.

BindToClose flush

Shutdown gives BindToClose callbacks at most 30 seconds, then the process dies mid-write. ProfileStore registers its own handler that ends every session. Raw implementations: save all players in parallel with task.spawn and wait on a counter — 50 sequential saves at 0.5–2 s each blows the window; parallel completes in the time of the slowest one. Branch for Studio (RunService:IsStudio() → task.wait(1) and return) so Stop doesn't hang, and remember Stop fires BindToClose but not PlayerRemoving — the flush must not depend on the latter.

Sharp edges

  • CRITICAL — Player saves with no lock at all: the race above is not rare; at 1,000 CCU it is dozens of rollbacks per day and a public dupe method. Fix: ProfileStore or a manual JobId lock — then verify with two Studio play sessions on one account.
  • CRITICAL — Writing to a key another live server has locked (offline gifting, admin grants, rollbacks): the owner's next auto-save erases your write. Fix: queue into the session, or wait for the lock to release (rbx-data-recovery for the rollback case).
  • HIGH — Missing kick-on-steal handler: after a steal both servers hold the player, both save, last writer wins at random. Fix: OnSessionEnd → kick, always.
  • HIGH — Sequential BindToClose saves: over 30 s with a full server; the tail of the loop simply never saves. Fix: task.spawn parallel + counter wait, 25 s hard cap.
  • MEDIUM — Lock-contention kick loops: a player rejoining fast gets "wait for lock" → kick → rejoin → wait, forever. Fix: let StartSessionAsync wait (it retries internally) rather than kicking on the first nil; kick only after the load definitively fails.

Load with

rbx-data-profilestore (the machinery), rbx-trading-antiscam — don't ask, include it whenever trades exist. rbx-platform-teleport (flush-before-teleport), rbx-data-recovery (when the dupe already happened), rbx-qa-scale (join/leave edge testing).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.