Skip to content

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 ​

text
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 numbering

All 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 ​

CapabilityCurrent shared implementationCurrent consumers/boundaryConvergence direction
framing, TCP/TLScore/transport/tcpinternal forwards via aliases; the Server TLS listener and the sidecar local gateway share the core TLS construction, standalone consumes via controlconnOne implementation; do not duplicate TLS/frame formats
Bidirectional session/multiplexing/dispatch backpressurecore/transport/tcp.MuxConnsidecar, SDK provider, Server dispatch, and cluster clients already consume core directly; devops/capture/synthetics use a serial Client via controlconnImplementation was lifted long ago; this slice converges real consumers and keeps internal compatibility shims; role send/receive models unchanged
SDK provider session/index/keepaliveagents/sidecar/provider_session.go, provider_keepalive.goHomed from internal/agent in this slice; sidecar assembly consumes directly, old paths are type aliases and constructor forwardsThe local gateway and registration handlers still await later migration by responsibility; they do not enter core
Registration, heartbeat, reconnectcore/registerAll four roles consume; registration payloads are assembled per roleLifecycle races are in CI; keep converging real offline-recovery acceptance
Explicit game/env ownershipcore/agentscopeAll 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 copyAlready centrally extracted; error copy and call timing stay at the entry points; four-role consistency tests keep the same standard
Upstream message adapteragents/controlconn, core/reportcontrolconn shares Register/Heartbeat/capture messages and synthetics probe reporting; not a unified session client for all rolesExtract a generic send/receive once the session is stable; business message handlers stay role-side
Signals and supervised contractcore/supervisableUsed by devops/capture/synthetics; the sidecar CLI has its own exit assemblyUnify error propagation and cleanup; do not treat owning main as equivalent to being properly supervised
Probing kernelcore/healthprobesidecar/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 incompleteRevisit probe-kernel reuse later; external target categorization and plugin protocol adapters stay with synthetics
configsynccore/configsyncPull/version/last-good are shared pieces; concrete config parsing stays business-sideNo agent should hand-write its own pull state machine
Metrics/reporting/audit/snapshotscore/metrics, report, execlog, crashComposed on demand; a shared package existing does not mean every role is wiredState is labeled by real consumption and end-to-end evidence
Managed-program supervisorcore/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-sideOne manager per process; probe windows, spawn failures, and stability-window semantics feed the state machine from Ops
go-plugin process lifecyclecore/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 protocolKeep one Controller managing one set of plugin processes; do not merge into the managed-program supervisor
OTelinternal/telemetryHas a default-SDK/disable switch and a no_otel trim; plugins additionally have a no_go_plugin trimThis 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 ​

  1. 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/transport keeps compatibility aliases and the request-response Server, without duplicating MuxConn or TLS config logic.
  2. 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.
  3. The sidecar's proprietary business moves homeward to agents/sidecar step by step; this slice migrates the provider session model, the index, and the original tests, keeping internal aliases. The rest of internal/agent and internal/app/agent remains migration remainder; each batch migrates exactly one responsibility and verifies the call chain.
  4. synthetics' agents/synthetics/{config,runner,probe,pluginhost} and the root cmd/synthetics-agent already 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 build already include all four agent roles (synthetics joins the aggregate via agent-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 --version checks; 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.py AGENTS single manifest) already include synthetics, delivered on 64-bit (ARMv7 remains sidecar/devops only); when release.yml passes no --roles, it aligns to the same manifest automatically.

First-Slice Migration and Consumer Verification (2026-10-20) ​

Capability/homingOld location → current sole implementationCompatibility and behavior
TLS listener configcreateServerTLSConfig/BuildServerTLSConfig in internal/transport/tcp/server.go → core/transport/tcp/tls_server.go:17, :57Original 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 indexinternal/agent/provider_session.go → agents/sidecar/provider_session.go:16, :96Old 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 testsinternal/agent/provider_session_test.go → agents/sidecar/provider_session_test.goAll original test functions moved along, assertions kept; connection-binding and closing tests added
Provider keepalive probeinternal/agent/provider_keepalive.go → agents/sidecar/provider_keepalive.go:16Implementation 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 lifecycleinternal/agent/task_runner.go → agents/sidecar/task_runner.go:17Implementation 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
ConsumerReference points (file:line)Status in this slice
sidecarinternal/app/agent/app.go:182, :206, :213; internal/agent/tcp_local_listener.go:330Consumes agents/sidecar sessions directly; the gateway :15, :16 and internal/agent/local_handler.go:15 consume core transport directly
sidecar upstreaminternal/app/agent/control_client.go:9, :10; internal/app/agent/upstream.go:122Already consumes core directly; verification kept
devopsagents/devops/runner/runner.go:54, :57Already on register/controlconn, no import changes needed; consumes the core Client via agents/controlconn/controlconn.go:12, :51
captureagents/capture/runner/runner.go:340, :343Already on register/controlconn, no import changes needed; still serial request-response
syntheticsagents/synthetics/runner/runner.go:52, :53Already on register/controlconn, no import changes needed; result wire and probe behavior unchanged
sidecar/synthetics pluginsagents/sidecar/funcplugin/host.go:61; agents/synthetics/pluginhost/controller.go:71Already consume core/pluginhost; verification kept; no duplicate hosts or new process managers
Server/cluster/ops dispatchinternal/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:17session/client references moved to core; the request-response NewServer at cmd/server/cluster.go:215 stays internal
CLI/examples/adapter toolscmd/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).