Skip to content

The agent that grows with you

fix(gateway): rollback.restore reads a null `all` as omitted

unsupportedpastelsecd58a25e958
diff --git a/gateway/session_tui_ops.py b/gateway/session_tui_ops.py
index 1504ec4361b..d85afda07b3 100644
--- a/gateway/session_tui_ops.py
+++ b/gateway/session_tui_ops.py
@@ -160,7 +160,7 @@ async def rollback(connection, ref, params, *, kind):
fields = _ROLLBACK_FIELDS[kind]
if any(key in params and (not isinstance(params[key], str) or (key == 'hash' and not params[key]))
for key in ('hash', 'file_path')) or (kind in ('diff', 'restore') and 'hash' not in params) or (
- not isinstance(params.get('all', False), bool)):
+ params.get('all') is not None and not isinstance(params['all'], bool)): # nullable: null is omitted
raise RuntimeStoreError('invalid_params')
live = _live_ref(connection, ref, params, fields, 'session:read' if kind != 'restore' else 'session:control')
authority = connection.authority
diff --git a/tests/gateway/test_session_tui_ops.py b/tests/gateway/test_session_tui_ops.py
index abee9caee0a..59d180a38fa 100644
--- a/tests/gateway/test_session_tui_ops.py
+++ b/tests/gateway/test_session_tui_ops.py
@@ -194,3 +194,32 @@ def test_rollback_restore_keeps_hand_edits_unless_all(tmp_path):
assert forced['success'] is True and not forced.get('skipped_user_edits'), forced
assert (work / 'mine.txt').read_text() == 'original mine\n'
asyncio.run(probe())
+
+
+def test_rollback_restore_reads_a_null_all_as_omitted(tmp_path):
+ """The published contract declares ``all`` nullable (``RollbackRestoreParams``): a client sending
+ its declared default gets the safe restore, like one sending nothing or ``false``."""
+ with owner(tmp_path) as (home, _peer, desc):
+ work = tmp_path / 'work'
+ work.mkdir()
+ (work / 'agent.txt').write_text('original\n')
+ (work / 'mine.txt').write_text('original mine\n')
+ out = {}
+
+ async def probe():
+ async with websocket(home, desc) as ws:
+ sid = (await rpc(ws, 'session.create', request_id='null-all', source='tui', toolsets=[],
+ cwd=str(work), checkpoints=True))['result']['session_id']
+ await asyncio.to_thread(_checkpoint, home, work, 'before write_file')
+ [row] = (await _git_rpc(ws, 'rollback.list', session_id=sid))['result']['checkpoints']
+ await asyncio.to_thread(_agent_write, home, work / 'agent.txt', 'agent\n')
+ for case, extra in (('omitted', {}), ('null', {'all': None}), ('false', {'all': False}),
+ ('true', {'all': True})):
+ (work / 'mine.txt').write_text('hand edit\n')
+ reply = await _git_rpc(ws, 'rollback.restore', session_id=sid, hash=row['hash'], **extra)
+ out[case] = (reply.get('result', {}).get('skipped_user_edits')
+ or reply.get('error', {}).get('message'), (work / 'mine.txt').read_text())
+ asyncio.run(probe())
+ kept = (['mine.txt'], 'hand edit\n')
+ assert out == {'omitted': kept, 'null': kept, 'false': kept, 'true': (None, 'original mine\n')}, out