Skip to content

[pull] main from vercel:main#328

Merged
pull[bot] merged 4 commits intoerickirt:mainfrom
vercel:main
May 5, 2026
Merged

[pull] main from vercel:main#328
pull[bot] merged 4 commits intoerickirt:mainfrom
vercel:main

Conversation

@pull
Copy link
Copy Markdown

@pull pull Bot commented May 5, 2026

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

…1935)

* [swc-plugin] Capture lexical `this` for nested arrow step functions

When a nested arrow `"use step"` references the enclosing function/method's
`this`, plumb that `this` through the workflow runtime so the step body
sees the correct receiver.

- Workflow mode wraps the step proxy with `.bind(this)`, so invoking the
  proxy captures the caller's `this` as `thisVal` on the queue item.
- Step mode hoists the body as a regular `function` (not an arrow) so the
  runtime's `stepFn.apply(thisVal, args)` rebinds `this` inside the
  hoisted body.

Detection only fires for arrows, since arrows inherit `this` lexically.
Nested non-arrow functions/methods/getters/setters introduce their own
`this`, so the detector stops at those boundaries.

The runtime already supported `thisVal` for instance-method steps; this
PR is purely a compiler change to feed the existing pipeline.

Caveat: capture works at runtime only when the captured value is
serializable across the workflow->step boundary (i.e. the enclosing
class implements `WORKFLOW_SERIALIZE`/`WORKFLOW_DESERIALIZE`).

Refs #1865

* Address PR review: preserve step proxy metadata + tighter `this` detection

- core: Override `.bind` on step proxies so the bound function retains
  `stepId` and `__closureVarsFn`. Without this, a bound proxy that flows
  through workflow serialization (e.g. as a step argument) would be
  treated as a non-serializable plain function by `getStepFunctionReducer`.
- swc-plugin: Detector now also walks `arrow.params` so `this` references
  in default values / destructuring initializers (e.g. `(x = this.foo) =>
  ...`) trigger the `.bind(this)` path.
- swc-plugin: Class bodies inside the arrow body are now treated as
  `this`-binding boundaries — `this` inside class field initializers,
  methods, etc. is bound to the class instance, not the outer arrow. The
  detector still walks `extends` clauses and computed property keys
  because those are evaluated in the surrounding scope.
- spec.md: Sharpen the note about `this` in step bodies — it's
  syntactically allowed but only meaningful for instance-method steps and
  lexical-`this` arrow steps; other shapes compile but `this` will be
  whatever the caller of the step proxy passes.
- Add `lexical-this-detector-edge-cases` fixture covering both the
  default-param positive case and the inner-class false-positive guard.
- Strengthen the runtime test to assert `stepId` / `__closureVarsFn`
  survive `.bind(...)`.

* [swc-plugin] Fix `arguments` closure-var capture; drop dead `this`/`arguments` checks

- Add `arguments` to `is_global_identifier` so it's not captured as a
  closure variable. Previously a nested `function`-form step like

      function step() { 'use step'; return arguments[0]; }

  was hoisted with `const { arguments } = ...` (a strict-mode syntax
  error) and the body's `arguments[0]` resolved against the destructured
  binding instead of the function's intrinsic `arguments` object.
- Remove dead `ForbiddenExpression` checks for `this` and `arguments` in
  `visit_mut_this_expr` / `visit_mut_ident`. The `'use step'` /
  `'use workflow'` directives are stripped during the module-level
  traversal before children are visited, so `in_step_function` /
  `in_workflow_function` are never observed as true here in practice.
  The existing `step-with-this-arguments-super` fixture explicitly
  documents that all three identifiers are allowed in step bodies.
- Tighten the spec note about `arguments` accordingly: it works in
  `function`-form steps (reflecting positional args) but is not captured
  for arrow-form steps; use `...args` for that case.
- Add `nested-step-arguments` fixture pinning down the new behavior.
…dispatch (#1943)

* Hoist AI model env, fix opencode external_directory permission, fail loud on AI infra errors

Three related fixes triggered by the failed run on #1935:

1. Hoist the AI model name to a top-level `AI_MODEL` env var
   (`anthropic/claude-opus-4.7`); both `opencode run` invocations
   now interpolate `vercel/${AI_MODEL}` so the model is specified in
   exactly one place.

2. Switch `OPENCODE_PERMISSION` from the bare-string shortcut
   `"allow"` to the explicit object form
   `{"*":"allow","external_directory":"allow"}`. The shortcut
   was observed not to override `external_directory` (which defaults to
   "ask" and auto-rejects in non-interactive `opencode run`),
   causing the conflict-resolution AI to fail when reading scratch files
   it created under `/tmp/`.

3. The `Resolve conflicts with opencode` step no longer uses
   `continue-on-error`, and now distinguishes two outcomes via an AI-
   written outcome file (`.backport-conflict-outcome.json`):

   - `{"status":"resolved"}` — the legitimate clean path; cherry-pick
     continues and the backport PR is opened.
   - `{"status":"unresolved", ...}` — the legitimate "AI couldn't
     do it, hand off to a human" path; `resolved=false` is set and the
     conflict-failure comment is posted on the source PR.
   - Anything else (missing file, malformed JSON, unknown status) is
     treated as an opencode/AI Gateway infra failure: the step exits
     non-zero, the workflow fails red, and the misleading
     "couldn't resolve" comment is suppressed.

   The prompt + scratch files are also moved into the workspace so
   opencode never needs `external_directory` access anyway.

* Allow manual workflow_dispatch with ref+model inputs; use AI_MODEL in PR body

Add a `workflow_dispatch` trigger to the backport workflow with two
optional inputs:

- `ref` — commit SHA on `main` to back-port (defaults to `main` HEAD)
- `model` — overrides the default AI model used by opencode for the
  decision and conflict-resolution steps (defaults to the workflow's
  hardcoded `AI_MODEL`)

The top-level `AI_MODEL` env var now uses
`${{ inputs.model || 'anthropic/claude-opus-4.7' }}` so manual runs
pick up the override without changing anything else.

Manual dispatch (like the `backport-stable` label) always forces a
backport regardless of any AI verdict — the operator's intent is
explicit by virtue of triggering the workflow. The PR body shows
"Triggered manually via `workflow_dispatch`." in that case.

The PR body's conflict-resolution attribution also now interpolates
`${AI_MODEL}` (e.g. "opencode with `anthropic/claude-opus-4.7`")
instead of hardcoding "Claude Opus" so the text stays accurate if the
default model is later changed.

* Address PR review: also detect leftover conflict markers in staged files

The previous `Resolve conflicts with opencode` sanity check used
`git diff --diff-filter=U` to detect unresolved cherry-pick conflicts,
which only catches unmerged index entries. That misses the case where
the AI runs `git add` on a file that still has `<<<<<<<` /
`=======` / `>>>>>>>` markers in its content — git happily stages
the broken file as a normal modification.

Add a second check using `git diff --check --cached`, which emits
`leftover conflict marker` lines when any staged content still has
the standard markers. Grep specifically for that phrase so unrelated
whitespace warnings don't trip the check. Also update the inline
comment to accurately describe what each check covers (per Copilot's
review on #1943).
* [swc-plugin] Preserve imports referenced by hoisted nested steps

Dead-code elimination ran before nested step functions were hoisted out of workflow bodies, so imports referenced only by hoisted step bodies were incorrectly stripped from the step bundle, causing a ReferenceError at runtime. Move DCE to run after hoisting in visit_mut_program.

* [swc-plugin] Namespace nested step IDs under non-exported workflow functions

Anonymous steps nested inside callback properties of a non-exported workflow function were registered with an unnamespaced step ID in step mode while the workflow-mode proxy looked them up under the workflow function name, causing a runtime 'step not found' failure. Set current_workflow_function_name in visit_mut_fn_decl for non-exported workflow functions to match the behavior in visit_mut_export_decl. Also clarify the fixture comment to distinguish step-mode and workflow-mode behavior per reviewer feedback.

* [swc-plugin] Namespace nested step IDs across all workflow declaration shapes

Extends the previous fix to cover all three non-exported workflow declaration forms (async function decl, const arrow, const fn-expr) by visiting the workflow body with workflow context before replacing it, and corrects the __internal_workflows manifest comment to report the same prefixed step IDs that are registered at runtime and looked up by the workflow-mode WORKFLOW_USE_STEP proxy. Adds a dedicated regression fixture covering all three shapes.
…es in o11y (#1942)

* fix(web-shared): hydrate FatalError/RetryableError and Error subclasses in o11y

The web o11y reviver set was missing entries for the recently-added
serialization types (FatalError, RetryableError, the built-in Error
subclasses, AggregateError, DOMException), causing devalue.unflatten to
throw "Unknown type X" and the UI to surface "Failed to load resource
details" whenever a step or run failed with one of these error types.

Adds the missing revivers to getWebRevivers() and a regression test that
round-trips real values through the runtime's dehydrateStepError back
through the web reviver set.

* fix(web-shared): address review feedback on error revivers

- Pass `cause` through ErrorOptions to the subclass constructor instead of
  assigning afterwards, matching `getCommonRevivers` in core. This gives
  the resulting `cause` property the same engine-set, non-enumerable
  semantics as a freshly thrown Error in the consumer realm.
- Guard `RetryableError.retryAfter` against missing/undefined values from
  older runtime payloads — without it, `new Date(undefined)` produces an
  Invalid Date rather than the property being absent. Add a defensive
  test that drives the reviver directly with a payload missing the field.
@pull pull Bot locked and limited conversation to collaborators May 5, 2026
@pull pull Bot added the ⤵️ pull label May 5, 2026
@pull pull Bot merged commit c80b747 into erickirt:main May 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant