Skip to content

Commit ab7d0ca

Browse files
committed
fix(gastown): address review comments — reset poll_null_count on all non-null polls, abort orphaned session on startup abort, guard agents.delete with identity check
1 parent 3c4e5ff commit ab7d0ca

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

cloudflare-gastown/container/src/process-manager.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,14 +686,27 @@ export async function startAgent(
686686
if (sessionCounted) {
687687
const instance = sdkInstances.get(workdir);
688688
if (instance) {
689+
// Abort the orphaned session if one was created before the abort
690+
if (agent.sessionId) {
691+
try {
692+
await instance.client.session.abort({ path: { id: agent.sessionId } });
693+
} catch (abortErr) {
694+
console.error(
695+
`${MANAGER_LOG} startAgent: failed to abort orphaned session ${agent.sessionId}:`,
696+
abortErr
697+
);
698+
}
699+
}
689700
instance.sessionCount--;
690701
if (instance.sessionCount <= 0) {
691702
instance.server.close();
692703
sdkInstances.delete(workdir);
693704
}
694705
}
695706
}
696-
agents.delete(request.agentId);
707+
if (agents.get(request.agentId) === agent) {
708+
agents.delete(request.agentId);
709+
}
697710
throw err;
698711
}
699712

cloudflare-gastown/src/dos/town/actions.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ export function applyAction(ctx: ApplyActionContext, action: Action): (() => Pro
574574
return async () => {
575575
try {
576576
const status = await ctx.checkPRStatus(action.pr_url);
577-
if (status && status !== 'open') {
578-
// Successful non-open status — reset null counter and emit event
577+
if (status !== null) {
578+
// Any non-null result resets the consecutive null counter
579579
query(
580580
sql,
581581
/* sql */ `
@@ -588,11 +588,13 @@ export function applyAction(ctx: ApplyActionContext, action: Action): (() => Pro
588588
`,
589589
[action.bead_id]
590590
);
591-
ctx.insertEvent('pr_status_changed', {
592-
bead_id: action.bead_id,
593-
payload: { pr_url: action.pr_url, pr_state: status },
594-
});
595-
} else if (status === null) {
591+
if (status !== 'open') {
592+
ctx.insertEvent('pr_status_changed', {
593+
bead_id: action.bead_id,
594+
payload: { pr_url: action.pr_url, pr_state: status },
595+
});
596+
}
597+
} else {
596598
// Null result — increment consecutive null counter
597599
query(
598600
sql,

0 commit comments

Comments
 (0)