Automations and webhooks for the AT Protocol airglow.run

fix(confirm): confirm destructive actions in a dialog with Cancel focused, and confirm secret deletion #115

Closed there-hugo.dev
Closed opened by there-hugo.dev

Found by the modern-web-guidance audit of 2026-11-14 (pnpm web-guidance, see .agents/skills/modern-web-guidance/).

Problem #

  • Deleting an automation and discarding or restoring drafts use window.confirm(), which focuses OK: a reflexive Enter deletes. Its buttons say OK and Cancel rather than the action, and it can't follow the theme.
  • RevokeSessions swaps its button for an inline confirm panel, and Cancel unmounts it again: both times focus drops to <body>, and its error isn't announced.
  • Deleting a secret takes effect at once, with no confirmation, and breaks the webhooks that use it.

Evidence #

  • app/islands/AutomationToolbar.tsx:155; app/islands/AutomationForm.tsx:1067, 1081, 1097, 1113, 1127, 1242, 1283.
  • app/islands/RevokeSessions.tsx:66-93; app/islands/SecretsManager.tsx:168-174.

Expected #

One shared confirmation built on <dialog>, with the safe action focused and the destructive button named with its verb.

Acceptance criteria #

Out of scope #

Undo for deletions.

Guidance #

  • dialog: pnpm web-guidance retrieve dialog
  • platform-controls-dismiss-dialog: pnpm web-guidance retrieve platform-controls-dismiss-dialog
  • prevent-page-scroll-under-modal-dialog: pnpm web-guidance retrieve prevent-page-scroll-under-modal-dialog

docs/design.md wins where a guide disagrees with it.

Queued: the loop will work on this version of the issue.

loop:queued cid=bafyreid6s4g5go7zvyhunukehdrcuzguijfnaodooi3nc4rxrfl6exloeq

Working on this, attempt 1.

loop:claim run=contribute-20261114-182107-115 branch=loop/115 attempt=1 issue=115

fix(confirm): confirm destructive actions in a dialog with Cancel focused, and confirm secret deletion

Destructive actions now ask in one shared modal <dialog> instead of window.confirm() or an inline panel. Cancel has the focus when it opens, so a reflexive Enter cancels, and the other button says what it does ("Delete automation", "Discard draft", "Revoke and sign out"). The new helper is confirmDialog() in app/islands/confirm-dialog.tsx. Deleting an automation, restoring or discarding drafts, removing a step or branch that holds steps, revoking all sessions and deleting a secret all go through it. Deleting a secret used to happen with no question at all. Now it asks first and names the secret.

What changed #

  • app/islands/confirm-dialog.tsx (new): confirmDialog({ title, body?, confirmLabel }) renders a <dialog aria-labelledby aria-describedby> into the page and opens it with showModal(). Inside is an <h2> title, an optional one-line body and a <form method="dialog"> with two Buttons: Cancel (secondary, autofocus) and the action (primary, named for its verb). The promise resolves from the close event: it is true only when returnValue is the action's value. Cancel, Esc and the back gesture resolve false. Then returnValue is reset and the dialog is removed. The code has no focus trap, no Esc handler and no focus restore: the browser does all three. Call sites read if (!(await confirmDialog(...))) return.
  • confirm-dialog.css.ts: the card look comes from tokens (surface, border, radii.lg, shadow.lg, space[5]). margin: auto puts the centring back after the reset's margin: 0. Width is min(28rem, 100vw − space[6]) with border-box. A long name wraps in the title (overflow-wrap: anywhere). overscroll-behavior: contain is set on :modal, and overflow: hidden plus overscroll-behavior: contain on ::backdrop, so scrolling doesn't reach the page behind.
  • AutomationToolbar: Delete asks "Delete this automation?" / "This cannot be undone." / Delete automation.
  • AutomationForm: all seven confirm() calls now use the dialog. They are discard restored draft, restore and discard the held-back draft, restore and discard the stale draft, remove a step with steps inside it, and remove branches with steps in them. Each keeps its old question, with the consequence as the body line. The buttons say Discard draft, Restore draft, Remove step, Remove else branch or Remove branches, matching the button that opened the dialog.
  • RevokeSessions: the inline confirm panel is gone. "Revoke all sessions" opens the dialog: "Stop your active automations and sign out everywhere?" / "You'll need to re-authorize Airglow to use it again." / Revoke and sign out. While the request runs, the same button reads "Revoking..." and is aria-disabled="true", not disabled, so it keeps the focus the dialog handed back. The error's role="alert" region is in the page from the first render, under the button, so an error is announced. The panel's now-unused styles are removed.
  • SecretsManager: Delete asks Delete the secret "<name>"? / "Webhooks that use it will stop working." / Delete secret. Each row's Delete is now named Delete <name>, like its neighbour Copy {{secret:<name>}}. While deleting it is aria-disabled, not disabled. After a delete, focus moves to the Delete button in the removed row's place (the next row, or the previous one after the last). With no rows left it moves to the Name field, not <body>.
  • Tests: lib/test/dialog.ts adds openDialog() and answerDialog(label). answerDialog clicks a button in the open dialog through happy-dom's real method="dialog" submit. It first gives hono/jsx/dom's <form> the ev.detail it reads on untrusted submits. The toolbar, revoke, sign-out and secrets tests answer the real dialog. The AutomationForm tests mock confirmDialog, since the dialog has its own tests.

Verified #

  • pnpm run check: passes.
  • pnpm run test: passes (201 files, 2843 tests). New tests cover the dialog's markup: the name and description, no role and no aria-modal, method="dialog", and autofocus on Cancel only. They also check that it resolves true, false on Cancel and false on a plain close (as Esc does), and gets a fresh id each time. Other new tests check that the toolbar and revoke flows post nothing on Cancel, that the revoke and secret buttons render aria-disabled="true" (the string) and are not disabled while the request runs, the step and branch questions and labels, the secret's name in the question, and where focus lands after a delete.
  • vp build --mode client builds (the helper imports render from hono/jsx/dom).
  • Not verified in a live browser: the dev server needs the PDS, which isn't here. Esc closing the dialog, Tab moving between the two buttons, focus returning to the opener and the page behind being inert are what native <dialog>/showModal() does. happy-dom doesn't model them, so no test checks them. The screenshots show Chromium putting the autofocus ring on Cancel.

Screenshots #

pnpm preview:ui confirm-dialog (new app/previews/confirm-dialog.preview.tsx) opens the dialog with showModal() over the page behind it, in both themes:

  • delete-automation: over the toolbar. Title, body line, then Cancel (focused, with the ring) and Delete automation at the end of the row.
  • revoke-sessions: over the danger zone. A two-line title, body, Cancel and Revoke and sign out.
  • title-only: the step-removal question with no body line. The buttons follow the title directly.
  • long-secret-narrow: 360px wide with a 64-character secret name. The first shot overflowed the screen (content-box sizing plus an unbreakable name). Fixed with border-box and overflow-wrap: anywhere; now the name wraps inside the dialog and both buttons fit.

I read every PNG after each fix. One finding: the first run sat in the top-left corner because the reset's margin: 0 removes the dialog's centring. margin: auto puts it back. In the dark theme the browser's default backdrop barely dims the page. The dialog stands out by its border and raised surface. The preview shows server markup only, so the revoke button's "Revoking..." and error states are covered by tests, not shots.

Acceptance criteria #

  • Out of scope, untouched: undo for deletions.

Decisions the owner can reverse #

  • The action button is Button primary, not red. Button has no destructive variant, and its comment calls the system "fully neutral", so I didn't add one. A danger variant would be a small Button extension if you want the action red, as the old revoke panel's was.
  • The backdrop is the browser's default, so no new colour token. It dims the light theme a little and the dark theme barely.
  • The title is an <h2> at the global heading size, as docs/design.md says ("don't restyle them"). It is large for a dialog, and on a narrow screen a long question takes several lines.
  • Wording: the revoke action button says "Revoke and sign out" (was "Yes, revoke and sign out"). The removal questions keep their wording, except "this branch" became "the else branch" / "the branches" to match the button pressed. The secret's body line is "Webhooks that use it will stop working."
  • After deleting a secret, focus goes to the next row's Delete button (or the previous row's, or the Name field).

Modern Web Guidance #

  • dialog: I opened it with showModal() and left out role="dialog", aria-modal, a focus trap and an Esc handler, so the browser handles all of them ("DON'T add role="dialog", aria-modal, a focus trap, inert toggling or an Esc handler"). Cancel carries autofocus ("put autofocus on the safe action (such as Cancel or Keep) in a destructive confirmation"). I reset returnValue to '' in the close listener and treat anything but the action's value as a no ("Treat '' as 'dismissed without choosing'").
  • platform-controls-dismiss-dialog: no closedby, so a modal opened with showModal() closes on Esc and the back gesture by default. It resolves false then ("there is no specific change developers need to make").
  • prevent-page-scroll-under-modal-dialog: overscroll-behavior: contain on :modal, plus overflow: hidden with it on ::backdrop. Nothing changes on html or body ("::backdrop defaults to overflow: visible (not a scroll container)").

