Audit stream opens on flush and pre-write panics - #6005
Merged
Conversation
JAORMX
requested review from
ChrisJBurns,
jhrozek,
rdimitrov and
tgrunnagle
as code owners
July 27, 2026 10:51
rdimitrov
previously approved these changes
Jul 27, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6005 +/- ##
==========================================
- Coverage 72.15% 72.14% -0.01%
==========================================
Files 720 720
Lines 74744 74745 +1
==========================================
- Hits 53929 53926 -3
- Misses 16942 16949 +7
+ Partials 3873 3870 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Stacked on #5874. Two fast-follows from rdimitrov's review: - Flush() now logs the stream connection event: a handler that establishes the stream by flushing headers and then blocks never hits WriteHeader/Write, so the event was delayed until the first data write or lost entirely. - The stream-open log moved into a defer registered before ServeHTTP, so a panic in an inner handler still produces the event during unwinding. On chains whose recovery middleware runs outside audit (the vMCP Serve path) the event previously vanished.
JAORMX
force-pushed
the
audit-stream-open-followups
branch
from
July 27, 2026 11:27
ff7ece7 to
9c98e94
Compare
rdimitrov
approved these changes
Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #5874 — addresses the two minor, non-blocking follow-ups from @rdimitrov's review, both in the deferred stream-open logging in
pkg/audit/auditor.go:streamOpenWriter.Flush()bypassedlogOnce— a handler that establishes the stream by flushing headers and then blocks waiting for events sends the implicit 200 throughFlush()without ever hittingWriteHeader/Write, so the connection event was delayed until a later data write or connection close.Flush()now callslogOnce(http.StatusOK); a flush commits the response headers with an implicit 200, so it counts as the stream being established.Stream-open event lost on a panic before the first write — on the vMCP Serve path, recovery is the outermost wrapper (outside audit), so a panic in an inner layer before any byte is written unwound straight past audit: recovery returns 500 and no stream-open event was recorded. The
sw.logOnce(http.StatusOK)call moved into adeferregistered beforenext.ServeHTTP, so the event is produced during unwinding. If the stream already logged on first write, the deferred call is a no-op. This restores parity with the pre-Audit authentication failures and webhook denials #5874 arrival-time logging for that case (the connection-open is recorded; the 500 written by the outer recovery is not visible to audit, same as before).The runner/proxy path was already unaffected by (2) — recovery is innermost there, so the 500 flows back out through
streamOpenWriterandlogOnce(500)fires.Type of change
Test plan
task test)task test-e2e)task lint-fix)Two new subtests in
TestStreamOpenAuditEvents:flush before first write logs the connection eventandpanic before first write still logs the connection event.API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.No CRD or exported-API changes.
Does this introduce a user-facing change?
Yes. Audit logs now always contain the stream-connection event for SSE / streamable GET opens: previously it could be delayed or lost for handlers that flush before writing, and lost entirely on a pre-write panic on the vMCP Serve path.