Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Web: Assume compute has finished when 20s no update

Kilian Lieret63727a5e5b31
diff --git a/sweagent/api/server.py b/sweagent/api/server.py
index 96cd0f88..41040b22 100644
--- a/sweagent/api/server.py
+++ b/sweagent/api/server.py
@@ -92,6 +92,12 @@ def run():
session_id = ensure_session_id_set()
if request.method == "OPTIONS": # CORS preflight
return _build_cors_preflight_response()
+ # While we're running as a local UI, let's make sure that there's at most
+ # one run at a time
+ global THREADS
+ for thread in THREADS.values():
+ if thread.is_alive():
+ thread.stop()
wu = WebUpdate(socketio)
wu.up_agent("Starting the run")
data_path = request.args["data_path"]
@@ -126,7 +132,6 @@ def run():
actions=ActionsArguments(open_pr=False, skip_if_commits_reference_issue=True),
)
thread = MainThread(defaults, wu)
- global THREADS
THREADS[session_id] = thread
thread.start()
return 'Commands are being executed', 202
diff --git a/sweagent/frontend/src/Run.js b/sweagent/frontend/src/Run.js
index 9be19549..d0c1cd94 100644
--- a/sweagent/frontend/src/Run.js
+++ b/sweagent/frontend/src/Run.js
@@ -33,6 +33,8 @@ function Run() {
const [tabKey, setTabKey] = useState('problem');
+ const stillComputingTimeoutRef = useRef(null);
+
axios.defaults.baseURL = url;
@@ -82,6 +84,14 @@ function Run() {
setHighlightedStep(null);
}
+ const requeueStopComputeTimeout = () => {
+ clearTimeout(stillComputingTimeoutRef.current);
+ setIsComputing(true);
+ stillComputingTimeoutRef.current = setTimeout(() => {
+ setIsComputing(false);
+ console.log("No activity for 20 second, setting isComputing to false");
+ }, 20000);
+ }
// Handle form submission
const handleSubmit = async (event) => {
@@ -114,6 +124,7 @@ function Run() {
// Use effect to listen to socket updates
React.useEffect(() => {
const handleUpdate = (data) => {
+ requeueStopComputeTimeout();
if (data.feed === 'agent') {
setAgentFeed(prevMessages => [...prevMessages, { type: data.type, message: data.message, format: data.format, step: data.thought_idx }]);
}
@@ -127,6 +138,7 @@ function Run() {
}
const handleLogMessage = (data) => {
+ requeueStopComputeTimeout();
setLogs(prevLogs => prevLogs + data.message);
if (data.level === "critical") {
console.log("Critical error", data.message);
@@ -149,7 +161,7 @@ function Run() {
socket.on('connect', () => {
console.log("Connected to server");
setIsConnected(true);
- setErrorBanner(''); // Clear any errors on successful connection
+ setErrorBanner('');
});
socket.on('disconnect', () => {