Follow-up, filed as a new issue on merge if the review agrees:

fix(automation-form): keep focus in the form after removing a condition's branches

Removing a condition step's branches drops keyboard focus to <body>. removeBranches in app/islands/AutomationForm.tsx sets the steps and clears the error, but never moves focus, unlike removeStep, which calls focusAfterRender(addFocusKey(slot)). The button that was pressed ("Remove else branch" or "Remove branches") is gone after the re-render, replaced by "+ Add else branch" or "+ Add then/else branches", so the focus it held falls to the page. This happens with or without the confirmation dialog (#115): the dialog hands focus back to the button, and the removal then unmounts it; with empty branches there is no dialog and the drop is immediate.

How I know: reading removeBranches (no focus call) and the condition body's markup around "Remove else branch", while wiring #115's dialog into it. The #115 test "asks before removing a branch with steps in it" shows the button is gone after the second press.

Where to start: give the "+ Add else branch" and "+ Add then/else branches" buttons a data-focus-key (as stepFocusKey does for the step tools) and call focusAfterRender with it at the end of removeBranches; add a test that checks document.activeElement after each removal.

Review: https://tangled.org/exosphere.site/airglow/compare/main...loop/115

loop:pushed run=contribute-20261114-182107-115 sha=65994ac5f1c9337cf998e162661f3186fe03e508

Changes requested. The dialog does what the issue asks, and at this head the check passes and all 2843 tests pass. The branch can't merge, though. It was cut from #113, and #114 (f4e3b3a, now on main) changed the same buttons. Git conflicts in RevokeSessions.tsx, RevokeSessions.css.ts, RevokeSessions.test.tsx and SecretsManager.tsx. #114 also added pendingProps, pendingText and useFocusRescue for exactly the pending-button work this branch writes by hand.

