Repository navigation
v2.1.0 fix: verify every write, finish project routing, close token leak - #4
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.openexits 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 isthings:///updateaimed at a project, which onlyupdate-projecthandles.So
thingsctl complete <project>printed✓ Completed: <project>while the row stayedtype=1, status=0. Found in the field: a project looked completed and wasn't.2.0.4 routed
updatecorrectly and stopped there.complete,moveandtagwere 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.jspolls 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 withTHINGSCTL_VERIFY_TIMEOUT_MS.Re-parenting, which the tool could not do at all.
update --list/--list-idmoves a to-do into a project or area;update --area/--area-idmoves a project into an area. Verified against the row'sproject/areacolumn, not against "something changed". Things always supported this — only thingsctl was missing it.Found by the pre-landing review
openechoes the whole failing URL,auth-tokenincluded, and that text was spliced intoThingsUrlError— 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.resolveTaskIdinterpolated the id into aLIKEpattern, socomplete '%' --yes-firstresolved to an arbitrary row. Escaped now, and it mattered more onceupdatecould relocate work.--completed falsecompleted the task. The CLI parser yields the string'false', which is truthy, so the flag did the opposite of what it says.completewas 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
waitForWriteand leaves the SQL and the failure text real.Checked end to end against real Things, not just in tests:
status=3projectcolumn holds the target uuidFollow-ups, not in this PR
--listreached three of the four. A per-command flag manifest would collapse that to one.https://claude.ai/code/session_01LMbjcZogpv9EbVnqovXpSX