Skip to content

fix(rpcsmartrouter): send the request's lava-* headers when the router refuses it before asking any provider (MAG-5076) - #755

Open
avitenzer wants to merge 1 commit into
mainfrom
fix/MAG-5076-refused-before-dispatch-headers
Open

avitenzer wants to merge 1 commit into
mainfrom
fix/MAG-5076-refused-before-dispatch-headers

Conversation

@avitenzer

Copy link
Copy Markdown
Contributor

Jira ticket: MAG-5076

What changes

A request the router ends before asking any provider now carries the request's own headers:

  • a lava-select-provider pin on a provider the router cannot use (blocked, out of rotation, without the add-on, a backup), plain or strict: the 500 Selected provider not available;
  • a router with no provider to ask: No pairings available.;
  • a deadline before the first dispatch.

These replies carried no lava-* header at all. The guid was only in the body, and lava-user-request-type was lost. They now carry Lava-Guid, lava-user-request-type, Lava-Relay-Timeout-Applied (when lava-relay-timeout was sent), Lava-Extension-Unavailable, and the stateful and debug headers. There is still no Lava-Provider-Address and no Lava-Retries: no attempt went out.

Only headers change. Every interface sends the same status and body as before. The 400 for a pin name the router does not have (#725) already had Lava-Guid; it now carries the rest too. gRPC gets them as trailers. WebSocket is unchanged.

Why

The rulebook decides it: Part I §1 says Lava-Guid goes on every reply over HTTP and gRPC, and Part IV §4 row 18 lists the pinned case under this ticket. That answers the ticket's open question about a refusal made before dispatch.

How

SendParsedRelay returned nil for these before appendHeadersToRelayResult ran, the same shape #671 fixed for budget expiry. It now returns a result that carries only those headers. The listeners only pass a result's headers on along this path, so status and body cannot move.

A cross-validated request is left out. Its pre-dispatch failures have their own reply (crossValidationFailFast), and the header builder would count a round that never ran.

Side effect: smartrouter_consistency_total / _failed_total now count these requests as failed. They already count every failed reply the header builder sees.

Not breaking

Headers are added to a reply that had none; no value changes. #671 did the same without !.

Docs follow-up: docs/api/directives.md and backup.md still say a request that reached no node carries no Lava-* headers. That is fixed in a docs PR stacked on docs#105, which rewrites the same lines.

Tests

  • TestFailedRelayReply_ARequestRefusedBeforeDispatchKeepsTheRequestHeaders_MAG5076: a plain pin, a strict pin and a router with no provider, through the JSON-RPC, REST, Tendermint RPC and GraphQL listeners. On main all 12 cases fail with "the reply carries no Lava-Guid".
  • TestGRPCListener_ARefusedPinCarriesTheRequestHeaders_MAG5076: both gRPC refusals (InvalidArgument and the provider-unavailable error). Both fail on main.
  • TestSelectProvider_ANameTheRouterDoesNotHaveIsRefusedWith400: now also requires lava-user-request-type on the 400, and the headers on the configured-but-unusable 500.
  • TestSendParsedRelay_ExpiredBeforeWriteDispatch pinned the header-less reply (require.Nil(result)). It now requires a result with the request type and no status.
  • go test over rpcsmartrouter, chainlib, routersession and relaycore passes. The new tests pass 5 of 5 under -race. go vet ./... and golangci-lint --new-from-rev are clean.

Automation

test_a_pin_on_a_provider_in_no_pool_carries_the_request_headers still carries the closed ticket's marker, and its arrangement predates #725. Its pin no-such-provider is now the 400 Selected provider is not configured, so its precondition (500, Selected provider not available) fails as soon as #725 deploys. Once this PR deploys, both headers are present on that 400 and on the provider-unavailable 500. The test needs a configured provider the router cannot use (for example a backup) and its marker removed.

🤖 Generated with Claude Code

…r refuses it before asking any provider (MAG-5076)

A request the router ended before it dispatched anything got the router's error with no lava-*
header at all. That covers a lava-select-provider pin on a provider the router cannot use (blocked,
out of rotation, without the add-on, a backup), plain or strict, answered 500 "Selected provider
not available"; a router with no provider to ask ("No pairings available."); and a deadline before
the first dispatch. The guid was only in the body and lava-user-request-type was lost. Part I §1
of the error rulebook puts Lava-Guid on every reply over HTTP and gRPC; Part IV §4 row 18 lists
the pinned case under MAG-5076.

SendParsedRelay returned nil for these, before appendHeadersToRelayResult ran. It now returns a
result that carries only the request's headers: Lava-Guid, lava-user-request-type,
Lava-Relay-Timeout-Applied when lava-relay-timeout was sent, Lava-Extension-Unavailable, and the
stateful and debug headers. No attempt went out, so there is no Lava-Provider-Address and no
Lava-Retries. Every listener sends the status and body it sent before: on this path the HTTP
listeners only pass the result's headers on, and gRPC sends them as trailers. The 400 for a pin
name the router does not have (MAG-3800) already carried Lava-Guid; it now carries the rest too.
WebSocket is unchanged.

A cross-validated request is left out: its pre-dispatch failures have their own reply
(crossValidationFailFast), and the header builder would count a round that never ran.

smartrouter_consistency_total and _failed_total now count these requests as failed, as they count
every failed reply the header builder sees.

Verified: TestFailedRelayReply_ARequestRefusedBeforeDispatchKeepsTheRequestHeaders_MAG5076 sends a
plain pin, a strict pin and a request to a router with no provider through the JSON-RPC, REST,
Tendermint RPC and GraphQL listeners; on main all 12 cases fail with "the reply carries no
Lava-Guid". TestGRPCListener_ARefusedPinCarriesTheRequestHeaders_MAG5076 does the same for both gRPC
refusals. TestSelectProvider_ANameTheRouterDoesNotHaveIsRefusedWith400 now also requires
lava-user-request-type on the 400 and the headers on the configured-but-unusable 500.
TestSendParsedRelay_ExpiredBeforeWriteDispatch pinned the header-less reply (require.Nil(result));
it now requires a result with the request type and no status. go test over rpcsmartrouter,
chainlib, routersession and relaycore passes, and the new tests pass 5 of 5 under -race.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant