opencode-model-router 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -0
- package/README.md +70 -4
- package/package.json +2 -2
- package/src/compat/child-session.ts +5 -0
- package/src/compat/v2-hooks.ts +47 -14
- package/src/escalate/effort-override.ts +165 -0
- package/src/escalate/ladder.ts +57 -7
- package/src/index.ts +180 -14
- package/src/router/agent-options.ts +43 -12
- package/src/router/config.ts +131 -20
- package/src/router/depth-guard.ts +152 -0
- package/src/router/depth.ts +826 -0
- package/src/v2.ts +1 -0
- package/src/verify/wiring.ts +16 -2
package/src/router/config.ts
CHANGED
|
@@ -37,8 +37,9 @@ export interface ReasoningConfig {
|
|
|
37
37
|
* Provider-agnostic reasoning effort for a tier.
|
|
38
38
|
*
|
|
39
39
|
* `xhigh` and `max` exist because Anthropic's adaptive models accept them;
|
|
40
|
-
* OpenAI's `
|
|
41
|
-
* downgrades those two with a warning (see
|
|
40
|
+
* OpenAI's reasoning effort parameter (`reasoningEffort`) stops at `high`, so
|
|
41
|
+
* the registration path downgrades those two with a warning (see
|
|
42
|
+
* `src/router/agent-options.ts`).
|
|
42
43
|
*/
|
|
43
44
|
export const EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"] as const;
|
|
44
45
|
|
|
@@ -121,6 +122,8 @@ export interface ModeConfig {
|
|
|
121
122
|
|
|
122
123
|
export interface EnforcementConfig {
|
|
123
124
|
mode?: "off" | "advisory" | "enforced";
|
|
125
|
+
/** Default 1; warned in "advisory" mode (bundled default), refused in "enforced" mode, ignored in "off"; null disables. */
|
|
126
|
+
maxDelegationDepth?: number | null;
|
|
124
127
|
envGate?: string;
|
|
125
128
|
perTier?: Record<string, "off" | "advisory" | "enforced">;
|
|
126
129
|
guard?: { readDraftCap?: number; sameOpRetryCap?: number; blockSelfScript?: boolean; deliverableFirst?: boolean; budget?: number; blockScriptWrites?: boolean };
|
|
@@ -167,7 +170,11 @@ export interface EnforcementConfig {
|
|
|
167
170
|
failureRecheck?: boolean;
|
|
168
171
|
/** Budget for the reference re-run, in ms (integer >= 1). Default 60000. */
|
|
169
172
|
recheckTimeoutMs?: number };
|
|
170
|
-
escalate?: { floorTier?: string | null; ladder?: string[]; maxAttemptsPerTier?: number; maxTotalAttempts?: number; costCeiling?: { base?: string; multiple?: number }
|
|
173
|
+
escalate?: { floorTier?: string | null; ladder?: string[]; maxAttemptsPerTier?: number; maxTotalAttempts?: number; costCeiling?: { base?: string; multiple?: number };
|
|
174
|
+
/** Bump reasoning effort before escalating tiers. Default true. */
|
|
175
|
+
effortBump?: boolean;
|
|
176
|
+
/** Maximum reasoning effort for a bump. Default "xhigh". */
|
|
177
|
+
effortBumpMax?: EffortLevel };
|
|
171
178
|
proportional?: { trivialBypass?: boolean; trivialClassifier?: string };
|
|
172
179
|
}
|
|
173
180
|
|
|
@@ -710,13 +717,86 @@ function validateTaskPatterns(obj: Record<string, unknown>): void {
|
|
|
710
717
|
*/
|
|
711
718
|
const MAX_TIMER_MS = 2_147_483_647;
|
|
712
719
|
|
|
713
|
-
|
|
720
|
+
/**
|
|
721
|
+
* Equals the depth tracker's MAX_DEPTH_HOPS (src/router/depth.ts, Phase 1.2),
|
|
722
|
+
* so a cycle or over-long chain counted as 32 is refused under every configured limit.
|
|
723
|
+
*/
|
|
724
|
+
export const MAX_DELEGATION_DEPTH_LIMIT = 32;
|
|
725
|
+
|
|
726
|
+
/** Total, typed and bounded rendering of an invalid config value. */
|
|
727
|
+
function describeValue(value: unknown): string {
|
|
728
|
+
let description: string;
|
|
729
|
+
try {
|
|
730
|
+
if (typeof value === "string") description = JSON.stringify(value);
|
|
731
|
+
else if (typeof value === "number") description = Object.is(value, -0) ? "-0" : String(value);
|
|
732
|
+
else if (typeof value === "bigint") description = `${value}n`;
|
|
733
|
+
else if (value === null) description = "null";
|
|
734
|
+
else if (typeof value === "object") {
|
|
735
|
+
const tag = Array.isArray(value) ? "array" : "object";
|
|
736
|
+
description = `${tag} ${JSON.stringify(value) ?? "<unserializable>"}`;
|
|
737
|
+
} else if (typeof value === "function") description = "<function>";
|
|
738
|
+
else description = String(value);
|
|
739
|
+
} catch {
|
|
740
|
+
description = `<${typeof value}>`;
|
|
741
|
+
}
|
|
742
|
+
if (description.length <= 80) return description;
|
|
743
|
+
// Keep the 80-code-unit bound without splitting a surrogate pair.
|
|
744
|
+
const end = /[\uD800-\uDBFF]/.test(description[78]!) && /[\uDC00-\uDFFF]/.test(description[79]!) ? 78 : 79;
|
|
745
|
+
return `${description.slice(0, end)}…`;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/** Copy without invoking accessors again; include defined get-only Proxy values. */
|
|
749
|
+
function withValidatedSnapshots<T extends object>(
|
|
750
|
+
obj: T,
|
|
751
|
+
snapshots: Record<string, unknown>,
|
|
752
|
+
): T {
|
|
753
|
+
const descriptors: Record<string, PropertyDescriptor> = Object.getOwnPropertyDescriptors(obj);
|
|
754
|
+
let changed = false;
|
|
755
|
+
for (const [key, value] of Object.entries(snapshots)) {
|
|
756
|
+
if (value !== undefined || Object.hasOwn(descriptors, key) || key in obj) {
|
|
757
|
+
descriptors[key] = { value, writable: true, enumerable: true, configurable: true };
|
|
758
|
+
changed = true;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
if (!changed) return obj;
|
|
762
|
+
// Keep inherited config values and array identity, not just own descriptors.
|
|
763
|
+
const copy: object = Array.isArray(obj) ? [] : Object.create(Object.getPrototypeOf(obj));
|
|
764
|
+
if (Array.isArray(obj)) Object.setPrototypeOf(copy, Object.getPrototypeOf(obj));
|
|
765
|
+
Object.defineProperties(copy, descriptors);
|
|
766
|
+
if (Object.isFrozen(obj)) Object.freeze(copy);
|
|
767
|
+
return copy as T;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/** Reject keys that could reparent a later Object.assign copy. */
|
|
771
|
+
function rejectPrototypeKeys(obj: object, path: string): void {
|
|
772
|
+
for (const key of ["__proto__", "constructor", "prototype"] as const) {
|
|
773
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
774
|
+
throw new Error(`tiers.json: ${path} must not contain the key "${key}"`);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
function validateEnforcement(value: unknown): Record<string, unknown> | undefined {
|
|
714
780
|
// Validate enforcement if present (optional — absent means no enforcement)
|
|
715
|
-
if (
|
|
716
|
-
if (!isPlainObject(
|
|
781
|
+
if (value !== undefined) {
|
|
782
|
+
if (!isPlainObject(value)) {
|
|
717
783
|
throw new Error("tiers.json: enforcement must be an object");
|
|
718
784
|
}
|
|
719
|
-
const enforcement =
|
|
785
|
+
const enforcement = value as Record<string, unknown>;
|
|
786
|
+
rejectPrototypeKeys(enforcement, "enforcement");
|
|
787
|
+
const maxDelegationDepth = enforcement.maxDelegationDepth;
|
|
788
|
+
if (
|
|
789
|
+
maxDelegationDepth !== undefined &&
|
|
790
|
+
maxDelegationDepth !== null &&
|
|
791
|
+
(typeof maxDelegationDepth !== "number" ||
|
|
792
|
+
!Number.isSafeInteger(maxDelegationDepth) ||
|
|
793
|
+
maxDelegationDepth < 1 ||
|
|
794
|
+
maxDelegationDepth > MAX_DELEGATION_DEPTH_LIMIT)
|
|
795
|
+
) {
|
|
796
|
+
throw new Error(
|
|
797
|
+
`tiers.json: enforcement.maxDelegationDepth must be null or an integer from 1 to 32 (got ${describeValue(maxDelegationDepth)})`,
|
|
798
|
+
);
|
|
799
|
+
}
|
|
720
800
|
if (enforcement.mode !== undefined) {
|
|
721
801
|
if (!["off", "advisory", "enforced"].includes(enforcement.mode as string)) {
|
|
722
802
|
throw new Error(
|
|
@@ -738,13 +818,7 @@ function validateEnforcement(obj: Record<string, unknown>): void {
|
|
|
738
818
|
throw new Error("tiers.json: enforcement.verify must be an object");
|
|
739
819
|
}
|
|
740
820
|
const verify = enforcement.verify as Record<string, unknown>;
|
|
741
|
-
|
|
742
|
-
// later `Object.assign` copy would reparent through it; reject it here.
|
|
743
|
-
for (const key of ["__proto__", "constructor", "prototype"] as const) {
|
|
744
|
-
if (Object.prototype.hasOwnProperty.call(verify, key)) {
|
|
745
|
-
throw new Error(`tiers.json: enforcement.verify must not contain the key "${key}"`);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
821
|
+
rejectPrototypeKeys(verify, "enforcement.verify");
|
|
748
822
|
if (verify.testBaseline !== undefined && typeof verify.testBaseline !== "boolean") {
|
|
749
823
|
throw new Error("tiers.json: enforcement.verify.testBaseline must be a boolean");
|
|
750
824
|
}
|
|
@@ -869,12 +943,29 @@ function validateEnforcement(obj: Record<string, unknown>): void {
|
|
|
869
943
|
);
|
|
870
944
|
}
|
|
871
945
|
}
|
|
946
|
+
const escalateValue = enforcement.escalate;
|
|
947
|
+
const snapshots: Record<string, unknown> = { maxDelegationDepth, escalate: escalateValue };
|
|
872
948
|
if (
|
|
873
|
-
|
|
874
|
-
typeof
|
|
875
|
-
|
|
949
|
+
escalateValue !== undefined &&
|
|
950
|
+
typeof escalateValue === "object" &&
|
|
951
|
+
escalateValue !== null
|
|
876
952
|
) {
|
|
877
|
-
const escalate =
|
|
953
|
+
const escalate = escalateValue as Record<string, unknown>;
|
|
954
|
+
rejectPrototypeKeys(escalate, "enforcement.escalate");
|
|
955
|
+
const effortBump = escalate.effortBump;
|
|
956
|
+
if (effortBump !== undefined && typeof effortBump !== "boolean") {
|
|
957
|
+
throw new Error(`tiers.json: enforcement.escalate.effortBump must be a boolean (got ${describeValue(effortBump)})`);
|
|
958
|
+
}
|
|
959
|
+
const effortBumpMax = escalate.effortBumpMax;
|
|
960
|
+
if (
|
|
961
|
+
effortBumpMax !== undefined &&
|
|
962
|
+
!EFFORT_LEVELS.some((level) => level === effortBumpMax)
|
|
963
|
+
) {
|
|
964
|
+
throw new Error(
|
|
965
|
+
`tiers.json: enforcement.escalate.effortBumpMax must be one of ${EFFORT_LEVELS.join("|")} (got ${describeValue(effortBumpMax)})`,
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
snapshots.escalate = withValidatedSnapshots(escalate, { effortBump, effortBumpMax });
|
|
878
969
|
if (
|
|
879
970
|
escalate.costCeiling !== undefined &&
|
|
880
971
|
typeof escalate.costCeiling === "object" &&
|
|
@@ -1007,6 +1098,7 @@ function validateEnforcement(obj: Record<string, unknown>): void {
|
|
|
1007
1098
|
);
|
|
1008
1099
|
}
|
|
1009
1100
|
}
|
|
1101
|
+
return withValidatedSnapshots(enforcement, snapshots);
|
|
1010
1102
|
}
|
|
1011
1103
|
}
|
|
1012
1104
|
|
|
@@ -1014,6 +1106,9 @@ function validateEnforcement(obj: Record<string, unknown>): void {
|
|
|
1014
1106
|
* Validate a raw parsed config. Strict and throwing by design: the bundled
|
|
1015
1107
|
* tiers.json must be valid on its own, and loadConfig turns a throw from an
|
|
1016
1108
|
* override layer into a warning plus a fallback rather than a crash.
|
|
1109
|
+
* Returns a copy when enforcement is present (even an undefined accessor),
|
|
1110
|
+
* snapshotting its depth/effort values without mutating the caller. Copies
|
|
1111
|
+
* preserve prototypes, arrays, unrelated descriptors and source frozenness.
|
|
1017
1112
|
*
|
|
1018
1113
|
* Section order matters and is preserved from when this was one function: a
|
|
1019
1114
|
* config with several problems reports the same first error it always did.
|
|
@@ -1040,13 +1135,14 @@ export function validateConfig(raw: unknown): RouterConfig {
|
|
|
1040
1135
|
validateModelGenerations(obj);
|
|
1041
1136
|
validateTaskPatterns(obj);
|
|
1042
1137
|
validateSubagentTiers(obj);
|
|
1043
|
-
validateEnforcement(obj);
|
|
1138
|
+
const enforcement = validateEnforcement(obj.enforcement);
|
|
1044
1139
|
validateDelegateInstructions(obj);
|
|
1045
1140
|
validateDispatchHeader(obj);
|
|
1046
1141
|
validateTaskPromptRepair(obj);
|
|
1047
1142
|
validateFalseRefusalDetection(obj);
|
|
1048
1143
|
|
|
1049
|
-
|
|
1144
|
+
const cfg = raw as RouterConfig;
|
|
1145
|
+
return withValidatedSnapshots(cfg, { enforcement });
|
|
1050
1146
|
}
|
|
1051
1147
|
|
|
1052
1148
|
/**
|
|
@@ -1269,6 +1365,21 @@ export function writeState(patch: Partial<RouterState>): void {
|
|
|
1269
1365
|
// Enforcement helpers
|
|
1270
1366
|
// ---------------------------------------------------------------------------
|
|
1271
1367
|
|
|
1368
|
+
/** The single place the delegation-depth default is applied; null disables it. */
|
|
1369
|
+
export function resolveDepthLimit(cfg: RouterConfig): number | null {
|
|
1370
|
+
const depth = cfg.enforcement?.maxDelegationDepth;
|
|
1371
|
+
return depth === undefined ? 1 : depth;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
/** The single place effort-bump defaults are applied, without mutating config. */
|
|
1375
|
+
export function resolveEffortBump(cfg: RouterConfig): { enabled: boolean; max: EffortLevel } {
|
|
1376
|
+
const escalate = cfg.enforcement?.escalate;
|
|
1377
|
+
return {
|
|
1378
|
+
enabled: escalate?.effortBump ?? true,
|
|
1379
|
+
max: escalate?.effortBumpMax ?? "xhigh",
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1272
1383
|
/** Returns the effective enforcement mode. Missing enforcement ⇒ mode:"advisory". */
|
|
1273
1384
|
export function normalizeEnforcement(
|
|
1274
1385
|
e: EnforcementConfig | undefined,
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { BeforeResult } from "../guard/enforce";
|
|
2
|
+
import { MAX_DELEGATION_DEPTH_LIMIT } from "./config";
|
|
3
|
+
import { MAX_DEPTH_HOPS } from "./depth";
|
|
4
|
+
import type { DepthTracker } from "./depth";
|
|
5
|
+
import type { EnforcementMode } from "./enforcement";
|
|
6
|
+
|
|
7
|
+
export const DELEGATION_DEPTH_GUARD = "delegation_depth";
|
|
8
|
+
export type DepthGuardResult = BeforeResult & { banner?: string };
|
|
9
|
+
|
|
10
|
+
const MAX_WARNED_CALLERS = 1_000;
|
|
11
|
+
const MAX_WARNED_CAUSES = 100;
|
|
12
|
+
|
|
13
|
+
function describe(value: unknown): string {
|
|
14
|
+
try {
|
|
15
|
+
return value instanceof Error ? `${value.name}: ${value.message}` : `${typeof value}: ${String(value)}`;
|
|
16
|
+
} catch {
|
|
17
|
+
return "unprintable value";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Runtime seam values are keyed by their bounded printed form, never identity. */
|
|
22
|
+
function describeValue(value: unknown): string {
|
|
23
|
+
let printed: string;
|
|
24
|
+
try {
|
|
25
|
+
printed = String(value);
|
|
26
|
+
} catch {
|
|
27
|
+
printed = "unprintable value";
|
|
28
|
+
}
|
|
29
|
+
return `${typeof value}: ${printed}`.slice(0, 80);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function depthLimitMessage(depth: number, max: number): string {
|
|
33
|
+
return `[router] DELEGATION DEPTH LIMIT — this session is at delegation depth ${depth}; enforcement.maxDelegationDepth is ${max}, so it cannot dispatch another subagent. Do this part of the work yourself and report the result; do not retry the dispatch.`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function depthAdvisoryBanner(depth: number, max: number): string {
|
|
37
|
+
return `[⚠ GUARD:delegation_depth] this session is at delegation depth ${depth}; enforcement.maxDelegationDepth is ${max}. In enforced mode this dispatch would have been refused. Do not dispatch further subagents from this session; do that work yourself.`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Pure dispatch decision; the caller owns refusal and advisory-banner delivery. */
|
|
41
|
+
export function createDepthGuard(deps: {
|
|
42
|
+
tracker: Pick<DepthTracker, "depthOf">;
|
|
43
|
+
limit: () => number | null;
|
|
44
|
+
mode: (callerSessionID: string | undefined) => EnforcementMode;
|
|
45
|
+
logger: { warn(msg: string): void };
|
|
46
|
+
}): { checkDispatch(callerSessionID: string | undefined): Promise<DepthGuardResult> } {
|
|
47
|
+
const warnedCallers = new Set<string>();
|
|
48
|
+
const warnedModes = new Set<unknown>();
|
|
49
|
+
const warnedModeErrors = new Set<unknown>();
|
|
50
|
+
const warnedLimitErrors = new Set<unknown>();
|
|
51
|
+
const warnedDepths = new Set<unknown>();
|
|
52
|
+
const warnedLimits = new Set<unknown>();
|
|
53
|
+
let warnedCaller = false;
|
|
54
|
+
|
|
55
|
+
function warn(message: string): boolean {
|
|
56
|
+
try {
|
|
57
|
+
deps.logger.warn(`[router] delegation depth: ${message}`);
|
|
58
|
+
return true;
|
|
59
|
+
} catch {
|
|
60
|
+
// A broken logger must not change an admission decision or reject a call.
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function warnUnknown(caller: string): void {
|
|
66
|
+
if (warnedCallers.has(caller)) return;
|
|
67
|
+
if (!warn(`cannot resolve depth for session ${caller}; allowing dispatch.`)) return;
|
|
68
|
+
warnedCallers.add(caller);
|
|
69
|
+
if (warnedCallers.size > MAX_WARNED_CALLERS) {
|
|
70
|
+
warnedCallers.delete(warnedCallers.values().next().value!);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function warnOnce(causes: Set<unknown>, cause: unknown, message: string): void {
|
|
75
|
+
if (causes.has(cause)) return;
|
|
76
|
+
// Remember only delivered warnings; a broken logger is retried next time.
|
|
77
|
+
if (!warn(message)) return;
|
|
78
|
+
causes.add(cause);
|
|
79
|
+
if (causes.size > MAX_WARNED_CAUSES) causes.delete(causes.values().next().value);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
async checkDispatch(callerSessionID) {
|
|
84
|
+
// Read both seams on every call so live config and caller-tier changes apply.
|
|
85
|
+
let mode: EnforcementMode = "advisory";
|
|
86
|
+
try {
|
|
87
|
+
const resolved = deps.mode(callerSessionID);
|
|
88
|
+
if (resolved === "off" || resolved === "advisory" || resolved === "enforced") {
|
|
89
|
+
mode = resolved;
|
|
90
|
+
} else {
|
|
91
|
+
const cause = describeValue(resolved);
|
|
92
|
+
warnOnce(warnedModes, cause, `invalid enforcement mode ${cause}; using advisory.`);
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
const cause = describe(error);
|
|
96
|
+
warnOnce(warnedModeErrors, cause, `cannot resolve enforcement mode (${cause}); using advisory.`);
|
|
97
|
+
}
|
|
98
|
+
if (mode === "off") return { block: false, mode };
|
|
99
|
+
|
|
100
|
+
let max: number | null;
|
|
101
|
+
try {
|
|
102
|
+
max = deps.limit();
|
|
103
|
+
} catch (error) {
|
|
104
|
+
const cause = describe(error);
|
|
105
|
+
warnOnce(warnedLimitErrors, cause, `cannot resolve delegation depth limit (${cause}); using 1.`);
|
|
106
|
+
max = 1;
|
|
107
|
+
}
|
|
108
|
+
if (max === null) return { block: false, mode };
|
|
109
|
+
if (!Number.isInteger(max) || max < 1 || max > MAX_DELEGATION_DEPTH_LIMIT) {
|
|
110
|
+
const cause = describeValue(max);
|
|
111
|
+
warnOnce(warnedLimits, cause, `invalid delegation depth limit ${cause}; using effective limit 1.`);
|
|
112
|
+
max = 1;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (typeof callerSessionID !== "string" || callerSessionID === "") {
|
|
116
|
+
if (!warnedCaller) {
|
|
117
|
+
warnedCaller = warn("missing or invalid caller session; allowing dispatch.");
|
|
118
|
+
}
|
|
119
|
+
return { block: false, mode, guard: null };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let depth: number | undefined;
|
|
123
|
+
try {
|
|
124
|
+
depth = await deps.tracker.depthOf(callerSessionID);
|
|
125
|
+
} catch {
|
|
126
|
+
warnUnknown(callerSessionID);
|
|
127
|
+
return { block: false, mode, guard: null };
|
|
128
|
+
}
|
|
129
|
+
if (depth === undefined) {
|
|
130
|
+
// The tracker owns unknown-depth warnings (including failure/timeout).
|
|
131
|
+
// Phase 2.3 must pass the same plugin logger to tracker and guard: D2
|
|
132
|
+
// requires one warning, not one per layer, including forgotten callers.
|
|
133
|
+
// Only invalid callers and tracker contract violations are ours to log.
|
|
134
|
+
return { block: false, mode, guard: null };
|
|
135
|
+
}
|
|
136
|
+
if (!Number.isInteger(depth) || depth < 0) {
|
|
137
|
+
const cause = describe(depth);
|
|
138
|
+
warnOnce(warnedDepths, JSON.stringify([callerSessionID, cause]),
|
|
139
|
+
`invalid depth ${cause} for session ${callerSessionID}; using ${MAX_DEPTH_HOPS}.`);
|
|
140
|
+
depth = MAX_DEPTH_HOPS;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (depth + 1 > max) {
|
|
144
|
+
if (mode === "enforced") {
|
|
145
|
+
return { block: true, mode, message: depthLimitMessage(depth, max), guard: DELEGATION_DEPTH_GUARD };
|
|
146
|
+
}
|
|
147
|
+
return { block: false, mode, guard: DELEGATION_DEPTH_GUARD, banner: depthAdvisoryBanner(depth, max) };
|
|
148
|
+
}
|
|
149
|
+
return { block: false, mode, guard: null };
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|