Skip to content

feat(hyperdx): accept flexible time inputs to fix LLM epoch-ms failures#403

Open
vibegui wants to merge 1 commit intomainfrom
vibegui/hyperdx-time-fix
Open

feat(hyperdx): accept flexible time inputs to fix LLM epoch-ms failures#403
vibegui wants to merge 1 commit intomainfrom
vibegui/hyperdx-time-fix

Conversation

@vibegui
Copy link
Copy Markdown
Contributor

@vibegui vibegui commented Apr 25, 2026

Summary

When a user asks the HyperDX agent something like "at around 14:00 GMT-3 we had a spike of errors, what was it?", the agent has to convert local time + timezone + today's date into epoch milliseconds before it can call QUERY_CHART_DATA. That math routinely fails — the LLM has no reliable current clock and falls back to guessing now from stale data (the actual screenshot from this report: "last timestamps I saw in the data were around 1777037400000 ms epoch"), so even correct TZ math against a guessed now produces a wrong window and the chart query fails.

This PR shifts the time math to the server, which has a real Date.now().

  • All 8 time-range tools (SEARCH_LOGS, GET_LOG_DETAILS, QUERY_CHART_DATA, QUERY_SPANS, QUERY_METRICS, GET_SERVICE_HEALTH, COMPARE_TIME_RANGES, DISCOVER_DATA) now accept number | string for startTime/endTime. Accepted string forms:

    • ISO 8601 with timezone — "2026-04-24T14:00:00-03:00", "…Z", "…+05:30"
    • now arithmetic — "now", "now-1h", "now+15m", compound "now-2h30m"
    • Shorthand "N ago" — "30m", "2h", "7d", compound "2h30m"
    • Date only (UTC midnight) — "2026-04-24"
    • Naive ISO without timezone is rejected with an actionable error the LLM can self-correct from.
  • New RESOLVE_TIME_RANGE tool — cheap, no-side-effect preview. The agent can call it to confirm its interpretation of ambiguous phrasing before firing a heavy chart query. Returns { startTime, endTime, startIso, endIso, durationMs, humanReadable }.

  • New HYPERDX_AGENT_GUIDE prompt resource — top-level instructions for an agent connecting to this MCP. Listed first in prompts/list so clients surface it as the natural entry point. Covers onboarding (DISCOVER_DATA first), time syntax with the GMT-3 worked example, tool selection, search essentials, and common pitfalls. Existing HYPERDX_QUERY_GUIDE also gained a Time Range Syntax section.

  • 35 unit tests in time.test.ts covering every accepted form, all rejection cases, and the regression where "1h-30m" used to emit a misleading "no timezone" error.

Backward compatible — numeric epoch ms still works everywhere; existing numeric defaults (Date.now() − 15 * 60 * 1000 etc.) are untouched.

Test plan

  • bun test hyperdx/server/lib/time.test.ts — 35/35 pass
  • tools/list exports "type": ["number","string"] for every time param with the new union description
  • RESOLVE_TIME_RANGE resolves all 4 input shapes correctly via live MCP call (epoch ms / ISO+TZ / now-1h / 2h30m)
  • Naive ISO emits "Timestamp '…' has no timezone. Append 'Z' for UTC or an offset like '-03:00'."
  • Malformed "1h-30m" emits "Could not parse '1h-30m' as a duration" (not the misleading TZ error)
  • prompts/list returns 3 prompts with HYPERDX_AGENT_GUIDE first
  • HYPERDX_AGENT_GUIDE body renders with the GMT-3 worked example and all required sections

Notes

🤖 Generated with Claude Code


Summary by cubic

Shifted time parsing to the server and added flexible time inputs across all HyperDX tools, fixing failures caused by the agent guessing epoch milliseconds. Also added a time-window preview tool and updated prompts so local times like “14:00 GMT-3” work without manual math.

  • New Features
    • All 8 time-range tools now accept number | string for startTime/endTime.
    • Accepted forms: ISO 8601 with timezone; now/now±<duration>; shorthand like 30m/2h30m; date-only YYYY-MM-DD (UTC midnight). Naive ISO without timezone is rejected with a clear fix.
    • Added RESOLVE_TIME_RANGE to preview resolved { startTime, endTime, startIso, endIso, durationMs, humanReadable } with no side effects.
    • Added HYPERDX_AGENT_GUIDE (listed first) and updated HYPERDX_QUERY_GUIDE with Time Range Syntax.
    • Backward compatible — numeric epoch ms still works; existing defaults unchanged.

Written for commit 4a0dabe. Summary will update on new commits.

…ailures

When a user asks "around 14:00 GMT-3 we had a spike of errors" the agent
had to compute epoch ms manually — and routinely guessed `now` from stale
data ("last timestamp I saw was around 1777037400000 ms"), making the
chart query fail. Shifts time math to the server, which has a real clock.

- All 8 time-range tools now accept `number | string` for time params:
  ISO 8601 with timezone, "now"/"now±<duration>", shorthand "30m"/"2h"/"7d",
  and date-only YYYY-MM-DD. Naive ISO without TZ is rejected with an
  actionable error the LLM can self-correct from.
- New RESOLVE_TIME_RANGE tool: cheap, side-effect-free preview of any
  expression pair. The agent can confirm "around 14:00 GMT-3" before
  firing a heavy chart query.
- New HYPERDX_AGENT_GUIDE prompt resource — top-level entry-point system
  prompt covering onboarding, time syntax with the GMT-3 worked example,
  tool selection, search essentials, and pitfalls. Listed first in
  prompts/list so MCP clients surface it as the natural starting point.
- Extended HYPERDX_QUERY_GUIDE with a Time Range Syntax section.
- Adds 35 unit tests in time.test.ts covering every accepted form,
  every rejection case, and the regression where "1h-30m" used to emit
  a misleading "no timezone" error.

Backward compatible: numeric epoch ms still works everywhere.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
strapi 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
meta-ads 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
data-for-seo 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
deco-llm 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
nanobanana 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
google-tag-manager 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
google-gemini 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
google-calendar-sa 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
google-calendar 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
google-big-query 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
google-drive 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
discord-read 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
readonly-sql 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
virtual-try-on 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
google-sheets 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
blog-generator 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
openrouter 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
google-slides 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
registry 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
sora 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
pinecone 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
flux 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
content-scraper 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
vtex-docs 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
whatsappagent 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
reddit 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
veo 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
slack-mcp 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
tiktok-ads 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
deco-news-weekly-digest 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
object-storage 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
pandadoc 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
multi-channel-inbox 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
whisper 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
hyperdx 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
gemini-pro-vision 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
google-meet 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
grain 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
google-search-console 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
mcp-studio 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
datajud 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
vtex 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
github-repo-reports 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
perplexity 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
farmrio-reorder-collection-db 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
replicate 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
google-forms 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

@decobot
Copy link
Copy Markdown
Collaborator

decobot commented Apr 25, 2026

The latest updates on your deployments. beta

Name Status Preview Updated
airtable 🔄 Building... Apr 25 2026, 1:50 PM (UTC)

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