✨ feat: propagate canonical request IDs through capture - #307
Conversation
|
| Filename | Overview |
|---|---|
| api/request_id_middleware.go | Adds outermost request-ID middleware, but permissive UUID parsing does not enforce its asserted canonical UUIDv4 contract. |
| ingest/ingest.go | Separately bounds Paper and provider identifiers before carrying them into asynchronous worker metadata. |
| pkg/logger/request.go | Adds context accessors and structured logger construction that keep canonical and provider-issued IDs distinct. |
| proxy/worker/pool.go | Restores correlation metadata in worker contexts and includes it in worker logs and raw-turn metadata. |
Sequence Diagram
sequenceDiagram
participant Client
participant API
participant ExtProc
participant Ingest
participant Worker
participant Storage
Client->>API: Request with optional X-Request-Id
API->>API: Validate or generate request_id
API-->>Client: X-Request-Id
ExtProc->>Ingest: Turn with request_id and upstream_request_id
Ingest->>Ingest: Bound worker correlation fields
Ingest->>Worker: Enqueue job metadata
Worker->>Worker: Restore context and scoped logger
Worker->>Storage: Correlated storage operations
Prompt To Fix All With AI
### Issue 1
api/request_id_middleware.go:32-39
**Noncanonical UUIDs pass validation**
When a caller supplies a parseable UUID that is not a canonical hyphenated UUIDv4, `canonicalRequestID` preserves it in the response header, request context, and logs, causing downstream correlation to receive an identifier outside the middleware's asserted UUIDv4 format.
```suggestion
func canonicalRequestID(candidate string) string {
if len(candidate) <= maxRequestIDTextBytes {
if parsed, err := uuid.Parse(candidate); err == nil &&
parsed.Version() == uuid.Version(4) && parsed.String() == candidate {
return candidate
}
}
return uuid.NewString()
}
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "✨ feat(ingest): preserve request IDs acr..." | Re-trigger Greptile
| func canonicalRequestID(candidate string) string { | ||
| if len(candidate) <= maxRequestIDTextBytes { | ||
| if _, err := uuid.Parse(candidate); err == nil { | ||
| return candidate | ||
| } | ||
| } | ||
| return uuid.NewString() | ||
| } |
There was a problem hiding this comment.
Noncanonical UUIDs pass validation
When a caller supplies a parseable UUID that is not a canonical hyphenated UUIDv4, canonicalRequestID preserves it in the response header, request context, and logs, causing downstream correlation to receive an identifier outside the middleware's asserted UUIDv4 format.
| func canonicalRequestID(candidate string) string { | |
| if len(candidate) <= maxRequestIDTextBytes { | |
| if _, err := uuid.Parse(candidate); err == nil { | |
| return candidate | |
| } | |
| } | |
| return uuid.NewString() | |
| } | |
| func canonicalRequestID(candidate string) string { | |
| if len(candidate) <= maxRequestIDTextBytes { | |
| if parsed, err := uuid.Parse(candidate); err == nil && | |
| parsed.Version() == uuid.Version(4) && parsed.String() == candidate { | |
| return candidate | |
| } | |
| } | |
| return uuid.NewString() | |
| } |
Knowledge Base Used: API server (api/)
Prompt To Fix With AI
This is a comment left during a code review.
Path: api/request_id_middleware.go
Line: 32-39
Comment:
**Noncanonical UUIDs pass validation**
When a caller supplies a parseable UUID that is not a canonical hyphenated UUIDv4, `canonicalRequestID` preserves it in the response header, request context, and logs, causing downstream correlation to receive an identifier outside the middleware's asserted UUIDv4 format.
```suggestion
func canonicalRequestID(candidate string) string {
if len(candidate) <= maxRequestIDTextBytes {
if parsed, err := uuid.Parse(candidate); err == nil &&
parsed.Version() == uuid.Version(4) && parsed.String() == candidate {
return candidate
}
}
return uuid.NewString()
}
```
**Knowledge Base Used:** [API server (api/)](https://app.greptile.com/paper-compute/-/custom-context/knowledge-base/papercomputeco/tapes/-/docs/api-server.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.21d1591 to
1a99cba
Compare
1a99cba to
d1f525e
Compare
Summary
request_idand providerupstream_request_idmetadata independently across asynchronous ingest and worker execution.How it works
The API establishes request-scoped correlation before handlers run. Ingest copies the Paper and provider identifiers into bounded job metadata, and workers restore both fields into their context and structured logger without allowing the provider ID to replace the Paper ID.
Test plan
Fixes PCC-1177