Skip to content

fix(agentvault): strip monotonic reading from leaf cert expiration - #435

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1792066414-leaf-cert-wall-clock
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1792066414-leaf-cert-wall-clock

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Description 📣

mintLeaf caches each leaf cert with expiration: notAfter, where notAfter := time.Now().Add(leafTTL). Because that value carries Go's monotonic clock reading, the reuse check time.Until(entry.expiration) > leafReuseMargin uses the monotonic clock. That clock doesn't advance while the host is asleep. So after a laptop sleeps overnight, the proxy keeps serving a cached leaf whose real NotAfter has already passed, and clients reject it until the proxy restarts. Machines that never sleep (e.g. a Mac mini) aren't affected.

Fix: .Round(0) strips the monotonic reading, so the cache compares against wall-clock time. This is applied in packages/agentvault/ca.go and also in packages/agentproxy/ca.go, which has the same pattern. The issuer-clamp branch (rootCert.NotAfter / interCert.NotAfter) already comes from a parsed cert, so it has no monotonic reading.

Type ✨

  • Bug fix
  • New feature
  • Improvement
  • Breaking change
  • Documentation

Tests 🛠️

gofmt -l packages/agentvault packages/agentproxy   # clean
go vet ./packages/agentvault/ ./packages/agentproxy/
go test -race -count=1 ./packages/agentvault/      # ok

go test -race ./packages/agentproxy/ reports a data race in TestClientAbortIsNotLoggedAsError (forward_test.go). The same race shows up on main without this change, and CI doesn't run that package.


Link to Devin session: https://app.devin.ai/sessions/d5c116c867554261b9c04b1833f86eb9
Open in Devin Desktop: https://app.devin.ai/desktop/session/d5c116c867554261b9c04b1833f86eb9?variant=devin

time.Until on a time.Now()-derived expiration uses the monotonic clock, which
stops while the host sleeps, so cached leaf certs were reused past NotAfter
after a laptop woke up.

Co-Authored-By: jake <jake@infisical.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: plus

[Low impact] Strips monotonic clock reading from certificate expiration times.

The fix appears safe to merge, with a non-blocking request for focused regression tests.

Findings

  1. P2 Clock fix lacks regression tests ▶

Summary

Both certificate managers now use .Round(0) so cached leaf expiration follows wall-clock time after host sleep.

  • Both agent proxies check cached leaf expiry against wall time.

Acknowledged and excluded: devin-ai-integration[bot] reports that the race in TestClientAbortIsNotLoggedAsError already occurs on main.

Reviews (1) · Last reviewed commit: "fix(agentvault): strip monotonic reading..." · Reviewed by Greptile

Comment thread packages/agentvault/ca.go
}

notAfter := time.Now().Add(leafTTL)
notAfter := time.Now().Add(leafTTL).Round(0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Clock fix lacks regression tests

Neither package tests the clock detail this fix depends on. Existing leaf tests check certificate reuse or validity, so removing .Round(0) would not fail them and could silently restore expired-certificate reuse after sleep.

Add a test here and in packages/agentproxy that mints a leaf with an issuer valid beyond leafTTL, then asserts that its cached expiration == expiration.Round(0). This guards the fix without changing the machine clock or waiting through sleep.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants