Add patch application state management in ServeSession

- Introduced a new flag `__applyingPatch` to track the patch application state, preventing `DescendantAdded` events during reconciliation.
- Updated the `__applyPatch` method to set and clear the `__applyingPatch` flag appropriately, enhancing control over script updates.
- Added checks in the `__connectScriptsOnlyWatchers` method to avoid processing during patch application.

These changes aim to improve the reliability of script handling during patch operations and prevent unintended side effects.
This commit is contained in:
Joe 2026-02-28 11:22:33 -06:00
parent 75727171ef
commit a68e0ab7c6

View file

@ -124,6 +124,7 @@ function ServeSession.new(options)
__serverInfo = nil,
__confirmingPatch = nil,
__isConfirming = false, -- Explicit confirmation state flag for defense-in-depth
__applyingPatch = false, -- Set during reconciler patch application to suppress DescendantAdded
__connections = connections,
__precommitCallbacks = {},
__postcommitCallbacks = {},
@ -561,8 +562,10 @@ function ServeSession:__applyPatch(patch)
end
Timer.stop()
self.__applyingPatch = true
local patchApplySuccess, unappliedPatch = pcall(self.__reconciler.applyPatch, self.__reconciler, patch)
if not patchApplySuccess then
self.__applyingPatch = false
if historyRecording then
ChangeHistoryService:FinishRecording(historyRecording, Enum.FinishRecordingOperation.Commit)
end
@ -596,6 +599,7 @@ function ServeSession:__applyPatch(patch)
PatchSet.assign(unappliedPatch, unappliedUpdateRefs)
end
end
self.__applyingPatch = false
if not PatchSet.isEmpty(unappliedPatch) then
Log.info(
@ -939,6 +943,9 @@ function ServeSession:__connectScriptsOnlyWatchers()
if self.__changeBatcher:isPaused() then
return
end
if self.__applyingPatch then
return
end
if not descendant:IsA("LuaSourceContainer") then
return
end