# Connect negotiated incremental synchronization to the stdio session Task ID: T-SESSION-003 Role: astra_implementer Status: READY ## 1. Context and baseline Root integration on feat/implement-roadmap at ca04975 with existing CLI/lifecycle and native build. The current server ignores notifications other than exit, concatenates response JSON and advertises empty capabilities. Document and Protocol owners have separate source ownership. ## 2. Objective and deliverables Connect one document store to each LSP session. Serialize response objects through the checked Protocol writer. Provide actual process tests that distinguish a working edit handler from a no-op. ## 3. Scope and non-goals Root owns this integration. Do not add editor semantics or compiler diagnostics. A malformed notification may emit bounded stderr diagnostics. It never receives a protocol response. ## 4. Files to inspect Inspect src/Server.cpp, include/vls/Server.hpp, tests/{TestSupport.hpp,LifecycleTests.cpp,ProcessTests.cpp}, include/Void/LanguageServer/{Protocol,Documents}, build.cpp, tests/CMakeLists.txt, CMakeLists.txt and T-PREFLIGHT-004. ## 5. Write ownership and coordination Write scope: src/Server.cpp; src/DocumentSync.cpp; include/vls/Server.hpp; include/vls/DocumentSync.hpp; tests/TestSupport.hpp; tests/LifecycleTests.cpp; tests/ProcessTests.cpp; build.cpp; tests/CMakeLists.txt; CMakeLists.txt Root owns these files. Share read-only early interfaces with the Documents and Protocol owners. Integrate after their handoffs. ## 6. Implementation or investigation approach Negotiate the first supported client positionEncoding, default UTF-16, supporting UTF-8 and UTF-16. Fix encoding before admitting overlays. On successful initialization advertise just positionEncoding and textDocumentSync openClose=true/change=2. Dispatch didOpen, didChange and didClose only during running state. Validate textDocument objects, URIs and full change arrays. Reserve/copy only bounded arrays. Report a malformed event in a known URI via mark_desynchronized even if the enclosing version is absent or stale. Preserve the original text if any later edit fails. Treat a missing range as full replacement; reject a present null or malformed range. Validate an optional rangeLength as LSP uinteger if supplied; it is deprecated and does not replace validating range coordinates. Empty contentChanges is passed to the document contract or marked malformed if unsupported. ## 7. Interfaces and data contracts Wire versions use signed32 LSP integers. Position components and rangeLength use unsigned LSP integers 0..INT32_MAX, including before any document line clamp. Accept an integer only when its decoded value is representable and classifiable under the upstream numeric contract. The open upstream numeric-spelling problem is retained as an explicit gate. Treat known document identity as sufficient to mark the barrier even when payload/version parsing fails. Preserve stdout protocol-only even for errors, notifications or fatal encoding failures. Construct typed success/error objects with request_id_json. On encoding failure use a checked InternalError with a safely representable original ID or close before any write; do not emit partial frames or uncorrelated success. ## 8. Dependencies and integration DocumentStore open/apply_changes/close/mark_desynchronized report typed errors. The root coordinates the single canonical Protocol translation units and legacy compatibility headers, adds actual document and test sources to native+CMake builds. Future semantic requests reuse the same store. No process tool authorization or frontend work is part of this integration. ## 9. Edge cases security and performance Do not echo raw source text from malformed notifications. Keep diagnostics bounded by choosing fixed categories or bounded messages. Reject 2147483648 as a position before clamping; do not partially publish an edit batch on a malformed event. Preserve prior response-envelope, malformed input, pre-initialize/shutdown/exit handling and stream-error exit codes. ## 10. Acceptance criteria 1. Validate negotiated UTF-8 and default/supported UTF-16 as well as capabilities through actual subprocess frames. 2. Open a, replace it with an astral scalar, attempt an edit at column 1 and observe the split-scalar diagnostic. Run for UTF-8 and UTF-16. Verify the notifications produce no stdout frames and shutdown/exit remain correct. 3. Use null/malformed range in a later event or invalid uinteger to mark a known document unavailable; a stale full replacement and ranged edit cannot recover, a newer full replacement can. Ensure URI close/reopen and lifecycle state are respected. 4. All pre-existing tests except the two known upstream regressions retain intended behavior including real executable and framing/parsing failures; add checks for invalid egress before a frame write. ## 11. Verification commands and evidence Build/test using dev cpp-gcc -c vbs build and vbs test with the project/build dir/profile explicit; the verified local seed path is build/tools/vbs-6c225-bin/bin/vbs. Run all suites directly if a runner aborts at upstream numeric failures. Run comparison CMake build and ctest --output-on-failure on build/bootstrap. Verify registered bodies and both process transcripts. Run clang-format on exactly the owned C++ paths and git diff --check. ## 12. Constraints and stop conditions Continue independent root work while worker headers settle. Avoid simultaneous editing with source workers. If exact classification requires unavailable upstream information, preserve the original failing cases and the dependency owner decision; do not add a decimal parser here. ## 13. Authorization and decisions Implementation of roadmap 02/03 is authorized. Keep primary VBS, current branch, VoidLibrary main and existing preflight ownership. No staging, commits, push or sibling changes. Root owns integration. ## 14. Return format Record implementation, exact commands, observed outputs and any remaining dependency problems in VERIFICATION.md and STATE.md. Fresh integrated adversarial review required before merge/release.