Global Chat: Receive job code for multiple steps#4888
Open
hanna-paasivirta wants to merge 6 commits into
Open
Conversation
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_messageno longer tries to pick out one job's code. It now always reads theworkflow_yamlattachment and stores the full YAML on the message. Global messages are tagged withmeta: %{"from_global" => true}and never carry ajob_id, even when the session was started from a job step. The old single-job extraction code is removed. This includesextract_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_attrsnow skips the job association logic for global messages. Non-global messages still go throughmaybe_put_job_id_from_sessionandmaybe_put_unsaved_job_metaexactly as before. The channel serializer adds afrom_globalflag to each message and drops the legacyfrom_global_job_codehandling.On the frontend, a new
from_globalfield is added to theMessagetype. Global messages carry the full workflow YAML incodeand nojob_id. A newhandlePreviewGlobalStephandler mirrorshandlePreviewJobCode, 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.handleApplyWorkflowis 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 pickshandlePreviewGlobalStepfor global messages andhandlePreviewJobCodefor job-code messages, anduseAutoPreviewnow allows global messages that have nojob_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
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!):
You can read more details in our
Responsible AI Policy
Pre-submission checklist
/reviewwith Claude Code)
(e.g.,
:owner,:admin,:editor,:viewer)