Agent Shared Runtime and Directory Boundaries
Verified on 2026-10-20 against aa75e64 and the first slice of todo:17. This page distinguishes current source locations, already-extracted capabilities, and capabilities pending migration; the companion user-facing page is Agent roles and selection; for categorization and console design see the Agent inventory and the four console page sets.
The Actual Current Layout
cmd/
server/ Server CLI
sidecar-agent/ sidecar CLI; the artifact is still named croupier-agent
devops-agent/ devops CLI
capture-agent/ capture CLI
synthetics-agent/ synthetics CLI (HTTP probing and external probe plugins)
core/ the composable shared Agent runtime
transport/ Handler/Client/Server shared contracts
tcp/ TCP/TLS client, framing, MuxConn, server TLS config
register/ registration, heartbeat, reconnect, owner identity
agentscope/ shared blank-rejection rules for registration identity (id/serverAddr/gameId/env)
backoff/ logx/ generic backoff and logging assembly
configsync/ versioned pulls and last-good application
supervisable/ process signals, exit codes, local heartbeat contract
healthprobe/ probes, failure windows, and protocol steps
report/ metrics/ reporting adapters and system metric sampling
execlog/ crash/ execution audit and crash helpers
process/ five-field cron, managed-process scheduling, and restart lifecycle decisions
pluginhost/ go-plugin processes, rate limiting, backoff, circuit breaking, and the sole exit manager
agents/
controlconn/ control-message adapter shared by devops/capture/synthetics
sidecar/
provider_session.go SDK provider sessions, indexing, and connection closing (homed in this slice)
provider_keepalive.go provider session transport keepalive probe (homed in this slice)
task_runner.go in-flight task lifecycle (execution seam, cancel, event reporting; homed in this slice)
funcplugin/ function plugin declaration, protocol, and host adapter
devops/{config,runner,session}/
capture/{config,runner,connector,source,filter,gate}/
synthetics/{config,runner,probe,pluginhost}/
internal/
app/agent/ sidecar assembly, supervision, provider, probes (migration remainder)
agent/ SDK local gateway and handlers (migration remainder); provider session/keepalive/task forwarding are aliases only
transport/tcp/ request-response Server; client/framing/MuxConn/TLS config forward to core
pkg/{pb,protocol}/ shared wire messages and message numberingAll four agent roles already have root cmd/ entries; synthetics' HTTP probing, persisted-result loop, and go-plugin adapter, plus the sidecar function-plugin adapter, were implemented before this slice. The root cmd/ is the sole agent binary entry — a second set of entries under agents/<role>/cmd must not be created; plugin examples inside role directories are standalone plugin-process examples.
Shared Capabilities and Business Boundaries
| Capability | Current shared implementation | Current consumers/boundary | Convergence direction |
|---|---|---|---|
| framing, TCP/TLS | core/transport/tcp | internal forwards via aliases; the Server TLS listener and the sidecar local gateway share the core TLS construction, standalone consumes via controlconn | One implementation; do not duplicate TLS/frame formats |
| Bidirectional session/multiplexing/dispatch backpressure | core/transport/tcp.MuxConn | sidecar, SDK provider, Server dispatch, and cluster clients already consume core directly; devops/capture/synthetics use a serial Client via controlconn | Implementation was lifted long ago; this slice converges real consumers and keeps internal compatibility shims; role send/receive models unchanged |
| SDK provider session/index/keepalive | agents/sidecar/provider_session.go, provider_keepalive.go | Homed from internal/agent in this slice; sidecar assembly consumes directly, old paths are type aliases and constructor forwards | The local gateway and registration handlers still await later migration by responsibility; they do not enter core |
| Registration, heartbeat, reconnect | core/register | All four roles consume; registration payloads are assembled per role | Lifecycle races are in CI; keep converging real offline-recovery acceptance |
| Explicit game/env ownership | core/agentscope | All four roles share the single blank-rejection rule (blank after trim = reject; report the first missing field in declaration order); each entry keeps its own error copy and call timing; sidecar scope checks only game/env and keep their Chinese copy | Already centrally extracted; error copy and call timing stay at the entry points; four-role consistency tests keep the same standard |
| Upstream message adapter | agents/controlconn, core/report | controlconn shares Register/Heartbeat/capture messages and synthetics probe reporting; not a unified session client for all roles | Extract a generic send/receive once the session is stable; business message handlers stay role-side |
| Signals and supervised contract | core/supervisable | Used by devops/capture/synthetics; the sidecar CLI has its own exit assembly | Unify error propagation and cleanup; do not treat owning main as equivalent to being properly supervised |
| Probing kernel | core/healthprobe | sidecar/Server assembly fairly complete; capture has readiness; synthetics' native HTTP probe still lives in agents/synthetics/probe and does not consume healthprobe; devops probe consumption incomplete | Revisit probe-kernel reuse later; external target categorization and plugin protocol adapters stay with synthetics |
| configsync | core/configsync | Pull/version/last-good are shared pieces; concrete config parsing stays business-side | No agent should hand-write its own pull state machine |
| Metrics/reporting/audit/snapshots | core/metrics, report, execlog, crash | Composed on demand; a shared package existing does not mean every role is wired | State is labeled by real consumption and end-to-end evidence |
| Managed-program supervisor | core/process, internal/app/agent/ops_* | Cron/scheduling, restart backoff, circuit breaking, exit classification, OOM-clue decisions, and the failure-count/backoff/recovery state machine are shared; Ops event logs, process assembly, and authorization remain sidecar-side | One manager per process; probe windows, spawn failures, and stability-window semantics feed the state machine from Ops |
| go-plugin process lifecycle | core/pluginhost (extracted before this slice) | sidecar/funcplugin and synthetics/pluginhost share startup, backpressure, backoff, circuit breaking, and Stop; each role keeps its own function/probe protocol | Keep one Controller managing one set of plugin processes; do not merge into the managed-program supervisor |
| OTel | internal/telemetry | Has a default-SDK/disable switch and a no_otel trim; plugins additionally have a no_go_plugin trim | This slice does not move telemetry, avoiding dependency leakage into the shared Checker or the game SDK |
SDK function registration and routing belong to the sidecar; SSH/RDP/VNC and the allowlist belong to devops; CDC sources, positions, and the three gates belong to capture; external target categorization and probe tasks belong to synthetics — business must not be moved into core for the sake of a tidy directory.
Target Layout and Migration Order
- The bidirectional session has been lifted; this slice moves the Server/Provider/tool and test consumers onto core and lifts the TLS listener configuration.
internal/transportkeeps compatibility aliases and the request-response Server, without duplicating MuxConn or TLS config logic. - The plugin host is already in
core/pluginhost, and sidecar/synthetics protocol adapters are in the role directories; the managed-program supervisor lifecycle is still in sidecar internal assembly, to be extracted later via audit/config dependency injection — no empty packages, no second process manager. - The sidecar's proprietary business moves homeward to
agents/sidecarstep by step; this slice migrates the provider session model, the index, and the original tests, keeping internal aliases. The rest ofinternal/agentandinternal/app/agentremains migration remainder; each batch migrates exactly one responsibility and verifies the call chain. - synthetics'
agents/synthetics/{config,runner,probe,pluginhost}and the rootcmd/synthetics-agentalready have real implementations reusing register/controlconn/pluginhost; native HTTP probing does not yet reuse healthprobe — advance by real consumption and verification.
Dependency direction: cmd → agents/<role> → core → pkg/pb/protocol; the Server's internal packages may consume core, and production code in core/agents must not import internal. .github/scripts/architecture_guard.sh checks that boundary; CI unit tests and coverage already include core/agents; the sidecar's remaining internal paths are explicit migration remainder — do not claim migration complete by renaming docs.
Build and Release Responsibilities
- Makefile:
make agents/make buildalready include all four agent roles (synthetics joins the aggregate viaagent-synthetics). nightly.yml: the sole daily build and nightly-tag update entry; keeps the bundle and publishes each role's standalone package, configs, role docs, and checksum manifest.release.yml: stable releases on v* tags only, with a manual run selecting a v* tag; no longer a second nightly uploader.- Native runners run agent
--versionchecks; cross-compiled artifacts do not impersonate native execution; ARMv7 carries sidecar/devops only — server/capture's old CDC parser has 32-bit integer overflow; synthetics is unverified on 32-bit, so the delivery surface stays 64-bit for now. - Packaging fails fast on missing inputs, and the manifest records SHA256 per real binary; nightly and stable packaging roles (the
package-agents.pyAGENTS single manifest) already include synthetics, delivered on 64-bit (ARMv7 remains sidecar/devops only); whenrelease.ymlpasses no--roles, it aligns to the same manifest automatically.
First-Slice Migration and Consumer Verification (2026-10-20)
| Capability/homing | Old location → current sole implementation | Compatibility and behavior |
|---|---|---|
| TLS listener config | createServerTLSConfig/BuildServerTLSConfig in internal/transport/tcp/server.go → core/transport/tcp/tls_server.go:17, :57 | Original function bodies only renamed helpers; internal/transport/tcp/server.go:219 and cmd/sidecar-agent/root.go:648 consume directly, old paths forward; TLS 1.2, mTLS with CA, insecure override, required/optional certs, and error text all unchanged |
| Provider session and index | internal/agent/provider_session.go → agents/sidecar/provider_session.go:16, :96 | Old path keeps type aliases; a new constructor entry binds an already-established MuxConn without dialing new connections; index, TTL, and closing behavior unchanged |
| Provider session tests | internal/agent/provider_session_test.go → agents/sidecar/provider_session_test.go | All original test functions moved along, assertions kept; connection-binding and closing tests added |
| Provider keepalive probe | internal/agent/provider_keepalive.go → agents/sidecar/provider_keepalive.go:16 | Implementation moved line by line (package name only); probe interval/removal/timeout/skip-on-Marshal-failure semantics unchanged; old path keeps type aliases + constructor forwards; the handshake helper depending on the gateway listener stays in internal/agent/tcp_local_listener_test.go for routing-related cases |
| In-flight task lifecycle | internal/agent/task_runner.go → agents/sidecar/task_runner.go:17 | Implementation moved line by line (package name only); Start/Cancel/event reporting/Marshal semantics unchanged; old path keeps type aliases + constructor forwards; private-helper cases like marshalTaskInvoke moved along; only exported-surface cases remain in internal via aliases |
| Consumer | Reference points (file:line) | Status in this slice |
|---|---|---|
| sidecar | internal/app/agent/app.go:182, :206, :213; internal/agent/tcp_local_listener.go:330 | Consumes agents/sidecar sessions directly; the gateway :15, :16 and internal/agent/local_handler.go:15 consume core transport directly |
| sidecar upstream | internal/app/agent/control_client.go:9, :10; internal/app/agent/upstream.go:122 | Already consumes core directly; verification kept |
| devops | agents/devops/runner/runner.go:54, :57 | Already on register/controlconn, no import changes needed; consumes the core Client via agents/controlconn/controlconn.go:12, :51 |
| capture | agents/capture/runner/runner.go:340, :343 | Already on register/controlconn, no import changes needed; still serial request-response |
| synthetics | agents/synthetics/runner/runner.go:52, :53 | Already on register/controlconn, no import changes needed; result wire and probe behavior unchanged |
| sidecar/synthetics plugins | agents/sidecar/funcplugin/host.go:61; agents/synthetics/pluginhost/controller.go:71 | Already consume core/pluginhost; verification kept; no duplicate hosts or new process managers |
| Server/cluster/ops dispatch | internal/server/{agent_session.go:10,tcp_listener.go:15,control_handler.go:25}; internal/cluster/transport.go:9; internal/logic/ops/agent_ops_client.go:9; internal/platform/dispatch/dispatcher.go:14; internal/svc/service_context.go:17 | session/client references moved to core; the request-response NewServer at cmd/server/cluster.go:215 stays internal |
| CLI/examples/adapter tools | cmd/sidecar-agent/root.go:19; examples/cmd/e2e-agent-probe/main.go:32; tools/adapters/{http/main.go:15,prom/main.go:10} | Client/Config consume core directly; NewServer in tests still uses the internal constructor |
The migration does not modify business decisions, error copy, wire formats, default timeouts, queues, reconnect, or exit policies. todo:17's MuxConn/session, managed-program supervisor lifecycle, sidecar homing, synthetics entry, and release aggregation are delivered; further convergence of control messages and the probe kernel is out of scope for this round and tracked in a separate ledger.
2026-10-20 lifecycle decision review: core/process provides restart backoff, circuit-break decisions/copy, cmd.Wait exit classification (Unix signals and the Windows no-signal boundary), and OOM-suspicion short-circuit logic; internal/app/agent keeps the supervisor state machine, event logs, process assembly, and authorization. The migration changes no default backoff, circuit-break thresholds, event types, state transitions, or probe behavior.
2026-10-22 supervisor state machine shared: core/process.SupervisorState converges the consecutive-failure count, the allowRestart gate, circuit-break/backoff decisions, backoff-expiry consumption, restart attempts, and stability-window recovery; internal/app/agent.supervisorState is a type alias with newSupervisorState forwarding construction; the Ops monitor drives the same state machine and keeps owning Wait, spawn/stop, authorization, events, and the stability window. State transitions, default backoff, thresholds, and events are unchanged; the old managedProcess fields remain only as a display-snapshot compatibility surface.
2026-10-20 ownership validation centrally extracted: core/agentscope provides the blank check NonBlank and the four-field registration identity Identity (id/serverAddr/gameId/env, reporting the first missing item in declaration order); devops/capture/synthetics config validation and internal/app/agent.ValidateAgentScope now consume these rules. Each entry point's error copy and call timing are unchanged (the sidecar keeps its Chinese copy); synthetics' first error field changed from map-iteration-order drift to fixed declaration order (an intentional behavior improvement; the copy itself is unchanged).
