push container state changes via docker events - #181
Open
DrDead0 wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The server-side container cache path lacks a clear fallback refresh mechanism and currently reports a misleading “1970” updatedAt before the first real snapshot arrives.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR shifts container state updates from “pull on every UI poll” to “agent pushes updates,” using Docker’s container event stream to keep the server’s in-memory container inventory current and letting the web UI poll the server cache cheaply.
Changes:
- Web now polls
/hosts/:id/containersevery 2s instead of 20s. - Server
/hosts/:id/containersnow serves fromContainerInventoryServicecache rather than requesting a fresh list from the agent per request. - Agent subscribes to Docker container events and debounces bursts to push a refreshed container list to the server.
File summaries
| File | Description |
|---|---|
| apps/web/tsconfig.app.json | Removes a TypeScript compiler option (ignoreDeprecations). |
| apps/web/src/hooks/useContainers.ts | Reduces refetch interval to 2s to reflect faster server-side cache freshness. |
| apps/server/src/hosts/hosts.service.ts | Decouples container listing from AgentsGateway and serves from in-memory inventory cache. |
| apps/server/src/hosts/hosts.service.spec.ts | Updates unit test wiring after HostsService constructor dependency changes. |
| apps/agent/internal/docker/service.go | Adds a Docker events API wrapper filtered to container lifecycle events. |
| apps/agent/internal/communication/client.go | Consumes Docker events, debounces, and pushes container lists proactively. |
Review details
Suppressed comments (1)
apps/server/src/hosts/hosts.service.spec.ts:35
- The
ContainerInventoryServicemock inmakeServiceonly stubsrememberHost, butHostsServicenow depends oninventory.getByHostId()forlistContainers(). Adding a stub here prevents future tests from failing with a runtimegetByHostId is not a functionif coverage is expanded.
return new HostsService(
agents as AgentsService,
{ rememberHost: jest.fn() } as unknown as ContainerInventoryService,
{
rememberHost: jest.fn(),
getByHostId: jest.fn().mockReturnValue(null),
} as unknown as HostMetricsService,
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| hostId: agent.id, | ||
| containers, | ||
| containers: snapshot?.containers ?? [], | ||
| updatedAt: snapshot?.updatedAt ? snapshot.updatedAt.toISOString() : null, |
Comment on lines
105
to
113
| this.inventory.rememberHost(agent.id, agent.uuid); | ||
|
|
||
| const containers = await this.agentsGateway.requestContainerList( | ||
| agent.uuid, | ||
| agent.id, | ||
| ); | ||
| const snapshot = this.inventory.getByHostId(agent.id); | ||
|
|
||
| return { | ||
| hostId: agent.id, | ||
| containers, | ||
| containers: snapshot?.containers ?? [], | ||
| updatedAt: snapshot?.updatedAt ? snapshot.updatedAt.toISOString() : null, | ||
| }; |
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.
Summary
This PR transitions container state management from a purely poll-based model to an event-driven push model.
Previously, the server forced the agent to run
docker psvia socket request on every dashboard poll, which was expensive and resulted in stale data. Now, the Go agent taps into the Docker event stream (type=container), uses a 500ms debouncer to safely batch event storms, and proactively pushes the new container list to the server. TheHostsServicehas been decoupled fromAgentsGatewayand now instantly serves the/hosts/:id/containersroute from its authoritative memory cache, allowing the web dashboard to poll the server cache very cheaply at a 2s interval.Type of change
Areas touched
apps/server(NestJS)apps/web(React / Vite)apps/agent(Go)packages/protocol(shared WebSocket contracts)infrastructure/.github/workflowsdocsRelated issues
Closes #162
How to test
docker run -d --name test-container alpine sleep 30).requestContainerListsocket round-trip.Checklist
docs/if module boundaries or the protocol changed.docs/decisions/if this is a larger architectural change.Local checks