detached ef9ee0c

refactor(mcp): return startup error last from startMCPInterruptible

commit
ef9ee0c39245f57a68c3f3458c2949b5d56d1d83
author
brice · · 2026-10-15 14:04 UTC
parent
16815dd
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
2 files · +5 -5
M packages/agent/mcp_runtime.go +4 -4
@@ -58,7 +58,7 @@ func startMCP(ctx context.Context, args *Args, version string) (func(), error) {
5858 manager := mcp.NewManager(cfg, args.CWD, mcp.ClientInfo{Name: "zut", Version: version}, provider.NewHTTPClient(false))
5959 sigCh := make(chan os.Signal, 1)
6060 signal.Notify(sigCh, mcpSignals...)
61- failures, requiredErr, sig := startMCPInterruptible(ctx, manager, sigCh)
61+ failures, sig, requiredErr := startMCPInterruptible(ctx, manager, sigCh)
6262 signal.Stop(sigCh)
6363 if sig != nil {
6464 // Interrupted during startup: no mode owns signals yet, so stop the
@@ -94,7 +94,7 @@ func signalExitCode(sig os.Signal) int {
9494 // startMCPInterruptible runs manager.Start and cancels the handshakes when a
9595 // signal arrives on sigCh, waiting until every connection attempt has closed
9696 // its transport. It returns the signal that interrupted startup, if any.
97-func startMCPInterruptible(ctx context.Context, manager *mcp.Manager, sigCh <-chan os.Signal) ([]error, error, os.Signal) {
97+func startMCPInterruptible(ctx context.Context, manager *mcp.Manager, sigCh <-chan os.Signal) ([]error, os.Signal, error) {
9898 startCtx, cancel := context.WithCancel(ctx)
9999 defer cancel()
100100 type result struct {
@@ -108,11 +108,11 @@ func startMCPInterruptible(ctx context.Context, manager *mcp.Manager, sigCh <-ch
108108 }()
109109 select {
110110 case r := <-done:
111- return r.failures, r.required, nil
111+ return r.failures, nil, r.required
112112 case sig := <-sigCh:
113113 cancel()
114114 <-done
115- return nil, nil, sig
115+ return nil, sig, nil
116116 }
117117 }
118118
@@ -58,7 +58,7 @@ func startMCP(ctx context.Context, args *Args, version string) (func(), error) {
58 manager := mcp.NewManager(cfg, args.CWD, mcp.ClientInfo{Name: "zut", Version: version}, provider.NewHTTPClient(false))58 manager := mcp.NewManager(cfg, args.CWD, mcp.ClientInfo{Name: "zut", Version: version}, provider.NewHTTPClient(false))
59 sigCh := make(chan os.Signal, 1)59 sigCh := make(chan os.Signal, 1)
60 signal.Notify(sigCh, mcpSignals...)60 signal.Notify(sigCh, mcpSignals...)
61- failures, requiredErr, sig := startMCPInterruptible(ctx, manager, sigCh)61+ failures, sig, requiredErr := startMCPInterruptible(ctx, manager, sigCh)
62 signal.Stop(sigCh)62 signal.Stop(sigCh)
63 if sig != nil {63 if sig != nil {
64 // Interrupted during startup: no mode owns signals yet, so stop the64 // Interrupted during startup: no mode owns signals yet, so stop the
@@ -94,7 +94,7 @@ func signalExitCode(sig os.Signal) int {
94 // startMCPInterruptible runs manager.Start and cancels the handshakes when a94 // startMCPInterruptible runs manager.Start and cancels the handshakes when a
95 // signal arrives on sigCh, waiting until every connection attempt has closed95 // signal arrives on sigCh, waiting until every connection attempt has closed
96 // its transport. It returns the signal that interrupted startup, if any.96 // its transport. It returns the signal that interrupted startup, if any.
97-func startMCPInterruptible(ctx context.Context, manager *mcp.Manager, sigCh <-chan os.Signal) ([]error, error, os.Signal) {97+func startMCPInterruptible(ctx context.Context, manager *mcp.Manager, sigCh <-chan os.Signal) ([]error, os.Signal, error) {
98 startCtx, cancel := context.WithCancel(ctx)98 startCtx, cancel := context.WithCancel(ctx)
99 defer cancel()99 defer cancel()
100 type result struct {100 type result struct {
@@ -108,11 +108,11 @@ func startMCPInterruptible(ctx context.Context, manager *mcp.Manager, sigCh <-ch
108 }()108 }()
109 select {109 select {
110 case r := <-done:110 case r := <-done:
111- return r.failures, r.required, nil111+ return r.failures, nil, r.required
112 case sig := <-sigCh:112 case sig := <-sigCh:
113 cancel()113 cancel()
114 <-done114 <-done
115- return nil, nil, sig115+ return nil, sig, nil
116 }116 }
117 }117 }
118 118
M packages/agent/mcp_runtime_test.go +1 -1
@@ -417,7 +417,7 @@ func TestStartMCPInterruptibleCancelsHandshake(t *testing.T) {
417417 sigCh := make(chan os.Signal, 1)
418418 result := make(chan os.Signal, 1)
419419 go func() {
420- _, _, sig := startMCPInterruptible(context.Background(), manager, sigCh)
420+ _, sig, _ := startMCPInterruptible(context.Background(), manager, sigCh)
421421 result <- sig
422422 }()
423423 <-reached
@@ -417,7 +417,7 @@ func TestStartMCPInterruptibleCancelsHandshake(t *testing.T) {
417 sigCh := make(chan os.Signal, 1)417 sigCh := make(chan os.Signal, 1)
418 result := make(chan os.Signal, 1)418 result := make(chan os.Signal, 1)
419 go func() {419 go func() {
420- _, _, sig := startMCPInterruptible(context.Background(), manager, sigCh)420+ _, sig, _ := startMCPInterruptible(context.Background(), manager, sigCh)
421 result <- sig421 result <- sig
422 }()422 }()
423 <-reached423 <-reached

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close