Skip to content

Commit 4ecd85e

Browse files
authored
fix: keep healthy channel accounts running when one credential fails (#109766)
* fix(secrets): isolate channel account credentials * fix(secrets): normalize Feishu default ownership * fix(feishu): preserve accountless secret ownership * fix(matrix): keep accountless top-level refs active
1 parent 538263b commit 4ecd85e

20 files changed

Lines changed: 555 additions & 110 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
7e2ff4dedb7b220a133cb419ee91e67585b9b9f2799706f336cdea973be80bfb plugin-sdk-api-baseline.json
2-
0a85effc98fb17a65d463956704bcb2dab31076cf0fa0d85b463a765ec9dc439 plugin-sdk-api-baseline.jsonl
1+
e06731c08fa6ad7c00fdd59807d0b99045de886afe65c482f8d46bd46e4b271d plugin-sdk-api-baseline.json
2+
0ab4e245ac7d4cc68f0c888e58ebb6c4b404a620ce4d0087cdf3cfd9c31b1e62 plugin-sdk-api-baseline.jsonl

‎extensions/discord/src/secret-config-contract.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ export function collectRuntimeConfigAssignments(params: {
131131
isBaseFieldActiveForChannelSurface(surface, "pluralkit") &&
132132
isRecord(discord.pluralkit) &&
133133
isEnabledFlag(discord.pluralkit),
134+
topLevelInheritedAccountActive: ({ account, enabled }) =>
135+
enabled && !Object.hasOwn(account, "pluralkit") && isEnabledFlag(discord.pluralkit),
134136
topInactiveReason:
135137
"no enabled Discord surface inherits this top-level PluralKit config or PluralKit is disabled.",
136138
accountActive: ({ account, enabled }) =>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Feishu tests cover secret contract plugin behavior.
2+
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
3+
import { createResolverContext } from "openclaw/plugin-sdk/secret-ref-runtime";
4+
import { describe, expect, it } from "vitest";
5+
import { collectRuntimeConfigAssignments } from "./secret-contract.js";
6+
7+
describe("feishu secret contract", () => {
8+
it("assigns an enabled accountless appSecret to the default owner without a configured appId", () => {
9+
const sourceConfig = {
10+
channels: {
11+
feishu: {
12+
enabled: true,
13+
appSecret: {
14+
source: "env",
15+
provider: "default",
16+
id: "FEISHU_APP_SECRET",
17+
},
18+
},
19+
},
20+
} satisfies OpenClawConfig;
21+
const context = createResolverContext({ sourceConfig, env: {} });
22+
23+
collectRuntimeConfigAssignments({
24+
config: structuredClone(sourceConfig),
25+
defaults: undefined,
26+
context,
27+
});
28+
29+
expect(context.assignments).toMatchObject([
30+
{
31+
path: "channels.feishu.appSecret",
32+
ownerKind: "account",
33+
ownerId: "feishu:default",
34+
},
35+
]);
36+
expect(context.warnings).toStrictEqual([]);
37+
});
38+
39+
it("does not synthesize a second default owner for normalized account aliases", () => {
40+
const sourceConfig = {
41+
channels: {
42+
feishu: {
43+
enabled: true,
44+
appId: "top-app-id",
45+
appSecret: {
46+
source: "env",
47+
provider: "default",
48+
id: "FEISHU_UNUSED_VALUE",
49+
},
50+
accounts: {
51+
" default ": {
52+
enabled: true,
53+
appId: "account-app-id",
54+
appSecret: "fixture",
55+
},
56+
},
57+
},
58+
},
59+
} satisfies OpenClawConfig;
60+
const context = createResolverContext({ sourceConfig, env: {} });
61+
62+
collectRuntimeConfigAssignments({
63+
config: structuredClone(sourceConfig),
64+
defaults: undefined,
65+
context,
66+
});
67+
68+
expect(context.assignments).toStrictEqual([]);
69+
expect(context.warnings).toMatchObject([{ path: "channels.feishu.appSecret" }]);
70+
});
71+
});

‎extensions/feishu/src/secret-contract.ts‎

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// Feishu plugin module implements secret contract behavior.
2+
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
23
import {
34
collectConditionalChannelFieldAssignments,
4-
collectSecretInputAssignment,
55
createChannelSecretTargetRegistryEntries,
66
getChannelSurface,
77
hasConfiguredSecretInputValue,
88
hasOwnProperty,
9-
isBaseFieldActiveForChannelSurface,
109
normalizeSecretStringValue,
1110
type ResolverContext,
1211
type SecretDefaults,
@@ -37,39 +36,27 @@ export function collectRuntimeConfigAssignments(params: {
3736
surface.channelEnabled &&
3837
hasConfiguredSecretInputValue(feishu.appId, params.defaults) &&
3938
hasConfiguredSecretInputValue(feishu.appSecret, params.defaults);
40-
const topLevelAppSecretActive =
41-
hasImplicitDefaultAccount || isBaseFieldActiveForChannelSurface(surface, "appSecret");
42-
collectSecretInputAssignment({
43-
value: feishu.appSecret,
44-
path: "channels.feishu.appSecret",
45-
expected: "string",
39+
if (
40+
hasImplicitDefaultAccount &&
41+
surface.hasExplicitAccounts &&
42+
!surface.accounts.some(({ accountId }) => normalizeAccountId(accountId) === DEFAULT_ACCOUNT_ID)
43+
) {
44+
surface.accounts.push({ accountId: "default", account: {}, enabled: true });
45+
}
46+
collectConditionalChannelFieldAssignments({
47+
channelKey: "feishu",
48+
field: "appSecret",
49+
channel: feishu,
50+
surface,
4651
defaults: params.defaults,
4752
context: params.context,
48-
active: topLevelAppSecretActive,
49-
inactiveReason: "no enabled account inherits this top-level Feishu appSecret.",
50-
apply: (value) => {
51-
feishu.appSecret = value;
52-
},
53+
topLevelActiveWithoutAccounts: surface.channelEnabled,
54+
topLevelInheritedAccountActive: ({ account, enabled }) =>
55+
enabled && !hasOwnProperty(account, "appSecret"),
56+
accountActive: ({ enabled }) => enabled,
57+
topInactiveReason: "no enabled account inherits this top-level Feishu appSecret.",
58+
accountInactiveReason: "Feishu account is disabled.",
5359
});
54-
if (surface.hasExplicitAccounts) {
55-
for (const { accountId, account, enabled } of surface.accounts) {
56-
if (!hasOwnProperty(account, "appSecret")) {
57-
continue;
58-
}
59-
collectSecretInputAssignment({
60-
value: account.appSecret,
61-
path: `channels.feishu.accounts.${accountId}.appSecret`,
62-
expected: "string",
63-
defaults: params.defaults,
64-
context: params.context,
65-
active: enabled,
66-
inactiveReason: "Feishu account is disabled.",
67-
apply: (value) => {
68-
account.appSecret = value;
69-
},
70-
});
71-
}
72-
}
7360
const baseConnectionMode =
7461
normalizeSecretStringValue(feishu.connectionMode) === "webhook" ? "webhook" : "websocket";
7562
const resolveAccountMode = (account: Record<string, unknown>) =>

‎extensions/googlechat/src/secret-contract.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ describe("googlechat secret contract", () => {
4343

4444
expect(context.assignments).toMatchObject([
4545
{
46-
ownerKind: "unknown",
47-
ownerId: "channels.googlechat.accounts.work.serviceAccount",
46+
ownerKind: "account",
47+
ownerId: "googlechat:work",
4848
requiredForGateway: false,
49-
disposition: "fail-closed",
49+
disposition: "isolate",
5050
},
5151
]);
5252

‎extensions/googlechat/src/secret-contract.ts‎

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Googlechat plugin module implements secret contract behavior.
2+
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
23
import {
34
createChannelSecretTargetRegistryEntries,
45
getChannelSurface,
@@ -18,6 +19,15 @@ type GoogleChatAccountLike = {
1819
accounts?: Record<string, unknown>;
1920
};
2021

22+
function accountSecretOwner(accountId: string) {
23+
return {
24+
ownerKind: "account" as const,
25+
ownerId: `googlechat:${normalizeAccountId(accountId)}`,
26+
requiredForGateway: false,
27+
disposition: "isolate" as const,
28+
};
29+
}
30+
2131
export const secretTargetRegistryEntries = createChannelSecretTargetRegistryEntries({
2232
channelKey: "googlechat",
2333
account: [
@@ -60,7 +70,7 @@ function collectGoogleChatAccountAssignment(params: {
6070
path: string;
6171
defaults?: SecretDefaults;
6272
context: ResolverContext;
63-
active?: boolean;
73+
ownerAccountIds: string[];
6474
inactiveReason?: string;
6575
}): void {
6676
const { explicitRef, ref } = resolveSecretInputRef({
@@ -71,7 +81,7 @@ function collectGoogleChatAccountAssignment(params: {
7181
if (!ref) {
7282
return;
7383
}
74-
if (params.active === false) {
84+
if (params.ownerAccountIds.length === 0) {
7585
pushInactiveSurfaceWarning({
7686
context: params.context,
7787
path: `${params.path}.serviceAccount`,
@@ -90,18 +100,17 @@ function collectGoogleChatAccountAssignment(params: {
90100
message: `${params.path}: serviceAccountRef is set; runtime will ignore plaintext serviceAccount.`,
91101
});
92102
}
93-
pushAssignment(params.context, {
94-
ref,
95-
path: `${params.path}.serviceAccount`,
96-
expected: "string-or-object",
97-
ownerKind: "unknown",
98-
ownerId: `${params.path}.serviceAccount`,
99-
requiredForGateway: false,
100-
disposition: "fail-closed",
101-
apply: (value) => {
102-
params.target.serviceAccount = value;
103-
},
104-
});
103+
for (const accountId of params.ownerAccountIds) {
104+
pushAssignment(params.context, {
105+
ref,
106+
path: `${params.path}.serviceAccount`,
107+
expected: "string-or-object",
108+
...accountSecretOwner(accountId),
109+
apply: (value) => {
110+
params.target.serviceAccount = value;
111+
},
112+
});
113+
}
105114
}
106115

107116
export function collectRuntimeConfigAssignments(params: {
@@ -115,22 +124,24 @@ export function collectRuntimeConfigAssignments(params: {
115124
}
116125
const googleChat = resolved.channel as GoogleChatAccountLike;
117126
const surface = resolveChannelAccountSurface(googleChat as Record<string, unknown>);
118-
const topLevelServiceAccountActive = !surface.channelEnabled
119-
? false
127+
const topLevelServiceAccountOwners = !surface.channelEnabled
128+
? []
120129
: !surface.hasExplicitAccounts
121-
? true
122-
: surface.accounts.some(
123-
({ account, enabled }) =>
124-
enabled &&
125-
!hasOwnProperty(account, "serviceAccount") &&
126-
!hasOwnProperty(account, "serviceAccountRef"),
127-
);
130+
? ["default"]
131+
: surface.accounts
132+
.filter(
133+
({ account, enabled }) =>
134+
enabled &&
135+
!hasOwnProperty(account, "serviceAccount") &&
136+
!hasOwnProperty(account, "serviceAccountRef"),
137+
)
138+
.map(({ accountId }) => accountId);
128139
collectGoogleChatAccountAssignment({
129140
target: googleChat,
130141
path: "channels.googlechat",
131142
defaults: params.defaults,
132143
context: params.context,
133-
active: topLevelServiceAccountActive,
144+
ownerAccountIds: topLevelServiceAccountOwners,
134145
inactiveReason: "no enabled account inherits this top-level Google Chat serviceAccount.",
135146
});
136147
if (!surface.hasExplicitAccounts) {
@@ -148,7 +159,7 @@ export function collectRuntimeConfigAssignments(params: {
148159
path: `channels.googlechat.accounts.${accountId}`,
149160
defaults: params.defaults,
150161
context: params.context,
151-
active: enabled,
162+
ownerAccountIds: enabled ? [accountId] : [],
152163
inactiveReason: "Google Chat account is disabled.",
153164
});
154165
}

‎extensions/irc/src/secret-contract.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export function collectRuntimeConfigAssignments(params: {
4949
isBaseFieldActiveForChannelSurface(surface, "nickserv") &&
5050
isRecord(irc.nickserv) &&
5151
isEnabledFlag(irc.nickserv),
52+
topLevelInheritedAccountActive: ({ account, enabled }) =>
53+
enabled && !Object.hasOwn(account, "nickserv") && isEnabledFlag(irc.nickserv),
5254
topInactiveReason:
5355
"no enabled account inherits this top-level IRC nickserv config or NickServ is disabled.",
5456
accountActive: ({ account, enabled }) =>

‎extensions/matrix/src/secret-contract.ts‎

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ import {
1212
} from "openclaw/plugin-sdk/channel-secret-basic-runtime";
1313
import { getMatrixScopedEnvVarNames } from "./env-vars.js";
1414

15+
function accountSecretOwner(accountId: string) {
16+
return {
17+
ownerKind: "account" as const,
18+
ownerId: `matrix:${normalizeAccountId(accountId)}`,
19+
requiredForGateway: false,
20+
disposition: "isolate" as const,
21+
};
22+
}
23+
1524
export const secretTargetRegistryEntries = createChannelSecretTargetRegistryEntries({
1625
channelKey: "matrix",
1726
account: ["accessToken", "password"],
@@ -34,10 +43,20 @@ export function collectRuntimeConfigAssignments(params: {
3443
normalizeSecretStringValue(
3544
params.context.env[getMatrixScopedEnvVarNames("default").accessToken],
3645
).length > 0;
37-
const defaultAccountAccessTokenConfigured = surface.accounts.some(
38-
({ accountId, account }) =>
39-
normalizeAccountId(accountId) === DEFAULT_ACCOUNT_ID &&
40-
hasConfiguredSecretInputValue(account.accessToken, params.defaults),
46+
const defaultScopedPasswordConfigured =
47+
normalizeSecretStringValue(params.context.env[getMatrixScopedEnvVarNames("default").password])
48+
.length > 0;
49+
const defaultAccount = surface.hasExplicitAccounts
50+
? surface.accounts.find(({ accountId }) => normalizeAccountId(accountId) === DEFAULT_ACCOUNT_ID)
51+
: undefined;
52+
const defaultAccountEnabled = surface.channelEnabled && (defaultAccount?.enabled ?? true);
53+
const defaultAccountAccessTokenConfigured = hasConfiguredSecretInputValue(
54+
defaultAccount?.account.accessToken,
55+
params.defaults,
56+
);
57+
const defaultAccountPasswordConfigured = hasConfiguredSecretInputValue(
58+
defaultAccount?.account.password,
59+
params.defaults,
4160
);
4261
const baseAccessTokenConfigured = hasConfiguredSecretInputValue(
4362
matrix.accessToken,
@@ -49,8 +68,13 @@ export function collectRuntimeConfigAssignments(params: {
4968
expected: "string",
5069
defaults: params.defaults,
5170
context: params.context,
52-
active: surface.channelEnabled,
53-
inactiveReason: "Matrix channel is disabled.",
71+
active:
72+
defaultAccountEnabled &&
73+
!defaultAccountAccessTokenConfigured &&
74+
!defaultScopedAccessTokenConfigured,
75+
inactiveReason:
76+
"Matrix channel or default account is disabled, or default-account access-token auth overrides the top-level accessToken.",
77+
owner: accountSecretOwner(DEFAULT_ACCOUNT_ID),
5478
apply: (value) => {
5579
matrix.accessToken = value;
5680
},
@@ -62,15 +86,18 @@ export function collectRuntimeConfigAssignments(params: {
6286
defaults: params.defaults,
6387
context: params.context,
6488
active:
65-
surface.channelEnabled &&
89+
defaultAccountEnabled &&
6690
!(
6791
baseAccessTokenConfigured ||
6892
envAccessTokenConfigured ||
6993
defaultScopedAccessTokenConfigured ||
70-
defaultAccountAccessTokenConfigured
94+
defaultAccountAccessTokenConfigured ||
95+
defaultAccountPasswordConfigured ||
96+
defaultScopedPasswordConfigured
7197
),
7298
inactiveReason:
73-
"Matrix channel is disabled or access-token auth is configured for the default Matrix account.",
99+
"Matrix channel or default account is disabled, or higher-precedence default-account auth is configured.",
100+
owner: accountSecretOwner(DEFAULT_ACCOUNT_ID),
74101
apply: (value) => {
75102
matrix.password = value;
76103
},
@@ -88,6 +115,7 @@ export function collectRuntimeConfigAssignments(params: {
88115
context: params.context,
89116
active: enabled,
90117
inactiveReason: "Matrix account is disabled.",
118+
owner: accountSecretOwner(accountId),
91119
apply: (value) => {
92120
account.accessToken = value;
93121
},
@@ -121,6 +149,7 @@ export function collectRuntimeConfigAssignments(params: {
121149
inheritedDefaultAccountAccessTokenConfigured
122150
),
123151
inactiveReason: "Matrix account is disabled or this account has an accessToken configured.",
152+
owner: accountSecretOwner(accountId),
124153
apply: (value) => {
125154
account.password = value;
126155
},

0 commit comments

Comments
 (0)