feat(agent): register scripts as sync units for lifecycle tracking#27153
Draft
SasSwart wants to merge 1 commit into
Draft
feat(agent): register scripts as sync units for lifecycle tracking#27153SasSwart 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' and appear in 'coder exp sync timeline'. As each script executes, its unit status transitions from pending to started, then to completed. Changes: - 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 (via WithUnitManager). - Tests: added TestScriptUnitsRegistered and TestScriptUnitsLifecycle. Rebased onto the sync-unit-timeline branch: the socket server already exposes a WithUnitManager option there, so this revives PR #26459 without re-introducing its NewServer signature change.
9b52d47 to
5981e99
Compare
This was referenced Jul 10, 2026
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.
Revives #26459 (closed as stale) and rebases it onto the
sync-timeline-watchbranch (#27152), which addscoder exp sync timeline --watch. Together, agent scripts now appear in the timeline: each script is registered as a sync unit and itsregistered → started → completedlifecycle is recorded in the unit event log, socoder exp sync timeline(and--watch) shows a live history of all coder scripts and when they ran.Stacked on: #27152 → #27150 → #27149. Base is
sync-timeline-watch, notmain. Rebasing onto the watch branch lets the--watchflag be used when testing script lifecycle live.Changes
agent/agentscripts/agentscripts.go:Optionsgains aUnitManagerfield.Init()registers each script as a unit keyed byDisplayName(scripts with an empty display name are skipped; duplicate names are logged and skipped).run()marks the unitstartedbefore execution andcompletedafterward, regardless of success or failure. All calls are nil-guarded, so the runner still works without a manager.agent/agent.go: creates a single sharedunit.Managerininit()and passes it to both the script runner (UnitManager) and the socket server.Rebase note
The original #26459 changed
agentsocket.NewServerto take*unit.Manageras a required positional parameter. The timeline stack already introduces the same composition root via aWithUnitManagerfunctional option, so this revival drops #26459'sNewServersignature change (and its test call-site edits) and instead wires the shared manager throughagentsocket.WithUnitManager(a.unitManager). Net diff is 3 files, +168, and it touches onlyagent/files (disjoint from the watch branch'scli/changes), so the rebase ontosync-timeline-watchwas conflict-free.Testing
go build ./agent/...go test ./agent/agentscripts/ ./agent/agentsocket/(incl. newTestScriptUnitsRegisteredandTestScriptUnitsLifecycle)go test ./cli/ -run TestSync(timeline/status/watch goldens unchanged)Original PR #26459 design notes
Unit name: each script's
DisplayNameis used as the unit name (unit.ID). User-friendly but not guaranteed unique; uniqueness enforcement was deferred to a follow-up.Status lifecycle per script:
For cron scripts that run multiple times, the cycle repeats:
completed → started → completed → ...Generated by Coder Agents on behalf of @SasSwart.