Skip to content

Fix seven bugs found during the refactor; give tests their own temp paths - #35

Merged
drzo merged 1 commit into
mainfrom
claude/loving-archimedes-r7fcwy
Nov 23, 2026
Merged

drzo merged 1 commit into
mainfrom
claude/loving-archimedes-r7fcwy

Conversation

@drzo

@drzo drzo commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes the bugs that were found, and left alone, while refactoring in #33 and #34, and stops the tests sharing fixed paths under /tmp.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Test addition or modification

Related Issues

Related to #33 and #34

Changes Made

Bug fixes

  • EditorStore deadlock. Listeners ran with the store's mutex held, so a listener that called back into the store hung. Listeners are now copied under the lock and called after it is released. getSelectedFile() returns a copy instead of a reference to a member read without the lock. getCurrentDocument() still returns a raw pointer; it now has a comment about its lifetime.
  • ProtocolMessage round-trip. data was escaped on output but never unescaped on input; documentId and userId were not escaped at all; a non-numeric number field threw from deserialize(). All string fields are now escaped and unescaped, and a bad number reads as 0.
  • KoboldCpp request JSON. Stop sequences and chat role names went into the request unescaped, and control characters other than \n, \r, \t were left raw. Every string in a request body now goes through one escaper covering all of U+0000–U+001F. The two OpenAI-style request builders are exposed in bolt::ai::detail so they can be tested.
  • TensorUtils on an empty tensor. Error, MAE and stats divided by the element count and returned NaN; they now return zeros.
  • Test runner. It only caught std::exception, so a test throwing anything else ended the whole test program. It now records that test as an error.
  • YaccGrammarSystem::validate_description. It did not reset the generator before collecting errors.
  • unified_rag_manager.cpp. It returned one result when asked for none.

Test temp paths

  • New bolt::test::uniqueTempPath() in test_framework.hpp gives each test process its own path under the system temp directory.
  • It replaces the 33 fixed /tmp/... paths used as real files or directories in test/. The same test sources are built into several test programs that CTest runs in parallel, so two processes could create, read and delete the same file; that is the likely cause of the intermittent failures seen earlier. It also removes the assumption that /tmp exists on Windows.

Testing

  • Unit tests added/updated

  • All existing tests pass

  • Locally on Linux (GCC), two build trees: 99/99 CTest tests (one new entry, the TestFramework suite), three consecutive parallel runs all green; scripts/smoke_test.sh passes.

  • New tests: EditorStore.ListenerMayCallBackIntoStore; three ProtocolMessage tests (round-trip, unchanged wire format for plain messages, bad number); five KoboldCpp request tests (plain requests byte-identical, stop sequences, control characters, roles); GGMLTest.TensorUtilsEmptyTensor; TestFramework.NonStandardExceptionIsRecordedAsError and UniqueTempPathKeepsNameAndExtension; E2E_YaccGrammar.GrammarSystem_ValidateAfterFailedGenerate.

  • Shown to fail without the fix: the EditorStore and empty-tensor tests. Not re-checked against the old code: the ProtocolMessage, KoboldCpp and test-runner tests.

Reviewer Notes

  • The yacc fix is latent and its test cannot catch a regression. Nothing records a generator error today, so the test passes with or without the fix.
  • The RAG manager fix is untested. That file is not part of any build target. The hybrid query now asks the narrative backend for half of top_k rounded up, so that a hybrid query with top_k == 1 still returns one result.
  • Behaviour changes beyond the bugs themselves:
    • EditorStore listeners now run after the lock is dropped, so another thread can change the store between a change and its notification, and a listener added during a notification is not called in that round.
    • A ProtocolMessage with a non-numeric type now deserializes as type 0 (JOIN_DOCUMENT) instead of being rejected as unparseable; a missing type already behaved that way. A non-numeric cursor position reads as 0.
    • An empty tensor's stats used to report min = FLT_MAX and max = lowest; they are now 0.
  • Still open, found on the way and not fixed:
    • sendDocumentState writes user ids and names unescaped into its nested state JSON.
    • The yacc lexer has no : token, so the documented syntax (vm test : dis { }) and built-in templates such as ECHO_SERVER fail validation.
    • The native KoboldCpp /api/v1/generate body uses the fixed escaper but has no direct test.
  • Left on fixed paths on purpose: test_rwkv_integration.cpp (a fixed place for a user-supplied model) and test_gpu_acceleration.cpp (its paths are never created). About two dozen root-level demo and standalone test programs also use fixed /tmp paths; they are not run in parallel by CTest and are not changed here.

Generated by Claude Code

…aths

Each fix has a regression test unless noted.

- EditorStore ran its listeners with its mutex held, so a listener that
  called back into the store deadlocked. Listeners are now copied under
  the lock and called after it is released. getSelectedFile() returns a
  copy instead of a reference to a member read without the lock.
- ProtocolMessage did not round-trip: data was escaped on output but
  never unescaped on input, documentId and userId were not escaped at
  all, and a non-numeric number field threw from deserialize(). All
  string fields are now escaped and unescaped, and a bad number reads
  as 0. Messages without special characters are byte-identical.
- KoboldCpp requests put stop sequences and chat role names into the
  JSON unescaped and left control characters other than \n \r \t raw.
  Every string in a request body now goes through one escaper that
  covers all of U+0000..U+001F. The two OpenAI-style request builders
  are exposed in bolt::ai::detail so they can be tested.
