@rbxts/scribe 2.6.1 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -139,6 +139,18 @@ function Monetization.new(ctx: any)
139
139
  or function(userId: number, passId: number): boolean
140
140
  return MarketplaceService:UserOwnsGamePassAsync(userId, passId)
141
141
  end
142
+ -- An injected legacy reader overrides engine detection.
143
+ local getPassOwnership: ((player: Player, passId: number) -> any)? = options.GetPassOwnershipAsync
144
+ if getPassOwnership == nil and options.UserOwnsGamePassAsync == nil then
145
+ local found, method = pcall(function()
146
+ return (MarketplaceService :: any).GetPassOwnershipAsync
147
+ end)
148
+ if found and type(method) == "function" then
149
+ getPassOwnership = function(player: Player, passId: number): any
150
+ return (MarketplaceService :: any):GetPassOwnershipAsync(player, passId)
151
+ end
152
+ end
153
+ end
142
154
  local getPolicyInfo: (player: Player) -> any = options.GetPolicyInfoAsync
143
155
  or function(player: Player): any
144
156
  return (game:GetService("PolicyService") :: any):GetPolicyInfoForPlayerAsync(player)
@@ -150,7 +162,7 @@ function Monetization.new(ctx: any)
150
162
  Name: string,
151
163
  Id: number,
152
164
  Category: string?,
153
- Grant: ((data: any) -> ())?,
165
+ Grant: ((data: any, player: Player) -> ())?,
154
166
  Grants: string?,
155
167
  PaidRandom: boolean,
156
168
  Retired: boolean,
@@ -823,22 +835,31 @@ function Monetization.new(ctx: any)
823
835
  -- The ownership predicate: perk flag, cached pass ownership, or Roblox Plus. No DevMode
824
836
  -- warning and no entry lookup, because internal scans legitimately walk keys that were
825
837
  -- never registered.
826
- local function ownsInternal(player: Player, entry: any, key: string): boolean
838
+ local function ownership(player: Player, entry: any, key: string): (boolean, boolean, number?)
827
839
  local reserved = reservedRaw(entry.LiveData)
828
840
  if reserved.Perks[key] == true then
829
- return true
841
+ return true, false, nil
830
842
  end
831
843
  local ownsCache = entry.SessionStore[Template.SESSION_ROOT]
832
844
  ownsCache = if type(ownsCache) == "table" then ownsCache.OwnsCache else nil
833
- if type(ownsCache) == "table" and ownsCache[key] == true then
834
- return true
845
+ local cached = if type(ownsCache) == "table" then ownsCache[key] else nil
846
+ if cached == true then
847
+ return true, false, nil
835
848
  end
836
849
  if key == "RobloxPlus" then
837
850
  -- Coerce: the property is nil on a player object that predates it, and a nil
838
851
  -- would read as "changed" against a false baseline on every ownership scan.
839
- return player.HasRobloxSubscription == true
852
+ return player.HasRobloxSubscription == true, false, nil
840
853
  end
841
- return false
854
+ if type(cached) == "number" then
855
+ return true, true, if cached > 0 then cached else nil
856
+ end
857
+ return false, false, nil
858
+ end
859
+
860
+ local function ownsOutright(entry: any, key: string): boolean
861
+ local owned, trial = ownership(entry.Player, entry, key)
862
+ return owned and not trial
842
863
  end
843
864
 
844
865
  -- Paid random items. The policy is per session, read once off the join path;
@@ -911,7 +932,17 @@ function Monetization.new(ctx: any)
911
932
  if not entry or entry.State ~= "Ready" or not entry.LiveData then
912
933
  return false
913
934
  end
914
- return ownsInternal(player, entry, key)
935
+ return (ownership(player, entry, key))
936
+ end
937
+
938
+ function self.GetTrial(player: Player, key: string): { EndsAt: number? }?
939
+ checkOwnsKey(key, "GetTrial")
940
+ local entry = ctx.Persistence.EntryFor(player)
941
+ if not entry or entry.State ~= "Ready" or not entry.LiveData then
942
+ return nil
943
+ end
944
+ local _, trial, trialEnds = ownership(player, entry, key)
945
+ return if trial then { EndsAt = trialEnds } else nil
915
946
  end
916
947
 
917
948
  -- One function behind both the query and the prompt, so they cannot disagree.
@@ -926,7 +957,7 @@ function Monetization.new(ctx: any)
926
957
  end
927
958
  end
928
959
  local ownedKey = if pass then name else product.Grants
929
- if ownedKey ~= nil and self.Owns(entry.Player, ownedKey) then
960
+ if ownedKey ~= nil and ownsOutright(entry, ownedKey) then
930
961
  return "owned"
931
962
  end
932
963
  return "purchasable"
@@ -947,14 +978,179 @@ function Monetization.new(ctx: any)
947
978
  end
948
979
  end
949
980
 
950
- -- Ownership only gains during a session, so a late answer must not clear a confirmed pass.
951
- local function foldOwnsCache(entry: any, key: string, owned: boolean): boolean
981
+ -- Pass ownership ----------------------------------------------------------------
982
+
983
+ -- Poll unknown ends every minute and recheck known ends within five minutes.
984
+ local TRIAL_POLL = 60
985
+ local TRIAL_RECHECK = 300
986
+
987
+ -- Normalize reported ends to Unix seconds. Zero means unknown.
988
+ local function trialEnd(value: any): number
989
+ if type(value) == "string" then
990
+ local parsed, at = pcall(DateTime.fromIsoDate, value)
991
+ value = if parsed then at else nil
992
+ end
993
+ if typeof(value) == "DateTime" then
994
+ value = value.UnixTimestamp
995
+ end
996
+ if type(value) ~= "number" or value ~= value or value <= 0 or value == math.huge then
997
+ return 0
998
+ end
999
+ -- Current Unix millisecond timestamps exceed 1e11.
1000
+ return if value > 1e11 then value / 1000 else value
1001
+ end
1002
+
1003
+ local passOwnershipAnswered = false
1004
+ local passOwnershipWarned = false
1005
+
1006
+ -- Returns (purchased, trialEnd). A trial with an unknown end uses 0.
1007
+ local function readPass(player: Player, userId: number, passId: number): (boolean, number?)
1008
+ if getPassOwnership == nil then
1009
+ return userOwnsGamePass(userId, passId) == true, nil
1010
+ end
1011
+ local ok, info = pcall(getPassOwnership, player, passId)
1012
+ if ok and type(info) == "table" and (type(info.Owned) == "boolean" or type(info.Active) == "boolean") then
1013
+ passOwnershipAnswered = true
1014
+ if info.Owned == true then
1015
+ return true, nil
1016
+ end
1017
+ return false, if info.Active == true then trialEnd(info.EndTime) else nil
1018
+ end
1019
+ if passOwnershipAnswered then
1020
+ error(if ok then "GetPassOwnershipAsync returned no ownership" else info, 0)
1021
+ end
1022
+ -- Fall back only until the first detailed response. Legacy reads conflate trials and purchases.
1023
+ local owned = userOwnsGamePass(userId, passId) == true
1024
+ if owned and not passOwnershipWarned then
1025
+ passOwnershipWarned = true
1026
+ Log.Warn(
1027
+ "Monetization",
1028
+ "PASS_TRIAL_READ_FAIL",
1029
+ `GetPassOwnershipAsync has not answered ({tostring(info)}), so pass ownership is read without `
1030
+ .. "free-trial detail and a trial counts as a purchase",
1031
+ { Player = player, PassId = passId }
1032
+ )
1033
+ end
1034
+ return owned, nil
1035
+ end
1036
+
1037
+ local passAsked = 0
1038
+
1039
+ local function passState(entry: any, name: string): { Seen: number, Watch: number? }
1040
+ local states = entry.PassStates
1041
+ if states == nil then
1042
+ states = {}
1043
+ entry.PassStates = states
1044
+ end
1045
+ local state = states[name]
1046
+ if state == nil then
1047
+ state = { Seen = 0 }
1048
+ states[name] = state
1049
+ end
1050
+ return state
1051
+ end
1052
+
1053
+ local resolvePass: (entry: any, name: string, quiet: boolean?) -> (boolean, boolean)
1054
+
1055
+ -- Roblox sends no expiry event. Recheck even if the reported end is still far away.
1056
+ local function watchTrial(entry: any, name: string, trialEnds: number)
1057
+ local state = passState(entry, name)
1058
+ local left = trialEnds - Clock.Now()
1059
+ local delay = if trialEnds > 0 and left > 0 then math.min(left + 1, TRIAL_RECHECK) else TRIAL_POLL
1060
+ passAsked += 1
1061
+ local token = passAsked
1062
+ state.Watch = token
1063
+ local function onTrial(): boolean
1064
+ return not promptStopped
1065
+ and not entry.TornDown
1066
+ and entry.Tree ~= nil
1067
+ and not entry.Tree.Dead
1068
+ and type(sessionAcc(entry).OwnsCache.Child(name).Get()) == "number"
1069
+ end
1070
+ Clock.Delay(delay, function()
1071
+ -- A superseded Clock.Delay still runs.
1072
+ if state.Watch ~= token then
1073
+ return
1074
+ end
1075
+ state.Watch = nil
1076
+ if not onTrial() then
1077
+ return
1078
+ end
1079
+ -- Keep trial access on failure and retry.
1080
+ if not resolvePass(entry, name) and state.Watch == nil and onTrial() then
1081
+ watchTrial(entry, name, 0)
1082
+ end
1083
+ end)
1084
+ end
1085
+
1086
+ -- A confirmed purchase wins for the session. For trials, the latest request wins.
1087
+ local function applyPass(entry: any, name: string, asked: number, owned: boolean, trialEnds: number?): boolean
952
1088
  if not entry.Tree or entry.Tree.Dead then
953
- return owned
1089
+ return owned or trialEnds ~= nil
1090
+ end
1091
+ local cache = sessionAcc(entry).OwnsCache.Child(name)
1092
+ local held = cache.Get()
1093
+ if owned or held == true then
1094
+ cache.Set(true)
1095
+ return true
1096
+ end
1097
+ local state = passState(entry, name)
1098
+ if asked < state.Seen then
1099
+ return held ~= nil
1100
+ end
1101
+ state.Seen = asked
1102
+ if trialEnds ~= nil and (trialEnds ~= held or state.Watch == nil) then
1103
+ watchTrial(entry, name, trialEnds)
1104
+ end
1105
+ if trialEnds ~= held then
1106
+ if held == nil then
1107
+ Metrics.Add("PassTrialsStarted")
1108
+ Log.Info("Monetization", "PASS_TRIAL_STARTED", `pass "{name}" is on free trial`, {
1109
+ Player = entry.Player,
1110
+ Pass = name,
1111
+ EndsAt = trialEnds,
1112
+ })
1113
+ elseif trialEnds == nil then
1114
+ Metrics.Add("PassTrialsEnded")
1115
+ Log.Info("Monetization", "PASS_TRIAL_ENDED", `the free trial of pass "{name}" ended`, {
1116
+ Player = entry.Player,
1117
+ Pass = name,
1118
+ })
1119
+ end
1120
+ -- Write last because listeners can recheck ownership.
1121
+ cache.Set(trialEnds)
1122
+ end
1123
+ return trialEnds ~= nil
1124
+ end
1125
+
1126
+ -- Returns (ok, hasAccess). A failed check leaves the cache intact.
1127
+ function resolvePass(entry: any, name: string, quiet: boolean?): (boolean, boolean)
1128
+ local pass = passesByName[name]
1129
+ passAsked += 1
1130
+ local asked = passAsked
1131
+ local ok, owned, trialEnds = pcall(readPass, entry.Player, entry.UserId, pass.Id)
1132
+ if not ok then
1133
+ Metrics.Add("OwnershipCheckFailures")
1134
+ Log.Warn(
1135
+ "Monetization",
1136
+ "OWNERSHIP_CHECK_FAIL",
1137
+ tostring(owned),
1138
+ { Player = entry.Player, Pass = name, PassId = pass.Id }
1139
+ )
1140
+ return false, false
954
1141
  end
955
- local kept = owned or sessionAcc(entry).OwnsCache.Child(key).Get() == true
956
- setOwnsCache(entry, key, kept)
957
- return kept
1142
+ if entry.TornDown then
1143
+ return true, owned or trialEnds ~= nil
1144
+ end
1145
+ -- Include a late join read in the silent baseline for this pass only.
1146
+ if quiet then
1147
+ entry.OwnsQuiet = name
1148
+ end
1149
+ local owns = applyPass(entry, name, asked, owned, trialEnds)
1150
+ if quiet then
1151
+ entry.OwnsQuiet = nil
1152
+ end
1153
+ return true, owns
958
1154
  end
959
1155
 
960
1156
  -- Every key whose ownership is worth tracking: everything registered, plus whatever
@@ -992,20 +1188,18 @@ function Monetization.new(ctx: any)
992
1188
  entry.OwnsLast = last
993
1189
  end
994
1190
  local candidates = ownershipCandidates(entry)
995
- -- A key that went away still needs its false. ownershipCandidates is built from
996
- -- current state, so a perk revoked under a name outside the Perks registry is listed
997
- -- nowhere and its false would never fire. The baseline records what was last
998
- -- reported, so unioning it in is exactly the set that could still owe a transition,
999
- -- and it cannot grow without bound: a false fired here never fires again.
1191
+ -- Revoked unregistered perks disappear from the candidates. Scan their last
1192
+ -- reported state once more to deliver the loss of access.
1000
1193
  for key in last do
1001
1194
  candidates[key] = true
1002
1195
  end
1003
1196
  for key in candidates do
1004
- local owned = ownsInternal(player, entry, key)
1005
- if owned ~= (last[key] == true) then
1006
- last[key] = owned
1007
- if not silent then
1008
- ctx.Signals.OnOwnershipChanged:Fire(player, key, owned)
1197
+ local owned, trial = ownership(player, entry, key)
1198
+ local state = if trial then "trial" elseif owned then "owned" else nil
1199
+ if state ~= last[key] then
1200
+ last[key] = state
1201
+ if not silent and key ~= entry.OwnsQuiet then
1202
+ ctx.Signals.OnOwnershipChanged:Fire(player, key, owned, trial)
1009
1203
  end
1010
1204
  end
1011
1205
  end
@@ -1031,21 +1225,22 @@ function Monetization.new(ctx: any)
1031
1225
  -- only real transitions fire. Returns a disconnect. The public doc-comment lives on
1032
1226
  -- Data.ObserveOwned (Server/init.luau); keep this a plain comment so docgen does not
1033
1227
  -- emit a duplicate entry.
1034
- function self.ObserveOwned(player: Player, key: string, callback: (owned: boolean) -> ()): () -> ()
1228
+ function self.ObserveOwned(player: Player, key: string, callback: (owned: boolean, trial: boolean) -> ()): () -> ()
1035
1229
  checkOwnsKey(key, "ObserveOwned")
1036
1230
  local entry = ctx.Persistence.EntryFor(player)
1037
1231
  if not entry or entry.State ~= "Ready" or not entry.Tree or entry.Tree.Dead then
1038
1232
  error("Scribe: ObserveOwned requires a Ready player (use Data.WaitForData)", 3)
1039
1233
  end
1040
- local last: boolean? = nil
1234
+ local lastOwned: boolean? = nil
1235
+ local lastTrial = false
1041
1236
  local function push()
1042
1237
  if entry.TornDown or not entry.LiveData then
1043
1238
  return
1044
1239
  end
1045
- local owned = ownsInternal(player, entry, key)
1046
- if owned ~= last then
1047
- last = owned
1048
- Sched.Spawn(callback, owned)
1240
+ local owned, trial = ownership(player, entry, key)
1241
+ if owned ~= lastOwned or trial ~= lastTrial then
1242
+ lastOwned, lastTrial = owned, trial
1243
+ Sched.Spawn(callback, owned, trial)
1049
1244
  end
1050
1245
  end
1051
1246
  -- Avoid public-read copies, as in watchOwnership.
@@ -1084,34 +1279,9 @@ function Monetization.new(ctx: any)
1084
1279
  markOwnershipReady(entry)
1085
1280
  return
1086
1281
  end
1087
- for name, pass in passesByName do
1282
+ for name in passesByName do
1088
1283
  Sched.Spawn(function()
1089
- local ok, owned = pcall(function()
1090
- return userOwnsGamePass(entry.UserId, pass.Id)
1091
- end)
1092
- if ok and not entry.TornDown then
1093
- -- Fold this resolution into the join baseline before writing it.
1094
- -- watchOwnership takes its silent baseline while this network round trip
1095
- -- is still out, so without this every player who already owned a pass got
1096
- -- a spurious owned=true. OR, never assign: ownership is the union of
1097
- -- Perks, OwnsCache and RobloxPlus. A nil OwnsLast means the baseline has
1098
- -- not been taken yet and that scan absorbs this by itself.
1099
- local last = entry.OwnsLast
1100
- if last ~= nil and entry.Tree and not entry.Tree.Dead then
1101
- last[name] = last[name] == true or owned == true
1102
- end
1103
- foldOwnsCache(entry, name, owned == true)
1104
- elseif not ok then
1105
- -- A throw or throttle leaves this pass unresolved and the cache not-owned.
1106
- -- Surface it rather than treating a failed check as a confirmed not-owned.
1107
- Metrics.Add("OwnershipCheckFailures")
1108
- Log.Warn(
1109
- "Monetization",
1110
- "OWNERSHIP_CHECK_FAIL",
1111
- tostring(owned),
1112
- { Player = entry.Player, Pass = name, PassId = pass.Id }
1113
- )
1114
- end
1284
+ resolvePass(entry, name, true)
1115
1285
  pending -= 1
1116
1286
  if pending <= 0 and not entry.TornDown then
1117
1287
  markOwnershipReady(entry)
@@ -1131,32 +1301,15 @@ function Monetization.new(ctx: any)
1131
1301
  if not entry or entry.State ~= "Ready" or not entry.LiveData then
1132
1302
  return false
1133
1303
  end
1134
- -- Ownership only ever gains for the session, so a cached true is already
1135
- -- verified; skip the query.
1136
- if self.Owns(player, key) then
1304
+ -- Confirmed purchases stay cached. Trial access can expire.
1305
+ if ownsOutright(entry, key) then
1137
1306
  return true
1138
1307
  end
1139
- -- Not owned per the cache. Verify live with the server-side UserOwnsGamePassAsync:
1140
- -- this is the exploit-proof check to gate grants on, and the client's Owns/OwnsAsync
1141
- -- are mirror reads that must never gate one. Refresh the cache while we are here.
1142
- local pass = passesByName[key]
1143
- if pass and not entry.TornDown then
1144
- local ok, owned = pcall(function()
1145
- return userOwnsGamePass(entry.UserId, pass.Id)
1146
- end)
1308
+ if passesByName[key] and not entry.TornDown then
1309
+ local ok, owns = resolvePass(entry, key)
1147
1310
  if ok then
1148
- if not entry.TornDown then
1149
- return foldOwnsCache(entry, key, owned == true)
1150
- end
1151
- return owned == true
1311
+ return owns
1152
1312
  end
1153
- Metrics.Add("OwnershipCheckFailures")
1154
- Log.Warn(
1155
- "Monetization",
1156
- "OWNERSHIP_CHECK_FAIL",
1157
- tostring(owned),
1158
- { Player = entry.Player, Pass = key, PassId = pass.Id }
1159
- )
1160
1313
  end
1161
1314
  return self.Owns(player, key)
1162
1315
  end
@@ -1206,7 +1359,8 @@ function Monetization.new(ctx: any)
1206
1359
  -- rather than silently rolled back.
1207
1360
  local function apply()
1208
1361
  if product.Grant then
1209
- (product.Grant :: (any) -> ())(entry.Tree.Accessor)
1362
+ -- A gift uses the recipient's entry.
1363
+ (product.Grant :: (any, Player) -> ())(entry.Tree.Accessor, entry.Player)
1210
1364
  end
1211
1365
  if product.Grants then
1212
1366
  checkPerkName(product.Grants)
@@ -1535,8 +1689,9 @@ function Monetization.new(ctx: any)
1535
1689
 
1536
1690
  local function recipientAlreadyOwns(recipientUserId: number, perkKey: string): boolean
1537
1691
  local recipientEntry = ctx.Persistence.EntryForUserId(recipientUserId)
1538
- if recipientEntry and recipientEntry.State == "Ready" then
1539
- if self.Owns(recipientEntry.Player, perkKey) then
1692
+ local present = recipientEntry ~= nil and recipientEntry.State == "Ready"
1693
+ if present then
1694
+ if ownsOutright(recipientEntry, perkKey) then
1540
1695
  return true
1541
1696
  end
1542
1697
  else
@@ -1555,6 +1710,10 @@ function Monetization.new(ctx: any)
1555
1710
  local pass = passesByName[perkKey]
1556
1711
  if pass then
1557
1712
  local ok, owned = pcall(function()
1713
+ -- The trial-aware read requires a local Player.
1714
+ if present then
1715
+ return (readPass(recipientEntry.Player, recipientUserId, pass.Id))
1716
+ end
1558
1717
  return MarketplaceService:UserOwnsGamePassAsync(recipientUserId, pass.Id)
1559
1718
  end)
1560
1719
  if not ok then
@@ -1810,7 +1969,7 @@ function Monetization.new(ctx: any)
1810
1969
 
1811
1970
  -- No matching intent: NoGiftIntentPolicy. A product with a consumable Grant still
1812
1971
  -- delivers real value, so the credit path only covers pure perk products.
1813
- if product.Grants and not product.Grant and self.Owns(entry.Player, product.Grants) then
1972
+ if product.Grants and not product.Grant and ownsOutright(entry, product.Grants) then
1814
1973
  -- Hold further credits until the existing paid credit is spent. Roblox may retry later.
1815
1974
  if (tonumber(reservedRaw(entry.LiveData).GiftCredits[product.Name]) or 0) > 0 then
1816
1975
  Log.Warn(
@@ -1864,7 +2023,7 @@ function Monetization.new(ctx: any)
1864
2023
 
1865
2024
  if product.Grants and not product.Grant then
1866
2025
  -- A giftable perk product bought without intent: grant to the buyer.
1867
- Log.Warn("Gifting", "GIFT_NO_INTENT", "perk product purchased with no gift intent; granting to buyer", {
2026
+ Log.Info("Gifting", "GIFT_NO_INTENT", "perk product purchased with no gift intent; granting to buyer", {
1868
2027
  Player = entry.Player,
1869
2028
  Product = product.Name,
1870
2029
  })
@@ -2428,13 +2587,13 @@ function Monetization.new(ctx: any)
2428
2587
  -- session cache would heal on the next join, but robuxLog writes the PERSISTED
2429
2588
  -- purchase history, so an unconfirmed event falsifies it.
2430
2589
  Sched.Spawn(function()
2431
- local ok, owned = pcall(function()
2432
- return userOwnsGamePass(entry.UserId, passId)
2433
- end)
2590
+ passAsked += 1
2591
+ local asked = passAsked
2592
+ local ok, owned, trialEnds = pcall(readPass, player, entry.UserId, passId)
2434
2593
  if entry.TornDown then
2435
2594
  return
2436
2595
  end
2437
- if not ok or owned ~= true then
2596
+ if not ok or (owned ~= true and trialEnds == nil) then
2438
2597
  -- Self-heals: the join scan re-resolves every declared pass, so a real
2439
2598
  -- purchase the API had not caught up with is credited on the next load.
2440
2599
  Metrics.Add("PassPurchasesUnconfirmed")
@@ -2446,7 +2605,11 @@ function Monetization.new(ctx: any)
2446
2605
  )
2447
2606
  return
2448
2607
  end
2449
- setOwnsCache(entry, passName, true)
2608
+ applyPass(entry, passName, asked, owned, trialEnds)
2609
+ if not owned then
2610
+ -- Trial starts also fire the prompt event. Only purchases enter the paid history.
2611
+ return
2612
+ end
2450
2613
  robuxLog(entry, {
2451
2614
  PurchaseId = `pass:{passId}:{Clock.Now()}`,
2452
2615
  Product = passName,
@@ -3081,7 +3244,7 @@ function Monetization.new(ctx: any)
3081
3244
  costAccessor.Set(balance - amount)
3082
3245
  end
3083
3246
  if spec.Grant then
3084
- (spec.Grant :: (any) -> ())(entry.Tree.Accessor)
3247
+ (spec.Grant :: (any, Player) -> ())(entry.Tree.Accessor, entry.Player)
3085
3248
  end
3086
3249
  checkCategory(spec.Category)
3087
3250
  -- Claimed INSIDE the transaction, so a Grant that throws rolls the claim back with
@@ -81,7 +81,9 @@ export type Entry = {
81
81
  SizeWarned: boolean,
82
82
  TornDown: boolean,
83
83
  -- Replication state (owned by Replication.luau)
84
+ ReadyAt: number?, -- monotonic time the profile became Ready
84
85
  HelloReceived: boolean,
86
+ HelloRefused: boolean?, -- first mismatch already logged
85
87
  -- Two flags, deliberately: QueueOpen means a snapshot has been taken, so a write
86
88
  -- belongs in the queue; HandshakeReady means the snapshot is on the wire, so this
87
89
  -- client may be sent frames. One flag left a gap between those two moments in
@@ -104,6 +106,7 @@ export type Entry = {
104
106
  Queue: { any },
105
107
  QueueIndex: { [string]: number },
106
108
  SharedQueue: { any },
109
+ SharedIndex: { [string]: number },
107
110
  MalformedCount: number,
108
111
  MalformedBlocked: boolean?, -- crossed the malformed-frame limit; inbound frames ignored
109
112
  LastMalformedLog: number?, -- os.clock of the last emitted malformed-frame log/anomaly
@@ -132,8 +135,10 @@ export type Entry = {
132
135
  StopLoadWatchdog: (() -> ())?,
133
136
  -- Monetization state
134
137
  GiftLastAt: number,
135
- OwnsLast: { [string]: boolean }?, -- last reported effective ownership, for change detection
138
+ OwnsLast: { [string]: string }?, -- last reported state ("owned" or "trial")
139
+ OwnsQuiet: string?, -- pass being added to the join baseline
136
140
  OwnsWatchers: { () -> () }?, -- Perks/OwnsCache listeners driving OnOwnershipChanged
141
+ PassStates: { [string]: { Seen: number, Watch: number? } }?, -- latest applied request and pending trial check
137
142
  }
138
143
 
139
144
  local SIZE_WARN_BYTES = 3.5 * 1024 * 1024 -- warn approaching the ~4 MB DataStore ceiling
@@ -354,6 +359,12 @@ function Persistence.new(ctx: any)
354
359
  -- per-player session store, or the per-player snapshot.
355
360
  local playerCompiled = compiled.Views.Player
356
361
  local persistentDefaults = Template.BuildDefaults(playerCompiled, "Persistent")
362
+ local sessionRootNames: { [string]: boolean } = {}
363
+ for name, node in (playerCompiled.Root.Children or {}) :: { [string]: any } do
364
+ if node.Persist == false then
365
+ sessionRootNames[name] = true
366
+ end
367
+ end
357
368
  local baseStore = ProfileStore.New(storeIndex, persistentDefaults)
358
369
  -- Persistence mode: which store to read, whether to hold a session, whether anything
359
370
  -- saves.
@@ -2107,15 +2118,19 @@ function Persistence.new(ctx: any)
2107
2118
  local data = profile.Data
2108
2119
  local view = table.clone(data)
2109
2120
  view[Template.RESERVED_ROOT] = nil
2121
+ -- Hide legacy Session keys from the hook and preserve them in the profile.
2122
+ for name in sessionRootNames do
2123
+ view[name] = nil
2124
+ end
2110
2125
  local keysBefore = table.clone(view)
2111
2126
  local function foldView()
2112
2127
  for key in data do
2113
- if key ~= Template.RESERVED_ROOT and view[key] == nil then
2128
+ if key ~= Template.RESERVED_ROOT and not sessionRootNames[key] and view[key] == nil then
2114
2129
  data[key] = nil
2115
2130
  end
2116
2131
  end
2117
2132
  for key, value in view do
2118
- if key ~= Template.RESERVED_ROOT then
2133
+ if key ~= Template.RESERVED_ROOT and not sessionRootNames[key] then
2119
2134
  data[key] = value
2120
2135
  end
2121
2136
  end
@@ -2137,6 +2152,25 @@ function Persistence.new(ctx: any)
2137
2152
  { Player = player }
2138
2153
  )
2139
2154
  end
2155
+ local sessionWrites: { string } = {}
2156
+ for name in sessionRootNames do
2157
+ if view[name] ~= nil then
2158
+ table.insert(sessionWrites, name)
2159
+ end
2160
+ end
2161
+ if #sessionWrites > 0 then
2162
+ table.sort(sessionWrites)
2163
+ local fields = table.concat(sessionWrites, ", ")
2164
+ Log.Warn(
2165
+ "Lifecycle",
2166
+ "ON_PLAYER_INIT_SESSION",
2167
+ `OnPlayerInit assigned Scribe.Session field(s) {fields}; the assignment was discarded. `
2168
+ .. "A Session field is built fresh each session and never saved, so the hook's table "
2169
+ .. "does not hold it: set it through its accessor once the player is Ready, or declare "
2170
+ .. "a saved field if OnPlayerInit should write it",
2171
+ { Player = player, Fields = fields }
2172
+ )
2173
+ end
2140
2174
  foldView()
2141
2175
  -- Exempt intentional removals from the first save's missing-key check.
2142
2176
  for key in keysBefore do
@@ -2542,6 +2576,7 @@ function Persistence.new(ctx: any)
2542
2576
  Queue = {},
2543
2577
  QueueIndex = {},
2544
2578
  SharedQueue = {},
2579
+ SharedIndex = {},
2545
2580
  MalformedCount = 0,
2546
2581
  OversizeCount = 0,
2547
2582
  FrameTokens = ctx.InboundFrameRate,