Skip to content

Add PostMode for webhooks#344

Open
michelemin wants to merge 2 commits into
mainfrom
post_mode
Open

Add PostMode for webhooks#344
michelemin wants to merge 2 commits into
mainfrom
post_mode

Conversation

@michelemin

@michelemin michelemin commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

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

Copilot AI review requested due to automatic review settings July 19, 2026 12:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / PostResponseMode webhook 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 thread runtime/plaid/src/bin/plaid.rs Outdated
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)
Comment thread runtime/plaid/src/bin/plaid.rs Outdated
return warp::reply::with_status(warp::reply(), StatusCode::BAD_GATEWAY).into_response();
};

if let Err(e) = log_sender.try_send(response_message) {
Copilot AI review requested due to automatic review settings July 19, 2026 12:25
@michelemin michelemin added enhancement New feature or request AI Prompted The code was primarily generated via prompts. Using AI code complete, does not count. labels Jul 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copilot AI review requested due to automatic review settings July 20, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 12 changed files in this pull request and generated 3 comments.

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;
}
Copilot AI review requested due to automatic review settings July 20, 2026 22:12
@michelemin
michelemin marked this pull request as ready for review July 20, 2026 22:13
@michelemin
michelemin requested a review from obelisk July 20, 2026 22:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 12 changed files in this pull request and generated 1 comment.

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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Prompted The code was primarily generated via prompts. Using AI code complete, does not count. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants