Repository navigation
card-129: Await request event recording on rejected MCP requests - #23
Merged
Merged
Conversation
Await recordRequestEvent in MCP route middleware before sending 403/401 responses, ensuring audit event persistence is deterministic before response completion.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Root Cause Analysis
In
functions/src/app.ts,recordRequestEvent(...)was invoked withvoid(fire-and-forget) before issuingres.status(403).json(...)(andres.status(401).json(...)).Because
recordRequestEventwas not awaited, the response was sent concurrently with the observer recording logic. In environments with asynchronous observers or event-loop / microtask preemption,await request(app)infunctions/test/app.test.tscan resolve and checkruntime.observer.listEvents()before the observer event is appended. In serverless Cloud Functions, unawaited background promises fired after sending the HTTP response are also subject to runtime CPU throttling or instance teardown.Evidence
test/app.test.ts: 30 passed, 0 failed.npm --prefix functions test): 40 passed, 0 failed.test/app.test.tsunder 4-core heavy background CPU load: 40 passed, 0 failed.vitest run --coverageruns collided oncoverage/.tmprather than failing insideapp.test.ts.app.ts.router.usemiddleware infunctions/src/app.tstoasyncand awaitedrecordRequestEvent(...)on both 403 (origin not allowed) and 401 (unauthorized) rejection paths, guaranteeing deterministic event recording before the HTTP response completes.Verification
npm --prefix functions test: 20/20 passed (0 failures).python3 scripts/run-gate.py metacortex_typecheck: Exit code 0python3 scripts/run-gate.py metacortex_test: Exit code 0 (181 passed, 1 skipped, 80.06% coverage)python3 scripts/run-gate.py metacortex_package: Exit code 0