Skip to content

Commit fce9fa8

Browse files
hsbtclaude
andcommitted
Mark same-commit failure boundary as flaky
When last_good and first_bad ran the same commit, a compare URL degenerates to X...X and misleads agents into commit bisection. Return no compare_url and note that the failure is likely flaky or environment-dependent instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 63f7241 commit fce9fa8

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

app/tools/mcp_tools/find_failure_origin.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ def self.analyze_query(rows, match_ids)
128128
end
129129

130130
def self.config_entry(first_bad, last_good, boundary)
131+
same_commit = last_good&.git_sha && last_good.git_sha == first_bad.git_sha
132+
note = if same_commit
133+
"last_good and first_bad ran the same commit; the failure is likely flaky or environment-dependent rather than caused by a code change."
134+
elsif last_good.nil?
135+
"No earlier report within the window (window exhausted or scan capped at #{MAX_REPORTS_PER_CONFIG} reports); the failure may have started earlier."
136+
end
131137
{
132138
server: first_bad.server.name,
133139
server_id: first_bad.server_id,
@@ -136,9 +142,8 @@ def self.config_entry(first_bad, last_good, boundary)
136142
occurrences: boundary[:occurrences],
137143
first_bad: first_bad.as_mcp_json,
138144
last_good: last_good&.as_mcp_json,
139-
compare_url: compare_url(last_good, first_bad),
140-
note: last_good ? nil :
141-
"No earlier report within the window (window exhausted or scan capped at #{MAX_REPORTS_PER_CONFIG} reports); the failure may have started earlier.",
145+
compare_url: (compare_url(last_good, first_bad) unless same_commit),
146+
note: note,
142147
}.compact
143148
end
144149
end

test/controllers/mcp_controller_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ class McpControllerTest < ActionDispatch::IntegrationTest
104104
assert_equal "mcp-srv", result.dig("earliest", "server")
105105
end
106106

107+
test "find_failure_origin flags same-commit boundary as flaky" do
108+
base = Time.now.utc.change(usec: 0)
109+
good = create_report(@server, base - 10.hours, SHA_HEAD, success: true)
110+
good.update!(branch: "4.0")
111+
bad = create_report(@server, base - 5.hours, SHA_HEAD, success: false)
112+
bad.update!(branch: "4.0")
113+
LogExcerpt.create!(report: bad, content: "TestFlaky#test_same_commit failed")
114+
115+
result = call_tool("find_failure_origin", { branch: "4.0", query: "test_same_commit" })
116+
config = result["configs"].first
117+
assert_equal bad.id, config.dig("first_bad", "id")
118+
assert_equal good.id, config.dig("last_good", "id")
119+
assert_nil config["compare_url"]
120+
assert_match "flaky", config["note"]
121+
end
122+
107123
test "find_failure_origin with unmatched query" do
108124
result = call_tool("find_failure_origin", { branch: "master", query: "no_such_failure" })
109125
assert_match "No failure log", result["message"]

0 commit comments

Comments
 (0)