Commit afbbfac
fix(server): PR #233 expert-review followups — security docs + retry/transform tests
Addresses code-reviewer + security-reviewer findings on PR #233.
DOCS (security — moved from docs-only to import-site where callers
see it)
- SkillMiddleware docstring now includes four security callouts:
(1) do NOT swallow ADCPError — serves fake success for failed
mutations (IdempotencyConflictError, ADCPTaskError).
(2) middleware is a data processor for the full skill payload —
params contain buyer briefs, budgets, PII; context has
caller_identity and tenant_id. Third-party middleware gets
the complete surface; treat as controller-processor.
(3) exception messages land in server logs verbatim via
logger.exception before client-facing sanitisation — do not
format params / caller_identity into exception text.
(4) short-circuit caches MUST key on (skill_name, params,
caller_identity, tenant_id). skill_name + params alone serves
principal A's data to principal B.
- Clarify params is request-side only; transforms happen on the
return side of call_next.
- Note ContextVars propagate through call_next (same asyncio task).
DOCS — docs/handler-authoring.md
- "Semantics worth knowing" expanded with the composition-order WHY
(audit outermost so rate-limited rejected calls don't disappear
from audit), short-circuit cache-key requirements, retry support,
transform-on-return-not-input rule.
- New "Security — middleware is a data processor" callout matches
the import-site docstring.
TESTS (+2, covering code-reviewer's gap list)
- test_middleware_can_invoke_call_next_multiple_times_for_retry:
retry-on-transient-error pattern. Middleware calls call_next 3
times; handler fails twice, succeeds on third. Locks the
re-entrant composition contract a naive loop-variable closure
would break.
- test_middleware_can_transform_result_on_return_side: enriching
middleware wraps the handler's return. Distinct code path from
short-circuit (which never calls call_next).
NITS
- Removed stale `from a2a.types import TaskStatus # noqa: F401
(unused but document` line with truncated comment in
test_middleware_can_short_circuit_without_invoking_handler.
Deferred (not blocking this PR):
- Protocol class for SkillMiddleware (do alongside ContextFactory to
keep declaration style consistent).
- Runtime validation of middleware return shape against skill output
schemas.
- ContextVar-propagation formal docs in a dedicated section.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 6f9bd26 commit afbbfac
3 files changed
Lines changed: 170 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
377 | 398 | | |
378 | 399 | | |
379 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
380 | 411 | | |
381 | 412 | | |
382 | 413 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
95 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
96 | 106 | | |
97 | 107 | | |
98 | 108 | | |
99 | 109 | | |
100 | 110 | | |
101 | 111 | | |
102 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
103 | 148 | | |
104 | 149 | | |
105 | 150 | | |
| |||
114 | 159 | | |
115 | 160 | | |
116 | 161 | | |
117 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
118 | 166 | | |
119 | 167 | | |
120 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
951 | 951 | | |
952 | 952 | | |
953 | 953 | | |
954 | | - | |
955 | | - | |
956 | 954 | | |
957 | 955 | | |
958 | 956 | | |
| |||
1054 | 1052 | | |
1055 | 1053 | | |
1056 | 1054 | | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
0 commit comments