Skip to content

fix(staged_tasks): filter completed entities in creation dedup and default relevance_score (#21875) - #21876

Merged
Git-on-my-level merged 1 commit into
BasedHardware:mainfrom
hardik4love-lang:fix/staged-tasks-uncompleted-dedup-sorting
Nov 8, 2026
Merged

Git-on-my-level merged 1 commit into
BasedHardware:mainfrom
hardik4love-lang:fix/staged-tasks-uncompleted-dedup-sorting

Conversation

@hardik4love-lang

@hardik4love-lang hardik4love-lang commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Fixes #21875 by filtering out completed staged tasks during creation-time deduplication in create_staged_task() and defaulting relevance_score to 0 when omitted. This ensures previously completed/promoted staged tasks do not deadlock future candidate creation, and that all newly created staged tasks have a valid sort key for Firestore order_by('relevance_score') queries.

Product invariants affected

  • none

How it was verified

Verified via hermetic pytest suite in backend/tests/unit/test_staged_tasks_dedup.py (18/18 tests passing), covering:

  • Skipping completed staged tasks during creation dedup.
  • Defaulting relevance_score to 0 when omitted.
  • Case-insensitivity, marker stripping, and active staged task deduplication.

Tests

backend/tests/unit/test_staged_tasks_dedup.py

UI evidence

UI-Evidence: none

Failure class (fixes)

Failure-Class: none

View guided diff

@hardik4love-lang

Copy link
Copy Markdown
Contributor Author

Hi @Git-on-my-level, @kodjima33,

All automated CI checks, hygiene preflights, and backend unit suites are now 100% green:

  • Formatting: PASS (\�lack==26.5.1)
  • Hygiene: PASS
  • Backend Unit Shards (1/6 – 6/6): PASS
  • Backend Unit Suite: PASS
  • Backend Hermetic Merge Gate: PASS
  • Staged Tasks Regression Suite: PASS (18/18 tests)

Ready for maintainer review and merge!

@Git-on-my-level

Copy link
Copy Markdown
Member

Reviewed both changed files against issue #21875 — this fix checks out.

backend/database/staged_tasks.py

  • create_staged_task now skips completed rows during description dedup (if data.get('completed'): continue). This resolves the deadlock where a previously promoted/completed staged task with a matching normalized description was returned as-is — invisible to get_staged_tasks (which filters completed == False) and rejected by promote_staged_task. The completed-skip pattern matches get_active_staged_tasks_for_compatibility in the same file, and the to_dict() or {} guard is a small robustness improvement.
  • Always writing relevance_score (default 0) is the right call: Firestore silently omits documents that lack an order_by field, so docs created without a score never appeared in get_staged_tasks / get_top_staged_task_for_promotion.

backend/tests/unit/test_staged_tasks_dedup.py

  • Both new tests directly regression-test the two defects (completed-doc no longer short-circuits creation; persisted doc carries relevance_score=0), with assertions on both the returned and the written document.

Two non-blocking notes:

  1. The relevance_score ternary is redundant — kwargs.get('relevance_score', 0) if kwargs.get('relevance_score') is not None else 0 can be simplified; behavior is correct either way, including an explicit 0 or None.
  2. The default only fixes future writes — legacy rows already stored without relevance_score will remain invisible to the ordered queries until backfilled. Worth a follow-up if any production rows predate the field.

Checks pass on the head (Backend unit suite, Backend Hermetic Merge Gate, Formatting, Hygiene). Thanks @hardik4love-lang — clean diagnosis and a well-scoped fix with the right tests. Leaving the merge decision to a human maintainer.


AI-generated maintainer feedback on behalf of the Omi maintainers.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution backend Backend Task (python) labels Oct 16, 2026
@hardik4love-lang

Copy link
Copy Markdown
Contributor Author

Thanks @Git-on-my-level! Appreciate the detailed review and confirmation. Ready for human maintainer merge.

@Git-on-my-level

Copy link
Copy Markdown
Member

The production change here is correct and nicely scoped — this is a genuine fix for the dedup deadlock and the missing-field sort drop described in #21875, and I have no blocking findings. Leaving formal sign-off to a human maintainer.

What I verified on the head:

  • backend/database/staged_tasks.py — the added if data.get('completed'): continue in create_staged_task's dedup loop is the right minimal fix. Before it, a completed/promoted/dismissed staged task with a matching normalized description was returned as the "existing" doc; since get_staged_tasks and get_top_staged_task_for_promotion both filter completed == False and promote_staged_task short-circuits to None for completed rows, a user could never re-create that task. The guard also mirrors the defensive data.get('completed') pattern already used elsewhere in this file (get_active_staged_tasks_for_compatibility, get_staged_task_for_compatibility).
  • backend/database/staged_tasks.py — hoisting relevance_score into the doc literal so it is always written (defaulting to 0) is correct and necessary: get_staged_tasks orders by relevance_score ASC, and Firestore silently omits documents missing the order_by field, so tasks created without an explicit score were invisible to reads and to the top-of-queue promotion pick. Moving it out of the kwargs-only loop is required for that guarantee. Nit, non-blocking: kwargs.get('relevance_score', 0) if kwargs.get('relevance_score') is not None else 0 is redundant — both branches evaluate to 0 when the key is absent; kwargs.get('relevance_score') or 0 or a plain default would read cleaner.
  • backend/tests/unit/test_staged_tasks_dedup.py — both new tests are hermetic (MagicMock collection, monkeypatched _user_col) and assert the right contracts: a completed doc is skipped and a fresh active row is written, and an omitted relevance_score persists as 0 in the saved document. Dropping the now-unused timezone import is tidy.

Performance: no new queries; the dedup loop still streams the same collection it did before.
Security: uid-scoped collection access is unchanged; nothing here widens access.
Blast radius: users who previously hit the deadlock can re-create the affected task; everyone else's staged-task flow is unchanged.

USER IMPACT: users who completed or promoted a staged task can now have that same task suggested again instead of it being silently blocked forever, and newly suggested tasks always appear in the staged-task list and promotion queue.

What I would still want as a reviewer: the default relevance_score of 0 sorts first in the ascending promotion order (lowest promoted first), so unscored tasks jump the queue ahead of scored ones — worth a quick maintainer sanity-check that this matches the intended ranking semantics. A test asserting that a relevance_score explicitly passed via kwargs still overrides the default would also be a cheap addition.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@hardik4love-lang
hardik4love-lang force-pushed the fix/staged-tasks-uncompleted-dedup-sorting branch from 26a94ef to 8f39938 Compare October 31, 2026 04:07
@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: correct, well-scoped fix for #21875 — both defects are real and the patch addresses them with hermetic test coverage. No blocking issues; merge sign-off left to a human maintainer.

Verified on head 8f39938:

  • backend/database/staged_tasks.py — create_staged_task dedup now skips docs with completed=True. Correct: completed staged rows are terminal history (clear_staged_tasks deliberately preserves them), and the old code returned that terminal doc — which is invisible to get_staged_tasks (filters completed == False) and unpromotable via promote_staged_task (returns None on completed) — permanently blocking re-detection of the same task. The change also aligns create-time dedup with the active-only semantics used everywhere else in the module.
  • backend/database/staged_tasks.py — relevance_score now defaults to 0 on the created doc. Correct: get_staged_tasks, get_top_staged_task_for_promotion, and promote_staged_task all order_by('relevance_score'), and Firestore silently omits documents missing the ordered field, so scoreless staged tasks were dropped from listing and promotion selection. Moving relevance_score out of the kwargs loop avoids double-handling and is consistent.
  • backend/tests/unit/test_staged_tasks_dedup.py — both new tests are hermetic (MagicMock _user_col monkeypatch) and assert the right contracts, including that the persisted set() doc carries relevance_score=0 and that a completed row no longer satisfies dedup.

Nit (non-blocking): kwargs.get('relevance_score', 0) if kwargs.get('relevance_score') is not None else 0 has a dead ", 0" fallback — the else branch already covers the omitted/None cases; feel free to simplify on a future touch.

Performance: the dedup loop still streams the full subcollection (pre-existing O(n) scan); the added completed check is trivial.

USER IMPACT: staged tasks a user already completed or promoted no longer block the same task from being captured again later, and newly captured tasks without a relevance score are no longer silently hidden from the staged-task list.

Still wanted (non-blocking): rows created before this fix still lack relevance_score and remain invisible to the ordered queries — a small backfill (batch_update_staged_scores-style sweep) would be a good follow-up.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

create_staged_task still returns the first matching description, including a completed row, and it omits relevance_score unless the caller passes one. test_create_staged_task_ignores_completed_staged_task_in_dedup and test_create_staged_task_defaults_relevance_score_when_omitted pin both on 8f39938. Hygiene, Formatting, and the backend unit suite are green.

@Git-on-my-level
Git-on-my-level merged commit f5ff02b into BasedHardware:main Nov 8, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty Proposal] fix(staged_tasks): filter completed entities in creation dedup and default relevance_score for index sorting ($50 proposed)

3 participants