fix(server): configurable /chat+ACP turn timeout; no 504-while-billing (#359) - #376
Open
gnanirahulnutakki wants to merge 1 commit into
Open
fix(server): configurable /chat+ACP turn timeout; no 504-while-billing (#359)#376gnanirahulnutakki wants to merge 1 commit into
gnanirahulnutakki wants to merge 1 commit into
Conversation
#359) The synchronous POST /chat and ACP HTTP handlers wrapped submit_chat in a hardcoded 30s tokio::time::timeout. submit_chat enqueues the turn onto a detached worker thread (which owns the !Send fused runtime) and awaits a oneshot. When the 30s wait elapsed, the handler returned 504 and dropped the oneshot receiver — but the worker's handle_http ran runtime.submit() to completion regardless, committing a receipt and billing cost for a reply the client never received. A misleading failure with real billing impact. Fix (tightest scope): - Make the ceiling configurable: ARDUR_HTTP_TURN_TIMEOUT_SECS (default 30, rejects 0/unparseable at boot), surfaced as Config.http_turn_timeout and AppState::http_turn_timeout(); both handlers now read it instead of a const. - Align billing with what the client was told: handle_http now races runtime.submit against reply.closed() (biased toward completion), mirroring the streaming path's events.closed() guard. When the client-facing timeout fires (or the caller hangs up), the submit future is dropped before it commits the receipt/journal/cost side effects (all at .await points inside submit_inner), so a 504 never pairs with a silently-billed turn. Verification: - New regression test crates/server/tests/chat_turn_timeout.rs: a turn that outruns a tiny timeout returns 504 and mints zero receipts (fails pre-fix with count==1); a turn within budget returns 200 and mints one. - cargo test -p ardur-server, cargo test -p ardur-e2e-tests, clippy --all-targets --all-features -D warnings, and fmt --check all green. Fixes #359 Checkpoint: architect/sessions/http-turn-timeout-359-2026-07-23/journal.md Signed-off-by: GR <gnanirn@gmail.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
The synchronous
POST /chatand ACP HTTP handlers wrappedstate.submit_chatin a hardcoded 30stokio::time::timeout(HTTP_TURN_TIMEOUTinroutes.rs).submit_chatenqueues the turn onto a detached worker thread (which owns the!Sendfused runtime) over a bounded mpsc, then awaits a oneshot reply. When the 30s wait elapsed:submit_chatfuture (dropping the oneshot receiver), buthandle_httphad already calledruntime.submit().awaitand ran the turn to completion regardless — committing a signed receipt and billing cost — then failed thereply.send(...)silently.Result: the client saw a
504, but the turn succeeded, minted a receipt, and billed. The streaming path (handle_http_stream) already guards against this withtokio::select!onevents.closed(); the synchronous path had no equivalent.Fix (tightest scope)
ARDUR_HTTP_TURN_TIMEOUT_SECS(default30, rejects0/unparseable at boot), surfaced asConfig.http_turn_timeout→AppState::http_turn_timeout(). Both handlers read it instead of the const.handle_httpnow racesruntime.submitagainstreply.closed()(biased toward the completion arm), mirroring the streaming path'sevents.closed()guard. When the client-facing timeout fires (or the caller hangs up), thesubmitfuture is dropped before it commits the receipt/journal/cost side effects (all at.awaitpoints insidesubmit_inner), so a504is never paired with a silently-billed turn. A turn that finishes exactly at the deadline still reports its already-committed outcome (biased select).Verification
crates/server/tests/chat_turn_timeout.rs:count == 1, i.e. billed under a 504), passes with it;cargo test -p ardur-server✅ ·cargo test -p ardur-e2e-tests✅cargo clippy --all-targets --all-features -- -D warnings✅ ·cargo fmt --check✅RUN.mddocuments the new knob.Fixes #359