Skip to content

Task schema properties not settable in TaskNodeViewer for nested tasks - #923

Merged
malibio merged 2 commits into
mainfrom
feature/issue-919-task-schema-properties-settable
Mar 9, 2026
Merged

malibio merged 2 commits into
mainfrom
feature/issue-919-task-schema-properties-settable

Conversation

@malibio

@malibio malibio commented Mar 7, 2026

Copy link
Copy Markdown
Collaborator

Closes #919

- Fix startedAt/completedAt missing from optimistic update in updateTaskNode()
- Fix startedAt/completedAt missing from backend response mapping in updateTaskNode()
- Fix state_unsafe_mutation Svelte 5 error in schema-property-form.svelte:
  pre-initialize comboboxOpen keys for date fields in $effect after schema loads
  instead of mutating $state inside template expressions (which Svelte 5 forbids)
- Add tests for startedAt and completedAt optimistic update coverage
- Update CLAUDE.md to guide agents to read architecture docs when working on
  node storage, data models, or type-specific fields

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@malibio

malibio commented Mar 9, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This PR fixes two independent defects that were both blocking task schema properties from being settable in TaskNodeViewer:

  1. Data-layer gap: startedAt and completedAt were missing from both the optimistic update path and the backend-response reconciliation path in updateTaskNode().
  2. Svelte 5 runtime violation: comboboxOpen was being mutated inside a {@const} / template expression — which Svelte 5 explicitly forbids (state_unsafe_mutation). The fix moves initialization into the $effect that runs after schema loads.

Both fixes are correct, minimal, and well-scoped. The change is a clear net improvement and the defects are properly addressed.


Findings

Suggested Improvements

shared-node-store.svelte.ts ~line 1483 — Type-assertion pattern

The (localChanges as Record<string, unknown>)['field'] = value idiom is used for every spoke field except content. This works, but it means the compiler cannot catch a typo in the string key (e.g. 'startedAt' vs 'started_at'). Since TaskNode is a concrete interface with these fields already defined, a cleaner approach would be to type localChanges as Partial<TaskNode> and assign directly:

const localChanges: Partial<TaskNode> = {};
if (update.startedAt !== undefined) localChanges.startedAt = update.startedAt;

This is a pre-existing pattern in the file, so it does not block this PR, but extending the same workaround to two more fields increases the surface area for future drift.

schema-property-form.svelte ~line 103 — comboboxOpen pre-initialization only runs for date fields

The comboboxOpen map is also used for text/assignee fields (lines 471–476), but those keys are initialized lazily via || false at read time. This is an inconsistency: date fields now get eagerly pre-initialized in the $effect, while text fields still rely on the lazy read-time default. There is no current breakage since the text/assignee path uses comboboxOpen[field.name] || false rather than a direct bind:open, but if a future change introduces a bind:open on a text field, it would reproduce the original Svelte 5 error. Consider unifying the initialization pattern to pre-initialize all popover-backed keys in the $effect.

Acceptance Criteria Coverage

Criterion Status
All core task fields (status, priority, dueDate, assignee) settable Pre-existing — not regressed
startedAt and completedAt settable and persist Fixed in shared-node-store.svelte.ts
Optimistic local updates work for all fields Fixed — both fields now included in optimistic path
Backend response mapped back correctly for all fields Fixed — both fields now in Object.assign reconciliation
No silent error swallowing Existing shouldLogDatabaseErrors() + throw error ensures failures surface; unchanged and correct
Tests pass 51/51 tests pass including the 2 new cases
Code passes quality:fix svelte-check: 0 errors, 0 warnings; ESLint: clean
Determine if bug affects root-level or only nested tasks Not explicitly documented in the change — the fix is correct regardless (the store is shared across root and nested)

Nitpicks

  • Nit: The two new test fixtures (updated = store.getNode(...) as Node & { startedAt?: string }) replicate the same casting pattern used by the pre-existing assignee and dueDate tests. This is consistent with the file's existing style, so no change needed — but worth noting that TaskNode from $lib/types already has these fields typed; the tests could import and cast to TaskNode directly for stronger typing.
  • Nit: The CLAUDE.md addition is valuable and placed correctly, but it states Svelte 4.x in the "Current Architecture" section immediately below it. The codebase uses Svelte 5 runes ($state, $effect, $props). That description predates this PR — not introduced here — but it is now directly adjacent to the new guidance, making the stale version a mild readability concern.

Verdict

Approve. Both bugs are correctly fixed, the Svelte 5 rune compliance is enforced via tooling (svelte-check passes clean), error handling is sound (errors are thrown after rollback, not swallowed), and the new tests cover the previously untested paths. The suggested improvements are non-blocking improvements to a pre-existing pattern.

🤖 Generated with Claude Code

@malibio

malibio commented Mar 9, 2026

Copy link
Copy Markdown
Collaborator Author

Review Status: APPROVED — Detailed findings posted above. Both defects are correctly fixed, all quality gates pass, and the change is a clear net improvement. Safe to merge.

- Suggestion 1: Replace six `(localChanges as Record<string, unknown>)[key]`
  casts in `updateTaskNode` with a properly typed `Partial<TaskNode>` local
  variable, eliminating the type-assertion idiom and enabling full compiler
  verification of field names and value types. Null-to-undefined coercion is
  applied for `priority` since `TaskNode.priority` is `T | undefined` while
  `TaskNodeUpdate.priority` allows `null` to clear the field.

- Suggestion 2: Unify combobox/popover pre-initialization in the schema
  load `$effect` to cover text/string fields alongside date fields. Date
  fields require this because they use `bind:open`; text/assignee fields
  are now initialized here too for a consistent strategy.

- Nitpick 1: Update test result casts from `Node & { field?: T }` to
  `unknown as TaskNode` across all `updateTaskNode` test assertions, giving
  stronger typing via the canonical `TaskNode` interface.

- Nitpick 2: Correct stale "Svelte 4.x" in CLAUDE.md to "Svelte 5.x" with
  rune context ($state, $derived, $effect).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@malibio

malibio commented Mar 9, 2026

Copy link
Copy Markdown
Collaborator Author

Review Recommendations Addressed

All four items from the review have been addressed in commit d2ae68d.

Suggestion 1: Type-assertion pattern in updateTaskNode ✅ Addressed

Replaced all six (localChanges as Record<string, unknown>)[key] = ... casts with a single Partial<TaskNode> typed local variable. All field assignments now get full compiler verification of key names and value types. One nuance handled: TaskNodeUpdate.priority allows null (to clear the field) while TaskNode.priority is T | undefined, so a ?? undefined coercion is applied at that single assignment point.

Import of TaskNode added to shared-node-store.svelte.ts.

Suggestion 2: Inconsistent popover initialization strategy ✅ Addressed

Extended the $effect pre-initialization loop to cover text/string fields alongside date fields. The comment was updated to explain the distinction: date fields require pre-initialization because they use bind:open (Svelte 5 forbids mutating $state during template evaluation), while text/assignee fields are now initialized here too for a unified strategy.

Nitpick 1: Test cast type ✅ Addressed

All six as Node & { field?: string } intersection casts in the updateTaskNode test block are now as unknown as TaskNode. Since getNode() returns Node | undefined and TaskNode doesn't extend Node, the double-cast is required by the TypeScript compiler; this is the correct pattern for intentional narrowing to a known subtype. All other test casts in the file that already used the intersection pattern (outside the task-specific tests) were left unchanged as they are appropriate for their context.

Nitpick 2: Svelte version in CLAUDE.md ✅ Fixed

Updated "Svelte 4.x" to "Svelte 5.x with reactive state management ($state, $derived, $effect runes)" in the Current Architecture section. Confirmed actual version from package.json: ^5.39.4.

Result

  • 115 test files / 3683 tests: all pass
  • svelte-check: 0 errors, 0 warnings
  • Pre-commit hooks: passed (ESLint, svelte-check, cargo fmt, clippy)

No re-review blockers. Ready for merge.

@malibio
malibio merged commit ae7dd27 into main Mar 9, 2026
@malibio
malibio deleted the feature/issue-919-task-schema-properties-settable branch March 9, 2026 16:55
malibio added a commit that referenced this pull request Jun 22, 2026
#923)

* Fix: Task schema properties settable in TaskNodeViewer (closes #919)

- Fix startedAt/completedAt missing from optimistic update in updateTaskNode()
- Fix startedAt/completedAt missing from backend response mapping in updateTaskNode()
- Fix state_unsafe_mutation Svelte 5 error in schema-property-form.svelte:
  pre-initialize comboboxOpen keys for date fields in $effect after schema loads
  instead of mutating $state inside template expressions (which Svelte 5 forbids)
- Add tests for startedAt and completedAt optimistic update coverage
- Update CLAUDE.md to guide agents to read architecture docs when working on
  node storage, data models, or type-specific fields

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* Address PR #923 review recommendations

- Suggestion 1: Replace six `(localChanges as Record<string, unknown>)[key]`
  casts in `updateTaskNode` with a properly typed `Partial<TaskNode>` local
  variable, eliminating the type-assertion idiom and enabling full compiler
  verification of field names and value types. Null-to-undefined coercion is
  applied for `priority` since `TaskNode.priority` is `T | undefined` while
  `TaskNodeUpdate.priority` allows `null` to clear the field.

- Suggestion 2: Unify combobox/popover pre-initialization in the schema
  load `$effect` to cover text/string fields alongside date fields. Date
  fields require this because they use `bind:open`; text/assignee fields
  are now initialized here too for a consistent strategy.

- Nitpick 1: Update test result casts from `Node & { field?: T }` to
  `unknown as TaskNode` across all `updateTaskNode` test assertions, giving
  stronger typing via the canonical `TaskNode` interface.

- Nitpick 2: Correct stale "Svelte 4.x" in CLAUDE.md to "Svelte 5.x" with
  rune context ($state, $derived, $effect).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
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.

Task schema properties not settable in TaskNodeViewer for nested tasks

1 participant