edge: 503 guard follows parenthesised calls, refuses method expressions
Astra R3: (w.WriteHeader)(503) and http.ResponseWriter.WriteHeader(w, c) escaped the guard. calleeObj unwraps parentheses; a WriteHeader method expression is refused as W5. Fixtures for both.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/edge/testdata/unavailable_guard/indirect.go+9 −0internal/edge/unavailable_guard_test.go+15 −3
CI passed — run details
Intent
<task-notification> <task-id>bbnfg0cwr</task-id> <tool-use-id>toolu_01My62Ydm79JK9nVYYTvmPKE</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/65c83978-bd41-49d3-9db5-c69ac6296f34/tasks/bbnfg0cwr.output</output-file> <status>completed</status> <summary>Background command "~/.cache/region-ha-held/retry-after/run.sh 3 " ROUND 3 (final). The branch tip is now 14851b8d. Round-1 and round-2 findings are in $HOME/.cache/region-ha-held/retry-after/r1.md and r2.md. First a disposition table for each round-2 finding, verified against the code. Note on r2 #1: the plans turned-off page deliberately sends no Retry-After (plandisabled.go:10-15, waiting changes nothing), so the fix keeps that via a new UnavailableNoRetry, which still names site and box; the existing test asserting no Retry-After is kept. Then report only NEW P1/P2 findings. Then re-give the census verdict for the re-proposed card docs/superpowers/notes/census-proposal-retry-after-503.md (only planDisabledAdmit's claim and the internal/edge envelope changed since round 2): APPROVE or REJECT per unit and per envelope. End with ACCEPT or NOT READY."; tail -3 ~/.cache/region-ha-held/retry-after/r3.log" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 15.1 g CO₂e (1,802,340 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on retry-after-503, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/edge/testdata/unavailable_guard/indirect.go b/internal/edge/testdata/unavailable_guard/indirect.go| index da0a90f83..026711c84 100644 |
| --- a/internal/edge/testdata/unavailable_guard/indirect.go |
| +++ b/internal/edge/testdata/unavailable_guard/indirect.go |
| @@ -12,3 +12,12 @@ func zzIndirectError(w http.ResponseWriter) { |
| fail := http.Error |
| fail(w, "busy", 503) |
| } |
| + |
| +func zzParenCall(w http.ResponseWriter) { |
| + (w.WriteHeader)(http.StatusServiceUnavailable) |
| +} |
| + |
| +func zzMethodExpr(w http.ResponseWriter) { |
| + code := http.StatusServiceUnavailable |
| + http.ResponseWriter.WriteHeader(w, code) |
| +} |
diff --git a/internal/edge/unavailable_guard_test.go b/internal/edge/unavailable_guard_test.go| index 8258fd50a..d579c92d3 100644 |
| --- a/internal/edge/unavailable_guard_test.go |
| +++ b/internal/edge/unavailable_guard_test.go |
| @@ -78,7 +78,7 @@ var unavailableGuardFixtures = map[string][]string{ |
| "variable.go": {"zzVariable: status written from a variable outside a relay"}, |
| "handed.go": {"zzHanded: constant 503 handed to zzWriteCode", "zzWriteCode: status written from a variable outside a relay"}, |
| "closure.go": {"zzClosureHandler: 503 written without the helper (WriteHeader)", "zzClosureError: 503 written without the helper (http.Error)"}, |
| - "indirect.go": {"zzIndirect: WriteHeader taken as a value", "zzIndirectError: http.Error taken as a value", "zzIndirectError: constant 503 handed to fail"}, |
| + "indirect.go": {"zzIndirect: WriteHeader taken as a value", "zzIndirectError: http.Error taken as a value", "zzIndirectError: constant 503 handed to fail", "zzParenCall: 503 written without the helper (WriteHeader)", "zzMethodExpr: WriteHeader taken as a value"}, |
| "site.go": {"zzSiteVar: Unavailable site is not a constant", "zzSiteBad: Unavailable site \"Bad Site\" does not match answerSite", "zzSiteDup: Unavailable site \"wake-failed\" named twice"}, |
| } |
| @@ -142,7 +142,7 @@ func is503(info *types.Info, e ast.Expr) bool { |
| // calleeObj is the function or method a call names, or nil. |
| func calleeObj(info *types.Info, call *ast.CallExpr) types.Object { |
| - switch f := call.Fun.(type) { |
| + switch f := ast.Unparen(call.Fun).(type) { |
| case *ast.Ident: |
| return info.Uses[f] |
| case *ast.SelectorExpr: |
| @@ -218,7 +218,10 @@ func unavailableProblems(info *types.Info, f *ast.File, helperFile bool, sites * |
| if id, ok := n.(*ast.Ident); ok && selNames[id] { |
| return true |
| } |
| - if ref := statusWriterRef(info, n); ref != "" && !callFuns[n.(ast.Expr)] && !helperFile { |
| + // A method expression (http.ResponseWriter.WriteHeader(w, |
| + // code)) moves the code to the second argument; refuse it even |
| + // when called rather than follow it. |
| + if ref := statusWriterRef(info, n); ref != "" && (!callFuns[n.(ast.Expr)] || isMethodExpr(info, n)) && !helperFile { |
| out = append(out, fmt.Sprintf("%s: %s taken as a value", name, ref)) |
| } |
| call, ok := n.(*ast.CallExpr) |
| @@ -303,6 +306,15 @@ func statusWriterRef(info *types.Info, n ast.Node) string { |
| return "" |
| } |
| +func isMethodExpr(info *types.Info, n ast.Node) bool { |
| + sel, ok := n.(*ast.SelectorExpr) |
| + if !ok { |
| + return false |
| + } |
| + s, ok := info.Selections[sel] |
| + return ok && s.Kind() == types.MethodExpr |
| +} |
| + |
| // genDeclName is the first name a var or const declaration declares, for |
| // the guard's report. |
| func genDeclName(d *ast.GenDecl) string { |