Sort, filter and page mail_search on a UTC key; show UTC dates; give mail_thread a cursor #108

Closed
opened 2026-11-01 20:54:32 +00:00 by svc-agent-writer · 2 comments

This was generated by AI during triage.

Part of #106 (items 2, 6 paging, 10). Decided at triage 2026-11-02: rows show UTC with Z; semantic and hybrid paging are out of scope.

Agent Brief

Category: bug
Summary: Sort, filter and page mail_search on a UTC key; show UTC dates; give mail_thread a cursor

Current behavior:
Sources store the message date as ISO 8601 with the sender's offset. Search order, since and before compare that text with the fallback internaldate, so two messages with offsets +11:00 and +00:00 can sort up to 11 hours out of order, and a bound can include or drop mail by the same amount. Row cells show the first 16 characters of the stored date, which drops the offset. The search cursor is a row offset, so a sync pass between two pages moves rows across the page boundary. mail_thread shows the first limit members and reports thread_size and shown, but has no cursor, so a thread longer than the cap can never be read past it.

Desired behavior:

  • Every date in a search, thread, people, evidence, changes or triage row is UTC with a trailing Z, minute precision as today. mail_read keeps the stored form with its offset.
  • Keyword and filter searches order by a UTC instant, newest first, with the message id as the tiebreak. since and before accept a date (YYYY-MM-DD) or a date-time with an offset, compare as UTC instants, and keep inclusive and exclusive semantics. A plain date means midnight UTC.
  • The UTC key is a stored column or an expression index, never a VIRTUAL generated column: the image ships SQLite 3.40.1, which cannot use an index on a virtual column (#96). Unparseable dates fall back to internaldate, as the #96 copy_key guard does.
  • Keyword and filter modes page by a keyset cursor over the UTC key and the id. A sync pass between pages never repeats or skips a row that existed before the first page. The cursor stays an opaque string; next_cursor=- still means no more. more and total stay in the footer.
  • mail_thread takes a cursor and returns next_cursor with thread_size and shown, paging oldest first.
  • A migration backfills the key for existing rows. Reader mode never writes it.

Key interfaces:

  • SearchParams: since, before and the cursor change meaning; the store's filter builder and search query use the UTC key.
  • mail_search and mail_thread signatures: cursor on mail_thread; parameter descriptions say UTC.
  • The store schema version and migration list.
  • The #96 bench script: run head and base alternating in one container before and after, and record the numbers in the PR.

Acceptance criteria:

  • Two messages dated 2026-01-01T09:00:00+11:00 and 2026-01-01T01:00:00+00:00 sort with the +00:00 one first (newest first), and since=2026-01-01 includes only the +00:00 one (2026-01-01T01:00Z) while since=2025-12-31 includes both.
  • since=2026-01-01T00:00:00+11:00 is the same bound as since=2025-12-31T13:00:00Z.
  • A row for the +11:00 message shows 2025-12-31T22:00Z.
  • Inserting a newer message between page one and page two of a keyword search neither repeats nor skips any row that page one could have shown.
  • A thread of 120 messages is fully readable through two mail_thread calls, and the second footer has next_cursor=-.
  • A row with an unparseable date still sorts by internaldate and is not dropped.
  • An existing store opens, migrates, and searches with no manual step; Store(reader=True) on an unmigrated store raises a clear error rather than writing.
  • The bench shows no regression over 10 percent on keyword search at 210k rows, in the image, head and base alternating in one container.
  • make check passes.

Out of scope:

  • Paging for semantic, hybrid and similar_to modes: they rank a candidate set, and need their own design and issue.
  • Any change to snippet, subject or address cells (#106 item 3 is a separate sub-issue).
  • Changing what mail_read shows.

Filed under: operator word "accept" sha256:c125d0397b60

> *This was generated by AI during triage.* Part of #106 (items 2, 6 paging, 10). Decided at triage 2026-11-02: rows show UTC with Z; semantic and hybrid paging are out of scope. ## Agent Brief **Category:** bug **Summary:** Sort, filter and page mail_search on a UTC key; show UTC dates; give mail_thread a cursor **Current behavior:** Sources store the message date as ISO 8601 with the sender's offset. Search order, `since` and `before` compare that text with the fallback internaldate, so two messages with offsets +11:00 and +00:00 can sort up to 11 hours out of order, and a bound can include or drop mail by the same amount. Row cells show the first 16 characters of the stored date, which drops the offset. The search cursor is a row offset, so a sync pass between two pages moves rows across the page boundary. mail_thread shows the first `limit` members and reports `thread_size` and `shown`, but has no cursor, so a thread longer than the cap can never be read past it. **Desired behavior:** - Every date in a search, thread, people, evidence, changes or triage row is UTC with a trailing `Z`, minute precision as today. mail_read keeps the stored form with its offset. - Keyword and filter searches order by a UTC instant, newest first, with the message id as the tiebreak. `since` and `before` accept a date (`YYYY-MM-DD`) or a date-time with an offset, compare as UTC instants, and keep inclusive and exclusive semantics. A plain date means midnight UTC. - The UTC key is a stored column or an expression index, never a VIRTUAL generated column: the image ships SQLite 3.40.1, which cannot use an index on a virtual column (#96). Unparseable dates fall back to internaldate, as the #96 copy_key guard does. - Keyword and filter modes page by a keyset cursor over the UTC key and the id. A sync pass between pages never repeats or skips a row that existed before the first page. The cursor stays an opaque string; `next_cursor=-` still means no more. `more` and `total` stay in the footer. - mail_thread takes a `cursor` and returns `next_cursor` with `thread_size` and `shown`, paging oldest first. - A migration backfills the key for existing rows. Reader mode never writes it. **Key interfaces:** - `SearchParams`: `since`, `before` and the cursor change meaning; the store's filter builder and search query use the UTC key. - `mail_search` and `mail_thread` signatures: `cursor` on mail_thread; parameter descriptions say UTC. - The store schema version and migration list. - The #96 bench script: run head and base alternating in one container before and after, and record the numbers in the PR. **Acceptance criteria:** - [ ] Two messages dated `2026-01-01T09:00:00+11:00` and `2026-01-01T01:00:00+00:00` sort with the +00:00 one first (newest first), and `since=2026-01-01` includes only the +00:00 one (2026-01-01T01:00Z) while `since=2025-12-31` includes both. - [ ] `since=2026-01-01T00:00:00+11:00` is the same bound as `since=2025-12-31T13:00:00Z`. - [ ] A row for the +11:00 message shows `2025-12-31T22:00Z`. - [ ] Inserting a newer message between page one and page two of a keyword search neither repeats nor skips any row that page one could have shown. - [ ] A thread of 120 messages is fully readable through two mail_thread calls, and the second footer has `next_cursor=-`. - [ ] A row with an unparseable date still sorts by internaldate and is not dropped. - [ ] An existing store opens, migrates, and searches with no manual step; `Store(reader=True)` on an unmigrated store raises a clear error rather than writing. - [ ] The bench shows no regression over 10 percent on keyword search at 210k rows, in the image, head and base alternating in one container. - [ ] `make check` passes. **Out of scope:** - Paging for semantic, hybrid and similar_to modes: they rank a candidate set, and need their own design and issue. - Any change to snippet, subject or address cells (#106 item 3 is a separate sub-issue). - Changing what mail_read shows. Filed under: operator word "accept" sha256:c125d0397b60
Collaborator

⏸ SVD architect gate: dev/mail-mind-mcp#108 sort-filter-and-page-mail-search-on-a-utc-key-show-utc-dates

Status: CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity substrate · dispatch effort high

Run: 20261102T111548Z-fe47ae00

Held because: CLEAN but 3 open risk(s) (2 verification · 1 decision) — HOLD-ALL parks everything. The risks, verbatim:

Open risks:

  1. Precision and Z of the non-minute cells. The brief says people, evidence and changes dates are 'UTC with a trailing Z, minute precision as today', but today people and evidence show calendar days ([:10], server.py:604/:642/:688) and changes shows seconds with +00:00. Lean: keep each cell's current precision in UTC. Day cells show the UTC day YYYY-MM-DD with no Z, because ISO 8601 has no zone on a bare date. Changes at shows YYYY-MM-DDTHH:MM:SSZ. Existing test expectations stay. Question: take the lean, or make all of these cells YYYY-MM-DDTHH:MMZ? That changes the mail_people seen and mail_evidence span/subject formats and their ADR 0008 tests. [decision]
  2. AC8 image bench, which cannot run in this stage. On the host, build the image at base and at head (make image with distinct IMAGE tags). In one container, alternate python scripts/bench_search.py --queries for base and head at least three times each. Pass: the head medians of the 'lorem' and '1234' rows (keyword search at 210k rows) are ≤ 10% above base. Record every number in the PR. The script uses only store.search(SearchParams(...)), whose shape is unchanged, so one script runs against both trees. [verification]
  3. Primary Files ceiling under test fallout (14 of 16 files). Check: after the edits, run uv run python3 -m pytest -q -m "not integration" on the host. If a test outside the Primary Files fails on ordering or format, fix it only while the total stays ≤ 16 files. Otherwise stop and report that file instead of widening scope. [verification]

Change: Add a stored messages.date_utc column at schema v14 ('YYYY-MM-DD HH:MM:SS' UTC). It is computed by _utc_key(), which is COALESCE(_copy_date(row), the same GLOB-guarded datetime(internaldate), '') and mirrors _copy_date at store.py:276. AFTER INSERT and AFTER UPDATE OF date, internaldate triggers keep it current, so raw INSERTs in the bench and tests stay correct; this mirrors messages_recipients_ad at :268. A messages_date_utc (date_utc DESC, id DESC) index is created in a _V14_SCRIPT run by _add_columns after the ALTERs (mirroring _V5_INDEXES). A chunked _fill_utc_keys backfill runs on the writer's open, mirroring _fill_recipients at :558-571; the reader keeps the existing _wait_for_schema error. _filters compares date_utc against _utc_bound(since/before) (date = midnight UTC, offset date-time converted, invalid → invalid_argument), with a + under keyset=True like the account term at :1564. A new search_page returns (rows, total, more) and pages by the row-value keyset (date_utc, id) < (?, ?); search() stays a two-tuple wrapper, so its 62 test callers are unchanged. In server.py: opaque base64url keyset cursors (mirroring ids.encode_source/decode at ids.py:51-70) for keyword/filter mail_search and mail_triage_rows, while ranked modes keep offset cursors; _row_cells shows YYYY-MM-DDTHH:MMZ; mail_thread gets a cursor and a next_cursor=X thread_size=N shown=M footer, with joined_thread ordered by (date_utc, id); people and evidence read NULLIF(date_utc,''); changes at is shown with Z. mail_read is unchanged.

Files: src/mail_mind_mcp/store.py · src/mail_mind_mcp/server.py · README.md · tests/test_utc_dates.py · tests/test_store.py · tests/test_server.py · tests/test_copies.py · tests/test_copy_collapse.py · tests/test_panel.py · tests/test_evidence.py · tests/test_embed_scans.py · tests/test_recipients.py · tests/test_attachment_vectors.py · tests/test_attachments.py

Decision: accept the 3 open risk(s) above and dispatch this spec (svd:go), or park (svd:skip) / re-spec (svd:respec)?

Your call (when this issue is held at the gate via svd:hold):

  • add label svd:go — approve; Half-B dispatch accepts exactly this spec (open risks accepted)
  • add label svd:fire beside svd:go — approve AND authorise the Half-B fire from the phone; never on its own
  • add label svd:skip — park it; dispatch refuses it and the issue stays for a human
  • add label svd:respec — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context

Spec: /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-sort-filter-and-page-mail-search-on-a-utc-key-show-utc-dates.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-sort-filter-and-page-mail-search-on-a-utc-key-show-utc-dates.md

### ⏸ SVD architect gate: dev/mail-mind-mcp#108 sort-filter-and-page-mail-search-on-a-utc-key-show-utc-dates **Status:** CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity `substrate` · dispatch effort `high` **Run:** `20261102T111548Z-fe47ae00` **Held because:** CLEAN but 3 open risk(s) (2 verification · 1 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. Precision and Z of the non-minute cells. The brief says people, evidence and changes dates are 'UTC with a trailing Z, minute precision as today', but today people and evidence show calendar days ([:10], server.py:604/:642/:688) and changes shows seconds with +00:00. Lean: keep each cell's current precision in UTC. Day cells show the UTC day YYYY-MM-DD with no Z, because ISO 8601 has no zone on a bare date. Changes at shows YYYY-MM-DDTHH:MM:SSZ. Existing test expectations stay. Question: take the lean, or make all of these cells YYYY-MM-DDTHH:MMZ? That changes the mail_people seen and mail_evidence span/subject formats and their ADR 0008 tests. [decision] 2. AC8 image bench, which cannot run in this stage. On the host, build the image at base and at head (make image with distinct IMAGE tags). In one container, alternate `python scripts/bench_search.py --queries` for base and head at least three times each. Pass: the head medians of the 'lorem' and '1234' rows (keyword search at 210k rows) are ≤ 10% above base. Record every number in the PR. The script uses only store.search(SearchParams(...)), whose shape is unchanged, so one script runs against both trees. [verification] 3. Primary Files ceiling under test fallout (14 of 16 files). Check: after the edits, run `uv run python3 -m pytest -q -m "not integration"` on the host. If a test outside the Primary Files fails on ordering or format, fix it only while the total stays ≤ 16 files. Otherwise stop and report that file instead of widening scope. [verification] **Change:** Add a stored messages.date_utc column at schema v14 ('YYYY-MM-DD HH:MM:SS' UTC). It is computed by `_utc_key()`, which is `COALESCE(_copy_date(row), the same GLOB-guarded datetime(internaldate), '')` and mirrors `_copy_date` at store.py:276. AFTER INSERT and AFTER UPDATE OF date, internaldate triggers keep it current, so raw INSERTs in the bench and tests stay correct; this mirrors messages_recipients_ad at :268. A `messages_date_utc (date_utc DESC, id DESC)` index is created in a `_V14_SCRIPT` run by `_add_columns` after the ALTERs (mirroring `_V5_INDEXES`). A chunked `_fill_utc_keys` backfill runs on the writer's open, mirroring `_fill_recipients` at :558-571; the reader keeps the existing `_wait_for_schema` error. `_filters` compares `date_utc` against `_utc_bound(since/before)` (date = midnight UTC, offset date-time converted, invalid → invalid_argument), with a `+` under keyset=True like the account term at :1564. A new `search_page` returns (rows, total, more) and pages by the row-value keyset `(date_utc, id) < (?, ?)`; `search()` stays a two-tuple wrapper, so its 62 test callers are unchanged. In server.py: opaque base64url keyset cursors (mirroring ids.encode_source/decode at ids.py:51-70) for keyword/filter mail_search and mail_triage_rows, while ranked modes keep offset cursors; `_row_cells` shows `YYYY-MM-DDTHH:MMZ`; mail_thread gets a cursor and a `next_cursor=X thread_size=N shown=M` footer, with joined_thread ordered by (date_utc, id); people and evidence read NULLIF(date_utc,''); changes `at` is shown with Z. mail_read is unchanged. **Files:** `src/mail_mind_mcp/store.py` · `src/mail_mind_mcp/server.py` · `README.md` · `tests/test_utc_dates.py` · `tests/test_store.py` · `tests/test_server.py` · `tests/test_copies.py` · `tests/test_copy_collapse.py` · `tests/test_panel.py` · `tests/test_evidence.py` · `tests/test_embed_scans.py` · `tests/test_recipients.py` · `tests/test_attachment_vectors.py` · `tests/test_attachments.py` **Decision:** accept the 3 open risk(s) above and dispatch this spec (`svd:go`), or park (`svd:skip`) / re-spec (`svd:respec`)? **Your call** (when this issue is held at the gate via `svd:hold`): - add label `svd:go` — approve; Half-B dispatch accepts exactly this spec (open risks accepted) - add label `svd:fire` **beside** `svd:go` — approve AND authorise the Half-B fire from the phone; never on its own - add label `svd:skip` — park it; dispatch refuses it and the issue stays for a human - add label `svd:respec` — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context <sub>Spec: `/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-sort-filter-and-page-mail-search-on-a-utc-key-show-utc-dates.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-sort-filter-and-page-mail-search-on-a-utc-key-show-utc-dates.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/mail-mind-mcp#108 sort-filter-and-page-mail-search-on-a-utc-key-show-utc-dates completed integration verify.

  • PR: #143
  • Branch: feat/svd-dev-mail-mind-mcp-108-sort-filter-and-page-mail-sear-19b0fa26
  • Commit: 39e4f75ec7
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Check commit statuses on PR head: absent
  • Checks: PR #143 @39e4f75: no remote checks (none reported); local host suite 864 passed, 8 skipped, 0 failed.
  • Warning: No remote CI statuses exist on the PR head; local host run is the only integration evidence.
  • Warning: Per the spec, a copy arriving in an inbox can change the shown representative id at a page boundary; this is a known, named risk outside the acceptance criteria.
  • Warning: no CI for commit statuses on PR head: Forgejo returned no commit statuses for 39e4f75; the repo has no CI (.woodpecker files are added by the architect). — reported as absent, not blocking (gh#633)
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261102T113230Z-19b0fa26 --confirm-merge)
spec-verify-dispatch Half B for dev/mail-mind-mcp#108 sort-filter-and-page-mail-search-on-a-utc-key-show-utc-dates completed integration verify. - PR: https://git.groupthink.asia/dev/mail-mind-mcp/pulls/143 - Branch: feat/svd-dev-mail-mind-mcp-108-sort-filter-and-page-mail-sear-19b0fa26 - Commit: 39e4f75ec7ff49a00723499b9e6988abd17455fc - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Check commit statuses on PR head: absent - Checks: PR #143 @39e4f75: no remote checks (none reported); local host suite 864 passed, 8 skipped, 0 failed. - Warning: No remote CI statuses exist on the PR head; local host run is the only integration evidence. - Warning: Per the spec, a copy arriving in an inbox can change the shown representative id at a page boundary; this is a known, named risk outside the acceptance criteria. - Warning: no CI for commit statuses on PR head: Forgejo returned no commit statuses for 39e4f75; the repo has no CI (.woodpecker files are added by the architect). — reported as absent, not blocking (gh#633) - Decision: review the PR and merge? (`codex-svd ship --run-id 20261102T113230Z-19b0fa26 --confirm-merge`)
svc-svd-writer 2026-11-02 11:50:00 +00:00
  • closed this issue
  • removed the
    svd:go
    label
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/mail-mind-mcp#108
No description provided.