Skip to content

fix(envoy-client): complete command and request lifecycles#4801

Closed
NathanFlurry wants to merge 1 commit intobreak-up/serialize-gateway-actor-keysfrom
engine-stabilize/envoy-client-lifecycle
Closed

fix(envoy-client): complete command and request lifecycles#4801
NathanFlurry wants to merge 1 commit intobreak-up/serialize-gateway-actor-keysfrom
engine-stabilize/envoy-client-lifecycle

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 27, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude Bot commented Apr 27, 2026

Overview

This PR fixes a silent failure in handle_req_start: when the actors fetch callback returns Err, the request lifecycle was left incomplete -- no response was ever sent back to the gateway, leaving the client hanging. The fix adds send_fetch_error_response to send a proper 500 error response in the error branch.

This is a correct and necessary fix. A few observations below.


Issues

1. Missing content-type: application/json header

The response body is JSON, but no content-type header is set. Clients that inspect the content-type before parsing the body (e.g., SDKs, error middleware) will not know to decode it as JSON.

Compare to test-envoy/src/behaviors.rs:75, which sets content-type: application/json for JSON responses, and tunnel.rs::send_error_response (~line 274), which intentionally sends a plain-text body without one.

Suggested addition in send_fetch_error_response:

headers.insert("content-type".to_string(), "application/json".to_string());

2. JSON body format does not match canonical RivetError structure

CLAUDE.md mandates: Errors use universal RivetError (group/code/message/metadata) at all boundaries.

The emitted body uses a flat code field that bundles group and code together (envoy_fetch_failed), rather than the canonical separate group + code fields. The x-rivet-error header correctly uses envoy.fetch_failed (dot-notation group.code), so the JSON body should match that same structure. Without group, clients using the canonical RivetError decoder will either fail to parse or silently fall through to unstructured error handling.

Suggested body format: group="envoy", code="fetch_failed", message="actor fetch failed"

3. HTTP status 500 vs 502

500 is defensible (actor runtime error), but 502 Bad Gateway is more semantically accurate since the envoy is acting as a reverse proxy and the upstream (the actor fetch handler) failed. Worth a deliberate choice either way. For reference, tunnel.rs uses 503 for the analogous "actor not found" path.


Minor Notes

  • No tests cover the fetch-error path. The existing mod tests harness looks well-suited to add a case asserting a 500 is returned when the fetch callback errors.
  • PR description is blank (understood given the Draft status).

Summary

The core fix is correct and necessary -- completing the request lifecycle on error prevents client hangs. Two items to address before merging:

  1. Add content-type: application/json to the error response headers.
  2. Align the JSON body to the canonical RivetError shape with separate group and code fields.

@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-protocol-version branch from 1303d27 to f025e6a Compare April 27, 2026 07:30
@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-client-lifecycle branch from cf29c73 to 2cdf843 Compare April 27, 2026 07:31
@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-protocol-version branch from f025e6a to c546b5e Compare April 27, 2026 08:31
@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-client-lifecycle branch from 2cdf843 to 415545d Compare April 27, 2026 08:31
@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-protocol-version branch from c546b5e to a1f99bc Compare April 27, 2026 17:35
@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-client-lifecycle branch from 415545d to 8801509 Compare April 27, 2026 17:35
@NathanFlurry NathanFlurry changed the base branch from engine-stabilize/envoy-protocol-version to graphite-base/4801 April 27, 2026 19:30
@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-client-lifecycle branch from 8801509 to 31dfe70 Compare April 27, 2026 19:30
@NathanFlurry NathanFlurry changed the base branch from graphite-base/4801 to break-up/serialize-gateway-actor-keys April 27, 2026 19:31
@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-client-lifecycle branch from 31dfe70 to 45f80a0 Compare April 27, 2026 19:40
@NathanFlurry NathanFlurry force-pushed the break-up/serialize-gateway-actor-keys branch from 4d01526 to 2f550f5 Compare April 27, 2026 19:40
@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-client-lifecycle branch from 45f80a0 to 3dbc40f Compare April 27, 2026 20:48
@NathanFlurry NathanFlurry force-pushed the break-up/serialize-gateway-actor-keys branch from 2f550f5 to 2eeb6ed Compare April 27, 2026 20:48
@NathanFlurry NathanFlurry marked this pull request as ready for review April 27, 2026 20:49
@NathanFlurry NathanFlurry force-pushed the break-up/serialize-gateway-actor-keys branch from 2eeb6ed to 5ae4b51 Compare April 27, 2026 21:29
@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-client-lifecycle branch from 3dbc40f to 1cd5bb4 Compare April 27, 2026 21:29
@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-client-lifecycle branch from 1cd5bb4 to d5c12d7 Compare April 27, 2026 21:38
@NathanFlurry NathanFlurry force-pushed the break-up/serialize-gateway-actor-keys branch from 22ba82f to 0a6afdc Compare April 27, 2026 22:03
@NathanFlurry NathanFlurry force-pushed the engine-stabilize/envoy-client-lifecycle branch from d5c12d7 to 436dba7 Compare April 27, 2026 22:03
@NathanFlurry
Copy link
Copy Markdown
Member Author

Landed in main via stack-merge fast-forward push. Commits are in main; closing to match.

@github-actions
Copy link
Copy Markdown
Contributor

Preview packages published to npm

Install with:

npm install rivetkit@pr-4801

All packages published as 0.0.0-pr.4801.1822679 with tag pr-4801.

Engine binary is shipped via @rivetkit/engine-cli on linux-x64-musl, linux-arm64-musl, darwin-x64, and darwin-arm64. Windows users should use the release installer or set RIVET_ENGINE_BINARY.

Docker images:

docker pull rivetdev/engine:slim-1822679
docker pull rivetdev/engine:full-1822679
Individual packages
npm install rivetkit@pr-4801
npm install @rivetkit/react@pr-4801
npm install @rivetkit/rivetkit-napi@pr-4801
npm install @rivetkit/workflow-engine@pr-4801

1 similar comment
@github-actions
Copy link
Copy Markdown
Contributor

Preview packages published to npm

Install with:

npm install rivetkit@pr-4801

All packages published as 0.0.0-pr.4801.1822679 with tag pr-4801.

Engine binary is shipped via @rivetkit/engine-cli on linux-x64-musl, linux-arm64-musl, darwin-x64, and darwin-arm64. Windows users should use the release installer or set RIVET_ENGINE_BINARY.

Docker images:

docker pull rivetdev/engine:slim-1822679
docker pull rivetdev/engine:full-1822679
Individual packages
npm install rivetkit@pr-4801
npm install @rivetkit/react@pr-4801
npm install @rivetkit/rivetkit-napi@pr-4801
npm install @rivetkit/workflow-engine@pr-4801

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant