Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

Stop retrying revoked connector grants

wyteea568a62223
diff --git a/src/main/features/connectors/manager.ts b/src/main/features/connectors/manager.ts
index 656f9986..6bacc4e3 100644
--- a/src/main/features/connectors/manager.ts
+++ b/src/main/features/connectors/manager.ts
@@ -78,10 +78,19 @@ function _missingRequiredScopes(entry: CatalogEntry, grant: OAuthGrant | undefin
function _storedAuthorizationProblem(inst: ConnectorInstance): { message: string; reason: string } | null {
const entry = findCatalogEntry(inst.id);
if (!entry) return null;
+ if (inst.auth_error?.message) {
+ return {
+ message: inst.auth_error.message,
+ reason: inst.auth_error.reason || inst.auth_error.code || 'authorization_error',
+ };
+ }
const statusError = inst.status?.kind === 'error' ? inst.status.message : '';
if (statusError && _isGoogleAuthFailure(entry, statusError)) {
return { message: statusError, reason: 'google_auth_error' };
}
+ if (statusError && _isStickyDcrAuthStatus(entry, statusError)) {
+ return { message: statusError, reason: 'dcr_auth_error' };
+ }
return null;
}
@@ -137,6 +146,15 @@ function _isDcrAuthFailure(entry: CatalogEntry, err: unknown): boolean {
return /DCR refresh HTTP\s+4\d\d|invalid_grant|connector_reconnect_required|access_token expired|no oauth_grant|transport unresolved/i.test(msg);
}
+function _isStickyDcrAuthStatus(entry: CatalogEntry, err: unknown): boolean {
+ if (entry.auth_mode !== 'mcp_dcr') return false;
+ const code = _connectorErrorCode(err);
+ if (code === 'connector_reconnect_required') return true;
+ if (code === 'connector_refresh_failed') return false;
+ const msg = (err as Error | null)?.message || String(err || '');
+ return /DCR refresh HTTP\s+4\d\d|invalid_grant|connector_reconnect_required|access_token expired|no oauth_grant|reconnect required|授权已失效|Authorization expired/i.test(msg);
+}
+
function _isTransientConnectorFailure(err: unknown): boolean {
const code = _connectorErrorCode(err);
const retryable = _connectorRetryable(err);
@@ -164,6 +182,7 @@ function _asConnectedFromCache(inst: ConnectorInstance): ConnectorInstance {
if (inst.status?.kind === 'connected') return inst;
return {
...inst,
+ auth_error: undefined,
status: { kind: 'connected', since: _now() },
};
}
@@ -244,9 +263,16 @@ async function _markAuthorizationError(uid: string, id: string, message: string,
try { await conn.close(); } catch { /* swallow */ }
_conns.delete(id);
}
+ const at = _now();
const updated = await registry.update(uid, id, (cur) => ({
...cur,
- status: { kind: 'error', message, at: _now() },
+ auth_error: {
+ code: _connectorErrorCode(message) || 'connector_reconnect_required',
+ message,
+ reason,
+ at,
+ },
+ status: { kind: 'error', message, at },
updated_at: _nowIso(),
}));
if (updated) log.warn('connector authorization requires reconnect', { id, reason });
@@ -496,6 +522,7 @@ async function _connectAndCacheTools(uid: string, inst: ConnectorInstance): Prom
transport,
tools_cache: tools,
tools_cached_at: _now(),
+ auth_error: undefined,
status: { kind: 'connected', since: _now() },
updated_at: _nowIso(),
}));
@@ -516,6 +543,7 @@ async function _connectAndCacheTools(uid: string, inst: ConnectorInstance): Prom
transport,
tools_cache: tools,
tools_cached_at: _now(),
+ auth_error: undefined,
status: { kind: 'connected', since: _now() },
updated_at: _nowIso(),
}));
@@ -538,6 +566,7 @@ async function _connectAndCacheTools(uid: string, inst: ConnectorInstance): Prom
transport: retryTransport,
tools_cache: tools,
tools_cached_at: _now(),
+ auth_error: undefined,
status: { kind: 'connected', since: _now() },
updated_at: _nowIso(),
}));
@@ -587,7 +616,7 @@ export async function bootstrap(uid: string): Promise<void> {
}
const problem = _storedAuthorizationProblem(inst);
if (problem) {
- if (!_hasStatusError(inst, problem.message)) {
+ if (!inst.auth_error?.message || !_hasStatusError(inst, problem.message)) {
try {
await _markAuthorizationError(uid, inst.id, problem.message, `bootstrap_${problem.reason}`);
} catch (err) {
@@ -616,7 +645,7 @@ export function listInstances(uid: string): ConnectorInstance[] {
}).map((inst) => {
const problem = _storedAuthorizationProblem(inst);
if (problem) {
- if (!_hasStatusError(inst, problem.message)) {
+ if (!inst.auth_error?.message || !_hasStatusError(inst, problem.message)) {
_markAuthorizationErrorSoon(uid, inst.id, problem.message, `list_${problem.reason}`);
}
return {
@@ -644,7 +673,7 @@ export function getInstance(uid: string, id: string): ConnectorInstance | null {
}
const problem = _storedAuthorizationProblem(inst);
if (problem) {
- if (!_hasStatusError(inst, problem.message)) {
+ if (!inst.auth_error?.message || !_hasStatusError(inst, problem.message)) {
_markAuthorizationErrorSoon(uid, inst.id, problem.message, `get_${problem.reason}`);
}
return {
diff --git a/src/main/features/connectors/types.ts b/src/main/features/connectors/types.ts
index 72fdb9a6..fc1e4e61 100644
--- a/src/main/features/connectors/types.ts
+++ b/src/main/features/connectors/types.ts
@@ -39,6 +39,13 @@ export type ConnectorStatus =
| { kind: 'disconnected' }
| { kind: 'error'; message: string; at: number };
+export interface ConnectorAuthError {
+ code: string;
+ message: string;
+ reason?: string;
+ at: number;
+}
+
export interface ConnectorInstance {
/** Stable id chosen by the user at install time (e.g. "github-personal"). Becomes the prefix on
* every tool name emitted into the AgentRunner tool list: `<id>__<tool_name>`. */
@@ -58,6 +65,9 @@ export interface ConnectorInstance {
tools_cache: ToolSchema[];
tools_cached_at: number;
status: ConnectorStatus;
+ /** Sticky non-sensitive auth failure marker. When a provider has definitively
+ * rejected a grant, boot/list/refresh paths must not keep retrying it. */
+ auth_error?: ConnectorAuthError;
/** OAuth grant when this instance was created via OAuth; absent for API-key installs.
* The manager rewrites the transport env at spawn time using `oauth_grant.access_token`;
* refresh logic in `oauth.ts::refreshIfStale` runs before connect / after a 401. */
diff --git a/test/main/features/connectors/manager.test.ts b/test/main/features/connectors/manager.test.ts
index 150fda06..39018656 100644
--- a/test/main/features/connectors/manager.test.ts
+++ b/test/main/features/connectors/manager.test.ts
@@ -427,6 +427,35 @@ describe('features/connectors/manager authorization recovery', () => {
kind: 'error',
message: expect.stringContaining('Authorization expired'),
});
+ expect(registry.load(TEST_UID).connections.notion.auth_error).toMatchObject({
+ code: 'connector_reconnect_required',
+ message: expect.stringContaining('Authorization expired'),
+ });
+ });
+
+ it('does not retry persisted DCR reconnect-required rows on bootstrap', async () => {
+ const registry = await import('../../../../src/main/features/connectors/registry');
+ const manager = await import('../../../../src/main/features/connectors/manager');
+
+ const inst = notionInstance();
+ inst.oauth_grant.refresh_token = null;
+ (inst.oauth_grant as any).server_managed = true;
+ (inst.oauth_grant as any).server_grant_id = 'grant-1';
+ inst.status = {
+ kind: 'error',
+ message: 'connector_reconnect_required: 授权已失效,请重新连接',
+ at: Date.now(),
+ };
+ delete (inst as any).dcr_client;
+ await registry.upsert(TEST_UID, inst);
+
+ await manager.bootstrap(TEST_UID);
+
+ expect(mocks.dcr.refreshDcrServerManaged).not.toHaveBeenCalled();
+ expect(registry.load(TEST_UID).connections.notion.auth_error).toMatchObject({
+ code: 'connector_reconnect_required',
+ message: expect.stringContaining('授权已失效'),
+ });
});
it('removes the connector row if a refresh response no longer includes required scopes', async () => {
@@ -469,6 +498,14 @@ describe('features/connectors/manager authorization recovery', () => {
message: expect.stringContaining('invalid_grant'),
});
expect(registry.load(TEST_UID).connections.notion).toBeTruthy();
+ expect(registry.load(TEST_UID).connections.notion.auth_error).toMatchObject({
+ code: 'connector_reconnect_required',
+ message: expect.stringContaining('invalid_grant'),
+ });
+
+ mocks.dcr.refreshDcrServerManaged.mockClear();
+ await manager.bootstrap(TEST_UID);
+ expect(mocks.dcr.refreshDcrServerManaged).not.toHaveBeenCalled();
});
it('adopts legacy DCR refresh tokens into server-managed grants', async () => {