Skip to content

fix(extension): invalidate ended browser task approvals - #5698

Open
iscekic wants to merge 9 commits into
browser-task-0787-s8from
browser-task-0787-s9
Open

fix(extension): invalidate ended browser task approvals#5698
iscekic wants to merge 9 commits into
browser-task-0787-s8from
browser-task-0787-s9

Conversation

@iscekic

@iscekic iscekic commented Aug 29, 2026

Copy link
Copy Markdown
Contributor
  • Workflow save prompts disappear when there is no draft left to save.
  • A newer memory or workflow draft no longer inherits an older prompt’s save result, error, or disabled buttons.
  • Repeated clicks cannot start a second save while the same draft is saving.

Summary

DelegatedApprovalScope adds trusted isLive and executionGuard callbacks to requestApproval; PendingApprovalEntry requires normalized drafts, and persisted metadata grants no delegated authority. applyApprovalDecision returns aborted for expired, cancelled, replayed, or unproven reloaded approvals and rechecks authority before writes; Stop cannot undo an issued save. settleMatchingApproval keeps failed live delegated approvals pending for explicit retry, while terminal settlement clears only matching approval state.

Files
  • apps/extension/entrypoints/sidepanel/pending-approval.ts — Source, modified, 570 changed lines. Generates fresh approval IDs, validates draft kinds, and adds expiry timers with first-wins settlement. Keeps one approval lock across settings reads and draft persistence; automatic approval retains the settings fallback. Preserves local cleanup errors, but delegated cleanup failures cannot retract a successful save. Prevents retained callbacks from clearing another request’s entry or lock.
  • apps/extension/entrypoints/sidepanel/pending-approval.test.ts — Test, modified, 369 changed lines. Updates the approval lifecycle tests.

ApprovalOrigin uses approvalOriginSchema to distinguish local drafts from DelegatedApprovalOrigin, whose delegatedApprovalOriginSchema requires invocationId, approvalId, and expiresAt. PendingAgentMemoryDraft and PendingAgentWorkflowDraft keep optional origins; NormalizedPendingAgentMemoryDraft and NormalizedPendingAgentWorkflowDraft require them. pendingAgentMemoryDraftSchema and pendingAgentWorkflowDraftSchema default absent origins to local, preserving existing drafts and background selections without migration.

Files
  • apps/extension/src/shared/agent-memories.ts — Source, modified, 33 changed lines. Defines origin validation, exact delegated approval matching, and normalized memory drafts. Requires nonempty delegated IDs and a nonnegative integer expiry; buildPendingMemoryDraft passes through an optional origin.
  • apps/extension/src/shared/agent-workflows.ts — Source, modified, 8 changed lines. Shares origin validation and adds the normalized workflow draft type while preserving optional producer metadata.

withPendingDraftStorageLock serializes draft access with a queue and Web Locks; the fallback retains local, in-context behavior. addAgentMemory, addAgentWorkflow, updateAgentWorkflow, savePendingAgentMemoryDraft, and savePendingWorkflowDraft accept optional ExecutionGuard callbacks immediately before writes. clearPendingAgentMemoryDraft and clearPendingWorkflowDraft accept an expected DelegatedApprovalOrigin, preventing stale cleanup from deleting replacements; old callers still clear unconditionally.

Files
  • apps/extension/src/shared/agent-memories-storage.ts — Source, modified, 110 changed lines. Adds the shared queue and native lock, preserves origins in serialization, and returns normalized drafts. Guards saves after awaited preparation and serializes comparison with removal, including writes from background selections.
  • apps/extension/src/shared/agent-workflows-storage.ts — Source, modified, 89 changed lines. Uses the shared lock for draft reads, saves, and conditional removal. Preserves origins, returns normalized drafts, and guards workflow creation, updates, and draft writes.
  • apps/extension/src/shared/agent-memories-storage.test.ts — Test, modified, 126 changed lines. Updates the memory draft persistence tests.
  • apps/extension/src/shared/agent-workflows-storage.test.ts — Test, modified, 99 changed lines. Updates the workflow draft persistence tests.

PendingMemorySaveCard and PendingWorkflowSaveCard use approvalDraftKey, isApprovalDraftLive, and discardInactiveApprovalDraft to hide stale delegated cards and protect newer drafts. Empty reloads clear old workflow forms, and save failures keep retry or rejection controls while the delegated invocation remains live. Local drafts still reload, background memory selections keep priority, and per-draft save locks prevent repeated clicks from starting duplicate saves.

Files
  • apps/extension/entrypoints/sidepanel/pending-memory-save-card.tsx — Source, modified, 168 changed lines. Normalizes stored drafts, prefers the active entry when delegation is involved, and reads decisions from the component’s atom store. Resets note, error, and busy state by draft identity; ignores older save or cancellation results. Renders the supervision slot in every visible state, including saved confirmation.
  • apps/extension/entrypoints/sidepanel/pending-workflow-save-card.tsx — Source, modified, 198 changed lines. Rechecks liveness after asynchronous loads and clears form, error, comparison, and busy state when drafts disappear or change. Ignores superseded loads and decisions, retains explicit recovery after live delegated save failures, and renders the supervision slot throughout the modal.
  • apps/extension/entrypoints/sidepanel/pending-workflow-save-card.test.ts — Test, modified, 561 changed lines. Updates the approval card tests.

