Skip to content

feat: [CLI-56856]: Add configurable request timeout#94

Open
dtsong-harness wants to merge 4 commits intoharness:mainfrom
dtsong-harness:feat/configurable-timeout
Open

feat: [CLI-56856]: Add configurable request timeout#94
dtsong-harness wants to merge 4 commits intoharness:mainfrom
dtsong-harness:feat/configurable-timeout

Conversation

@dtsong-harness
Copy link
Copy Markdown
Contributor

@dtsong-harness dtsong-harness commented Apr 9, 2026

Summary

  • Adds a --timeout global flag (default: no timeout) to configure the HTTP request timeout for API calls
  • Supports HARNESS_TIMEOUT_SECONDS environment variable as an alternative to the flag
  • Replaces hardcoded 10-second timeout in util/client/iacm/iacm-client.go

Motivation

The 10-second hardcoded timeout causes failures for API calls that legitimately take longer (e.g., large account queries, migration jobs, slow network conditions). Users currently have no way to increase this without switching to raw curl calls.

By defaulting to no timeout (0), long-running commands like migrations work out of the box, while users can set a timeout if desired.

Usage

# Via flag (set 30-second timeout)
hc iacm plan --timeout 30 --org myorg --project myproject --workspace myworkspace

# Via environment variable
export HARNESS_TIMEOUT_SECONDS=30
hc iacm plan --org myorg --project myproject --workspace myworkspace

# Default behavior: no timeout
hc iacm plan --org myorg --project myproject --workspace myworkspace

Changes

File Change
config/globals.go Added TimeoutSeconds field and DefaultTimeoutSeconds constant (default: 0)
cmd/hc/main.go Registered --timeout persistent flag, HARNESS_TIMEOUT_SECONDS env var, and input validation
util/client/iacm/iacm-client.go Uses configurable timeout instead of hardcoded 10s

Test plan

  • go build ./cmd/hc/ compiles successfully
  • go test ./... — all existing tests pass
  • hc --help shows --timeout flag with "default: no timeout"
  • Manual: hc --timeout 30 iacm plan ... uses 30s timeout
  • Manual: HARNESS_TIMEOUT_SECONDS=30 hc iacm plan ... uses 30s timeout
  • Manual: negative timeout value is rejected with error

🤖 Generated with Claude Code

…_TIMEOUT env var

The HTTP request timeout was hardcoded to 10 seconds across the CLI, causing
failures for API calls that legitimately take longer. This adds a --timeout
global flag (default 10s) and HARNESS_TIMEOUT environment variable so users
can increase the timeout as needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 9, 2026

CLA assistant check
All committers have signed the CLA.

Comment thread cmd/hc/main.go Outdated
Comment thread cmd/hc/main.go Outdated
Comment thread config/globals.go Outdated
Comment thread cmd/auth/login.go Outdated
- Rename env var from HARNESS_TIMEOUT to HARNESS_TIMEOUT_SECONDS for clarity
- Error and exit on invalid HARNESS_TIMEOUT_SECONDS value instead of silently ignoring
- Remove redundant default in GlobalFlags struct (already set via flag default in main.go)
- Revert login.go to hardcoded 10s timeout since it's a one-off client

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread cmd/hc/main.go
config.Global.ProjectID = envVal
}
if envVal := os.Getenv("HARNESS_TIMEOUT_SECONDS"); envVal != "" {
timeout, err := strconv.Atoi(envVal)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is user input. So a sanity check on the value range may be useful. timeout should be within a range, maybe [0, 3600]? I don't think the server will have a timeout of 1 hour.

Validates --timeout flag and HARNESS_TIMEOUT_SECONDS are within [0, 3600]
to prevent unreasonable timeout values from user input.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove max timeout cap and default to 0 (no timeout) since long-running
commands like migrations need unbounded time.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dtsong-harness dtsong-harness changed the title feat: add configurable request timeout feat: [CLI-56856]: Add configurable request timeout Apr 10, 2026
@dtsong-harness dtsong-harness changed the title feat: [CLI-56856]: Add configurable request timeout feat: add configurable request timeout via --timeout flag and HARNESS_TIMEOUT env var Apr 10, 2026
@dtsong-harness dtsong-harness changed the title feat: add configurable request timeout via --timeout flag and HARNESS_TIMEOUT env var feat: [CLI-56856]: Add configurable request timeout Apr 10, 2026
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.

3 participants