Skip to content

feat(agents): add last-used tracking to identify stale agents#2627

Open
JonasJesus42 wants to merge 1 commit intomainfrom
feat/agent-last-used-tracking
Open

feat(agents): add last-used tracking to identify stale agents#2627
JonasJesus42 wants to merge 1 commit intomainfrom
feat/agent-last-used-tracking

Conversation

@JonasJesus42
Copy link
Contributor

@JonasJesus42 JonasJesus42 commented Mar 9, 2026

Derive agent last-used timestamps from monitoring_logs to help identify stale/unused agents that clutter the organization.

Backend:

  • Add getLastUsedByVirtualMcpIds to MonitoringStorage (GROUP BY + MAX)
  • New MONITORING_AGENT_LAST_USED MCP tool with input validation (max 500 IDs)

Frontend:

  • useAgentLastUsed hook in mesh-sdk (stable query key via sorted IDs)
  • Agents page: "Last used" column, usage filter (Recently used/Stale/Never)
  • Agents page: "never used" count in header stats
  • Home: sort "Recently used agents" by actual usage instead of updated_at

Made-with: Cursor

What is this contribution about?

Describe your changes and why they're needed.

Screenshots/Demonstration

Add screenshots or a Loom video if your changes affect the UI.

How to Test

Provide step-by-step instructions for reviewers to test your changes:

  1. Step one
  2. Step two
  3. Expected outcome

Migration Notes

If this PR requires database migrations, configuration changes, or other setup steps, document them here. Remove this section if not applicable.

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes

Summary by cubic

Adds last-used tracking for agents derived from monitoring_logs to help surface stale or never-used agents. Updates the Agents page and Home to display and sort by real usage.

  • New Features
    • Backend
      • MonitoringStorage.getLastUsedByVirtualMcpIds computes last-used per agent.
      • New MCP tool MONITORING_AGENT_LAST_USED (max 500 IDs).
    • SDK
      • useAgentLastUsed hook in packages/mesh-sdk (sorted IDs for stable key, 60s cache).
    • UI
      • Agents page: new “Last used” column; usage filter (Recently used, Stale 30+ days, Never); header shows “never used” count.
      • Home: “Recently used agents” sorted by actual last activity (not updated_at).

Written for commit 28263df. Summary will update on new commits.

Derive agent last-used timestamps from monitoring_logs to help identify
stale/unused agents that clutter the organization.

Backend:
- Add getLastUsedByVirtualMcpIds to MonitoringStorage (GROUP BY + MAX)
- New MONITORING_AGENT_LAST_USED MCP tool with input validation (max 500 IDs)

Frontend:
- useAgentLastUsed hook in mesh-sdk (stable query key via sorted IDs)
- Agents page: "Last used" column, usage filter (Recently used/Stale/Never)
- Agents page: "never used" count in header stats
- Home: sort "Recently used agents" by actual usage instead of updated_at

Made-with: Cursor
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

🧪 Benchmark

Should we run the Virtual MCP strategy benchmark for this PR?

React with 👍 to run the benchmark.

Reaction Action
👍 Run quick benchmark (10 & 128 tools)

Benchmark will run on the next push after you react.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Release Options

Should a new version be published when this PR is merged?

React with an emoji to vote on the release type:

Reaction Type Next Version
👍 Prerelease 2.152.1-alpha.1
🎉 Patch 2.152.1
❤️ Minor 2.153.0
🚀 Major 3.0.0

Current version: 2.152.0

Deployment

  • Deploy to production (triggers ArgoCD sync after Docker image is published)

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 11 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/mesh/src/web/components/home/agents-list.tsx">

<violation number="1" location="apps/mesh/src/web/components/home/agents-list.tsx:152">
P2: Cap the number of agent IDs sent to useAgentLastUsed (the tool rejects more than 500). Otherwise orgs with >500 agents will hit validation errors and this query will fail.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

agent.id !== null && !isDecopilot(agent.id),
);

const agentIds = nonDecopilotAgents.map((a) => a.id);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 9, 2026

Choose a reason for hiding this comment

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

P2: Cap the number of agent IDs sent to useAgentLastUsed (the tool rejects more than 500). Otherwise orgs with >500 agents will hit validation errors and this query will fail.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/mesh/src/web/components/home/agents-list.tsx, line 152:

<comment>Cap the number of agent IDs sent to useAgentLastUsed (the tool rejects more than 500). Otherwise orgs with >500 agents will hit validation errors and this query will fail.</comment>

<file context>
@@ -140,12 +144,29 @@ function AgentsListContent() {
+      agent.id !== null && !isDecopilot(agent.id),
+  );
+
+  const agentIds = nonDecopilotAgents.map((a) => a.id);
+  const lastUsedMap = useAgentLastUsed(agentIds);
+
</file context>
Fix with Cubic

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.

1 participant