Skip to content

Commit 43cec6e

Browse files
committed
fix(sandbox): allocation budget actually fires — Mono lacks per-thread GC counter
GC.GetAllocatedBytesForCurrentThread returns 0 unconditionally under Unity's Mono (verified empirically), so the F-08 allocation-bomb backstop could never trigger in either VM guard: bombs ran to a real OutOfMemory or the wall-clock timeout. Both guards now baseline/sample GC.GetTotalMemory(false) — a cheap managed-heap read that is also thread-agnostic (the async Lua-CSharp VM migrates between pool threads). Heap total is process-wide and noisy, so the default budget is raised 64MB -> 256MB: editor background allocation over a 2s window tripped the old threshold in the infinite-loop test (false positive), while real concat-doubling bombs blow past 256MB within a few iterations either way. Verified: full EditMode suite 1583/1583 green, including both AllocationBomb_ConcatDoubling tests (budget fires, not timeout/OOM) and the untouched infinite-loop step/timeout test.
1 parent 9ad67d7 commit 43cec6e

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

Assets/CoreAIMods/Runtime/Sandbox/InstructionLimitDebugger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace CoreAI.Sandbox
2020
internal sealed class InstructionLimitDebugger : IDebugger
2121
{
2222
/// <summary>Default per-execution GC allocation budget enforced between VM instructions.</summary>
23-
public const long DefaultMaxAllocatedBytesBudget = 64 * 1024 * 1024;
23+
public const long DefaultMaxAllocatedBytesBudget = 256 * 1024 * 1024;
2424

2525
private long _maxSteps;
2626
private int _timeoutMs;

Assets/CoreAIMods/Runtime/Sandbox/LuaCsExecutionGuard.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace CoreAI.Sandbox.LuaCs
2424
public sealed class LuaCsExecutionGuard
2525
{
2626
/// <summary>Default per-execution GC allocation budget enforced between VM instructions.</summary>
27-
public const long DefaultMaxAllocatedBytesBudget = 64 * 1024 * 1024;
27+
public const long DefaultMaxAllocatedBytesBudget = 256 * 1024 * 1024;
2828

2929
private readonly int _timeoutMs;
3030
private readonly long _maxSteps;
@@ -34,7 +34,7 @@ public sealed class LuaCsExecutionGuard
3434
/// <param name="maxSteps">Maximum Lua-CSharp instruction steps allowed for one guarded call.</param>
3535
/// <param name="maxAllocatedBytes">
3636
/// Maximum total GC allocation (bytes) permitted for one guarded call, checked on every
37-
/// instruction. Defaults to <see cref="DefaultMaxAllocatedBytesBudget"/> (64MB).
37+
/// instruction. Defaults to <see cref="DefaultMaxAllocatedBytesBudget"/> (256MB).
3838
/// <c>&lt;= 0</c> disables the check.
3939
/// </param>
4040
public LuaCsExecutionGuard(

Assets/CoreAIMods/Runtime/Sandbox/LuaExecutionGuard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public sealed class LuaExecutionGuard
3131
/// <param name="maxAllocatedBytes">
3232
/// Maximum total GC allocation (bytes) permitted for one guarded call, checked on every VM
3333
/// instruction. Defaults to
34-
/// <see cref="InstructionLimitDebugger.DefaultMaxAllocatedBytesBudget"/> (64MB).
34+
/// <see cref="InstructionLimitDebugger.DefaultMaxAllocatedBytesBudget"/> (256MB).
3535
/// </param>
3636
public LuaExecutionGuard(
3737
int timeoutMs = 2000,

0 commit comments

Comments
 (0)