Skip to content

fix(refs): stop task refs resolving to an item the user did not name - #422

Merged
ryanlewis merged 4 commits into
mainfrom
fix/refs
Oct 9, 2026
Merged

ryanlewis merged 4 commits into
mainfrom
fix/refs

Conversation

@ryanlewis

@ryanlewis ryanlewis commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Several kinds of task reference could make complete, cancel, edit or show act on an item other than the one named. This closes those paths.

What changes

  • Exact title on a closed or trashed item. Before, complete "zz base" with "zz base" completed and "zz base extra" open completed "zz base extra". An exact title is now looked up across every status. An open item with the exact title still wins. When only closed or trashed items have it, a write fails non-zero with already closed or trashed. The error names the most recent of those items and how many share the title, and says no open task was touched. show displays the item, or offers the closed items as candidates. A uuid or row number that names a closed item keeps the existing exit-0 note.

  • Leading zeros. 07, 00 and 0 are no longer row numbers, since listings never print them. They match an exact title only, and the error suggests 7 when the last list has a row 7.

  • Unreadable cache. A last-list cache file that exists but is empty, truncated, garbled or not a file now refuses a bare number with stale list cache. Before, it was treated as no cache, and the number fell through to a task titled with it. A missing cache still falls through to an exact title, as documented in A numeric ref past the end of the last list falls through to a title match #375.

  • uuid-shaped refs. A ref that looks like a Things uuid but matches none now gets exact-title matching only, never substring matching. That shape is 21 or 22 ASCII letters and digits, or the 36-character hex form. uuids match case-sensitively and titles do not, so a uuid typed in the wrong case could reach a task whose title contained it.

  • Empty refs. An empty or all-space ref is refused before any lookup, with a new empty reference JSON token. Other refs are not trimmed.

  • Case and space variants. A title that matches a closed or trashed item once case and surrounding space are set aside is refused the same way. So complete "pay rent" with only a completed "Pay rent" no longer closes the open "Re: Pay rent deposit" through the case-folding substring match. An open item that matches with case and space set aside, such as an open "pay rent" for "PAY RENT", still wins over a closed one.

  • Tasks in a trashed project. This partly addresses Items filed into a trashed project show no Trash hint #401. show marks a to-do whose project is in the Trash (in Trash), and --json adds "projectTrashed": true only when it is true. open refuses such a to-do with trashed, since Things has nowhere to show it. Refusals about it name the project, in the text and in a new project JSON field.

  • Several closed items. "Most recent" is the item Things last modified, then the latest stop date, then the latest creation date. When several closed items share the title, the refusal lists them all in matches.

The commands and agents docs pages and the bundled skill file are updated to match.

Tests

Table-driven tests in cmd/things/refs_test.go cover:

  • closed, cancelled and trashed exact titles with an open substring twin
  • a to-do in a trashed project, directly and through a heading
  • several closed copies of one title
  • a case variant
  • the uuid and row paths keeping the note
  • leading-zero refs and a bare 0
  • every unreadable cache variant
  • uuid-shaped misses against a decoy title
  • empty refs

The cache package tests cover the new read errors. make test and make lint pass.

Not in this PR

  • things --project <to-do uuid> still prints nothing and exits 0. That goes through the listing filter rather than ref lookup, so it is tracked separately.
  • things open <title> can open a trashed or closed item by exact title. Things can show those, and nothing is written. A to-do in a trashed project is refused, as above.

- An exact title on a completed, cancelled or trashed row (or a to-do in a
  trashed project) now wins over a substring match on an open row, so the
  write is refused or noted on that row instead of landing on an open twin
  whose title contains it. An open row with the exact title still wins.
- Digits with a leading zero, and a bare 0, are not row numbers. They reach
  an exact title only.
- A last-list cache file that exists but cannot be read (empty, garbled,
  truncated, not a file) refuses a bare-number ref instead of falling
  through to a title.
- A uuid-shaped ref that is no item's uuid matches an exact title only,
  never a substring, since uuids are case-sensitive and titles are not.
- An empty or blank ref is refused up front with the new
  `empty reference` JSON token.
A write (complete, cancel, edit, project edit) whose ref is an exact title
that only completed, cancelled or trashed items carry now fails non-zero
with `already closed` or `trashed`, naming the most recent of them and how
many share the title. A uuid or row number that names a closed item keeps
the exit-0 note. show still displays the item, or offers the closed items
as candidates.

Also from review: trim the ref before the uuid-shape check, fetch all
exact-title rows in one query, reword the uuid-shaped not-found error, and
update the ProjectTrashed comment and the skill's uuid shapes.
- A title that matches a closed or trashed item once case and surrounding
  space are set aside is refused too, before the case-folding substring
  match can reach an open lookalike.
- show marks a to-do whose project is in the Trash "(in Trash)" and emits
  "projectTrashed": true; open refuses it with the trashed token.
- Trashed-project refusals name the project, in text and in a new
  "project" JSON field.
- A uuid-shaped ref padded with space is retried trimmed.
- "Most recent" uses Things' modification date first, and a refusal over
  several closed items lists them in "matches".
- Tests pin preferInstances on closed rows, the trim, and recency.
When the exact title misses, GetTask now matches open rows under the fold key first: one open match wins and several are ambiguous. Only when none exists does a closed or trashed fold match raise the closed-title refusal. Tests pin the trashed-project check and preferInstances on the folded path.
@ryanlewis
ryanlewis merged commit d79e432 into main Oct 9, 2026
10 checks passed
@ryanlewis
ryanlewis deleted the fix/refs branch October 9, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant