@@ -5,30 +5,45 @@ import { getPendingOps } from "../../features/magic-context/storage";
55import { getOrCreateSessionMeta } from "../../features/magic-context/storage-meta" ;
66import { getTagsBySession } from "../../features/magic-context/storage-tags" ;
77import { getErrorMessage } from "../../shared/error-message" ;
8+ import { formatThresholdClampNote } from "../../shared/format-threshold" ;
89import { sessionLog } from "../../shared/logger" ;
910import type { Database } from "../../shared/sqlite" ;
1011import {
1112 getProactiveCompartmentTriggerPercentage ,
1213 POST_DROP_TARGET_RATIO ,
1314} from "./compartment-trigger" ;
14- import { resolveExecuteThresholdDetail } from "./event-resolvers" ;
15+ import {
16+ MAX_EXECUTE_THRESHOLD ,
17+ resolveExecuteThresholdDetail ,
18+ type ExecuteThresholdDetail ,
19+ } from "./event-resolvers" ;
1520import { formatBytes } from "./format-bytes" ;
1621import { estimateTokens } from "./read-session-formatting" ;
1722
1823function formatExecuteThreshold (
19- thresholdPercentage : number ,
20- mode : "tokens" | "percentage" ,
24+ detail : ExecuteThresholdDetail ,
2125 contextLimit : number ,
2226) : string {
27+ const { percentage, mode } = detail ;
28+ // Surfaces the silent clamp from issue #241: when the configured value exceeded
29+ // the 80% safety cap, append a note showing the configured value and the cap so
30+ // the user sees the math (e.g. "190,000 > 80% of 128,000"). "" when not clamped.
31+ const clampNote = formatThresholdClampNote ( {
32+ clamped : detail . clamped ,
33+ mode,
34+ configuredValue : detail . configuredValue ,
35+ contextLimit,
36+ maxPercentage : MAX_EXECUTE_THRESHOLD ,
37+ } ) ;
2338 if ( mode === "tokens" && contextLimit > 0 ) {
24- const tokens = Math . floor ( ( thresholdPercentage / 100 ) * contextLimit ) ;
25- return `${ tokens . toLocaleString ( ) } tokens (${ thresholdPercentage . toFixed ( 1 ) } % of ${ contextLimit . toLocaleString ( ) } ) [token-mode]` ;
39+ const tokens = Math . floor ( ( percentage / 100 ) * contextLimit ) ;
40+ return `${ tokens . toLocaleString ( ) } tokens (${ percentage . toFixed ( 1 ) } % of ${ contextLimit . toLocaleString ( ) } ) [token-mode]${ clampNote } ` ;
2641 }
2742 if ( contextLimit > 0 ) {
28- const tokens = Math . floor ( ( thresholdPercentage / 100 ) * contextLimit ) ;
29- return `${ thresholdPercentage } % (${ tokens . toLocaleString ( ) } of ${ contextLimit . toLocaleString ( ) } )` ;
43+ const tokens = Math . floor ( ( percentage / 100 ) * contextLimit ) ;
44+ return `${ percentage } % (${ tokens . toLocaleString ( ) } of ${ contextLimit . toLocaleString ( ) } )${ clampNote } ` ;
3045 }
31- return `${ thresholdPercentage } % ` ;
46+ return `${ percentage } % ${ clampNote } ` ;
3247}
3348
3449export function executeStatus (
@@ -59,7 +74,6 @@ export function executeStatus(
5974 } ,
6075 ) ;
6176 const executeThresholdPercentage = thresholdDetail . percentage ;
62- const thresholdMode : "tokens" | "percentage" = thresholdDetail . mode ;
6377 try {
6478 const meta = getOrCreateSessionMeta ( db , sessionId ) ;
6579 const tags = getTagsBySession ( db , sessionId ) ;
@@ -120,7 +134,7 @@ export function executeStatus(
120134 `- Queue will auto-execute: ${ cacheExpired ? "yes (cache expired)" : `when TTL expires or context >= ${ executeThresholdPercentage } %` } ` ,
121135 "" ,
122136 "### Execute Threshold" ,
123- `- Execute threshold: ${ formatExecuteThreshold ( executeThresholdPercentage , thresholdMode , displayContextLimit ) } ` ,
137+ `- Execute threshold: ${ formatExecuteThreshold ( thresholdDetail , displayContextLimit ) } ` ,
124138 `- Last input tokens: ${ meta . lastInputTokens . toLocaleString ( ) } tokens` ,
125139 "" ,
126140 `**Protected tags:** ${ protectedTags } ` ,
0 commit comments