Repository navigation
Conversation
A pending Candidate stops being readable two days after it is created: every suggested-surface read runs `candidate_has_lapsed` and drops it. Candidate creation did not ask the same question. A semantic claim was reusable for 14 days on `created_at` alone, so from day 2 to day 14 a fresh capture of the same task merged its evidence into a Candidate the Suggested surface will never show, and the merge refreshes neither `created_at` nor `expires_at` — the proposal stays invisible for the rest of the window no matter how often the user mentions the task again. That is the shape INV-TASK-2 forbids: "Admit a proposal the Suggested surface will not show. A stored, invisible Candidate is a dropped one that also costs storage." It was recorded as a known gap when the two-day TTL landed in BasedHardware#11974 ("the 14-day candidate reuse window now outlives the 2-day suggestion TTL"). Reuse is now bounded by the suggestion's own life: a lapsed pending claim is not reused, so the next capture creates a fresh Candidate, repoints the semantic claim at it, and the user is offered the task again. A live claim still merges exactly as before, so repeated mentions inside the window do not multiply rows. `PENDING_CANDIDATE_REUSE_WINDOW` had no other reader and is gone rather than left to disagree with the TTL. Failure-Class: none
kodjima33
approved these changes
Aug 24, 2026
kodjima33
left a comment
Collaborator
There was a problem hiding this comment.
Backend bug fix: candidate reuse window (14d) outlived the suggestion TTL (2d), so a lapsed pending candidate silently swallowed the next capture for up to 12 days. Now bounded by candidate_has_lapsed. Tested, verified not on main. 5/5.
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.
What changed and why
A pending Candidate stops being readable two days after it is created: every suggested-surface read runs
candidate_has_lapsedand drops it. Candidate creation did not ask the same question — a semantic claim was reusable for 14 days oncreated_atalone (PENDING_CANDIDATE_REUSE_WINDOW), so from day 2 to day 14 a fresh capture of the same task merged into a Candidate the Suggested surface will never show. The merge refreshes neithercreated_atnorexpires_at, so the proposal stays invisible for the remaining twelve days however often the user mentions the task again; only after day 14 does a new Candidate get created.That is the shape INV-TASK-2 forbids: "Admit a proposal the Suggested surface will not show. A stored, invisible Candidate is a dropped one that also costs storage." It was recorded as a known gap when the two-day TTL landed in #11974 — "the 14-day candidate reuse window now outlives the 2-day suggestion TTL".
That note called the gap "dedup-vs-expiry semantics — a product call, not a defect", and closed it with "self-heals once TTL reaps the doc". Two things argue for treating it as a defect after all. First, nothing reaps the doc: the comment on
SUGGESTION_TTLin this same file states that a Firestore TTL policy cannot be declared through the repo's manifest, so "Expired Candidates therefore remain stored but unreadable". The row is never collected, and the only thing that ends the window is the 14-day reuse clock itself — so the self-healing arrives on day 15, not on day 3. Second, whatever the intended dedup semantics, the observable outcome is the one INV-TASK-2 names: from day 2 the user keeps mentioning a task and keeps being offered nothing, while a row that will never be shown absorbs each new capture. If the product call is that a semantic claim should survive its suggestion, the honest form of that is refreshingexpires_aton merge; what happens today is neither.This does not grow storage. The invisible row was already being written and kept — bounding reuse changes which row a later capture lands on, not how many rows exist; the "1,014 Candidates … growing by ~100/day" the invariant complains about is the population this fix makes visible again rather than one it adds to.
Reuse is now bounded by the suggestion's own life: a lapsed pending claim is not reused, so the next capture creates a fresh Candidate, repoints the semantic claim at it, and the user is offered the task again. A live claim still merges exactly as before, so repeated mentions inside the window do not multiply rows.
PENDING_CANDIDATE_REUSE_WINDOWhad no other reader and is removed rather than left to disagree with the TTL.A lapsed twin does not suppress the new Candidate on the read side:
_suggested_candidatessuppresses a semantic identity only via user dismissals (suppressed_dedupe_keys) or terminal accepted/rejected resolutions, and a lapsed pending row is neither.Product invariants affected
INV-TASK-2 — this is the "admit only proposals the user will actually see" clause, applied to Candidate reuse rather than to the confidence floor.
How it was verified
Reproduced against
upstream/mainat02c48d7da6with a new store-level test through the strict Firestore transaction fake: a capture at T, then the same task captured again at T + 2d 1h. Before the change the second capture returns the samecandidate_id, andcandidate_has_lapsedis true for it — the user is offered nothing:After the change the second capture is a new Candidate with a fresh
expires_at, and the pending claim points at it.python -m pytest tests/unit/test_candidate_lifecycle.py— 51 passed (49 before, +2 new).Candidate and task-intelligence suites:
test_candidate_lifecycle.py,test_conversation_suggestion_visibility.py,test_backend_candidate_capture.py,test_task_intelligence_contract_freeze.py,test_process_conversation_usage_context.py— 165 passed;test_candidates_router.py,test_candidates_skip_malformed.py,test_get_candidate_skip_malformed.py,test_staged_candidate_migration.py,test_staged_tasks_dedup.py,test_task_intelligence_rollout.py,test_task_intelligence_attribution.py— 123 passed..github/scripts/check_task_capture_authority.py—INV-TASK-2 holds (automatic capture proposes only).black --check backend/database/candidates.py backend/tests/unit/test_candidate_lifecycle.py— clean.scripts/pr-preflight --base upstream/main --pr-body-file <this body>— 26 checks passed in 200s, includingproduct-invariants,failure-class-protocol,firestore-query-coverage,backend-async-blockers,backend-import-purityandbackend-module-isolation.Not verified against a live Firestore project: the reuse path is exercised through the repo's strict transaction fake, the same harness the surrounding lifecycle tests use.
Tests
backend/tests/unit/test_candidate_lifecycle.py:test_a_lapsed_pending_claim_is_not_reused_for_a_later_capture— the regression test; red before the change with the assertion quoted above.test_a_live_pending_claim_is_still_reused_within_its_window— pins the other side, so the fix cannot turn into "stop deduplicating".test_fresh_high_confidence_capture_replaces_stale_low_confidence_pending_claimreferenced the removed constant; it now advances pastSUGGESTION_TTLinstead of past the 14-day window, which is the same thing it was proving.Failure class (fixes)
Failure-Class: none