@@ -95,6 +95,8 @@ func main() {
9595 flag .StringVar (& opts .tags , "tags" , "" , "Build tags to pass to `go run` capture phase (e.g. 'mock')" )
9696 flag .Parse ()
9797
98+ fmt .Printf ("[DEBUG] Parsed Timeout: %v\n " , opts .timeout )
99+
98100 if showVersion {
99101 fmt .Printf ("lx %s\n " , version )
100102 return
@@ -873,6 +875,9 @@ func diagnoseLLMError(err error) string {
873875 msg := err .Error ()
874876
875877 switch {
878+ case strings .Contains (msg , "timeout reached" ):
879+ return fmt .Sprintf ("TIMEOUT: The operation exceeded the time limit. (%s)" , msg )
880+
876881 case strings .Contains (msg , "API_KEY_INVALID" ):
877882 return "The API key is incorrect. Please double-check the api_key in 'lx-config.yaml'."
878883 case strings .Contains (msg , "quota" ):
@@ -883,6 +888,7 @@ func diagnoseLLMError(err error) string {
883888 return "Your response has been blocked by security policy. Please edit the prompt."
884889 case strings .Contains (msg , "connection" ) || strings .Contains (msg , "timeout" ):
885890 return "The network connection is unstable. Please check your Internet connection."
891+
886892 default :
887893 return fmt .Sprintf ("An unknown error has occurred: %v" , err )
888894 }
@@ -962,12 +968,21 @@ func (c *commandLLM) Generate(ctx context.Context, model string, prompt string)
962968
963969 cmd := exec .CommandContext (ctx , c .binPath , finalArgs ... )
964970
971+ cmd .SysProcAttr = & syscall.SysProcAttr {Setpgid : true }
972+
973+ cmd .Cancel = func () error {
974+ return syscall .Kill (- cmd .Process .Pid , syscall .SIGKILL )
975+ }
976+
965977 var out bytes.Buffer
966978 var stderr bytes.Buffer
967979 cmd .Stdout = & out
968980 cmd .Stderr = & stderr
969981
970982 if err := cmd .Run (); err != nil {
983+ if ctx .Err () == context .DeadlineExceeded {
984+ return "" , fmt .Errorf ("timeout reached (%s): process group killed" , ctx .Err ())
985+ }
971986 return "" , fmt .Errorf ("command execution failed: %v\n Stderr: %s" , err , stderr .String ())
972987 }
973988
0 commit comments