Go Advanced Data Operations
2026-10-27: 34/34 scenario assertions and all eight baseline SQLite checkpoints plus four isolated mutation databases PASS on the qualified workspace runtime — RELEASE PENDING.
Shared School model, five-school fixture, expected results, coverage priorities, and dated receipt.
The excerpts below are synchronized from the complete executable application. Its imports, composition root and result-reporting helpers are in that file. Follow the shared setup and evidence contract before adapting these calls. Request current entity/action Assist, then scoped field Assist; keep generated domain libraries unchanged.
Analytic records use ExecuteRecords and public Value conversion methods. Use scoped Assist for SelectSchoolTypeWith and SelectPlatformWith. The recorded Go workspace also deep-clones filtered child requests so one parent cannot contaminate the next probe. Apply both the recorded relation-isolation and ID-set observation patches before running. This result remains WORKSPACE PASS — RELEASE PENDING.
Run from the site checkout with the native prerequisites in the seven-runtime baseline:
node scripts/school-examples.mjs --suite advanced --language go --go-runtime ../teaql-golang
Filtered pagination
Active schools with capacity at least 500 have total 3. Offset 1, limit 2 returns Riverside then West.
page, err := lib.Q.SchoolsMinimal().SelectName().WhichAreActive().WithStudentCapacityGreaterThanOrEqualTo(500).
OrderByStudentCapacityDesc().OrderByIdAsc().Offset(1).Limit(2).Count().
Comment("Page active schools by capacity").Purpose("Review the School directory").ExecuteForList(context)
must(err); if page.TotalCount == nil { panic("Missing filtered total") }
report("pagination", map[string]any{"names": names(page), "total": *page.TotalCount})
Two loaded relations
Riverside resolves to PRIMARY and Campus Learning Platform through selected child requests.
rows, err := lib.Q.SchoolsMinimal().SelectName().WithNameIs("Riverside Primary School").
SelectSchoolTypeWith(lib.Q.SchoolTypesMinimal().SelectCode()).
SelectPlatformWith(lib.Q.PlatformsMinimal().SelectName()).Limit(2).
Comment("Load School type and platform").Purpose("Review loaded School relations").ExecuteForList(context)
must(err); if len(rows.Data) != 1 { panic("Expected one School") }
expression := school.NewSchoolExpression(rows.Data[0])
report("relations", map[string]any{"school": need(expression.Name().Eval()), "type": need(expression.SchoolType().Code().Eval()), "platform": need(expression.Platform().Name().Eval())})
Grouped analytics
PRIMARY: count 3, sum 1600, average 533.3333333333334; SECONDARY: count 2, sum 1700, average 850.
groups, err := lib.Q.Schools().GroupBySchoolType().CountAs("count").SumStudentCapacityAs("total").AvgStudentCapacityAs("average").Limit(10).
Comment("Group School capacity by type").Purpose("Verify provider aggregation").ExecuteRecords(context)
must(err); distribution := []map[string]any{}
for _, row := range groups { distribution = append(distribution, map[string]any{"type": need(row["school_type"].TryU64()),
"count": need(row["count"].TryU64()), "total": need(row["total"].TryF64()), "average": need(row["average"].TryF64())}) }
report("groups", distribution)
Relation metrics
SchoolType parents return the same counts and sums without loading their child lists.
cards, err := lib.Q.SchoolTypesMinimal().SelectCode().CountSchoolsAs("count").
SumStudentCapacityOfSchoolsAs("total", lib.Q.Schools()).OrderByCodeAsc().Limit(10).
Comment("Calculate SchoolType relation metrics").Purpose("Verify provider relation aggregation").ExecuteRecords(context)
must(err); metrics := map[string]any{}
for _, row := range cards { metrics[need(row["code"].TryText())] = map[string]any{"count": need(row["count"].TryU64()), "total": need(row["total"].TryF64())} }
report("relation-metrics", metrics)
Two Facets and zero buckets
Filtering to Riverside yields PRIMARY: 1 and SECONDARY: 0 with include-all, only PRIMARY: 1 with matched-only, and platform count 1.
facets := func(includeAll bool) *core.SmartList[*school.School] {
rows, err := lib.Q.SchoolsMinimal().SelectName().WithNameIs("Riverside Primary School").
FacetBySchoolTypeAs("types", lib.Q.SchoolTypesMinimal().SelectCode().CountSchoolsAs("count"), includeAll).
FacetByPlatformAs("platforms", lib.Q.PlatformsMinimal().SelectName().CountSchoolsAs("count"), false).
OrderByIdAsc().Limit(2).Comment("Facet the matching School set").Purpose("Compare zero and matched buckets").ExecuteForList(context)
must(err); return rows
}
allRows, matched := facets(true), facets(false)
report("facets", map[string]any{"includeAll": buckets(allRows, "types", "code"), "matchedOnly": buckets(matched, "types", "code"), "platforms": buckets(allRows, "platforms", "name"), "rows": names(allRows)})
Top-N for two parents
PRIMARY returns Riverside and West; SECONDARY returns Lakeside and Hill. The child limit applies independently to each parent.
types, err := lib.Q.SchoolTypesMinimal().SelectCode().
SelectSchoolListWith(lib.Q.SchoolsMinimal().SelectName().OrderByStudentCapacityDesc().OrderByIdAsc().Limit(2)).
OrderByCodeAsc().Limit(10).Comment("Load the two largest schools for each type").Purpose("Verify Top-N across two parents").ExecuteForList(context)
must(err); top := map[string][]string{}
for _, row := range types.Data {
expression := school_type.NewSchoolTypeExpression(row); children := []string{}
for i := 0; i < need(expression.SchoolList().Size().Eval()); i++ { children = append(children, need(expression.SchoolList().Get(i).Name().Eval())) }
top[need(expression.Code().Eval())] = children
}
report("top-n", top)
Multiple pages and stable ties
Traverse all five Schools with page size 2 and a final empty page. Capacity descending, name ascending and ID ascending order the two capacity-500 rows as Hill then West. Every page, including the empty tail, reports total 5. This is offset paging, not a continuous cursor.
pages := [][]string{}; totals := []uint64{}
for _, offset := range []uint64{0, 2, 4, 6} {
page, err := lib.Q.SchoolsMinimal().SelectName().
OrderByStudentCapacityDesc().OrderByNameAsc().OrderByIdAsc().Offset(offset).Limit(2).Count().
Comment("Traverse School pages including an empty tail").Purpose("Verify stable page boundaries").ExecuteForList(context)
must(err); if page.TotalCount == nil { panic("Missing filtered total") }
pages = append(pages, names(page)); totals = append(totals, *page.TotalCount)
}
report("page-boundaries", map[string]any{"pages": pages, "totals": totals})
No-match page
A filter matching no School returns an empty page and exact total 0, even with a nonzero offset.
page, err := lib.Q.SchoolsMinimal().SelectName().WithNameIs("No such School").
OrderByStudentCapacityDesc().OrderByIdAsc().Offset(1).Limit(2).Count().
Comment("Read a School filter with no matches").Purpose("Verify empty page count").ExecuteForList(context)
must(err); if page.TotalCount == nil { panic("Missing filtered total") }
report("empty-page", map[string]any{"names": names(page), "total": *page.TotalCount})
Facets with no matching rows
A no-match query retains both zero-count SchoolType buckets with include-all. Matched-only type and platform Facets are empty, and the result page is empty.
facets := func(includeAll bool) *core.SmartList[*school.School] {
rows, err := lib.Q.SchoolsMinimal().SelectName().WithNameIs("No such School").
FacetBySchoolTypeAs("types", lib.Q.SchoolTypesMinimal().SelectCode().CountSchoolsAs("count"), includeAll).
FacetByPlatformAs("platforms", lib.Q.PlatformsMinimal().SelectName().CountSchoolsAs("count"), false).
OrderByIdAsc().Limit(2).Comment("Facet the matching School set").Purpose("Compare zero and matched buckets").ExecuteForList(context)
must(err); return rows
}
allRows, matched := facets(true), facets(false)
report("empty-facets", map[string]any{"includeAll": buckets(allRows, "types", "code"), "matchedOnly": buckets(matched, "types", "code"), "platforms": buckets(allRows, "platforms", "name"), "rows": names(allRows)})
Positive, negative and nested relation predicates
Matching PRIMARY yields North, Riverside and West; excluding it yields Hill and Lakeside. A two-level School → SchoolType → Platform predicate returns the same three primary Schools. Predicates do not require loading the relation.
matching, err := lib.Q.SchoolsMinimal().SelectName().
WithSchoolTypeMatching(lib.Q.SchoolTypesMinimal().WithCodeIs("PRIMARY")).
OrderByNameAsc().Limit(10).Comment("Match School type by child request").
Purpose("Verify relation predicate semantics").ExecuteForList(context)
must(err)
excluding, err := lib.Q.SchoolsMinimal().SelectName().
WithoutSchoolTypeMatching(lib.Q.SchoolTypesMinimal().WithCodeIs("PRIMARY")).
OrderByNameAsc().Limit(10).Comment("Exclude School type by child request").
Purpose("Verify negative relation predicates").ExecuteForList(context)
must(err)
nested, err := lib.Q.SchoolsMinimal().SelectName().
WithSchoolTypeMatching(lib.Q.SchoolTypesMinimal().WithCodeIs("PRIMARY").
WithPlatformMatching(lib.Q.PlatformsMinimal().WithNameIs("Campus Learning Platform"))).
OrderByNameAsc().Limit(10).Comment("Match School through type and platform").
Purpose("Verify two-level relation predicates").ExecuteForList(context)
must(err)
report("relation-predicates", map[string]any{"matching": names(matching), "excluding": names(excluding), "nested": names(nested)})
Filtered children and an empty parent bucket
Select only inactive child Schools. Both SchoolType parents remain present: PRIMARY has a loaded empty list and SECONDARY contains Hill. Filtering a selected child list must not filter out its parent.
types, err := lib.Q.SchoolTypesMinimal().SelectCode().
SelectSchoolListWith(lib.Q.SchoolsMinimal().SelectName().WhichAreNotActive().OrderByStudentCapacityDesc().OrderByIdAsc().Limit(2)).
OrderByCodeAsc().Limit(10).Comment("Load inactive Schools for each type").Purpose("Preserve parents with empty child lists").ExecuteForList(context)
must(err); top := map[string][]string{}
for _, row := range types.Data {
expression := school_type.NewSchoolTypeExpression(row); children := []string{}
for i := 0; i < need(expression.SchoolList().Size().Eval()); i++ { children = append(children, need(expression.SchoolList().Get(i).Name().Eval())) }
top[need(expression.Code().Eval())] = children
}
report("filtered-children", top)
Filtered aggregates
Active Schools with capacity at least 500 produce PRIMARY: count 2, sum 1300, average 650; SECONDARY: count 1, sum 1200, average 1200. The aggregate request carries the filters itself.
groups, err := lib.Q.Schools().WhichAreActive().WithStudentCapacityGreaterThanOrEqualTo(500).GroupBySchoolType().CountAs("count").SumStudentCapacityAs("total").AvgStudentCapacityAs("average").Limit(10).
Comment("Aggregate active Schools with capacity at least 500").Purpose("Verify provider aggregation").ExecuteRecords(context)
must(err); distribution := []map[string]any{}
for _, row := range groups { distribution = append(distribution, map[string]any{"type": need(row["school_type"].TryU64()),
"count": need(row["count"].TryU64()), "total": need(row["total"].TryF64()), "average": need(row["average"].TryF64())}) }
report("filtered-groups", distribution)
Reject blank query intent
Separate bounded queries supply a blank comment or a blank purpose. Both must reject execution with an intent-related diagnostic; a successful query or an unrelated error fails this case.
rejected := []bool{}
for _, intent := range [][2]string{{" ", "Verify blank comment rejection"}, {"Check blank purpose rejection", " "}} {
denied := func() (denied bool) {
check := func(failure any) bool {
message := strings.ToLower(fmt.Sprint(failure))
if !strings.Contains(message, "comment") && !strings.Contains(message, "purpose") && !strings.Contains(message, "intent") { panic(failure) }
return true
}
defer func() { if failure := recover(); failure != nil { denied = check(failure) } }()
_, err := lib.Q.SchoolsMinimal().Limit(1).Comment(intent[0]).Purpose(intent[1]).ExecuteForList(context)
if err != nil { return check(err) }; return false
}()
rejected = append(rejected, denied)
}
report("blank-intent", map[string]any{"blankComment": rejected[0], "blankPurpose": rejected[1]})
Group analytics after deletion
After Riverside is updated and Hill is deleted, PRIMARY has count 3 and sum 1750; SECONDARY has count 1 and sum 1200. Tombstones must not inflate ordinary aggregates.
groups, err := lib.Q.Schools().GroupBySchoolType().CountAs("count").SumStudentCapacityAs("total").AvgStudentCapacityAs("average").Limit(10).
Comment("Aggregate surviving Schools after deletion").Purpose("Verify provider aggregation").ExecuteRecords(context)
must(err); distribution := []map[string]any{}
for _, row := range groups { distribution = append(distribution, map[string]any{"type": need(row["school_type"].TryU64()),
"count": need(row["count"].TryU64()), "total": need(row["total"].TryF64()), "average": need(row["average"].TryF64())}) }
report("deleted-groups", distribution)
Relation metrics after deletion
SchoolType relation counts and sums must agree with the surviving School rows: PRIMARY 3/1750, SECONDARY 1/1200.
cards, err := lib.Q.SchoolTypesMinimal().SelectCode().CountSchoolsAs("count").
SumStudentCapacityOfSchoolsAs("total", lib.Q.Schools()).OrderByCodeAsc().Limit(10).
Comment("Calculate relation metrics after School deletion").Purpose("Verify provider relation aggregation").ExecuteRecords(context)
must(err); metrics := map[string]any{}
for _, row := range cards { metrics[need(row["code"].TryText())] = map[string]any{"count": need(row["count"].TryU64()), "total": need(row["total"].TryF64())} }
report("deleted-metrics", metrics)
Facet totals after deletion
Ordinary type Facets count PRIMARY: 3 and SECONDARY: 1; platform count is 4. The two-row page is Lakeside then Riverside, so facet totals must ignore the page limit and exclude the tombstone.
facets := func(includeAll bool) *core.SmartList[*school.School] {
rows, err := lib.Q.SchoolsMinimal().SelectName().
FacetBySchoolTypeAs("types", lib.Q.SchoolTypesMinimal().SelectCode().CountSchoolsAs("count"), includeAll).
FacetByPlatformAs("platforms", lib.Q.PlatformsMinimal().SelectName().CountSchoolsAs("count"), false).
OrderByStudentCapacityDesc().OrderByIdAsc().Limit(2).Comment("Facet the matching School set").Purpose("Compare zero and matched buckets").ExecuteForList(context)
must(err); return rows
}
allRows, matched := facets(true), facets(false)
report("deleted-facets", map[string]any{"includeAll": buckets(allRows, "types", "code"), "matchedOnly": buckets(matched, "types", "code"), "platforms": buckets(allRows, "platforms", "name"), "rows": names(allRows)})
Ordinary children after deletion
After restart, PRIMARY returns Riverside and West; SECONDARY returns only Lakeside. A deleted child cannot appear in an ordinary selected relation.
types, err := lib.Q.SchoolTypesMinimal().SelectCode().
SelectSchoolListWith(lib.Q.SchoolsMinimal().SelectName().OrderByStudentCapacityDesc().OrderByIdAsc().Limit(2)).
OrderByCodeAsc().Limit(10).Comment("Load surviving Schools for each type").Purpose("Exclude tombstones from ordinary child lists").ExecuteForList(context)
must(err); top := map[string][]string{}
for _, row := range types.Data {
expression := school_type.NewSchoolTypeExpression(row); children := []string{}
for i := 0; i < need(expression.SchoolList().Size().Eval()); i++ { children = append(children, need(expression.SchoolList().Get(i).Name().Eval())) }
top[need(expression.Code().Eval())] = children
}
report("deleted-children", top)
Deleted-only children preserve live parents
Explicit deleted-only child selection yields an empty PRIMARY list and Hill under SECONDARY. Both live parents remain visible; the child version filter cannot change parent visibility.
types, err := lib.Q.SchoolTypesMinimal().SelectCode().
SelectSchoolListWith(lib.Q.SchoolsMinimal().SelectName().DeletedRowsOnly().OrderByStudentCapacityDesc().OrderByIdAsc().Limit(2)).
OrderByCodeAsc().Limit(10).Comment("Load retired Schools for each live type").Purpose("Keep child deletion scope separate from parent visibility").ExecuteForList(context)
must(err); top := map[string][]string{}
for _, row := range types.Data {
expression := school_type.NewSchoolTypeExpression(row); children := []string{}
for i := 0; i < need(expression.SchoolList().Size().Eval()); i++ { children = append(children, need(expression.SchoolList().Get(i).Name().Eval())) }
top[need(expression.Code().Eval())] = children
}
report("deleted-child-tombstones", top)
Continuous pages in ascending ID order
Read offsets 0, 2 and 4 in one trusted context. The first page uses OFFSET; the next two report CURSOR_SEEK without duplicates or omissions.
pages := make([][]string, 0); plans := make([]string, 0)
for _, step := range [][2]uint64{{0,0},{2,0},{4,0}} {
page, err := lib.Q.SchoolsMinimal().SelectName().WithStudentCapacityGreaterThanOrEqualTo(int64(step[1])).
OrderByIdAsc().Offset(step[0]).Limit(2).OptimizeForContinuousPageFetchWith("continuous-ascending", 60).
Comment("Browse School pagination").Purpose("Verify continuous-ascending").ExecuteForList(context)
must(err); pages = append(pages, names(page)); plans = append(plans, context.ContinuousPagePlan())
}
report("continuous-ascending", map[string]any{"pages": pages, "plans": plans})
Continuous pages in descending ID order
Traverse the same five Schools in reverse ID order and observe two CURSOR_SEEK plans.
pages := make([][]string, 0); plans := make([]string, 0)
for _, step := range [][2]uint64{{0,0},{2,0},{4,0}} {
page, err := lib.Q.SchoolsMinimal().SelectName().WithStudentCapacityGreaterThanOrEqualTo(int64(step[1])).
OrderByIdDesc().Offset(step[0]).Limit(2).OptimizeForContinuousPageFetchWith("continuous-descending", 60).
Comment("Browse School pagination").Purpose("Verify continuous-descending").ExecuteForList(context)
must(err); pages = append(pages, names(page)); plans = append(plans, context.ContinuousPagePlan())
}
report("continuous-descending", map[string]any{"pages": pages, "plans": plans})
Continuous cursor miss and recovery
Start at offset 2 without a cursor: observe CACHE_MISS, then reuse its boundary at offset 4.
pages := make([][]string, 0); plans := make([]string, 0)
for _, step := range [][2]uint64{{2,0},{4,0}} {
page, err := lib.Q.SchoolsMinimal().SelectName().WithStudentCapacityGreaterThanOrEqualTo(int64(step[1])).
OrderByIdAsc().Offset(step[0]).Limit(2).OptimizeForContinuousPageFetchWith("continuous-cache-miss", 60).
Comment("Browse School pagination").Purpose("Verify continuous-cache-miss").ExecuteForList(context)
must(err); pages = append(pages, names(page)); plans = append(plans, context.ContinuousPagePlan())
}
report("continuous-cache-miss", map[string]any{"pages": pages, "plans": plans})
Retained ID-set random page jumps
Build at offset 4, then jump to 0, 2 and 6. Preserve capacity/name/ID order, exact total 5 and ID_SET_HIT even for the empty tail.
pages := make([][]string, 0); plans := make([]string, 0)
totals := make([]uint64, 0); observedCounts := make([]uint64, 0)
for _, step := range [][2]uint64{{4,0},{0,0},{2,0},{6,0}} {
page, err := lib.Q.SchoolsMinimal().SelectName().WithStudentCapacityGreaterThanOrEqualTo(int64(step[1])).
OrderByStudentCapacityDesc().OrderByNameAsc().OrderByIdAsc().Offset(step[0]).Limit(2).OptimizePaginationWithIDSetConfig("id-set-jump", 60, 100).Count().
Comment("Browse School pagination").Purpose("Verify id-set-jump").ExecuteForList(context)
must(err); pages = append(pages, names(page)); plans = append(plans, context.IDSetPlan())
totals = append(totals, *page.TotalCount); count, _ := context.IDSetCount(); observedCounts = append(observedCounts, count)
}
report("id-set-jump", map[string]any{"pages": pages, "plans": plans, "totals": totals, "observedCounts": observedCounts})
Retained empty ID set
Run the same unmatched predicate twice. Retain the empty set, report total 0 and transition from ID_SET_BUILD to ID_SET_HIT.
pages := make([][]string, 0); plans := make([]string, 0)
totals := make([]uint64, 0); observedCounts := make([]uint64, 0)
for _, step := range [][2]uint64{{0,100000},{2,100000}} {
page, err := lib.Q.SchoolsMinimal().SelectName().WithStudentCapacityGreaterThanOrEqualTo(int64(step[1])).
OrderByStudentCapacityDesc().OrderByNameAsc().OrderByIdAsc().Offset(step[0]).Limit(2).OptimizePaginationWithIDSetConfig("id-set-empty", 60, 100).Count().
Comment("Browse School pagination").Purpose("Verify id-set-empty").ExecuteForList(context)
must(err); pages = append(pages, names(page)); plans = append(plans, context.IDSetPlan())
totals = append(totals, *page.TotalCount); count, _ := context.IDSetCount(); observedCounts = append(observedCounts, count)
}
report("id-set-empty", map[string]any{"pages": pages, "plans": plans, "totals": totals, "observedCounts": observedCounts})
ID-set safety-limit fallback
Set maxIds to 3 for five matching Schools. Observe LIMIT_EXCEEDED with a retained-count lower bound of 4; ordinary counted pagination still returns the correct page and exact total 5.
pages := make([][]string, 0); plans := make([]string, 0)
totals := make([]uint64, 0); observedCounts := make([]uint64, 0)
for _, step := range [][2]uint64{{2,0}} {
page, err := lib.Q.SchoolsMinimal().SelectName().WithStudentCapacityGreaterThanOrEqualTo(int64(step[1])).
OrderByStudentCapacityDesc().OrderByNameAsc().OrderByIdAsc().Offset(step[0]).Limit(2).OptimizePaginationWithIDSetConfig("id-set-overflow", 60, 3).Count().
Comment("Browse School pagination").Purpose("Verify id-set-overflow").ExecuteForList(context)
must(err); pages = append(pages, names(page)); plans = append(plans, context.IDSetPlan())
totals = append(totals, *page.TotalCount); count, _ := context.IDSetCount(); observedCounts = append(observedCounts, count)
}
report("id-set-overflow", map[string]any{"pages": pages, "plans": plans, "totals": totals, "observedCounts": observedCounts})
ID-set predicate isolation
Use one namespace with capacity thresholds 500, 1000 and 500. Distinct predicates build separate sets; returning to 500 hits its original set with exact total 4.
pages := make([][]string, 0); plans := make([]string, 0)
totals := make([]uint64, 0); observedCounts := make([]uint64, 0)
for _, step := range [][2]uint64{{0,500},{0,1000},{0,500}} {
page, err := lib.Q.SchoolsMinimal().SelectName().WithStudentCapacityGreaterThanOrEqualTo(int64(step[1])).
OrderByStudentCapacityDesc().OrderByNameAsc().OrderByIdAsc().Offset(step[0]).Limit(2).OptimizePaginationWithIDSetConfig("id-set-isolation", 60, 100).Count().
Comment("Browse School pagination").Purpose("Verify id-set-isolation").ExecuteForList(context)
must(err); pages = append(pages, names(page)); plans = append(plans, context.IDSetPlan())
totals = append(totals, *page.TotalCount); count, _ := context.IDSetCount(); observedCounts = append(observedCounts, count)
}
report("id-set-isolation", map[string]any{"pages": pages, "plans": plans, "totals": totals, "observedCounts": observedCounts})
Atomic Platform and School commit
The commit control changes Platform to Transactional Campus and Riverside to capacity 810;
both versions become 2. The runner clones the seeded database for each case.
Rust uses one typed transaction capability for both audited saves; other runtimes
save the loaded Platform graph and its School child.
rollback := os.Getenv("SCHOOL_SCENARIO") == "transaction-rollback"
root, err := lib.Q.Platforms().SelectSchoolListWith(lib.Q.Schools().WithNameIs("Riverside Primary School").Limit(2)).
Limit(2).Comment("Load the Platform and School transaction graph").Purpose("Verify atomic graph writes").ExecuteForOne(context)
must(err); child := root.SchoolList().Items()[0]
if rollback { winner := load(context, "Riverside Primary School"); winner.UpdateStudentCapacity(801)
_, err = winner.AuditAs("Advance School before the stale graph").Save(context); must(err) }
root.UpdateName("Transactional Campus"); child.UpdateStudentCapacity(810)
fmt.Println("SCHOOL_GRAPH_ATTEMPT")
_, conflict := root.AuditAs("Revise Platform and School atomically").Save(context)
if conflict != nil { text := strings.ToLower(conflict.Error()); if !rollback || !(strings.Contains(text, "version") || strings.Contains(text, "optimistic") || strings.Contains(text, "conflict") || strings.Contains(text, "stale")) { panic(conflict) } }
report(os.Getenv("SCHOOL_SCENARIO"), map[string]any{"rejected": conflict != nil})
Multi-entity rollback
The same block first commits an independent School revision to capacity 801/version 2, then attempts the stale Platform/School graph. Require an optimistic conflict. The SQL trace must show Platform UPDATE before the failing School UPDATE. The read-only database check requires the original Platform name, version and update time, and keeps the independently committed School revision. No compensating writes are used.
Concurrent writes to one School
Two separate processes load version 1, write readiness records, then wait for the runner to release a shared barrier. Exactly one save commits and one reports an optimistic conflict. The final capacity must match the actual winner (811 or 822), at version 2. A locked/busy database error fails the test; it is never counted as an optimistic conflict.
target, worker, barrier := os.Getenv("SCHOOL_TARGET"), os.Getenv("SCHOOL_WORKER"), os.Getenv("SCHOOL_BARRIER")
row := load(context, target); observedVersion := need(school.NewSchoolExpression(row).Version().Eval())
ready, err := json.Marshal(map[string]any{"observedVersion": observedVersion}); must(err)
must(os.WriteFile(barrier + "/" + worker + ".ready", ready, 0600))
deadline := time.Now().Add(30 * time.Second)
for { if _, err := os.Stat(barrier + "/release"); err == nil { break }; if time.Now().After(deadline) { panic("Barrier timeout") }; time.Sleep(10 * time.Millisecond) }
capacity := int64(811); if worker == "b" { capacity = 822 }; row.UpdateStudentCapacity(capacity)
_, conflict := row.AuditAs("Concurrent School capacity revision").Save(context); outcome, conflictReason := "committed", ""
if conflict != nil { text := strings.ToLower(conflict.Error()); if !(strings.Contains(text, "version") || strings.Contains(text, "optimistic") || strings.Contains(text, "conflict") || strings.Contains(text, "stale")) { panic(conflict) }; outcome = "conflict"; conflictReason = conflict.Error() }
data, err := json.Marshal(map[string]any{"worker": worker, "target": target, "observedVersion": observedVersion, "outcome": outcome, "conflictReason": conflictReason}); must(err)
fmt.Println("SCHOOL_WORKER " + string(data))
Concurrent writes to different Schools
The same worker block targets Riverside for worker a and North for worker b. Both must commit, leaving capacities 811 and 822 at version 2. All other rows, relations, identity and creation time must be unchanged.