From a01af8818d41c7586238cbe584ef79617e53e60f Mon Sep 17 00:00:00 2001 From: blasco Date: Tue, 20 Oct 2026 12:19:03 +0200 Subject: [PATCH] fix: avoid Git context overflow in V2 session diffs --- lua/opencode/protocols/v2/operations.lua | 3 +++ tests/unit/protocol_v2_operations_spec.lua | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lua/opencode/protocols/v2/operations.lua b/lua/opencode/protocols/v2/operations.lua index c473d170..30e6e670 100644 --- a/lua/opencode/protocols/v2/operations.lua +++ b/lua/opencode/protocols/v2/operations.lua @@ -367,6 +367,9 @@ end ---@return Promise function M.diff_session(connection, session_id, from, to, reverse_path_map) return json_request(connection, 'V2 diff_session', 'GET', '/api/session/' .. session_id .. '/diff', { + -- The server's INT_MAX default can overflow Git's hunk merging. Keep effectively + -- full-file context below INT_MAX / 2 so side-by-side reconstruction stays valid. + context = 1000000000, from = from, to = to, }):and_then(function(value) diff --git a/tests/unit/protocol_v2_operations_spec.lua b/tests/unit/protocol_v2_operations_spec.lua index 399c4d1f..c8cc0a02 100644 --- a/tests/unit/protocol_v2_operations_spec.lua +++ b/tests/unit/protocol_v2_operations_spec.lua @@ -212,11 +212,23 @@ describe('V2 protocol operations', function() end) :wait() assert.equals('/api/session/ses_123/diff', request.path) - assert.equals('from=msg_one&to=msg_two', request.query) + assert.equals('context=1000000000&from=msg_one&to=msg_two', request.query) assert.equals('/host/file.lua', files[1].file) assert.equals('@@ -1 +1 @@\n-old\n+new', files[1].patch) end) + it('requests bounded full-file context even without explicit turn boundaries', function() + local request + transport.request = function(_, value) + request = value + return Promise.new():resolve({ status = 200, body = '{"data":[]}' }) + end + assert.same({}, operations.diff_session(ready_connection(), 'ses_123'):wait()) + assert.equals('GET', request.method) + assert.equals('/api/session/ses_123/diff', request.path) + assert.equals('context=1000000000', request.query) + end) + it('uses direct, location/data, and page response contracts from the V2 fixtures', function() local bodies = { ['/api/location'] = fixture('location.json'),