Skip to content

Preserve vMCP resources until requests drain - #6715

Merged
ChrisJBurns merged 1 commit into
mainfrom
fix/vmcp-audit-shutdown
Sep 25, 2026
Merged

ChrisJBurns merged 1 commit into
mainfrom
fix/vmcp-audit-shutdown

Conversation

@JAORMX

@JAORMX JAORMX commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #6110.

  • A workflow can outlive the HTTP shutdown deadline. Closing its audit writer while it is still running loses its terminal audit records, so Server.Stop now leaves request-used resources intact when HTTP draining fails. A serial retry with a fresh context can complete the drain and cleanup.
  • Cleanup failures should remain visible to callers. Server-construction rollback now joins the Serve failure with the core-close error, and Start preserves both serving and shutdown error chains.
  • Add regression coverage and document who owns HTTP draining when vMCP is embedded.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other

Test plan

  • Unit tests (task test; targeted regressions pass, full-suite failures detailed below)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual verification: git diff --check and comparison of unrelated failures against untouched merge commit 6180ced93

The three new regression tests pass with race detection through the repository task:

GOFLAGS='-run=Test(StopIncompleteDrainPreservesWorkflowAuditUntilRetry|NewServeFailureReleasesWorkflowAuditFile|StartJoinsHTTPAndStopErrors)$ -count=1' task test

Coverage includes a real HTTP composite workflow held across two failed shutdown attempts, a terminal audit record written before cleanup, successful fresh-context shutdown retry, constructor rollback releasing the audit descriptor, and preservation of both error identities on a serving failure.

task lint-fix reports zero issues.

The full task test run was not green:

  • pkg/transport: TestBridge_ToolsListChanged_TriggersReSync timed out during teardown after ten minutes. Reproduced the hang on untouched 6180ced93 using a 30-second test timeout.
  • pkg/vmcp/server/sessionmanager: the termination-during-initialization test received the earlier termination error and missed its expected factory call. Its focused baseline rerun passed; this failure was not reproduced in that rerun.

Does this introduce a user-facing change?

Library callers receive an error without resource teardown if the owned HTTP server has not drained. Callers that keep running must retry Stop serially with a fresh context. Embedders serving Handler through their own HTTP server must fully drain that server before calling Stop.

Implementation plan

Implementation plan
  1. Preserve both construction and core-cleanup errors when Serve fails; remove the now-unnecessary deferred cleanup guard.
  2. Use the existing http.Server.Shutdown drain barrier. Return immediately on drain failure before closing core, audit, or session resources, while retaining the HTTP server for a serial retry.
  3. Preserve serving and shutdown error identities in Start with errors.Join.
  4. Cover incomplete drain and retry through real HTTP workflow execution, constructor rollback, and joined serving errors without production test hooks.
  5. Document retry limits and embedding ownership; run repository tests, lint, and independent review.

Special notes for reviewers

  • This intentionally avoids a new request tracker or asynchronous finalizer. It does not force-close active connections.
  • The ten-second limit bounds HTTP draining, not all subsequent cleanup. Retry is supported after an incomplete drain, not after arbitrary partial cleanup failures or concurrent/repeated successful Stop calls.
  • The CLI keeps its existing error-and-exit policy. This does not guarantee terminal audit records after process termination.
  • The constructor test verifies descriptor release on rollback. It does not inject a simultaneous private file-close failure; no test-only hook was added for that case.

Keep workflow auditing and session resources available when HTTP draining times out, so callers can retry shutdown without losing terminal audit records. Preserve cleanup error chains during server construction and serving failures.

Document drain ownership and retry limits, and cover incomplete shutdown, constructor rollback, and joined errors with regression tests.

Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
@github-actions github-actions Bot added the size/M Medium PR: 300-599 lines changed label Sep 25, 2026
@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.23%. Comparing base (6180ced) to head (ac7116b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6715      +/-   ##
==========================================
- Coverage   79.23%   79.23%   -0.01%     
==========================================
  Files         800      800              
  Lines       81019    81013       -6     
==========================================
- Hits        64194    64188       -6     
  Misses      16820    16820              
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChrisJBurns
ChrisJBurns merged commit 2c33721 into main Sep 25, 2026
47 checks passed
@ChrisJBurns
ChrisJBurns deleted the fix/vmcp-audit-shutdown branch September 25, 2026 14:01
@github-actions github-actions Bot mentioned this pull request Sep 26, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants