Skip to content

Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.

Stop an unanswered request for the wheel outliving its run (#145)

David McKay3861dfd6303f
diff --git a/agent-computer/src/control.ts b/agent-computer/src/control.ts
index 1baceb09..d74913ba 100644
--- a/agent-computer/src/control.ts
+++ b/agent-computer/src/control.ts
@@ -21,6 +21,15 @@ export type ControlState = {
reason?: string;
/** True once the Bot has asked for help and no person has taken the wheel yet. */
requested: boolean;
+ /**
+ * When the Bot asked, so an unanswered request can stop being shown.
+ *
+ * A request nobody answers used to last forever. The run that made it had already ended, but the
+ * prompt stayed on the computer, and control belongs to the computer rather than to a conversation
+ * — so every later conversation with that Bot showed a live "Take control" for work it was not
+ * doing, with the reason the Bot gave, written for whoever asked and rendered to whoever looked.
+ */
+ requestedAt?: string;
/**
* A secret the Bot is waiting for, described by its label only.
*
@@ -57,6 +66,16 @@ export class ControlRequestError extends Error {
}
export const NO_SECRET_PENDING = "Nothing is waiting for a secret.";
+/**
+ * How long an unanswered request to take the wheel is shown for.
+ *
+ * Long enough that somebody who stepped away can still act on it, short enough that it does not
+ * follow the Bot into tomorrow's conversations. The run that made it is already over either way:
+ * nothing resumes when a person takes the wheel this late, so the value trades "still useful" against
+ * "still on screen" and nothing else.
+ */
+export const HELP_REQUEST_TTL_MS = 10 * 60 * 1000;
+
export const HUMAN_HAS_CONTROL =
"A person has control of the computer right now. Wait for them to hand it back before acting.";
export const TAKE_CONTROL_FIRST =
@@ -79,8 +98,27 @@ export function createControl(
};
return {
- /** The current state, as the surface polls it. A copy, so a caller cannot mutate the machine. */
+ /**
+ * The current state, as the surface polls it. A copy, so a caller cannot mutate the machine.
+ *
+ * An unanswered request is dropped once it is older than {@link HELP_REQUEST_TTL_MS}. It is
+ * expired on read rather than on a timer because there is nothing to wake: the run that asked
+ * has ended, and the only thing that cares is whoever looks next.
+ *
+ * Only ever the ASK. A person actually holding the wheel is never timed out from under them:
+ * they may be halfway through typing a code, and taking the browser back mid-sign-in is worse
+ * than any stale prompt.
+ */
get(): ControlState {
+ if (
+ state.requested &&
+ state.holder === "bot" &&
+ state.requestedAt &&
+ Date.parse(now()) - Date.parse(state.requestedAt) > HELP_REQUEST_TTL_MS
+ ) {
+ const { reason: _reason, requestedAt: _at, ...rest } = state;
+ state = { ...rest, requested: false };
+ }
return { ...state };
},
@@ -94,6 +132,7 @@ export function createControl(
state = {
...state,
requested: true,
+ requestedAt: now(),
reason:
typeof reason === "string" && reason.trim()
? reason.trim()
diff --git a/agent-computer/tests/control.test.ts b/agent-computer/tests/control.test.ts
index 95570332..bbcc3f09 100644
--- a/agent-computer/tests/control.test.ts
+++ b/agent-computer/tests/control.test.ts
@@ -236,3 +236,53 @@ describe("the crappy paths: secrets", () => {
).toEqual(["secretRef", "secretSnapshotId", "secretWanted"]);
});
});
+
+/**
+ * A request nobody answered does not outlive the run that made it.
+ *
+ * Control belongs to the computer, not to a conversation, and an unanswered request used to sit on
+ * it forever. The run that asked had ended, but every later conversation with that Bot showed a live
+ * "Take control" for work it was not doing — and showed the reason the Bot gave, which is written
+ * for whoever asked and was being rendered to whoever looked.
+ *
+ * Seen in the product: a brand new channel, on an unrelated question, displaying "Google Docs is
+ * asking for sign-in before I can read the PRD document" from a conversation minutes earlier.
+ */
+describe("an unanswered request to take the wheel", () => {
+ test("is still shown inside the window", () => {
+ let clock = "2026-08-22T03:00:00.000Z";
+ const control = createControl(() => clock);
+ control.requestHelp("sign in to Drive");
+
+ clock = "2026-08-22T03:05:00.000Z";
+ const state = control.get();
+ expect(state.requested).toBe(true);
+ expect(state.reason).toBe("sign in to Drive");
+ });
+
+ test("stops being shown once it is stale, and takes its reason with it", () => {
+ let clock = "2026-08-22T03:00:00.000Z";
+ const control = createControl(() => clock);
+ control.requestHelp("sign in to Drive");
+
+ clock = "2026-08-22T03:20:00.000Z";
+ const state = control.get();
+ expect(state.requested).toBe(false);
+ // The reason is the part that leaked between conversations, so it goes too.
+ expect(state.reason).toBeUndefined();
+ });
+
+ test("never takes the wheel back off a person who holds it", () => {
+ /*
+ * The one case that must not expire. Somebody may be halfway through typing a code, and pulling
+ * the browser back mid-sign-in is worse than any stale prompt. Only the ASK times out.
+ */
+ let clock = "2026-08-22T03:00:00.000Z";
+ const control = createControl(() => clock);
+ control.requestHelp("sign in to Drive");
+ control.take();
+
+ clock = "2026-08-22T04:00:00.000Z";
+ expect(control.get().holder).toBe("human");
+ });
+});