feat: register scripts as sync units for lifecycle tracking#26459
Draft
SasSwart wants to merge 1 commit into
Draft
feat: register scripts as sync units for lifecycle tracking#26459SasSwart wants to merge 1 commit into
SasSwart wants to merge 1 commit into
Conversation
The script runner now registers each script as a sync unit during Init() so all scripts are immediately visible via 'coder exp sync list'. As each script executes, its unit status transitions from pending to started, then to completed. Changes: - agent/agentsocket/server.go: NewServer takes *unit.Manager as a required parameter instead of creating its own internally. - agent/agentscripts/agentscripts.go: Options gains a UnitManager field. Init() registers scripts using DisplayName as the unit ID. run() sets unit status to started before execution and completed after. - agent/agent.go: Creates a shared unit.Manager and passes it to both the script runner and the socket server. - Tests: Updated NewServer call sites; added TestScriptUnitsRegistered and TestScriptUnitsLifecycle.
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.
The script runner now registers each workspace agent script as a sync unit during initialization, making all scripts immediately visible via
coder exp sync list. As the script runner executes each script, its unit status transitions through the lifecycle: pending, started, completed.Problem
The
agent/unit.Manager(sync unit system) andagent/agentscripts.Runner(script runner) were independent. Scripts run by the agent were invisible tocoder exp sync list, and there was no way to observe script lifecycle through the dependency coordination system.Changes
Shared
unit.Manager(composition root)Previously,
unit.NewManager()was created insideagentsocket.NewServer(), hidden from the rest of the agent. This PR lifts it out so the agent creates a singleunit.Managerand passes it to both the script runner and the socket server.agent/agentsocket/server.go:NewServertakes*unit.Manageras an explicit required parameter instead of creating its own.agent/agent.go: Creates a sharedunit.NewManager()ininit(), passes it to bothagentscripts.New()andagentsocket.NewServer().Script lifecycle tracking
agent/agentscripts/agentscripts.go:Optionsgains aUnitManagerfield.Init()registers each script using itsDisplayNameas the unit ID.run()marks the unit asstartedbefore execution andcompletedafter (regardless of success/failure).DisplayNamefor now. Uniqueness enforcement is deferred to a follow-up.Tests
NewServercall sites in tests to passunit.NewManager().TestScriptUnitsRegistered: verifies scripts with display names are registered as pending units during Init, and scripts without display names are skipped.TestScriptUnitsLifecycle: verifies the full pending, started, completed transition through Execute.Mini RFC / Design notes
Unit name
Each script's
DisplayNameis used as the unit name (unit.ID). This is user-friendly but not guaranteed unique. Uniqueness will be addressed in a follow-up.Status lifecycle per script
For cron scripts that run multiple times, the cycle repeats:
completed → started → completed → ...What this does NOT change
SyncListRPC from PR feat: addcoder exp sync listcommand #26443 surfaces the units as-is.DisplayName(follow-up).