Index: db.scm
==================================================================
--- db.scm
+++ db.scm
@@ -92,19 +92,10 @@
 (define (db:hoh-get dat key1 key2)
   (let* ((subhash (hash-table-ref/default dat key1 #f)))
     (and subhash
 	 (hash-table-ref/default subhash key2 #f))))
 
-(define (db:get-cache-stmth dbdat run-id db stmt)
-  (let* (;; (dbdat       (dbfile:get-dbdat dbstruct run-id))
-	 (stmt-cache  (dbr:dbdat-stmt-cache dbdat))
-	 (stmth       (db:hoh-get stmt-cache db stmt)))
-    (or stmth
-	(let* ((newstmth (sqlite3:prepare db stmt)))
-	  (db:hoh-set! stmt-cache db stmt newstmth)
-	  newstmth))))
-
 ;;======================================================================
 ;; SQLITE3 HELPERS
 ;;======================================================================
 
 (define (db:general-sqlite-error-dump exn stmt . params)
@@ -1047,12 +1038,12 @@
               ;; what to do with toplevel? call rollup?
               (begin
                 (set! toplevels   (cons (list test-id run-dir uname testname item-path run-id) toplevels))
                 (debug:print-info 0 *default-log-port* "Found old toplevel test in RUNNING state, test-id=" test-id))
               (set! incompleted (cons (list test-id run-dir uname testname item-path run-id) incompleted))))
-        db
-        "SELECT id,rundir,uname,testname,item_path FROM tests WHERE run_id=? AND (strftime('%s','now') - event_time) > (run_duration + ?) AND state IN ('RUNNING','REMOTEHOSTSTART');"
+        (db:get-cache-stmth dbdat db
+        "SELECT id,rundir,uname,testname,item_path FROM tests WHERE run_id=? AND (strftime('%s','now') - event_time) > (run_duration + ?) AND state IN ('RUNNING','REMOTEHOSTSTART');")
         run-id deadtime)
 
        ;; in LAUNCHED for more than one day. Could be long due to job queues TODO/BUG: Need override for this in config
        ;;
        ;; (db:delay-if-busy dbdat)

Index: dbfile.scm
==================================================================
--- dbfile.scm
+++ dbfile.scm
@@ -1185,6 +1185,17 @@
 	(let ((res (proc)))
 	  (dbfile:simple-file-release-lock fname)
 	  res)
 	(assert #t "FATAL: simple file lock never got a lock."))))
   
+(define (db:get-cache-stmth dbdat run-id db stmt)
+  (let* (;; (dbdat       (dbfile:get-dbdat dbstruct run-id))
+	 (stmt-cache  (dbr:dbdat-stmt-cache dbdat))
+	 ;; (stmth       (db:hoh-get stmt-cache db stmt))
+	 (stmth       (hash-table-ref/default stmt-cache stmt #f)))
+    (or stmth
+	(let* ((newstmth (sqlite3:prepare db stmt)))
+	  ;; (db:hoh-set! stmt-cache db stmt newstmth)
+	  (hash-table-set! stmt-cache stmt newstmth)
+	  newstmth))))
+
 )

Index: rmt.scm
==================================================================
--- rmt.scm
+++ rmt.scm
@@ -225,11 +225,11 @@
      ;;DOT CASE7 -> "rmt:open-qry-close-locally";
      ;; on homehost and this is a write, we already have a server
      ((and (not (remote-force-server runremote))     ;; honor forced use of server, i.e. server NOT required
 	   (cdr (remote-hh-dat runremote))           ;; on homehost
            (not (member cmd api:read-only-queries))  ;; this is a write
-           (remote-server-url runremote))            ;; have a server
+           (remote-server-url runremote))            ;; have a server (needed to sync written data back)
       (mutex-unlock! *rmt-mutex*)
       (debug:print-info 12 *default-log-port* "rmt:send-receive, case  4.1")
       (rmt:open-qry-close-locally cmd 0 params))
 
      ;;DOT CASE8 [label="force\nserver"];
@@ -1038,11 +1038,11 @@
 
 (define (extras-transport-failed *default-log-port* *rmt-mutex* attemptnum runremote cmd rid params)
   (debug:print 0 *default-log-port* "WARNING: communication failed. Trying again, try num: " attemptnum)
   (mutex-lock! *rmt-mutex*)
   (http-transport:close-connections runremote)
-  (remote-server-url-set! runremote #f)
+  ;; (remote-server-url-set! runremote #f)
   (mutex-unlock! *rmt-mutex*)
   (debug:print-info 12 *default-log-port* "rmt:send-receive, case  9.1")
   (rmt:send-receive cmd rid params attemptnum: (+ attemptnum 1)))
   
 (define (extras-transport-succeded *default-log-port* *rmt-mutex* attemptnum runremote res params rid cmd)