fix(telemetry): align client with unified contract, stop firing collection_completed on data arrival#98
Closed
fix(telemetry): align client with unified contract, stop firing collection_completed on data arrival#98
Conversation
…ction_completed on data arrival
Two fixes bundled because they touch the same files:
1. collection_completed no longer fires when data arrives
The export-complete handler was calling markCollectionCompleted whenever
the connector emitted data via setData('result'). For multi-step
connectors that stream partial results, this marked the run as complete
mid-execution — the UI showed success while the connector was still
running, and the COMPLETE status event that fired later was deduped away.
The fix splits responsibilities:
- connector-status COMPLETE is the authoritative terminal signal. It
fires when the connector process exits and is the only place
markCollectionCompleted gets called during a connector run.
- export-complete now handles persistence only. It continues to write
data to the personal server when it arrives, without touching run
status or telemetry.
persistedRunIds dedupes across both paths so simple connectors that
attach data to the COMPLETE payload still persist correctly.
2. Align contract types with the server
Updates src/lib/telemetry/contracts.ts to match the unified contract
at https://github.com/vana-com/context-gateway/blob/main/packages/contracts/src/telemetry.ts
Notable changes:
- Added grant_flow_started and grant_flow_expired to the event name list
- Removed needs_input from the error class whitelist; use
abandoned_waiting_for_input for real timeouts
- Removed the outcome field (rollups use eventName + errorClass, never
a free-form string)
- Added detail (free-form debugging) and recordCount fields
- Added trackGrantFlowStarted and trackGrantFlowExpired helpers
- trackCollectionNeedsInput no longer sets errorClass (it's intermediate,
not a failure); added optional interactionKind metadata
See TELEMETRY.md in context-gateway for the state machine, outcome
priority rules, and migration notes.
Member
Author
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
Two fixes bundled because they touch the same files:
1.
collection_completedno longer fires when data arrives (real bug)The
export-completehandler inuseEvents.tswas callingmarkCollectionCompletedwhenever the connector emitted data viasetData('result'). For multi-step connectors that stream partial results (e.g., ChatGPT), this marked the run as complete mid-execution — the UI showed success while the connector was still running, and theCOMPLETEstatus event that fired later was deduped away.Fix: Split responsibilities cleanly.
connector-status: COMPLETEis the authoritative terminal signal. It fires when the connector process exits and is the only placemarkCollectionCompletedgets called during a connector run.export-completenow handles persistence only. It continues to write data to the personal server when it arrives, without touching run status or telemetry.persistedRunIdsdedupes across both paths so simple connectors that attach data to theCOMPLETEpayload still persist correctly.This matches the state machine described in the new telemetry contract (see context-gateway PR).
2. Align contract types with the server
Updates
src/lib/telemetry/contracts.tsto match the unified contract in the server.Source of truth: https://github.com/vana-com/context-gateway/blob/main/packages/contracts/src/telemetry.ts
Because
@opendatalabs/contractscan't be published to npm (private repo, no license), the types are copied with a header comment pointing at the source. When the server contract changes, this file must be updated to match. The server validates events against its own copy — a mismatch will cause events from this client to be rejected.Notable contract changes
grant_flow_startedandgrant_flow_expiredto the event name listneeds_inputfrom the error class whitelist; useabandoned_waiting_for_inputfor real timeoutsoutcomefield (rollups useeventName+errorClass, never a free-form string)detail(free-form debugging context) andrecordCountfieldstrackGrantFlowStartedandtrackGrantFlowExpiredhelperstrackCollectionNeedsInputno longer setserrorClass(it's intermediate, not a failure); added optionalinteractionKindmetadataTest plan
tsc -b --noEmitpasses (only unrelated errors from missing@tauri-apps/plugin-updatertype deps)needsInput: trueon the telemetry rollupexport-completefiresDepends on