Skip to content

The agent that grows with you

fix(gateway): list a steer in transfer as `steering` so a returned prompt keeps its card

unsupportedpastels8196fbc12411
diff --git a/apps/desktop/src/store/pending-submissions.test.ts b/apps/desktop/src/store/pending-submissions.test.ts
index 84c6a36bde6..ebc4b387013 100644
--- a/apps/desktop/src/store/pending-submissions.test.ts
+++ b/apps/desktop/src/store/pending-submissions.test.ts
@@ -46,6 +46,24 @@ it('carries the queued-row controls the owner lists onto the card, and none when
expect(Object.values(readPendingSubmissions('chat')).some(entry => 'controls' in entry)).toBe(false)
})
+it('a steer in transfer hides its card without retiring it, so a return to the queue repaints it (RT-35)', () => {
+ reconcilePendingSubmissions('chat', [{ admission_id: 'moving', status: 'queued', user: 'steer me' }])
+ // Handed to the running turn: listed `started` and `steering` until that turn settles it.
+ reconcilePendingSubmissions('chat', [{ admission_id: 'moving', status: 'started', steering: true, user: 'steer me' }])
+ expect(getQueuedPrompts('chat')).toEqual([])
+
+ // The text never reached the turn: the owner puts the same admission back in its queue place.
+ reconcilePendingSubmissions('chat', [{ admission_id: 'moving', status: 'queued', user: 'steer me' }])
+ expect(getQueuedPrompts('chat').map(({ id, serverStatus }) => ({ id, serverStatus }))).toEqual([
+ { id: 'moving', serverStatus: 'queued' }
+ ])
+
+ // An ordinary claim still only moves forward: a replayed `queued` never repaints a started row.
+ reconcilePendingSubmissions('chat', [{ admission_id: 'moving', status: 'started', user: 'steer me' }])
+ reconcilePendingSubmissions('chat', [{ admission_id: 'moving', status: 'queued', user: 'steer me' }])
+ expect(getQueuedPrompts('chat')).toEqual([])
+})
+
it('reconciles server queue by identity without replaying or duplicating local entries', () => {
enqueueQueuedPrompt('chat', { id: 'one', text: 'same', attachments: [] })
enqueueQueuedPrompt('chat', { id: 'local', text: 'same', attachments: [] })
diff --git a/apps/desktop/src/store/pending-submissions.ts b/apps/desktop/src/store/pending-submissions.ts
index 660985d1cbd..0241a240a98 100644
--- a/apps/desktop/src/store/pending-submissions.ts
+++ b/apps/desktop/src/store/pending-submissions.ts
@@ -274,7 +274,9 @@ function updateKnownReceipts(known: Record<string, PendingSubmission>, value: Ra
...previous,
id: raw.admission_id,
text: raw.user ?? previous?.text ?? '',
- status: raw.status,
+ // A steer in transfer reads `started` but can still go back to its queue place: it never
+ // raises the admission's rank, so the owner's later `queued` listing repaints its card.
+ status: raw.steering === true ? (previous?.status ?? 'queued') : raw.status,
...(fence && !predates(fence, previous?.seen) ? { seen: fence } : {})
}
}
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.ts
index 8ce17873fc7..f88164d7d94 100644
--- a/apps/shared/src/gateway-contract.generated.ts
+++ b/apps/shared/src/gateway-contract.generated.ts
@@ -4942,6 +4942,7 @@ export interface CanonicalPendingAdmission {
input_id: string
text: string
controls?: ('steer' | 'replace')[] | null
+ steering?: boolean | null
}
export interface CanonicalPendingPrompt {
kind: 'approval' | 'clarify'
@@ -6744,7 +6745,7 @@ export interface CanonicalRpcMethods {
'prompt.replace_queued': { params: CanonicalReplaceQueuedParams; result: AdmissionStatus }
/** Acknowledge a turn lost across an owner restart; the FIFO behind it resumes. Never requeues the lost input. */
'prompt.resolve_unknown': { params: PromptResolveUnknownParams; result: AdmissionStatus }
- /** Hand a still-queued admission's text to the running turn's agent as a steer. The admission reads 'started' with that turn and never runs on its own; it settles terminal 'steered' when the turn completes, else 'interrupted'. Refusals: admission_started, session_idle, steer_unavailable (no agent to take it: the admission stays queued), unsupported_control, not_found. */
+ /** Hand a still-queued admission's text to the running turn's agent as a steer. The admission reads 'started' with that turn (pending snapshots mark it 'steering') and never runs on its own; it settles terminal 'steered' when the turn completes with its text, else 'interrupted' (its completion frame says 'cancelled', as an interrupted turn's does); a text the turn never consumed goes back to its queue place. Refusals: admission_started, session_idle, steer_unavailable (no agent to take it: the admission stays queued), unsupported_control, not_found. */
'prompt.steer_queued': { params: CanonicalSteerQueuedParams; result: AdmissionStatus }
'prompt.submit': { params: CanonicalSubmitParams; result: AdmissionStatus }
/** The classic CLI's /diff session: everything changed since the session's earliest retained checkpoint, as data for its terminal renderer. */
diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.json
index 40946493f2e..710a68ce406 100644
--- a/apps/shared/src/gateway-contract.openrpc.json
+++ b/apps/shared/src/gateway-contract.openrpc.json
@@ -9137,6 +9137,18 @@
],
"default": null,
"title": "Controls"
+ },
+ "steering": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Steering"
}
},
"required": [
@@ -47281,7 +47293,7 @@
},
{
"name": "prompt.steer_queued",
- "summary": "Hand a still-queued admission's text to the running turn's agent as a steer. The admission reads 'started' with that turn and never runs on its own; it settles terminal 'steered' when the turn completes, else 'interrupted'. Refusals: admission_started, session_idle, steer_unavailable (no agent to take it: the admission stays queued), unsupported_control, not_found.",
+ "summary": "Hand a still-queued admission's text to the running turn's agent as a steer. The admission reads 'started' with that turn (pending snapshots mark it 'steering') and never runs on its own; it settles terminal 'steered' when the turn completes with its text, else 'interrupted' (its completion frame says 'cancelled', as an interrupted turn's does); a text the turn never consumed goes back to its queue place. Refusals: admission_started, session_idle, steer_unavailable (no agent to take it: the admission stays queued), unsupported_control, not_found.",
"params": [
{
"name": "params",
diff --git a/gateway/session_authority.py b/gateway/session_authority.py
index 0c7a8d9b6c8..a0014767836 100644
--- a/gateway/session_authority.py
+++ b/gateway/session_authority.py
@@ -261,6 +261,7 @@ class SessionAuthority:
self.authorize(actor, ref, 'session:read')
live = self.sessions[ref.session_id]
from gateway.session_local_recovery import local_history
+ from gateway.session_queued_controls import pending_rows
with live.event_stream.lock:
subscription = next((key for key, member in live.subscribers.items()
if member == actor), None) or uuid.uuid4().hex
@@ -278,7 +279,7 @@ class SessionAuthority:
epoch, sequence = live.event_stream.watermark()
snapshot = SubscriptionSnapshot(subscription, handle, epoch,
sequence, tuple(local_history(self, ref)),
- tuple(self._pending_receipt(r) for r in self._pending_rows(ref)), prompts)
+ tuple(self._pending_receipt(r) for r in pending_rows(self, ref)), prompts)
from gateway.session_viewer_close import cancel_persisted_close
await asyncio.to_thread(cancel_persisted_close, self, ref.session_id) # the viewer cancels it
from gateway.session_deferred_pick import reask_on_attach
@@ -333,13 +334,14 @@ class SessionAuthority:
text = payload.get('native_text_v1', {}).get('event', {}).get('text', '')
from gateway.session_queued_controls import queued_controls
return PendingAdmission(**vars(self._receipt(row)), input_id=row['request_id'], text=text,
- controls=queued_controls(self, row))
+ controls=queued_controls(self, row), steering=row['outcome'] == STEERING)
def _publish_pending(self, ref):
live = self.sessions[ref.session_id]
+ from gateway.session_queued_controls import pending_rows
with live.event_stream.lock:
handle = self._handle(ref)
- pending = [asdict(self._pending_receipt(row)) for row in self._pending_rows(ref)]
+ pending = [asdict(self._pending_receipt(row)) for row in pending_rows(self, ref)]
# Turns bump runtime_revision without any session.updated event, so
# this is the only place a viewer learns the CAS revision a later
# prepared mutation must present.
diff --git a/gateway/session_contract.py b/gateway/session_contract.py
index 43f648e8204..dda3763a395 100644
--- a/gateway/session_contract.py
+++ b/gateway/session_contract.py
@@ -66,6 +66,9 @@ class PendingAdmission(AdmissionReceipt):
text: str
# The queued-row verbs this owner serves for the row (``steer`` / ``replace``); empty otherwise.
controls: list[str] = field(default_factory=list)
+ # A queued admission in transfer to the running turn (``prompt.steer_queued``): it reads ``started``
+ # but goes back to its queue place if its text never reached that turn.
+ steering: bool = False
@dataclass(frozen=True)
diff --git a/gateway/session_queued_controls.py b/gateway/session_queued_controls.py
index 6e2c703c911..bd4d88cfac0 100644
--- a/gateway/session_queued_controls.py
+++ b/gateway/session_queued_controls.py
@@ -59,6 +59,19 @@ def queued_controls(authority, row):
return ['steer', 'replace']
+def pending_rows(authority, ref):
+ """The pending rows a viewer is shown, plus each queued admission in transfer to the running
+ claim: listed ``started`` and ``steering``, because it may still go back to its queue place, and a
+ client must not retire an admission it no longer sees. The caller holds the stream lock."""
+ rows = {row['admission_id']: row for row in authority._pending_rows(ref)}
+ entry = authority.steer_transfers.get(ref.session_id)
+ for admission_id in entry[1] if entry is not None else ():
+ row = get_session_admission(authority.db, admission_id=admission_id)
+ if row is not None and row['status'] == 'terminal' and row['outcome'] == STEERING:
+ rows[admission_id] = row
+ return sorted(rows.values(), key=lambda row: row['seq'])
+
+
async def _queued(connection, ref, admission_id):
receipt = await connection.authority.receipt(connection.actor, ref, admission_id)
return receipt, get_session_admission(connection.authority.db, admission_id=admission_id)
diff --git a/tests/gateway/test_prompt_queued_transfer.py b/tests/gateway/test_prompt_queued_transfer.py
index ab2708a12d7..24c75573069 100644
--- a/tests/gateway/test_prompt_queued_transfer.py
+++ b/tests/gateway/test_prompt_queued_transfer.py
@@ -129,6 +129,33 @@ async def test_a_steer_settles_steered_only_when_a_drain_of_the_turn_took_it(tmp
assert ran == ['running', 'follow-up'], 'the returned prompt runs once, as its own turn'
+async def test_a_transfer_stays_listed_as_steering_until_its_claim_settles(tmp_path, monkeypatch):
+ """Reviewer repro (returned prompt stays hidden): a pending snapshot taken while a steer is in
+ transfer still lists it, marked ``steering``, so no client retires an admission that may go back to
+ the queue. Once it settles ``steered`` it leaves the pending set."""
+ db, authority = _authority(tmp_path, monkeypatch)
+ interactive(db)
+ turn, frames = Turn(monkeypatch), []
+ authority.sessions['s'].event_stream.observers.add(frames.append)
+
+ def listed(admission_id):
+ pending = [f['params']['payload']['pending'] for f in frames if f['params']['type'] == 'session.info'][-1]
+ return [(row['status'], row.get('steering'), row['controls']) for row in pending
+ if row['admission_id'] == admission_id]
+ with db:
+ await _submit(authority, 'running')
+ await asyncio.wait_for(turn.claimed.wait(), 30)
+ queued = await _submit(authority, 'follow-up')
+ reply = await _call(_connection(authority), 'prompt.steer_queued', admission_id=queued.admission_id)
+ assert 'error' not in reply, reply
+ assert listed(queued.admission_id) == [('started', True, [])]
+ turn.release.set()
+ await _drained(authority)
+ assert listed(queued.admission_id) == []
+ assert _ledger(db)[-1] == ('follow-up', 'terminal', 'steered')
+
+
@pytest.mark.asyncio
@pytest.mark.parametrize('retry', [False, True])
async def test_a_steer_write_that_committed_but_reported_failure_is_still_settled_by_its_claim(
diff --git a/tui_gateway/contracts/canonical_sessions.py b/tui_gateway/contracts/canonical_sessions.py
index 9d2e65912ec..525dc0c2755 100644
--- a/tui_gateway/contracts/canonical_sessions.py
+++ b/tui_gateway/contracts/canonical_sessions.py
@@ -85,6 +85,10 @@ class CanonicalPendingAdmission(AdmissionStatus):
# The queued-row verbs the owner serves for this row: ``steer`` (``prompt.steer_queued``) and
# ``replace`` (``prompt.replace_queued``). Absent from an owner that predates them.
controls: list[Literal['steer', 'replace']] | None = None
+ # A queued admission in transfer to the running turn (``prompt.steer_queued``): listed ``started``
+ # until that turn settles it, but it returns to ``queued`` if its text never reached the turn, so a
+ # client keeps it at its queued rank. Absent from an owner that predates it.
+ steering: bool | None = None
class CanonicalPendingPrompt(Result):
@@ -292,8 +296,11 @@ for _name, _params, _result in (
canonical_method('prompt.steer_queued', params=CanonicalSteerQueuedParams, result=AdmissionStatus,
doc="Hand a still-queued admission's text to the running turn's agent as a steer. "
- "The admission reads 'started' with that turn and never runs on its own; it "
- "settles terminal 'steered' when the turn completes, else 'interrupted'. "
+ "The admission reads 'started' with that turn (pending snapshots mark it "
+ "'steering') and never runs on its own; it settles terminal 'steered' when the "
+ "turn completes with its text, else 'interrupted' (its completion frame says "
+ "'cancelled', as an interrupted turn's does); a text the turn never consumed "
+ "goes back to its queue place. "
"Refusals: admission_started, session_idle, steer_unavailable (no agent to take "
"it: the admission stays queued), unsupported_control, not_found.")
canonical_method('prompt.replace_queued', params=CanonicalReplaceQueuedParams, result=AdmissionStatus,