Skip to content

Commit 25b2a62

Browse files
committed
feat: US-001 - ManagerDriver accepts ActorQuery targets for gateway operations
1 parent da0b24b commit 25b2a62

45 files changed

Lines changed: 186808 additions & 1846 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ members = [
7272
axum-test = "17"
7373
base64 = "0.22"
7474
bcrypt = "0.13.0"
75+
ciborium = "0.2"
7576
bytes = "1.6.0"
7677
cjson = "0.1"
7778
colored_json = "5.0.0"

engine/CLAUDE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ When changing a versioned VBARE schema, follow the existing migration pattern.
2626
- `engine/sdks/rust/runner-protocol/src/lib.rs` `PROTOCOL_MK2_VERSION`
2727
- `engine/sdks/typescript/runner/src/mod.ts` `PROTOCOL_VERSION`
2828
- Update the Rust latest re-export in `engine/sdks/rust/runner-protocol/src/lib.rs` to the new generated module.
29+
30+
## Guard matrix query paths
31+
32+
- In `engine/packages/guard/src/routing/mod.rs`, query paths use the format `/gateway/{name};namespace=...;method=...;key=.../{path}` where the actor name is the path segment and matrix params follow it. Parse the name from the segment prefix (before the first `;`) and the remaining params from the raw segment after the first `;`, all before percent-decoding. Reject raw `@token` syntax, duplicate params, unknown params, `name` as a matrix param, and params missing `=`.
33+
- `namespace` is a required matrix param. The guard resolves it directly via `namespace::ops::resolve_for_name_global` instead of scanning all namespaces.
34+
- `crashPolicy` is an optional matrix param. When omitted, defaults to `Sleep`.
35+
- For `key`, split on literal commas first and percent-decode each component separately so empty components like `key=` and `a,,b` survive round trips.
36+
- Keep query `input` as validated raw CBOR bytes in the parsed guard query shape. Validate the base64url and CBOR structure via `ciborium` during parsing, but defer any higher-level input conversion to the later gateway resolution step.
37+
- In `engine/packages/guard/src/routing/pegboard_gateway.rs`, resolve query gateway paths by resolving the namespace from the matrix param, then choosing a runner selector. Query-path creation should fail on ambiguous runners instead of guessing.

engine/artifacts/errors/guard.invalid_request.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/packages/guard/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ path = "src/lib.rs"
1212
[dependencies]
1313
anyhow.workspace = true
1414
axum.workspace = true
15+
base64.workspace = true
1516
bytes.workspace = true
17+
ciborium.workspace = true
1618
futures.workspace = true
1719
gas.workspace = true
1820
http-body-util.workspace = true
@@ -23,19 +25,23 @@ tower.workspace = true
2325
hyper = "1.6.0"
2426
indoc.workspace = true
2527
lazy_static.workspace = true
28+
namespace.workspace = true
2629
once_cell.workspace = true
2730
pegboard-envoy.workspace = true
2831
pegboard-gateway.workspace = true
2932
pegboard-gateway2.workspace = true
3033
pegboard-runner.workspace = true
3134
pegboard.workspace = true
3235
regex.workspace = true
36+
rivet-api-types.workspace = true
37+
rivet-api-util.workspace = true
3338
rivet-api-builder.workspace = true
3439
rivet-api-public.workspace = true
3540
rivet-cache.workspace = true
3641
rivet-config.workspace = true
3742
rivet-data.workspace = true
3843
rivet-error.workspace = true
44+
rivet-types.workspace = true
3945
rivet-guard-core.workspace = true
4046
rivet-logs.workspace = true
4147
rivet-metrics.workspace = true

engine/packages/guard/src/cache/mod.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,24 @@ pub fn create_cache_key_function() -> CacheKeyFn {
2121

2222
// MARK: Path-based cache key
2323
// Check for path-based actor routing
24-
if let Some(actor_path_info) = parse_actor_path(req_ctx.path()) {
25-
tracing::debug!("using path-based cache key for actor");
24+
if let Some(actor_path_info) = parse_actor_path(req_ctx.path())? {
25+
match actor_path_info {
26+
crate::routing::ParsedActorPath::Direct(actor_path_info) => {
27+
tracing::debug!("using path-based cache key for actor");
2628

27-
if let Ok(cache_key) =
28-
pegboard_gateway::build_cache_key_path_based(req_ctx, &actor_path_info)
29-
{
30-
return Ok(cache_key);
29+
if let Ok(cache_key) =
30+
pegboard_gateway::build_cache_key_path_based(req_ctx, &actor_path_info)
31+
{
32+
return Ok(cache_key);
33+
}
34+
}
35+
crate::routing::ParsedActorPath::Query(_) => {
36+
// Query paths encode all routing params (namespace, name, method,
37+
// key, input, region) as matrix params in the URL path. Hash the
38+
// full path so different queries produce distinct cache keys.
39+
tracing::debug!("using query-path cache key for actor");
40+
return Ok(host_path_method_cache_key(req_ctx));
41+
}
3142
}
3243
}
3344

engine/packages/guard/src/errors.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,14 @@ pub struct MustUseRegionalHost {
7070
pub struct ActorRunnerFailed {
7171
pub actor_id: Id,
7272
}
73+
74+
#[derive(RivetError, Serialize)]
75+
#[error(
76+
"guard",
77+
"invalid_request",
78+
"Invalid request.",
79+
"{message}"
80+
)]
81+
pub struct InvalidRequest {
82+
pub message: String,
83+
}

0 commit comments

Comments
 (0)