This is a general question for which I am sure there are solutions already – asking here to avoind reinventing the wheel
I use n8n to modify bookmarks in Karakeep (a bookmark and notes manager): a creation of modification of a bookmark/note fires a webhook to n8n which is used to trigger a flow (retrieve the bookmark contents, analyze it and modify the bookmark on Karakeep with a new title, tags, …).
Since the workflow modifies a bookmark/note, the webhook on Karakeep is started again and the whole thing goes into a loop.
My example is with Karakeep but I believe the general problem is common. What are the typical solutions for this?
I considered using one of the metadata of the bookmark (e.g. `author`) to mark the fact that the bookmark was already processed by n8n. This however breaks if I edit manually the bookmark again (and do not change the author). I am still looking for more an more convoluted ways to use such a flag but first I want to kame sure that I am not missing solething obvious – THE solution everybody uses
Don’t flag the record itself, compare before you write. Before the update node, check whether the new title and tags differ from what Karakeep already has, and skip the write if they don’t. Then the second webhook fires, finds nothing to change and ends the loop. A manual edit still goes through, since there the content really changed. Not sure what Karakeep sends in the payload, so there may be an easier check there.
This is a good idea, thank you. I am using an LLM to create the new title, tags etc. so the content is not deterministic and will change between two runs.
You’re right to flag that — compare-before-write breaks once an LLM is in the middle, because the new title/tags will drift a little on every run even when nothing really changed.
The pattern that works here is to dedupe on the input, not the output:
Right after the webhook, hash the source content before the LLM ever sees it — the bookmark’s URL plus its original title/content, and the last-modified time if Karakeep sends one in the payload.
Store that hash keyed by bookmark ID — n8n’s static data is enough for a single workflow, or a small table if you want it visible — and compare the incoming hash with the last one you processed.
If the hash matches, stop the workflow right there. Only if it changed do you call the LLM, write the result back, and update the stored hash.
That breaks the loop: your own write fires the webhook again, but the source hash is unchanged, so the second run exits before the LLM runs. A manual edit still works, because editing the bookmark changes the source hash, so the next run processes it again.
A plain flag on the record (like setting author) can’t do that on its own, because it can’t tell your edit apart from a manual one — the stored hash is what gives the flag its memory. And if Karakeep’s webhook payload happens to include an event ID or something that distinguishes an API update from a UI edit, that can be a useful extra check, but I wouldn’t rely on it alone.
One catch with hashing: only hash the fields your own write never touches. Title and tags would change the hash right after the workflow updates them, so the loop just moves. Note body and URL are safe. If the webhook only sends the bookmark ID, fetch it first and hash what comes back
Then compare the input, not the output. I’d hash just the bookmark content you send to the LLM (leave title and tags out) and store it per bookmark id in a Data Table. If the hash matches when the webhook fires, stop before the LLM node. Your own write changes title and tags, so it won’t change the hash, as long as the content field isn’t touched.
Adding to the hashing idea above, with what Karakeep actually sends (I checked its code):
The webhook body is only jobId, bookmarkId, userId (the bookmark’s owner, not the editor), url, type and operation (source). So it can’t tell your edit from a manual one, and you have to GET the bookmark first, as elmirbesirovic said.
PATCH /bookmarks/{id} sends an “edited” webhook on every call, even if nothing changed (source). Adding tags only sends one when a tag is really added or removed (source).
Don’t put modifiedAt in the hash. Your own writes change it.
Leave Karakeep’s own AI tags (attachedBy = ai) out too. Karakeep can add them later without an “edited” webhook.
After the GET, $json is the bookmark, so read the event type with {{ $('Webhook').item.json.body.operation }}.
On the Karakeep webhook, tick only created, crawled and edited (source). A new link sends both created (before the page is fetched) and crawled.
One trade-off with hashing only the content: a manual edit of the title or tags won’t run the flow again. If you want those edits to count, keep the title and the human tags in, but save the hash after your workflow writes, from a fresh GET. Karakeep cleans tag names (trims spaces and removes a leading #, source), so a hash of what you sent may not match. Then put a 5-second Wait right after the Webhook node, so both of your writes are done before the check runs.
Hi @Priyanshu_Kumar, ok the fresh GET after the writes is better than what i suggested, i didn’t know Karakeep cleans tag names. Content-only still does the job if manual title edits don’t need to rerun the flow