fix(telemetry): persist ingress spans and ordinary request attempts - #1093
fix(telemetry): persist ingress spans and ordinary request attempts#1093yamashirotakashi wants to merge 1 commit into
Conversation
|
✅ Deterministic PR hygiene checks passed. |
📝 WalkthroughWalkthroughThe request pipeline now validates and propagates ingress spans through request logs and usage records. Ordinary Responses requests create durable attempt metadata. Persistence retains explicitly defined empty attempt arrays. ChangesIngress correlation and request attempts
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e0039ce969
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| logCtx.activeAttempt = attempt; | ||
| logCtx.activeAttemptStartedAt = Date.now(); | ||
| (logCtx.attempts ??= []).push(attempt); |
There was a problem hiding this comment.
Capture effort after constructing the ordinary attempt
For ordinary Cursor requests, applyRouteDependentNormalization calls recordAttemptRequestedEffort before this block assigns logCtx.activeAttempt. Cursor uses runTurn, so it never reaches a later recordAdapterReasoning call that would backfill the field, even though its request builder uses the selected effort to choose the wire model. Record the settled effort immediately after assigning the new attempt so persisted Cursor attempt telemetry includes requestedEffort.
Useful? React with 👍 / 👎.
| ); | ||
| logCtx.activeAttempt = attempt; | ||
| logCtx.activeAttemptStartedAt = Date.now(); | ||
| (logCtx.attempts ??= []).push(attempt); |
There was a problem hiding this comment.
Distinguish ordinary attempts from combo attempts
Once every ordinary request receives this non-empty attempts array, existing management consumers classify it as a combo solely from entry.attempts?.length; for example, src/server/management/shared.ts:112-115 now reports combo_attempt_unavailable for an unpriced ordinary custom-provider request. Update those consumers to detect an actual combo (such as by the top-level provider/metadata) before using combo-only diagnostics.
Useful? React with 👍 / 👎.
| logCtx.activeAttempt = attempt; | ||
| logCtx.activeAttemptStartedAt = Date.now(); | ||
| (logCtx.attempts ??= []).push(attempt); |
There was a problem hiding this comment.
Create attempts only when an upstream dispatch starts
When a request resolves the Kiro adapter but carries an unexpanded previous_response_id, the validation immediately below returns 400 without sending upstream; because this block has already pushed an attempt, the deferred finalizer persists a status-400 attempt with sendCount: 0. Later local-only rejections such as the image-bridge stream=true check have the same problem, so request history reports physical attempts that never occurred. Delay attempt creation until the selected dispatch path starts, or omit attempts whose send count remains zero.
Useful? React with 👍 / 👎.
⏳ DRAFT
What to do
Review readiness checklist
0/4 boxes ticked. This PR stays in draft until every box above is ticked. |
|
Retargeted this to The content is worth landing: ingress-span propagation and durable per-attempt records do not exist on Two things still stand between this and review:
One design question to answer in the description while you are in there: what happens to an ingress span that is well-formed but arrives on a request that never reaches adapter resolution? Your summary says exactly one attempt is created "after final initial adapter resolution," which reads correct, but the failure path before that point is where telemetry work usually leaks or double-counts, and a reviewer will look there first.
|
|
Thanks for retargeting — the branch is on Neither behavior exists on The blocker is a missing contract, not a missing test. The description says the change captures "only guard-issued" ingress spans. The code accepts any client-supplied header value matching a shape: const INGRESS_SPAN_RE = /^[A-Za-z0-9_-]{24}_[0-9a-f]{16}$/;
return INGRESS_SPAN_RE.test(span) ? span : undefined;A regex is a format check, not provenance. Nothing issues these values, nothing signs them, and nothing prevents a caller from sending any conforming string — including one chosen to collide with another caller's span. Once persisted into usage records and Three things needed before this can be reviewed on the merits:
Also still worth doing: rebase onto current For clarity — the None of the above is about code quality. The implementation is careful. It just needs someone to state what the data means before we start writing it down permanently. |
Summary
x-opencodex-ingress-spanvalues on ordinary Responses requests and carry them through request and usage logs.attempts: []while omitting malformed non-array values; reject malformed or secret-shaped ingress values.Scope
99440ecd91a951e5b580fdde843998d99181400aValidation
bun test tests/request-log.test.ts tests/usage-log.test.ts tests/server-auth.test.tsgit apply --checkagainst a clean pinned base: passedSecurity
Ingress values are accepted only in the positive issuer shape. Representative
gho_,github_pat_,Bearer, andsk-values are rejected. Logs persist correlation metadata only, never raw content or credentials.Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
All CI tests are green on my local testing.
I pushed my PR to the latest dev commit.
I fixed all correct Codex and CodeRabbit findings.
My PR is ready for review.
Summary by CodeRabbit
New Features
Bug Fixes