--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 7ED086DE0243\r
+ for <notmuch@notmuchmail.org>; Sat, 2 Apr 2016 09:19:24 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.02\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.02 tagged_above=-999 required=5 tests=[AWL=-0.009,\r
+ SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 4cu-_GAnWwKx for <notmuch@notmuchmail.org>;\r
+ Sat, 2 Apr 2016 09:19:16 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 61F246DE02C2\r
+ for <notmuch@notmuchmail.org>; Sat, 2 Apr 2016 09:19:16 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1amOH5-0004fC-A4; Sat, 02 Apr 2016 12:19:47 -0400\r
+Received: (nullmailer pid 13159 invoked by uid 1000);\r
+ Sat, 02 Apr 2016 16:19:11 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: Daniel Kahn Gillmor <dkg@fifthhorseman.net>,\r
+ Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH 1/2] test thread breakage when messages are removed and\r
+ re-added\r
+Date: Sat, 2 Apr 2016 13:19:01 -0300\r
+Message-Id: <1459613942-13098-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.8.0.rc3\r
+In-Reply-To: <1459606541-23889-1-git-send-email-dkg@fifthhorseman.net>\r
+References: <1459606541-23889-1-git-send-email-dkg@fifthhorseman.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 02 Apr 2016 16:19:24 -0000\r
+\r
+From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+\r
+This test (T590-thread-breakage.sh) currently fails!\r
+\r
+If you have a two-message thread where message "B" is in-reply-to "A",\r
+notmuch rightly sees this as a single thread.\r
+\r
+But if you:\r
+\r
+ * remove "A" from the message store\r
+ * run "notmuch new"\r
+ * add "A" back into the message store\r
+ * re-run "notmuch new"\r
+\r
+Then notmuch sees the messages as distinct threads.\r
+\r
+I think this happens because if you insert "B" initially (before\r
+anything is known about "A"), then a "ghost message" gets added to the\r
+database in reference to "A" that is in the same thread, which "A"\r
+takes over when it appears.\r
+\r
+But if "A" is subsequently removed, no ghost message is retained, so\r
+when "A" appears, it is treated as a new thread.\r
+\r
+I don't know how to easily fix this, but i see a few options:\r
+\r
+ghost-on-removal\r
+----------------\r
+\r
+We could unilaterally add a ghost upon message removal. This has a\r
+few disadvantages: the message index would leak information about what\r
+messages the user has ever been exposed to, and we also create a\r
+perpetually-growing dataset -- the ghosts can never be removed.\r
+\r
+ghost-on-removal-when-shared-thread-exists\r
+------------------------------------------\r
+\r
+We could add a ghost upon message removal iff there are other\r
+non-ghost messages with the same thread ID.\r
+\r
+We'd also need to remove all ghost messages that share a thread when\r
+the last non-ghost message in that thread is removed.\r
+\r
+This still has a bit of information leakage, though: the message index\r
+would reveal that i've seen a newer message in a thread, even if i had\r
+deleted it from my message store\r
+\r
+track-dependencies\r
+------------------\r
+\r
+rather than a simple "ghost-message" we could store all the (A,B)\r
+message-reference pairs internally, showing which messages A reference\r
+which other messages B.\r
+\r
+Then removal of message X would require deleting all message-reference\r
+pairs (X,B), and only deleting a ghost message if no (A,X) reference\r
+pair exists.\r
+\r
+This requires modifying the database by adding a new and fairly weird\r
+table that would need to be indexed by both columns. I don't know\r
+whether xapian has nice ways to do that.\r
+\r
+scan-dependencies\r
+-----------------\r
+\r
+Without modifying the database, we could do something less efficient.\r
+\r
+Upon removal of message X, we could scan the headers of all non-ghost\r
+messages that share a thread with X. If any of those messages refers\r
+to X, we would add a ghost message. If none of them do, then we would\r
+just drop X entirely from the table.\r
+---\r
+\r
+Here I just changed the FAILing test to BROKEN. This reflects our\r
+usual distinction between known bug and regression.\r
+\r
+ test/T590-thread-breakage.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 67 insertions(+)\r
+ create mode 100755 test/T590-thread-breakage.sh\r
+\r
+diff --git a/test/T590-thread-breakage.sh b/test/T590-thread-breakage.sh\r
+new file mode 100755\r
+index 0000000..8c8e63b\r
+--- /dev/null\r
++++ b/test/T590-thread-breakage.sh\r
+@@ -0,0 +1,67 @@\r
++#!/usr/bin/env bash\r
++#\r
++# Copyright (c) 2016 Daniel Kahn Gillmor\r
++#\r
++\r
++test_description='thread breakage by reindexing (currently broken)'\r
++\r
++. ./test-lib.sh || exit 1\r
++\r
++message_a() {\r
++ mkdir -p ${MAIL_DIR}/cur\r
++ cat > ${MAIL_DIR}/cur/a <<EOF\r
++Subject: First message\r
++Message-ID: <a@example.net>\r
++From: Alice <alice@example.net>\r
++To: Bob <bob@example.net>\r
++Date: Thu, 31 Mar 2016 20:10:00 -0400\r
++\r
++This is the first message in the thread.\r
++EOF\r
++}\r
++\r
++message_b() {\r
++ mkdir -p ${MAIL_DIR}/cur\r
++ cat > ${MAIL_DIR}/cur/b <<EOF\r
++Subject: Second message\r
++Message-ID: <b@example.net>\r
++In-Reply-To: <a@example.net>\r
++References: <a@example.net>\r
++From: Bob <bob@example.net>\r
++To: Alice <alice@example.net>\r
++Date: Thu, 31 Mar 2016 20:15:00 -0400\r
++\r
++This is the second message in the thread.\r
++EOF\r
++}\r
++\r
++\r
++test_thread_count() {\r
++ notmuch new >/dev/null\r
++ test_begin_subtest "${2:-Expecting $1 thread(s)}"\r
++ count=$(notmuch count --output=threads)\r
++ test_expect_equal "$count" "$1"\r
++}\r
++\r
++test_thread_count 0 'There should be no threads initially'\r
++\r
++message_a\r
++test_thread_count 1 'One message in: one thread'\r
++\r
++message_b\r
++test_thread_count 1 'Second message in the same thread: one thread'\r
++\r
++rm -f ${MAIL_DIR}/cur/a\r
++test_thread_count 1 'First message removed: still only one thread'\r
++\r
++message_a\r
++# this is known to fail (it shows 2 threads) because no "ghost\r
++# message" was created for message A when it was removed from the\r
++# index, despite message B still pointing to it.\r
++test_begin_subtest 'First message reappears: should return to the same thread'\r
++test_subtest_known_broken\r
++notmuch new >/dev/null\r
++count=$(notmuch count --output=threads)\r
++test_expect_equal "$count" "1"\r
++\r
++test_done\r
+-- \r
+2.8.0.rc3\r
+\r