Skip to content

feat(cli): declare agent runs via x-checkly-source: AGENT [ship]#1412

Open
martzoukos wants to merge 1 commit into
mainfrom
martzoukos/ai-454-agent-source-header
Open

feat(cli): declare agent runs via x-checkly-source: AGENT [ship]#1412
martzoukos wants to merge 1 commit into
mainfrom
martzoukos/ai-454-agent-source-header

Conversation

@martzoukos

Copy link
Copy Markdown
Contributor

What

When the CLI is driven by an agent (detectCliMode() === 'agent'), send x-checkly-source: AGENT on API requests instead of the hardcoded CLI.

- config.headers['x-checkly-source'] = 'CLI'
+ config.headers['x-checkly-source'] = detectCliMode() === 'agent' ? 'AGENT' : 'CLI'

Why

Authentication can't distinguish an agent from a human — they share the same API key. The backend needs a self-declared signal to tell agent-created import plans apart from human ones, so it can safely garbage-collect abandoned agent onboarding reservations (agent onboarding reserves pending mappings server-side that outlive the throwaway sandbox; if the user never finalizes with checkly import commit, they'd linger forever).

detectCliMode() already returns 'agent' for agent-driven runs — including when the AI runner sets CHECKLY_CLI_MODE=agent — so this just routes that existing signal onto the source header. Composes with the agent-drivable import flow from #1402.

Backend counterpart

The backend adds AGENT to its client-source vocabulary, persists this header onto the import plan's new source column, and runs a daily reaper over source = 'AGENT' AND committedAt IS NULL AND createdAt < now() - TTL. This CLI change is what makes source = 'AGENT' actually get set.

Testing

  • New rest/__tests__/request-interceptor.spec.ts: asserts AGENT in agent mode, CLI for interactive/CI.
  • Existing detectOperator suite unaffected (16/16 green together); tsc + eslint clean.

Note: no [ship] tag — leaving the release call to maintainers.

🤖 Generated with Claude Code

When the CLI is driven by an agent (detectCliMode() === 'agent'), send
`x-checkly-source: AGENT` instead of `CLI` on API requests. Auth can't tell
an agent from a human (same API key), so the backend keys off this header to
tell agent-created import plans apart from human ones and to safely GC
abandoned agent onboarding reservations.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@martzoukos martzoukos changed the title feat(cli): declare agent runs via x-checkly-source: AGENT feat(cli): declare agent runs via x-checkly-source: AGENT [ship] Jul 16, 2026
@martzoukos
martzoukos enabled auto-merge (squash) July 16, 2026 14:23

@github-actions github-actions 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.

Auto-approved: ship/show PR from a same-repo branch.

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