mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 06:54:28 +00:00
fix(runner): enforce ownership and safe reconnects
Gate dispatch on reconciliation, retain cancellations across disconnects, and stop replaced clients. Guard the single-server runner topology with a database lease. Restage missing generated inputs, report signal exits, and bound generated-file cleanup.
This commit is contained in:
@@ -43,6 +43,19 @@ function createMockWs() {
|
||||
}
|
||||
}
|
||||
|
||||
function reconcile(runnerId: string, ws: RunnerSocket) {
|
||||
runnerService.handleMessage(
|
||||
runnerId,
|
||||
ws,
|
||||
JSON.stringify({
|
||||
type: 'reconcile',
|
||||
environment: { platform: 'linux', shell: '/bin/sh' },
|
||||
activeExecutions: [],
|
||||
completedExecutions: [],
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
describe('Concurrent Runner Sessions', () => {
|
||||
setupTestDbHooks()
|
||||
|
||||
@@ -64,6 +77,7 @@ describe('Concurrent Runner Sessions', () => {
|
||||
{ id: runner.id, teamId: team.id, name: runner.name, keyHash: hashRunnerKey(key) },
|
||||
conn.ws,
|
||||
)
|
||||
reconcile(runner.id, conn.ws)
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
@@ -201,6 +215,8 @@ describe('Concurrent Runner Sessions', () => {
|
||||
},
|
||||
gpuConn.ws,
|
||||
)
|
||||
reconcile(defaultRunner.id, defaultConn.ws)
|
||||
reconcile(gpuRunner.id, gpuConn.ws)
|
||||
|
||||
const defaultTool = createRunnerBashTool(
|
||||
{},
|
||||
|
||||
@@ -186,6 +186,21 @@ describe('createRunnerBashTool', () => {
|
||||
).rejects.toThrow(/exited with code 1/)
|
||||
})
|
||||
|
||||
it('reports signal termination as a command failure', async () => {
|
||||
const tool = createRunnerBashTool({}, { teamId: mockTeamId })
|
||||
vi.mocked(runnerService.exec).mockResolvedValue({
|
||||
executionId: 'signaled',
|
||||
output: '',
|
||||
exitCode: null,
|
||||
signal: 'SIGTERM',
|
||||
timedOut: false,
|
||||
aborted: false,
|
||||
})
|
||||
await expect(invokeTool(tool, '1', { command: 'command' }, createMockSignal())).rejects.toThrow(
|
||||
'terminated by SIGTERM',
|
||||
)
|
||||
})
|
||||
|
||||
it('should handle timeouts', async () => {
|
||||
const tool = createRunnerBashTool({}, { teamId: mockTeamId })
|
||||
|
||||
|
||||
@@ -208,6 +208,14 @@ export const createRunnerBashTool = (
|
||||
throw new Error(appendStatus(outputText, execResult.error))
|
||||
}
|
||||
|
||||
if (execResult.signal) {
|
||||
logger.error(
|
||||
{ signal: execResult.signal, command, outputText },
|
||||
'Bash command was terminated',
|
||||
)
|
||||
throw new Error(appendStatus(outputText, 'Bash command terminated by ' + execResult.signal))
|
||||
}
|
||||
|
||||
if (execResult.exitCode !== 0 && execResult.exitCode !== null) {
|
||||
logger.error(
|
||||
{ exitCode: execResult.exitCode, command, outputText },
|
||||
|
||||
Reference in New Issue
Block a user