Summary
Six production code paths in pkg/cli/ call time.Sleep with hardcoded literal durations instead of the project's established named-constant pattern. This breaks the consistency model that R8 (HTTP timeouts → constants) and the existing APICallCooldown / backupCleanupRetryDelay / timestampDifferentiationDelay named constants set up.
This is #aw_sg17a2, identified in Sergo Run 17.
Evidence
Magic-literal sites (prod code)
| File:Line |
Sleep |
Purpose (from inline comment) |
pkg/cli/trial_repository.go:153 |
2 * time.Second |
"Give GitHub a moment to fully initialize the repository" |
pkg/cli/run_workflow_execution.go:571 |
1 * time.Second |
"Add a small delay between workflows to avoid overwhelming GitHub API" |
pkg/cli/mcp_inspect_inspector.go:157 |
2 * time.Second |
"Give servers a moment to start up" |
pkg/cli/mcp_inspect_inspector.go:201 |
100 * time.Millisecond |
"Give each process a chance to clean up" |
pkg/cli/mcp_inspect_mcp_scripts_server.go:62 |
200 * time.Millisecond |
(startup-pace gate) |
pkg/cli/mcp_inspect.go:134 |
500 * time.Millisecond |
(startup-pace gate) |
Comparison: established named-constant pattern (good citizens)
pkg/cli/logs_rate_limit.go:87, 97, 110, 121 — uses APICallCooldown (a typed Duration constant). Four sites, one symbol.
pkg/cli/update_extension_check.go:386 — uses backupCleanupRetryDelay.
pkg/workflow/compiler_skip_write_test.go:58, 126 — uses timestampDifferentiationDelay.
pkg/cli/run_workflow_tracking.go:73 — uses a delay variable derived from caller context (also acceptable: not a magic literal).
The pattern is clear and adopted across pkg/cli/: when a sleep duration encodes a policy decision (rate-limit pacing, GitHub propagation lag, IPC startup wait), it lives in a named time.Duration constant near the code that uses it.
Severity
Medium (consistency / maintainability). No correctness bug today. But:
- Tuning these durations means hunting through call-site code instead of editing one symbol.
- New contributors learn the wrong pattern by copy-paste.
- Tests that mock time (or want to run faster) cannot inject a smaller value.
- The "why this number" justification lives in adjacent comments, not the symbol name.
Recommendation
Replace each literal with a package-level const (or var if it should be overridable in tests). Suggested names:
// pkg/cli/trial_repository.go
const trialRepoInitDelay = 2 * time.Second
// pkg/cli/run_workflow_execution.go
const betweenWorkflowsDelay = 1 * time.Second
// pkg/cli/mcp_inspect_inspector.go
const (
mcpStdioServerStartupDelay = 2 * time.Second
mcpProcessCleanupDelay = 100 * time.Millisecond
)
// pkg/cli/mcp_inspect_mcp_scripts_server.go
const mcpScriptsServerStartupDelay = 200 * time.Millisecond
// pkg/cli/mcp_inspect.go
const mcpInspectorStartupDelay = 500 * time.Millisecond
Group related constants (the two mcp_inspect_inspector.go sleeps) into a single const ( ... ) block.
Validation
Related
- R8 #aw_sg8a2 (HTTP timeout literals → constants, FIXED R12, 4 sites) — exact same refactor shape.
- R8 #aw_sg8a1 (file-mode octal literals, FIXED R9, 57 sites) — same "magic literal → named constant" theme.
- Established pattern in
pkg/constants/constants.go for Default* symbols.
References:
Generated by 🤖 Sergo - Serena Go Expert · ● opu47 18.5M · ◷
Summary
Six production code paths in
pkg/cli/calltime.Sleepwith hardcoded literal durations instead of the project's established named-constant pattern. This breaks the consistency model that R8 (HTTP timeouts → constants) and the existingAPICallCooldown/backupCleanupRetryDelay/timestampDifferentiationDelaynamed constants set up.This is #aw_sg17a2, identified in Sergo Run 17.
Evidence
Magic-literal sites (prod code)
pkg/cli/trial_repository.go:1532 * time.Secondpkg/cli/run_workflow_execution.go:5711 * time.Secondpkg/cli/mcp_inspect_inspector.go:1572 * time.Secondpkg/cli/mcp_inspect_inspector.go:201100 * time.Millisecondpkg/cli/mcp_inspect_mcp_scripts_server.go:62200 * time.Millisecondpkg/cli/mcp_inspect.go:134500 * time.MillisecondComparison: established named-constant pattern (good citizens)
pkg/cli/logs_rate_limit.go:87, 97, 110, 121— usesAPICallCooldown(a typed Duration constant). Four sites, one symbol.pkg/cli/update_extension_check.go:386— usesbackupCleanupRetryDelay.pkg/workflow/compiler_skip_write_test.go:58, 126— usestimestampDifferentiationDelay.pkg/cli/run_workflow_tracking.go:73— uses adelayvariable derived from caller context (also acceptable: not a magic literal).The pattern is clear and adopted across
pkg/cli/: when a sleep duration encodes a policy decision (rate-limit pacing, GitHub propagation lag, IPC startup wait), it lives in a namedtime.Durationconstant near the code that uses it.Severity
Medium (consistency / maintainability). No correctness bug today. But:
Recommendation
Replace each literal with a package-level
const(orvarif it should be overridable in tests). Suggested names:Group related constants (the two
mcp_inspect_inspector.gosleeps) into a singleconst ( ... )block.Validation
go vet ./pkg/cli/...andgo test ./pkg/cli/....Related
pkg/constants/constants.goforDefault*symbols.References: