Add PostMode for webhooks#344
Open
michelemin wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class support for webhook POST response behavior (rule-based or static) while keeping existing POST fan-out behavior unchanged, and extends the rule/runtime interface to allow response rules to select an HTTP status code.
Changes:
- Introduces
PostMode/PostResponseModewebhook configuration (including a configurable response timeout) and TOML deserialization/tests. - Adds a new host function/API (
set_response_status) plus runtime plumbing to carry a per-invocation HTTP status for webhook responses. - Updates the webhook POST handler to optionally run a dedicated “response rule” synchronously and return its body/status.
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| runtime/plaid/src/functions/response.rs | Adds set_response_status host function with status validation. |
| runtime/plaid/src/functions/mod.rs | Introduces new InvalidHttpResponseStatus function error code. |
| runtime/plaid/src/functions/api.rs | Exposes set_response_status through the WASM API table. |
| runtime/plaid/src/executor/mod.rs | Threads response status/invalid-status through Env and response delivery path. |
| runtime/plaid/src/config.rs | Adds PostMode config, parsing/validation, and unit tests. |
| runtime/plaid/src/bin/plaid.rs | Implements optional synchronous POST responder (static or rule) on top of normal fan-out. |
| runtime/plaid-stl/src/plaid/mod.rs | Adds STL wrapper for set_response_status. |
| runtime/plaid-stl/src/lib.rs | Adds WebhookResponse + new entrypoint macro supporting status+body responses. |
| runtime/Cargo.lock | Bumps runtime crate versions to 46.2.0. |
| modules/Cargo.lock | Bumps plaid_stl version to 46.2.0 for module builds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+129
to
+133
| let mut message = message.create_duplicate(); | ||
| message.type_ = name.clone(); | ||
| message.response_sender = Some(response_sender); | ||
| message.module = Some(rule.clone()); | ||
| (response_receiver, message, post_mode.response_timeout_seconds) |
| return warp::reply::with_status(warp::reply(), StatusCode::BAD_GATEWAY).into_response(); | ||
| }; | ||
|
|
||
| if let Err(e) = log_sender.try_send(response_message) { |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 10 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
runtime/plaid/src/bin/plaid.rs:178
- The response-rule enqueue failure returns 429 (Too Many Requests) even though the normal webhook fan-out has already been accepted/queued successfully. A client retrying on 429 can therefore duplicate normal log ingestion while only the response path was overloaded. Consider either (a) enqueueing the response rule before accepting the fan-out when you want to signal backpressure, or (b) treating response-rule enqueue failure as a best-effort response failure (e.g. 2xx with empty body, or a non-retry-oriented status) to avoid misleading retries.
if let Err(e) = log_sender.try_send(response_message) {
match e {
TrySendError::Full(_) => {
error!("Queue Full! Response rule [{name}] for webhook {webhook} was not run");
return warp::reply::with_status(warp::reply(), StatusCode::TOO_MANY_REQUESTS).into_response();
Comment on lines
+603
to
+607
| if let Some(invalid_status) = env.as_ref(&store).invalid_response_status { | ||
| els.log_module_error( | ||
| module.name.clone(), | ||
| format!("Invalid HTTP response status: {invalid_status}"), | ||
| message.data.clone(), |
Add optional post_mode support while preserving normal webhook fan-out. Allow response rules to return an HTTP body and status, with timeout and failure handling. Add WebhookResponse and a matching STL entrypoint macro. Co-authored-by: Codex CLI (GPT-5) <noreply@openai.com>
Comment on lines
+86
to
+102
| /// Set the HTTP status to return when a module is serving a webhook response. | ||
| pub fn set_response_status(mut env: FunctionEnvMut<Env>, status: u32) -> i32 { | ||
| let status = match u16::try_from(status) { | ||
| Ok(status) if (100..=599).contains(&status) => status, | ||
| _ => { | ||
| error!( | ||
| "{}: Invalid HTTP response status: {status}", | ||
| env.data().module.name | ||
| ); | ||
| env.as_mut().data_mut().invalid_response_status = Some(status); | ||
| return FunctionErrors::InvalidHttpResponseStatus as i32; | ||
| } | ||
| }; | ||
|
|
||
| env.as_mut().data_mut().response_status = Some(status); | ||
| 0 | ||
| } |
Comment on lines
+348
to
+353
| let buffer_size = fetch_data_and_source(vec![].as_mut_ptr(), 0); | ||
| let buffer_size = if buffer_size < 4 { | ||
| return -3; | ||
| } else { | ||
| buffer_size as u32 | ||
| }; |
Comment on lines
+386
to
+390
| let status_result = unsafe { set_response_status(response.status.into()) }; | ||
| if status_result != 0 { | ||
| set_error_context("Invalid HTTP response status"); | ||
| return 1; | ||
| } |
Comment on lines
+201
to
+203
| TrySendError::Full(_) => { | ||
| error!("Queue Full! Response rule [{name}] for webhook {webhook} was not run"); | ||
| return warp::reply::with_status(warp::reply(), StatusCode::TOO_MANY_REQUESTS).into_response(); |
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.
Add optional post_mode support while preserving normal webhook fan-out.
Allow response rules to return an HTTP body and status, with timeout and
failure handling. Add WebhookResponse and a matching STL entrypoint macro.
Key design decision to be discussed: a webhook POST still triggers a normal fan-out to the normal log processing channels. The optional dedicated responder is on top.
Co-authored-by: Codex CLI (GPT-5) noreply@openai.com