Retire removed accounts instead of deleting them

Removing an account had no path at all, so a dead session could only be
left running or hand-edited out of the database. The first cut deleted the
account and everything it owned, which threw away conversations and media
that are worth keeping.

Retire instead: keep the row and every row it produced, destroy the stored
cookies and Matrix token. Wiping the credentials is what makes sending and
syncing impossible rather than merely disabled — isEnabledAccount requires
a verified status, so no runtime ever starts, and no session survives for
anything to use. setActive, markLoginRequired and the background credential
refresh now skip retired accounts so none of them quietly revives one;
re-importing a session deliberately does.

Keeping the content visible needed more than keeping the rows. Conversations
and media are only served from running runtimes, so a retired account's
history would have disappeared from the dashboard regardless. Media already
reads the account content table for every listed account. Conversations now
have an archive path that reads the stored ActiveChat payloads directly.

Every write path refuses a retired conversation with a 409: send-reply,
both suggest endpoints, share-media, shareable-media and all read-state
writes. Lazy-loading detail is skipped too — the fallback chat service
belongs to a different account, so it would sync the wrong session and
write the wrong cache. Archived detail derives conversation state from the
transcript alone for the same reason.

Migration 32 rebuilds reddit_accounts to admit the new status, with foreign
keys off and a foreign_key_check before they are restored, as migration 11
does. Two migration tests rewound user_version by counting back from the
head, which silently breaks whenever a migration is appended; they now
target absolute versions.

Conversations never opened before removal keep only their summary. Message
history is lazy-loaded on first open and there is no session left to fetch
the rest with.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Jamie BruntonandClaude Opus 5 committed 2026-08-12 08:58:22 +01:00
1 parent 3f60f7f665
commit a9cea7ed18
16 files changed
+433 -97

No files matched your search

