Repository navigation
feat(agent): add a dry-run tool to purge orphaned chat transcripts - #191
Merged
Merged
Conversation
Before #187, deleting a conversation removed its agent_chats row and left the transcript in its Durable Object. `pnpm purge:orphan-chats` finds those and, with --apply, wipes them. Objects are never addressed by raw id from the Worker: a cold start through idFromString has no ctx.id.name, so the Agents SDK throws, and later calls by name land on the same broken instance. The script reads unclaimed objects through Cloudflare's query API, and wipes go by name through destroy(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Before #187, deleting a conversation removed its
agent_chatsrow and left the transcript in its Durable Object. Nothing links to those transcripts, but they still exist, after the UI told people they were gone.What
pnpm purge:orphan-chatsis a dry run by default.--applywipes what it lists. A person runs it; nothing runs automatically.POST /v1/admin/agent-chats/unclaimedworks out which ids no row accounts for. It hashes names from rows and opens no object.POST /v1/admin/agent-chats/purgewipes by name through the existingdestroy()path. It refuses if a row exists or the name doesn't hash to the given id, and logs the actor and outcome for each chat.Empty, recently active (default 24h) and unidentifiable chats are reported and left alone. Output has ids and dates, never transcript text.
Both routes are platform-admin only, and keys need a new
admin:agent-chatsscope, so a docs reindex key can't delete chats.Why not wipe by raw id
Tested in workerd with the object evicted first: a cold start through
idFromString()has noctx.id.name, so the Agents SDK throws on every call, including custom methods. A later call by name then lands on that same nameless instance and throws too. Done to a live chat, that would break it until eviction. A warm object hides this.Testing
Not tested
failed, nothing is lost, and a re-run after the objects go idle should work.Before running with
--applyChats from before the 2026-11-05 D1 move also have no row, so they show as orphans even though nobody deleted them. Check the dates in the dry run.
🤖 Generated with Claude Code