fix(lint): clean rebased subagent findings
- commit
- 733daadf13a0860b4f5e732eeec71435bcaf525f
- author
- brice · · 2026-08-05 04:46 UTC
- parent
- 9e6e5b7
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
5 files · +9 -51
M packages/agent/subagents/agent.go +0 -9
| @@ -370,15 +370,6 @@ func (a *Agent) SetOnTurnEnd(fn func(step int, errMsg string)) { | |||
| 370 | 370 | } | |
| 371 | 371 | } | |
| 372 | 372 | ||
| 373 | - | func (a *Agent) setStatus(s Status) { | |
| 374 | - | a.mu.Lock() | |
| 375 | - | a.status = s | |
| 376 | - | a.mu.Unlock() | |
| 377 | - | if s == StatusRunning { | |
| 378 | - | a.setProcessState(ProcessAlive) | |
| 379 | - | } | |
| 380 | - | } | |
| 381 | - | ||
| 382 | 373 | func (a *Agent) setActivity(msg string) { | |
| 383 | 374 | a.mu.Lock() | |
| 384 | 375 | a.activity = strings.TrimSpace(msg) | |
| @@ -370,15 +370,6 @@ func (a *Agent) SetOnTurnEnd(fn func(step int, errMsg string)) { | |||||
| 370 | } | 370 | } | ||
| 371 | } | 371 | } | ||
| 372 | 372 | ||||
| 373 | - | func (a *Agent) setStatus(s Status) { | |||
| 374 | - | a.mu.Lock() | |||
| 375 | - | a.status = s | |||
| 376 | - | a.mu.Unlock() | |||
| 377 | - | if s == StatusRunning { | |||
| 378 | - | a.setProcessState(ProcessAlive) | |||
| 379 | - | } | |||
| 380 | - | } | |||
| 381 | - | ||||
| 382 | func (a *Agent) setActivity(msg string) { | 373 | func (a *Agent) setActivity(msg string) { | ||
| 383 | a.mu.Lock() | 374 | a.mu.Lock() | ||
| 384 | a.activity = strings.TrimSpace(msg) | 375 | a.activity = strings.TrimSpace(msg) | ||
M packages/agent/subagents/event.go +1 -1
| @@ -297,7 +297,7 @@ func readFollowerEvents(r io.Reader, offset int64) ([]Event, int64) { | |||
| 297 | 297 | ring := newEventRing() | |
| 298 | 298 | committed := offset | |
| 299 | 299 | for { | |
| 300 | - | line, err, truncated, consumed, complete := readBoundedLineStats(br, maxEventLogLineBytes) | |
| 300 | + | line, truncated, consumed, complete, err := readBoundedLineStats(br, maxEventLogLineBytes) | |
| 301 | 301 | if !complete { | |
| 302 | 302 | break | |
| 303 | 303 | } | |
| @@ -297,7 +297,7 @@ func readFollowerEvents(r io.Reader, offset int64) ([]Event, int64) { | |||||
| 297 | ring := newEventRing() | 297 | ring := newEventRing() | ||
| 298 | committed := offset | 298 | committed := offset | ||
| 299 | for { | 299 | for { | ||
| 300 | - | line, err, truncated, consumed, complete := readBoundedLineStats(br, maxEventLogLineBytes) | 300 | + | line, truncated, consumed, complete, err := readBoundedLineStats(br, maxEventLogLineBytes) |
| 301 | if !complete { | 301 | if !complete { | ||
| 302 | break | 302 | break | ||
| 303 | } | 303 | } | ||
M packages/agent/subagents/persist.go +4 -3
| @@ -470,11 +470,12 @@ func replayEventsIntoAgent(a *Agent, evs []Event) { | |||
| 470 | 470 | case EventTurnResult, "turn_result": | |
| 471 | 471 | if result, err := decodeTurnResultEvent(ev, a.ID, a.maxOutputBytes, a.maxOutputLines); err == nil { | |
| 472 | 472 | a.setResult(result) | |
| 473 | - | if result.Status == ResultFailed { | |
| 473 | + | switch result.Status { | |
| 474 | + | case ResultFailed: | |
| 474 | 475 | a.setTurnState(TurnFailed, result.TurnID) | |
| 475 | - | } else if result.Status == ResultCanceled { | |
| 476 | + | case ResultCanceled: | |
| 476 | 477 | a.setTurnState(TurnCanceled, result.TurnID) | |
| 477 | - | } else { | |
| 478 | + | default: | |
| 478 | 479 | a.setTurnState(TurnSucceeded, result.TurnID) | |
| 479 | 480 | } | |
| 480 | 481 | } | |
| @@ -470,11 +470,12 @@ func replayEventsIntoAgent(a *Agent, evs []Event) { | |||||
| 470 | case EventTurnResult, "turn_result": | 470 | case EventTurnResult, "turn_result": | ||
| 471 | if result, err := decodeTurnResultEvent(ev, a.ID, a.maxOutputBytes, a.maxOutputLines); err == nil { | 471 | if result, err := decodeTurnResultEvent(ev, a.ID, a.maxOutputBytes, a.maxOutputLines); err == nil { | ||
| 472 | a.setResult(result) | 472 | a.setResult(result) | ||
| 473 | - | if result.Status == ResultFailed { | 473 | + | switch result.Status { |
| 474 | + | case ResultFailed: | |||
| 474 | a.setTurnState(TurnFailed, result.TurnID) | 475 | a.setTurnState(TurnFailed, result.TurnID) | ||
| 475 | - | } else if result.Status == ResultCanceled { | 476 | + | case ResultCanceled: |
| 476 | a.setTurnState(TurnCanceled, result.TurnID) | 477 | a.setTurnState(TurnCanceled, result.TurnID) | ||
| 477 | - | } else { | 478 | + | default: |
| 478 | a.setTurnState(TurnSucceeded, result.TurnID) | 479 | a.setTurnState(TurnSucceeded, result.TurnID) | ||
| 479 | } | 480 | } | ||
| 480 | } | 481 | } | ||
M packages/agent/subagents/runner.go +4 -24
| @@ -6,7 +6,6 @@ import ( | |||
| 6 | 6 | "context" | |
| 7 | 7 | "encoding/json" | |
| 8 | 8 | "fmt" | |
| 9 | - | "io" | |
| 10 | 9 | "os" | |
| 11 | 10 | "os/exec" | |
| 12 | 11 | "path/filepath" | |
| @@ -403,7 +402,7 @@ func workerEnvironment(provider string) []string { | |||
| 403 | 402 | var env []string | |
| 404 | 403 | for _, entry := range os.Environ() { | |
| 405 | 404 | name, _, ok := strings.Cut(entry, "=") | |
| 406 | - | if ok && workerSecretEnvName(name) && !(provider == "amazon-bedrock" && isBedrockCredentialEnv(name)) { | |
| 405 | + | if ok && workerSecretEnvName(name) && (provider != "amazon-bedrock" || !isBedrockCredentialEnv(name)) { | |
| 407 | 406 | continue | |
| 408 | 407 | } | |
| 409 | 408 | env = append(env, entry) | |
| @@ -436,7 +435,7 @@ func workerSecretEnvName(name string) bool { | |||
| 436 | 435 | } | |
| 437 | 436 | ||
| 438 | 437 | func readBoundedLine(r *bufio.Reader, limit int) ([]byte, error, bool) { | |
| 439 | - | line, err, truncated, _, _ := readBoundedLineStats(r, limit) | |
| 438 | + | line, truncated, _, _, err := readBoundedLineStats(r, limit) | |
| 440 | 439 | return line, err, truncated | |
| 441 | 440 | } | |
| 442 | 441 | ||
| @@ -444,7 +443,7 @@ func readBoundedLine(r *bufio.Reader, limit int) ([]byte, error, bool) { | |||
| 444 | 443 | // number of source bytes consumed and whether a newline terminated the record. | |
| 445 | 444 | // The follower uses those extra values to avoid advancing past a partial final | |
| 446 | 445 | // JSONL record that may be completed by a concurrent append. | |
| 447 | - | func readBoundedLineStats(r *bufio.Reader, limit int) ([]byte, error, bool, int64, bool) { | |
| 446 | + | func readBoundedLineStats(r *bufio.Reader, limit int) ([]byte, bool, int64, bool, error) { | |
| 448 | 447 | if limit <= 0 { | |
| 449 | 448 | limit = 512 * 1024 | |
| 450 | 449 | } | |
| @@ -467,7 +466,7 @@ func readBoundedLineStats(r *bufio.Reader, limit int) ([]byte, error, bool, int6 | |||
| 467 | 466 | } | |
| 468 | 467 | } | |
| 469 | 468 | if err != bufio.ErrBufferFull { | |
| 470 | - | return line, err, truncated, consumed, len(chunk) > 0 && chunk[len(chunk)-1] == '\n' | |
| 469 | + | return line, truncated, consumed, len(chunk) > 0 && chunk[len(chunk)-1] == '\n', err | |
| 471 | 470 | } | |
| 472 | 471 | } | |
| 473 | 472 | } | |
| @@ -684,22 +683,3 @@ func applyEventToSink(ev Event, sink Sink) { | |||
| 684 | 683 | type RunnerFunc func(ctx context.Context, sink Sink) error | |
| 685 | 684 | ||
| 686 | 685 | func (f RunnerFunc) Run(ctx context.Context, sink Sink) error { return f(ctx, sink) } | |
| 687 | - | ||
| 688 | - | // streamLines kept around for any caller still using it directly. | |
| 689 | - | // | |
| 690 | - | // Deprecated: the runner now parses JSONL from stdout via | |
| 691 | - | // parseEventLine; this helper is unused inside the package but | |
| 692 | - | // remains exported via internal use by tests in the runner_test | |
| 693 | - | // suite that pre-date the daemon switch. | |
| 694 | - | func streamLines(r io.Reader, fn func(string)) { | |
| 695 | - | br := bufio.NewReader(r) | |
| 696 | - | for { | |
| 697 | - | line, err := br.ReadString('\n') | |
| 698 | - | if line != "" { | |
| 699 | - | fn(strings.TrimRight(line, "\r\n")) | |
| 700 | - | } | |
| 701 | - | if err != nil { | |
| 702 | - | return | |
| 703 | - | } | |
| 704 | - | } | |
| 705 | - | } | |
| @@ -6,7 +6,6 @@ import ( | |||||
| 6 | "context" | 6 | "context" | ||
| 7 | "encoding/json" | 7 | "encoding/json" | ||
| 8 | "fmt" | 8 | "fmt" | ||
| 9 | - | "io" | |||
| 10 | "os" | 9 | "os" | ||
| 11 | "os/exec" | 10 | "os/exec" | ||
| 12 | "path/filepath" | 11 | "path/filepath" | ||
| @@ -403,7 +402,7 @@ func workerEnvironment(provider string) []string { | |||||
| 403 | var env []string | 402 | var env []string | ||
| 404 | for _, entry := range os.Environ() { | 403 | for _, entry := range os.Environ() { | ||
| 405 | name, _, ok := strings.Cut(entry, "=") | 404 | name, _, ok := strings.Cut(entry, "=") | ||
| 406 | - | if ok && workerSecretEnvName(name) && !(provider == "amazon-bedrock" && isBedrockCredentialEnv(name)) { | 405 | + | if ok && workerSecretEnvName(name) && (provider != "amazon-bedrock" || !isBedrockCredentialEnv(name)) { |
| 407 | continue | 406 | continue | ||
| 408 | } | 407 | } | ||
| 409 | env = append(env, entry) | 408 | env = append(env, entry) | ||
| @@ -436,7 +435,7 @@ func workerSecretEnvName(name string) bool { | |||||
| 436 | } | 435 | } | ||
| 437 | 436 | ||||
| 438 | func readBoundedLine(r *bufio.Reader, limit int) ([]byte, error, bool) { | 437 | func readBoundedLine(r *bufio.Reader, limit int) ([]byte, error, bool) { | ||
| 439 | - | line, err, truncated, _, _ := readBoundedLineStats(r, limit) | 438 | + | line, truncated, _, _, err := readBoundedLineStats(r, limit) |
| 440 | return line, err, truncated | 439 | return line, err, truncated | ||
| 441 | } | 440 | } | ||
| 442 | 441 | ||||
| @@ -444,7 +443,7 @@ func readBoundedLine(r *bufio.Reader, limit int) ([]byte, error, bool) { | |||||
| 444 | // number of source bytes consumed and whether a newline terminated the record. | 443 | // number of source bytes consumed and whether a newline terminated the record. | ||
| 445 | // The follower uses those extra values to avoid advancing past a partial final | 444 | // The follower uses those extra values to avoid advancing past a partial final | ||
| 446 | // JSONL record that may be completed by a concurrent append. | 445 | // JSONL record that may be completed by a concurrent append. | ||
| 447 | - | func readBoundedLineStats(r *bufio.Reader, limit int) ([]byte, error, bool, int64, bool) { | 446 | + | func readBoundedLineStats(r *bufio.Reader, limit int) ([]byte, bool, int64, bool, error) { |
| 448 | if limit <= 0 { | 447 | if limit <= 0 { | ||
| 449 | limit = 512 * 1024 | 448 | limit = 512 * 1024 | ||
| 450 | } | 449 | } | ||
| @@ -467,7 +466,7 @@ func readBoundedLineStats(r *bufio.Reader, limit int) ([]byte, error, bool, int6 | |||||
| 467 | } | 466 | } | ||
| 468 | } | 467 | } | ||
| 469 | if err != bufio.ErrBufferFull { | 468 | if err != bufio.ErrBufferFull { | ||
| 470 | - | return line, err, truncated, consumed, len(chunk) > 0 && chunk[len(chunk)-1] == '\n' | 469 | + | return line, truncated, consumed, len(chunk) > 0 && chunk[len(chunk)-1] == '\n', err |
| 471 | } | 470 | } | ||
| 472 | } | 471 | } | ||
| 473 | } | 472 | } | ||
| @@ -684,22 +683,3 @@ func applyEventToSink(ev Event, sink Sink) { | |||||
| 684 | type RunnerFunc func(ctx context.Context, sink Sink) error | 683 | type RunnerFunc func(ctx context.Context, sink Sink) error | ||
| 685 | 684 | ||||
| 686 | func (f RunnerFunc) Run(ctx context.Context, sink Sink) error { return f(ctx, sink) } | 685 | func (f RunnerFunc) Run(ctx context.Context, sink Sink) error { return f(ctx, sink) } | ||
| 687 | - | ||||
| 688 | - | // streamLines kept around for any caller still using it directly. | |||
| 689 | - | // | |||
| 690 | - | // Deprecated: the runner now parses JSONL from stdout via | |||
| 691 | - | // parseEventLine; this helper is unused inside the package but | |||
| 692 | - | // remains exported via internal use by tests in the runner_test | |||
| 693 | - | // suite that pre-date the daemon switch. | |||
| 694 | - | func streamLines(r io.Reader, fn func(string)) { | |||
| 695 | - | br := bufio.NewReader(r) | |||
| 696 | - | for { | |||
| 697 | - | line, err := br.ReadString('\n') | |||
| 698 | - | if line != "" { | |||
| 699 | - | fn(strings.TrimRight(line, "\r\n")) | |||
| 700 | - | } | |||
| 701 | - | if err != nil { | |||
| 702 | - | return | |||
| 703 | - | } | |||
| 704 | - | } | |||
| 705 | - | } | |||
M packages/agent/subagents/scheduler.go +0 -14
| @@ -278,20 +278,6 @@ func (f *Supervisor) armQueueTimeout(a *Agent) { | |||
| 278 | 278 | ||
| 279 | 279 | func (f *Supervisor) expireQueued(id string) { f.cancelQueued(id, context.DeadlineExceeded) } | |
| 280 | 280 | ||
| 281 | - | func (f *Supervisor) removeQueued(a *Agent) { | |
| 282 | - | if a == nil { | |
| 283 | - | return | |
| 284 | - | } | |
| 285 | - | f.mu.Lock() | |
| 286 | - | for i, queued := range f.queue { | |
| 287 | - | if queued == a { | |
| 288 | - | f.queue = append(f.queue[:i], f.queue[i+1:]...) | |
| 289 | - | break | |
| 290 | - | } | |
| 291 | - | } | |
| 292 | - | f.mu.Unlock() | |
| 293 | - | } | |
| 294 | - | ||
| 295 | 281 | func (f *Supervisor) cancelQueued(id string, cause error) { | |
| 296 | 282 | a := f.Get(id) | |
| 297 | 283 | if a == nil { | |
| @@ -278,20 +278,6 @@ func (f *Supervisor) armQueueTimeout(a *Agent) { | |||||
| 278 | 278 | ||||
| 279 | func (f *Supervisor) expireQueued(id string) { f.cancelQueued(id, context.DeadlineExceeded) } | 279 | func (f *Supervisor) expireQueued(id string) { f.cancelQueued(id, context.DeadlineExceeded) } | ||
| 280 | 280 | ||||
| 281 | - | func (f *Supervisor) removeQueued(a *Agent) { | |||
| 282 | - | if a == nil { | |||
| 283 | - | return | |||
| 284 | - | } | |||
| 285 | - | f.mu.Lock() | |||
| 286 | - | for i, queued := range f.queue { | |||
| 287 | - | if queued == a { | |||
| 288 | - | f.queue = append(f.queue[:i], f.queue[i+1:]...) | |||
| 289 | - | break | |||
| 290 | - | } | |||
| 291 | - | } | |||
| 292 | - | f.mu.Unlock() | |||
| 293 | - | } | |||
| 294 | - | ||||
| 295 | func (f *Supervisor) cancelQueued(id string, cause error) { | 281 | func (f *Supervisor) cancelQueued(id string, cause error) { | ||
| 296 | a := f.Get(id) | 282 | a := f.Get(id) | ||
| 297 | if a == nil { | 283 | if a == nil { | ||