Skip to content

Browse and restore Trash in the TUI - #672

Open
WhiskeyTuesday wants to merge 3 commits into
basecamp:mainfrom
WhiskeyTuesday:tui-trash
Open

WhiskeyTuesday wants to merge 3 commits into
basecamp:mainfrom
WhiskeyTuesday:tui-trash

Conversation

@WhiskeyTuesday

@WhiskeyTuesday WhiskeyTuesday commented Nov 21, 2026 •

Copy link
Copy Markdown

The TUI can send mail to Trash but cannot browse it or restore a thread. Add a 0 Trash tab, with paginated browsing, thread reading, and i to restore through HEY's normal topic restore operation.

Trash returns topics rather than posting IDs. The adapter preserves that distinction, blocks posting mutations in Trash, and avoids marking a trashed topic as a seen posting. A restored row leaves the list only after success; earlier page reads cannot bring it back, and late responses cannot remove an unrelated row after switching sources.

Depends on basecamp/hey-sdk#314 or an equivalent SDK change that preserves Trash’s pagination cursor. This PR temporarily pins the exact helper commit in my public fork so it can be built and reviewed now. Before merging, that replacement needs to be removed and a published SDK release pinned. Feedback on the Trash UI and restore behavior is welcome while the SDK dependency is reviewed.

Tests cover navigation, opaque pagination, opening without a posting observation, restore success and failure, blocked mutations, stale reads, and topic/posting ID collisions.

Validation after rebasing onto f6244d7: TUI tests, make lint, and make build passed. make test failed only TestFindBareLinksPastRejectedPrefixesIsLinear; the same five-second assertion fails on unchanged upstream on this machine. Focused live checks on combined build 9da3f57 passed in a real HEY account: trashing, browsing, reading, refusal of Move while trashed, and restoring the owned fixture with independent server readback.


Summary by cubic

Adds a Trash tab (shortcut 0) to the TUI so trashed threads can be browsed, read, and restored with i. Previously Trash was write-only: mail could be sent there, but there was no way to browse or restore it.

Trash serves topics rather than posting IDs. The adapter keeps that distinction — posting mutations are blocked in Trash, and a trashed topic is never observed as a seen posting. A successful restore removes the row and closes any open reader; a failed restore leaves the thread in place to retry. A restore also invalidates any read begun earlier, so a stale page or live response cannot resurrect the restored row even after the reader switches sources and back. Trash is excluded as a move destination. Tests cover navigation, opaque pagination, restore success and failure, blocked mutations, stale reads, and topic/posting ID collisions.

Dependencies

  • Depends on a published HEY SDK release containing Topics.GetTrashPage; until it lands, go.mod carries a temporary replace to a fork commit that must be removed before merging.

Written for commit 8466640. Summary will update on new commits.

View guided diff

Copilot AI 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.

🟡 Changes recommended

A pending Trash refresh can reinsert a restored topic after navigation because an early return skips request invalidation; the ordering needs a fix and regression test.

1 open issue
What changed in this PR

Adds Trash browsing and restoration to the TUI’s existing mail navigation, while keeping Trash topic IDs separate from posting IDs.

Changes:

  • Adds a 0 Trash tab with pagination, thread reading, and i to restore.
  • Blocks posting mutations in Trash and adds tests for restore outcomes, stale responses, and ID collisions.
  • Documents the behavior and temporarily pins an SDK fork for pagination support; a published SDK release is required before merging.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
internal/​tui/​tui_test.go Updates source-count expectations for Trash.
internal/​tui/​trash.go Implements restoration, mutation restrictions, and contextual help.
internal/​tui/​trash_test.go Tests navigation, pagination, restoration, and identity safeguards.
internal/​tui/​move.go Excludes Trash from move destinations.
internal/​tui/​mail.go Integrates Trash navigation, reading, and action guards.
internal/​tui/​mail_test.go Adjusts mail-source expectations for Trash.
internal/​tui/​collections_test.go Accounts for Trash during collection discovery.
internal/​mail/​source.go Adds the Trash source kind.
internal/​mail/​page.go Adapts paginated Trash topics into list rows.
go.sum Records checksums for the temporary SDK fork.
go.mod Pins the SDK fork containing pagination support.
docs/​tui.md Documents Trash controls and restrictions.
docs/​architecture/​mail-sources-and-paging.md Explains Trash identities and restore behavior.

Review effort: Balanced

Comment thread internal/tui/trash.go Outdated
Comment on lines +78 to +84
if v.currentSourceKind() != mail.KindTrash {
return notify("Thread restored")
}
// A page or live head read begun before the restore may still contain this
// topic. Ignore those answers so they cannot resurrect the restored row.
v.moreRequestID++
v.liveRequestID++

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 8466640. Confirmed the reported ordering: A pre-restore Trash live refresh could still pass the request/source checks after a round trip through the Imbox: navigation invalidates paginated reads but does not change the live refresh generation.

The fix moves live-refresh invalidation ahead of the non-Trash early return, still after the restore error check. Paging invalidation remains scoped to Trash so a late restore does not interfere with the other source's page read.

The new regression holds an actual SDK refresh response from an offline test server, starts a restore with i, navigates to the Imbox, completes the successful restore, returns to a freshly read Trash list, and then delivers the old response. It reproduced the restored topic reappearing before the fix and now rejects that response. A separate test checks that a failed restore still allows an otherwise valid refresh.

TUI/mail tests, the targeted race check, and lint pass. The full test suite still hits the previously observed TestFindBareLinksPastRejectedPrefixesIsLinear timing failure; the new regressions pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants