Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

fix(agents): make SDK/coding staleness window configurable so agents don't vanish before the selected time range (#1317)

Wen-Chun Huang15bcec2652c2
diff --git a/src/client/src/__tests__/lib/platform/agents/index.test.ts b/src/client/src/__tests__/lib/platform/agents/index.test.ts
index e84efbc8..d7d96516 100644
--- a/src/client/src/__tests__/lib/platform/agents/index.test.ts
+++ b/src/client/src/__tests__/lib/platform/agents/index.test.ts
@@ -229,20 +229,26 @@ describe("listAgents", () => {
expect(issuedQuery).not.toMatch(/s\.source\s+IN\s*\(\s*'sdk'\s*,\s*'both'\s*\)/);
});
- it("[REGRESSION] hides stale SDK-only rows whose last_seen is older than the freshness window", async () => {
- // Phantom SDK rows can linger in openlit_agents_summary when a
- // workload's service.name shifts after controller-managed recreate
- // (e.g. OBI briefly emits as `anthropic-app` before the SDK is
- // re-enabled with OTEL_SERVICE_NAME=demo-anthropic-app). The
- // materializer no longer refreshes those rows after the OBI fix,
- // but they persist in the table until the 90-day TTL. Pin the
- // SDK-specific freshness filter so we always hide them from the
- // list query.
+ it("[REGRESSION] lists SDK agents by the same time-range filter as other sources", async () => {
+ // SDK rows must not be hidden by a separate staleness guard (e.g.
+ // `last_seen >= now() - 10 MINUTE`). An idle SDK agent whose
+ // `last_seen` falls inside the user's selected window should stay
+ // visible, matching controller rows. Phantom SDK rows are prevented
+ // at write time in the materializer, not by a read-side cutoff.
mockedDataCollector.mockResolvedValueOnce({ data: [makeRow()] });
- await listAgents();
+ await listAgents({
+ timeStart: "2026-05-11 00:00:00",
+ timeEnd: "2026-05-11 23:59:59",
+ });
const issuedQuery = (mockedDataCollector.mock.calls[0][0] as any).query as string;
expect(issuedQuery).toMatch(
- /s\.source\s*!=\s*'sdk'\s+OR\s+s\.last_seen\s*>=\s*now\(\)\s*-\s*INTERVAL\s+10\s+MINUTE/
+ /s\.last_seen\s*>=\s*parseDateTimeBestEffort\('2026-05-11 00:00:00'\)/
+ );
+ expect(issuedQuery).not.toMatch(
+ /s\.source\s*!=\s*'sdk'\s+OR\s+s\.last_seen\s*>=\s*now\(\)\s*-\s*INTERVAL/
+ );
+ expect(issuedQuery).not.toMatch(
+ /s\.source\s*!=\s*'coding'\s+OR\s+s\.last_materialized_at\s*>=\s*now\(\)\s*-\s*INTERVAL/
);
});
diff --git a/src/client/src/lib/platform/agents/index.ts b/src/client/src/lib/platform/agents/index.ts
index 36ebec2e..26c88223 100644
--- a/src/client/src/lib/platform/agents/index.ts
+++ b/src/client/src/lib/platform/agents/index.ts
@@ -339,7 +339,9 @@ async function loadAgents(params: ListAgentsParams): Promise<ListAgentsResult> {
// an *optional* upper bound: relative time ranges (24H/7D/1M/3M) leave it
// off so we always include the most recent materialized rows, even if the
// browser captured `end` slightly before the materializer wrote the row.
- // Custom ranges still send both bounds.
+ // Custom ranges still send both bounds. All sources (sdk, controller,
+ // coding, both) share the same `last_seen` window — no extra staleness
+ // guard. Phantom SDK rows are prevented at write time in the materializer.
//
// Stopped-workload exception: a workload the user has Stopped no longer
// emits heartbeats, so `s.last_seen` ages out fast. We special-case it
@@ -362,37 +364,6 @@ async function loadAgents(params: ListAgentsParams): Promise<ListAgentsResult> {
);
}
- // Hide stale SDK-only rows. When a controller-managed container is recreated
- // for SDK-injection, the original `service.name` (from compose service or
- // container hostname) stops emitting and any phantom row materialized from
- // pre-recreate traces lingers in `openlit_agents_summary` until TTL (90d).
- // Filtering by `last_seen >= now() - 10 MINUTE` for source='sdk' rows lets
- // such phantoms drop out of the UI within a few minutes without waiting for
- // TTL. Controller-source rows are left untouched because they get refreshed
- // every controller heartbeat (~10s).
- where.push(
- `(s.source != 'sdk' OR s.last_seen >= now() - INTERVAL 10 MINUTE)`
- );
-
- // Same problem, different source: when a coding-agent vendor stops
- // emitting (e.g. the user disables their Claude Code plugin), the
- // materializer doesn't tombstone the row because
- // `discoverCodingAgents` only returns vendors with current data —
- // no INSERT means no new `last_materialized_at`, so the previous
- // row (with its non-zero `coding_session_count_24h` /
- // `coding_cost_usd_24h`) lingers until the 90d TTL. The hub then
- // shows e.g. "Claude Code · 6 sessions · 1 user" with clickthrough
- // landing on an empty detail page because otel_traces has no
- // matching spans. Gating on `last_materialized_at` (not
- // `last_seen` — last_seen is the timestamp of the last hosted span
- // at the time of materialization, NOT when we last refreshed)
- // hides coding rows whose materializer skipped them this round.
- // 10 minutes matches the SDK guard and gives the cron-driven
- // materializer plenty of headroom.
- where.push(
- `(s.source != 'coding' OR s.last_materialized_at >= now() - INTERVAL 10 MINUTE)`
- );
-
if (filters.source?.length) {
where.push(`s.source IN (${escapeList(filters.source)})`);
}