File tree Expand file tree Collapse file tree
src/core/tools/error-interception Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,8 +89,18 @@ export class ToolErrorInterceptor {
8989 /**
9090 * Creates or returns existing per-task state. Uses a WeakMap keyed by the
9191 * Task object so state is discarded when the task is garbage collected.
92+ *
93+ * When `task` is null or undefined (invalid WeakMap key), returns an
94+ * ephemeral default state to satisfy the fail-open philosophy rather than
95+ * throwing TypeError from WeakMap.set().
9296 */
9397 public getTaskState ( task : object ) : InterceptorTaskState {
98+ // WeakMap keys must be objects; null/undefined are invalid and would
99+ // throw TypeError on .set(). Fail-open: return an ephemeral default
100+ // state so callers can proceed without crashing.
101+ if ( ! task ) {
102+ return { categoryCounts : new Map ( ) , shellCircuitOpen : false }
103+ }
94104 let taskState = this . state . perTask . get ( task )
95105 if ( ! taskState ) {
96106 taskState = { categoryCounts : new Map ( ) , shellCircuitOpen : false }
You can’t perform that action at this time.
0 commit comments