fix(inbox): preserve task/cron source_kind in thread UPSERT#197
Merged
Conversation
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.
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.
Summary
ensureMessageThread'sON CONFLICTclause overwrotesource_kindwithexcluded.source_kind, andparams.sourceKind ?? \"user\"meant any re-ensure from a caller that didn't passsourceKind(e.g.runtime-facade.tshardcoding\"user\") flipped a task/cron thread back touser.source_kindwhen it's already'task'or'cron_job'; otherwise take the incoming value.user -> task/cron_jobupgrades still work.user -> taskupgrade.Files
packages/config/local/inbox.ts— conservativeCASEoverwrite forsource_kindin the thread UPSERT.packages/config/local/inbox.test.ts— regression testpreserves 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
userare not auto-repaired by this change. If we want to backfill, we'd add a one-shotUPDATE 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.