Skip to content

fix(automations): resolve friendly template fields ({user_name}, {challenge_title}, …) - #33

Merged
tbcsec merged 1 commit into
mainfrom
fix/automation-friendly-fields
Jul 25, 2026
Merged

fix(automations): resolve friendly template fields ({user_name}, {challenge_title}, …)#33
tbcsec merged 1 commit into
mainfrom
fix/automation-friendly-fields

Conversation

@tbcsec

@tbcsec tbcsec commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Fixes #27

Root cause

Event payloads carry raw ids, and render_template substitutes payload values verbatim — so {user_id} in an announcement body rendered a UUID.

Fix — friendly companion fields

Before a matched rule's actions run, the engine resolves every id field in the payload into a human-friendly companion:

id field friendly companion
user_id (+ opener/assignee/author/actor_user_id) user_name (+ matching *_user_name)
team_id team_name
challenge_id challenge_title
survey_id survey_title
ticket_id ticket_subject
competition_id competition_name
  • Resolved once per rule run in run_rule — the single choke point both the engine and the time-based scheduler pass through, so every template-rendering action (notify / announcement / email / webhook body) sees them.
  • The rule builder now suggests them: the catalog derives each trigger's friendly fields from the same map, so {user_name} & co. appear in the field suggestions automatically.
  • Design call — ids stay ids: {user_id} still renders the id (webhook payloads and conditions legitimately need raw values). The friendly names are companions, not replacements — the builder's suggestions steer authors to the right placeholder.
  • Unresolvable ids (entity deleted between event and rule-fire) fall back to the raw value, so an advertised placeholder never renders as a literal {user_name}. Enrichment is fail-open — a lookup error logs and the rule still runs.

Verification

  • ✅ 3 new tests: enrich_payload unit (resolution, id fallback, input non-mutation), run_rule end-to-end (announcement body renders grace drew first blood on Warmup., not UUIDs), catalog advertising per trigger
  • ✅ Full backend suite: 377 passed

Follow-up (after this + #31 merge)

The demo seed's first-blood announcement can then showcase this: "{user_name} drew first blood on {challenge_title}!" — which also makes successive demo announcements visibly distinct (the perception half of #19). Kept out of this PR to avoid a demo.py conflict with #31.

🤖 Generated with Claude Code

…allenge_title}, …

Event payloads carry raw ids, so a template like "{user_id} solved it"
rendered a UUID (#27). Before a matched rule's actions run, the engine now
resolves each id field into a human-friendly companion:

  user_id → user_name            team_id → team_name
  opener/assignee/author/actor_user_id → *_user_name
  challenge_id → challenge_title survey_id → survey_title
  ticket_id → ticket_subject     competition_id → competition_name

- FRIENDLY_FIELDS + enrich_payload in utils/automation_actions.py; invoked
  once per rule run in run_rule — the single choke point both the engine and
  the time-based scheduler pass through, so every template-rendering action
  (notify / announcement / email / webhook body) sees the fields.
- Ids stay ids: webhooks and conditions legitimately need raw values, so the
  friendly names are companions, not replacements. An id that no longer
  resolves falls back to the raw value — an advertised placeholder never
  renders as a literal {user_name}.
- The builder catalog derives the friendly fields per trigger from the same
  map, so the rule editor suggests {user_name} & co. automatically.
- Enrichment is fail-open (a lookup error logs and the rule still runs).

Tests: enrich_payload unit (resolution, id fallback, non-mutation), run_rule
end-to-end (announcement body renders names, not UUIDs), catalog advertising.
Backend suite: 377 passed.

Fixes #27

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tbcsec
tbcsec merged commit 600fd88 into main Jul 25, 2026
3 checks passed
@tbcsec
tbcsec deleted the fix/automation-friendly-fields branch July 25, 2026 18:21
@tbcsec tbcsec added the bug label Jul 26, 2026
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.

[Bug]: automation template id's are display the ID value

1 participant