feat(agent-trigger): Webhook and Manual trigger backends (CodeDiscovery B-02) - #412
Draft
esafwan wants to merge 2 commits into
Draft
feat(agent-trigger): Webhook and Manual trigger backends (CodeDiscovery B-02)#412esafwan wants to merge 2 commits into
esafwan wants to merge 2 commits into
Conversation
- W1: new guest endpoint agent_trigger_webhook in huf/ai/agent_trigger_api.py resolving triggers by webhook_slug, rejecting disabled triggers, validating the key with hmac.compare_digest (fail closed), parsing JSON/form payload into a prompt, and enqueueing run_agent_sync (pattern copied from flow_api.py flow_webhook/_webhook_key_is_valid) - W4: conversation identity channel_id='webhook'/'manual' with external_id per the agent's persist_user_history setting (agent_hooks.py pattern) - M1: authenticated run_trigger(trigger_name) for Manual triggers with Agent Trigger read permission + agent.use capability check, running run_agent_sync(channel_id='manual') as the session user - W2: AgentTrigger.validate() requires webhook_slug+webhook_key for Webhook triggers and enforces slug uniqueness among enabled webhook triggers; event_name now has depends_on for App Event in the DocType schema
…kup, raw body cap - run as trigger owner via frappe.set_user (Guest would be rejected by run_agent_sync for non-guest agents); webhook key remains the auth boundary - resolve slug with disabled=0 filter + ambiguity check (validation only enforces uniqueness across enabled triggers) - hard-cap the raw request body before parsing; label payload as untrusted in the generated prompt
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.
Problem
CodeDiscovery finding B-02:
Agent Trigger.trigger_typedeclares Webhook / App Event / Manual, but only Schedule and Doc Event have backend consumers — a user can save a Webhook or Manual trigger and nothing can ever fire it. (Decomposition dossier on file. App Event is deliberately excluded — design-first, two glossary terms unratified.)Scope
huf/ai/agent_trigger_api.py:agent_trigger_webhook(slug, webhook_key)— guest endpoint: deterministic enabled-trigger lookup by slug (ambiguity-safe), constant-time fail-closed key check (hmac.compare_digest, empty configured key rejects), raw-body size cap BEFORE parsing, payload embedded as explicitly-labeled untrusted data in the prompt, enqueuesrun_agent_syncas the trigger owner (frappe.set_user, same pattern asflow_webhook) withchannel_id="webhook".run_trigger(trigger_name, prompt?)— authenticated Manual trigger runner: Agent Trigger read permission +agent.usecapability, runs synchronously as the session user withchannel_id="manual".agent_trigger.py:validate()requires slug+key for Webhook triggers and enforces slug uniqueness across enabled webhook triggers;event_namegets its missingdepends_on.Key decisions
Agent contributions
Implementation by the release-orchestration pipeline; an independent second review REJECTED the first cut (Guest execution identity, nondeterministic slug lookup, post-parse payload cap); all three findings fixed by the pipeline; second commit.
Tests executed
py_compile+ JSON schema validation.set_userpresent, disabled-filter + raw cap present, key check accepts/rejects correctly, untrusted labeling present.Risks and limitations
webhook_keyis still a plainDatafield (plaintext at rest) until W3 lands.Rollback
Revert the 2 commits; Webhook/Manual types return to inert (current develop behavior).
Remaining work