본문으로 건너뛰기
cccskills
무료GitHub에 공개

tla-plus

Model distributed systems and concurrent algorithms in TLA+ or PlusCal, then check possible states with TLC. Use the results to investigate deadlocks, broken rules, and differences between specifications and implementation code.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

Create, run, and verify TLA+ and PlusCal formal specifications. Use for modeling distributed systems, protocols, concurrent algorithms, state machines. Can compose specs from code, find divergences between spec and implementation, spot concurrency bugs and invariant violations. Use when asked to "write a TLA+ spec", "model check", "verify protocol", "find race conditions", or "formal verification".

설치 방법 보기

이럴 때 유용합니다

  • Model a distributed protocol before implementation
  • Create a specification from existing concurrent code
  • Investigate deadlocks and race conditions
  • Trace model-checking failures back to code paths

포함된 파일(15)

  • SKILL.md7.3 KB
  • references/language.md5.3 KB
  • references/patterns/code-to-spec.md6.0 KB
  • references/patterns/distributed-systems.md5.7 KB
  • references/patterns/invariants.md5.4 KB
  • references/patterns/protocols.md5.5 KB
  • references/pluscal.md5.1 KB
  • scripts/check.sh921 B
  • scripts/parse.sh417 B
  • scripts/setup.sh2.9 KB
  • scripts/tlc.sh1.3 KB
  • scripts/translate.sh440 B
  • templates/basic.tla930 B
  • templates/distributed.tla2.6 KB
  • templates/pluscal.tla1004 B

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

TLA+ Formal Specification Skill

Write non-trivial TLA+ specifications, run the TLC model checker, and bridge the gap between formal specs and implementation code.

Setup (Run Once)

bash SKILL_DIR/scripts/setup.sh

This downloads tla2tools.jar (v1.8.0) and verifies Java 11+. The JAR is stored at SKILL_DIR/lib/tla2tools.jar.

Quick Reference

Load the right reference for your task:

TaskReference
TLA+ syntax, operators, typesreferences/language.md
PlusCal syntax, processes, labelsreferences/pluscal.md
Distributed systems patternsreferences/patterns/distributed-systems.md
Protocol specificationsreferences/patterns/protocols.md
Invariants, safety, livenessreferences/patterns/invariants.md
Code ↔ spec mapping, bug findingreferences/patterns/code-to-spec.md

Load references on-demand — read the ones relevant to the current task before writing any spec.

Templates

Start from a template when creating a new spec:

TemplateUse For
templates/basic.tlaPure TLA+ state machine
templates/pluscal.tlaPlusCal algorithm with processes
templates/distributed.tlaDistributed system with messages

Running Specs

Full Check (Recommended)

Translates PlusCal (if present), parses, and model-checks in one step:

bash SKILL_DIR/scripts/check.sh spec.tla --config spec.cfg

Individual Tools

# Parse only (syntax check)
bash SKILL_DIR/scripts/parse.sh spec.tla

# Translate PlusCal to TLA+
bash SKILL_DIR/scripts/translate.sh spec.tla -nocfg

# Model check with TLC
bash SKILL_DIR/scripts/tlc.sh spec.tla --config spec.cfg --workers auto
bash SKILL_DIR/scripts/tlc.sh spec.tla --no-deadlock    # suppress deadlock check

Direct Java Invocation

JAR="SKILL_DIR/lib/tla2tools.jar"

# Parse
java -cp "$JAR" tla2sany.SANY spec.tla

# Translate PlusCal
java -cp "$JAR" pcal.trans -nocfg spec.tla

# Model check
java -cp "$JAR" tlc2.TLC -workers auto -config spec.cfg spec.tla

# REPL
java -cp "$JAR" tlc2.REPL

# Dump state graph (for visualization)
java -cp "$JAR" tlc2.TLC -dump dot,actionlabels,colorize states.dot spec.tla

Workflow: Writing a Spec

1. Understand the System

Before writing any TLA+:

  • Identify the concurrent agents (processes, nodes, threads)
  • Identify shared mutable state (queues, databases, locks, counters)
  • Identify the key safety property ("what must never happen?")
  • Identify the key liveness property ("what must eventually happen?")

2. Choose PlusCal vs Pure TLA+

Use PlusCal when:

  • The system is naturally sequential/imperative
  • You're modeling code (threads, goroutines, async tasks)
  • You need await, while, goto semantics
  • The audience is programmers

Use Pure TLA+ when:

  • You need fine-grained fairness control
  • The system is naturally a state machine
  • You need interruptible/restartable actions
  • You need refinement mappings
  • A single label would need to update a variable twice

3. Start Small, Then Expand

  1. Write the simplest possible spec that captures the core behavior
  2. Add a type invariant immediately
  3. Run TLC with small constants (2-3 nodes, 2-3 messages)
  4. Add safety invariants one at a time, running after each
  5. Add liveness properties with fairness
  6. Increase constants to expand coverage

4. Config File

Every spec needs a .cfg file. Create one alongside the .tla:

SPECIFICATION Spec

\* Properties to check
INVARIANT TypeInvariant
INVARIANT Safety

\* Uncomment for liveness (slower)
\* PROPERTY Liveness

\* Constants
CONSTANT
  NumNodes = 3
  MaxMsgs = 5
  NULL = NULL

\* Uncomment to bound state space
\* CONSTRAINT StateConstraint

\* Uncomment to ignore deadlocks
\* CHECK_DEADLOCK FALSE

Workflow: Spec From Code

When the user has existing code and wants a spec:

  1. Read the code — understand concurrency structure, shared state, synchronization
  2. Read references/patterns/code-to-spec.md
  3. Map constructs — threads→processes, locks→await, channels→queues
  4. Abstract — don't model every line, only concurrency-relevant operations
  5. Write spec — start with the concurrent skeleton, add detail iteratively
  6. Run TLC — find deadlocks, invariant violations, liveness failures
  7. Report — translate any TLC error traces back to code execution paths

Workflow: Finding Bugs

When comparing a spec to code, or looking for bugs:

  1. Read references/patterns/code-to-spec.md
  2. Write a spec modeling the suspected buggy area
  3. Run with small constants — TLC is exhaustive, small state space is fine
  4. Interpret error traces — map TLA+ state sequences to code execution paths
  5. Check atomicity — does the code do atomically what the spec's label does?
  6. Check completeness — does the code handle all either/or branches?
  7. Check ordering — does the code enforce the same happens-before relations?

If TLC finds a violation:

  • The error trace is a concrete counterexample — a specific sequence of events
  • Map each state in the trace to concrete code state
  • The transition that causes the violation is the bug location

Interpreting TLC Output

Success

Model checking completed. No error has been found.
  Estimates of the probability that TLC did not check all reachable states
  because two distinct states had the same fingerprint:
  calculated (optimistic):  val: 0

Invariant Violation

Error: Invariant SafetyInvariant is violated.
The following behavior constitutes a counter-example:
State 1: <Initial predicate>
  /\ var1 = ...
State 2: <Action line X>
  /\ var1 = ... (changed values in red)

Deadlock

Error: Deadlock reached.

→ No process can make progress. Check await conditions and process completion.

Liveness Violation

Error: Temporal properties were violated.

→ Check fairness settings. Add WF_vars or SF_vars. Trace may include a "stuttering" suffix.

Key Principles

  1. Type invariants first — catch spec bugs before checking real properties
  2. Small constants — 3 nodes finds most bugs; 10 nodes takes 1000× longer
  3. Safety before liveness — invariants are faster to check
  4. One property at a time — add incrementally, run after each addition
  5. Fairness is opt-in — TLA+ assumes everything can crash by default
  6. => with \A, /\ with \E — never use => with \E
  7. Sequences are 1-indexed — always
  8. Every action must specify all variables — use UNCHANGED for untouched ones

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Analyze bug-fix commits in a Git repository to uncover recurring failure patterns. Produce individual bug analyses and a reusable pattern guide that removes project-specific details, helping inform future code reviews.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Extract recurring bug patterns from past fixes
  • Build a reusable guide for code reviews
  • Analyze fixes within a chosen date range or path
apache/cassandra1만2026년 10월 17일 업데이트

Write Apache Cassandra distributed tests that simulate multiple nodes within one JVM, the Java runtime. The guide covers cluster setup, queries, node restarts, message dropping for failure scenarios, and troubleshooting problems caused by isolated class loading.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Writing read and write tests across multiple nodes
  • Testing timeouts by dropping messages between nodes
  • Verifying node replacement and restarts
apache/cassandra1만2026년 10월 17일 업데이트

Review selected files for bugs by reading full source code, callers, and related implementations. Apply detailed checklists and investigate suspected issues, then report evidence, confidence levels, and suggested fixes.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Review selected files in a critical code change
  • Investigate concerns raised by an initial review
  • Check complex state transitions and object lifecycles
apache/cassandra1만2026년 10월 17일 업데이트

heatmap

무료

Analyze Git history to find frequently and recently changed files and lines, then rank review targets. Use the results to focus pull request reviews, bug investigations, or security audits on specific code regions and risks.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Prioritizing files during pull request reviews
  • Finding starting points for bug investigations
  • Narrowing security audits to frequently changed code
apache/cassandra1만2026년 10월 17일 업데이트

Review changes of 1,000 lines or more by dividing work across files, focused areas, and commits. Combine several review methods, check consistency across subsystems, verify bug fixes, and report validated findings alongside a checklist showing review coverage.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Reviewing feature branches with 1,000 or more changed lines
  • Checking a large change before merging
  • Finding inconsistencies across commits and subsystems
apache/cassandra1만2026년 10월 17일 업데이트

Explain code structure and behavior with text diagrams, including before-and-after views of changes. Trace data flow and state changes, clarify design choices, and examine assumptions, possible failures, and interactions between tasks running at the same time.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Understanding a patch through before-and-after diagrams
  • Tracing a class's behavior and state changes
  • Mapping component relationships across a codebase
apache/cassandra1만2026년 10월 17일 업데이트

apache의 스킬 모두 보기

이 스킬의 문제 신고