agent-gear 2.23.0 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -2
- package/dist/acp/bridge.d.ts +1 -1
- package/dist/acp/bridge.d.ts.map +1 -1
- package/dist/acp/bridge.js +11 -8
- package/dist/acp/bridge.js.map +1 -1
- package/dist/acp/bridge.test.js +20 -20
- package/dist/acp/bridge.test.js.map +1 -1
- package/dist/acp/spawner.js +1 -1
- package/dist/acp/spawner.js.map +1 -1
- package/dist/socketio-client.js +1 -1
- package/dist/socketio-client.js.map +1 -1
- package/package.json +1 -1
- package/src/acp/bridge.test.ts +20 -20
- package/src/acp/bridge.ts +12 -8
- package/src/acp/spawner.ts +1 -1
- package/src/socketio-client.ts +1 -1
- package/tests/acp-bridge.test.ts +4 -4
- package/tests/manual/repro-question-tool.ts +8 -3
package/src/acp/bridge.test.ts
CHANGED
|
@@ -109,7 +109,7 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
109
109
|
expect(result).toEqual({ outcome: { outcome: 'selected', optionId: 'opt-1' } });
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
it('should resolve with cancelled after
|
|
112
|
+
it('should resolve with cancelled after 905s timeout', async () => {
|
|
113
113
|
const bridge = createBridge();
|
|
114
114
|
|
|
115
115
|
const promise = bridge.requestPermission({
|
|
@@ -117,7 +117,7 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
117
117
|
options: [{ optionId: 'opt-1', name: 'Allow', kind: 'allow_once' }],
|
|
118
118
|
} as never);
|
|
119
119
|
|
|
120
|
-
await vi.advanceTimersByTimeAsync(
|
|
120
|
+
await vi.advanceTimersByTimeAsync(905_000);
|
|
121
121
|
|
|
122
122
|
const result = await promise;
|
|
123
123
|
expect(result).toEqual({ outcome: { outcome: 'cancelled' } });
|
|
@@ -140,7 +140,7 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
140
140
|
const result = await promise;
|
|
141
141
|
expect(result).toEqual({ outcome: { outcome: 'selected', optionId: 'opt-1' } });
|
|
142
142
|
|
|
143
|
-
await vi.advanceTimersByTimeAsync(
|
|
143
|
+
await vi.advanceTimersByTimeAsync(905_000);
|
|
144
144
|
});
|
|
145
145
|
|
|
146
146
|
it('should warn and ignore invalid requestId in handlePermissionResponse', () => {
|
|
@@ -210,7 +210,7 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
210
210
|
options: [{ optionId: 'opt-1', name: 'Allow', kind: 'allow_once' }],
|
|
211
211
|
} as never);
|
|
212
212
|
|
|
213
|
-
await vi.advanceTimersByTimeAsync(
|
|
213
|
+
await vi.advanceTimersByTimeAsync(905_000);
|
|
214
214
|
await promise;
|
|
215
215
|
|
|
216
216
|
const emitCall = mockSocket.emit.mock.calls.find((c: unknown[]) => c[0] === 'acp:permission');
|
|
@@ -879,7 +879,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
879
879
|
expect((resolved![1] as { detail: string }).detail).toHaveLength(100);
|
|
880
880
|
});
|
|
881
881
|
|
|
882
|
-
it('T-B4:
|
|
882
|
+
it('T-B4: 1805s 超时返回 cancel 并发出 resolved(timeout),不残留 pending', async () => {
|
|
883
883
|
const bridge = createBridge();
|
|
884
884
|
|
|
885
885
|
const promise = bridge.unstable_createElicitation({
|
|
@@ -891,13 +891,13 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
891
891
|
const emitCall = mockSocket.emit.mock.calls.find((c: unknown[]) => c[0] === 'acp:elicitation');
|
|
892
892
|
const requestId = (emitCall![1] as { requestId: string }).requestId;
|
|
893
893
|
|
|
894
|
-
await vi.advanceTimersByTimeAsync(
|
|
894
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
895
895
|
|
|
896
896
|
expect(await promise).toEqual({ action: 'cancel' });
|
|
897
897
|
expect(mockSocket.emit).toHaveBeenCalledWith('acp:elicitation:resolved', expect.objectContaining({
|
|
898
898
|
requestId,
|
|
899
899
|
reason: 'timeout',
|
|
900
|
-
detail: 'bridge timeout (
|
|
900
|
+
detail: 'bridge timeout (1805s)',
|
|
901
901
|
}));
|
|
902
902
|
expect(testLog.records).toContainEqual(
|
|
903
903
|
expect.objectContaining({ level: 'warn', event: 'elicitation_timeout', requestId }),
|
|
@@ -913,7 +913,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
913
913
|
);
|
|
914
914
|
});
|
|
915
915
|
|
|
916
|
-
it('T-B5: 正常 form 模式只发 acp:elicitation,响应后
|
|
916
|
+
it('T-B5: 正常 form 模式只发 acp:elicitation,响应后 1805s 内不发 resolved(clearTimeout 生效)', async () => {
|
|
917
917
|
const bridge = createBridge();
|
|
918
918
|
|
|
919
919
|
const promise = bridge.unstable_createElicitation({
|
|
@@ -929,8 +929,8 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
929
929
|
|
|
930
930
|
expect(await promise).toEqual({ action: 'accept', content: { answer: 'x' } });
|
|
931
931
|
|
|
932
|
-
// 推进
|
|
933
|
-
await vi.advanceTimersByTimeAsync(
|
|
932
|
+
// 推进 1805s:已响应的请求不得再发 timeout resolved
|
|
933
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
934
934
|
expect(mockSocket.emit).not.toHaveBeenCalledWith('acp:elicitation:resolved', expect.anything());
|
|
935
935
|
});
|
|
936
936
|
|
|
@@ -958,7 +958,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
958
958
|
expect(await promise).toEqual({ action: 'cancel' });
|
|
959
959
|
});
|
|
960
960
|
|
|
961
|
-
it('T-B5c: stop() 就地收敛 pending 问询为 cancelled,
|
|
961
|
+
it('T-B5c: stop() 就地收敛 pending 问询为 cancelled,1805s 后不再发 timeout', async () => {
|
|
962
962
|
const bridge = createBridge();
|
|
963
963
|
|
|
964
964
|
const promise = bridge.unstable_createElicitation({
|
|
@@ -979,7 +979,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
979
979
|
}));
|
|
980
980
|
|
|
981
981
|
mockSocket.emit.mockClear();
|
|
982
|
-
await vi.advanceTimersByTimeAsync(
|
|
982
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
983
983
|
expect(mockSocket.emit).not.toHaveBeenCalledWith('acp:elicitation:resolved', expect.anything());
|
|
984
984
|
});
|
|
985
985
|
|
|
@@ -997,8 +997,8 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
997
997
|
|
|
998
998
|
expect(await promise).toEqual({ outcome: { outcome: 'cancelled' } });
|
|
999
999
|
expect(settled).toHaveBeenCalledTimes(1);
|
|
1000
|
-
await vi.advanceTimersByTimeAsync(
|
|
1001
|
-
// timer 已清理:
|
|
1000
|
+
await vi.advanceTimersByTimeAsync(905_000);
|
|
1001
|
+
// timer 已清理:905s 后不会再有新的 permission 事件,且不会二次 settled
|
|
1002
1002
|
expect(mockSocket.emit.mock.calls.filter((c: unknown[]) => c[0] === 'acp:permission')).toHaveLength(1);
|
|
1003
1003
|
expect(settled).toHaveBeenCalledTimes(1);
|
|
1004
1004
|
});
|
|
@@ -1101,7 +1101,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
1101
1101
|
await stopPromise;
|
|
1102
1102
|
});
|
|
1103
1103
|
|
|
1104
|
-
it('T-B11: 进程退出(spawner.closed)收敛 pending 并发 cancelled,
|
|
1104
|
+
it('T-B11: 进程退出(spawner.closed)收敛 pending 并发 cancelled,1805s 后不再发 timeout', async () => {
|
|
1105
1105
|
const bridge = createBridge();
|
|
1106
1106
|
await bridge.start();
|
|
1107
1107
|
|
|
@@ -1125,11 +1125,11 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
1125
1125
|
detail: 'process exited',
|
|
1126
1126
|
}));
|
|
1127
1127
|
|
|
1128
|
-
// 真实时钟推进
|
|
1128
|
+
// 真实时钟推进 1805s:timer 已清理,不得再发 timeout
|
|
1129
1129
|
const resolvedReasons = mockSocket.emit.mock.calls
|
|
1130
1130
|
.filter((c: unknown[]) => c[0] === 'acp:elicitation:resolved')
|
|
1131
1131
|
.map((c: unknown[]) => (c[1] as { reason: string }).reason);
|
|
1132
|
-
await vi.advanceTimersByTimeAsync(
|
|
1132
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
1133
1133
|
const afterReasons = mockSocket.emit.mock.calls
|
|
1134
1134
|
.filter((c: unknown[]) => c[0] === 'acp:elicitation:resolved')
|
|
1135
1135
|
.map((c: unknown[]) => (c[1] as { reason: string }).reason);
|
|
@@ -1150,7 +1150,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
1150
1150
|
bridge.settlePendingOnDisconnect();
|
|
1151
1151
|
|
|
1152
1152
|
expect(await promise).toEqual({ action: 'cancel' });
|
|
1153
|
-
await vi.advanceTimersByTimeAsync(
|
|
1153
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
1154
1154
|
const reasons = mockSocket.emit.mock.calls
|
|
1155
1155
|
.filter((c: unknown[]) => c[0] === 'acp:elicitation:resolved')
|
|
1156
1156
|
.map((c: unknown[]) => (c[1] as { reason: string }).reason);
|
|
@@ -1183,7 +1183,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
1183
1183
|
const permissionId = (mockSocket.emit.mock.calls.find(
|
|
1184
1184
|
(c: unknown[]) => c[0] === 'acp:permission',
|
|
1185
1185
|
)![1] as { requestId: string }).requestId;
|
|
1186
|
-
await vi.advanceTimersByTimeAsync(
|
|
1186
|
+
await vi.advanceTimersByTimeAsync(905_000);
|
|
1187
1187
|
await permissionPromise;
|
|
1188
1188
|
expect(permissionSettled).toHaveBeenCalledWith(permissionId);
|
|
1189
1189
|
});
|
|
@@ -1216,7 +1216,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
1216
1216
|
}));
|
|
1217
1217
|
|
|
1218
1218
|
mockSocket.emit.mockClear();
|
|
1219
|
-
await vi.advanceTimersByTimeAsync(
|
|
1219
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
1220
1220
|
expect(mockSocket.emit).not.toHaveBeenCalledWith('acp:elicitation:resolved', expect.anything());
|
|
1221
1221
|
});
|
|
1222
1222
|
});
|
package/src/acp/bridge.ts
CHANGED
|
@@ -12,6 +12,10 @@ import { withSpan } from '../observability/trace.js';
|
|
|
12
12
|
|
|
13
13
|
const ACP_PROTOCOL_VERSION = 1;
|
|
14
14
|
|
|
15
|
+
/** 问询/授权兜底超时 = controller-api 权威超时 + 5s race 余量(提问 30 分钟 / 权限审批 15 分钟) */
|
|
16
|
+
const ELICITATION_FALLBACK_TIMEOUT_MS = 1_805_000;
|
|
17
|
+
const PERMISSION_FALLBACK_TIMEOUT_MS = 905_000;
|
|
18
|
+
|
|
15
19
|
/** 初始 mode/model 应用后回读确认失败时的重试间隔 */
|
|
16
20
|
const INITIAL_CONFIG_RETRY_DELAY_MS = 300;
|
|
17
21
|
|
|
@@ -418,7 +422,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
418
422
|
this.activePrompt = null;
|
|
419
423
|
this.inputQueue = [];
|
|
420
424
|
// 会话关闭:所有在途问询/授权必须先同步收敛(在 cancel/closeSession 的 5s race 之前),
|
|
421
|
-
// 否则 race 窗口内
|
|
425
|
+
// 否则 race 窗口内 1805s/905s timer 仍可能迟到发 timeout。
|
|
422
426
|
this.settlePendingRequests('session stopped by user');
|
|
423
427
|
this.clearPendingInitialConfig();
|
|
424
428
|
let stopTimer: ReturnType<typeof setTimeout> | undefined;
|
|
@@ -442,7 +446,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
442
446
|
|
|
443
447
|
/**
|
|
444
448
|
* 清空 pending 请求:clearTimeout + resolve(cancel) + delete。
|
|
445
|
-
* 问询额外回发 resolved(cancelled),让服务端待办收敛为 cancelled 而不是等
|
|
449
|
+
* 问询额外回发 resolved(cancelled),让服务端待办收敛为 cancelled 而不是等 1805s 超时误标 expired。
|
|
446
450
|
* 同时发出 settled 事件,供 socketio-client 清理 requestId → bridge 映射(避免 Map 单调增长/阻止 GC)。
|
|
447
451
|
*/
|
|
448
452
|
private settlePendingRequests(detail: string): void {
|
|
@@ -979,7 +983,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
979
983
|
this.pendingPermissions.delete(requestId);
|
|
980
984
|
this.emit('permission:settled', requestId);
|
|
981
985
|
resolve({ outcome: { outcome: 'cancelled' } });
|
|
982
|
-
},
|
|
986
|
+
}, PERMISSION_FALLBACK_TIMEOUT_MS);
|
|
983
987
|
|
|
984
988
|
this.pendingPermissions.set(requestId, { resolve, timeout });
|
|
985
989
|
|
|
@@ -1045,16 +1049,16 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
1045
1049
|
requestId,
|
|
1046
1050
|
...(pending?.elicitationId ? { elicitationId: pending.elicitationId } : {}),
|
|
1047
1051
|
},
|
|
1048
|
-
'elicitation timed out after
|
|
1052
|
+
'elicitation timed out after 1805s, auto-cancelling',
|
|
1049
1053
|
);
|
|
1050
1054
|
this.socket.emit('acp:elicitation:resolved', {
|
|
1051
1055
|
requestId,
|
|
1052
1056
|
sessionId: this.sessionId,
|
|
1053
1057
|
reason: 'timeout',
|
|
1054
|
-
detail: 'bridge timeout (
|
|
1058
|
+
detail: 'bridge timeout (1805s)',
|
|
1055
1059
|
});
|
|
1056
1060
|
resolve({ action: 'cancel' });
|
|
1057
|
-
},
|
|
1061
|
+
}, ELICITATION_FALLBACK_TIMEOUT_MS);
|
|
1058
1062
|
|
|
1059
1063
|
this.pendingElicitations.set(requestId, {
|
|
1060
1064
|
resolve,
|
|
@@ -1124,7 +1128,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
1124
1128
|
elicitationId: params.elicitationId,
|
|
1125
1129
|
});
|
|
1126
1130
|
|
|
1127
|
-
// Agent 自行完成/取消:对匹配的 pending 就地收敛,避免悬挂到
|
|
1131
|
+
// Agent 自行完成/取消:对匹配的 pending 就地收敛,避免悬挂到 1805s 被误标 expired。
|
|
1128
1132
|
// 契约 reason:'cancelled' 的产生路径之一(另一处为会话关闭 settle)。
|
|
1129
1133
|
const entry = [...this.pendingElicitations.entries()]
|
|
1130
1134
|
.find(([, pending]) => pending.elicitationId === params.elicitationId);
|
|
@@ -1205,7 +1209,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
1205
1209
|
);
|
|
1206
1210
|
const wasStopped = this.stopped || this.silentStop;
|
|
1207
1211
|
this.stopped = true;
|
|
1208
|
-
// 进程崩溃同样必须收敛 pending:否则
|
|
1212
|
+
// 进程崩溃同样必须收敛 pending:否则 1805s timer 泄漏且迟发 timeout 事件
|
|
1209
1213
|
this.settlePendingRequests('session failed');
|
|
1210
1214
|
this.clearPendingInitialConfig();
|
|
1211
1215
|
// 已停止(含 silent 替换/对账)后迟到的初始化失败:不得再发 stopped,
|
package/src/acp/spawner.ts
CHANGED
|
@@ -125,7 +125,7 @@ export class AcpSpawner {
|
|
|
125
125
|
|
|
126
126
|
this.process.on('error', (error) => {
|
|
127
127
|
this.log.error({ event: 'acp_process_error', command: cmd, err: error }, 'acp process error');
|
|
128
|
-
// spawn 失败同样视为进程终止:必须 resolve closed,让 bridge 收敛 pending,避免
|
|
128
|
+
// spawn 失败同样视为进程终止:必须 resolve closed,让 bridge 收敛 pending,避免 1805s(提问)/905s(权限审批)迟到 timeout
|
|
129
129
|
this.process = null;
|
|
130
130
|
this.resolveClosed?.();
|
|
131
131
|
});
|
package/src/socketio-client.ts
CHANGED
|
@@ -1807,7 +1807,7 @@ export function connectToServer(
|
|
|
1807
1807
|
heartbeat.stop();
|
|
1808
1808
|
gatewayManager.closeAll();
|
|
1809
1809
|
// 断线后 pending 计时器必须就地收敛:socket.io 会缓存断线期间 emit,
|
|
1810
|
-
// 不收敛会在重连后补发
|
|
1810
|
+
// 不收敛会在重连后补发 1805s(提问)/905s(权限审批)timeout(待办被误标 expired)。
|
|
1811
1811
|
for (const bridge of acpBridges.values()) {
|
|
1812
1812
|
bridge.settlePendingOnDisconnect();
|
|
1813
1813
|
}
|
package/tests/acp-bridge.test.ts
CHANGED
|
@@ -519,7 +519,7 @@ describe('AcpSessionBridge', () => {
|
|
|
519
519
|
expect(result).toEqual({ outcome: { outcome: 'selected', optionId: 'opt-1' } });
|
|
520
520
|
});
|
|
521
521
|
|
|
522
|
-
it('should resolve with cancelled on
|
|
522
|
+
it('should resolve with cancelled on 905s timeout', async () => {
|
|
523
523
|
const bridge = createBridge();
|
|
524
524
|
|
|
525
525
|
const promise = bridge.requestPermission({
|
|
@@ -527,7 +527,7 @@ describe('AcpSessionBridge', () => {
|
|
|
527
527
|
toolCall: { toolCallId: 'tc-1' },
|
|
528
528
|
} as never);
|
|
529
529
|
|
|
530
|
-
await vi.advanceTimersByTimeAsync(
|
|
530
|
+
await vi.advanceTimersByTimeAsync(905_000);
|
|
531
531
|
|
|
532
532
|
const result = await promise;
|
|
533
533
|
expect(result).toEqual({ outcome: { outcome: 'cancelled' } });
|
|
@@ -609,7 +609,7 @@ describe('AcpSessionBridge', () => {
|
|
|
609
609
|
expect(mockSocket.emit).not.toHaveBeenCalledWith('acp:elicitation', expect.anything());
|
|
610
610
|
});
|
|
611
611
|
|
|
612
|
-
it('
|
|
612
|
+
it('1805s 超时自动 resolve cancel', async () => {
|
|
613
613
|
const bridge = createBridge();
|
|
614
614
|
|
|
615
615
|
const promise = bridge.unstable_createElicitation({
|
|
@@ -619,7 +619,7 @@ describe('AcpSessionBridge', () => {
|
|
|
619
619
|
requestedSchema: { type: 'object' },
|
|
620
620
|
} as never);
|
|
621
621
|
|
|
622
|
-
await vi.advanceTimersByTimeAsync(
|
|
622
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
623
623
|
|
|
624
624
|
const result = await promise;
|
|
625
625
|
expect(result).toEqual({ action: 'cancel' });
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* 用法(在 packages/agent-controller 目录):
|
|
14
14
|
* npx tsx tests/manual/repro-question-tool.ts <policy> [prompt]
|
|
15
15
|
*
|
|
16
|
-
* policy = none
|
|
16
|
+
* policy = none 不响应问询(观测提问兜底超时后的工具结果;bridge 兜底为 1805s,
|
|
17
|
+
* 需等待约 30 分钟,脚本定时器留 15s 余量)
|
|
17
18
|
* accept 收到问询立即 accept(对照组:question 工具应 completed)
|
|
18
19
|
* decline 收到问询立即 decline
|
|
19
20
|
* cancel 收到问询立即 cancel(秒级复现 "dismissed")
|
|
@@ -97,8 +98,12 @@ async function main(): Promise<void> {
|
|
|
97
98
|
log('prompt sent');
|
|
98
99
|
|
|
99
100
|
await new Promise<void>((resolve) => {
|
|
100
|
-
//
|
|
101
|
-
const
|
|
101
|
+
// 提问 bridge 兜底 1805s(30 分钟 5 秒,= controller-api 权威 1800s + 5s race 余量)+ 15s 余量
|
|
102
|
+
const BRIDGE_ELICITATION_FALLBACK_MS = 1_805_000;
|
|
103
|
+
const timer = setTimeout(() => {
|
|
104
|
+
log('TIMEOUT 1820s(未观测到 bridge timeout,请检查策略/进程)');
|
|
105
|
+
resolve();
|
|
106
|
+
}, BRIDGE_ELICITATION_FALLBACK_MS + 15_000);
|
|
102
107
|
bridge.on('acp:stopped', () => {
|
|
103
108
|
log('bridge stopped');
|
|
104
109
|
clearTimeout(timer);
|