What I checked:

  • Acceptance criteria, against the code. confirmDialog opens a <dialog aria-labelledby> with showModal(). It holds a <form method="dialog"> with two Buttons: Cancel, which has autofocus, and the action named for its verb. It resolves from returnValue in close and resets it. There is no focus trap and no Esc handler. All seven AutomationForm confirm() calls and the toolbar's now use it, RevokeSessions too. rg 'confirm\(' finds none left in app/ or lib/. Deleting a secret asks first and names the secret. Undo (out of scope) is untouched.
  • Native behaviour, in headless Chromium, on the same markup and close logic. Enter on open cancels. Esc resolves false. Tab then Enter confirms. Focus returns to the opener every time, even though the host is removed in the close handler.
  • Screenshots. I ran pnpm preview:ui confirm-dialog and read all four states in both themes. The dialog is centred, the long secret name wraps at 360px, and Cancel shows the focus ring.
  • Guides. The dialog guide is satisfied (pnpm web-guidance retrieve dialog).
  • The fixes below, tried first. On a throwaway branch I merged this head into f4e3b3a and resolved the conflicts as described. I ported #114's tests to answer the dialog. Then vp test run gave 201 files and 2874 tests, all passing. vp check was clean apart from a format fix and an unused let resolve. The dialog looked the same with cardSurface in the preview.

Changes:

  1. Rebase onto main (f4e3b3a) and use #114's helpers.
    • In RevokeSessions.tsx, write the revoke button as {...pendingProps(state === "submitting", revoke)} and drop the hand-written aria-disabled and the if (state === "submitting") return guard. Keep #114's rootRef / useFocusRescue and put focusFallback on the alert LiveRegion. Call focus.start() after the dialog resolves true, next to setState("submitting"), so it records the button that focus came back to. Call focus.settle() in the catch.
    • In SecretsManager.tsx, keep aria-label={Delete ${secret.name}} and use #114's {...pendingProps(deleting === secret.name, () => handleDelete(secret.name))}. Remove the if (deleting) return guard and the [deleting, secrets] deps. Again, call focus.start() only after the dialog resolves true.
  2. Use pendingText for the pending style. In RevokeSessions.css.ts and SecretsManager.css.ts, set "&[aria-disabled='true']": pendingText (from app/styles/utilities.css.ts) in place of opacity: 0.6. #114 removed that opacity on purpose because it fades the focus ring of a control that keeps focus.
  3. Drop the neighbour-Delete focus code in SecretsManager.handleDelete. That is the names/neighbour lookup, the requestAnimationFrame, and data-delete-secret. #114's useFocusRescue already keeps focus off <body> after a delete: it moves focus to the "Secret ... deleted" status message, and #114's test asserts that. Two mechanisms would fight over focus, and the issue doesn't ask for a change here.
    • Remove the branch's test "moves focus to the Delete in the removed row's place" and the Name-field expectation in "says a deleted secret in the status region".
    • Port #114's "keeps Delete focused and aria-disabled while pending, then focuses the message" and "leaves focus on Delete or the error when a delete fails" by adding answerDialog("Delete secret") plus a timer advance after the click.
    • Port #114's RevokeSessions focus test to the dialog flow: click "Revoke all sessions", answer "Revoke and sign out", check aria-disabled="true" and that a second click posts nothing, then check that focus is back on the button after a failure.
  4. Build the dialog's surface from cardSurface. Card/styles.css.ts exports it so that bespoke surfaces don't re-declare background, border, radius and padding, and docs/design.md forbids an island style that re-creates a component. In confirm-dialog.css.ts, spread ...cardSurface in place of padding, border, borderRadius and backgroundColor, and override only borderColor: vars.color.border. The preview looks unchanged.

Follow-up (removeBranches drops focus to <body>): file. The claim holds. removeBranches in AutomationForm.tsx never calls focusAfterRender, and the button it was called from unmounts. That happens on main too: with empty branches no dialog opens and focus drops straight away. Focus after a removal is outside this issue.

loop:verdict run=review-20261114-183739-115 sha=65994ac5f1c9337cf998e162661f3186fe03e508 verdict=changes-requested

Fix round 1: the review asked for changes. `loop:fix run=contribute-20261115-000035-115 round=1 issue=115`
fix(confirm): confirm destructive actions in a dialog with Cancel focused, and confirm secret deletion - **Rebase onto `main` and use #114's helpers**: merged `origin/main` rather than rebasing, because this loop never rewrites a branch's pushed commits. The result is the same. - In `RevokeSessions`, the button uses `pendingProps(state === "submitting", revoke)`, and the hand-written `aria-disabled` and the guard are gone. `rootRef`/`useFocusRescue` stay. The alert `LiveRegion` has `focusFallback`. `focus.start()` runs after the dialog resolves true, and `focus.settle()` runs in the catch. - In `SecretsManager`, the button keeps `aria-label="Delete <name>"` and uses #114's `pendingProps`. The `if (deleting) return` guard and the `[deleting, secrets]` deps are gone, and `focus.start()` runs only after the dialog resolves true. - **`pendingText`**: the revoke and secret Delete buttons use `"&[aria-disabled='true']": pendingText` in place of `opacity: 0.6`. - **Neighbour-Delete focus code**: removed (`names`/`neighbour`, the `requestAnimationFrame`, `data-delete-secret`). After a delete, #114's rescue moves focus to the "Secret ... deleted" message. The neighbour test and the Name-field expectation are removed. #114's two secret focus tests and its revoke focus test now answer the dialog. The revoke test checks `aria-disabled="true"`, that a second click posts nothing, and that focus is on the button after a failure. - **`cardSurface`**: `confirm-dialog.css.ts` spreads `...cardSurface` and overrides only `borderColor: vars.color.border`. I re-shot `pnpm preview:ui confirm-dialog` in both themes and it looks unchanged. #114's `pending-controls` `secret-deleting` shot shows the dimmed "Deleting..." text with the full focus ring. - `pnpm run check` passes. `pnpm run test` passes: 201 files, 2874 tests. - Owner decision dropped: focus no longer moves to the next row's Delete after a secret is deleted. It goes to the status message, as on `main`. **Follow-up**: the same as the last push's. Review: [https://tangled…
**Changes requested, for two stale references only.** All four changes from the last review are done. `pnpm run check` passes and `pnpm run test` passes (201 files, 2874 tests). The dialog works in real Chromium. What remains: the branch removed RevokeSessions' inline confirm panel, and one doc and one code comment still describe it. Since the last review (on `65994ac`): 1. **Rebase on `main` and use #114's helpers: fixed.** `main` is merged in. RevokeSessions and SecretsManager use `pendingProps`. `focus.start()` runs only after the dialog resolves true, and `focus.settle()` runs on failure. The `role="alert"` region (`focusFallback`) is in the page from the first render. 2. **`pendingText`: fixed.** Both pending styles use it, and the hover is turned off while pending. 3. **Neighbour-Delete focus code: removed.** #114's focus test and the rescue to the "Secret ... deleted" message are back, ported to answer the dialog. 4. **`cardSurface`: fixed.** Only `borderColor` and the shadow are overridden. Nothing from round 1 broke: no `confirm(` is left in `app/` or `lib/`, all seven AutomationForm calls and the toolbar's use `confirmDialog`, and the acceptance criteria still hold against the code. How I checked: - **Real Chromium.** I ran `pnpm preview:ui confirm-dialog --serve` and imported the real `confirmDialog`, `SecretsManager` and `RevokeSessions` client-side through its Vite server (hono/jsx/dom, fetch stubbed). - Cancel has focus on open. Enter and Esc resolve false. Tab then Enter resolves true. Focus goes back to the opener each time, and the dialog leaves the DOM. - Secrets: Cancel posts nothing and returns focus to "Delete alpha". Confirming keeps focus on the button with `aria-disabled="true"`, and a second Enter while it runs opens no dialog. Success moves focus to the status message. A failure leaves focus on Delete. - Revoke: Esc posts nothing. Confirming leaves focus on "Revoking..." with `aria-disabled="true"`. A failure puts focus back on "Revoke all sessions" and the alert reads the error…
Fix round 2: the review asked for changes. `loop:fix run=contribute-20261115-001635-115 round=2 issue=115`
fix(confirm): confirm destructive actions in a dialog with Cancel focused, and confirm secret deletion Both stale references to the removed inline confirm panel are fixed: 1. `docs/solutions/security-issues/oauth-grant-revocation-error-contract.md` line 121 now says a failed revoke "drives the user to an error message under the Revoke all sessions button, announced by its alert region". It no longer says the user goes back to the confirm panel. 2. The focus-rescue comment in `app/islands/RevokeSessions.tsx` now reads: "If the failure's re-render takes focus off the Revoke all sessions button (where the dialog hands focus back), it goes back to it, or else to the error." Only these two changed: a doc line and a comment. No code changed. `pnpm run check` passes, and so does `pnpm run test` (2874 tests). **Follow-up**: the same as the last push's. Review: [https://tangled.org/exosphere.site/airglow/compare/main...loop/115](https://tangled.org/exosphere.site/airglow/compare/main...loop/115) `loop:pushed run=contribute-20261115-001635-115 sha=9e446c807f78bad63b96079749e664a364c4a7ed round=2`
**Merge.** This round fixes both stale references from the last review, and the fix touches nothing else. `pnpm run check` passes, and `pnpm run test` passes all 2874 tests in 201 files. The acceptance criteria still hold against the code. The dialog's behaviour was checked in real Chromium last round, and the code has not changed since. Since the last review (on `4daf46f`), only a doc and a comment changed, according to `git diff 4daf46f..9e446c8`: 1. **`docs/solutions/security-issues/oauth-grant-revocation-error-contract.md`: fixed.** A failed revoke now "drives the user to an error message under the Revoke all sessions button, announced by its alert region". That matches the code: `setError(...)` and `setState("error")` set the message, and the `role="alert"` region announces it. 2. **`app/islands/RevokeSessions.tsx` comment: fixed.** It now names the Revoke all sessions button, which is where the dialog hands focus back. Searching `app/`, `lib/` and `docs/` finds no "confirm panel", "confirm button" or `confirm(` left. The checks from earlier rounds still hold, so I did not run them again: - `confirmDialog` is built on `<dialog>`, `showModal()` and `method="dialog"`, with Cancel `autofocus` and the result read from `returnValue`. - All eight call sites use it. - Deleting a secret asks first and names the secret. - RevokeSessions uses #114's helpers. - The preview shows the same screens in both themes. Follow-up (`removeBranches` drops focus to `<body>`): **file**, as the last two reviews decided. `removeBranches` in `AutomationForm.tsx` still never moves focus, and the button that was pressed unmounts. Focus after a removal is outside this issue. `loop:verdict run=review-20261115-002554-115 sha=9e446c807f78bad63b96079749e664a364c4a7ed verdict=merge followup=1`
Merged onto `main` as 6b04f989cb26fe708b4499be1cc6474d1e87ace3. `loop:merged sha=6b04f989cb26fe708b4499be1cc6474d1e87ace3 head=9e446c807f78bad63b96079749e664a364c4a7ed`
Filed the follow-up as [#136](https://tangled.org/exosphere.site/airglow/issues/136), a new issue, not marked ready, from branch `loop/115` (6b04f989cb26): fix(automation-form): keep focus in the form after removing a condition's branches `loop:filed issue=136`
Sign up or Sign in to add to the discussion.