Skip to content

Commit eb0eaff

Browse files
committed
fix(plugin): include reasoning bytes in projection denominator and clamp ratio
Oracle review caught that reasoningByteSize was added to the numerator (droppable bytes) but not the denominator (total active bytes), which could make projected post-drop usage unrealistically low. Fixed by summing byteSize + reasoningByteSize in totalActiveBytes and clamping dropRatio to [0, 1] as a safety bound.
1 parent 0feaf50 commit eb0eaff

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/plugin/src/hooks/magic-context/compartment-trigger.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ function estimateProjectedPostDropPercentage(
4949
clearedReasoningThroughTag?: number,
5050
): number | null {
5151
const activeTags = getTagsBySession(db, sessionId).filter((tag) => tag.status === "active");
52-
const totalActiveBytes = activeTags.reduce((sum, tag) => sum + tag.byteSize, 0);
52+
// Denominator must include both text/tool bytes and reasoning bytes to match the numerator
53+
const totalActiveBytes = activeTags.reduce(
54+
(sum, tag) => sum + tag.byteSize + tag.reasoningByteSize,
55+
0,
56+
);
5357
if (totalActiveBytes === 0) return null;
5458

5559
let droppableBytes = 0;
@@ -96,7 +100,7 @@ function estimateProjectedPostDropPercentage(
96100

97101
if (droppableBytes === 0) return null;
98102

99-
const dropRatio = droppableBytes / totalActiveBytes;
103+
const dropRatio = Math.min(droppableBytes / totalActiveBytes, 1);
100104
return usage.percentage * (1 - dropRatio);
101105
}
102106

0 commit comments

Comments
 (0)