Skip to content

fix(chat): write each Action Center event once when an approval or a click repeats - #1935

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/chat-ac-writes-once
Nov 1, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/chat-ac-writes-once

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat's writes to Action Center could repeat when an approval or a click repeated. Follow-ups from the #1897, #1902 and #1898 reviews. No migration.

  1. Add to AC-{n}, attachToAction (feat(chat): let Chat send findings to Action Center, attach files to tasks and set Ready for review, with Undo (W2-10) #1897).
    • Problem: a retried approval could attach the finding twice.
    • Fix: the event carries idempotencyKey: chat:{step}, the form Send to Action Center uses. Before attaching, an event with the same key is looked up. If there is one, it comes back and nothing is added, even if the action has closed in between.
  2. Card clicks (feat(chat): let the person attach Chat's file to its task and mark it done, with Undo (W2-12) #1902).
    • writeTaskStatus gains onlyIfChanged, a conditional update (.neq('status', …)). The event and the Updated stamp are written only when the row really changed.
    • Mark done uses it, and so does Undo: two Undos at once write one event. The drawer's own write is unchanged.
    • Attach only now writes the card's conversationId and runId into its event, checked on the server: the conversation must be the person's, and the run that conversation's. execution is null, since it's the person's own click.
  3. Daily suggestions (feat(chat): open a daily suggestion on its own page, with Content Editor, Do it with Chat, Not now and Remove (W2-26) #1898).
    • recordUse reads with .is('removed_at', null), so a removed suggestion writes neither suggestion nor feed stamp.
    • Site Audit matching uses the codebase's pageKey, so http or https, www and a trailing slash don't matter. It looks at the audit's url and final_url, within the brand's last 500 audits, the limit the server's audit-recheck uses too.

Test helper: the fake Supabase client used in tests reads JSON filters such as data->>key as PostgREST does.

Questions for review:

  • A strict one-event guarantee for fix(tracking): keep job active until webhook results drain #1 would need a unique partial index on action_events (action_id, (data->>'idempotencyKey')) where event = 'evidence_attached'. That's a migration, so it isn't here. Today the engine's own idempotency record separates concurrent calls, and the look-up covers repeats.
  • In a true race of two Mark done clicks, the event's linked can belong to the click that didn't link. Undo then leaves the link. This is a small edge case and was left as is.

Related issue

None. Follow-ups to the #1897, #1902 and #1898 reviews.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Unit tests: 9 tests break when the fixes are reverted, at least one per item. The 40 related test files pass (1,107 tests).
  2. On a daily suggestion's page (/dashboard/chat/inbox/{id}), the last audit date now shows when the audited address differs in www, http or a trailing slash.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes (0 errors; 7 old warnings in files this PR doesn't touch)
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

Full checks on this branch (cb68716): web 803 files / 8384 tests pass, and yarn build passes. Server format:check and lint are clean, and 352 files / 4994 tests pass (3 skipped).

🤖 Generated with Claude Code

…click repeats

Follow-ups from the approval notes on ansvisor#1897, ansvisor#1902 and ansvisor#1898.

- Add to AC-{n} (attachToAction, W2-10): the evidence_attached event
  carries its approval's key (`chat:{step}`, as Send to Action Center's
  payload does), and a retried approval finds that event and returns it
  instead of adding the finding again. Two calls at the very same moment
  are already kept apart by the engine's idempotency claim; a database-level
  guarantee would need a unique index (a migration), not added here.
- Card clicks (W2-12): Attach to task & mark done and its Undo write the
  task's status only when it really changes (`.neq('status', …)` through
  writeTaskStatus's new onlyIfChanged), so two clicks at once leave one
  History event. The drawer's own writes are unchanged.
- Attach only from a card now records the card's chat and run on its
  file_attached event, as a mark done's event does. attachFileToTask takes
  the card's place and reads it on the server (the person's own chat and a
  run of it) before recording it; no execution mode, as it is the
  person's own click.
- Daily suggestions (W2-26): recordUse skips a removed suggestion (no use,
  no feed stamp), and the page's last Site Audit matches the action's pages
  by pageKey (no scheme, www or trailing slash), by the audit's url or
  final_url, among the brand's latest 500 audits (as the server's recheck
  reads them).
- The test fake reads JSON-path filters (`data->>key`) as PostgREST does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gkhngyk
gkhngyk merged commit c2edb66 into ansvisor:main Nov 1, 2026
6 checks passed
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.

2 participants