Skip to content

fix(todo-sync): provide default priority to prevent SQLite NOT NULL violation#2345

Open
DarkFunct wants to merge 1 commit intocode-yeongyu:devfrom
DarkFunct:fix/todo-sync-priority-null
Open

fix(todo-sync): provide default priority to prevent SQLite NOT NULL violation#2345
DarkFunct wants to merge 1 commit intocode-yeongyu:devfrom
DarkFunct:fix/todo-sync-priority-null

Conversation

@DarkFunct
Copy link

@DarkFunct DarkFunct commented Mar 6, 2026

Problem

syncTaskToTodo() calls extractPriority(task.metadata) which returns undefined when task metadata has no priority field (the common case — almost no one manually passes metadata.priority).

However, OpenCode's TodoTable schema defines priority as NOT NULL:

CREATE TABLE `todo` (
  `priority` text NOT NULL,
  ...
);

This causes a SQLiteError: NOT NULL constraint failed: todo.priority on every Todo.update() call. The error is silently caught by the try/catch in syncTaskTodoUpdate, making Task→Todo sync completely non-functional by default.

Root Cause

// todo-sync.ts — syncTaskToTodo()
return {
  id: task.id,
  content: task.subject,
  status: todoStatus,
  priority: extractPriority(task.metadata), // ← returns undefined when no metadata.priority
};

Fix

- priority: extractPriority(task.metadata),
+ priority: extractPriority(task.metadata) ?? "medium",

One-line change: provide "medium" as default when no priority is specified. This matches the semantic middle ground and doesn't alter behavior for users who explicitly set priority via metadata.

Impact

Without this fix, no tasks created via task_create or task_update appear in the OpenCode TUI Todo panel unless the user manually passes metadata: { priority: "medium" } — which virtually no one does.


Summary by cubic

Provide a default "medium" priority in Task→Todo sync to satisfy the TodoTable NOT NULL constraint and restore syncing for tasks without metadata.priority.

  • Bug Fixes
    • Use extractPriority(task.metadata) ?? "medium" to avoid NULL writes.
    • Stops SQLite NOT NULL errors and makes new/updated tasks show in the Todo panel by default.

Written for commit 229c6b0. Summary will update on new commits.

…iolation

extractPriority() returns undefined when task metadata has no priority
field, but OpenCode's TodoTable requires priority as NOT NULL. This
causes a silent SQLiteError that prevents all Task→Todo syncing.

Add ?? "medium" fallback so todos always have a valid priority.
Copilot AI review requested due to automatic review settings March 6, 2026 15:33
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA).

To sign the CLA, please comment on this PR with:

I have read the CLA Document and I hereby sign the CLA

This is a one-time requirement. Once signed, all your future contributions will be automatically accepted.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Fixes a SQLite NOT NULL constraint violation by providing a safe default value ('medium'), restoring functionality without side effects.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Task→Todo sync failures by ensuring a default priority is always provided when converting a Task into a Todo payload, preventing SQLite NOT NULL violations on todo.priority.

Changes:

  • Default priority to "medium" when metadata.priority is missing or invalid in syncTaskToTodo().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

content: task.subject,
status: todoStatus,
priority: extractPriority(task.metadata),
priority: extractPriority(task.metadata) ?? "medium",
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes syncTaskToTodo() so missing/invalid metadata.priority now yields a concrete priority ("medium") instead of undefined. The existing unit tests in src/tools/task/todo-sync.test.ts currently assert priority is undefined for (a) tasks without metadata, (b) tasks without metadata.priority, and (c) invalid priority values, so they will fail unless updated to expect the new default (and/or the desired fallback behavior is adjusted).

Suggested change
priority: extractPriority(task.metadata) ?? "medium",
priority: extractPriority(task.metadata),

Copilot uses AI. Check for mistakes.
@acamq
Copy link
Collaborator

acamq commented Mar 6, 2026

@DarkFunct Thanks for the PR! While I review, could you sign the CLA?

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA).

To sign the CLA, please comment on this PR with:

I have read the CLA Document and I hereby sign the CLA

This is a one-time requirement. Once signed, all your future contributions will be automatically accepted.

I have read the CLA Document and I hereby sign the CLA

You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Thank you!

@acamq
Copy link
Collaborator

acamq commented Mar 7, 2026

Thanks for this fix — the diagnosis is spot on. The priority: undefined was causing SQLite NOT NULL violations that were silently swallowed, breaking the entire Task→Todo sync.

One small thing: the existing tests expect priority: undefined for tasks without metadata. After this change, they'll expect "medium" instead. Would you be willing to update the test expectations?

Specifically, these tests:

  • converts pending task to pending todo (line 26-32)
  • ignores invalid priority values (line 162)
  • handles missing metadata (line 180)

If not, no worries — I can handle it in a follow-up. Just let me know.

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.

3 participants