Skip to content

keep only logbook func_args in pyscript_running event - #900

Merged
craigbarratt merged 1 commit into
custom-components:masterfrom
dmamelin:running-event-func-args
Nov 18, 2026
Merged

craigbarratt merged 1 commit into
custom-components:masterfrom
dmamelin:running-event-func-args

Conversation

@dmamelin

@dmamelin dmamelin commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to e104bda. Closes #898.
The event now keeps a whitelist of the func_args the logbook describes it with: trigger_type, event_type, var_name, value and trigger_time. The other func_args aren't used anywhere, but the recorder stores them for every call, which bloats the database.

Problem

pyscript_running is fired before each triggered call and carried the call's full func_args. That causes three problems:

  1. Not JSON serializable. A webhook request broke the recorder and websocket subscribers with Event is not JSON serializable. e104bda dropped request, but that is a blacklist: any non-serializable argument added later breaks the event again.
  2. Sensitive data. As reported in webhook_handler: pyscript_running includes a non-serializable request and sensitive arguments #898, the webhook payload (which can hold an auth token) and the webhook_id end up in the recorder's events table and in the serialization error log. The event is fired before the user's function runs, so the function can't sanitize them.
  3. Large data. With Service via decorator manager #899, @service fires pyscript_running too, so all service call data would be stored in the recorder for every call.

Breaking change

In theory, this can break listeners of pyscript_running that read other func_args from it. I don't think that's a problem:

  • the event's func_args aren't documented;
  • the event was added only for the logbook (Logbook Functionality #62);
  • pyscript_running is easy to replace with @state_trigger or @event_trigger on the same source, or with an event fired from the function itself via event.fire().

The pyscript_running event carried all of func_args. Besides values
that aren't JSON serializable, these can include large or sensitive
data, eg, a webhook payload with an auth token and the webhook_id,
or service call data once @service fires the event.

The event now keeps only the func_args the logbook describes it with:
trigger_type, event_type, var_name, value and trigger_time. Anything
that read other func_args from this event won't see them anymore.

@craigbarratt craigbarratt left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, @dmamelin. Keeping only what the logbook uses is a better fix than removing specific arguments. It covers #898, and also any argument added later that is large or not JSON serializable, such as the service call data from #899.

I agree the reduced func_args is fine since they're undocumented. I'll mention it in the release notes.

After this is merged, I'll add a small follow-up so the @webhook_handler timeout and unparsable-body warnings name the function instead of the webhook id.

@craigbarratt
craigbarratt merged commit d9da587 into custom-components:master Nov 18, 2026
6 checks passed
craigbarratt added a commit that referenced this pull request Nov 18, 2026
A webhook id acts as the webhook's credential, so the webhook_handler
timeout and unparsable-body warnings now name the function instead.
Follow-up to #900 for #898.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

webhook_handler: pyscript_running includes a non-serializable request and sensitive arguments

2 participants