fix: Prevent commit-retry infinite loop by preserving retry count across cleanup
commitRetryCount was being deleted in cleanupAgentState(), which runs before tryAutoCleanup() checks the count. This reset the counter to 0 on every cycle, making MAX_COMMIT_RETRIES=1 dead code. Agents would retry commits forever. Move commitRetryCount cleanup to stop()/delete() only, letting tryAutoCleanup() manage it during the retry lifecycle.
This commit is contained in:
@@ -107,13 +107,14 @@ export class MultiProviderAgentManager implements AgentManager {
|
||||
|
||||
/**
|
||||
* Centralized cleanup of all in-memory state for an agent.
|
||||
* Cancels polling timer, removes from activeAgents and commitRetryCount.
|
||||
* Cancels polling timer, removes from activeAgents.
|
||||
* NOTE: Does NOT clear commitRetryCount — that's managed by tryAutoCleanup()
|
||||
* and explicitly by stop()/delete() to avoid resetting retries mid-cycle.
|
||||
*/
|
||||
private cleanupAgentState(agentId: string): void {
|
||||
const active = this.activeAgents.get(agentId);
|
||||
if (active?.cancelPoll) active.cancelPoll();
|
||||
this.activeAgents.delete(agentId);
|
||||
this.commitRetryCount.delete(agentId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -635,6 +636,7 @@ export class MultiProviderAgentManager implements AgentManager {
|
||||
await active.tailer.stop();
|
||||
}
|
||||
this.cleanupAgentState(agentId);
|
||||
this.commitRetryCount.delete(agentId);
|
||||
|
||||
// Sync credentials before marking stopped
|
||||
await this.syncCredentialsPostCompletion(agentId);
|
||||
@@ -811,6 +813,7 @@ export class MultiProviderAgentManager implements AgentManager {
|
||||
await active.tailer.stop();
|
||||
}
|
||||
this.cleanupAgentState(agentId);
|
||||
this.commitRetryCount.delete(agentId);
|
||||
|
||||
// 2. Best-effort cleanup
|
||||
try { await this.cleanupManager.removeAgentWorktrees(agent.name, agent.initiativeId); }
|
||||
|
||||
Reference in New Issue
Block a user