Skip to content

feat(harness): use native engine trigger metadata delivery - #386

Merged
ytallo merged 1 commit into
mainfrom
feat/native-trigger-metadata-delivery
Jul 1, 2026
Merged

feat(harness): use native engine trigger metadata delivery#386
ytallo merged 1 commit into
mainfrom
feat/native-trigger-metadata-delivery

Conversation

@ytallo

@ytallo ytallo commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Why

#333 (agent trigger subscriptions) merged one commit short: feat(harness): use native engine trigger metadata delivery was written locally but never pushed before the PR got squash-merged, so main still carries the older payload-folding approach for subscription metadata delivery.

What

Bumps iii-sdk / iii-helpers to 0.20.0-alpha.1 for engine::register_trigger's first-class per-invocation metadata argument, and refactors harness::notify_agent to receive that metadata as a distinct handler argument instead of round-tripping it through a __metadata key folded into the fired event payload.

  • notify_agent::register now uses RegisterFunction::new_async_with_metadata, receiving (event, metadata) instead of a single mutated event.
  • parse_metadata replaces take_metadata — it reads the engine-delivered metadata argument directly instead of removing a reserved key from the payload.
  • Drops TRIGGER_META_KEY (__metadata) and the payload round-tripping it required — the engine now stores registration metadata on the Trigger and hands it back at fire time as its own argument, so the fired payload can never be mistaken for (or spoof) subscription metadata.
  • Doc comments in subscribe.rs, subscriptions/mod.rs, and subscriptions/registry.rs updated to describe the new delivery path.

No behavior change from the agent's perspective — this only changes how the harness receives trusted metadata from the engine at fire time.

Test plan

  • cargo build --all-targets
  • cargo test (115 passed)

Summary by CodeRabbit

  • Bug Fixes

    • Subscription notifications now use fire-time metadata directly, improving reliability and avoiding payload mutation.
    • Missing or invalid subscription metadata is now detected more consistently, preventing malformed notifications from being delivered.
  • Documentation

    • Clarified how subscription registration, teardown, and notification metadata are handled.
  • Chores

    • Updated dependency versions to match the pre-release SDK and helper package.

Bump iii-sdk / iii-helpers to 0.20.0-alpha.1 for engine::register_trigger's
first-class per-invocation metadata argument, and refactor notify_agent to
receive it as a distinct handler argument instead of round-tripping it
through a `__metadata` key folded into the fired payload.
@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
workers Ready Ready Preview, Comment Jul 1, 2026 9:39pm
workers-tech-spec Ready Ready Preview, Comment Jul 1, 2026 9:39pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Subscription trigger metadata is now delivered to notify_agent as a distinct invocation argument rather than being embedded in the fired payload. The TRIGGER_META_KEY constant is removed, handler registration switches to a metadata-aware variant with a new parse_metadata helper, and related docs, tests, and dependency pins are updated.

Changes

Subscription metadata delivery change

Layer / File(s) Summary
Documentation updates
harness/src/functions/subscribe.rs, harness/src/subscriptions/mod.rs, harness/src/subscriptions/registry.rs
Docs reworded to describe metadata attached to the engine Trigger and delivered separately, rather than folded into the payload.
Handler wiring and metadata parsing
harness/src/subscriptions/mod.rs, harness/src/subscriptions/notify_agent.rs
TRIGGER_META_KEY constant removed; registration switches to RegisterFunction::new_async_with_metadata passing metadata: Option<Value> into on_fire; new parse_metadata returns typed NotifyMetadata or MetadataError::Missing/Invalid.
Updated tests
harness/src/subscriptions/notify_agent.rs
Tests rewritten to target parse_metadata, covering missing, invalid, and valid metadata cases.
Dependency version alignment
harness/Cargo.toml
iii-sdk and iii-helpers pinned to =0.20.0-alpha.1 instead of =0.20.0.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Engine
  participant RegisterFunction
  participant on_fire
  participant parse_metadata

  Engine->>RegisterFunction: fire trigger (event, metadata)
  RegisterFunction->>on_fire: on_fire(deps, event, metadata)
  on_fire->>parse_metadata: parse_metadata(metadata)
  parse_metadata-->>on_fire: NotifyMetadata or MetadataError
  on_fire-->>Engine: notification sent or dropped
Loading

Suggested reviewers: sergiofilhowz, andersonleal

Poem

A rabbit hopped through payload dust,
found metadata deemed unjust—
"No more hiding in the event's core,
now you're an argument, front-door!" 🐇
parse_metadata sorts it clean,
Missing or Invalid, tests pristine.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: harness now uses native engine trigger metadata delivery instead of the payload workaround.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/native-trigger-metadata-delivery

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

skill-check — worker

0 verified, 30 skipped (no docs/).

Layer Result
structure
vale
ai
render

Four for four. Nicely done.

@ytallo
ytallo merged commit a9cc1b7 into main Jul 1, 2026
36 of 37 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
harness/src/subscriptions/notify_agent.rs (1)

151-160: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert once deserializes, not just that missing metadata is accepted.

on_fire uses meta.once to drive one-shot cleanup, but the new valid-case test never proves that "once": true survives parsing. Pinning that field here would catch regressions where one-shot subscriptions silently become persistent.

Suggested test tightening
         let valid = Some(json!({
             "subscription_id": "sub_1",
             "session_id": "s_secret",
-            "label": "done"
+            "label": "done",
+            "once": true
         }));
         let meta = parse_metadata(valid).unwrap();

         assert_eq!(meta.subscription_id, "sub_1");
         assert_eq!(meta.session_id, "s_secret");
         assert_eq!(meta.label.as_deref(), Some("done"));
+        assert!(meta.once);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@harness/src/subscriptions/notify_agent.rs` around lines 151 - 160, The
parse_metadata valid-case test in notify_agent::parse_metadata only checks
subscription_id, session_id, and label, but it does not verify that the once
flag is preserved. Update the existing valid metadata fixture to include "once":
true and assert the resulting meta.once is true, so the test covers the one-shot
path used by on_fire and catches regressions in parsing that field.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@harness/src/subscriptions/notify_agent.rs`:
- Around line 151-160: The parse_metadata valid-case test in
notify_agent::parse_metadata only checks subscription_id, session_id, and label,
but it does not verify that the once flag is preserved. Update the existing
valid metadata fixture to include "once": true and assert the resulting
meta.once is true, so the test covers the one-shot path used by on_fire and
catches regressions in parsing that field.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d046f0ab-c230-4b53-86a4-cb006d64b2d2

📥 Commits

Reviewing files that changed from the base of the PR and between 44b2f6f and 21816d9.

⛔ Files ignored due to path filters (1)
  • harness/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • harness/Cargo.toml
  • harness/src/functions/subscribe.rs
  • harness/src/subscriptions/mod.rs
  • harness/src/subscriptions/notify_agent.rs
  • harness/src/subscriptions/registry.rs

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.

1 participant