- TensorUtils divided by the element count for an empty tensor (NaN).
  It now returns zeros.
- The test runner only caught std::exception, so a test that threw
  anything else ended the whole test program. It now records that test
  as an error.
- YaccGrammarSystem::validate_description did not reset the generator
  before collecting errors. Latent today, since nothing records a
  generator error yet; the added test passes with or without the fix.
- unified_rag_manager.cpp returned one result when asked for none.
  Untested: the file is not part of the build.

Tests wrote to fixed paths under /tmp. The same test sources are built
into several test programs that CTest runs in parallel, so two
processes could create, read and delete the same file; this is the
likely cause of the intermittent failures seen earlier. Add
bolt::test::uniqueTempPath(), which gives each process its own path
under the system temp directory, and use it for the 33 such paths in
test/. This also removes the assumption that /tmp exists on Windows.

One new CTest entry (the TestFramework suite): 99 tests.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011vmiZ7F3rQu7dith9sQw71
@drzo
drzo marked this pull request as ready for review November 23, 2026 13:48
Copilot AI balanced review requested due to automatic review settings November 23, 2026 13:48
@cursor

cursor Bot commented Nov 23, 2026

Copy link
Copy Markdown

Bugbot needs on-demand usage enabled

Bugbot uses usage-based billing for this team and requires on-demand usage to be enabled.

A team admin can enable on-demand usage in the Cursor dashboard.

@drzo
drzo merged commit 4e0cfe1 into main Nov 23, 2026
53 of 54 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 7 potential issues.

Devin Review

pos = data.find("\":\"", pos) + 3;
auto end = data.find("\"", pos);
return data.substr(pos, end - pos);
return detail::unescapeJsonStringAt(data, pos);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Remote edits hit the first line

A remote edit below the first line now reaches DocumentOperation::deserialize with its operation fields intact. extractInt reads past position instead of line and falls back to zero. The server inserts or deletes text on the first line instead.

Learn more

A WebSocket text edit carries a serialized operation inside the outer message’s data string. The new unescaping restores the inner JSON for handleDocumentOperation, so its text now reaches the collaborative session rather than being lost at the first escaped quote. DocumentOperation::deserialize passes a composite key to extractInt. The lookup finds the composite key, but the subsequent colon search starts at the beginning of that match. It takes the colon after position, passes a substring beginning with { to std::stoi, and returns zero on failure. applyOperation then applies the edit at that position and records it in the document history.

Example: In a document with lines aaa and bbb, an insert of X at line 1, character 1 changes aaa to aXaa and leaves bbb untouched. The intended result is aaa followed by bXbb.

Recommended fix: Parse position.line and position.character from the nested operation object and reject invalid coordinates instead of substituting zero. Add a regression test that deserializes the outer message, applies its operation to a multiline document, and checks that line 0 remains unchanged.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +252 to +257
std::vector<std::function<void()>> listeners;
{
std::lock_guard<std::mutex> lock(mutex_);
listeners = listeners_;
}
for (auto& listener : listeners) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Listener snapshots discard callback state

notifyListeners now invokes copies of the registered callbacks. A mutable callback that captures state by value loses its updates after each notification.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread test/test_bolt_core.cpp
Comment on lines +259 to +265
const bool completed = finished.wait_for(std::chrono::seconds(10)) == std::future_status::ready;
if (completed) {
worker.join();
} else {
worker.detach();
}
BOLT_ASSERT_TRUE(completed);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Deadlock test timeout leaves suite blocked

On a real deadlock, worker.detach() leaves the singleton locked. runSingleTest catches the assertion and continues, so later editor tests can still hang.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +60 to +67
if (c == '\\' && pos + 1 < data.size()) {
c = data[++pos];
if (c == 'n')
c = '\n';
else if (c == 'r')
c = '\r';
else if (c == 't')
c = '\t';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Unicode escapes still change room names

unescapeJsonStringAt leaves Unicode escape digits as literal text. Clients that escape non-ASCII document IDs still address a different room from clients that send UTF-8 directly.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread test/test_ai_ggml.cpp
BOLT_ASSERT_TRUE(gf != nullptr);
}

BOLT_TEST(GGMLTest, TensorUtilsEmptyTensor) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 New regressions bypass required GoogleTest

The new feature regression cases use BOLT_TEST instead of the required GoogleTest framework. The GoogleTest targets already support that framework.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +380 to +381
BOLT_ASSERT_THROWS(std::runtime_error,
FileSystemUtils::readFile(bolt::test::uniqueTempPath("bolt_nonexistent_file_xyz.txt")));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Missing-file tests mask temp setup errors

If temporary-directory lookup fails, BOLT_ASSERT_THROWS accepts its filesystem_error as the expected runtime_error. Neither missing-file test reaches readFile.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

pos = data.find("\":\"", pos) + 3;
auto end = data.find("\"", pos);
return data.substr(pos, end - pos);
return detail::unescapeJsonStringAt(data, pos);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟥 Nonmembers can edit shared documents

unescapeJsonStringAt now restores structured edits from WebSocket clients. handleDocumentOperation applies them to the named document without checking whether the sending connection joined it.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants