Skip to content

Secure, Fast, and Extensible Sandbox runtime for AI agents.

fix(egress): resolver redactions longest-first; timeout bounds queueing

高然7ffb95bdee3f
diff --git a/components/egress/pkg/credentialvault/resolver_client.go b/components/egress/pkg/credentialvault/resolver_client.go
index 99c270f13..5fca20d29 100644
--- a/components/egress/pkg/credentialvault/resolver_client.go
+++ b/components/egress/pkg/credentialvault/resolver_client.go
@@ -393,17 +393,17 @@ func (c *resolverClient) Resolve(ctx context.Context, input ResolveInput) (*Reso
return nil, err
}
- // Bound in-flight resolves; acquire honors cancellation.
+ // The deadline bounds the whole call — queueing included — so queued
+ // resolves cannot stack one timeout per pending batch.
+ callCtx, cancel := context.WithTimeout(ctx, c.timeout)
+ defer cancel()
select {
case c.concurrency <- struct{}{}:
defer func() { <-c.concurrency }()
- case <-ctx.Done():
- return nil, &ResolverError{Kind: ResolverTimeout, err: ctx.Err()}
+ case <-callCtx.Done():
+ return nil, &ResolverError{Kind: ResolverTimeout, err: callCtx.Err()}
}
- callCtx, cancel := context.WithTimeout(ctx, c.timeout)
- defer cancel()
-
request, err := http.NewRequestWithContext(callCtx, http.MethodPost, c.requestURL, bytes.NewReader(document))
if err != nil {
return nil, resolverErrorf(ResolverInvalidRequest, "request_build_failed")
@@ -714,8 +714,8 @@ func strictJSONObject(data []byte) (map[string]json.RawMessage, error) {
return fields, nil
}
-// canonicalResolverRedactions dedups and orders values by length then
-// bytes (decision-snapshot canonical form).
+// canonicalResolverRedactions dedups and orders values longest-first with
+// ascending byte tie-break (decision-snapshot canonical form).
func canonicalResolverRedactions(values []string) []string {
seen := make(map[string]struct{}, len(values))
merged := make([]string, 0, len(values))
@@ -731,7 +731,7 @@ func canonicalResolverRedactions(values []string) []string {
}
sort.Slice(merged, func(i, j int) bool {
if len(merged[i]) != len(merged[j]) {
- return len(merged[i]) < len(merged[j])
+ return len(merged[i]) > len(merged[j])
}
return merged[i] < merged[j]
})
diff --git a/components/egress/pkg/credentialvault/resolver_redaction_test.go b/components/egress/pkg/credentialvault/resolver_redaction_test.go
index 4bccaa826..c1574f128 100644
--- a/components/egress/pkg/credentialvault/resolver_redaction_test.go
+++ b/components/egress/pkg/credentialvault/resolver_redaction_test.go
@@ -84,12 +84,13 @@ func TestResolverRedactionsAreIncrementalR9(t *testing.T) {
func TestCanonicalResolverRedactionsOrdering(t *testing.T) {
ordered := canonicalResolverRedactions([]string{"ccc", "bb", "a", "bb", ""})
- require.Equal(t, []string{"a", "bb", "ccc"}, ordered)
+ require.Equal(t, []string{"ccc", "bb", "a"}, ordered)
ordered = canonicalResolverRedactions([]string{"b", "a"})
require.Equal(t, []string{"a", "b"}, ordered)
- // The order matches the decision-snapshot canonical form.
+ // The order matches the decision-snapshot canonical form (longest
+ // first, ties ascending) — the mixed-length case enforces direction.
require.True(t, canonicalRedactions(ordered))
}