Repository navigation
Capped thread copies: count an action's threads as ONE or MANY - #470
Merged
Merged
Conversation
CountStore keeps, per canonical key, a value and a count, sorted by key with no zero entries, so equal contents give equal entries whatever the order of operations. The count policy is per store: exact, or capped at Many (0, 1, MANY), where removing from Many has two outcomes and the caller picks one. It is plain Go with no Starlark and no language change, meant as the shared core for later users: the checker's own state (such as threads) and a spec-visible multiset. Tests: lib/countstore_test.go, random add/remove sequences against exact counts for both policies, canonical equality, outcomes and errors, clone and rekey. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The capped policy's increment, removal outcomes and capping now go through CardinalityCounter (Inc, Dec, NewCardinalityCounter), so the 0/1/MANY rules live in one place. A capped count is the counter's ValueCode. New test checks the two agree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the count policy and the exact counts. Each entry's count is a CardinalityCounter (ONE or MANY; absent is ZERO), so Add is the counter's Inc, RemoveOutcomes is its Dec, and there are no branches on a policy. Exact counts can come later as a separate type if needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Remove returns an error for a nil outcome instead of panicking. - Entries returns a copy, so callers cannot break the sort order or the no-ZERO invariant. - Document the key contract: the key is the element's identity, a complete canonical encoding or a collision-resistant hash; Add keeps the first value and Equal compares keys and counts. - Rekey merges with CardinalityCounter.Plus (new: the abstract sum) and builds into a temporary store, so a panicking key leaves it unchanged. - Total returns a shared MANY counter instead of allocating one. - Tests for each, plus Rekey MANY+MANY, idempotence, clone independence and the empty store; Plus is tested against concrete sums. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When max_concurrent_actions is MANY (-1), for an action in its
action_options or globally, an action's identical threads (same frames)
share one slot with a CardinalityCounter of copies. A new thread starts
as ONE; groups with identical frames merge at every yield (ONE + ONE is
MANY); running a copy of a MANY group splits it first into "ONE left" and
"MANY left" forks, a weakly fair choice. The group keeps its slot, and
the running copy takes a new one. Ordinary threads are unchanged and hash
as before. Crash on yield is skipped for copies for now.
--experimental_capped_threads makes MANY the default for an unset global
max_concurrent_actions. Actions with a fixed limit keep ordinary threads
and their limit, and only ordinary threads count towards the global
limit. Without the flag, options and output are unchanged.
Copies stay finite only when the threads' combined effect on the state
is bounded; a counter the threads change grows without bound.
Tests: tests/specs/capped-thread-copies (the rule as a spec) and
capped-threads-{lock,lock-buggy,fair-split,loop,flag}. The reference
suite passes unchanged (168/168).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
crash_on_yield now applies to grouped threads too. A group of ONE crashes as an ordinary thread. One copy of a MANY group crashing leaves ONE or MANY copies, so the crash has two successors, as a split does. Tests: tests/specs/capped-threads-crash (Quiet fails when a busy copy crashes, as with exact limits 1 to 3) and capped-threads-crash-loop (passes, as with exact limits). Reachable states include every state of the exact runs. Reference suite: 170/170. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add copies.go to the modelchecker Bazel rule. A MANY group can act again and again, so state that grows with each step must be bounded by the spec, as for any action that can run forever: say so as a caution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Role actions: decide copies with the same action_options keys as the concurrency limits, including the instance key "Role#0.Action". A fixed limit under any key keeps ordinary threads. Tests: capped-threads-role-limit and capped-threads-role-limit-buggy. - mergeCopies: one pass, keyed by frames and the thread's fairness, using the new CappedCountStore.AddCount instead of calling Add twice for MANY. - Document why the split is a fair choice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thread fairness is set only from the action at the root frame, so identical frames already have the same fairness, and liveness treats every thread continuation as strongly fair (fairnessLinkName), so a thread's fairness only marks its action's start link. Keying the merge on it too can never change a result; drop it and document why. Also remove the generated .json and out/ files that the role-limit specs committed by mistake. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Builds on #469 (
CappedCountStore). Identical threads of an action can now be counted as ONE or MANY copies, so any number of them can be in flight.action_options: <Action>: max_concurrent_actions: -1(MANY).--experimental_capped_threads, which makes MANY the default whenmax_concurrent_actionsisn't set.action_optionskeys the concurrency limits use (Role.Action,Role#.Actionand the instance keyRole#0.Action). A fixed limit under any key keeps ordinary threads.CardinalityCounterof copies.CappedCountStore.AddCount(new here). ONE + ONE is MANY.fair oneofdoes. Liveness treats both options as strongly fair.copies.goexplains why fairness is sound here.max_concurrent_actionskeep ordinary threads and their limit. Only ordinary threads count toward the global limit.-1, threads, hashing, options and output are unchanged.Caution: a MANY group can act again and again, like any action that can run forever. State that grows with each step, such as a counter the threads change, has to be bounded by the spec.
Verification
tests/specs:capped-thread-copiesmodels the scheduling rule itself as a spec.capped-threads-lockpasses andcapped-threads-lock-buggyfails MutualExclusion, as an exact limit of 2 does.capped-threads-fair-splitpasses. A build with an unfair split fails it.capped-threads-loopandcapped-threads-crash-looppass.capped-threads-crashfails liveness, because a crashed busy copy leaves busy set.capped-threads-flagruns with the flag and mixes copies with an action limited to 1.capped-threads-role-limitandcapped-threads-role-limit-buggyrun with the flag and give a role action a per-role limit of 1 (passes) or 2 (fails).python3 test_references.pypasses 172/172, and existing baselines are unchanged.go test ./libincludes the newTestCappedCountStoreAddCount.go test ./modelchecker ./libfails the same 7 tests as on main, which fail there already.🤖 Generated with Claude Code
https://claude.ai/code/session_013eDw2fcqNcKpnpHXHYFi7n