Skip to content

Fix a subtle race condition when indexing#1081

Open
jviotti wants to merge 2 commits into
mainfrom
race
Open

Fix a subtle race condition when indexing#1081
jviotti wants to merge 2 commits into
mainfrom
race

Conversation

@jviotti

@jviotti jviotti commented Jun 23, 2026

Copy link
Copy Markdown
Member

Signed-off-by: Juan Cruz Viotti jv@jviotti.com

Review in cubic

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 1 file

Re-trigger cubic

@augmentcode

augmentcode Bot commented Jun 23, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Fixes a subtle indexing race by preventing SchemaTransformer bundle instances from being shared across threads.

Changes: Replaces the process-wide cached bundle (static + mutex) with a per-thread (thread_local) cache so each worker thread gets its own mutable bundle instance.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode 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.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/index/generators.h Outdated
// from multiple threads at once. Producing runs across a thread pool, so
// we keep the cache thread-local to give every worker its own bundle
// rather than sharing a single one across threads
thread_local std::unordered_map<const void *, std::unique_ptr<CacheEntry>>

@augmentcode augmentcode Bot Jun 23, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cache is now thread_local and keyed by &configuration, so entries live for the lifetime of each worker thread; if Configuration objects are ever short-lived (or their addresses can be reused), this can lead to stale cache hits and/or unbounded per-thread growth.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Benchmark Index (community)

Details
Benchmark suite Current: a4cd077 Previous: 0959497 Ratio
Add one schema (0 existing) 387 ms 328 ms 1.18
Add one schema (100 existing) 30 ms 22 ms 1.36
Add one schema (1000 existing) 83 ms 65 ms 1.28
Add one schema (10000 existing) 677 ms 539 ms 1.26
Update one schema (1 existing) 23 ms 16 ms 1.44
Update one schema (101 existing) 31 ms 22 ms 1.41
Update one schema (1001 existing) 88 ms 67 ms 1.31
Update one schema (10001 existing) 689 ms 549 ms 1.26
Cached rebuild (1 existing) 7 ms 4 ms 1.75
Cached rebuild (101 existing) 9 ms 5 ms 1.80
Cached rebuild (1001 existing) 29 ms 18 ms 1.61
Cached rebuild (10001 existing) 251 ms 165 ms 1.52
Index 100 schemas 486 ms 390 ms 1.25
Index 1000 schemas 1550 ms 1284 ms 1.21
Index 10000 schemas 13900 ms 10931 ms 1.27
Index 10000 schemas (custom meta-schema) 16848 ms 13523 ms 1.25
Index 10000 schemas ($ref fan-out) 16701 ms 13757 ms 1.21

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Benchmark Index (enterprise)

Details
Benchmark suite Current: a4cd077 Previous: 0959497 Ratio
Add one schema (0 existing) 376 ms 376 ms 1
Add one schema (100 existing) 32 ms 32 ms 1
Add one schema (1000 existing) 87 ms 86 ms 1.01
Add one schema (10000 existing) 666 ms 675 ms 0.99
Update one schema (1 existing) 24 ms 24 ms 1
Update one schema (101 existing) 31 ms 31 ms 1
Update one schema (1001 existing) 85 ms 86 ms 0.99
Update one schema (10001 existing) 678 ms 686 ms 0.99
Cached rebuild (1 existing) 8 ms 8 ms 1
Cached rebuild (101 existing) 10 ms 10 ms 1
Cached rebuild (1001 existing) 33 ms 33 ms 1
Cached rebuild (10001 existing) 275 ms 274 ms 1.00
Index 100 schemas 615 ms 469 ms 1.31
Index 1000 schemas 1550 ms 1505 ms 1.03
Index 10000 schemas 13583 ms 13530 ms 1.00
Index 10000 schemas (custom meta-schema) 15770 ms 15954 ms 0.99
Index 10000 schemas ($ref fan-out) 16442 ms 16125 ms 1.02

This comment was automatically generated by workflow using github-action-benchmark.

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
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.

1 participant