Repository navigation
fix(fleet): skip Go slot refresh when container is absent (#628) #642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ad921b0
fix(fleet): skip telemetry refresh when slot container is absent (#628)
cursoragent 8acdbbd
style: biome format fleet skip changes
cursoragent 59f1028
test: stub inspectContainerOrNull in remote service refresh sandbox
cursoragent 19e4417
docs(changelog): move #628 entry under 未发布
cursoragent 871f448
fix(fleet): only skip telemetry refresh on confirmed missing container
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /** Shared helpers for docker slot containers on the control plane / node host. */ | ||
|
|
||
| export function isMissingContainerMessage(message) { | ||
| return /no such container/i.test(String(message || '')) | ||
| } | ||
|
|
||
| /** Local `docker inspect` / Engine 404: container id or name is gone. */ | ||
| export function isDockerInspectNotFound({ stderr = '', stdout = '' } = {}) { | ||
| const hay = `${stderr}\n${stdout}` | ||
| return /no such container|no such object/i.test(hay) | ||
| } | ||
|
|
||
| export function telemetryContainerSkip(container, detail) { | ||
| return { | ||
| ok: true, | ||
| skipped: true, | ||
| action: 'skipped', | ||
| reason: 'container_unavailable', | ||
| container: String(container || ''), | ||
| ...(detail ? { detail: String(detail).slice(0, 300) } : {}), | ||
| } | ||
| } | ||
|
|
||
| export function logTelemetryContainerSkip(scope, vmId, container, detail) { | ||
| const suffix = detail ? `: ${detail}` : '' | ||
| console.warn(`[${scope}] Go slot service refresh skipped ${vmId}: no container ${container} on this host${suffix}`) | ||
| } |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import test from 'node:test' | ||
| import assert from 'node:assert/strict' | ||
| import { inspectContainerOutcome } from '../../src/lib/vm/vm-runtime.mjs' | ||
| import { isDockerInspectNotFound } from '../../src/lib/vm/docker-container.mjs' | ||
|
|
||
| test('isDockerInspectNotFound matches docker inspect stderr for absent names', () => { | ||
| assert.equal(isDockerInspectNotFound({ stderr: 'Error: No such object: kin-05' }), true) | ||
| assert.equal(isDockerInspectNotFound({ stderr: 'Error response from daemon: No such container: kin-05' }), true) | ||
| assert.equal(isDockerInspectNotFound({ stderr: 'Cannot connect to the Docker daemon' }), false) | ||
| }) | ||
|
|
||
| test('inspectContainerOutcome: missing container', () => { | ||
| const outcome = inspectContainerOutcome('kin-ghost', { | ||
| run: () => ({ | ||
| ok: false, | ||
| stderr: 'Error: No such object: kin-ghost', | ||
| stdout: '', | ||
| code: 1, | ||
| }), | ||
| }) | ||
| assert.deepEqual(outcome, { status: 'missing' }) | ||
| }) | ||
|
|
||
| test('inspectContainerOutcome: daemon down is an error, not missing', () => { | ||
| const outcome = inspectContainerOutcome('kin-01', { | ||
| run: () => ({ | ||
| ok: false, | ||
| stderr: 'Cannot connect to the Docker daemon at unix:///var/run/docker.sock', | ||
| stdout: '', | ||
| code: 1, | ||
| }), | ||
| }) | ||
| assert.equal(outcome.status, 'error') | ||
| assert.match(outcome.error, /Cannot connect/) | ||
| }) | ||
|
|
||
| test('inspectContainerOutcome: found parses running state', () => { | ||
| const outcome = inspectContainerOutcome('kin-01', { | ||
| run: () => ({ | ||
| ok: true, | ||
| stdout: 'true|12345|kin-px-net|2026-01-01T00:00:00Z|img|host|docker||false', | ||
| stderr: '', | ||
| }), | ||
| }) | ||
| assert.equal(outcome.status, 'found') | ||
| assert.equal(outcome.container.running, true) | ||
| assert.equal(outcome.container.pid, 12345) | ||
| }) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import test from 'node:test' | ||
| import assert from 'node:assert/strict' | ||
| import fs from 'node:fs' | ||
| import os from 'node:os' | ||
| import path from 'node:path' | ||
| import { runFleetUpdate } from '../../src/lib/vm/fleet-update.mjs' | ||
| import { restartTelemetrySidecar } from '../../src/lib/vm/slot-process-status.mjs' | ||
|
|
||
| function writeSlot(root, id) { | ||
| const dir = path.join(root, 'vms') | ||
| fs.mkdirSync(dir, { recursive: true }) | ||
| fs.writeFileSync( | ||
| path.join(dir, `${id}.json`), | ||
| JSON.stringify({ | ||
| id, | ||
| name: id.replace('vm-', ''), | ||
| status: 'running', | ||
| runtime: { type: 'docker', worker: 'go' }, | ||
| }), | ||
| ) | ||
| } | ||
|
|
||
| test('restartTelemetrySidecar skips only when inspect confirms the container is missing', async () => { | ||
| const root = fs.mkdtempSync(path.join(os.tmpdir(), 'kin-tel-miss-')) | ||
| const skipped = await restartTelemetrySidecar({ | ||
| projectRoot: root, | ||
| vm: { id: 'vm-11', runtime: { type: 'docker' } }, | ||
| enabled: true, | ||
| inspectContainerOutcome: () => ({ status: 'missing' }), | ||
| run: async () => { | ||
| throw new Error('docker exec must not run when the container is absent') | ||
| }, | ||
| }) | ||
| assert.equal(skipped.skipped, true) | ||
| fs.rmSync(root, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| test('restartTelemetrySidecar fails when inspect cannot reach docker', async () => { | ||
| const root = fs.mkdtempSync(path.join(os.tmpdir(), 'kin-tel-daemon-')) | ||
| const failed = await restartTelemetrySidecar({ | ||
| projectRoot: root, | ||
| vm: { id: 'vm-12', runtime: { type: 'docker' } }, | ||
| enabled: true, | ||
| inspectContainerOutcome: () => ({ | ||
| status: 'error', | ||
| error: 'Cannot connect to the Docker daemon', | ||
| }), | ||
| }) | ||
| assert.equal(failed.ok, false) | ||
| assert.equal(failed.code, 'docker_inspect_failed') | ||
| assert.equal(failed.skipped, undefined) | ||
| fs.rmSync(root, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| test('restartTelemetrySidecar fails when the container exists but exec fails', async () => { | ||
| const root = fs.mkdtempSync(path.join(os.tmpdir(), 'kin-tel-exec-')) | ||
| const failed = await restartTelemetrySidecar({ | ||
| projectRoot: root, | ||
| vm: { id: 'vm-13', runtime: { type: 'docker' } }, | ||
| enabled: true, | ||
| inspectContainerOutcome: () => ({ | ||
| status: 'found', | ||
| container: { name: 'kin-13', running: true }, | ||
| }), | ||
| run: async () => { | ||
| throw new Error('permission denied') | ||
| }, | ||
| }) | ||
| assert.equal(failed.ok, false) | ||
| assert.equal(failed.action, 'restart_failed') | ||
| assert.match(failed.error, /permission denied/) | ||
| fs.rmSync(root, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| test('fleet telemetry fails the batch when local inspect errors', async () => { | ||
| const root = fs.mkdtempSync(path.join(os.tmpdir(), 'kin-fleet-inspect-')) | ||
| writeSlot(root, 'vm-14') | ||
| const report = await runFleetUpdate(root, { | ||
| action: 'telemetry', | ||
| telemetryFn: async () => ({ | ||
| ok: false, | ||
| code: 'docker_inspect_failed', | ||
| error: 'Cannot connect to the Docker daemon', | ||
| }), | ||
| }) | ||
| assert.equal(report.failed_count, 1) | ||
| assert.equal(report.skipped_count, 0) | ||
| fs.rmSync(root, { recursive: true, force: true }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inspect failures skipped as missing
Medium Severity
The new pre-check treats any failed
inspectContaineras a missing slot and returns a successful skip.inspectContainerreturnsnullfor daemon-down, permission, and timeout errors as well as a real absence, so those hard failures never reach the laterNo such containerclassifier. Fleet then reportsokwithskipped_count, andinstall.shrefresh can exit 0 without restarting Go services.Triggered by learned rule: kin-egress reload waits for old process exit
Reviewed by Cursor Bugbot for commit 2a4e0c9. Configure here.