Skip to content

Conversation

djeebus
Copy link
Contributor

@djeebus djeebus commented Sep 9, 2025

@djeebus djeebus added the improvement Improvement for current functionality label Sep 9, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@djeebus
Copy link
Contributor Author

djeebus commented Sep 9, 2025

Don't think it was worth it to make all the changes; I'll go back and //nolint some of the ones that cannot be invalid casts.

@djeebus djeebus marked this pull request as draft September 9, 2025 18:02
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Type Assertion Errors Mask Key Existence

The Load, LoadAndDelete, and LoadOrStore methods now incorrectly conflate "key found" with "type assertion succeeded". Their ok/loaded return values now reflect the type assertion result, causing them to return false and a zero value when a key exists but has an unexpected type. This silently masks potential programming errors and is inconsistent with the Range method's panic behavior.

packages/envd/internal/utils/map.go#L21-L44

func (m *Map[K, V]) Load(key K) (value V, ok bool) {
v, ok := m.m.Load(key)
if ok {
value, ok = v.(V)
}
return
}
func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool) {
v, loaded := m.m.LoadAndDelete(key)
if loaded {
value, loaded = v.(V)
}
return
}
func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) {
a, loaded := m.m.LoadOrStore(key, value)
if loaded {
actual, loaded = a.(V)
}
return
}

Fix in Cursor Fix in Web


Bug: Type Assertion Failures Mask Errors

This update changes how type assertion failures are handled. Previously, these would panic, providing fail-fast behavior. Now, in dirtySortedKeys, a failed key.(int64) assertion silently appends 0 to the slice, potentially corrupting the sorted keys. Similarly, Map's Load, LoadAndDelete, and LoadOrStore methods now return zero values and false on assertion failure, making "key not found" indistinguishable from "key found with wrong type." This can obscure underlying type-related bugs.

packages/orchestrator/internal/sandbox/block/cache.go#L238-L240

m.dirty.Range(func(key, _ any) bool {
n, _ := key.(int64)
keys = append(keys, n)

packages/envd/internal/utils/map.go#L21-L28

func (m *Map[K, V]) Load(key K) (value V, ok bool) {
v, ok := m.m.Load(key)
if ok {
value, ok = v.(V)
}
return
}

Fix in Cursor Fix in Web


# Conflicts:
#	.golangci.yml
#	packages/api/internal/orchestrator/placement/placement_benchmark_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement for current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant