Skip to content

v2.1.0 fix: verify every write, finish project routing, close token leak - #4

Merged
kaufmanhenry merged 3 commits into
mainfrom
fix/project-writes-and-reparenting
Sep 29, 2026
Merged

kaufmanhenry merged 3 commits into
mainfrom
fix/project-writes-and-reparenting

Conversation

@kaufmanhenry

Copy link
Copy Markdown
Owner

Finishes the fix 2.0.4 started, and makes the class of bug it belongs to detectable instead of silent.

The bug

Every write goes out through the Things URL scheme via open. open exits 0 as soon as macOS hands the URL over — it says nothing about whether Things accepted it. Things silently ignores a command it cannot apply, and the classic case is things:///update aimed at a project, which only update-project handles.

So thingsctl complete <project> printed ✓ Completed: <project> while the row stayed type=1, status=0. Found in the field: a project looked completed and wasn't.

2.0.4 routed update correctly and stopped there. complete, move and tag were still broken. 2.0.4 was also never published, so npm's latest is still 2.0.3.

What changed

Routing. All four write commands route by entity type. Headings are refused rather than dispatched into a command that cannot apply to them.

Verification. A write is not confirmed until the database says so. src/lib/verify.js polls the row until the change is visible and reports a clear failure otherwise. This is the part that matters: it turns the next silent drop into an error instead of a lie. Timeout is overridable with THINGSCTL_VERIFY_TIMEOUT_MS.

Re-parenting, which the tool could not do at all. update --list / --list-id moves a to-do into a project or area; update --area / --area-id moves a project into an area. Verified against the row's project / area column, not against "something changed". Things always supported this — only thingsctl was missing it.

Found by the pre-landing review

  • The auth token leaked into error output. open echoes the whole failing URL, auth-token included, and that text was spliced into ThingsUrlError — printed to stderr by the CLI and returned as tool output by the MCP server, i.e. into a model transcript. Redacted at the source.
  • % as an id matched every task. resolveTaskId interpolated the id into a LIKE pattern, so complete '%' --yes-first resolved to an arbitrary row. Escaped now, and it mattered more once update could relocate work.
  • --completed false completed the task. The CLI parser yields the string 'false', which is truthy, so the flag did the opposite of what it says.
  • Bulk complete was N x 3s against a quit Things, and the synchronous wait blocks the MCP server's event loop. Bounded: shared batch budget, backoff, one connection per wait instead of one per poll, and a lower default timeout in the MCP server.

Verification

129 tests, up from 79 at 2.0.3. The dispatch suite previously mocked verification wholesale, so every failure path was uncovered; it now stubs only waitForWrite and leaves the SQL and the failure text real.

Checked end to end against real Things, not just in tests:

  • a scratch project completes and lands status=3
  • a to-do re-parents and the project column holds the target uuid
  • tagging with a tag that doesn't exist now reports failure instead of a checkmark

Follow-ups, not in this PR

  • The write path is synchronous end to end. The MCP server gets a lower timeout to bound the freeze; making it async is the real fix.
  • Adding a CLI flag requires registering it in four places (cli.js dispatch, MCP schema, help.js, README). This PR was bitten by it — --list reached three of the four. A per-command flag manifest would collapse that to one.

https://claude.ai/code/session_01LMbjcZogpv9EbVnqovXpSX

…renting

Writes aimed at a project were discarded by Things and still reported success.
`complete`, `update` and `move` all built `things:///update`, which Things only
applies to to-dos; it ignores a project uuid without raising anything. `open`
exits 0 either way, so the CLI printed a checkmark for a write that never
happened. Found when completing a project appeared to work and the row stayed
`type=1, status=0`.

Three changes:

- Route projects to `things:///update-project`, the endpoint Things documents
  for them. Headings are refused outright rather than dispatched into a no-op.
- Confirm every write against the database before reporting success. `open`
  exiting 0 says macOS handed over the URL, nothing more, so lib/verify polls
  the row (up to 3s) until the change is visible and reports a clear failure
  otherwise. This is what turned the routing bug from an error into a lie.
- Add re-parenting, which the tool could not do at all: `update --list` /
  `--list-id` moves a to-do into a project or area, `update --area` /
  `--area-id` moves a project into an area. Passing the wrong pair for the type
  is refused with an explanation instead of being silently dropped by Things.

Also fixes `things_move`'s description, which read as a re-parent when it only
ever rescheduled, and the CLI's hand-curated flag allowlist for `update`, which
would have dropped the new options.

Verified end to end against real Things: a scratch project completes and lands
`status=3`, a scratch to-do re-parents into an area and completes.

Claude-Session: https://claude.ai/code/session_01LMbjcZogpv9EbVnqovXpSX
2.0.4 landed the same root-cause fix for `update` only: it routes project
updates to `things:///update-project`. This branch is a superset, so the code
conflicts resolve to this side.

What 2.0.4 left unfixed, and this branch finishes:
- `complete` and `move` still built `things:///update`, so completing or
  rescheduling a PROJECT remained a silent no-op that reported success.
- Nothing verified that a write landed, which is what let the no-op print a
  checkmark in the first place.
- No way to move a to-do or project to a different parent.

Kept 2.0.4's CHANGELOG entry and its buildUpdateProjectUrl unit test; folded
that test into this branch's fuller describe block rather than leaving two
blocks of the same name. Restated the 2.1.0 entry so it credits 2.0.4 with the
`update` half instead of claiming the whole fix.

100 tests pass.

Claude-Session: https://claude.ai/code/session_01LMbjcZogpv9EbVnqovXpSX
Five review lenses ran against this branch. What they found, and what changed:

SECURITY
- macOS `open` echoes the whole failing url back on stderr, auth-token
  included, and exec.js spliced that into ThingsUrlError. The CLI prints it to
  stderr and the MCP server returns it as tool output, so the token landed in a
  model transcript. Redacted at the source; complete.js no longer interpolates
  the raw error into per-item output either.
- resolveTaskId interpolated the id into a LIKE pattern, so `complete '%'
  --yes-first` resolved to an arbitrary row. Wildcards are escaped now. This
  got worse the moment update could relocate work instead of only completing it.

CORRECTNESS
- tag.js was still building `things:///update`, so tagging a project stayed a
  silent no-op. The diff claimed to fix every write and had missed one.
- `--completed false` sent completed=true: the parser yields the string
  'false', which is truthy. Booleans are normalised once, up front.
- Re-parenting was verified only by "userModificationDate moved", which a
  concurrent edit or a Cloud sync also satisfies. It now asserts the row's
  project/area column equals the resolved target.
- update/move refused nothing for headings and would stall the full timeout.
- Restored the "project" label on update's success line, dropped when I
  resolved the 2.0.4 merge.

PERFORMANCE
- One connection per wait, not one per poll (measured ~18x on the poll loop).
- Backoff 20/40/80 then 100ms; the first read almost always misses, so every
  verified write used to pay a flat 100ms.
- Bulk complete shares one budget: N ids against a quit Things was N x 3s.
- The wait is synchronous and blocks the MCP server's event loop, so that
  server now defaults to a 1200ms timeout. THINGSCTL_VERIFY_TIMEOUT_MS
  overrides both. Making the write path async is the real fix; not done here.

SIMPLIFICATION / MAINTAINABILITY
- Deleted WriteNotAppliedError, which was dead on arrival, and replaced the
  three hand-copied failure strings with verify.notApplied.
- verify.js exports 6 names instead of 6 with 3 unused; VERIFY_FIELDS selects
  the 8 columns predicates actually read, not 13.
- db.close() resets the test-seam flag; help.js documents the new flags.
- move.js says "Rescheduled" on success, matching its own failure string.

TESTS: 100 -> 129. The old dispatch suite mocked verification wholesale, so
every failure path was uncovered. It now stubs only waitForWrite, leaving the
SQL and the failure text real, and covers: failure reporting for all four write
commands, heading refusal, list-id/area-id precedence, row-level re-parent
verification, --completed false, LIKE escaping, and token redaction.

Verified end to end against real Things: re-parent lands in the project column,
task and project both complete, and tagging with a tag that does not exist now
reports failure instead of a checkmark.

Claude-Session: https://claude.ai/code/session_01LMbjcZogpv9EbVnqovXpSX
@kaufmanhenry
kaufmanhenry merged commit 62fae9b into main Sep 29, 2026
3 checks passed
@kaufmanhenry
kaufmanhenry deleted the fix/project-writes-and-reparenting branch September 29, 2026 17:07
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