Skip to content

Conversation

@SasSwart
Copy link
Contributor

@SasSwart SasSwart commented Nov 13, 2025

closes: #10352
closes: coder/internal#1094
closes: coder/internal#1095

In this pull request, we enable a new set of experimental cli commands grouped under coder exp sync.
These commands allow any process acting within a coder workspace to inform the coder agent of its requirements and execution progress. The coder agent will then relay this information to other processes that have subscribed.

These commands are:

# Check if this feature is enabled in your environment 
coder exp sync ping

# express that your unit depends on another
coder exp sync want <unit> <dependency_unit> 

# express that your unit intends to start a portion of the script that requires 
# other units to have completed first. This command blocks until all dependencies have been met
coder exp sync start <unit> 

# express that your unit has completes its work, allowing dependent units to begin their execution
coder exp sync complete <unit>

Example:

In order to automatically run claude code in a new workspace, it must first have a git repository cloned. The scripts responsible for cloning the repository and for running claude code would coordinate in the following way:

# Script A: Claude code

# Inform the agent that the claude script wants the git script.
# That is, the git script must have completed before the claude script can begin its execution
coder exp sync want claude git

# Inform the agent that we would now like to begin execution of claude.
# This command will block until the git script (and any other defined dependencies)
# have completed
coder exp sync start claude

# Now we run claude code and any other commands we need
claude ...

# Once our script has completed, we inform the agent, so that any scripts that depend on this one
# may begin their execution

coder exp sync complete claude
# Script B: Git

# Because the git script does not have any dependencies, we can simply inform the agent that we 
# intend to start
coder exp sync start git

git clone ssh://git@github.com/coder/coder

# Once the repository have been cloned, we inform the agent that this script is complete, so that
# scripts that depend on it may begin their execution.
coder exp sync complete git

Notes:

  • Unit names (ie. claude and git) given as input to the sync commands are arbitrary strings. You do not have to conform to specific identifiers. We recommend naming your scripts descriptively, but succinctly.
  • Scripts unit names should be well documented. Other scripts will need to know the names you've chosen in order to depend on yours.

@SasSwart SasSwart force-pushed the jjs/internal-1095-branch3-agent-integration branch 2 times, most recently from 300321f to 0308560 Compare November 13, 2025 10:02
@SasSwart SasSwart changed the title Jjs/internal 1095 branch3 agent integration chore(agent): integrate the agent socket api into the workspace agent Nov 13, 2025
@SasSwart SasSwart marked this pull request as ready for review November 13, 2025 14:20
@mafredri mafredri self-requested a review November 14, 2025 12:03
@SasSwart SasSwart force-pushed the jjs/internal-1095-branch2-socket-server branch from a17863a to 9fdc98d Compare November 14, 2025 13:02
@SasSwart SasSwart force-pushed the jjs/internal-1095-branch3-agent-integration branch 2 times, most recently from f75b9fa to 53a0bb9 Compare November 17, 2025 13:54
@SasSwart SasSwart changed the base branch from jjs/internal-1095-branch2-socket-server to main November 17, 2025 14:08
@SasSwart SasSwart changed the base branch from main to jjs/internal-1095-branch2-socket-server November 17, 2025 14:09
@SasSwart SasSwart force-pushed the jjs/internal-1095-branch2-socket-server branch from f7245fa to 79d783a Compare November 20, 2025 07:23
@SasSwart SasSwart force-pushed the jjs/internal-1095-branch3-agent-integration branch from 53a0bb9 to eb34bc4 Compare November 21, 2025 11:02
Base automatically changed from jjs/internal-1095-branch2-socket-server to main November 21, 2025 11:09
@SasSwart SasSwart force-pushed the jjs/internal-1095-branch3-agent-integration branch from eb34bc4 to c8e8c20 Compare November 21, 2025 11:13
@SasSwart SasSwart changed the title chore(agent): integrate the agent socket api into the workspace agent chore(agent): integrate agent socket api into workspace agent Nov 24, 2025
@SasSwart SasSwart requested a review from mafredri November 24, 2025 09:24
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, some minor feedback inline, mainly re: lib design.

return c.conn.Close()
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: client.go

@SasSwart
Copy link
Contributor Author

@mafredri your remaining concerns are all related to the agent socket client. Can we deal with them in #20718? It deals primarily with this case. The client code here is already modified in that PR and we can include these suggestions.

relates to: coder/internal#1094

This is number 4 of 5 pull requests in an effort to add agent script
ordering. It adds an API client that can call the workspace agent socket
API for script ordering operations.

In a follow-up PR, CLI commands will be added that consume this API.

I used an LLM to produce some of these changes, but I have conducted
thorough self review and consider this contribution to be ready for an
external reviewer.

---------

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor nit about test placement, otherwise good to go 👍🏻

})
}

func TestAgentInitializesOnWindowsWithoutSocketServer(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test belongs IMO in agent/agent_test.go.

ping Test agent socket connectivity and health
start Wait until all unit dependencies are satisfied
status Show unit status and dependency state
want Declare that a unit depends on another unit completing before it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be shorter to make it look nicer (follow-up PR if you want).

@mafredri mafredri changed the title chore(agent): integrate agent socket api into workspace agent feat: implement agent socket api, client and cli Nov 27, 2025
@SasSwart SasSwart merged commit ce627bf into main Nov 28, 2025
38 checks passed
@SasSwart SasSwart deleted the jjs/internal-1095-branch3-agent-integration branch November 28, 2025 06:33
@github-actions github-actions bot locked and limited conversation to collaborators Nov 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

4 participants