Skip to content

fix(tasks): persist shared-task copies before delivery - #19436

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
aryanorastar:codex/shared-task-acceptance-atomic
Sep 27, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
aryanorastar:codex/shared-task-acceptance-atomic

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #19433.

Accepting several shared tasks could permanently save only the first few. The route claimed the share in Redis, then read, saved, indexed, and scheduled a reminder for each task individually. Once one task was saved, a later failure left the claim consumed: the endpoint failed and every retry returned 409, stranding the missing tasks.

This change prepares all eligible copies first and uses the existing create_action_items_batch Firestore transaction. Indexing, reminders, and Chat-first wake-up follow the complete database write. It retains the current maximum of 20 shared tasks, account-generation fence, provenance, duplicate-accept behavior, and response schema.

No new database schema, retry service, receipt protocol, dependency, or mobile/hardware change.

Evidence

On unchanged main (ee071b242a), three behavioral regressions fail against the real HTTP route, Firestore SDK, and local Firestore emulator:

  1. A failure writing the second task leaves the first task committed.
  2. A failure reading the second source task during copying leaves the first copy committed.
  3. A failure delivering the first reminder prevents the second task from being saved.

After the change, all four emulator tests pass: failed preparation/writes leave zero copies and can retry both tasks; a delivery failure cannot lose later canonical tasks; concurrent accepts yield one complete copy set (200 + 409) with the correct generation/provenance.

firebase emulators:exec --only firestore --project demo-task-sharing \
  'PYTHONPATH=backend backend/.venv/bin/pytest -q backend/tests/integration/test_shared_task_acceptance_atomic_emulator.py'

The emulator proof is an explicitly run integration suite, not part of the default unit selector. Default CI regression coverage lives in the existing test_shared_action_items.py suite: no writes before all source reads, one batch for 20 tasks, no delivery before persistence, rollback on pre-commit failure, locked/deleted races, metadata alignment after filtering, and no duplicate acceptance release after delivery failure. Existing sharing tests are migrated to the batch database boundary, not deleted or weakened.

Verification

  • 130 focused unit tests passed through the file-isolated backend/test.sh runner: test_shared_action_items, test_task_sharing, test_action_item_idempotency, test_action_item_canonical_contract, test_action_item_reminder_cancel_on_complete, test_action_item_vector_best_effort, test_workstream_core, and test_workstream_router_contract.
  • bash backend/scripts/typecheck.sh: 0 errors; existing warnings remain.
  • Uvicorn + curl against the real route and local Firestore emulator on 127.0.0.1:10274: injected write failure → HTTP 500, 0 persisted tasks; retry → HTTP 200, 2 tasks; duplicate accept → HTTP 409, still 2 tasks. Both local servers were stopped afterward.
  • OMI_PR_BODY_FILE=/tmp/omi-19433-pr-body.md make preflight: 31 checks passed. The history-based guard reported its existing shallow-clone skip; this is not a claim that the skipped guard ran.
  • The normal bounded pre-push gate passed on commit e65e0cddc7, including type-checking. Full GitHub CI is a separate check.

All records are synthetic, Redis and external delivery are local substitutes, authentication is a test dependency override, and outbound Python network calls are blocked. No production request, account modification, real reminder, or physical device claim.

Scope and limitations

This fixes partial-copy failures, not the complete Redis/Firestore acceptance lifecycle. Process death after the Redis claim, ambiguous Firestore commit outcomes, and historical partial accepts remain separate recovery limitations. Delivery failure can still surface an error after saving tasks; this PR ensures it cannot prevent later tasks from being persisted. It does not add a durable delivery outbox or promise notification retries.

#18719 adds claim/provenance assertions; it does not fix production persistence. Its individual-create mocks will need migrating to the batch call if this lands first. #19409 concerns desktop share attribution, not copying.

Why not a new guard or coordinator? The shared transaction primitive already exists. This route now uses it instead of constructing a multi-commit copy loop. Behavioral tests execute the route, and the emulator verifies actual rollback rather than relying on a lenient transaction fake.

Product invariants affected

none — preserves existing task creation, sharing, and account-generation semantics.

Failure-Class: FC-durable-record-gated-on-delivery-reachability

Line-Count-Exception: backend/routers/action_items.py | 1130 -> 1135 | Prepare the whole share before the existing atomic batch write and defer delivery until all copies are durable; five net lines avoid partial-copy loss without introducing a new persistence path.

Review in cubic

Resolve eligible copies before one atomic Firestore transaction so a later source-read, write, or delivery failure cannot strand a partially accepted share. Add unit and real-emulator regressions.

Failure-Class: FC-durable-record-gated-on-delivery-reachability

@kodjima33 kodjima33 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.

Confidence 5/5: fixes #19433 (partial-save on multi-task share accept), scoped diff, CI green, emulator+unit tests added. Verified bug (per-item loop, not batch) still present on main.

@kodjima33
kodjima33 merged commit f918330 into BasedHardware:main Sep 27, 2026
44 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.

Shared-task acceptance can permanently lose later tasks after a partial failure

2 participants