BrowserTaskSupervisionContext defaults to null; BrowserTaskSupervisionSlot places supplied content inside both approval dialogs without adding a wrapper or spacing. The slot remains available during editing, saving, errors, full storage, and memory confirmation, so supervision stays within the modal boundary. This level adds no provider controls and does not enable complete delegated execution.

Files
  • apps/extension/entrypoints/sidepanel/browser-task-supervision-slot.tsx — Source, added, 8 changed lines. Adds the shared context and slot; an absent provider renders nothing and leaves the local layout unchanged.

Tests: 4 modified files—pending-approval.test.ts, pending-workflow-save-card.test.ts, agent-memories-storage.test.ts, and agent-workflows-storage.test.ts—with 1,155 changed lines.
Generated: 0 files changed.


Verification

Manual browser verification has not run; this level does not enable the complete provider feature. Live browser verification remains pending, and the handoff includes no end-to-end (E2E) report.

Visual Changes

Visual Changes: N/A

Reviewer Notes

Human steps

  • before merge: Complete all section gates, including checks with native Chrome, Firefox, the real command-line interface (CLI), and the local relay.
  • before merge: After the gates pass, merge the lower stack levels before this level.
  • after merge: Continue merging the higher stack levels in order.

This level needs no new environment values, secrets, data migration, feature flags, or cache resets.

Context

  • This description covers Cloud level 9, from browser-task-0787-s8 to browser-task-0787-s9, not the complete section.
  • The base is Cloud level 8, which supplies browser execution coordination.
  • The companion CLI level 6 supplies owned browser-job support.
  • The handoff reports 188 passing tests and all five scoped checks passing. These are automated results, not manual browser evidence.

Notes

Live browser verification is pending. Native Chrome and Firefox behavior, the real CLI, and the local relay remain required before human-ready.

Stacked PRs — merge bottom to top. Each level shows only its own diff.

Runtime verification (E2E, user advocacy, simplify) runs on the tip PR over every level.
Every level keeps its own checks, its own bot review, and its own threads; each one is answered on its own PR.
Each level is its own deliverable: it builds and passes its own checks alone.
A finding on a level is repaired on that level, then carried upward with stack.sh forward.

  1. browser-task-0787feat(browser-task): define negotiated job contracts #5638
  2. browser-task-0787-s2feat(session-ingest): persist owned browser jobs #5644
  3. browser-task-0787-s3feat(session-ingest): route fenced browser providers #5648
  4. browser-task-0787-s4feat(cloud-agent-sdk): support browser provider jobs #5653
  5. browser-task-0787-s7fix(extension): expose honest browser runner outcomes #5681
  6. browser-task-0787-s8feat(extension): coordinate browser execution across panels #5694
  7. browser-task-0787-s9fix(extension): invalidate ended browser task approvals #5698 ← this PR
  8. browser-task-0787-s10feat(extension): persist browser jobs and profile consent #5702 (tip)

@kilo-code-bot

kilo-code-bot Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/extension/entrypoints/sidepanel/pending-memory-save-card.tsx 138 In-flight Cancel still tears down the save confirmation
apps/extension/entrypoints/sidepanel/pending-workflow-save-card.tsx 163 Superseded approve/cancel can clear a replacement draft
Files Reviewed (12 files)
  • apps/extension/entrypoints/sidepanel/browser-task-supervision-slot.tsx - 0 issues
  • apps/extension/entrypoints/sidepanel/pending-approval.test.ts - 0 issues
  • apps/extension/entrypoints/sidepanel/pending-approval.ts - 0 issues
  • apps/extension/entrypoints/sidepanel/pending-memory-save-card.tsx - 1 issue
  • apps/extension/entrypoints/sidepanel/pending-workflow-save-card.test.ts - 0 issues
  • apps/extension/entrypoints/sidepanel/pending-workflow-save-card.tsx - 1 issue
  • apps/extension/src/shared/agent-memories-storage.test.ts - 0 issues
  • apps/extension/src/shared/agent-memories-storage.ts - 0 issues
  • apps/extension/src/shared/agent-memories.ts - 0 issues
  • apps/extension/src/shared/agent-workflows-storage.test.ts - 0 issues
  • apps/extension/src/shared/agent-workflows-storage.ts - 0 issues
  • apps/extension/src/shared/agent-workflows.ts - 0 issues

Reviewed by grok-4.6 · Input: 513.7K · Output: 38.7K · Cached: 1.9M

Review guidance: REVIEW.md from base branch browser-task-0787-s8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant