Skip to content

fix(httptransport): record client cancellations as 499 - #5236

Merged
turip merged 2 commits into
mainfrom
feat/client-cancel-499
Oct 2, 2026
Merged

turip merged 2 commits into
mainfrom
feat/client-cancel-499

Conversation

@turip

@turip turip commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Summary

  • record wrapped context.Canceled errors as 499 Client Closed Request
  • avoid passing caller cancellations through generic error encoders, so no error response body is written
  • preserve error-handler reporting for cancellation logs
  • cover cancellations returned by request decoding and operation execution

Validation

  • go test ./pkg/framework/transport/httptransport
  • make lint-go-fast GO_LINT_PATH=./pkg/framework/transport/httptransport/...

Summary by CodeRabbit

  • Bug Fixes
    • Requests now receive HTTP status 499 and an empty response body when cancellation occurs during request decoding or operation processing and the request context is also canceled.
    • Operation cancellation without a canceled request context continues to follow the existing error-response flow.

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no new actionable issue was identified.

Summary

The PR records decoder and operation cancellations as empty 499 responses only when the HTTP request context is also canceled.

  • It inlines one-use test helpers and adds coverage for an internal cancellation while the request remains active.

Reviews (2) · Last reviewed commit: "fix(httptransport): distinguish request ..."

@turip
turip requested a review from a team as a code owner October 2, 2026 11:58
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openmeterio/openmeter/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: ee369915-21ee-4f91-a60f-fb324bc4fb22

📥 Commits

Reviewing files that changed from the base of the PR and between 730b0c8 and b58d03f.

📒 Files selected for processing (2)
  • pkg/framework/transport/httptransport/handler.go
  • pkg/framework/transport/httptransport/handler_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The HTTP handler now routes request-decoding and operation errors through shared handling. When both the error and request context are canceled, it returns status 499 and reports the error without encoding a response. Other errors use the existing encoding flow.

Changes

HTTP cancellation handling

Layer / File(s) Summary
Cancellation-aware HTTP error handling
pkg/framework/transport/httptransport/handler.go, pkg/framework/transport/httptransport/handler_test.go
Both error paths use shared handling. When the error and request context are canceled, the handler returns status 499, reports the error, and skips response encoding. Tests also cover operation cancellation with an uncanceled request context, which returns status 408.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: gergely-kurucz-konghq

Merge Risk: ⚪ Minimal · up to b58d0

The cancellation handling appears ready to merge after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to b58d0

The change is narrowly scoped and preserves cancellation reporting. Internal cancellation of an active request retains normal error handling. Remaining uncertainty concerns whether upstream code can cancel the request context for reasons other than client disconnection; no introduced security vulnerability was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated effect is per-request response classification and diagnostic reporting for callers of the generic handler. The changed path introduces no new identity or privilege transition; repository-wide endpoint and tenant exposure is not established by the available caller evidence.

Trust Boundaries and Controls

  • observed — Generic error encoders are intentionally skipped only by the dual-cancellation branch, while the configured error handler still receives the error. Nonmatching failures retain encoder dispatch, self-encoding support, and the fallback internal-server-error response.

Resilience and Maintainability Implications

  • observed — The canceled-request tests exercise both decoding and operation failures and verify a bodyless 499, preserved error reporting, and suppression of response encoding. These establish the tested terminal behavior, not concurrent callback safety or upstream cancellation ownership.

Hardening Proposals

  • proposed — If upstream code uses request-context cancellation for server-initiated decisions, define whether those cancellations should receive 499. Where client-disconnect attribution matters, preserve cancellation provenance rather than treating context.Canceled as confirmation of peer closure.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: recording client cancellations as HTTP 499 responses in httptransport.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@turip turip added the release-note/bug-fix Release note: Bug Fixes label Oct 2, 2026
@turip
turip merged commit 03e86ef into main Oct 2, 2026
@turip
turip deleted the feat/client-cancel-499 branch October 2, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants