Skip to content

feat(codegen): explicit activity-version pinning#172

Open
daniilrrr wants to merge 2 commits into
mainfrom
daniil/activity-version-capping
Open

feat(codegen): explicit activity-version pinning#172
daniilrrr wants to merge 2 commits into
mainfrom
daniil/activity-version-capping

Conversation

@daniilrrr

@daniilrrr daniilrrr commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an explicit activity-version pinning mechanism to Rust SDK codegen, mirroring the TypeScript SDK's VERSIONED_ACTIVITY_TYPES map.

Problem

Today, proto sync can auto-bump generated activity submission methods to whatever ACTIVITY_TYPE_* literal is present in the proto annotation, even if that activity version has not been released to production yet.

Mechanism

  • Adds codegen/activity_version_caps.json with an explicit pins map.
  • The map keys are base activity families, e.g. ACTIVITY_TYPE_SIGN_TRANSACTION.
  • The map values are the exact ACTIVITY_TYPE_* literals codegen should emit, e.g. ACTIVITY_TYPE_SIGN_TRANSACTION_V2.
  • Codegen strips trailing _V<number> suffixes to derive the base family, checks for a pin, and overrides the emitted activity type before looking up intent/result types in proto/activities.json.
  • Pin targets are validated against activities.json, and pins that cross base activity families are rejected.

No-op default

This PR seeds the config with empty pins, so it is mechanism-only and generated client output remains unchanged. The actual pins should be set in #171.

How to add a pin

Add an entry to codegen/activity_version_caps.json:

{
  "pins": {
    "ACTIVITY_TYPE_SIGN_TRANSACTION": "ACTIVITY_TYPE_SIGN_TRANSACTION_V2"
  }
}

The target activity version must already exist in proto/activities.json and must already be released in production.

Ordering

This should merge before #171 so that PR can add/bump pins using this mechanism.

Verification

  • PATH="/workspace/.cargo/bin:$PATH" make generate
  • git diff --stat -- client/src/generated produced no output
  • PATH="/workspace/.cargo/bin:$PATH" make lint
  • PATH="/workspace/.cargo/bin:$PATH" make test

@daniilrrr

Copy link
Copy Markdown
Contributor Author

More detail, from AI:

Prior art / reference

This mirrors the existing version-capping pattern in the TypeScript SDK repo tkhq/sdk. In the TS SDK, the capping map lives at the top of each codegen script as a const named VERSIONED_ACTIVITY_TYPES:

  • tkhq/sdk: packages/sdk-types/scripts/codegen.js
  • tkhq/sdk: packages/sdk-server/scripts/codegen.js
  • tkhq/sdk: packages/core/scripts/codegen.js
  • tkhq/sdk: packages/sdk-browser/scripts/codegen.js

Concrete references:

  • tkhq/sdk: packages/sdk-server/scripts/codegen.js#L16 — the map (string form): e.g. ACTIVITY_TYPE_SIGN_TRANSACTION: "ACTIVITY_TYPE_SIGN_TRANSACTION_V2", and notably ACTIVITY_TYPE_ETH_SEND_TRANSACTION: "ACTIVITY_TYPE_ETH_SEND_TRANSACTION" (deliberately pinned to V1).
  • tkhq/sdk: packages/sdk-server/scripts/codegen.js#L311 — the consumer: type: "${versionedActivityType ?? unversionedActivityType}" (use the pinned version if present, else the raw/unversioned value).
  • tkhq/sdk: packages/core/scripts/codegen.js#L578-L582 — same idea with an explicit comment: "Use the capped version if one exists, otherwise use the raw swagger value" → VERSIONED_ACTIVITY_TYPES[unversionedActivityType]?.[0] ?? rawActivityType.
  • tkhq/sdk: packages/sdk-types/scripts/codegen.js#L21-L122 — the 3-element array form [activityType, intentType, resultType] (sdk-types also pins intent/result type names).
  • Git history precedent: commit 56c730b41 ("Lock ethsendtransaction version") — the exact precedent for deliberately holding an activity at an older version.

How the Rust approach differs

Our Rust approach mirrors the same idea — an explicit base activity family → exact activity type map applied as an override before intent/result lookup — but consolidates it to a single source file (codegen/activity_version_caps.json) instead of the TS SDK's duplicated VERSIONED_ACTIVITY_TYPES map across 4 codegen scripts. A pin therefore only has to be set once. The downstream proto/activities.json lookup keys off the (possibly pinned) activity type, so the correct intent/result types come along automatically rather than being pinned separately.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a configurable “activity-version pinning” mechanism to Rust SDK codegen so generated activity submission methods can be capped to explicitly approved ACTIVITY_TYPE_* versions (mirroring the TypeScript SDK’s version map) rather than always following the proto annotation’s latest value.

Changes:

  • Introduces codegen/activity_version_caps.json with a pins map (base activity family → exact versioned activity literal).
  • Updates codegen to resolve the proto-provided activity type through the pins map before looking up intent/result types in proto/activities.json.
  • Adds helper functions and unit tests for version-suffix stripping and pin resolution/validation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
codegen/src/main.rs Loads caps config, resolves/pins activity types during codegen, and adds helper functions + tests.
codegen/activity_version_caps.json Adds the pins configuration file (seeded empty for no-op behavior).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread codegen/src/main.rs
Comment thread codegen/src/main.rs
- split initial validate from resolve of activities
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.

2 participants