Skip to content

fix(inbox): preserve task/cron source_kind in thread UPSERT#197

Merged
LIU9293 merged 1 commit into
mainfrom
fix/inbox-source-kind-upsert-776629
Apr 20, 2026
Merged

fix(inbox): preserve task/cron source_kind in thread UPSERT#197
LIU9293 merged 1 commit into
mainfrom
fix/inbox-source-kind-upsert-776629

Conversation

@LIU9293

@LIU9293 LIU9293 commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • One-time tasks were showing up as User Thread in the inbox UI because ensureMessageThread's ON CONFLICT clause overwrote source_kind with excluded.source_kind, and params.sourceKind ?? \"user\" meant any re-ensure from a caller that didn't pass sourceKind (e.g. runtime-facade.ts hardcoding \"user\") flipped a task/cron thread back to user.
  • Make the UPSERT conservative: keep existing source_kind when it's already 'task' or 'cron_job'; otherwise take the incoming value. user -> task/cron_job upgrades still work.
  • Adds a regression test covering task preservation, cron_job preservation, and the allowed user -> task upgrade.

Files

  • packages/config/local/inbox.ts — conservative CASE overwrite for source_kind in the thread UPSERT.
  • packages/config/local/inbox.test.ts — regression test preserves task/cron source_kind when a later ensureMessageThread call defaults to user.

Test Plan

  • bun test packages/config/local/inbox.test.ts → 7/7 pass (6 existing + 1 new).
  • bun test packages/core/test/web-routes.test.ts → 7/7 pass (inbox consumer unaffected).

Notes

  • Historical rows already flipped to user are not auto-repaired by this change. If we want to backfill, we'd add a one-shot UPDATE message_thread SET source_kind='task' WHERE task_id IS NOT NULL AND source_kind='user' (and the cron_job equivalent) on startup — happy to follow up if needed.

Previously ensureMessageThread's ON CONFLICT clause overwrote
source_kind with excluded.source_kind unconditionally, while the
params-level default was "user". Any re-ensure of a task or cron
thread from a caller that did not pass sourceKind (e.g.
runtime-facade.ts hardcoding "user") would flip an already-typed
thread back to "user", causing one-time tasks to appear as regular
user threads in the inbox UI.

Make the UPSERT conservative: keep the existing source_kind when it
is already 'task' or 'cron_job'; otherwise take the new value. This
still allows user -> task/cron_job upgrades, and does not require
touching every caller.

Adds a regression test covering task preservation, cron_job
preservation, and the allowed user -> task upgrade.
@LIU9293
LIU9293 merged commit 7e48d55 into main Apr 20, 2026
2 checks passed
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