Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ a new command, but cannot replace an earlier untracked reply. Replies sent
through the chat adapter are tracked; messages a plugin sends directly through
Discord's API are not.

## Command evaluation deadline

Expression evaluation defaults to **five minutes**. Set a different startup
limit with `YETIBOT_COMMAND_TIMEOUT_MS`, or the equivalent EDN configuration
`{:yetibot {:command {:timeout {:ms 300000}}}}`. Values are positive integer
milliseconds, at most 2,147,483,647; missing or invalid values use five minutes.
Restart to apply a configuration change.

This deadline does not change provider/tool timeouts, generation limits or call
budgets. A timeout does not cancel an already-running external request or prove
that its side effects did not occur; do not automatically retry it. Inherited
execution scopes close on timeout and reject subsequent derived effects.

## Dev postgres

To quickly provision a postgresql database to work against, run:
Expand Down
15 changes: 14 additions & 1 deletion src/yetibot/core/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,20 @@
;; enabled by default
true)))

(def expr-eval-timeout-ms 5000)
(s/def ::expr-eval-timeout-ms
#(try
(and (or (integer? %) (string? %))
(<= 1 (Long/parseLong (str %)) Integer/MAX_VALUE))
(catch Exception _ false)))

(defn configured-expr-eval-timeout-ms
"Startup command deadline in milliseconds; invalid/missing settings use five minutes."
[]
(let [{:keys [value error]} (get-config ::expr-eval-timeout-ms
[:command :timeout :ms])]
(if error 300000 (Long/parseLong (str value)))))

(def expr-eval-timeout-ms (configured-expr-eval-timeout-ms))

(def ^:private exception-format "👮 %s 👮")

Expand Down
26 changes: 26 additions & 0 deletions test/yetibot/core/test/util/agent_execution.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(ns yetibot.core.test.util.agent-execution
(:require [midje.sweet :refer [fact => throws]]
[clojure.core.async :as async]
[yetibot.core.config :as config]
[yetibot.core.util.config :as config-util]
[yetibot.core.util.agent-execution :as execution]
[yetibot.core.parser :as parser]
[yetibot.core.handler :as handler]
Expand Down Expand Up @@ -353,6 +355,30 @@
@seen => [[family ""]]
@admissions => ["agent"])))))

(fact "command deadlines default to five minutes and validate configured millisecond values"
(doseq [[value expected] [[nil 300000] [100 100] ["600000" 600000]
[1 1] [2147483647 2147483647]
[0 300000] [-1 300000] [1.5 300000]
[true 300000] ["invalid" 300000]
["2147483648" 300000]]]
(with-redefs [config/get-config
(partial config-util/get-config {:command {:timeout {:ms value}}})]
(handler/configured-expr-eval-timeout-ms) => expected)))

(fact "ordinary commands longer than the former five-second limit complete within the default deadline"
(lineage-fixture
(fn [_ _ _]
(hooks/cmd-hook-resolved #"slowordinary" #".*"
(fn [_] (Thread/sleep 5100) "long-ok"))
(with-redefs [config/get-config (partial config-util/get-config {})
handler/add-user-message-to-history (fn [& _])
handler/add-bot-response-to-history (fn [& _])]
(with-redefs [handler/expr-eval-timeout-ms
(handler/configured-expr-eval-timeout-ms)]
(:result (first (handler/record-and-run-raw "!slowordinary" nil nil
{:record-yetibot-response? false})))
=> "long-ok")))))

(fact "concurrent nested aliases cannot starve command evaluation on async dispatchers"
(doseq [route [:raw :delivery]]
(lineage-fixture
Expand Down