@dsmm/dsmm 0.3.15 → 0.3.17
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/README.md +13 -5
- package/docs/agent-presets.md +1 -1
- package/docs/compatibility.md +5 -5
- package/docs/deferred-native-approval-risk.md +1 -1
- package/docs/design.md +1 -1
- package/docs/lsp.md +1 -1
- package/docs/maintenance.md +2 -1
- package/docs/model-routing.md +13 -6
- package/docs/native-permissions.md +1 -1
- package/docs/profiles.md +3 -1
- package/docs/releasing.md +2 -2
- package/docs/roadmap.md +3 -3
- package/docs/runtime-recovery.md +4 -4
- package/docs/safety-guards.md +1 -1
- package/docs/settings-status.md +4 -2
- package/docs/tui.md +53 -0
- package/dsh-plugin.json +41 -0
- package/lib/client/ProfilesSection.js +1 -1
- package/lib/client/SessionProfiles.js +8 -7
- package/lib/client/children-locales.d.ts +1 -1
- package/lib/client/controller.d.ts +13 -1
- package/lib/client/controller.js +114 -20
- package/lib/client/deployment-locales.js +3 -2
- package/lib/client/deployment-modules.js +1 -1
- package/lib/client/index.js +22 -4
- package/lib/client/locales.d.ts +1 -0
- package/lib/client/locales.js +2 -0
- package/lib/client.js +144 -29
- package/lib/commands.d.ts +7 -3
- package/lib/commands.js +20 -11
- package/lib/host-llm.js +6 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -6
- package/lib/model-routing.js +43 -19
- package/lib/profile-diagnostics.js +1 -0
- package/lib/profile-runtime.js +1 -1
- package/lib/request-routing.d.ts +27 -0
- package/lib/request-routing.js +69 -0
- package/lib/role-llm-runtime.js +15 -2
- package/lib/role-routing.d.ts +4 -3
- package/lib/role-routing.js +17 -10
- package/lib/runtime-recovery.js +56 -16
- package/lib/settings.d.ts +3 -0
- package/lib/settings.js +9 -0
- package/lib/state.d.ts +2 -2
- package/lib/state.js +13 -4
- package/lib/status.d.ts +5 -0
- package/lib/status.js +18 -7
- package/lib/tui-actions.d.ts +21 -0
- package/lib/tui-actions.js +301 -0
- package/lib/tui-adapter.d.ts +25 -0
- package/lib/tui-adapter.js +422 -0
- package/lib/tui-types.d.ts +98 -0
- package/lib/tui-types.js +2 -0
- package/package.json +4 -2
package/lib/model-routing.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DsmmAwareLlmRuntime } from "./host-llm.js";
|
|
2
|
-
import { applyModelRoute, clearRoleRouteLock, effectiveRoleFallbackRoutes, establishRolePolicy, latestNativeModelSelection, nativeModelSelectionWasAccepted, orderedModelRoutes, persistedRoleRoute, pinRoleRoute, roleRouteLock, selectInitialModelRoute, sameExactModelRoute, sameModelRoute, takeAdmittedRecoveryRoute } from "./role-routing.js";
|
|
3
|
-
import { resolveAdmittedDsmmRole } from "./role-policy.js";
|
|
2
|
+
import { applyModelRoute, clearRoleRouteLock, effectiveRoleFallbackRoutes, establishRolePolicy, latestNativeModelSelection, nativeModelSelectionWasAccepted, orderedModelRoutes, persistedRoleRoute, pinRoleRoute, roleRouteLock, selectInitialModelRoute, selectInitialModelRouteChoice, sameExactModelRoute, sameModelRoute, takeAdmittedRecoveryRoute } from "./role-routing.js";
|
|
4
3
|
import { childOwnedSessionEvents, sessionEvents } from "./session-scope.js";
|
|
5
4
|
import { isCurrentRecoveryStep } from "./recovery-policy.js";
|
|
6
5
|
import { capturedRoleInvocation } from "./role-invocation.js";
|
|
7
|
-
import { modelRouteFromCall } from "./role-llm.js";
|
|
6
|
+
import { modelRouteFromCall, projectModelRouteParameters } from "./role-llm.js";
|
|
8
7
|
import { configuredModelParameterPolicy, resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
9
8
|
import { registerRuntimeRecovery } from "./runtime-recovery.js";
|
|
9
|
+
import { captureRequestRouting, captureRequestRoute } from "./request-routing.js";
|
|
10
10
|
const preparations = new WeakMap();
|
|
11
11
|
export async function prepareDsmmRequest(frame, proposal, assertCurrent) {
|
|
12
12
|
const prepare = preparations.get(frame.agent);
|
|
@@ -21,45 +21,58 @@ export function registerModelRouting(ctx, controller, getSettings, agent) {
|
|
|
21
21
|
return;
|
|
22
22
|
installedContexts.add(readyCtx);
|
|
23
23
|
const lockedAgents = new Set();
|
|
24
|
+
let active = true;
|
|
24
25
|
const assembledSelections = new WeakMap();
|
|
25
26
|
let dispose, disposeAgent, disposeAssembly;
|
|
26
27
|
try {
|
|
27
28
|
const owned = agent !== undefined && readyCtx.get?.("llm") instanceof DsmmAwareLlmRuntime;
|
|
28
29
|
let recovery;
|
|
29
|
-
registerRuntimeRecovery(readyCtx, controller, getSettings,
|
|
30
|
+
registerRuntimeRecovery(readyCtx, controller, getSettings, prepare => { recovery = prepare; });
|
|
30
31
|
disposeAssembly = readyCtx.on("system-prompt/assemble", async (_assembly, context, next) => {
|
|
31
32
|
if (context.agent !== undefined && context.signal !== undefined)
|
|
32
33
|
assembledSelections.set(context.agent, { signal: context.signal, intent: latestNativeModelSelection(context.agent) });
|
|
33
34
|
return next();
|
|
34
35
|
}, { prepend: true });
|
|
35
36
|
const prepare = async (frame, proposal, assertCurrent = () => frame.signal.throwIfAborted()) => {
|
|
37
|
+
if (frame.signal.aborted)
|
|
38
|
+
return proposal;
|
|
39
|
+
const decision = captureRequestRouting(frame, readyCtx, controller, getSettings, () => {
|
|
40
|
+
if (!active)
|
|
41
|
+
throw new Error("DSMM routing owner retired");
|
|
42
|
+
assertCurrent();
|
|
43
|
+
});
|
|
36
44
|
const downstream = recovery === undefined ? proposal : await recovery(frame, proposal);
|
|
37
45
|
if (frame.signal.aborted)
|
|
38
46
|
return downstream;
|
|
39
|
-
assertCurrent();
|
|
40
|
-
const settings
|
|
47
|
+
decision.assertCurrent();
|
|
48
|
+
const { settings, admission, role, configuredRoot } = decision;
|
|
41
49
|
const parameterPolicy = admission === undefined ? configuredModelParameterPolicy(settings) : resolvedModelParameterPolicy(admission);
|
|
42
|
-
if (!settings.modules.deepwork.enabled)
|
|
50
|
+
if (!settings.modules.deepwork.enabled) {
|
|
51
|
+
captureRequestRoute(frame, decision);
|
|
43
52
|
return downstream;
|
|
53
|
+
}
|
|
44
54
|
const ordinaryRoot = frame.agent.session.header?.origin !== "subagent";
|
|
45
55
|
const admitted = takeAdmittedRecoveryRoute(frame);
|
|
46
|
-
const role = resolveAdmittedDsmmRole(frame.agent, settings, controller.active(frame.agent, settings.defaultActive));
|
|
47
56
|
const policy = role === undefined ? undefined : settings.roleRouting[role];
|
|
48
57
|
const invocation = capturedRoleInvocation(frame.agent);
|
|
49
58
|
const primary = invocation?.initialRoute ?? policy?.primary;
|
|
50
59
|
const identity = await establishRolePolicy(frame, settings, role, readyCtx, admission?.epoch);
|
|
51
|
-
assertCurrent();
|
|
60
|
+
decision.assertCurrent();
|
|
52
61
|
frame.signal.throwIfAborted();
|
|
53
62
|
const fallbacks = effectiveRoleFallbackRoutes(settings, role);
|
|
54
63
|
const currentStep = isCurrentRecoveryStep(ordinaryRoot ? sessionEvents(frame.agent.session) : childOwnedSessionEvents(frame.agent.session), frame.turn, frame.step);
|
|
55
|
-
if (
|
|
64
|
+
if (configuredRoot && !currentStep)
|
|
65
|
+
throw new Error("Configured root has no current request step");
|
|
66
|
+
if (role === undefined || identity === undefined || !currentStep) {
|
|
67
|
+
captureRequestRoute(frame, decision);
|
|
56
68
|
return downstream;
|
|
69
|
+
}
|
|
57
70
|
let lock = roleRouteLock(frame.agent, identity);
|
|
58
71
|
const exactPolicy = invocation === undefined ? primary !== undefined || policy?.fallbackRoutes !== undefined || fallbacks.length > 0
|
|
59
72
|
: invocation.routeSource !== "inherited" || invocation.exactEffort || fallbacks.length > 0;
|
|
60
73
|
const captured = assembledSelections.get(frame.agent);
|
|
61
74
|
const manual = captured?.signal === frame.signal ? captured.intent : undefined;
|
|
62
|
-
if (ordinaryRoot) {
|
|
75
|
+
if (ordinaryRoot && !configuredRoot) {
|
|
63
76
|
const selected = modelRouteFromCall(downstream);
|
|
64
77
|
if (lock === undefined || !sameExactModelRoute(lock.route, selected) || lock.manualSelectionSeq !== manual?.seq) {
|
|
65
78
|
const generation = (lock?.generation ?? -1) + 1;
|
|
@@ -68,11 +81,12 @@ export function registerModelRouting(ctx, controller, getSettings, agent) {
|
|
|
68
81
|
lock.generation = generation;
|
|
69
82
|
lockedAgents.add(frame.agent);
|
|
70
83
|
}
|
|
84
|
+
captureRequestRoute(frame, decision, "native");
|
|
71
85
|
return downstream;
|
|
72
86
|
}
|
|
73
87
|
const llm = frame.agent.ctx?.get?.("llm") ?? readyCtx.get?.("llm") ?? readyCtx.llm;
|
|
74
88
|
const assembledManual = manual !== undefined && sameModelRoute(downstream, manual.route) && downstream.reasoningEffort === manual.route.reasoningEffort;
|
|
75
|
-
if (manual !== undefined && lock?.manualSelectionSeq !== manual.seq
|
|
89
|
+
if (!configuredRoot && manual !== undefined && lock?.manualSelectionSeq !== manual.seq
|
|
76
90
|
&& (assembledManual || nativeModelSelectionWasAccepted(frame.agent, manual))) {
|
|
77
91
|
const selected = assembledManual ? modelRouteFromCall(downstream) : manual.route;
|
|
78
92
|
const generation = (lock?.generation ?? -1) + 1;
|
|
@@ -82,11 +96,15 @@ export function registerModelRouting(ctx, controller, getSettings, agent) {
|
|
|
82
96
|
lockedAgents.add(frame.agent);
|
|
83
97
|
}
|
|
84
98
|
// A consumed explicit selection must not undo an admitted fallback.
|
|
85
|
-
if (lock?.manualSelectionSeq !== undefined)
|
|
99
|
+
if (!configuredRoot && lock?.manualSelectionSeq !== undefined) {
|
|
100
|
+
captureRequestRoute(frame, decision, "native");
|
|
86
101
|
return applyModelRoute(downstream, lock.route);
|
|
87
|
-
|
|
102
|
+
}
|
|
103
|
+
if (admitted !== undefined) {
|
|
104
|
+
captureRequestRoute(frame, decision, lock?.effortSource);
|
|
88
105
|
return applyModelRoute(downstream, admitted);
|
|
89
|
-
|
|
106
|
+
}
|
|
107
|
+
const accepted = persistedRoleRoute(frame, primary, fallbacks, identity, configuredRoot);
|
|
90
108
|
if (lock !== undefined && accepted !== undefined && !sameExactModelRoute(accepted, lock.route)) {
|
|
91
109
|
lock.route = { ...accepted };
|
|
92
110
|
lock.candidateIndex = lock.candidates.findIndex(candidate => sameExactModelRoute(candidate, accepted));
|
|
@@ -96,16 +114,21 @@ export function registerModelRouting(ctx, controller, getSettings, agent) {
|
|
|
96
114
|
lock.rateLimits = 0;
|
|
97
115
|
}
|
|
98
116
|
if (lock === undefined) {
|
|
99
|
-
const inherited = modelRouteFromCall(downstream);
|
|
117
|
+
const inherited = primary === undefined ? modelRouteFromCall(downstream) : undefined;
|
|
100
118
|
const candidates = invocation?.candidates ?? orderedModelRoutes([primary ?? inherited, ...fallbacks]);
|
|
101
|
-
const
|
|
102
|
-
|
|
119
|
+
const resolver = parameterPolicy.mode === "passthrough" ? readyCtx.get?.("dsmmLlmRoutes") : undefined;
|
|
120
|
+
const choice = configuredRoot ? await selectInitialModelRouteChoice(llm ?? {}, candidates, frame.signal, resolver, parameterPolicy.mode === "native-defaults" ? route => modelRouteFromCall(projectModelRouteParameters(route, primary === undefined && sameExactModelRoute(route, inherited) ? "native" : "dsmm-config", false)) : undefined, decision.assertCurrent) : undefined;
|
|
121
|
+
const selected = choice?.route ?? accepted ?? invocation?.initialRoute ?? (exactPolicy ? await selectInitialModelRoute(llm ?? {}, candidates, frame.signal, resolver, decision.assertCurrent) : inherited);
|
|
122
|
+
decision.assertCurrent();
|
|
103
123
|
frame.signal.throwIfAborted();
|
|
104
|
-
lock = pinRoleRoute(frame.agent, identity, selected, candidates, { preserveCandidates: parameterPolicy.mode === "native-defaults", initialCandidate: accepted ?? invocation?.selectedCandidate });
|
|
124
|
+
lock = pinRoleRoute(frame.agent, identity, selected, candidates, { preserveCandidates: parameterPolicy.mode === "native-defaults", initialCandidate: choice?.requestedRoute ?? accepted ?? invocation?.selectedCandidate });
|
|
125
|
+
if (configuredRoot)
|
|
126
|
+
lock.effortSource = primary === undefined && lock.candidateIndex === 0 ? "native" : "dsmm-config";
|
|
105
127
|
if (accepted !== undefined)
|
|
106
128
|
lock.startupSettled = true;
|
|
107
129
|
lockedAgents.add(frame.agent);
|
|
108
130
|
}
|
|
131
|
+
captureRequestRoute(frame, decision, configuredRoot ? lock.effortSource : undefined);
|
|
109
132
|
return applyModelRoute(downstream, lock.route);
|
|
110
133
|
};
|
|
111
134
|
if (owned) {
|
|
@@ -126,6 +149,7 @@ export function registerModelRouting(ctx, controller, getSettings, agent) {
|
|
|
126
149
|
throw error;
|
|
127
150
|
}
|
|
128
151
|
readyCtx.effect?.(() => () => {
|
|
152
|
+
active = false;
|
|
129
153
|
for (const agent of lockedAgents)
|
|
130
154
|
clearRoleRouteLock(agent);
|
|
131
155
|
lockedAgents.clear();
|
|
@@ -33,6 +33,7 @@ const roleRouting = { primary: route, fallbackRoutes: [route], strategy: null, r
|
|
|
33
33
|
const configFields = {
|
|
34
34
|
permissionControl: schemaFieldShape(permissionControlSchema),
|
|
35
35
|
modelParameters: { passthrough: null },
|
|
36
|
+
rootModelPolicy: null,
|
|
36
37
|
locale: null, modeName: null, section: null, defaultActive: null, promptOrder: null,
|
|
37
38
|
deepseekV4ProCalibration: null, deepseekV4ProDefaultReasoningEffort: null, deepseekFlashCalibration: null, deepseekFlashDefaultReasoningEffort: null,
|
|
38
39
|
deepseekV4ProMaxReasoningPresets: null, deepseekFlashMaxReasoningPresets: null,
|
package/lib/profile-runtime.js
CHANGED
|
@@ -240,7 +240,7 @@ export class DsmmProfileRuntime {
|
|
|
240
240
|
check(maintenanceSignal);
|
|
241
241
|
if (hasOpenTurn(sessionEvents(agent.session)))
|
|
242
242
|
throw new DsmmProfileError("busy", "A session turn is still open.");
|
|
243
|
-
await this.mode.selectIdle(agent, request.active, admitted.settings.defaultActive);
|
|
243
|
+
await this.mode.selectIdle(agent, request.active, admitted.settings.defaultActive, () => check(maintenanceSignal));
|
|
244
244
|
const role = resolveAdmittedDsmmRole(agent, admitted.settings, this.mode.active(agent, admitted.settings.defaultActive));
|
|
245
245
|
const profileModel = role === undefined ? undefined : admitted.settings.roleRouting[role]?.primary;
|
|
246
246
|
const deepwork = this.mode.describe(agent, admitted.settings.defaultActive);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AgentRequestFrame, DshAgent, DshContext } from "./dsh-types.js";
|
|
2
|
+
import type { DsmmSettingsGetter } from "./settings.js";
|
|
3
|
+
import type { DeepworkModeController } from "./state.js";
|
|
4
|
+
import type { DsmmEffortSource } from "./host-llm.js";
|
|
5
|
+
import { resolveAdmittedDsmmRole } from "./role-policy.js";
|
|
6
|
+
/** Shared by selection, recovery and the native prepared-call owner. */
|
|
7
|
+
export interface DsmmRequestRoutingDecision {
|
|
8
|
+
readonly frame: AgentRequestFrame;
|
|
9
|
+
readonly settings: ReturnType<DsmmSettingsGetter>;
|
|
10
|
+
readonly admission: ReturnType<NonNullable<DsmmSettingsGetter["admission"]>> | undefined;
|
|
11
|
+
readonly role: ReturnType<typeof resolveAdmittedDsmmRole>;
|
|
12
|
+
readonly policy: string | undefined;
|
|
13
|
+
readonly configuredRoot: boolean;
|
|
14
|
+
assertPolicyCurrent(): void;
|
|
15
|
+
assertCurrent(): void;
|
|
16
|
+
}
|
|
17
|
+
declare const results: WeakMap<AgentRequestFrame, {
|
|
18
|
+
decision: DsmmRequestRoutingDecision;
|
|
19
|
+
effortSource?: DsmmEffortSource;
|
|
20
|
+
assertCurrent(): void;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function currentRequestRouting(agent: DshAgent): DsmmRequestRoutingDecision | undefined;
|
|
23
|
+
export declare function preparedRequestRouting(frame: AgentRequestFrame): ReturnType<typeof results.get>;
|
|
24
|
+
export declare function captureRequestRouting(frame: AgentRequestFrame, ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, assertOwner: () => void): DsmmRequestRoutingDecision;
|
|
25
|
+
export declare function captureRequestRoute(frame: AgentRequestFrame, decision: DsmmRequestRoutingDecision, effortSource?: DsmmEffortSource): void;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=request-routing.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { resolveAdmittedDsmmRole } from "./role-policy.js";
|
|
2
|
+
import { liveRolePolicyIdentity, roleRouteLock } from "./role-routing.js";
|
|
3
|
+
import { childOwnedSessionEvents, sessionEvents } from "./session-scope.js";
|
|
4
|
+
import { isCurrentRecoveryStep } from "./recovery-policy.js";
|
|
5
|
+
const decisions = new WeakMap();
|
|
6
|
+
const routeAssertions = new WeakMap();
|
|
7
|
+
const results = new WeakMap();
|
|
8
|
+
export function currentRequestRouting(agent) { return decisions.get(agent); }
|
|
9
|
+
export function preparedRequestRouting(frame) { return results.get(frame); }
|
|
10
|
+
export function captureRequestRouting(frame, ctx, controller, getSettings, assertOwner) {
|
|
11
|
+
const settings = getSettings(frame.agent), admission = getSettings.admission?.(frame.agent);
|
|
12
|
+
const role = settings.modules.deepwork.enabled
|
|
13
|
+
? resolveAdmittedDsmmRole(frame.agent, settings, controller.active(frame.agent, settings.defaultActive)) : undefined;
|
|
14
|
+
const policy = liveRolePolicyIdentity(frame.agent, settings, role, admission?.epoch);
|
|
15
|
+
const modeRevision = controller.describe(frame.agent, settings.defaultActive).revision;
|
|
16
|
+
const initialLock = policy === undefined ? undefined : roleRouteLock(frame.agent, policy);
|
|
17
|
+
const initialGeneration = initialLock?.generation;
|
|
18
|
+
const captured = Object.freeze({ ...frame });
|
|
19
|
+
const events = () => captured.agent.session.header?.origin === "subagent" ? childOwnedSessionEvents(captured.agent.session) : sessionEvents(captured.agent.session);
|
|
20
|
+
const currentStep = isCurrentRecoveryStep(events(), captured.turn, captured.step);
|
|
21
|
+
const decision = Object.freeze({ frame: captured, settings, admission, role, policy,
|
|
22
|
+
configuredRoot: captured.agent.session.header?.origin !== "subagent" && admission !== undefined
|
|
23
|
+
&& admission.settings === settings && settings.rootModelPolicy === "configured" && settings.modules.deepwork.enabled && role !== undefined,
|
|
24
|
+
assertPolicyCurrent() {
|
|
25
|
+
assertOwner();
|
|
26
|
+
captured.signal.throwIfAborted();
|
|
27
|
+
if (frame.agent !== captured.agent || frame.signal !== captured.signal || frame.turn !== captured.turn || frame.step !== captured.step) {
|
|
28
|
+
throw new Error("DSMM request frame changed");
|
|
29
|
+
}
|
|
30
|
+
const agents = ctx.get?.("agents");
|
|
31
|
+
const current = getSettings(captured.agent), currentAdmission = getSettings.admission?.(captured.agent);
|
|
32
|
+
const currentRole = current.modules.deepwork.enabled
|
|
33
|
+
? resolveAdmittedDsmmRole(captured.agent, current, controller.active(captured.agent, current.defaultActive)) : undefined;
|
|
34
|
+
if (agents !== undefined && (captured.agent.id === undefined || agents.get(captured.agent.id) !== captured.agent)
|
|
35
|
+
|| current !== settings || currentAdmission !== admission || currentRole !== role
|
|
36
|
+
|| controller.describe(captured.agent, current.defaultActive).revision !== modeRevision
|
|
37
|
+
|| liveRolePolicyIdentity(captured.agent, current, currentRole, currentAdmission?.epoch) !== policy
|
|
38
|
+
|| currentStep && !isCurrentRecoveryStep(events(), captured.turn, captured.step)) {
|
|
39
|
+
throw new Error("DSMM request routing admission is no longer current");
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
assertCurrent() {
|
|
43
|
+
decision.assertPolicyCurrent();
|
|
44
|
+
if (decisions.get(captured.agent) !== decision)
|
|
45
|
+
throw new Error("DSMM request routing was superseded");
|
|
46
|
+
const assertRoute = routeAssertions.get(decision);
|
|
47
|
+
if (assertRoute !== undefined)
|
|
48
|
+
assertRoute();
|
|
49
|
+
else if (decision.configuredRoot && initialLock !== undefined
|
|
50
|
+
&& (roleRouteLock(captured.agent, policy) !== initialLock || initialLock.generation !== initialGeneration)) {
|
|
51
|
+
throw new Error("DSMM request route generation changed");
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
decisions.set(frame.agent, decision);
|
|
56
|
+
return decision;
|
|
57
|
+
}
|
|
58
|
+
export function captureRequestRoute(frame, decision, effortSource) {
|
|
59
|
+
decision.assertCurrent();
|
|
60
|
+
const lock = decision.policy === undefined ? undefined : roleRouteLock(frame.agent, decision.policy);
|
|
61
|
+
const generation = lock?.generation;
|
|
62
|
+
routeAssertions.set(decision, () => {
|
|
63
|
+
const current = decision.policy === undefined ? undefined : roleRouteLock(frame.agent, decision.policy);
|
|
64
|
+
if (current !== lock || current?.generation !== generation)
|
|
65
|
+
throw new Error("DSMM request route generation changed");
|
|
66
|
+
});
|
|
67
|
+
results.set(frame, Object.freeze({ decision, effortSource, assertCurrent: decision.assertCurrent }));
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=request-routing.js.map
|
package/lib/role-llm-runtime.js
CHANGED
|
@@ -3,6 +3,8 @@ import { captureDsmmEffortSource, requiresDsmmCallAdmission, snapshotDsmmCall }
|
|
|
3
3
|
import { resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
4
4
|
import { modelRouteFromCall, projectModelRouteParameters } from "./role-llm.js";
|
|
5
5
|
import { prepareDsmmRequest } from "./model-routing.js";
|
|
6
|
+
import { preparedRequestRouting } from "./request-routing.js";
|
|
7
|
+
import { roleRouteLock } from "./role-routing.js";
|
|
6
8
|
/** Connect the cold Host LLM owner to the existing exact Agent/role admission authority. */
|
|
7
9
|
export function createDsmmRoleLlmOwner(ctx, providers) {
|
|
8
10
|
const nativeFallback = async (frame, proposal) => {
|
|
@@ -21,7 +23,7 @@ export function createDsmmRoleLlmOwner(ctx, providers) {
|
|
|
21
23
|
if (core === undefined) {
|
|
22
24
|
return nativeFallback(frame, proposal);
|
|
23
25
|
}
|
|
24
|
-
|
|
26
|
+
let admission = await core.admit(frame);
|
|
25
27
|
if (admission === undefined) {
|
|
26
28
|
return nativeFallback(frame, proposal);
|
|
27
29
|
}
|
|
@@ -35,9 +37,18 @@ export function createDsmmRoleLlmOwner(ctx, providers) {
|
|
|
35
37
|
const routed = await prepareDsmmRequest(frame, proposal, admission.assertCurrent);
|
|
36
38
|
admission.assertCurrent();
|
|
37
39
|
frame.signal.throwIfAborted();
|
|
38
|
-
const
|
|
40
|
+
const routing = preparedRequestRouting(frame);
|
|
41
|
+
if (routing === undefined)
|
|
42
|
+
throw new Error("DSMM request lost its routing capture");
|
|
43
|
+
const originalAdmission = admission;
|
|
44
|
+
admission = Object.freeze({ ...originalAdmission, assertCurrent() { originalAdmission.assertCurrent(); routing.assertCurrent(); } });
|
|
45
|
+
const effortSource = routing.effortSource ?? captureDsmmEffortSource(frame.agent);
|
|
39
46
|
const config = snapshotDsmmCall(projectModelRouteParameters(modelRouteFromCall(routed), effortSource, policy.mode !== "native-defaults"));
|
|
40
47
|
admission.assertCurrent();
|
|
48
|
+
if (routing.decision.configuredRoot && routing.decision.policy !== undefined) {
|
|
49
|
+
const lock = roleRouteLock(agent, routing.decision.policy);
|
|
50
|
+
lock.route = modelRouteFromCall(config);
|
|
51
|
+
}
|
|
41
52
|
if (policy.mode !== "passthrough") {
|
|
42
53
|
await ctx.get("llm").resolveCallConfig(config, frame.signal);
|
|
43
54
|
admission.assertCurrent();
|
|
@@ -51,6 +62,8 @@ export function createDsmmRoleLlmOwner(ctx, providers) {
|
|
|
51
62
|
return { kind: "stock", admission, config, effortSource };
|
|
52
63
|
}
|
|
53
64
|
catch (error) {
|
|
65
|
+
admission.assertCurrent();
|
|
66
|
+
frame.signal.throwIfAborted();
|
|
54
67
|
if (!(error instanceof LlmError) || error.code !== "UNSUPPORTED_OPTION"
|
|
55
68
|
&& (error.code !== "UNSUPPORTED_REASONING_EFFORT" || effortSource === "native"))
|
|
56
69
|
throw error;
|
package/lib/role-routing.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface RoleRouteLock {
|
|
|
17
17
|
switches: number;
|
|
18
18
|
totalDelayMs: number;
|
|
19
19
|
manualSelectionSeq?: number;
|
|
20
|
+
effortSource?: "native" | "dsmm-config";
|
|
20
21
|
}
|
|
21
22
|
export interface NativeModelSelectionIntent {
|
|
22
23
|
seq: number;
|
|
@@ -31,8 +32,8 @@ export declare function nativeModelSelectionWasAccepted(agent: DshAgent, intent:
|
|
|
31
32
|
export declare function isUnavailableRouteFailure(error: unknown, nativeRequestFailure?: boolean): boolean;
|
|
32
33
|
export declare function orderedModelRoutes(candidates: readonly DsmmModelRoute[]): DsmmModelRoute[];
|
|
33
34
|
/** Exact metadata preparation, never a completion or advisory catalog health check. */
|
|
34
|
-
export declare function selectInitialModelRoute(llm: DshLlmRuntime, candidates: readonly DsmmModelRoute[], signal?: AbortSignal, resolver?: DsmmLlmRouteResolver): Promise<DsmmModelRoute>;
|
|
35
|
-
export declare function selectInitialModelRouteChoice(llm: DshLlmRuntime, candidates: readonly DsmmModelRoute[], signal?: AbortSignal, resolver?: DsmmLlmRouteResolver): Promise<{
|
|
35
|
+
export declare function selectInitialModelRoute(llm: DshLlmRuntime, candidates: readonly DsmmModelRoute[], signal?: AbortSignal, resolver?: DsmmLlmRouteResolver, assertCurrent?: () => void): Promise<DsmmModelRoute>;
|
|
36
|
+
export declare function selectInitialModelRouteChoice(llm: DshLlmRuntime, candidates: readonly DsmmModelRoute[], signal?: AbortSignal, resolver?: DsmmLlmRouteResolver, project?: (route: DsmmModelRoute) => DsmmModelRoute, assertCurrent?: () => void): Promise<{
|
|
36
37
|
route: DsmmModelRoute;
|
|
37
38
|
requestedRoute: DsmmModelRoute;
|
|
38
39
|
}>;
|
|
@@ -52,5 +53,5 @@ export declare function effectiveRoleFallbackRoutes(settings: DsmmSettings, role
|
|
|
52
53
|
export declare function applyModelRoute(config: DshLlmCallConfig, route: DsmmModelRoute): DshLlmCallConfig;
|
|
53
54
|
export declare function sameModelRoute(left: Pick<DsmmModelRoute, "provider" | "model">, right: Pick<DsmmModelRoute, "provider" | "model">): boolean;
|
|
54
55
|
/** Accepted post-policy route changes are durable host/recovery ownership, not a new primary request. */
|
|
55
|
-
export declare function persistedRoleRoute(frame: Pick<AgentRequestFrame, "agent">, primary: DsmmModelRoute | undefined, fallbacks?: readonly DsmmModelRoute[], identity?: string): DsmmModelRoute | undefined;
|
|
56
|
+
export declare function persistedRoleRoute(frame: Pick<AgentRequestFrame, "agent">, primary: DsmmModelRoute | undefined, fallbacks?: readonly DsmmModelRoute[], identity?: string, configuredRoot?: boolean): DsmmModelRoute | undefined;
|
|
56
57
|
//# sourceMappingURL=role-routing.d.ts.map
|
package/lib/role-routing.js
CHANGED
|
@@ -51,26 +51,30 @@ export function orderedModelRoutes(candidates) {
|
|
|
51
51
|
return routes;
|
|
52
52
|
}
|
|
53
53
|
/** Exact metadata preparation, never a completion or advisory catalog health check. */
|
|
54
|
-
export async function selectInitialModelRoute(llm, candidates, signal, resolver) {
|
|
55
|
-
return (await selectInitialModelRouteChoice(llm, candidates, signal, resolver)).route;
|
|
54
|
+
export async function selectInitialModelRoute(llm, candidates, signal, resolver, assertCurrent) {
|
|
55
|
+
return (await selectInitialModelRouteChoice(llm, candidates, signal, resolver, undefined, assertCurrent)).route;
|
|
56
56
|
}
|
|
57
|
-
export async function selectInitialModelRouteChoice(llm, candidates, signal, resolver) {
|
|
57
|
+
export async function selectInitialModelRouteChoice(llm, candidates, signal, resolver, project, assertCurrent) {
|
|
58
58
|
if (resolver === undefined && llm.resolveCallConfig === undefined)
|
|
59
59
|
throw new Error("dsmm route admission requires the Host model service");
|
|
60
60
|
let unavailable;
|
|
61
61
|
for (const route of orderedModelRoutes(candidates)) {
|
|
62
|
+
assertCurrent?.();
|
|
62
63
|
signal?.throwIfAborted();
|
|
63
64
|
try {
|
|
64
65
|
if (resolver === undefined && llm.listProviders !== undefined && !llm.listProviders().some(provider => provider.id === route.provider))
|
|
65
66
|
throw new DsmmMissingProviderError();
|
|
66
|
-
const
|
|
67
|
-
const
|
|
67
|
+
const projected = project?.(route) ?? route;
|
|
68
|
+
const call = modelRouteToCall(projected);
|
|
69
|
+
const prepared = resolver === undefined ? await llm.resolveCallConfig(call, signal) : await resolver.resolveRoute(projected, signal);
|
|
70
|
+
assertCurrent?.();
|
|
68
71
|
if (resolver === undefined && call.customParameters !== undefined)
|
|
69
72
|
throw new LlmError("Raw route parameters require their declared Host provider owner", "UNSUPPORTED_ROUTE_PARAMETERS");
|
|
70
73
|
signal?.throwIfAborted();
|
|
71
74
|
return { route: canonicalRoute(prepared), requestedRoute: canonicalRoute(route) };
|
|
72
75
|
}
|
|
73
76
|
catch (error) {
|
|
77
|
+
assertCurrent?.();
|
|
74
78
|
signal?.throwIfAborted();
|
|
75
79
|
if (!isUnavailableRouteFailure(error))
|
|
76
80
|
throw error;
|
|
@@ -96,7 +100,7 @@ export function roleRouteRuntimeState(agent, settings, role, epoch) {
|
|
|
96
100
|
const resolved = resolveRoleRuntimePolicy(settings, role);
|
|
97
101
|
const identity = liveRolePolicyIdentity(agent, settings, role, epoch);
|
|
98
102
|
const lock = identity === undefined ? undefined : roleRouteLock(agent, identity);
|
|
99
|
-
return { ...(role === undefined ? {} : { role }), strategy: agent.session.header?.origin === "subagent" ? resolved.strategy : "startup-lock", rateLimit: { ...resolved.rateLimit },
|
|
103
|
+
return { ...(role === undefined ? {} : { role }), strategy: agent.session.header?.origin === "subagent" || epoch !== undefined && settings.rootModelPolicy === "configured" && settings.modules.deepwork.enabled && role !== undefined ? resolved.strategy : "startup-lock", rateLimit: { ...resolved.rateLimit },
|
|
100
104
|
...(lock === undefined ? {} : { route: { ...lock.route } }), retries: lock?.retries ?? 0,
|
|
101
105
|
rateLimitFailures: lock?.rateLimits ?? 0, switches: lock?.switches ?? 0, totalDelayMs: lock?.totalDelayMs ?? 0 };
|
|
102
106
|
}
|
|
@@ -107,7 +111,7 @@ export function liveRolePolicyIdentity(agent, settings, role, epoch) {
|
|
|
107
111
|
}
|
|
108
112
|
const policy = settings.roleRouting[role];
|
|
109
113
|
const resolved = resolveRoleRuntimePolicy(settings, role);
|
|
110
|
-
const fields = { role, epoch, primary: policy?.primary, levels: policy?.levels,
|
|
114
|
+
const fields = { role, epoch, rootModelPolicy: settings.rootModelPolicy, deepworkEnabled: settings.modules.deepwork.enabled, primary: policy?.primary, levels: policy?.levels,
|
|
111
115
|
fallbackSource: resolved.fallbackSource, fallbackRoutes: resolved.fallbackRoutes,
|
|
112
116
|
strategy: resolved.strategy, rateLimit: resolved.rateLimit, modelParameters: settings.modelParameters,
|
|
113
117
|
recovery: { enabled: settings.runtimeRecovery.enabled, retryOnStatusCodes: settings.runtimeRecovery.retryOnStatusCodes,
|
|
@@ -190,7 +194,7 @@ export function sameModelRoute(left, right) {
|
|
|
190
194
|
return left.provider === right.provider && left.model === right.model;
|
|
191
195
|
}
|
|
192
196
|
/** Accepted post-policy route changes are durable host/recovery ownership, not a new primary request. */
|
|
193
|
-
export function persistedRoleRoute(frame, primary, fallbacks = [], identity) {
|
|
197
|
+
export function persistedRoleRoute(frame, primary, fallbacks = [], identity, configuredRoot = false) {
|
|
194
198
|
const currentIdentity = agentPolicies.get(frame.agent)?.identity;
|
|
195
199
|
const events = policyEvents(frame);
|
|
196
200
|
let matchingPolicy = false;
|
|
@@ -216,8 +220,11 @@ export function persistedRoleRoute(frame, primary, fallbacks = [], identity) {
|
|
|
216
220
|
continue;
|
|
217
221
|
selected = modelRouteFromHeader(header);
|
|
218
222
|
}
|
|
219
|
-
|
|
220
|
-
|
|
223
|
+
if (configuredRoot) {
|
|
224
|
+
const lock = identity === undefined ? undefined : roleRouteLock(frame.agent, identity);
|
|
225
|
+
return selected !== undefined && lock !== undefined && lock.candidateIndex >= 0 && sameExactModelRoute(selected, lock.route) ? lock.route : undefined;
|
|
226
|
+
}
|
|
227
|
+
// Native/child routes retain durable Host ownership after a matching policy.
|
|
221
228
|
return selected === undefined ? undefined : [primary, ...fallbacks].find((route) => route !== undefined && sameExactModelRoute(route, selected)) ?? selected;
|
|
222
229
|
}
|
|
223
230
|
function isRecord(value) {
|
package/lib/runtime-recovery.js
CHANGED
|
@@ -7,6 +7,7 @@ import { childOwnedSessionEvents, resolveSelectedAgentPreset, sessionEvents } fr
|
|
|
7
7
|
import { resolveAdmittedDsmmRole as resolveEffectiveDsmmRole } from "./role-policy.js";
|
|
8
8
|
import { resolveRoleRuntimePolicy } from "./routing-policy.js";
|
|
9
9
|
import { configuredModelParameterPolicy, resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
10
|
+
import { currentRequestRouting } from "./request-routing.js";
|
|
10
11
|
const installedContexts = new WeakSet();
|
|
11
12
|
const RECOVERY_WARNING = "dsmm runtime recovery refused an unproven or exhausted retry";
|
|
12
13
|
const CONTINUATION_WARNING = "dsmm runtime recovery continuation steering failed for turn";
|
|
@@ -23,7 +24,7 @@ function isRecord(value) {
|
|
|
23
24
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24
25
|
}
|
|
25
26
|
function isRateLimit(failure) {
|
|
26
|
-
if (["AUTH", "MISSING_CREDENTIAL", "INVALID_CREDENTIAL", "QUOTA", "ACCOUNT_QUOTA", "CONTEXT_WINDOW_EXCEEDED", "INVALID_ARGS", "CANCELLED", "ABORTED"].includes(failure.code) || failure.status === 402)
|
|
27
|
+
if (["AUTH", "PERMISSION", "PERMISSION_DENIED", "FORBIDDEN", "MISSING_CREDENTIAL", "INVALID_CREDENTIAL", "QUOTA", "ACCOUNT_QUOTA", "CONTEXT_WINDOW_EXCEEDED", "INVALID_ARGS", "CANCELLED", "ABORTED"].includes(failure.code) || failure.status === 401 || failure.status === 403 || failure.status === 402)
|
|
27
28
|
return false;
|
|
28
29
|
return failure.code === "RATE_LIMIT" || failure.status === 429;
|
|
29
30
|
}
|
|
@@ -106,6 +107,14 @@ export function registerRuntimeRecovery(ctx, controller, getSettings, bindReques
|
|
|
106
107
|
if (!active || !live(agent) || !getSettings(agent).modules.deepwork.enabled)
|
|
107
108
|
return;
|
|
108
109
|
if (frame.type === "start") {
|
|
110
|
+
const decision = currentRequestRouting(agent);
|
|
111
|
+
try {
|
|
112
|
+
decision?.assertCurrent();
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
attemptsByAgent.delete(agent);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
109
118
|
const settings = getSettings(agent);
|
|
110
119
|
const role = resolveEffectiveDsmmRole(agent, settings, controller.active(agent, settings.defaultActive));
|
|
111
120
|
const policy = liveRolePolicyIdentity(agent, settings, role, getSettings.admission?.(agent).epoch);
|
|
@@ -116,7 +125,7 @@ export function registerRuntimeRecovery(ctx, controller, getSettings, bindReques
|
|
|
116
125
|
return;
|
|
117
126
|
}
|
|
118
127
|
const previous = attemptsByAgent.get(agent);
|
|
119
|
-
const attempt = { id: frame.attemptId, turn: frame.turn, step: frame.step, revision: frame.revision, chunks: 0,
|
|
128
|
+
const attempt = { decision, id: frame.attemptId, turn: frame.turn, step: frame.step, revision: frame.revision, chunks: 0,
|
|
120
129
|
route: modelRouteFromHeader(header), header, policy, generation: lock?.generation, manualSelectionSeq: lock?.manualSelectionSeq,
|
|
121
130
|
valid: Number.isSafeInteger(frame.revision) && frame.revision >= 1 && (previous === undefined || frame.revision === previous.revision + 1), output: false, consumed: false };
|
|
122
131
|
attemptsByAgent.set(agent, attempt);
|
|
@@ -158,35 +167,52 @@ export function registerRuntimeRecovery(ctx, controller, getSettings, bindReques
|
|
|
158
167
|
if (!active || !live(frame.agent))
|
|
159
168
|
return downstream;
|
|
160
169
|
const pending = pendingByAgent.get(frame.agent);
|
|
161
|
-
if (pending === undefined
|
|
170
|
+
if (pending === undefined)
|
|
162
171
|
return downstream;
|
|
163
|
-
|
|
172
|
+
const decision = currentRequestRouting(frame.agent);
|
|
173
|
+
decision?.assertCurrent();
|
|
174
|
+
if (pending.turn !== frame.turn || pending.step !== frame.step
|
|
175
|
+
|| !isCurrentRecoveryStep(recoveryEvents(frame.agent), pending.turn, pending.step)) {
|
|
176
|
+
pendingByAgent.delete(frame.agent);
|
|
177
|
+
return downstream;
|
|
178
|
+
}
|
|
179
|
+
pending.attempt.decision?.assertPolicyCurrent();
|
|
180
|
+
if (pending.attempt.decision !== undefined && (decision?.policy !== pending.attempt.decision.policy
|
|
181
|
+
|| decision?.admission !== pending.attempt.decision.admission || frame.signal !== pending.attempt.decision.frame.signal)) {
|
|
182
|
+
pendingByAgent.delete(frame.agent);
|
|
183
|
+
throw new Error("DSMM retry routing capture changed");
|
|
184
|
+
}
|
|
185
|
+
if (!decision?.configuredRoot && latestNativeModelSelection(frame.agent)?.seq !== pending.manualSelectionSeq) {
|
|
164
186
|
pendingByAgent.delete(frame.agent);
|
|
165
187
|
throw new Error("dsmm retry was superseded by an explicit native model selection");
|
|
166
188
|
}
|
|
167
|
-
if (frame.signal.aborted
|
|
189
|
+
if (frame.signal.aborted) {
|
|
168
190
|
pendingByAgent.delete(frame.agent);
|
|
169
191
|
return downstream;
|
|
170
192
|
}
|
|
171
|
-
if (pending.turn !== frame.turn || pending.step !== frame.step)
|
|
172
|
-
return downstream;
|
|
173
193
|
if (pending.policy !== undefined) {
|
|
174
194
|
const settings = getSettings(frame.agent);
|
|
175
195
|
const role = resolveEffectiveDsmmRole(frame.agent, settings, controller.active(frame.agent, settings.defaultActive));
|
|
176
196
|
if (role !== pending.role || liveRolePolicyIdentity(frame.agent, settings, role, getSettings.admission?.(frame.agent).epoch) !== pending.policy) {
|
|
177
197
|
pendingByAgent.delete(frame.agent);
|
|
198
|
+
if (decision?.configuredRoot)
|
|
199
|
+
throw new Error("DSMM retry policy is no longer current");
|
|
178
200
|
return downstream;
|
|
179
201
|
}
|
|
180
202
|
}
|
|
181
203
|
const accepted = frame.agent.session.requestHeader?.();
|
|
182
204
|
const lock = pending.policy === undefined ? undefined : roleRouteLock(frame.agent, pending.policy);
|
|
205
|
+
const failure = pending.attempt.failure;
|
|
183
206
|
if (!active || lock === undefined || lock.generation !== pending.generation || attemptsByAgent.get(frame.agent) !== pending.attempt
|
|
184
|
-
|| accepted === undefined || !sameExactModelRoute(modelRouteFromHeader(accepted), pending.failedRoute)
|
|
207
|
+
|| accepted === undefined || !sameExactModelRoute(modelRouteFromHeader(accepted), pending.failedRoute)
|
|
208
|
+
|| decision?.configuredRoot && (failure === undefined || !positiveNoOutput({ ...frame, provider: pending.failedRoute.provider, failure }, pending.attempt, true))) {
|
|
185
209
|
pendingByAgent.delete(frame.agent);
|
|
210
|
+
if (decision?.configuredRoot)
|
|
211
|
+
throw new Error("DSMM retry evidence is no longer current");
|
|
186
212
|
return downstream;
|
|
187
213
|
}
|
|
188
214
|
pendingByAgent.delete(frame.agent);
|
|
189
|
-
if (frame.agent.session.header?.origin !== "subagent")
|
|
215
|
+
if (frame.agent.session.header?.origin !== "subagent" && !decision?.configuredRoot)
|
|
190
216
|
return downstream;
|
|
191
217
|
lock.route = { ...pending.route };
|
|
192
218
|
recordAdmittedRecoveryRoute(frame, pending.route);
|
|
@@ -202,6 +228,7 @@ export function registerRuntimeRecovery(ctx, controller, getSettings, bindReques
|
|
|
202
228
|
let settings;
|
|
203
229
|
let role;
|
|
204
230
|
try {
|
|
231
|
+
attemptsByAgent.get(frame.agent)?.decision?.assertCurrent();
|
|
205
232
|
settings = getSettings(frame.agent);
|
|
206
233
|
if (!settings.modules.deepwork.enabled)
|
|
207
234
|
return await next();
|
|
@@ -209,7 +236,7 @@ export function registerRuntimeRecovery(ctx, controller, getSettings, bindReques
|
|
|
209
236
|
}
|
|
210
237
|
catch {
|
|
211
238
|
const prior = attemptsByAgent.get(frame.agent);
|
|
212
|
-
return isRateLimit(frame.failure) && prior?.policy !== undefined ? undefined : await next();
|
|
239
|
+
return (isRateLimit(frame.failure) || isUnavailableRouteFailure(frame.failure, true)) && prior?.policy !== undefined ? undefined : await next();
|
|
213
240
|
}
|
|
214
241
|
const unavailable = isUnavailableRouteFailure(frame.failure, true);
|
|
215
242
|
if (role === undefined || (!isRateLimit(frame.failure) && !unavailable))
|
|
@@ -218,13 +245,23 @@ export function registerRuntimeRecovery(ctx, controller, getSettings, bindReques
|
|
|
218
245
|
const policy = liveRolePolicyIdentity(frame.agent, settings, role, getSettings.admission?.(frame.agent).epoch);
|
|
219
246
|
const lock = policy === undefined ? undefined : roleRouteLock(frame.agent, policy);
|
|
220
247
|
const attempt = attemptsByAgent.get(frame.agent);
|
|
248
|
+
const decision = attempt?.decision;
|
|
249
|
+
decision?.assertCurrent();
|
|
221
250
|
const header = frame.agent.session.requestHeader?.();
|
|
222
251
|
if (!active || frame.signal.aborted || lock === undefined || header === undefined
|
|
223
252
|
|| header.config.provider !== frame.provider || !sameExactModelRoute(modelRouteFromHeader(header), lock.route)
|
|
224
253
|
|| attempt === undefined || attempt.policy !== policy || attempt.generation !== lock.generation
|
|
225
|
-
|| latestNativeModelSelection(frame.agent)?.seq !== attempt.manualSelectionSeq
|
|
254
|
+
|| !decision?.configuredRoot && latestNativeModelSelection(frame.agent)?.seq !== attempt.manualSelectionSeq
|
|
226
255
|
|| !isCurrentRecoveryStep(recoveryEvents(frame.agent), frame.turn, frame.step) || !positiveNoOutput(frame, attempt))
|
|
227
256
|
return undefined;
|
|
257
|
+
const expectedGeneration = lock.generation;
|
|
258
|
+
const assertRouteCurrent = () => {
|
|
259
|
+
decision?.assertCurrent();
|
|
260
|
+
frame.signal.throwIfAborted();
|
|
261
|
+
if (!active || !live(frame.agent) || roleRouteLock(frame.agent, policy) !== lock || lock.generation !== expectedGeneration) {
|
|
262
|
+
throw new Error("DSMM recovery route generation changed");
|
|
263
|
+
}
|
|
264
|
+
};
|
|
228
265
|
attempt.consumed = true;
|
|
229
266
|
const resolved = resolveRoleRuntimePolicy(settings, role);
|
|
230
267
|
const bounds = resolved.rateLimit;
|
|
@@ -239,7 +276,7 @@ export function registerRuntimeRecovery(ctx, controller, getSettings, bindReques
|
|
|
239
276
|
else {
|
|
240
277
|
lock.startupSettled = true;
|
|
241
278
|
lock.rateLimits += 1;
|
|
242
|
-
switching = frame.agent.session.header?.origin === "subagent"
|
|
279
|
+
switching = (frame.agent.session.header?.origin === "subagent" || decision?.configuredRoot === true)
|
|
243
280
|
&& resolved.strategy === "rate-limit-fallback" && lock.rateLimits >= bounds.switchAfterRateLimits;
|
|
244
281
|
if (!switching && lock.retries >= bounds.maxRetries)
|
|
245
282
|
return undefined;
|
|
@@ -254,9 +291,10 @@ export function registerRuntimeRecovery(ctx, controller, getSettings, bindReques
|
|
|
254
291
|
const llm = frame.agent.ctx?.get?.("llm") ?? ctx.get?.("llm") ?? ctx.llm;
|
|
255
292
|
const admission = getSettings.admission?.(frame.agent);
|
|
256
293
|
const parameterPolicy = admission === undefined ? configuredModelParameterPolicy(settings) : resolvedModelParameterPolicy(admission);
|
|
257
|
-
const selected = await selectInitialModelRouteChoice(llm ?? {}, candidates, frame.signal, parameterPolicy.mode === "passthrough" ? ctx.get?.("dsmmLlmRoutes") : undefined);
|
|
294
|
+
const selected = await selectInitialModelRouteChoice(llm ?? {}, candidates, frame.signal, parameterPolicy.mode === "passthrough" ? ctx.get?.("dsmmLlmRoutes") : undefined, decision?.configuredRoot && parameterPolicy.mode === "native-defaults" ? route => modelRouteFromCall(projectModelRouteParameters(route, "dsmm-config", false)) : undefined, assertRouteCurrent);
|
|
295
|
+
assertRouteCurrent();
|
|
258
296
|
route = parameterPolicy.mode === "native-defaults"
|
|
259
|
-
? modelRouteFromCall(projectModelRouteParameters(selected.route, selected.requestedRoute.reasoningEffort === undefined ? "dsmm-config" : "native", false))
|
|
297
|
+
? modelRouteFromCall(projectModelRouteParameters(selected.route, decision?.configuredRoot || selected.requestedRoute.reasoningEffort === undefined ? "dsmm-config" : "native", false))
|
|
260
298
|
: selected.route;
|
|
261
299
|
candidateIndex = index + 1 + candidates.findIndex(candidate => sameExactModelRoute(candidate, selected.requestedRoute));
|
|
262
300
|
}
|
|
@@ -267,7 +305,6 @@ export function registerRuntimeRecovery(ctx, controller, getSettings, bindReques
|
|
|
267
305
|
if (delay > bounds.maxDelayMs || delay > bounds.maxTotalDelayMs - lock.totalDelayMs)
|
|
268
306
|
return undefined;
|
|
269
307
|
lock.totalDelayMs += delay;
|
|
270
|
-
const expectedGeneration = lock.generation;
|
|
271
308
|
if (delay > 0) {
|
|
272
309
|
const wait = new AbortController();
|
|
273
310
|
waits.add(wait);
|
|
@@ -286,16 +323,19 @@ export function registerRuntimeRecovery(ctx, controller, getSettings, bindReques
|
|
|
286
323
|
}
|
|
287
324
|
}
|
|
288
325
|
const currentSettings = getSettings(frame.agent);
|
|
326
|
+
decision?.assertCurrent();
|
|
289
327
|
const currentRole = resolveEffectiveDsmmRole(frame.agent, currentSettings, controller.active(frame.agent, currentSettings.defaultActive));
|
|
290
328
|
if (!active || !live(frame.agent) || frame.signal.aborted || currentRole !== role
|
|
291
329
|
|| liveRolePolicyIdentity(frame.agent, currentSettings, currentRole, getSettings.admission?.(frame.agent).epoch) !== policy
|
|
292
330
|
|| roleRouteLock(frame.agent, policy) !== lock || lock.generation !== expectedGeneration
|
|
293
331
|
|| attemptsByAgent.get(frame.agent) !== attempt || !isCurrentRecoveryStep(recoveryEvents(frame.agent), frame.turn, frame.step)
|
|
294
|
-
|| latestNativeModelSelection(frame.agent)?.seq !== attempt.manualSelectionSeq
|
|
332
|
+
|| !decision?.configuredRoot && latestNativeModelSelection(frame.agent)?.seq !== attempt.manualSelectionSeq
|
|
295
333
|
|| !positiveNoOutput(frame, attempt, true)
|
|
296
334
|
|| !sameExactModelRoute(modelRouteFromHeader(frame.agent.session.requestHeader?.()), attempt.route))
|
|
297
335
|
return undefined;
|
|
298
336
|
if (switching) {
|
|
337
|
+
if (decision?.configuredRoot)
|
|
338
|
+
lock.effortSource = "dsmm-config";
|
|
299
339
|
lock.candidateIndex = candidateIndex;
|
|
300
340
|
lock.generation += 1;
|
|
301
341
|
if (!unavailable)
|