Repository navigation
Description
Origin
Deferred from PR #156 review feedback (thread on tools/learning_temporal.go:211), independently flagged by the review council on the fix commit (LOW, concurrency), and confirmed by the /uf.address-feedback Tier 2 dispatch (MEDIUM concurrency finding, retained as advisory).
Problem
Two concurrent StoreLearning calls superseding the same target can both pass validation. The one-successor invariant (design D3 of learning-temporal-validity: "chains, not forks") is enforced by a check-then-act sequence:
resolveSupersededTargetreadssuperseded_byduring validation (prepareTemporal).- Writes land in two legs after the successor's page insert:
linkSupersededcallsstore.UpdatePage(target)from the validation-time snapshot — the properties map was read before the successor file write and store insert, so a competing update in between is blindly overwritten.markSupersededFileread-modify-writes the target's markdown frontmatter, blindly replacingsuperseded_by.
The second writer overwrites the first successor, silently forking the chain — no supersedes_warning is emitted.
Scope of the unserialized window: the store lock serializes processes; the race is between concurrent in-process tool calls under streamable HTTP sharing one store handle. The window spans the successor file write, store insert, and embedding generation (seconds-wide).
Impact is metadata-only (forked supersession chain), but it violates the documented invariant.
Fix scope — every write leg
- Store leg: compare-and-swap update guarded on the properties JSON (
superseded_bylives in the JSON blob per design D1 — needsjson_extractin the UPDATE predicate or a schema change), or a per-target in-process mutex. - File leg:
markSupersededFilemust re-read and re-checksuperseded_bybefore replacing it (or the mutex must cover both legs).
Both legs must be covered: re-ingestion restores only missing pages, so after a graph.db loss the stale file leg wins and reintroduces the fork.
Constraints
- Spec-first: this is a real increment (SQL/locking strategy + both write legs + tests) and needs its own change spec.
- Follow the PR-145 toctou pattern (CAS preferred over lock widening).
Acceptance
- Two concurrent supersessions of the same target cannot fork the chain (second writer fails validation or receives
supersedes_warning) - Both write legs guarded (store + markdown file)
- Behavior survives
graph.dbdeletion + re-ingestion from markdown - Race regression test (concurrent goroutines superseding the same target)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
docs(openspec): record as_of context deferral grounds and supersessio…
docs(openspec): record as_of context deferral grounds and supersessio…
fix: serialize concurrent same-target supersession writes across ever…