fix(session): cleared session-scoped tool state

Cleared queued tool-choice directives and ACP always decisions after successful logical session transitions.

Added new-session and cross-session regression coverage for staged resolves and both ACP always decisions.

Fixes #4093
This commit is contained in:
roboomp
2026-07-23 19:57:57 +00:00
committed by can1357
parent 3d64910bb0
commit e6cdfd6187
5 changed files with 121 additions and 3 deletions
@@ -4023,6 +4023,12 @@ export class AgentSession {
this.#rewoundToolResultIds.clear();
}
/** Drop mutable tool decisions and directives owned by the previous logical session. */
#clearSessionScopedToolState(): void {
this.#toolChoiceQueue.clear();
this.#tools.clearAcpPermissionDecisions();
}
/**
* Rebuild checkpoint/rewind runtime state from the current branch. Handles two
* cases surfaced by session resume, `switchSession()` reloading the same file,
@@ -5690,6 +5696,7 @@ export class AgentSession {
this.#bash.finishSessionTransition(bashTransition, sessionTransitioned);
}
this.#clearSessionScopedToolState();
this.#clearCheckpointRuntimeState();
this.setTodoPhases([]);
this.#freshProviderSessionId = undefined;
@@ -6810,6 +6817,9 @@ export class AgentSession {
if (switchingToDifferentSession) {
await this.#memory.resetContextForNewTranscript();
}
if (switchingToDifferentSession) {
this.#clearSessionScopedToolState();
}
this.#reconnectToAgent();
try {
await this.#sessionSwitchReconciler?.();
@@ -158,6 +158,11 @@ export class SessionTools {
return this.#skillsSettings;
}
/** Drops cached per-session ACP `allow_always`/`reject_always` decisions. */
clearAcpPermissionDecisions(): void {
this.#acpPermissionDecisions.clear();
}
/** Re-wraps active and mounted tools after the ACP client changes. */
refreshAcpPermissionGates(): void {
this.#acpPermissionDecisions.clear();