Global Chat: Receive job code for multiple steps#4888
Conversation
elias-ba
left a comment
There was a problem hiding this comment.
Really nice work @hanna-paasivirta 👏🏽 🎉. I think this breaks the AI Assistant (at least the Global Chat), right ? So until PR 547 of Apollo be merged and deployed we can't really ship this guy. Maybe communicate that very well with the team so that they won't cut a release with this. Again great work
|
So I've run some testing against this and it seems to work just fine on main apollo? Because apollo already sends the full yaml back, and this PR just uses it and ignores the other stuff. So long as we release this before the apollo update, users won;'t see any breakage. This PR is fully compatible with both apollo releases. The preview and UI are broken, btu we know that and work that is coming up soon. I think that means this PR is ready to go |
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)