fix(dingtalk): exclude removed instances from routing + clear binding on remove
Two bugs fixed: 1. findByDingTalkUserId now filters status != 'removed' so a re-bound new instance is not shadowed by an old removed one with the same DingTalk user ID. 2. When an agent is deleted (removed), its dingtalkUserId is cleared so the DingTalk ID is freed for reuse by the next binding. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a8b5571aea
commit
50401660ef
|
|
@ -1,5 +1,5 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { DataSource, Not, Repository } from 'typeorm';
|
||||
import { AgentInstance } from '../../domain/entities/agent-instance.entity';
|
||||
|
||||
@Injectable()
|
||||
|
|
@ -27,7 +27,8 @@ export class AgentInstanceRepository {
|
|||
}
|
||||
|
||||
findByDingTalkUserId(dingTalkUserId: string): Promise<AgentInstance | null> {
|
||||
return this.repo.findOne({ where: { dingTalkUserId } as any });
|
||||
// Exclude removed instances so a rebound new instance is routed correctly
|
||||
return this.repo.findOne({ where: { dingTalkUserId, status: Not('removed') } as any });
|
||||
}
|
||||
|
||||
save(instance: AgentInstance): Promise<AgentInstance> {
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@ export class AgentInstanceController {
|
|||
if (!inst) throw new NotFoundException(`Instance ${id} not found`);
|
||||
await this.deployService.removeInstance(inst);
|
||||
inst.status = 'removed';
|
||||
inst.dingTalkUserId = null as any; // Clear DingTalk binding so the ID can be reused by a new instance
|
||||
await this.instanceRepo.save(inst);
|
||||
return { message: 'Instance removed', id };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue