Skip to content

Global Chat: Receive job code for multiple steps#4888

Open
hanna-paasivirta wants to merge 6 commits into
mainfrom
global-chat-receive-multiple-steps
Open

Global Chat: Receive job code for multiple steps#4888
hanna-paasivirta wants to merge 6 commits into
mainfrom
global-chat-receive-multiple-steps

Conversation

@hanna-paasivirta

@hanna-paasivirta hanna-paasivirta commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Description

This PR lets Lightning receive job code for multiple steps at once from the Apollo AI server when using global chat. Before, the backend tried to extract a single job's code from the response. Now global chat always receives the full workflow YAML with every step body embedded. That means the assistant can change several steps and Lightning can apply all of them in one go.

Only global chat is affected. Job chat and workflow chat are unchanged.

Closes #4890

This PR will break the Global Assistant. The corresponding changes on Apollo need to be released soon after this one See: OpenFn/apollo#547

Implementation details

  • On the backend, build_global_message no longer tries to pick out one job's code. It now always reads the workflow_yaml attachment and stores the full YAML on the message. Global messages are tagged with meta: %{"from_global" => true} and never carry a job_id, even when the session was started from a job step. The old single-job extraction code is removed. This includes extract_global_code_and_job, resolve_job_from_key, and the name normalization helpers. We previously matched steps by name. We now match by step UUID instead, because the assistant might rename a step and name matching would break on rename. This relies on the AI server preserving the step IDs in the YAML it returns.

  • prepare_message_attrs now skips the job association logic for global messages. Non-global messages still go through maybe_put_job_id_from_session and maybe_put_unsaved_job_meta exactly as before. The channel serializer adds a from_global flag to each message and drops the legacy from_global_job_code handling.

  • On the frontend, a new from_global field is added to the Message type. Global messages carry the full workflow YAML in code and no job_id. A new handlePreviewGlobalStep handler mirrors handlePreviewJobCode, but extracts the open step's body from the workflow YAML by matching the open step's UUID. It shows a diff only when that step's body actually changed and clears any stale diff otherwise. handleApplyWorkflow is relaxed so global messages can apply the full workflow even while a job is open. Non-global workflow chat keeps the workflow_template-only guard, so its Apply stays a no-op when a job is open. Auto-preview routing picks handlePreviewGlobalStep for global messages and handlePreviewJobCode for job-code messages, and useAutoPreview now allows global messages that have no job_id.

  • When a step preview fails, we log the error and surface it to the user with a toast. Invalid workflow YAML shows an alert. A step whose ID is missing from the YAML (likely because the server did not preserve the ID) shows a warning.

  • The diff preview only shows for the single step that is currently open, and only when the user has a job-code step open. A follow-up PR will make it easier to view several step changes and diffs at once. This PR focuses on the basic functionality: receiving and applying changes correctly across several steps from Apollo.

Validation steps

Run the Apollo server from this branch with the required corresponding changes from Apollo: OpenFn/apollo#547

  1. On the OpenFn app, open an existing workflow, click into a job code step, and open the AI assistant. Make sure to tick the box for "Global assistant - experimental feature" to talk to the Global assistant.
  2. Ask the assistant to make an edit on several steps, including the one you are viewing (e.g. add a log to steps a, b that says "hello")
  3. Verify the diff appears as expected in the current step.
  4. Click apply, and verify that the changes were implemented in the other parts of the workflow as expected.
  • Verify that generate with AI from scratch (with job code filled in) still works like before.

Additional notes for the reviewer

Changes should only affect Global assistant, but please verify that this is true.

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

Pre-submission checklist

  • I have performed an AI review of my code (we recommend using /review
    with Claude Code)
  • I have implemented and tested all related authorization policies.
    (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

@github-project-automation github-project-automation Bot moved this to New Issues in Core Jun 23, 2026
@hanna-paasivirta hanna-paasivirta changed the title first pass receive yaml only Global Chat: Receive job code for multiple steps Jun 23, 2026
@hanna-paasivirta hanna-paasivirta marked this pull request as ready for review June 23, 2026 19:00
@theroinaochieng theroinaochieng moved this from New Issues to In review in Core Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Global assistant: Receive several job code step changes

2 participants