Skip to content

add operationMetrics to core, add registry to trueforge server - #1075

Open
ramantehlan wants to merge 22 commits into
mainfrom
sd/additional-metrics
Open

ramantehlan wants to merge 22 commits into
mainfrom
sd/additional-metrics

Conversation

@ramantehlan

@ramantehlan ramantehlan commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #

Changes

How was this tested?

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/trueforge-sdk, python/trueforge_sdk, .github/fern/openapi/openapi.json, docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge
  • Docs / .env.example updated if configuration or behavior changed

Note

Medium Risk
Broad instrumentation touches turn persistence, outbound HTTP, LLM/MCP paths, and the metrics scrape endpoint; behavior is mostly additive when metrics are omitted, but mis-wiring could affect hot paths or scrape reliability.

Overview
Adds an optional OperationMetrics hook in trueforge-core so hosts can record harness behavior without importing a metrics client, and wires a Prometheus implementation in trueforge on the existing GET /metrics registry.

Instrumentation spans outbound HTTP (generic/model/MCP pools, retries, blocked URLs), LLM streams (duration, TTFT, stream errors by provider), MCP connect/ops/disconnect/session retry, tool calls (outcome + duration by server class), harness limits (iteration, large tool responses, context compaction, MCP response size), active threads/turns, turn lifetime and persist failures, turn timeouts/SSE disconnects, Parallel web search/extract, ServiceFoundry calls, and Postgres query duration. ITurnResourceResolver and turn construction pass operationMetrics through orchestrator, threads, builtins, sandbox, and RemoteMCP.

Server wiring: shared httpMetrics.registry, createOperationMetrics, outbound fetch metrics at boot, Postgres Kysely logging, ActiveTurnRegistry gauges, turns/schedules APIs; GET /metrics also appends OpenTelemetry text for Daytona and Redis SDK meters. Core exports types/helpers (observeMcpOperation, elapsedSeconds, OUTBOUND_URL_BLOCKED).

Reviewed by Cursor Bugbot for commit b77bf03. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b77bf03

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@truefoundry/trueforge Patch
@truefoundry/trueforge-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/trueforge-core/src/core/observability/operationMetrics.ts Outdated
Comment thread packages/trueforge/src/app.ts Outdated
Comment thread packages/trueforge/src/observability/agentMetrics.ts Outdated
Comment thread packages/trueforge/src/main.ts Outdated

@chiragjn chiragjn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Basic approach looking good

Comment thread packages/trueforge-core/src/core/util/ssrfGuard.ts
Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/trueforge-core/src/core/observability/operationMetrics.ts Outdated
UNPROCESSED_RETRY_STATUSES and MAYBE_PROCESSED_RETRY_STATUSES choose which responses replay. Tests check request outcome, status class, and retry counts.

Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
These files stay on disk for local runs and should not ship with the branch.

Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
OpenAPI generation creates the same registry as the server, and turn and schedule wiring always receives the recorder.

Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
The collectDefaultMetrics switch had no caller.

Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
The metrics cases added here are dropped. The rest of the file stays.

Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
The Vercel stream test is back to its previous coverage.

Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
The retry label is the status that was replayed. Status class and blocked-request checks only need the error or the single wrap under it.

Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
…am errors.

Both series were classifying the same status ranges in separate helpers.

Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/trueforge-core/src/agent-session/TurnHandle.ts
Comment thread packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts Outdated
…ror.

Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>
Signed-off-by: Raman Tehlan <ramantehlan@gmail.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0d3733d. Configure here.

Comment thread packages/trueforge/src/http/prometheus.ts

@chiragjn chiragjn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is fine for trueforge-core to be prometheus metrics aware

It can take prom registry at server init time
and internally it can keep emitting metrics with util functions wherever needed

https://github.com/truefoundry/tfy-llm-gateway/blob/main/src/metrics/helpers.ts#L168

This branch has not been deployed

No deployments
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