PLG-CAL-003 fix deferred slot replanning

This commit is contained in:
zhi
2026-04-01 08:52:11 +00:00
parent 97021f97c0
commit 24c4a7ad14
5 changed files with 71 additions and 2 deletions

View File

@@ -167,6 +167,15 @@ export class CalendarScheduler {
return;
}
// Agent is idle again - previously deferred slots should become eligible
// for selection in the next planning pass.
if (this.state.deferredSlotIds.size > 0) {
this.logDebug(
`Agent returned to idle; clearing ${this.state.deferredSlotIds.size} deferred slot marker(s) for replanning`
);
this.state.deferredSlotIds.clear();
}
// Agent is idle - handle pending slots
await this.handleIdleAgent(response.slots);
@@ -298,6 +307,10 @@ export class CalendarScheduler {
// Revert slot to not_started status
await this.revertSlot(slot);
await this.config.bridge.reportAgentStatus({ status: 'idle' });
this.state.isProcessing = false;
this.state.currentSlot = null;
await this.triggerReplan('wake failure');
return;
}
// Note: isProcessing remains true until agent signals completion
@@ -511,6 +524,7 @@ Please use this time for the scheduled activity.`;
} finally {
this.state.isProcessing = false;
this.state.currentSlot = null;
await this.triggerReplan('slot completion');
}
}
@@ -548,6 +562,7 @@ Please use this time for the scheduled activity.`;
} finally {
this.state.isProcessing = false;
this.state.currentSlot = null;
await this.triggerReplan('slot abort');
}
}
@@ -608,6 +623,25 @@ Please use this time for the scheduled activity.`;
}
}
/**
* Trigger an immediate replanning pass after the current slot lifecycle ends.
* This lets previously deferred/not-started slots compete again as soon as
* the agent becomes idle.
*/
private async triggerReplan(reason: string): Promise<void> {
if (!this.state.isRunning) {
return;
}
this.logDebug(`Triggering immediate replanning after ${reason}`);
try {
await this.runHeartbeat();
} catch (err) {
this.config.logger.error(`Failed to trigger replanning after ${reason}:`, err);
}
}
/**
* Get a stable ID for a slot (real or virtual).
*/