feat: add AIConfigTracker, metrics & resumption tokens (AIC-2664)#174
Open
ctawiah wants to merge 1 commit into
Open
feat: add AIConfigTracker, metrics & resumption tokens (AIC-2664)#174ctawiah wants to merge 1 commit into
ctawiah wants to merge 1 commit into
Conversation
…IC-2664) Implements the AITRACK surface on LDAIConfigTracker: per-run UUID runId and track data, the full set of track methods (duration, time-to-first-token, success/error, feedback, tokens, tool calls, judge result) plus trackDurationOf and trackMetricsOf wrappers, and a metric summary. Record-once metrics use atomic claim-before-emit guards so exactly one event is produced under concurrency; tool-call and judge-result events are not once-only. Negative durations and token counts are clamped, and a null judge score is distinct from a legitimate 0.0. Resumption tokens are URL-safe Base64 of canonical JSON in fixed key order (runId, configKey, variationKey, version, graphKey); variationKey is always emitted for cross-SDK parity and modelName/providerName are not carried. Decode strictly type-validates each field and rejects malformed/oversized tokens. LDAIClientImpl now wires createTracker() on the config types to the real tracker and adds createTracker(token, context) to reconstruct a run across processes. Co-authored-by: Cursor <cursoragent@cursor.com>
3 tasks
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.
Requirements
Related issues
AIC-2664 — Step 4: AITRACK. Stacked on #173 (Step 3).
Describe the solution you've provided
Implements the AITRACK surface to spec, thread-safe by construction:
LDAIConfigTrackergains the full method set:trackDuration,trackTimeToFirstToken,trackSuccess/trackError,trackFeedback,trackTokens,trackToolCall(s),trackJudgeResult, plus thetrackDurationOfandtrackMetricsOfwrappers,getTrackData(),getResumptionToken(), andgetSummary(). Event names match the spec and the JS/Python SDKs.LDAIConfigTrackerImpl(internal): per-run UUIDrunId; record-once metrics use atomic claim-before-emit (AtomicBoolean) so exactly one event is emitted under concurrency (trackSuccess/trackErrorshare one guard). Tool-call and judge-result events are not once-only; tool calls accumulate in aCopyOnWriteArrayListandgetSummary().getToolCalls()returns an immutable snapshot.0.0.trackMetricsOfrecords an error and rethrows on both operation and extractor failures.ResumptionTokens): URL-safe Base64 (no padding) of canonical JSON in fixed key orderrunId, configKey, variationKey, version, graphKey.variationKeyis always emitted for cross-SDK parity;modelName/providerNameare not carried (restored trackers report""). Decoding strictly type-validates each field and rejects malformed or oversized (>4 KB) tokens.LDAIClientImplnow produces real trackers fromcreateTracker()(a freshrunIdper call) and addsLDAIClient.createTracker(token, context)to reconstruct a run across process boundaries. The placeholderNoOpAIConfigTrackeris removed.LDAITrackingTypes(mirroring theLDAIConfigTypespattern).Tests
trackMetricsOfrethrow + error, summary, and concurrency (N threads → exactly one once-only event, intact tool-call list).runId, eachcreateTracker()starts a new run.Out of scope (per ticket)
No Judge/Evaluator (Step 5), no AIGRAPH
createGraphTracker, no provider-specifictrackOpenAIMetrics/trackBedrockMetrics(post-1.0).Made with Cursor
Note
Medium Risk
New public API surface and telemetry behavior on every AI config evaluation; resumption token parsing handles untrusted input with size limits and strict validation.
Overview
Replaces the placeholder no-op
LDAIConfigTrackerwith a full AITRACK implementation that emits AI run metrics throughLDClient.trackMetric, keyed by a per-runrunId.LDAIConfigTrackeris expanded from a stub to the full API: duration, time-to-first-token, success/error, feedback, tokens, tool calls, judge results,trackDurationOf/trackMetricsOf,getTrackData(),getResumptionToken(), andgetSummary().LDAITrackingTypesadds the public value types (TokenUsage,Metrics,JudgeResult, etc.).LDAIConfigTrackerImplsends spec-aligned$ld:ai:*events with shared correlation fields; record-once metrics use atomic guards for thread safety.ResumptionTokensencodes/decodes cross-process resumption (cross-SDK byte fixtures in tests).LDAIClientImplwires real trackers (new UUID percreateTracker()on configs) and addsLDAIClient.createTracker(token, context)for deferred events;NoOpAIConfigTrackeris removed.Reviewed by Cursor Bugbot for commit 19d0f4f. Bugbot is set up for automated code reviews on this repo. Configure here.