johns-harness 2026.11.13 → 2026.11.14
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 +13 -0
- package/dist/compact-B247y5Qt.js +9 -1
- package/dist/pi-embedded-C6ITuRXf.js +9 -1
- package/dist/pi-embedded-DoQsYfIY.js +9 -1
- package/dist/plugin-sdk/dispatch-BP0viZiL.js +9 -1
- package/dist/plugin-sdk/dispatch-CQsjmw7g.js +9 -1
- package/dist/plugin-sdk/dispatch-Cerq29sy.js +9 -1
- package/dist/plugin-sdk/dispatch-Cndjtt0g.js +9 -1
- package/dist/plugin-sdk/dispatch-UogiJYul.js +9 -1
- package/dist/plugin-sdk/reply-DbZnH8-h.js +9 -1
- package/dist/reply-C5LKjXcC.js +9 -1
- package/dist/subscription-call-auth.js +193 -0
- package/docs/PATCHES.md +23 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2026.11.14
|
|
4
|
+
|
|
5
|
+
### Sub-agents and swarms return to the subscription mid-run; status names the profile that served each call
|
|
6
|
+
|
|
7
|
+
- **Cause:** a run chose its auth profile once, at start, and never moved back. A sub-agent or swarm member is one run of hundreds of model calls, so one that started while the Claude subscription was cooling after a rate limit stayed on the paid API key until it ended (seven hours and 470 calls in the reported case). The main session re-picked every turn, which is why it looked fine. Sub-agents that started on a healthy subscription were already served by it.
|
|
8
|
+
- **Fix (Family 98):** the profile is chosen before every model call. A run on the API key moves back to the subscription on the first call after it is usable again. Leaving the subscription is still only the existing failure-driven fallback, and a run holds off 1, 5, 25 then 60 minutes before returning after the subscription fails inside it. User-locked profiles and other providers are unchanged.
|
|
9
|
+
- **Status:** every assistant record in the transcript now carries the profile that served it (`authProfileId`, `authMode`, and the fallback reason when a paid key served). `/status` reads that record, so a card for a run still in flight shows what its last call used, for example `api-key (anthropic:default) [API fallback: subscription in cooldown]`, and adds per-profile call counts when a run used both.
|
|
10
|
+
- The stamp is transcript metadata only. It is never sent to a provider and adds nothing to the context.
|
|
11
|
+
- **Not changed:** calls made while the subscription is rate limited or cooling still go to the API key.
|
|
12
|
+
- **Validation:** isolated gateway with a real spawned sub-agent and a two-member swarm against a mock Anthropic endpoint with fixture credentials: the unpatched tree stays on `x-api-key` for every call; this release goes `x-api-key, x-api-key, Bearer, Bearer` per run once the cooldown ends, and Bearer from the first call when spawned healthy. No live Anthropic call was made with the real subscription credential.
|
|
13
|
+
- **Gates:** verifier **597 pass, 0 fail**; full suite **1,398 pass, 0 fail, 5 skip** (1,403 tests); packed-artifact check passed.
|
|
14
|
+
- **Rollback:** `npm i -g johns-harness@2026.11.13`.
|
|
15
|
+
|
|
3
16
|
## 2026.11.13
|
|
4
17
|
|
|
5
18
|
### Gemini 4 Hydrogen native chat and xhigh
|
package/dist/compact-B247y5Qt.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCallAuth, withServedAuthProfile, formatServedAuthLabel } from "./subscription-call-auth.js"; // JOHNNESS_PATCH_CALL_AUTH_98
|
|
1
2
|
// JOHNNESS_PATCH_SUBSCRIPTION_USAGE_93 dist/compact-B247y5Qt.js
|
|
2
3
|
import { loadSubscriptionStatus } from "./subscription-usage.js";
|
|
3
4
|
import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "./anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
@@ -17531,6 +17532,7 @@ async function runEmbeddedAttempt(params) {
|
|
|
17531
17532
|
activeSession.agent.streamFn = wrapStreamFnTrimToolCallNames(activeSession.agent.streamFn, allowedToolNames);
|
|
17532
17533
|
if (isXaiProvider(params.provider, params.modelId)) activeSession.agent.streamFn = wrapStreamFnDecodeXaiToolCallArguments(activeSession.agent.streamFn);
|
|
17533
17534
|
if (anthropicPayloadLogger) activeSession.agent.streamFn = anthropicPayloadLogger.wrapStreamFn(activeSession.agent.streamFn);
|
|
17535
|
+
if (params.callAuth) activeSession.agent.streamFn = params.callAuth.wrapStreamFn(activeSession.agent.streamFn); // JOHNNESS_PATCH_CALL_AUTH_98: outermost, every model call picks its credential
|
|
17534
17536
|
try {
|
|
17535
17537
|
const prior = await sanitizeSessionHistory({
|
|
17536
17538
|
messages: activeSession.messages,
|
|
@@ -18638,6 +18640,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
18638
18640
|
}
|
|
18639
18641
|
};
|
|
18640
18642
|
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
|
18643
|
+
const callAuth = createCallAuth({ provider, store: authStore, candidates: profileCandidates, lockedProfileId, getIndex: () => profileIndex, setIndex: (index) => { profileIndex = index; }, getProfileId: () => lastProfileId, getKey: () => apiKeyInfo?.apiKey, apply: (candidate) => applyApiKeyInfo(candidate), freshStore: () => ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false }), resolveOrder: () => resolveAuthProfileOrder({ cfg: params.config, store: authStore, provider, preferredProfile: preferredProfileId }), inCooldown: isProfileInCooldown, tracker: subscriptionAuth, warn: (message) => log$16.warn(message) }); // JOHNNESS_PATCH_CALL_AUTH_98: a run is many model calls, not one credential
|
|
18641
18644
|
const MAX_RUN_LOOP_ITERATIONS = resolveMaxRunRetryIterations(profileCandidates.length);
|
|
18642
18645
|
let overflowCompactionAttempts = 0;
|
|
18643
18646
|
let toolResultTruncationAttempted = false;
|
|
@@ -18755,6 +18758,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
18755
18758
|
authProfileId: lastProfileId,
|
|
18756
18759
|
authProfileIdSource: lockedProfileId ? "user" : "auto",
|
|
18757
18760
|
authStorage,
|
|
18761
|
+
callAuth, // JOHNNESS_PATCH_CALL_AUTH_98
|
|
18758
18762
|
modelRegistry,
|
|
18759
18763
|
agentId: workspaceResolution.agentId,
|
|
18760
18764
|
legacyBeforeAgentStartResult,
|
|
@@ -35857,7 +35861,11 @@ async function buildExportSessionReply(params) {
|
|
|
35857
35861
|
}
|
|
35858
35862
|
//#endregion
|
|
35859
35863
|
//#region src/agents/model-auth-label.ts
|
|
35860
|
-
function resolveModelAuthLabel(params) {
|
|
35864
|
+
function resolveModelAuthLabel(params) { // JOHNNESS_PATCH_CALL_AUTH_98: the transcript names the profile that served the latest model call
|
|
35865
|
+
params = withServedAuthProfile(params);
|
|
35866
|
+
return formatServedAuthLabel(resolveStoredModelAuthLabel(params), params);
|
|
35867
|
+
}
|
|
35868
|
+
function resolveStoredModelAuthLabel(params) {
|
|
35861
35869
|
const resolvedProvider = params.provider?.trim();
|
|
35862
35870
|
if (!resolvedProvider) return;
|
|
35863
35871
|
const providerKey = normalizeProviderId(resolvedProvider);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCallAuth, withServedAuthProfile, formatServedAuthLabel } from "./subscription-call-auth.js"; // JOHNNESS_PATCH_CALL_AUTH_98
|
|
1
2
|
// JOHNNESS_PATCH_SUBSCRIPTION_USAGE_93 dist/pi-embedded-C6ITuRXf.js
|
|
2
3
|
import { loadSubscriptionStatus } from "./subscription-usage.js";
|
|
3
4
|
import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "./anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
@@ -27893,7 +27894,11 @@ async function buildExportSessionReply(params) {
|
|
|
27893
27894
|
}
|
|
27894
27895
|
//#endregion
|
|
27895
27896
|
//#region src/agents/model-auth-label.ts
|
|
27896
|
-
function resolveModelAuthLabel(params) {
|
|
27897
|
+
function resolveModelAuthLabel(params) { // JOHNNESS_PATCH_CALL_AUTH_98: the transcript names the profile that served the latest model call
|
|
27898
|
+
params = withServedAuthProfile(params);
|
|
27899
|
+
return formatServedAuthLabel(resolveStoredModelAuthLabel(params), params);
|
|
27900
|
+
}
|
|
27901
|
+
function resolveStoredModelAuthLabel(params) {
|
|
27897
27902
|
const resolvedProvider = params.provider?.trim();
|
|
27898
27903
|
if (!resolvedProvider) return;
|
|
27899
27904
|
const providerKey = normalizeProviderId(resolvedProvider);
|
|
@@ -103143,6 +103148,7 @@ async function runEmbeddedAttempt(params) {
|
|
|
103143
103148
|
activeSession.agent.streamFn = wrapStreamFnTrimToolCallNames(activeSession.agent.streamFn, allowedToolNames);
|
|
103144
103149
|
if (isXaiProvider(params.provider, params.modelId)) activeSession.agent.streamFn = wrapStreamFnDecodeXaiToolCallArguments(activeSession.agent.streamFn);
|
|
103145
103150
|
if (anthropicPayloadLogger) activeSession.agent.streamFn = anthropicPayloadLogger.wrapStreamFn(activeSession.agent.streamFn);
|
|
103151
|
+
if (params.callAuth) activeSession.agent.streamFn = params.callAuth.wrapStreamFn(activeSession.agent.streamFn); // JOHNNESS_PATCH_CALL_AUTH_98: outermost, every model call picks its credential
|
|
103146
103152
|
try {
|
|
103147
103153
|
const prior = await sanitizeSessionHistory({
|
|
103148
103154
|
messages: activeSession.messages,
|
|
@@ -104250,6 +104256,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
104250
104256
|
}
|
|
104251
104257
|
};
|
|
104252
104258
|
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
|
104259
|
+
const callAuth = createCallAuth({ provider, store: authStore, candidates: profileCandidates, lockedProfileId, getIndex: () => profileIndex, setIndex: (index) => { profileIndex = index; }, getProfileId: () => lastProfileId, getKey: () => apiKeyInfo?.apiKey, apply: (candidate) => applyApiKeyInfo(candidate), freshStore: () => ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false }), resolveOrder: () => resolveAuthProfileOrder({ cfg: params.config, store: authStore, provider, preferredProfile: preferredProfileId }), inCooldown: isProfileInCooldown, tracker: subscriptionAuth, warn: (message) => log$3.warn(message) }); // JOHNNESS_PATCH_CALL_AUTH_98: a run is many model calls, not one credential
|
|
104253
104260
|
const MAX_RUN_LOOP_ITERATIONS = resolveMaxRunRetryIterations(profileCandidates.length);
|
|
104254
104261
|
let overflowCompactionAttempts = 0;
|
|
104255
104262
|
let toolResultTruncationAttempted = false;
|
|
@@ -104374,6 +104381,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
104374
104381
|
authProfileId: lastProfileId,
|
|
104375
104382
|
authProfileIdSource: lockedProfileId ? "user" : "auto",
|
|
104376
104383
|
authStorage,
|
|
104384
|
+
callAuth, // JOHNNESS_PATCH_CALL_AUTH_98
|
|
104377
104385
|
modelRegistry,
|
|
104378
104386
|
agentId: workspaceResolution.agentId,
|
|
104379
104387
|
legacyBeforeAgentStartResult,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCallAuth, withServedAuthProfile, formatServedAuthLabel } from "./subscription-call-auth.js"; // JOHNNESS_PATCH_CALL_AUTH_98
|
|
1
2
|
// JOHNNESS_PATCH_SUBSCRIPTION_USAGE_93 dist/pi-embedded-DoQsYfIY.js
|
|
2
3
|
import { loadSubscriptionStatus } from "./subscription-usage.js";
|
|
3
4
|
import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "./anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
@@ -27889,7 +27890,11 @@ async function buildExportSessionReply(params) {
|
|
|
27889
27890
|
}
|
|
27890
27891
|
//#endregion
|
|
27891
27892
|
//#region src/agents/model-auth-label.ts
|
|
27892
|
-
function resolveModelAuthLabel(params) {
|
|
27893
|
+
function resolveModelAuthLabel(params) { // JOHNNESS_PATCH_CALL_AUTH_98: the transcript names the profile that served the latest model call
|
|
27894
|
+
params = withServedAuthProfile(params);
|
|
27895
|
+
return formatServedAuthLabel(resolveStoredModelAuthLabel(params), params);
|
|
27896
|
+
}
|
|
27897
|
+
function resolveStoredModelAuthLabel(params) {
|
|
27893
27898
|
const resolvedProvider = params.provider?.trim();
|
|
27894
27899
|
if (!resolvedProvider) return;
|
|
27895
27900
|
const providerKey = normalizeProviderId(resolvedProvider);
|
|
@@ -103133,6 +103138,7 @@ async function runEmbeddedAttempt(params) {
|
|
|
103133
103138
|
activeSession.agent.streamFn = wrapStreamFnTrimToolCallNames(activeSession.agent.streamFn, allowedToolNames);
|
|
103134
103139
|
if (isXaiProvider(params.provider, params.modelId)) activeSession.agent.streamFn = wrapStreamFnDecodeXaiToolCallArguments(activeSession.agent.streamFn);
|
|
103135
103140
|
if (anthropicPayloadLogger) activeSession.agent.streamFn = anthropicPayloadLogger.wrapStreamFn(activeSession.agent.streamFn);
|
|
103141
|
+
if (params.callAuth) activeSession.agent.streamFn = params.callAuth.wrapStreamFn(activeSession.agent.streamFn); // JOHNNESS_PATCH_CALL_AUTH_98: outermost, every model call picks its credential
|
|
103136
103142
|
try {
|
|
103137
103143
|
const prior = await sanitizeSessionHistory({
|
|
103138
103144
|
messages: activeSession.messages,
|
|
@@ -104240,6 +104246,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
104240
104246
|
}
|
|
104241
104247
|
};
|
|
104242
104248
|
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
|
104249
|
+
const callAuth = createCallAuth({ provider, store: authStore, candidates: profileCandidates, lockedProfileId, getIndex: () => profileIndex, setIndex: (index) => { profileIndex = index; }, getProfileId: () => lastProfileId, getKey: () => apiKeyInfo?.apiKey, apply: (candidate) => applyApiKeyInfo(candidate), freshStore: () => ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false }), resolveOrder: () => resolveAuthProfileOrder({ cfg: params.config, store: authStore, provider, preferredProfile: preferredProfileId }), inCooldown: isProfileInCooldown, tracker: subscriptionAuth, warn: (message) => log$3.warn(message) }); // JOHNNESS_PATCH_CALL_AUTH_98: a run is many model calls, not one credential
|
|
104243
104250
|
const MAX_RUN_LOOP_ITERATIONS = resolveMaxRunRetryIterations(profileCandidates.length);
|
|
104244
104251
|
let overflowCompactionAttempts = 0;
|
|
104245
104252
|
let toolResultTruncationAttempted = false;
|
|
@@ -104357,6 +104364,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
104357
104364
|
authProfileId: lastProfileId,
|
|
104358
104365
|
authProfileIdSource: lockedProfileId ? "user" : "auto",
|
|
104359
104366
|
authStorage,
|
|
104367
|
+
callAuth, // JOHNNESS_PATCH_CALL_AUTH_98
|
|
104360
104368
|
modelRegistry,
|
|
104361
104369
|
agentId: workspaceResolution.agentId,
|
|
104362
104370
|
legacyBeforeAgentStartResult,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCallAuth, withServedAuthProfile, formatServedAuthLabel } from "../subscription-call-auth.js"; // JOHNNESS_PATCH_CALL_AUTH_98
|
|
1
2
|
// JOHNNESS_PATCH_SUBSCRIPTION_USAGE_93 dist/plugin-sdk/dispatch-BP0viZiL.js
|
|
2
3
|
import { loadSubscriptionStatus } from "../subscription-usage.js";
|
|
3
4
|
import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "../anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
@@ -24290,7 +24291,11 @@ async function recordDiscordModelPickerRecentModel(params) {
|
|
|
24290
24291
|
}
|
|
24291
24292
|
//#endregion
|
|
24292
24293
|
//#region src/agents/model-auth-label.ts
|
|
24293
|
-
function resolveModelAuthLabel(params) {
|
|
24294
|
+
function resolveModelAuthLabel(params) { // JOHNNESS_PATCH_CALL_AUTH_98: the transcript names the profile that served the latest model call
|
|
24295
|
+
params = withServedAuthProfile(params);
|
|
24296
|
+
return formatServedAuthLabel(resolveStoredModelAuthLabel(params), params);
|
|
24297
|
+
}
|
|
24298
|
+
function resolveStoredModelAuthLabel(params) {
|
|
24294
24299
|
const resolvedProvider = params.provider?.trim();
|
|
24295
24300
|
if (!resolvedProvider) return;
|
|
24296
24301
|
const providerKey = normalizeProviderId(resolvedProvider);
|
|
@@ -87392,6 +87397,7 @@ async function runEmbeddedAttempt(params) {
|
|
|
87392
87397
|
activeSession.agent.streamFn = wrapStreamFnTrimToolCallNames(activeSession.agent.streamFn, allowedToolNames);
|
|
87393
87398
|
if (isXaiProvider(params.provider, params.modelId)) activeSession.agent.streamFn = wrapStreamFnDecodeXaiToolCallArguments(activeSession.agent.streamFn);
|
|
87394
87399
|
if (anthropicPayloadLogger) activeSession.agent.streamFn = anthropicPayloadLogger.wrapStreamFn(activeSession.agent.streamFn);
|
|
87400
|
+
if (params.callAuth) activeSession.agent.streamFn = params.callAuth.wrapStreamFn(activeSession.agent.streamFn); // JOHNNESS_PATCH_CALL_AUTH_98: outermost, every model call picks its credential
|
|
87395
87401
|
try {
|
|
87396
87402
|
const prior = await sanitizeSessionHistory({
|
|
87397
87403
|
messages: activeSession.messages,
|
|
@@ -88481,6 +88487,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
88481
88487
|
}
|
|
88482
88488
|
};
|
|
88483
88489
|
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
|
88490
|
+
const callAuth = createCallAuth({ provider, store: authStore, candidates: profileCandidates, lockedProfileId, getIndex: () => profileIndex, setIndex: (index) => { profileIndex = index; }, getProfileId: () => lastProfileId, getKey: () => apiKeyInfo?.apiKey, apply: (candidate) => applyApiKeyInfo(candidate), freshStore: () => ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false }), resolveOrder: () => resolveAuthProfileOrder({ cfg: params.config, store: authStore, provider, preferredProfile: preferredProfileId }), inCooldown: isProfileInCooldown, tracker: subscriptionAuth, warn: (message) => log$7.warn(message) }); // JOHNNESS_PATCH_CALL_AUTH_98: a run is many model calls, not one credential
|
|
88484
88491
|
const MAX_RUN_LOOP_ITERATIONS = resolveMaxRunRetryIterations(profileCandidates.length);
|
|
88485
88492
|
let overflowCompactionAttempts = 0;
|
|
88486
88493
|
let toolResultTruncationAttempted = false;
|
|
@@ -88597,6 +88604,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
88597
88604
|
authProfileId: lastProfileId,
|
|
88598
88605
|
authProfileIdSource: lockedProfileId ? "user" : "auto",
|
|
88599
88606
|
authStorage,
|
|
88607
|
+
callAuth, // JOHNNESS_PATCH_CALL_AUTH_98
|
|
88600
88608
|
modelRegistry,
|
|
88601
88609
|
agentId: workspaceResolution.agentId,
|
|
88602
88610
|
legacyBeforeAgentStartResult,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCallAuth, withServedAuthProfile, formatServedAuthLabel } from "../subscription-call-auth.js"; // JOHNNESS_PATCH_CALL_AUTH_98
|
|
1
2
|
// JOHNNESS_PATCH_SUBSCRIPTION_USAGE_93 dist/plugin-sdk/dispatch-CQsjmw7g.js
|
|
2
3
|
import { loadSubscriptionStatus } from "../subscription-usage.js";
|
|
3
4
|
import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "../anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
@@ -24399,7 +24400,11 @@ async function recordDiscordModelPickerRecentModel(params) {
|
|
|
24399
24400
|
}
|
|
24400
24401
|
//#endregion
|
|
24401
24402
|
//#region src/agents/model-auth-label.ts
|
|
24402
|
-
function resolveModelAuthLabel(params) {
|
|
24403
|
+
function resolveModelAuthLabel(params) { // JOHNNESS_PATCH_CALL_AUTH_98: the transcript names the profile that served the latest model call
|
|
24404
|
+
params = withServedAuthProfile(params);
|
|
24405
|
+
return formatServedAuthLabel(resolveStoredModelAuthLabel(params), params);
|
|
24406
|
+
}
|
|
24407
|
+
function resolveStoredModelAuthLabel(params) {
|
|
24403
24408
|
const resolvedProvider = params.provider?.trim();
|
|
24404
24409
|
if (!resolvedProvider) return;
|
|
24405
24410
|
const providerKey = normalizeProviderId(resolvedProvider);
|
|
@@ -87392,6 +87397,7 @@ async function runEmbeddedAttempt(params) {
|
|
|
87392
87397
|
activeSession.agent.streamFn = wrapStreamFnTrimToolCallNames(activeSession.agent.streamFn, allowedToolNames);
|
|
87393
87398
|
if (isXaiProvider(params.provider, params.modelId)) activeSession.agent.streamFn = wrapStreamFnDecodeXaiToolCallArguments(activeSession.agent.streamFn);
|
|
87394
87399
|
if (anthropicPayloadLogger) activeSession.agent.streamFn = anthropicPayloadLogger.wrapStreamFn(activeSession.agent.streamFn);
|
|
87400
|
+
if (params.callAuth) activeSession.agent.streamFn = params.callAuth.wrapStreamFn(activeSession.agent.streamFn); // JOHNNESS_PATCH_CALL_AUTH_98: outermost, every model call picks its credential
|
|
87395
87401
|
try {
|
|
87396
87402
|
const prior = await sanitizeSessionHistory({
|
|
87397
87403
|
messages: activeSession.messages,
|
|
@@ -88481,6 +88487,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
88481
88487
|
}
|
|
88482
88488
|
};
|
|
88483
88489
|
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
|
88490
|
+
const callAuth = createCallAuth({ provider, store: authStore, candidates: profileCandidates, lockedProfileId, getIndex: () => profileIndex, setIndex: (index) => { profileIndex = index; }, getProfileId: () => lastProfileId, getKey: () => apiKeyInfo?.apiKey, apply: (candidate) => applyApiKeyInfo(candidate), freshStore: () => ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false }), resolveOrder: () => resolveAuthProfileOrder({ cfg: params.config, store: authStore, provider, preferredProfile: preferredProfileId }), inCooldown: isProfileInCooldown, tracker: subscriptionAuth, warn: (message) => log$7.warn(message) }); // JOHNNESS_PATCH_CALL_AUTH_98: a run is many model calls, not one credential
|
|
88484
88491
|
const MAX_RUN_LOOP_ITERATIONS = resolveMaxRunRetryIterations(profileCandidates.length);
|
|
88485
88492
|
let overflowCompactionAttempts = 0;
|
|
88486
88493
|
let toolResultTruncationAttempted = false;
|
|
@@ -88597,6 +88604,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
88597
88604
|
authProfileId: lastProfileId,
|
|
88598
88605
|
authProfileIdSource: lockedProfileId ? "user" : "auto",
|
|
88599
88606
|
authStorage,
|
|
88607
|
+
callAuth, // JOHNNESS_PATCH_CALL_AUTH_98
|
|
88600
88608
|
modelRegistry,
|
|
88601
88609
|
agentId: workspaceResolution.agentId,
|
|
88602
88610
|
legacyBeforeAgentStartResult,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCallAuth, withServedAuthProfile, formatServedAuthLabel } from "../subscription-call-auth.js"; // JOHNNESS_PATCH_CALL_AUTH_98
|
|
1
2
|
// JOHNNESS_PATCH_SUBSCRIPTION_USAGE_93 dist/plugin-sdk/dispatch-Cerq29sy.js
|
|
2
3
|
import { loadSubscriptionStatus } from "../subscription-usage.js";
|
|
3
4
|
import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "../anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
@@ -24983,7 +24984,11 @@ async function recordDiscordModelPickerRecentModel(params) {
|
|
|
24983
24984
|
}
|
|
24984
24985
|
//#endregion
|
|
24985
24986
|
//#region src/agents/model-auth-label.ts
|
|
24986
|
-
function resolveModelAuthLabel(params) {
|
|
24987
|
+
function resolveModelAuthLabel(params) { // JOHNNESS_PATCH_CALL_AUTH_98: the transcript names the profile that served the latest model call
|
|
24988
|
+
params = withServedAuthProfile(params);
|
|
24989
|
+
return formatServedAuthLabel(resolveStoredModelAuthLabel(params), params);
|
|
24990
|
+
}
|
|
24991
|
+
function resolveStoredModelAuthLabel(params) {
|
|
24987
24992
|
const resolvedProvider = params.provider?.trim();
|
|
24988
24993
|
if (!resolvedProvider) return;
|
|
24989
24994
|
const providerKey = normalizeProviderId(resolvedProvider);
|
|
@@ -87706,6 +87711,7 @@ async function runEmbeddedAttempt(params) {
|
|
|
87706
87711
|
activeSession.agent.streamFn = wrapStreamFnTrimToolCallNames(activeSession.agent.streamFn, allowedToolNames);
|
|
87707
87712
|
if (isXaiProvider(params.provider, params.modelId)) activeSession.agent.streamFn = wrapStreamFnDecodeXaiToolCallArguments(activeSession.agent.streamFn);
|
|
87708
87713
|
if (anthropicPayloadLogger) activeSession.agent.streamFn = anthropicPayloadLogger.wrapStreamFn(activeSession.agent.streamFn);
|
|
87714
|
+
if (params.callAuth) activeSession.agent.streamFn = params.callAuth.wrapStreamFn(activeSession.agent.streamFn); // JOHNNESS_PATCH_CALL_AUTH_98: outermost, every model call picks its credential
|
|
87709
87715
|
try {
|
|
87710
87716
|
const prior = await sanitizeSessionHistory({
|
|
87711
87717
|
messages: activeSession.messages,
|
|
@@ -88795,6 +88801,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
88795
88801
|
}
|
|
88796
88802
|
};
|
|
88797
88803
|
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
|
88804
|
+
const callAuth = createCallAuth({ provider, store: authStore, candidates: profileCandidates, lockedProfileId, getIndex: () => profileIndex, setIndex: (index) => { profileIndex = index; }, getProfileId: () => lastProfileId, getKey: () => apiKeyInfo?.apiKey, apply: (candidate) => applyApiKeyInfo(candidate), freshStore: () => ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false }), resolveOrder: () => resolveAuthProfileOrder({ cfg: params.config, store: authStore, provider, preferredProfile: preferredProfileId }), inCooldown: isProfileInCooldown, tracker: subscriptionAuth, warn: (message) => log$7.warn(message) }); // JOHNNESS_PATCH_CALL_AUTH_98: a run is many model calls, not one credential
|
|
88798
88805
|
const MAX_RUN_LOOP_ITERATIONS = resolveMaxRunRetryIterations(profileCandidates.length);
|
|
88799
88806
|
let overflowCompactionAttempts = 0;
|
|
88800
88807
|
let toolResultTruncationAttempted = false;
|
|
@@ -88911,6 +88918,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
88911
88918
|
authProfileId: lastProfileId,
|
|
88912
88919
|
authProfileIdSource: lockedProfileId ? "user" : "auto",
|
|
88913
88920
|
authStorage,
|
|
88921
|
+
callAuth, // JOHNNESS_PATCH_CALL_AUTH_98
|
|
88914
88922
|
modelRegistry,
|
|
88915
88923
|
agentId: workspaceResolution.agentId,
|
|
88916
88924
|
legacyBeforeAgentStartResult,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCallAuth, withServedAuthProfile, formatServedAuthLabel } from "../subscription-call-auth.js"; // JOHNNESS_PATCH_CALL_AUTH_98
|
|
1
2
|
// JOHNNESS_PATCH_SUBSCRIPTION_USAGE_93 dist/plugin-sdk/dispatch-Cndjtt0g.js
|
|
2
3
|
import { loadSubscriptionStatus } from "../subscription-usage.js";
|
|
3
4
|
import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "../anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
@@ -24664,7 +24665,11 @@ async function recordDiscordModelPickerRecentModel(params) {
|
|
|
24664
24665
|
}
|
|
24665
24666
|
//#endregion
|
|
24666
24667
|
//#region src/agents/model-auth-label.ts
|
|
24667
|
-
function resolveModelAuthLabel(params) {
|
|
24668
|
+
function resolveModelAuthLabel(params) { // JOHNNESS_PATCH_CALL_AUTH_98: the transcript names the profile that served the latest model call
|
|
24669
|
+
params = withServedAuthProfile(params);
|
|
24670
|
+
return formatServedAuthLabel(resolveStoredModelAuthLabel(params), params);
|
|
24671
|
+
}
|
|
24672
|
+
function resolveStoredModelAuthLabel(params) {
|
|
24668
24673
|
const resolvedProvider = params.provider?.trim();
|
|
24669
24674
|
if (!resolvedProvider) return;
|
|
24670
24675
|
const providerKey = normalizeProviderId(resolvedProvider);
|
|
@@ -87433,6 +87438,7 @@ async function runEmbeddedAttempt(params) {
|
|
|
87433
87438
|
activeSession.agent.streamFn = wrapStreamFnTrimToolCallNames(activeSession.agent.streamFn, allowedToolNames);
|
|
87434
87439
|
if (isXaiProvider(params.provider, params.modelId)) activeSession.agent.streamFn = wrapStreamFnDecodeXaiToolCallArguments(activeSession.agent.streamFn);
|
|
87435
87440
|
if (anthropicPayloadLogger) activeSession.agent.streamFn = anthropicPayloadLogger.wrapStreamFn(activeSession.agent.streamFn);
|
|
87441
|
+
if (params.callAuth) activeSession.agent.streamFn = params.callAuth.wrapStreamFn(activeSession.agent.streamFn); // JOHNNESS_PATCH_CALL_AUTH_98: outermost, every model call picks its credential
|
|
87436
87442
|
try {
|
|
87437
87443
|
const prior = await sanitizeSessionHistory({
|
|
87438
87444
|
messages: activeSession.messages,
|
|
@@ -88522,6 +88528,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
88522
88528
|
}
|
|
88523
88529
|
};
|
|
88524
88530
|
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
|
88531
|
+
const callAuth = createCallAuth({ provider, store: authStore, candidates: profileCandidates, lockedProfileId, getIndex: () => profileIndex, setIndex: (index) => { profileIndex = index; }, getProfileId: () => lastProfileId, getKey: () => apiKeyInfo?.apiKey, apply: (candidate) => applyApiKeyInfo(candidate), freshStore: () => ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false }), resolveOrder: () => resolveAuthProfileOrder({ cfg: params.config, store: authStore, provider, preferredProfile: preferredProfileId }), inCooldown: isProfileInCooldown, tracker: subscriptionAuth, warn: (message) => log$7.warn(message) }); // JOHNNESS_PATCH_CALL_AUTH_98: a run is many model calls, not one credential
|
|
88525
88532
|
const MAX_RUN_LOOP_ITERATIONS = resolveMaxRunRetryIterations(profileCandidates.length);
|
|
88526
88533
|
let overflowCompactionAttempts = 0;
|
|
88527
88534
|
let toolResultTruncationAttempted = false;
|
|
@@ -88638,6 +88645,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
88638
88645
|
authProfileId: lastProfileId,
|
|
88639
88646
|
authProfileIdSource: lockedProfileId ? "user" : "auto",
|
|
88640
88647
|
authStorage,
|
|
88648
|
+
callAuth, // JOHNNESS_PATCH_CALL_AUTH_98
|
|
88641
88649
|
modelRegistry,
|
|
88642
88650
|
agentId: workspaceResolution.agentId,
|
|
88643
88651
|
legacyBeforeAgentStartResult,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCallAuth, withServedAuthProfile, formatServedAuthLabel } from "../subscription-call-auth.js"; // JOHNNESS_PATCH_CALL_AUTH_98
|
|
1
2
|
// JOHNNESS_PATCH_SUBSCRIPTION_USAGE_93 dist/plugin-sdk/dispatch-UogiJYul.js
|
|
2
3
|
import { loadSubscriptionStatus } from "../subscription-usage.js";
|
|
3
4
|
import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "../anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
@@ -24577,7 +24578,11 @@ async function recordDiscordModelPickerRecentModel(params) {
|
|
|
24577
24578
|
}
|
|
24578
24579
|
//#endregion
|
|
24579
24580
|
//#region src/agents/model-auth-label.ts
|
|
24580
|
-
function resolveModelAuthLabel(params) {
|
|
24581
|
+
function resolveModelAuthLabel(params) { // JOHNNESS_PATCH_CALL_AUTH_98: the transcript names the profile that served the latest model call
|
|
24582
|
+
params = withServedAuthProfile(params);
|
|
24583
|
+
return formatServedAuthLabel(resolveStoredModelAuthLabel(params), params);
|
|
24584
|
+
}
|
|
24585
|
+
function resolveStoredModelAuthLabel(params) {
|
|
24581
24586
|
const resolvedProvider = params.provider?.trim();
|
|
24582
24587
|
if (!resolvedProvider) return;
|
|
24583
24588
|
const providerKey = normalizeProviderId(resolvedProvider);
|
|
@@ -87392,6 +87397,7 @@ async function runEmbeddedAttempt(params) {
|
|
|
87392
87397
|
activeSession.agent.streamFn = wrapStreamFnTrimToolCallNames(activeSession.agent.streamFn, allowedToolNames);
|
|
87393
87398
|
if (isXaiProvider(params.provider, params.modelId)) activeSession.agent.streamFn = wrapStreamFnDecodeXaiToolCallArguments(activeSession.agent.streamFn);
|
|
87394
87399
|
if (anthropicPayloadLogger) activeSession.agent.streamFn = anthropicPayloadLogger.wrapStreamFn(activeSession.agent.streamFn);
|
|
87400
|
+
if (params.callAuth) activeSession.agent.streamFn = params.callAuth.wrapStreamFn(activeSession.agent.streamFn); // JOHNNESS_PATCH_CALL_AUTH_98: outermost, every model call picks its credential
|
|
87395
87401
|
try {
|
|
87396
87402
|
const prior = await sanitizeSessionHistory({
|
|
87397
87403
|
messages: activeSession.messages,
|
|
@@ -88481,6 +88487,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
88481
88487
|
}
|
|
88482
88488
|
};
|
|
88483
88489
|
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
|
88490
|
+
const callAuth = createCallAuth({ provider, store: authStore, candidates: profileCandidates, lockedProfileId, getIndex: () => profileIndex, setIndex: (index) => { profileIndex = index; }, getProfileId: () => lastProfileId, getKey: () => apiKeyInfo?.apiKey, apply: (candidate) => applyApiKeyInfo(candidate), freshStore: () => ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false }), resolveOrder: () => resolveAuthProfileOrder({ cfg: params.config, store: authStore, provider, preferredProfile: preferredProfileId }), inCooldown: isProfileInCooldown, tracker: subscriptionAuth, warn: (message) => log$7.warn(message) }); // JOHNNESS_PATCH_CALL_AUTH_98: a run is many model calls, not one credential
|
|
88484
88491
|
const MAX_RUN_LOOP_ITERATIONS = resolveMaxRunRetryIterations(profileCandidates.length);
|
|
88485
88492
|
let overflowCompactionAttempts = 0;
|
|
88486
88493
|
let toolResultTruncationAttempted = false;
|
|
@@ -88597,6 +88604,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
88597
88604
|
authProfileId: lastProfileId,
|
|
88598
88605
|
authProfileIdSource: lockedProfileId ? "user" : "auto",
|
|
88599
88606
|
authStorage,
|
|
88607
|
+
callAuth, // JOHNNESS_PATCH_CALL_AUTH_98
|
|
88600
88608
|
modelRegistry,
|
|
88601
88609
|
agentId: workspaceResolution.agentId,
|
|
88602
88610
|
legacyBeforeAgentStartResult,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCallAuth, withServedAuthProfile, formatServedAuthLabel } from "../subscription-call-auth.js"; // JOHNNESS_PATCH_CALL_AUTH_98
|
|
1
2
|
// JOHNNESS_PATCH_SUBSCRIPTION_USAGE_93 dist/plugin-sdk/reply-DbZnH8-h.js
|
|
2
3
|
import { loadSubscriptionStatus } from "../subscription-usage.js";
|
|
3
4
|
import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "../anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
@@ -29356,7 +29357,11 @@ async function recordDiscordModelPickerRecentModel(params) {
|
|
|
29356
29357
|
}
|
|
29357
29358
|
//#endregion
|
|
29358
29359
|
//#region src/agents/model-auth-label.ts
|
|
29359
|
-
function resolveModelAuthLabel(params) {
|
|
29360
|
+
function resolveModelAuthLabel(params) { // JOHNNESS_PATCH_CALL_AUTH_98: the transcript names the profile that served the latest model call
|
|
29361
|
+
params = withServedAuthProfile(params);
|
|
29362
|
+
return formatServedAuthLabel(resolveStoredModelAuthLabel(params), params);
|
|
29363
|
+
}
|
|
29364
|
+
function resolveStoredModelAuthLabel(params) {
|
|
29360
29365
|
const resolvedProvider = params.provider?.trim();
|
|
29361
29366
|
if (!resolvedProvider) return;
|
|
29362
29367
|
const providerKey = normalizeProviderId(resolvedProvider);
|
|
@@ -88982,6 +88987,7 @@ async function runEmbeddedAttempt(params) {
|
|
|
88982
88987
|
activeSession.agent.streamFn = wrapStreamFnTrimToolCallNames(activeSession.agent.streamFn, allowedToolNames);
|
|
88983
88988
|
if (isXaiProvider(params.provider, params.modelId)) activeSession.agent.streamFn = wrapStreamFnDecodeXaiToolCallArguments(activeSession.agent.streamFn);
|
|
88984
88989
|
if (anthropicPayloadLogger) activeSession.agent.streamFn = anthropicPayloadLogger.wrapStreamFn(activeSession.agent.streamFn);
|
|
88990
|
+
if (params.callAuth) activeSession.agent.streamFn = params.callAuth.wrapStreamFn(activeSession.agent.streamFn); // JOHNNESS_PATCH_CALL_AUTH_98: outermost, every model call picks its credential
|
|
88985
88991
|
try {
|
|
88986
88992
|
const prior = await sanitizeSessionHistory({
|
|
88987
88993
|
messages: activeSession.messages,
|
|
@@ -90071,6 +90077,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
90071
90077
|
}
|
|
90072
90078
|
};
|
|
90073
90079
|
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
|
90080
|
+
const callAuth = createCallAuth({ provider, store: authStore, candidates: profileCandidates, lockedProfileId, getIndex: () => profileIndex, setIndex: (index) => { profileIndex = index; }, getProfileId: () => lastProfileId, getKey: () => apiKeyInfo?.apiKey, apply: (candidate) => applyApiKeyInfo(candidate), freshStore: () => ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false }), resolveOrder: () => resolveAuthProfileOrder({ cfg: params.config, store: authStore, provider, preferredProfile: preferredProfileId }), inCooldown: isProfileInCooldown, tracker: subscriptionAuth, warn: (message) => log$7.warn(message) }); // JOHNNESS_PATCH_CALL_AUTH_98: a run is many model calls, not one credential
|
|
90074
90081
|
const MAX_RUN_LOOP_ITERATIONS = resolveMaxRunRetryIterations(profileCandidates.length);
|
|
90075
90082
|
let overflowCompactionAttempts = 0;
|
|
90076
90083
|
let toolResultTruncationAttempted = false;
|
|
@@ -90187,6 +90194,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
90187
90194
|
authProfileId: lastProfileId,
|
|
90188
90195
|
authProfileIdSource: lockedProfileId ? "user" : "auto",
|
|
90189
90196
|
authStorage,
|
|
90197
|
+
callAuth, // JOHNNESS_PATCH_CALL_AUTH_98
|
|
90190
90198
|
modelRegistry,
|
|
90191
90199
|
agentId: workspaceResolution.agentId,
|
|
90192
90200
|
legacyBeforeAgentStartResult,
|
package/dist/reply-C5LKjXcC.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCallAuth, withServedAuthProfile, formatServedAuthLabel } from "./subscription-call-auth.js"; // JOHNNESS_PATCH_CALL_AUTH_98
|
|
1
2
|
// JOHNNESS_PATCH_SUBSCRIPTION_USAGE_93 dist/reply-C5LKjXcC.js
|
|
2
3
|
import { loadSubscriptionStatus } from "./subscription-usage.js";
|
|
3
4
|
import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "./anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
@@ -25812,7 +25813,11 @@ async function recordDiscordModelPickerRecentModel(params) {
|
|
|
25812
25813
|
}
|
|
25813
25814
|
//#endregion
|
|
25814
25815
|
//#region src/agents/model-auth-label.ts
|
|
25815
|
-
function resolveModelAuthLabel(params) {
|
|
25816
|
+
function resolveModelAuthLabel(params) { // JOHNNESS_PATCH_CALL_AUTH_98: the transcript names the profile that served the latest model call
|
|
25817
|
+
params = withServedAuthProfile(params);
|
|
25818
|
+
return formatServedAuthLabel(resolveStoredModelAuthLabel(params), params);
|
|
25819
|
+
}
|
|
25820
|
+
function resolveStoredModelAuthLabel(params) {
|
|
25816
25821
|
const resolvedProvider = params.provider?.trim();
|
|
25817
25822
|
if (!resolvedProvider) return;
|
|
25818
25823
|
const providerKey = normalizeProviderId(resolvedProvider);
|
|
@@ -81152,6 +81157,7 @@ async function runEmbeddedAttempt(params) {
|
|
|
81152
81157
|
activeSession.agent.streamFn = wrapStreamFnTrimToolCallNames(activeSession.agent.streamFn, allowedToolNames);
|
|
81153
81158
|
if (isXaiProvider(params.provider, params.modelId)) activeSession.agent.streamFn = wrapStreamFnDecodeXaiToolCallArguments(activeSession.agent.streamFn);
|
|
81154
81159
|
if (anthropicPayloadLogger) activeSession.agent.streamFn = anthropicPayloadLogger.wrapStreamFn(activeSession.agent.streamFn);
|
|
81160
|
+
if (params.callAuth) activeSession.agent.streamFn = params.callAuth.wrapStreamFn(activeSession.agent.streamFn); // JOHNNESS_PATCH_CALL_AUTH_98: outermost, every model call picks its credential
|
|
81155
81161
|
try {
|
|
81156
81162
|
const prior = await sanitizeSessionHistory({
|
|
81157
81163
|
messages: activeSession.messages,
|
|
@@ -82259,6 +82265,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
82259
82265
|
}
|
|
82260
82266
|
};
|
|
82261
82267
|
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
|
82268
|
+
const callAuth = createCallAuth({ provider, store: authStore, candidates: profileCandidates, lockedProfileId, getIndex: () => profileIndex, setIndex: (index) => { profileIndex = index; }, getProfileId: () => lastProfileId, getKey: () => apiKeyInfo?.apiKey, apply: (candidate) => applyApiKeyInfo(candidate), freshStore: () => ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false }), resolveOrder: () => resolveAuthProfileOrder({ cfg: params.config, store: authStore, provider, preferredProfile: preferredProfileId }), inCooldown: isProfileInCooldown, tracker: subscriptionAuth, warn: (message) => log$7.warn(message) }); // JOHNNESS_PATCH_CALL_AUTH_98: a run is many model calls, not one credential
|
|
82262
82269
|
const MAX_RUN_LOOP_ITERATIONS = resolveMaxRunRetryIterations(profileCandidates.length);
|
|
82263
82270
|
let overflowCompactionAttempts = 0;
|
|
82264
82271
|
let toolResultTruncationAttempted = false;
|
|
@@ -82376,6 +82383,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
82376
82383
|
authProfileId: lastProfileId,
|
|
82377
82384
|
authProfileIdSource: lockedProfileId ? "user" : "auto",
|
|
82378
82385
|
authStorage,
|
|
82386
|
+
callAuth, // JOHNNESS_PATCH_CALL_AUTH_98
|
|
82379
82387
|
modelRegistry,
|
|
82380
82388
|
agentId: workspaceResolution.agentId,
|
|
82381
82389
|
legacyBeforeAgentStartResult,
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// JOHNNESS_PATCH_CALL_AUTH_98
|
|
2
|
+
// A run is not a turn. A sub-agent or swarm member is ONE run of hundreds of model calls, and the
|
|
3
|
+
// runner chose its auth profile once, at run start: a run that began while the Claude subscription
|
|
4
|
+
// was cooling stayed on the paid API key for hours after the subscription recovered. The credential
|
|
5
|
+
// is now chosen per model call, and every assistant record names the profile that served it.
|
|
6
|
+
// Never log or persist credential material here: profile ids and whitelisted categories only.
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
|
|
10
|
+
export const CALL_AUTH_SUBSCRIPTION = 'anthropic:subscription';
|
|
11
|
+
const SUB = CALL_AUTH_SUBSCRIPTION;
|
|
12
|
+
// After the subscription fails inside a run, that run does not go back to it before this hold-off,
|
|
13
|
+
// whatever the shared cooldown says. A run can never flap or hammer a subscription that rejects it.
|
|
14
|
+
export const CALL_AUTH_HOLD_MS = Object.freeze([60_000, 300_000, 1_500_000, 3_600_000]);
|
|
15
|
+
const FAILURE_WINDOW_MS = 2 * 3_600_000;
|
|
16
|
+
const isClaudeOAuth = c => c?.provider === 'anthropic' && c.type === 'oauth';
|
|
17
|
+
|
|
18
|
+
export function createCallAuth(deps) {
|
|
19
|
+
const candidates = deps.candidates;
|
|
20
|
+
const clock = () => (deps.now ?? Date.now)();
|
|
21
|
+
// Deterministic subscription-first order only. Other multi-profile orders rotate by last use;
|
|
22
|
+
// re-picking those per call would split one conversation's prompt cache across accounts.
|
|
23
|
+
const repick = deps.provider === 'anthropic' && !deps.lockedProfileId && candidates.length > 1
|
|
24
|
+
&& candidates.includes(SUB) && isClaudeOAuth(deps.store?.profiles?.[SUB]);
|
|
25
|
+
const counts = { calls: 0, returned: 0, byProfile: {} };
|
|
26
|
+
const stamped = new WeakSet();
|
|
27
|
+
let failures = [], serving;
|
|
28
|
+
const recent = () => (failures = failures.filter(at => clock() - at < FAILURE_WINDOW_MS));
|
|
29
|
+
const heldOff = () => {
|
|
30
|
+
const list = recent();
|
|
31
|
+
return list.length > 0 && clock() - list.at(-1) < CALL_AUTH_HOLD_MS[Math.min(list.length, CALL_AUTH_HOLD_MS.length) - 1];
|
|
32
|
+
};
|
|
33
|
+
const noteFailure = () => { failures = [...recent(), clock()]; };
|
|
34
|
+
const warn = message => { try { deps.warn?.(message); } catch {} };
|
|
35
|
+
|
|
36
|
+
// The run holds the store it read at run start. Cooldowns expire and OAuth generations rotate
|
|
37
|
+
// underneath a long run, so bring the subscription's current state in before each decision.
|
|
38
|
+
function sync() {
|
|
39
|
+
let fresh;
|
|
40
|
+
try { fresh = deps.freshStore?.(); } catch { return; }
|
|
41
|
+
if (!fresh || fresh === deps.store || !isClaudeOAuth(fresh.profiles?.[SUB])) return;
|
|
42
|
+
deps.store.profiles[SUB] = fresh.profiles[SUB];
|
|
43
|
+
deps.store.usageStats ??= {};
|
|
44
|
+
if (fresh.usageStats?.[SUB]) deps.store.usageStats[SUB] = fresh.usageStats[SUB];
|
|
45
|
+
else delete deps.store.usageStats[SUB];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Only ever moves TOWARD the subscription. Leaving it stays the runner's own failover, which
|
|
49
|
+
// reacts to that profile's failure, records it and starts the shared cooldown.
|
|
50
|
+
async function select() {
|
|
51
|
+
if (!repick) return;
|
|
52
|
+
sync();
|
|
53
|
+
const active = candidates[deps.getIndex()];
|
|
54
|
+
// The runner's failover moved this run off the subscription since the previous call.
|
|
55
|
+
if (serving === SUB && active !== SUB) noteFailure();
|
|
56
|
+
let restore = false;
|
|
57
|
+
if (active !== SUB && candidates.includes(SUB) && !deps.inCooldown(deps.store, SUB) && !heldOff()) {
|
|
58
|
+
let first;
|
|
59
|
+
try { first = deps.resolveOrder()?.[0]; } catch {}
|
|
60
|
+
if (first === SUB) try {
|
|
61
|
+
await deps.apply(SUB);
|
|
62
|
+
// Keep the forward-only failover valid: the serving profile leads, the rest follow.
|
|
63
|
+
candidates.splice(candidates.indexOf(SUB), 1);
|
|
64
|
+
candidates.unshift(SUB);
|
|
65
|
+
deps.setIndex(0);
|
|
66
|
+
counts.returned += 1;
|
|
67
|
+
warn(`auth profile ${SUB} is usable again; this run's model calls return to it`);
|
|
68
|
+
return;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
noteFailure();
|
|
71
|
+
try { deps.tracker?.failed(SUB, /refresh/i.test(String(error)) ? 'oauth_refresh_failed' : 'credential_unavailable'); } catch {}
|
|
72
|
+
restore = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Same profile: resolve it again so a rotated or expired OAuth generation is never replayed,
|
|
76
|
+
// and so a failed return leaves the serving credential exactly as it was.
|
|
77
|
+
if (restore || isClaudeOAuth(deps.store.profiles?.[active])) try { await deps.apply(active); } catch {}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function stamp(message, profileId) {
|
|
81
|
+
if (!message || typeof message !== 'object' || !profileId || stamped.has(message)) return;
|
|
82
|
+
stamped.add(message);
|
|
83
|
+
message.authProfileId = profileId;
|
|
84
|
+
const mode = deps.store?.profiles?.[profileId]?.type;
|
|
85
|
+
if (mode) message.authMode = mode;
|
|
86
|
+
let fallback;
|
|
87
|
+
try { fallback = deps.tracker?.result(profileId); } catch {}
|
|
88
|
+
if (fallback?.reason) message.authProfileFallback = { fromProfileId: fallback.fromProfileId, reason: fallback.reason };
|
|
89
|
+
counts.calls += 1;
|
|
90
|
+
counts.byProfile[profileId] = (counts.byProfile[profileId] ?? 0) + 1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Outermost stream function. The stream object and its events pass through untouched; only the
|
|
94
|
+
// final message, as the agent loop receives it from result(), gains the profile that served it.
|
|
95
|
+
function wrapStreamFn(inner) {
|
|
96
|
+
return async (model, context, options) => {
|
|
97
|
+
await select();
|
|
98
|
+
// The agent loop resolved its key before this call's profile was selected.
|
|
99
|
+
const key = repick ? deps.getKey?.() : undefined;
|
|
100
|
+
const served = serving = deps.getProfileId();
|
|
101
|
+
const stream = await inner(model, context, key ? { ...options, apiKey: key } : options);
|
|
102
|
+
if (typeof stream?.result !== 'function') return stream;
|
|
103
|
+
const result = stream.result.bind(stream);
|
|
104
|
+
stream.result = async () => {
|
|
105
|
+
const message = await result();
|
|
106
|
+
try { stamp(message, served); } catch {}
|
|
107
|
+
return message;
|
|
108
|
+
};
|
|
109
|
+
return stream;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return { wrapStreamFn, select, stats: () => structuredClone(counts), repicks: repick };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Status truth. The session store learns the served profile only when a run ends, and a sub-agent
|
|
117
|
+
// can be hours into one run. The transcript's latest model call is what actually ran last.
|
|
118
|
+
const servedCache = new Map();
|
|
119
|
+
const isModelCall = m => [m.usage?.input, m.usage?.output, m.usage?.cacheRead, m.usage?.cacheWrite].some(v => v > 0) || (m.stopReason === 'error' && typeof m.errorMessage === 'string');
|
|
120
|
+
const cleanId = id => String(id).replace(/[\u0000-\u001f\u007f]/g, ' ').slice(0, 100);
|
|
121
|
+
export function readServedAuthProfile(file, maxBytes = 4 * 1024 * 1024) {
|
|
122
|
+
let fd;
|
|
123
|
+
try {
|
|
124
|
+
fd = fs.openSync(file, 'r');
|
|
125
|
+
const stat = fs.fstatSync(fd);
|
|
126
|
+
const cached = servedCache.get(file);
|
|
127
|
+
if (cached && cached.size === stat.size && cached.mtimeMs === stat.mtimeMs) return cached.value;
|
|
128
|
+
let end = stat.size, carry = Buffer.alloc(0), scanned = 0, latest, unknown = false, stop = false;
|
|
129
|
+
const calls = {};
|
|
130
|
+
while (end > 0 && scanned < maxBytes && !stop) {
|
|
131
|
+
const start = Math.max(0, end - 65536), block = Buffer.alloc(end - start);
|
|
132
|
+
fs.readSync(fd, block, 0, block.length, start);
|
|
133
|
+
scanned += block.length;
|
|
134
|
+
const bytes = Buffer.concat([block, carry]);
|
|
135
|
+
let lineEnd = bytes.length;
|
|
136
|
+
for (let i = bytes.length - 1; i >= (start === 0 ? -1 : 0); i -= 1) {
|
|
137
|
+
if (i !== -1 && bytes[i] !== 10) continue;
|
|
138
|
+
const line = bytes.subarray(i + 1, lineEnd).toString('utf8');
|
|
139
|
+
lineEnd = i;
|
|
140
|
+
if (!line.includes('"role"')) continue;
|
|
141
|
+
let message;
|
|
142
|
+
try { const entry = JSON.parse(line); message = entry.message ?? entry; } catch { continue; }
|
|
143
|
+
// The counts cover the calls since the latest user message: the current turn or run.
|
|
144
|
+
if (message?.role === 'user') { stop = true; break; }
|
|
145
|
+
if (message?.role !== 'assistant') continue;
|
|
146
|
+
const id = typeof message.authProfileId === 'string' && message.authProfileId ? cleanId(message.authProfileId) : undefined;
|
|
147
|
+
// An unstamped latest call (older harness) is unknown, never an older record's answer.
|
|
148
|
+
// Delivery mirrors and other synthetic records are not model calls and are skipped.
|
|
149
|
+
if (!id) { if (!latest && isModelCall(message)) unknown = true; continue; }
|
|
150
|
+
const reason = message.authProfileFallback?.reason;
|
|
151
|
+
if (!latest && !unknown) latest = {
|
|
152
|
+
profileId: id,
|
|
153
|
+
mode: typeof message.authMode === 'string' ? message.authMode : undefined,
|
|
154
|
+
fallback: typeof reason === 'string' ? { fromProfileId: cleanId(message.authProfileFallback.fromProfileId ?? SUB), reason } : undefined
|
|
155
|
+
};
|
|
156
|
+
calls[id] = (calls[id] ?? 0) + 1;
|
|
157
|
+
}
|
|
158
|
+
carry = bytes.subarray(0, lineEnd);
|
|
159
|
+
end = start;
|
|
160
|
+
}
|
|
161
|
+
const value = latest ? { ...latest, calls } : undefined;
|
|
162
|
+
servedCache.delete(file);
|
|
163
|
+
servedCache.set(file, { size: stat.size, mtimeMs: stat.mtimeMs, value });
|
|
164
|
+
while (servedCache.size > 64) servedCache.delete(servedCache.keys().next().value);
|
|
165
|
+
return value;
|
|
166
|
+
} catch {} finally { if (fd !== undefined) try { fs.closeSync(fd); } catch {} }
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// All ten status label copies call this first. It replaces what the store remembered from the
|
|
171
|
+
// previous finished run with what the transcript shows for the latest model call.
|
|
172
|
+
export function withServedAuthProfile(params) {
|
|
173
|
+
try {
|
|
174
|
+
const entry = params?.sessionEntry;
|
|
175
|
+
if (!entry) return params;
|
|
176
|
+
const file = typeof entry.sessionFile === 'string' && entry.sessionFile ? entry.sessionFile
|
|
177
|
+
: entry.sessionId && params.agentDir ? path.join(params.agentDir, '..', 'sessions', `${entry.sessionId}.jsonl`) : undefined;
|
|
178
|
+
if (!file) return params;
|
|
179
|
+
const served = readServedAuthProfile(file);
|
|
180
|
+
if (!served) return params;
|
|
181
|
+
const authProfileFallback = served.fallback ? { fromProfileId: served.fallback.fromProfileId, toProfileId: served.profileId, reason: served.fallback.reason } : null;
|
|
182
|
+
return { ...params, sessionEntry: { ...entry, authProfileServed: served.profileId, authProfileFallback }, servedAuth98: served };
|
|
183
|
+
} catch { return params; }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// One run can be served by more than one profile. When it was, the label says how many calls each.
|
|
187
|
+
export function formatServedAuthLabel(label, params) {
|
|
188
|
+
const calls = params?.servedAuth98?.calls;
|
|
189
|
+
if (typeof label !== 'string' || !calls) return label;
|
|
190
|
+
const parts = Object.entries(calls).sort((a, b) => b[1] - a[1]);
|
|
191
|
+
if (parts.length < 2) return label;
|
|
192
|
+
return `${label} [calls since last message: ${parts.slice(0, 4).map(([id, count]) => `${count} ${id}`).join(', ')}]`;
|
|
193
|
+
}
|
package/docs/PATCHES.md
CHANGED
|
@@ -3280,3 +3280,26 @@ Patcher: `scripts/patch-thinking-block-binding-97.py` (exact hunks in
|
|
|
3280
3280
|
drives the real adapter over scripted SSE/400 responses on both auth paths. Historical replays
|
|
3281
3281
|
(families 67, 82, 86 to 95) layer 97 so hash-pinned fixtures still round trip.
|
|
3282
3282
|
Rollback: `npm i -g johns-harness@2026.11.9`.
|
|
3283
|
+
|
|
3284
|
+
## Family 98: the auth profile is chosen per model call (2026.11.14)
|
|
3285
|
+
|
|
3286
|
+
**Marker:** `JOHNNESS_PATCH_CALL_AUTH_98`. **Release:** `johns-harness@2026.11.14`.
|
|
3287
|
+
|
|
3288
|
+
**Report:** "I don't think the sub agent is building on the subscription. I did status and you're on subscription, but I got a bill on api." A sub-agent ran 470 Fable calls over about seven hours on the API key while its status card read `oauth (anthropic:subscription)`.
|
|
3289
|
+
|
|
3290
|
+
**Root cause:** the ten runners (`runEmbeddedPiAgent`) chose the auth profile once, at run start, and could only move forward to the next profile on a failure. They never moved back. The main session is many short runs, so it re-picked the subscription on the turn after a cooldown ended. A sub-agent or swarm member is one run of hundreds of model calls: one that started while the subscription was cooling (a 429 nineteen minutes earlier, in this case) stayed on the paid key until it ended. Nothing about sub-agents or swarms selects a different profile; a run that starts healthy is served by the subscription. Status had two gaps: `authProfileServed` and `authProfileFallback` reach the session store only when a run ends, so a card for an in-flight run fell through to the configured order and named the subscription; and assistant records carried no profile, so the transcript could not settle it.
|
|
3291
|
+
|
|
3292
|
+
**Change:**
|
|
3293
|
+
- `dist/subscription-call-auth.js` (owned). `createCallAuth` wraps the run's stream function outermost, so it runs before every model call. When the order is the deterministic Claude subscription-first order and the run is on another profile, it brings the subscription's current credential and cooldown state in from the auth store and, if the subscription is usable and leads the order again, moves the run back to it and reorders the candidates to `[serving, rest]` so the stock forward-only failover still has the API key behind it. It only ever moves toward the subscription; leaving it stays the runner's own failure-driven failover with its cooldown accounting. After a subscription failure inside a run, that run holds off 1, 5, 25 then 60 minutes before returning, whatever the shared cooldown says. User-locked profiles, other providers and single-profile runs are never re-picked.
|
|
3294
|
+
- Every assistant message is stamped when the agent loop receives it: `authProfileId`, `authMode`, and `authProfileFallback` (`fromProfileId`, whitelisted reason) when a paid key served instead of the subscription. The stamp is transcript metadata. Provider serializers build request messages from role and content only, so it is never sent to a provider and adds nothing to the context.
|
|
3295
|
+
- `resolveModelAuthLabel` (ten copies) reads the stamp on the transcript's latest model call before the stored value, so a card for a run in flight names the profile that served its last call, with the fallback reason. When the calls since the last user message used more than one profile, the label adds the count for each.
|
|
3296
|
+
|
|
3297
|
+
**Limit:** calls made while the subscription is rate limited or cooling still go to the API key. That is the Family 87 fallback, unchanged. This family ends the pin, so a run returns as soon as the subscription is usable.
|
|
3298
|
+
|
|
3299
|
+
**Proof (isolated gateway, `/tmp` state dir, free port, mock Anthropic endpoint, fixture credentials, external requests blocked):** `tests/helpers/call-auth-98-gateway.mjs` drives a real `sessions_spawn` sub-agent and a real `swarm_spawn` of two, each spawned while the subscription is cooling, and ends the cooldown mid-run. On `8d22cd5` (run with `CALL_AUTH_98_EXPECT=bug`) every call of all three runs is `x-api-key`, the transcripts carry no profile, and the sub-agent's mid-run card reads `oauth (anthropic:subscription)` once the cooldown has ended. On this tree each run is `x-api-key, x-api-key, Bearer, Bearer`; transcript stamps are default, default, subscription, subscription with cost above zero, above zero, 0, 0; the mid-run card reads `api-key (anthropic:default) [API fallback: subscription in cooldown]`; a sub-agent spawned on a healthy subscription is Bearer from its first call; and none of the 25 request bodies, which replay 12 stamped records, contains a stamp field. The live subscription credential was not copied into the fixture, so this is not a live Anthropic call.
|
|
3300
|
+
|
|
3301
|
+
**Replay:** `patches/call-auth-98/changes.json`, `scripts/patch-call-auth-98.py` (`--check` read-only, `--present-only`, `--record`): ten runner bundles with five uniform hunks each, plus the owned module at exact pinned content. The import is prepended above the Family 93 header line, outside the chained Family 91 to 93 import hunks. `scripts/subscription_login_layer.py` and `tests/helpers/subscription-login-layer.mjs` strip and re-layer it with Families 86 to 97. Verifier checks 98.1 to 98.6.
|
|
3302
|
+
|
|
3303
|
+
**Tests:** `tests/call-auth-98.test.mjs` (7): manifest coverage and exact replay, drift refusal before any write, return on the first call after a cooldown ends, hold-off after a failover and after a failed return, locks and other providers untouched, status from the transcript, and the isolated-gateway run above.
|
|
3304
|
+
|
|
3305
|
+
**Rollback:** `npm i -g johns-harness@2026.11.13`.
|