Skip to content

feat(agent-proxy): report proxied service usage#322

Merged
saifsmailbox98 merged 3 commits into
mainfrom
saif/age2-57-log-insights-on-dashboard
Jul 24, 2026
Merged

feat(agent-proxy): report proxied service usage#322
saifsmailbox98 merged 3 commits into
mainfrom
saif/age2-57-log-insights-on-dashboard

Conversation

@saifsmailbox98

@saifsmailbox98 saifsmailbox98 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Description 📣

Adds best-effort usage reporting to the agent proxy, which powers a "last used" indicator on proxied services in the dashboard. Until now the proxy only logged per-request activity to its local stream, so the platform had no signal of whether a proxied service was actually being used.

When the proxy brokers a request for a proxied service, it records the service's ID and the time. Once per poll tick it reports the latest time per service via POST /v1/proxied-services/:serviceId/report-usage, authenticating with the proxy's own machine identity (never the agent's — the agent token lives in the untrusted execution environment, so letting it report would let a compromised agent forge usage).

  • Accumulates distinct service IDs in memory, bounded by the number of configured services rather than traffic, and snapshot-and-clears on each flush. An unreachable backend never grows memory or blocks brokering; a dropped report just re-sends on the next tick if the service is still in use.
  • Reports the actual broker time (server clamps it to now() and only advances monotonically), so a longer --poll-interval doesn't skew the timestamp.

Companion PR: Infisical/infisical#7359

Type ✨

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

Tests 🛠️

# Here's some code block to paste some code snippets

@linear

linear Bot commented Jul 21, 2026

Copy link
Copy Markdown

AGE2-57

@infisical-review-police

Copy link
Copy Markdown

💬 Discussion in Slack: #pr-review-cli-322-feat-agent-proxy-report-proxied-service-usage

Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel.

@greptile-apps

greptile-apps Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds usage reporting for services brokered through the agent proxy. The main changes are:

  • In-memory tracking of the latest broker time per service.
  • Periodic usage reports authenticated with the proxy token.
  • A new API helper for the report-usage endpoint.

Confidence Score: 4/5

The usage flush lifecycle needs fixes before merging.

  • Sequential report timeouts can delay service-cache refreshes for minutes.
  • Normal shutdown can discard usage accumulated since the last poll tick.
  • The API request shape and proxy-token authentication appear consistent with the surrounding code.

packages/agentproxy/proxy.go

Important Files Changed

Filename Overview
packages/agentproxy/proxy.go Adds synchronized usage tracking and periodic reporting, but reporting can block cache refreshes and pending usage is not flushed during shutdown.
packages/api/agent_proxy.go Adds the usage-report request model and API helper with standard error handling.

Comments Outside Diff (1)

  1. packages/agentproxy/proxy.go, line 174 (link)

    P2 Pending Usage Is Lost On Shutdown

    The usage poller has no stop or final-flush path, while shutdown only stops the lease refresh loop. Any usage recorded after the last tick is therefore discarded when the process exits, so a service used shortly before a normal restart may never have its last-used timestamp reported.

Reviews (1): Last reviewed commit: "feat(agent-proxy): report proxied servic..." | Re-trigger Greptile

Comment thread packages/agentproxy/proxy.go Outdated
@saifsmailbox98
saifsmailbox98 force-pushed the saif/age2-57-log-insights-on-dashboard branch from 8bcafc5 to 338722f Compare July 21, 2026 14:14
@saifsmailbox98
saifsmailbox98 requested a review from akhilmhdh July 21, 2026 18:58
akhilmhdh
akhilmhdh previously approved these changes Jul 22, 2026
@saifsmailbox98
saifsmailbox98 force-pushed the saif/age2-57-log-insights-on-dashboard branch 2 times, most recently from 4f496cb to 8e54f1c Compare July 22, 2026 16:39
akhilmhdh
akhilmhdh previously approved these changes Jul 22, 2026
@saifsmailbox98
saifsmailbox98 force-pushed the saif/age2-57-log-insights-on-dashboard branch from 8e54f1c to b05835f Compare July 24, 2026 15:47
@saifsmailbox98
saifsmailbox98 requested a review from akhilmhdh July 24, 2026 18:00
@saifsmailbox98
saifsmailbox98 merged commit 0b53da4 into main Jul 24, 2026
30 checks passed
saifsmailbox98 added a commit that referenced this pull request Jul 25, 2026
…nfig #319)

Resolve packages/agentproxy/proxy.go, keeping both sides:
- local coupled mode (New/Serve/Shutdown, serviceResolver, control-plane
  fence, graceful pollLoop stop) from this branch.
- proxied-service usage reporting (recordUsage/flushUsage) from #322.

Also flush usage on shutdown: `run` is frequently shorter than one poll
interval, so the poll-tick flush alone would never report a short session's
usage. The daemon (`start`) path still flushes each tick.
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.

2 participants