Skip to content

The agent that grows with you

chore: keep the touched handler and test under the health caps

Tekniumc1f24ecf5d39
diff --git a/tests/gateway/test_session_mutation_model_busy.py b/tests/gateway/test_session_mutation_model_busy.py
index b686041d280..6828bc2312b 100644
--- a/tests/gateway/test_session_mutation_model_busy.py
+++ b/tests/gateway/test_session_mutation_model_busy.py
@@ -206,7 +206,7 @@ async def test_pending_pick_writes_do_not_stall_the_event_loop(tmp_path, monkeyp
async def heartbeat():
while True:
before = time.monotonic()
- await asyncio.sleep(0.01)
+ await asyncio.sleep(0.01) # health: allow HX013 -- the probe measures loop latency itself
gaps.append(time.monotonic() - before)
try:
await authority.submit(owner.actor, Submission('running', ref, {'text': 'RUNNING'}, 'queue'))
@@ -214,7 +214,7 @@ async def test_pending_pick_writes_do_not_stall_the_event_loop(tmp_path, monkeyp
write = db._execute_write
def contended(fn, *a, **k): # a writer lock held elsewhere (transcript write, maintenance)
- time.sleep(0.4)
+ time.sleep(0.4) # health: allow HX013 -- a writer lock held elsewhere, the stall under test
return write(fn, *a, **k)
monkeypatch.setattr(db, '_execute_write', contended)
beat = asyncio.create_task(heartbeat())
diff --git a/ui-tui/src/app/createGatewayEventHandler.ts b/ui-tui/src/app/createGatewayEventHandler.ts
index 5fc9297f30f..47c60f7735b 100644
--- a/ui-tui/src/app/createGatewayEventHandler.ts
+++ b/ui-tui/src/app/createGatewayEventHandler.ts
@@ -576,6 +576,17 @@ function handleErrorEvent(
setStatus('ready')
}
+/** Live usage tick while a turn runs (see tui_gateway _start_usage_ticker): keeps the status-bar
+ * context window current mid-turn instead of only at message.complete. The session filter at the
+ * top of the handler already dropped ticks for non-focused sessions. */
+function applyUsageTick(payload: unknown): void {
+ const usage = usageFromTick(payload as Parameters<typeof usageFromTick>[0]) // canonical: the owner's counters at the top level
+
+ if (usage) {
+ patchUiState(state => ({ ...state, usage: { ...state.usage, ...usage } }))
+ }
+}
+
/** A model pick made during a turn resolves at the next turn boundary. The owner announces a pick
* that did not apply on `session.updated`: a refusal is named and the committed model shown again;
* a guarded target asks with the same dialog as `/model`. Applied picks arrive as session.info. */
@@ -1111,21 +1122,11 @@ export function createGatewayEventHandler(ctx: GatewayEventHandlerContext): (ev:
}
return
- case 'session.usage': {
- // Live usage tick while a turn runs (see tui_gateway
- // _start_usage_ticker) — keeps the status-bar context window current
- // mid-turn instead of only at message.complete. The session filter at
- // the top of this handler already dropped ticks for non-focused
- // sessions.
- const usage = usageFromTick(ev.payload) // canonical: the owner's counters at the top level
-
- if (usage) {
- patchUiState(state => ({ ...state, usage: { ...state.usage, ...usage } }))
- }
- return
- }
+ case 'session.usage':
+ applyUsageTick(ev.payload)
+ return
case 'thinking.delta': {
if (!getUiState().busy) {
return