@@ -98,6 +98,7 @@ function establishmentPill(establishment: AccountEstablishmentSummary | null | u
function AccountRow({ account }: { account: RedditAccountSummary }) {
const removeMutation = useRemoveRedditAccountMutation();
const [confirmRemove, setConfirmRemove] = useState(false);
const isRemoved = account.status === 'removed';
useEffect(() => {
if (!confirmRemove) return;
@@ -105,24 +106,31 @@ function AccountRow({ account }: { account: RedditAccountSummary }) {
return () => globalThis.clearTimeout(timer);
}, [confirmRemove]);
const rowClass = isRemoved ? 'account-row is-removed' : account.isRunning ? 'account-row is-active' : 'account-row';
return (
<div className={account.isRunning ? 'account-row is-active' : 'account-row'}>
<div className={rowClass}>
<div>
<strong><RedditUsernameLink username={account.redditUsername} /></strong>
<span>{account.isRunning ? 'Running independently' : 'Waiting for a refreshed session'}</span>
<span>
{isRemoved
? 'Removed — its conversations and media are kept, read-only'
: account.isRunning ? 'Running independently' : 'Waiting for a refreshed session'}
</span>
</div>
<div className="account-row-pills">
{establishmentPill(account.establishment)}
<span className={account.isRunning ? 'pill success' : 'pill warning'}>
{account.isRunning ? 'Running' : 'Paused'}
{isRemoved ? null : establishmentPill(account.establishment)}
<span className={isRemoved ? 'pill neutral' : account.isRunning ? 'pill success' : 'pill warning'}>
{isRemoved ? 'Removed' : account.isRunning ? 'Running' : 'Paused'}
</span>
</div>
<div className="account-row-actions">
{confirmRemove ? (
{isRemoved ? (
<span className="field-hint">Import a session for this account to bring it back.</span>
) : confirmRemove ? (
<>
<span className="account-remove-warning">
Removes u/{account.redditUsername}, its stored session and all of its messages,
conversations and activity. This cannot be undone.
Stops u/{account.redditUsername} and deletes its stored session. Conversations,
messages and media it collected are kept, but become read-only.
</span>
<button className="button secondary" onClick={() => setConfirmRemove(false)} type="button">
Cancel
@@ -151,7 +159,7 @@ function AccountRow({ account }: { account: RedditAccountSummary }) {
{removeMutation.isError ? (
<strong className="save-error" role="alert">{errorMessage(removeMutation.error)}</strong>
) : null}
{account.establishment && account.establishment.state !== 'unknown' ? (
{!isRemoved && account.establishment && account.establishment.state !== 'unknown' ? (
<EstablishmentDetail establishment={account.establishment} />
) : null}
</div>
@@ -203,8 +211,10 @@ export function AccountsPage() {
? session.username ?? null
: null;
const accounts = accountsQuery.data ?? [];
const pausedCount = accounts.filter((account) => !account.isRunning).length;
const heldAccounts = accounts.filter((account) => account.establishment?.sendingHeld);
// Removed accounts are not paused work — nothing about them needs attention.
const liveAccounts = accounts.filter((account) => account.status !== 'removed');
const pausedCount = liveAccounts.filter((account) => !account.isRunning).length;
const heldAccounts = liveAccounts.filter((account) => account.establishment?.sendingHeld);
return (
<div className="page accounts-page">
@@ -5,6 +5,7 @@
.account-list { display: grid; gap: .6rem; }
.account-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; padding: .85rem; background: var(--surface-raised); border: 1px solid var(--border); border-radius: .75rem; }
.account-row.is-active { border-color: var(--accent); }
.account-row.is-removed { opacity: .72; }
.account-row > div { display: grid; gap: .2rem; min-width: 0; }
.account-row span { color: var(--muted); font-size: .82rem; }
.account-row .pill { font-size: .7rem; }
@@ -536,7 +536,8 @@ function useAutoMarkRead(conversationId: string, conversation: ConversationDetai
const mutate = markRead.mutate;
useEffect(() => {
if (!conversation || newestTimestamp <= lastReadMessageTs) return;
if (!conversation || conversation.readOnly) return;
if (newestTimestamp <= lastReadMessageTs) return;
const key = `${conversationId}:${newestTimestamp}`;
if (markedRef.current === key) return;
const timer = window.setTimeout(() => {
@@ -585,11 +586,13 @@ export function ConversationDetail({ conversationId, onClose }: ConversationDeta
</span>
</div>
<div className="conversation-detail-controls">
<ConversationTriageActions
conversation={conversation}
conversationId={conversationId}
onResolved={onClose}
/>
{conversation.readOnly ? null : (
<ConversationTriageActions
conversation={conversation}
conversationId={conversationId}
onResolved={onClose}
/>
)}
<button aria-label="Close conversation" onClick={onClose} type="button">Close</button>
</div>
</header>
@@ -617,7 +620,19 @@ export function ConversationDetail({ conversationId, onClose }: ConversationDeta
</div>
) : null}
<MessageHistory conversation={conversation} now={now} />
<ConversationComposer conversation={conversation} conversationId={conversationId} />
{conversation.readOnly ? (
<section aria-labelledby="read-only-heading" className="conversation-read-only" role="status">
<h3 id="read-only-heading">Read-only</h3>
<p>
{conversation.owner?.redditUsername
? `u/${conversation.owner.redditUsername} was removed from the app.`
: 'The account that owned this conversation was removed from the app.'}
{' '}Its history is kept here, but nothing can be sent or synced from it.
</p>
</section>
) : (
<ConversationComposer conversation={conversation} conversationId={conversationId} />
)}
</article>
);
}
@@ -127,6 +127,7 @@ function ConversationRow({
if (isSelected) itemClasses.push('is-selected');
if (unread) itemClasses.push('is-unread');
if (isChecked) itemClasses.push('is-checked');
if (conversation.readOnly) itemClasses.push('is-read-only');
const descriptors = [
redditUsernameLabel(conversation.username),
@@ -134,6 +135,7 @@ function ConversationRow({
relativeTime,
...(conversation.sellerDetected ? ['Seller'] : []),
...(conversation.hasReceivedImages ? ['Image received'] : []),
...(conversation.readOnly ? ['Removed account, read-only'] : []),
];
return (
@@ -179,6 +181,11 @@ function ConversationRow({
</span>
))}
{showOwner ? <AccountOwnerBadge owner={conversation.owner} /> : null}
{conversation.readOnly ? (
<span className="conversation-read-only-marker" title="The account that owned this conversation was removed. History is kept, but nothing can be sent.">
Read-only
</span>
) : null}
{conversation.sellerDetected ? <span className="conversation-seller-marker">Seller</span> : null}
{conversation.hasReceivedImages ? <span className="conversation-image-marker">Image received</span> : null}
<span className="conversation-list-profile"><RedditUsernameLink username={conversation.username} /></span>
@@ -96,6 +96,11 @@
.conversation-shortcut-hint { margin-left: auto; opacity: .8; }
.conversation-image-marker { justify-self: start; padding: .18rem .45rem; color: #d8e8ff !important; background: #18324d; border: 1px solid #315d85; border-radius: 999px; font-size: .68rem !important; font-weight: 750; }
.conversation-seller-marker { display: inline-flex; justify-self: start; padding: .18rem .45rem; margin-right: .35rem; color: #ffd6d0 !important; background: #4b1e1a; border: 1px solid #874139; border-radius: 999px; font-size: .68rem !important; font-weight: 800; }
.conversation-read-only-marker { display: inline-flex; justify-self: start; padding: .18rem .45rem; margin-right: .35rem; color: var(--muted) !important; background: var(--surface-raised); border: 1px solid var(--border); border-radius: 999px; font-size: .68rem !important; font-weight: 800; }
.conversation-list-item.is-read-only .conversation-list-snippet { opacity: .8; }
.conversation-read-only { padding: 1rem; margin: 0 1rem 1rem; color: var(--muted); background: var(--surface-raised); border: 1px dashed var(--border); border-radius: .65rem; }
.conversation-read-only h3 { margin: 0 0 .3rem; color: var(--text); font-size: .9rem; }
.conversation-read-only p { margin: 0; font-size: .82rem; }
.conversation-list-state, .conversation-detail-state { display: grid; place-items: center; align-content: center; gap: .5rem; min-height: 16rem; padding: 1.5rem; color: var(--muted); text-align: center; }
.conversation-list-state strong, .conversation-detail-state strong { color: #e9f1ec; }
/* Column layout: history takes the slack, the composer stays reachable. */