Skip to content

Define shared event subscriptions and handler input in adapter-core - #278

Closed
willwashburn wants to merge 1 commit into
mainfrom
codex/flow-event-contract
Closed

willwashburn wants to merge 1 commit into
mainfrom
codex/flow-event-contract

Conversation

@willwashburn

@willwashburn willwashburn commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Cloud and authored Flows need a shared boundary between subscription selection and handler execution. Today their envelopes differ, and generated flow code repeats source checks inside runs. This adds @relayfile/adapter-core/events: catalog-backed subscription declarations and validated event snapshots that downstream hosts can use before starting a handler.

  • defineEventSubscription / parseEventSubscription describe a connection, exact adapter event types, and optional concrete path prefixes. Unknown selectors fail closed.
  • createAdapterEvent / parseAdapterEvent preserve existing logical event identity, transport identity, verified-context fields, paths and JSON payload as immutable snapshots.
  • Reuses the existing trigger catalog; adds no provider inventory, credentials, filter execution, dedupe store or Flows runtime.
  • Documents host matching/authentication/durable-delivery responsibilities and the Cloud envelope bridge. Nonmatching events should create no run. Provider payload semantics remain adapter-specific.

Validation

The required repository gate completed with exit 0:

PATH="/tmp/flows-ci-toolchain/node_modules/.bin:$PATH" npm_config_cache=/tmp/relayfile-event-npm-cache npx turbo build typecheck test > /tmp/relayfile-event-gate.log 2>&1

Captured final output excerpt:

 Tasks:    157 successful, 157 total
Cached:    0 cached, 157 total
  Time:    39.36s

New public-export tests cover all catalog events, provider/event type mismatches, schema/selector refusal, immutable snapshots, provenance, paths, identity preservation and JSON validation. A packed consumer and browser-target bundle also agree on the serialized contract. Commands and captured evidence.

Release and downstream work

After human review and merge, publish core (@relayfile/adapter-core) through the publish workflow. This feature PR does not bump versions. No provider packages or mount resync are required for this additive contract.

Then consume the published version in Flows and Cloud: wire .on(source, handler), one-off CLI supplied events, authenticated Cloud delivery, stable event identity and handler binding. Finally update the builder to generate that supported shape. This PR alone does not make those execution paths work; the staged contract is in event-subscriptions.md.

Flows PR AgentWorkforce/flows#401 remains a separate completion-handling/schema repair. Its cancellation fixture now represents an explicit request to stop work, not a filter mismatch.

Review in cubic


Note

Low Risk
Additive contract and validation layer with no runtime listeners or execution changes; downstream hosts must still implement matching, auth, and dedupe correctly when they adopt it.

Overview
Introduces @relayfile/adapter-core/events, a new browser-safe subpath for versioned event subscription declarations and handler event envelopes that Cloud and Flows can share before starting a run.

Subscriptions use defineEventSubscription / parseEventSubscription with schema relayfile.event-subscription/1: provider, connectionId, exact catalog-backed eventTypes, and optional concrete pathPrefixes. Unknown providers, event names, schema versions, or extra selector fields are rejected.

Handler input uses createAdapterEvent / parseAdapterEvent with schema relayfile.adapter-event/1: preserves upstream logical id separately from optional transport deliveryId, plus workspace/connection context, canonical timestamps, adapter-mapped paths, and frozen JSON payload. Parsing validates shape and catalog names only—no auth, matching, or deduplication (documented as host responsibilities).

The package export is wired in package.json, re-exported from the core entrypoint, covered by contract.test.ts, and documented in docs/event-subscriptions.md with rollout notes for Flows/Cloud. Verification notes confirm turbo gate and packed/browser bundle parity.

Reviewed by Cursor Bugbot for commit d0fd82b. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-14T22:51:52.613885Z d0fd82b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 2df3e941-fee0-4bb0-9290-7f45c9de7e6b

📥 Commits

Reviewing files that changed from the base of the PR and between 0ce581f and d0fd82b.

📒 Files selected for processing (12)
  • CHANGELOG.md
  • docs/event-subscriptions.md
  • docs/verification/event-contract.md
  • packages/core/README.md
  • packages/core/package.json
  • packages/core/src/events/contract.test.ts
  • packages/core/src/events/event.ts
  • packages/core/src/events/index.ts
  • packages/core/src/events/subscription.ts
  • packages/core/src/events/types.ts
  • packages/core/src/events/validation.ts
  • packages/core/src/index.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds versioned subscription and adapter-event contracts to @relayfile/adapter-core/events. It adds browser-safe validation, constructors, package exports, contract tests, changelog content, and usage and verification documentation.

Changes

Event contract module

Layer / File(s) Summary
Event models and validation
packages/core/src/events/types.ts, packages/core/src/events/validation.ts
Defines versioned subscription and adapter-event types. Validates providers, event types, paths, timestamps, lists, and JSON payloads.
Subscription and adapter event constructors
packages/core/src/events/subscription.ts, packages/core/src/events/event.ts
Adds constructors and parsers that reject unsupported schemas and return frozen validated objects.
Public package surface and contract tests
packages/core/src/events/index.ts, packages/core/src/index.ts, packages/core/package.json, packages/core/src/events/contract.test.ts
Exports the events module and tests validation, identity preservation, immutability, payload handling, paths, and provider-specific typing.
Usage documentation and verification records
docs/event-subscriptions.md, docs/verification/event-contract.md, packages/core/README.md, CHANGELOG.md
Documents event contracts, host delivery obligations, rollout details, verification results, and the unreleased feature. 🍃

Priority: ⬇️ Low

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Consumer
  participant EventConstructors
  participant EventValidation
  Consumer->>EventConstructors: define or create event input
  EventConstructors->>EventValidation: validate record and fields
  EventValidation-->>EventConstructors: validated event data
  EventConstructors-->>Consumer: frozen contract object
Loading

Merge Risk: ⚪ Minimal · up to d0fd8

The new event-contract API validates and snapshots contract data without adding runtime delivery behavior. No actionable merge risk remains from the available evidence.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 7 files. (5 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding shared event subscriptions and handler input contracts to adapter-core.
Description check ✅ Passed The description directly explains the new event contracts, validation behavior, responsibilities, testing, and downstream scope.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 7 files. (5 skipped: 5 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/flow-event-contract

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

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

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

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0fd82bd12

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +47 to +48
if (!result.startsWith("/") || result.includes("\\") || /[\u0000-\u001f\u007f*?\[\]{}]/u.test(result)
|| (result !== "/" && result.split("/").slice(1).some(part => !part || part === "." || part === ".."))) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Accept metacharacters emitted by canonical path helpers

When a storage key contains a literal *, this rejects an adapter-owned canonical path: for example, S3's toObjectRelayfilePath({ bucket: "b", key: "folder/*.txt" }) emits /s3/b/folder/*.txt because its segment encoder leaves * unchanged, so both createAdapterEvent and an exact-path subscription fail for a valid materialized record. Validate affected record paths separately from selector glob syntax, or otherwise ensure all existing path-mapper outputs remain accepted.

AGENTS.md reference: AGENTS.md:L7-L7

Useful? React with 👍 / 👎.

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