This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: go-1-24-synctest-virtual-clock-determinism-standard

Go 1.24 synctest Synthetic Bubble & Virtual Clock Determinism Standard

Enforces isolated synthetic time bubbles using Go 1.24's testing/synctest package across concurrent microservice actor and integration suites. Eliminates non-deterministic wall-clock sleeps, flaky channel polling loops, and real-time race conditions in deadline-sensitive state machines. Guarantees that goroutines within tests advance virtual time instantaneously upon durable blockage without leaking goroutines beyond the bubble boundary.

Prohibited Anti-Pattern: Non-Deterministic Wall-Clock Sleep and Arbitrary Channel Polling in Concurrent Integration Tests

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Go 1.24 synctest Synthetic Bubble & Virtual Clock Determinism Standard - Enforces isolated synthetic time bubbles using Go 1.24's testing/synctest package across concurrent microservice actor and integration suites. Eliminates non-deterministic wall-clock sleeps, flaky channel polling loops, and real-time race conditions in deadline-sensitive state machines. Guarantees that goroutines within tests advance virtual time instantaneously upon durable blockage without leaking goroutines beyond the bubble boundary.
globs: **/*_test.go, tests/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/go-1-24-synctest-virtual-clock-determinism-standard"
---

# Go 1.24 synctest Synthetic Bubble & Virtual Clock Determinism Standard

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Non-Deterministic Wall-Clock Sleep and Arbitrary Channel Polling in Concurrent Integration Tests

## System Constraints
You are a Principal Software Architect enforcing the Go 1.24 testing/synctest Virtual Clock Determinism Standard. You must mandate strict isolation of concurrent actor suites within synthetic bubbles (`synctest.Run`). Forbid any wall-clock `time.Sleep` padding, unconstrained timer polling, or real external I/O within synctest bubbles that causes deadlocks or breaks virtual clock advancement. Ensure all spawned goroutines are tracked, durably blocked, or properly terminated before bubble exit.

## Strict Guidelines
- Engineers MUST ALWAYS wrap time-dependent and deadline-sensitive concurrent tests inside `synctest.Run(func() { ... })` when targeting Go 1.24+.
- Engineers MUST NEVER use arbitrary wall-clock `time.Sleep(...)` or loop retries to await state transitions in asynchronous distributed actors.
- Engineers MUST call `synctest.Wait()` to deterministically block until all goroutines in the current bubble have reached a quiescent, blocked state before asserting state.
- Services and actors inside a `synctest.Run` bubble MUST NOT perform real network, disk, or unmocked OS blocking I/O, as external blocking violates bubble isolation and triggers synthetic deadlocks.
- Engineers MUST ensure all goroutines spawned inside a synthetic bubble terminate or reach permanent cancellation before `synctest.Run` completes to prevent leaked bubble panics.
- Timers, tickers, and context deadlines inside the bubble MUST rely strictly on standard library `time` and `context` primitives, which automatically link into the synthetic virtual clock.

## Bad vs Good Implementations
### Flaky Wall-Clock Deadline Evaluation vs. Deterministic synctest Bubble

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Relies on real wall-clock elapsed time (time.Sleep). On slow CI nodes or CPU-throttled containers, 300ms may elapse before the goroutine is scheduled, or conversely the goroutine may not transition in time, leading to non-deterministic test failures and slow execution.
```go
package actor_test

import (
	"context"
	"testing"
	"time"
)

func TestActorHeartbeatTimeout_Flaky(t *testing.T) {
	ctx, cancel := context.WithTimeout(context.Background(), 250*time.Millisecond)
	defer cancel()

	hb := NewHeartbeatMonitor(ctx)
	go hb.Start()

	// ANTI-PATTERN: Wall-clock sleeping introduces race conditions,
	// CI flakiness, and inflates test suite execution duration.
	time.Sleep(300 * time.Millisecond)

	if !hb.IsExpired() {
		t.Fatalf("expected heartbeat to be expired after wall-clock timeout")
	}
}
```

#### Production Standard (Correct)
> **Standard**: Wraps execution inside synctest.Run. The 10-second context and 11-second virtual sleep advance instantly in simulated time without burning CPU or real-world time. synctest.Wait ensures all background goroutines in the bubble settle before assertions occur.
```go
package actor_test

import (
	"context"
	"testing"
	"testing/synctest"
	"time"
)

func TestActorHeartbeatTimeout_Deterministic(t *testing.T) {
	synctest.Run(func() {
		ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
		defer cancel()

		hb := NewHeartbeatMonitor(ctx)
		go hb.Start()

		// Advance the synthetic bubble clock deterministically.
		// synctest virtualizes time: sleeping instantly advances time
		// as soon as all bubble goroutines are durably blocked.
		time.Sleep(11 * time.Second)
		synctest.Wait()

		if !hb.IsExpired() {
			t.Fatalf("expected heartbeat to be expired deterministically")
		}
	})
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Go 1.24 synctest Synthetic Bubble & Virtual Clock Determinism Standard

Go 1.24 synctest Synthetic Bubble & Virtual Clock Determinism Standard defines an industrial-grade behavioral standard for backend engineering. Enforces isolated synthetic time bubbles using Go 1.24's testing/synctest package across concurrent microservice actor and integration suites. Eliminates non-deterministic wall-clock sleeps, flaky channel polling loops, and real-time race conditions in deadline-sensitive state machines. Guarantees that goroutines within tests advance virtual time instantaneously upon durable blockage without leaking goroutines beyond the bubble boundary. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Non-Deterministic Wall-Clock Sleep and Arbitrary Channel Polling in Concurrent Integration Tests Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftNon-Deterministic Wall-Clock Sleep and Arbitrary Channel Polling in Concurrent Integration TestsCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS wrap time-dependent and deadline-sensitive concurrent tests inside `synctest.Run(func() { ... })` when targeting Go 1.24+.

Engineers MUST ALWAYS wrap time-dependent and deadline-sensitive concurrent tests inside `synctest.Run(func() { ... })` when targeting Go 1.24+.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NEVER use arbitrary wall-clock `time.Sleep(...)` or loop retries to await state transitions in asynchronous distributed actors.

Engineers MUST NEVER use arbitrary wall-clock `time.Sleep(...)` or loop retries to await state transitions in asynchronous distributed actors.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST call `synctest.Wait()` to deterministically block until all goroutines in the current bubble have reached a quiescent, blocked state before asserting state.

Engineers MUST call `synctest.Wait()` to deterministically block until all goroutines in the current bubble have reached a quiescent, blocked state before asserting state.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services and actors inside a `synctest.Run` bubble MUST NOT perform real network, disk, or unmocked OS blocking I/O, as external blocking violates bubble isolation and triggers synthetic deadlocks.

Services and actors inside a `synctest.Run` bubble MUST NOT perform real network, disk, or unmocked OS blocking I/O, as external blocking violates bubble isolation and triggers synthetic deadlocks.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Engineers MUST ensure all goroutines spawned inside a synthetic bubble terminate or reach permanent cancellation before `synctest.Run` completes to prevent leaked bubble panics.

Engineers MUST ensure all goroutines spawned inside a synthetic bubble terminate or reach permanent cancellation before `synctest.Run` completes to prevent leaked bubble panics.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Timers, tickers, and context deadlines inside the bubble MUST rely strictly on standard library `time` and `context` primitives, which automatically link into the synthetic virtual clock.

Timers, tickers, and context deadlines inside the bubble MUST rely strictly on standard library `time` and `context` primitives, which automatically link into the synthetic virtual clock.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Go 1.24 synctest Synthetic Bubble & Virtual Clock Determinism Standard critical for AI coding assistants?

Enforces isolated synthetic time bubbles using Go 1.24's testing/synctest package across concurrent microservice actor and integration suites. Eliminates non-deterministic wall-clock sleeps, flaky channel polling loops, and real-time race conditions in deadline-sensitive state machines. Guarantees that goroutines within tests advance virtual time instantaneously upon durable blockage without leaking goroutines beyond the bubble boundary. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Non-Deterministic Wall-Clock Sleep and Arbitrary Channel Polling in Concurrent Integration Tests) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Go