Commit graph

13 commits

Author SHA1 Message Date
Virgil
976ff0141c refactor(ax): tighten remaining naming and docs
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-04 05:08:34 +00:00
Claude
3bf5496fce
ax(batch): fix abbreviated names in comment examples and locals
Some checks failed
Security Scan / security (push) Has been cancelled
Test / test (push) Has been cancelled
h→hash/histogram, e→miningError, a/b→current/previous,
n→count, user/pass→username/password, passMatch→passwordMatch
in comment examples and auth.go locals.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 18:50:29 +01:00
Claude
43e4b447ac
ax(batch): remove banned import references from comment examples
Replace all fmt.Println, fmt.Sprintf, log.Printf, log.Println, and
json.Unmarshal references in doc comments with logging.Info/logging.Warn
or direct value access patterns. Comments are examples that agents
learn from -- they must not demonstrate banned imports.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 18:07:35 +01:00
Claude
ba2e68a685
ax(mining): remove ErrCodeInternal alias in favour of canonical ErrCodeInternalError
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Two names for the same constant violates AX Principle 1 (predictable
names over short names). The alias `ErrCodeInternal` is ambiguous and
shorter than the fully-descriptive `ErrCodeInternalError`. Remove the
alias and update all five call sites to use the canonical name.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 17:52:03 +01:00
Claude
852db44e4e
ax(mining): replace prose comment with usage examples in error code block
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
AX Principle 2: comments show HOW with real values, not WHAT the block contains.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 17:39:58 +01:00
Claude
0ad11f4199
ax(mining): add usage-example comments to MiningError.Error and Unwrap
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
AX Principle 2 — comments show HOW with real values, not prose.
Error() and Unwrap() were the only exported methods on MiningError
lacking usage example comments.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 14:21:01 +01:00
Claude
ecad4f5555
ax(mining): add usage example comments to MiningError builder methods
WithCause, WithDetails, WithSuggestion, IsRetryable, and StatusCode were
exported methods with no comment — violating AX Principle 2 (comments as
usage examples).

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 13:39:31 +01:00
Claude
194c45a98b
ax(mining): replace prose struct comment with usage example
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
MiningError had "is a structured error type" — restates the declaration.
AX principle 2: comments show HOW with real values, not WHAT the signature says.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 11:24:33 +01:00
Claude
03d326a97e
ax(mining): remove banned fmt import from errors.go
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
Replace fmt.Sprintf calls with string concatenation throughout
all MiningError constructors and the Error() method.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 08:40:59 +01:00
Claude
7cf7e13b51
ax(mining): replace prose comments in errors.go with usage examples
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
AX principle 2: comments must show HOW with real values, not restate
what the function name already says. All 14 error constructor comments
converted from "ErrX creates a Y error" to concrete call-site examples.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 08:01:02 +01:00
Claude
cb27f33e57
ax(mining): replace prose method comments with usage example in errors.go
Seven MiningError method comments restated the function signature verbatim
(AX principle 2 violation). Deleted all seven and replaced NewMiningError's
comment with a concrete call-site example per the RFC rule: if a comment
restates what the type signature already says, delete it.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 07:38:00 +01:00
snider
d533164893 fix: Comprehensive code hardening from 4-domain Opus review
Error Handling:
- Fix silent Write() error in WebSocket (events.go)
- Add error context to transport handshake messages
- Check os.MkdirAll error in zip extraction (miner.go)
- Explicitly ignore io.Copy errors on drain with comments
- Add retry logic (2 attempts) for transient stats collection failures

Resource Lifecycle:
- Add shutdown mechanism to DigestAuth goroutine
- Call Service.Stop() on context cancellation
- Add NodeService transport cleanup to Service.Stop()
- Fix WriteStdin goroutine leak on timeout with non-blocking send

API Design:
- Add profile validation (name, miner type required)
- Return 404 instead of 500 for missing profile PUT
- Make DELETE profile idempotent (return success if not found)
- Standardize error responses in node_service.go handlers

Observability:
- Add logging for P2P GetAllStats failures
- Add request ID correlation helper for handler logs
- Add logging for miner process exits (xmrig_start.go)
- Rate limit debug logs in transport hot path (1 in 100)
- Add metrics infrastructure with /metrics endpoint

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 14:33:30 +00:00
snider
95ae55e4fa feat: Add rate limiter with cleanup and custom error types
Rate Limiter:
- Extract rate limiting to pkg/mining/ratelimiter.go with proper lifecycle
- Add Stop() method to gracefully shutdown cleanup goroutine
- Add RateLimiter.Middleware() for Gin integration
- Add ClientCount() for monitoring
- Fix goroutine leak in previous inline implementation

Custom Errors:
- Add pkg/mining/errors.go with MiningError type
- Define error codes: MINER_NOT_FOUND, INSTALL_FAILED, TIMEOUT, etc.
- Add predefined error constructors (ErrMinerNotFound, ErrStartFailed, etc.)
- Support error chaining with WithCause, WithDetails, WithSuggestion
- Include HTTP status codes and retry policies

Service:
- Add Service.Stop() method for graceful cleanup
- Update CLI commands to use context.Background() for Manager methods

Tests:
- Add comprehensive tests for RateLimiter (token bucket, multi-IP, refill)
- Add comprehensive tests for MiningError (codes, status, retryable)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 10:56:26 +00:00