Skip to content

Commit e3ad841

Browse files
author
Zoo (VP)
committed
fix(error-interception): add null guard to getTaskState to prevent WeakMap crash
1 parent 21e93c0 commit e3ad841

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/core/tools/error-interception/ToolErrorInterceptor.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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 }

0 commit comments

Comments
 (0)