Skip to content

Add Trigger agent cost observability - #904

Merged
ross0x01 merged 1 commit into
mainfrom
codex/trigger-agent-cost-observability
Jul 15, 2026
Merged

Add Trigger agent cost observability#904
ross0x01 merged 1 commit into
mainfrom
codex/trigger-agent-cost-observability

Conversation

@ross0x01

@ross0x01 ross0x01 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • tag every initial agent-long Trigger run with permission_full_access or permission_ask_approval
  • add Trigger run ID, billed usage duration, and total Trigger cost to hackerai-agent_run
  • aggregate approval wait count/wall time plus active model-stream, terminal-wait, and sandbox-recovery durations
  • preserve zero-valued telemetry and cover the wiring with regression tests

Validation

  • jest --runInBand --no-cache lib/api/__tests__/chat-logger.test.ts lib/chat/__tests__/agent-run-timing.test.ts lib/api/__tests__/agent-long-contracts.test.ts lib/ai/tools/__tests__/run-terminal-cmd.test.ts lib/ai/tools/__tests__/interact-terminal-session.test.ts (144 tests passed)
  • tsc --noEmit --incremental false
  • changed-file ESLint
  • full ESLint (0 errors; 6 existing warnings)
  • Prettier check and git diff --check

Summary by CodeRabbit

  • New Features

    • Added detailed agent-run timing and cost telemetry, including model streaming, terminal waits, sandbox recovery, and approval waits.
    • Agent runs now include permission-mode metadata for improved tracking.
    • Analytics capture expanded trigger usage, cost, timing, and recovery metrics.
  • Bug Fixes

    • Ensured timing metrics are recorded even when terminal operations or other measured tasks fail.
    • Improved sandbox recovery tracking and readiness verification.

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hackerai Ready Ready Preview, Comment Jul 15, 2026 9:49pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b6d87d66-176a-4239-812b-4558163c765b

📥 Commits

Reviewing files that changed from the base of the PR and between 5d2a9a4 and f0079ec.

📒 Files selected for processing (12)
  • lib/ai/tools/index.ts
  • lib/ai/tools/interact-terminal-session.ts
  • lib/ai/tools/run-terminal-cmd.ts
  • lib/api/__tests__/agent-long-contracts.test.ts
  • lib/api/__tests__/chat-logger.test.ts
  • lib/api/agent-stream-runner.ts
  • lib/api/agent-trigger-route.ts
  • lib/api/chat-logger.ts
  • lib/chat/__tests__/agent-run-timing.test.ts
  • lib/chat/agent-run-timing.ts
  • trigger/agent-long.ts
  • types/agent.ts

📝 Walkthrough

Walkthrough

Agent runs now track approval waits, model streaming, terminal waits, sandbox recovery, Trigger usage, and cost. The telemetry flows through tool and stream contexts into completion analytics, while Trigger tags include the requested permission mode.

Changes

Agent Runtime Telemetry

Layer / File(s) Summary
Timing contracts and tracker
types/agent.ts, lib/chat/agent-run-timing.ts, lib/chat/__tests__/agent-run-timing.test.ts
Adds active-time categories, timing snapshots, and AgentRunTimingTracker coverage for approval waits, model streams, measured operations, and error handling.
Execution timing instrumentation
lib/ai/tools/index.ts, lib/ai/tools/interact-terminal-session.ts, lib/ai/tools/run-terminal-cmd.ts, lib/api/agent-stream-runner.ts, trigger/agent-long.ts, lib/api/__tests__/agent-long-contracts.test.ts
Wraps terminal waits and sandbox recovery, connects approval-wait tracking, and adds model stream lifecycle callbacks to the agent execution flow.
Completion telemetry and analytics
trigger/agent-long.ts, lib/api/chat-logger.ts, lib/api/__tests__/chat-logger.test.ts, lib/api/__tests__/agent-long-contracts.test.ts
Combines Trigger usage with timing snapshots and forwards trigger duration, cost, approval, streaming, terminal, and recovery metrics to hackerai-agent_run.
Trigger permission metadata
lib/api/agent-trigger-route.ts, lib/api/__tests__/agent-long-contracts.test.ts
Adds a permission-mode tag to triggered agent runs and verifies queued trigger metadata and status fields.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AgentRun
  participant AgentStreamRunner
  participant TerminalTools
  participant TimingTracker
  participant Analytics
  AgentRun->>AgentStreamRunner: start and finish model stream timing
  AgentRun->>TerminalTools: provide active-time measurer
  TerminalTools->>TimingTracker: record terminal wait or sandbox recovery
  AgentRun->>TimingTracker: record approval waits
  AgentRun->>Analytics: submit Trigger usage and timing snapshot
  Analytics->>Analytics: emit hackerai-agent_run properties
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main focus on Trigger agent cost and telemetry observability.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/trigger-agent-cost-observability

Comment @coderabbitai help to get the list of available commands.

@ross0x01
ross0x01 marked this pull request as ready for review July 15, 2026 21:49
@ross0x01
ross0x01 merged commit fb6161d into main Jul 15, 2026
5 checks passed
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