Skip to content

fix(firestore-translate-text): emit start and completion events on every write - #3149

Merged
cabljac merged 1 commit into
kitsfrom
fix/kits-translate-text-events
Sep 8, 2026
Merged

fix(firestore-translate-text): emit start and completion events on every write#3149
cabljac merged 1 commit into
kitsfrom
fix/kits-translate-text-events

Conversation

@cabljac

@cabljac cabljac commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

The kit's handleDocumentWrite returned before recording anything when a gen2 write event arrived without change data, so that invocation published neither onStart nor onCompletion. The extension's fstranslate is a gen1 onWrite with no such path: every call publishes onStart first and onCompletion last, and each early return records completion on its way out.

The guard now runs after logs.start and recordStartEvent, and records onCompletion before returning, so the no-data path matches the other no-op branches (delete, unchanged input, missing input). The onStart payload carries { data: undefined, params } there. The payload shape itself is untouched; restoring the extension's { change, context } shape is PR #3098.

I compared every branch of the two handlers. Field-name checks, create, delete, the three update branches, the per-document translation-path return, and the error paths already published the same events in the same order (onSuccess only from updateTranslations, one onError per layer before onCompletion). The one remaining difference is that the kit awaits the handler-level onError where the extension does not; that only changes what happens when the publish itself rejects, so I left it alone.

A new lifecycle events block pins the exact event sequence for each branch, and the existing no-data test now asserts the pair is published. 112 tests and tsc --noEmit pass. No live deploy or Eventarc subscription was exercised.

Fixes #3020

…ery write

`handleDocumentWrite` returned before recording anything when the gen2
event arrived with no change data, so neither `onStart` nor
`onCompletion` was published for that invocation. The extension's
`fstranslate` is a gen1 `onWrite` and has no such path: every call
publishes `onStart` first and `onCompletion` last, with each early
return recording completion before it leaves.

The guard now sits after `logs.start` and `recordStartEvent`, and
records `onCompletion` before returning, so the no-data path behaves
like the other no-op branches (delete, unchanged input, missing input).
`onStart` carries `{ data: undefined, params }` there; the payload shape
itself is unchanged and is being restored to the extension's
`{ change, context }` separately.

Every other branch already matched the extension: `onSuccess` comes only
from `updateTranslations`, and a translator failure records one
`onError` per layer (translator, `translateSingle`, handler) before
`onCompletion`. Those sequences are now pinned by a `lifecycle events`
block that asserts the exact event order for each branch, so a future
early return cannot drop the pair unnoticed. 112 tests and
`tsc --noEmit` pass. No live deploy was run.

Fixes #3020
Parity ledger: #2974, firestore-translate-text.
@cabljac cabljac mentioned this pull request Sep 8, 2026
69 tasks

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that onStart and onCompletion lifecycle events are published on every invocation of the fstranslate extension, including early-return paths where write events arrive without change data. This is achieved by moving the start event recording before the check for event.data and recording a completion event prior to returning early. Additionally, the test suite has been updated and expanded with comprehensive lifecycle event sequence assertions. There are no review comments to address, and I have no additional feedback to provide.

@IzaakGough IzaakGough left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

@cabljac
cabljac merged commit 8af35a2 into kits Sep 8, 2026
11 of 12 checks passed
@cabljac
cabljac deleted the fix/kits-translate-text-events branch September 8, 2026 14:19
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.

2 participants