diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-11 08:34:41 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-11 08:34:41 +0300 |
| commit | e95f3fdf0a66ba05ba2c8fb7e755e107f9cf7991 (patch) | |
| tree | 412c7e21ec9c317beb99ed7fe0d4d93a7dacbe50 /internal/hexaiaction | |
| parent | 73dadb573f92dca310036e8793932e94277abd62 (diff) | |
Thread context.Context through blocking I/O entry points
Accept ctx as the first parameter on the blocking I/O entry points and
propagate it to downstream blocking calls so the work is cancellable from
the process entry point:
- appconfig.Load / LoadWithOptions: honor ctx before the blocking file
reads, returning defaults on a cancelled context.
- LSP: lsp.Server.Run(ctx) ties the serve loop to the caller context via a
new watchParentContext bridge (cancels the server context, aborting
in-flight LLM work). Threaded through hexailsp.Run/RunWithConfig/
RunWithFactory and runtimeconfig.Store.Reload.
- MCP: mcp.Server.Run(ctx) stops accepting requests once ctx is cancelled;
threaded through hexaimcp.Run/RunWithFactory/RunBackfill.
- editor: RunEditor/OpenTempAndEdit/OpenFile take ctx and use
exec.CommandContext so a cancelled context kills the editor subprocess;
threaded through hexaicli, hexaiaction and askcli call sites.
Top-level callers (cmd/hexai-lsp-server, cmd/hexai-mcp-server) now build a
signal-cancelled context (SIGINT/SIGTERM) so shutdown tears the run down
cleanly. Updated comments to explain the cancellation flow and added
cancellation tests for the LSP/MCP loops, editor, and config load.
All tests pass with -race; cross-package coverage 86.2%.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/hexaiaction')
| -rw-r--r-- | internal/hexaiaction/custom_action_test.go | 2 | ||||
| -rw-r--r-- | internal/hexaiaction/custom_exec_more_test.go | 4 | ||||
| -rw-r--r-- | internal/hexaiaction/custom_exec_test.go | 4 | ||||
| -rw-r--r-- | internal/hexaiaction/prompts_simplify_test.go | 2 | ||||
| -rw-r--r-- | internal/hexaiaction/run.go | 4 | ||||
| -rw-r--r-- | internal/hexaiaction/run_more_test.go | 8 | ||||
| -rw-r--r-- | internal/hexaiaction/run_seam_test.go | 2 | ||||
| -rw-r--r-- | internal/hexaiaction/run_test.go | 2 |
8 files changed, 14 insertions, 14 deletions
diff --git a/internal/hexaiaction/custom_action_test.go b/internal/hexaiaction/custom_action_test.go index 74ac350..e2f7902 100644 --- a/internal/hexaiaction/custom_action_test.go +++ b/internal/hexaiaction/custom_action_test.go @@ -30,7 +30,7 @@ func TestActionCustom_UsesEditorPrompt(t *testing.T) { runner.newClient = func(_ appconfig.App) (actionClient, error) { return llmFake2{}, nil } oldRunEd := editor.RunEditor - editor.RunEditor = func(_ string, path string) error { + editor.RunEditor = func(_ context.Context, _ string, path string) error { return os.WriteFile(path, []byte("make it done"), 0o600) } t.Cleanup(func() { editor.RunEditor = oldRunEd }) diff --git a/internal/hexaiaction/custom_exec_more_test.go b/internal/hexaiaction/custom_exec_more_test.go index d826b39..73d9839 100644 --- a/internal/hexaiaction/custom_exec_more_test.go +++ b/internal/hexaiaction/custom_exec_more_test.go @@ -19,7 +19,7 @@ func (c *capDoer) Chat(_ context.Context, msgs []llm.Message, _ ...llm.RequestOp func (*capDoer) DefaultModel() string { return "m" } func TestExecuteAction_Custom_DoesNotMutateProvidedSelection(t *testing.T) { - cfg := appconfig.Load(nil) + cfg := appconfig.Load(context.Background(), nil) parts := InputParts{Selection: "code"} selectedCustom := &appconfig.CustomAction{ID: "x", Title: "X", Instruction: "Do it"} _, _ = executeAction(context.Background(), ActionCustom, parts, &cfg, fakeDoer{"OK"}, nil, selectedCustom) @@ -29,7 +29,7 @@ func TestExecuteAction_Custom_DoesNotMutateProvidedSelection(t *testing.T) { } func TestRunCustom_UserTemplate_InjectsDiagnostics(t *testing.T) { - cfg := appconfig.Load(nil) + cfg := appconfig.Load(context.Background(), nil) parts := InputParts{Selection: "code", Diagnostics: []string{"L1", "L2"}} ca := appconfig.CustomAction{ID: "y", Title: "Y", User: "{{diagnostics}}\n{{selection}}"} cap := &capDoer{} diff --git a/internal/hexaiaction/custom_exec_test.go b/internal/hexaiaction/custom_exec_test.go index 1a5b99e..11670fd 100644 --- a/internal/hexaiaction/custom_exec_test.go +++ b/internal/hexaiaction/custom_exec_test.go @@ -9,7 +9,7 @@ import ( ) func TestExecuteAction_CustomConfigured_Instruction(t *testing.T) { - cfg := appconfig.Load(nil) + cfg := appconfig.Load(context.Background(), nil) parts := InputParts{Selection: "code"} selectedCustom := &appconfig.CustomAction{ID: "x", Title: "X", Instruction: "Do it"} out, err := executeAction(context.Background(), ActionCustom, parts, &cfg, fakeDoer{"OK"}, nil, selectedCustom) @@ -19,7 +19,7 @@ func TestExecuteAction_CustomConfigured_Instruction(t *testing.T) { } func TestExecuteAction_CustomConfigured_User(t *testing.T) { - cfg := appconfig.Load(nil) + cfg := appconfig.Load(context.Background(), nil) parts := InputParts{Selection: "sel"} selectedCustom := &appconfig.CustomAction{ID: "y", Title: "Y", User: "Apply to: {{selection}}"} out, err := executeAction(context.Background(), ActionCustom, parts, &cfg, fakeDoer{"OK2"}, nil, selectedCustom) diff --git a/internal/hexaiaction/prompts_simplify_test.go b/internal/hexaiaction/prompts_simplify_test.go index 4cd831d..b13bf13 100644 --- a/internal/hexaiaction/prompts_simplify_test.go +++ b/internal/hexaiaction/prompts_simplify_test.go @@ -16,7 +16,7 @@ func (simplifyClient) Chat(_ context.Context, _ []llm.Message, _ ...llm.RequestO func (simplifyClient) DefaultModel() string { return "m" } func TestRunSimplify_Smoke(t *testing.T) { - cfg := appconfig.Load(nil) + cfg := appconfig.Load(context.Background(), nil) out, err := runSimplify(context.Background(), &cfg, simplifyClient{}, "code") if err != nil { t.Fatalf("runSimplify: %v", err) diff --git a/internal/hexaiaction/run.go b/internal/hexaiaction/run.go index 92aa72d..f0ce7ee 100644 --- a/internal/hexaiaction/run.go +++ b/internal/hexaiaction/run.go @@ -114,7 +114,7 @@ func (tmuxActionStatusSink) SetLLMStart(provider, model string) error { } func loadActionConfig(ctx context.Context, logger *log.Logger) appconfig.App { - return appconfig.LoadWithOptions(logger, appconfig.LoadOptions{ConfigPath: configPathFromContext(ctx)}) + return appconfig.LoadWithOptions(ctx, logger, appconfig.LoadOptions{ConfigPath: configPathFromContext(ctx)}) } type actionPlan struct { @@ -381,7 +381,7 @@ func handleCustomAction(ctx context.Context, parts InputParts, cfg actionConfig, } func handleCustomPromptAction(ctx context.Context, parts InputParts, cfg actionConfig, client chatDoer, stderr io.Writer) (string, error) { - prompt, err := editor.OpenTempAndEdit(nil) + prompt, err := editor.OpenTempAndEdit(ctx, nil) if err != nil || strings.TrimSpace(prompt) == "" { _, _ = fmt.Fprintln(stderr, logging.AnsiBase+"hexai-tmux-action: custom prompt canceled or empty; echoing input"+logging.AnsiReset) return parts.Selection, nil diff --git a/internal/hexaiaction/run_more_test.go b/internal/hexaiaction/run_more_test.go index 67ffa96..97bcbe9 100644 --- a/internal/hexaiaction/run_more_test.go +++ b/internal/hexaiaction/run_more_test.go @@ -31,7 +31,7 @@ func TestRun_MissingAPIKey(t *testing.T) { func TestRun_NoInput_IsActionable(t *testing.T) { runner := NewRunner() - runner.loadConfig = func(context.Context, *log.Logger) appconfig.App { return appconfig.Load(nil) } + runner.loadConfig = func(context.Context, *log.Logger) appconfig.App { return appconfig.Load(context.Background(), nil) } runner.newClient = func(appconfig.App) (actionClient, error) { return llmFake{}, nil } runner.chooseAction = func(appconfig.App) (actionChoice, error) { return actionChoice{kind: ActionSkip}, nil @@ -62,7 +62,7 @@ func TestHandleDiagnosticsActionInvokesLLM(t *testing.T) { t.Setenv("HEXAI_TMUX_STATUS", "0") parts := InputParts{Diagnostics: []string{"warn1"}, Selection: "code"} client := &stubChatDoer{} - cfg := appconfig.Load(nil) + cfg := appconfig.Load(context.Background(), nil) if _, err := handleDiagnosticsAction(context.Background(), parts, &cfg, client); err != nil { t.Fatalf("handleDiagnosticsAction: %v", err) } @@ -84,7 +84,7 @@ func TestHandleSimplifyActionPassesSelection(t *testing.T) { t.Setenv("HEXAI_TMUX_STATUS", "0") parts := InputParts{Selection: "value := 1"} client := &stubChatDoer{} - cfg := appconfig.Load(nil) + cfg := appconfig.Load(context.Background(), nil) if _, err := handleSimplifyAction(context.Background(), parts, &cfg, client); err != nil { t.Fatalf("handleSimplifyAction: %v", err) } @@ -107,7 +107,7 @@ func TestHandleCustomActionUsesProvidedCustom(t *testing.T) { sel := appconfig.CustomAction{ID: "custom", Title: "Do", Instruction: "do it"} parts := InputParts{Selection: "text"} client := &stubChatDoer{} - cfg := appconfig.Load(nil) + cfg := appconfig.Load(context.Background(), nil) if _, err := handleCustomAction(context.Background(), parts, &cfg, client, &sel); err != nil { t.Fatalf("handleCustomAction: %v", err) } diff --git a/internal/hexaiaction/run_seam_test.go b/internal/hexaiaction/run_seam_test.go index 8fb8533..d37f179 100644 --- a/internal/hexaiaction/run_seam_test.go +++ b/internal/hexaiaction/run_seam_test.go @@ -65,7 +65,7 @@ func TestRun_WithInjectedConfigAndStatusSink(t *testing.T) { t.Setenv("XDG_CONFIG_HOME", t.TempDir()) sink := &recordingActionStatusSink{} runner := NewRunner() - runner.loadConfig = func(context.Context, *log.Logger) appconfig.App { return appconfig.Load(nil) } + runner.loadConfig = func(context.Context, *log.Logger) appconfig.App { return appconfig.Load(context.Background(), nil) } runner.newClient = func(_ appconfig.App) (actionClient, error) { return llmFake{}, nil } runner.chooseAction = func(_ appconfig.App) (actionChoice, error) { return actionChoice{kind: ActionSkip}, nil diff --git a/internal/hexaiaction/run_test.go b/internal/hexaiaction/run_test.go index b927d57..574874f 100644 --- a/internal/hexaiaction/run_test.go +++ b/internal/hexaiaction/run_test.go @@ -26,7 +26,7 @@ func TestExecuteAction_Skip(t *testing.T) { } func TestExecuteAction_Rewrite_Document_GoTest(t *testing.T) { - cfg := appconfig.Load(nil) // defaults + cfg := appconfig.Load(context.Background(), nil) // defaults // Use fenced output to exercise StripFences client := fakeDoer{"```\nDONE\n```"} |
