Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
8c83db5
petri pitch
Mar 16, 2026
85bc90a
petri: add consensus integration plan, codebase mapping, and risk ana…
Mar 20, 2026
beffddd
Merge remote-tracking branch 'origin/stabilisation' into petri
Mar 20, 2026
76f4b9a
petri: revise planning docs after stabilisation merge
Mar 20, 2026
d714c16
petri: add Phase 8 (Soft Finality SDK Endpoint) to plan
Mar 20, 2026
6e16478
petri: implement Phase 0 — foundation types and feature flag
Mar 20, 2026
73ee96e
petri: implement Phase 1 — transaction classification
Mar 20, 2026
ca7d45c
petri: update architecture diagram for Phase 1
Mar 20, 2026
8886756
petri: fix classification timing — classify at mempool insertion, not…
Mar 20, 2026
e25d2d4
petri: implement Phase 2 — Continuous Forge loop
Mar 20, 2026
807e3c9
petri: update architecture diagram for Phase 2
Mar 20, 2026
79fd7e6
petri: implement Phase 3 — Block Finalization
Mar 20, 2026
2f5740e
petri: update architecture diagram for Phase 3
Mar 20, 2026
04df594
petri: implement Phase 4 — RPC Routing Refactor
Mar 20, 2026
7c1de05
petri: update architecture diagram for Phase 4
Mar 20, 2026
9f29730
petri: add reflexion review comments for P3/P4 clarity
Mar 20, 2026
17cb4fd
petri: implement Phase 5 — Finality & Status API
Mar 20, 2026
f3d5ea7
petri: update architecture diagram for Phase 5
Mar 20, 2026
c5baadb
petri: guard soft_finality_at to preserve first-set semantics
Mar 20, 2026
c9c13d7
petri: implement Phase 6 — Integration Testing & Hardening
Mar 20, 2026
e72c6b9
petri: update architecture diagram for Phase 6
Mar 20, 2026
0b043f6
petri: implement Phase 7 — Secretary Deprecation (markers only)
Mar 21, 2026
334426a
petri: update architecture diagram for Phase 7
Mar 21, 2026
7892972
petri: add missing @deprecated marker on getBlockTimestamp RPC
Mar 21, 2026
e59090b
petri: integrate Petri tests into better_testing harness
Mar 21, 2026
b09f2cb
petri: add configurable Petri params via env/config and devnet wiring
Mar 21, 2026
e63b034
petri: add devnet scenarios for block production and tx inclusion
Mar 21, 2026
64bbc50
petri: add relay flow e2e devnet scenario
Mar 21, 2026
c45d87a
petri: add Petri consensus metrics to MetricsCollector
Mar 21, 2026
6eaedbf
petri: add soak run + performance baseline scenario
Mar 21, 2026
0b78d2f
petri: add Config.petri accessor and fix docker-compose indentation
Mar 21, 2026
4cda553
fix: use getLastBlockNumber RPC in petri soak scenario
Mar 21, 2026
8efa4e7
fix: gate PoRBFT Secretary flow when Petri consensus is active
Mar 21, 2026
758eb68
fix: deterministic block compilation and reentrance guard for Petri c…
Mar 21, 2026
0024c9f
fix: Petri accept-and-sign model for block hash voting
Mar 21, 2026
472cb56
feat: Petri consensus fully working — make default, fix DB poisoning,…
Mar 22, 2026
de52d29
docs: add petri/consensus.md, deprecate PoRBFT, guard L2PS SecretaryM…
Mar 22, 2026
8751305
ignores
Mar 23, 2026
5e9ded4
Merge branch 'stabilisation' into petri
Mar 23, 2026
7f492f5
refactor: complete better_testing/ → testing/ migration for Petri tests
Mar 23, 2026
5d2fffd
fix: use localeCompare in sort() calls for reliable alphabetical orde…
Mar 23, 2026
1f4c3ee
docs: add missing Petri config keys to .env.example files
Mar 23, 2026
6c6872a
docs: fix StateDelta hash comment to reflect normalized field set
Mar 23, 2026
dc02d10
fix: require softFinalityObserved in petri_tx_inclusion test
Mar 23, 2026
62a7a7a
fix: validate Petri config invariants before freezing
Mar 23, 2026
aaa561c
fix: use strict undefined check for blockNumber in mempool queries
Mar 23, 2026
567848d
fix: expose tracker count via public accessor, fix broken metric
Mar 23, 2026
27a1fa1
fix: deduplicate transactions in petriBlockCompiler before ordering
Mar 23, 2026
4dbd532
fix: reset startingConsensus on preflight error via try/finally
Mar 23, 2026
f1fc78f
fix: only remove committed TXs from mempool after block insertion
Mar 23, 2026
73a6863
fix: add try/catch to getTransactionFinality RPC handler
Mar 23, 2026
ab5b63d
fix: clear currentRoundDeltas at start of each forge round
Mar 23, 2026
4ae0734
fix: prevent double-counting mismatched submissions in collectBlockHa…
Mar 23, 2026
7f6ce72
fix: add local mempool fallback when Petri relay fails
Mar 23, 2026
6682606
fix: address minor review feedback from CodeRabbit
Mar 24, 2026
d41a902
fix: align block wait to global boundary instead of fixed sleep
Mar 24, 2026
b155aec
fix: use Petri config-driven wait window in ensureCandidateBlockFormed
Mar 24, 2026
87d2304
fix: use real election logic in secretaryCoordination test suite
Mar 24, 2026
784ddcc
fix: add timeout on delta exchange and validate peer response structure
Mar 24, 2026
353644b
fix: add failure reason when soft finality is not observed
Mar 24, 2026
7f07a0b
fix: mark TX as FAILED when speculative execution fails
Mar 24, 2026
1b02c40
fix: drain in-flight forge round before block compilation
Mar 24, 2026
6d8c770
fix: lazily classify unclassified mempool TXs at start of forge round
Mar 24, 2026
1db79d7
fix: use explicit null check for currentRoundPromise in drain()
Mar 24, 2026
de41db8
ignores and memory
Mar 24, 2026
79a51dd
Merge remote-tracking branch 'origin/stabilisation' into merge/stabil…
claude Apr 1, 2026
083ada5
fix: update speculativeExecutor to use new in-memory GCR API + add me…
claude Apr 1, 2026
aa7663e
fix: update omni gcr handler to new in-memory GCR API + gitignore mer…
claude Apr 2, 2026
9e8e557
Merge pull request #755 from kynesyslabs/merge/stabilisation-into-petri
tcsenpai Apr 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ L2PS_HASH_INTERVAL_MS=5000
# ===========================================
# OmniProtocol TCP Server Configuration
# ===========================================
OMNI_ENABLED=false
OMNI_PORT=3001
OMNI_MODE=OMNI_ONLY
OMNI_ENABLED=true
OMNI_FATAL=false
OMNI_MODE=OMNI_PREFERRED
OMNI_PORT=3001

# OmniProtocol TLS Encryption
OMNI_TLS_ENABLED=false
Expand Down Expand Up @@ -80,3 +80,14 @@ TLSNOTARY_MAX_RECV_DATA=65536
# ZK Identity System Configuration
# Points awarded for each successful ZK attestation (default: 10)
ZK_ATTESTATION_POINTS=10

# ===========================================
# Petri Consensus Configuration
# ===========================================
# Petri is enabled by default. Set to false to fall back to PoRBFT v2.
PETRI_CONSENSUS=true
PETRI_FORGE_INTERVAL_MS=2000
PETRI_BLOCK_INTERVAL_MS=10000
PETRI_AGREEMENT_THRESHOLD=7
PETRI_PROBLEMATIC_TTL_ROUNDS=5
PETRI_SHARD_SIZE=10
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ BUGS_AND_SECURITY_REPORT.md
CEREMONY_COORDINATION.md
PR_REVIEW_COMPREHENSIVE.md
PR_REVIEW_RAW.md
MERGE_REPORT*.md

# ZK Ceremony files (SECURITY: must not be committed)
zk_ceremony/
Expand Down Expand Up @@ -290,3 +291,5 @@ documentation/demos_yp_v5.pdf
/documentation/internal-docs
/PR_DUMP.md
/.beads
/testing/runs
/better_testing/PR_ANALYSIS_RAW.md
Binary file modified .mycelium/mycelium.db
Binary file not shown.
14 changes: 14 additions & 0 deletions .serena/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,17 @@ read_only_memory_patterns: []
# Possible values: unset (use global setting), "lf", "crlf", or "native" (platform default)
# This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.
line_ending:

# advanced configuration option allowing to configure language server-specific options.
# Maps the language key to the options.
# Have a look at the docstring of the constructors of the LS implementations within solidlsp (e.g., for C# or PHP) to see which options are available.
# No documentation on options means no options are available.
ls_specific_settings: {}

# list of regex patterns for memories to completely ignore.
# Matching memories will not appear in list_memories or activate_project output
# and cannot be accessed via read_memory or write_memory.
# To access ignored memory files, use the read_file tool on the raw file path.
# Extends the list from the global configuration, merging the two lists.
# Example: ["_archive/.*", "_episodes/.*"]
ignored_memory_patterns: []
143 changes: 8 additions & 135 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,140 +1,6 @@
# AI Agent Instructions for Demos Network

## Issue Tracking with br (beads_rust)

**IMPORTANT**: This project uses **br (beads_rust)** for ALL issue tracking. Do NOT use markdown TODOs, task lists, or other tracking methods.

### Why br?

- Dependency-aware: Track blockers and relationships between issues
- Git-friendly: Auto-syncs to JSONL for version control
- Agent-optimized: JSON output, ready work detection, discovered-from links
- Prevents duplicate tracking systems and confusion

### Quick Start

**Check for ready work:**
```bash
br ready --json
```

**Create new issues:**
```bash
br create "Issue title" -t bug|feature|task -p 0-4 --json
br create "Issue title" -p 1 --deps discovered-from:br-123 --json
```

**Claim and update:**
```bash
br update br-42 --status in_progress --json
br update br-42 --priority 1 --json
```

**Complete work:**
```bash
br close br-42 --reason "Completed" --json
```

### Issue Types

- `bug` - Something broken
- `feature` - New functionality
- `task` - Work item (tests, docs, refactoring)
- `epic` - Large feature with subtasks
- `chore` - Maintenance (dependencies, tooling)

### Priorities

- `0` - Critical (security, data loss, broken builds)
- `1` - High (major features, important bugs)
- `2` - Medium (default, nice-to-have)
- `3` - Low (polish, optimization)
- `4` - Backlog (future ideas)

### Workflow for AI Agents

1. **Check ready work**: `br ready` shows unblocked issues
2. **Claim your task**: `br update <id> --status in_progress`
3. **Work on it**: Implement, test, document
4. **Discover new work?** Create linked issue:
- `br create "Found bug" -p 1 --deps discovered-from:<parent-id>`
5. **Complete**: `br close <id> --reason "Done"`
6. **Commit together**: Always commit the `.beads/issues.jsonl` file together with the code changes so issue state stays in sync with code state

### Auto-Sync

br automatically syncs with git:
- Exports to `.beads/issues.jsonl` after changes (5s debounce)
- Imports from JSONL when newer (e.g., after `git pull`)
- No manual export/import needed!

### GitHub Copilot Integration

If using GitHub Copilot, also create `.github/copilot-instructions.md` for automatic instruction loading.
Run `br onboard` to get the content, or see step 2 of the onboard instructions.

### MCP Server (Recommended)

If using Claude or MCP-compatible clients, install the beads MCP server:

```bash
pip install beads-mcp
```

Add to MCP config (e.g., `~/.config/claude/config.json`):
```json
{
"beads": {
"command": "beads-mcp",
"args": []
}
}
```

Then use `mcp__beads__*` functions instead of CLI commands.

### Managing AI-Generated Planning Documents

AI assistants often create planning and design documents during development:
- PLAN.md, IMPLEMENTATION.md, ARCHITECTURE.md
- DESIGN.md, CODEBASE_SUMMARY.md, INTEGRATION_PLAN.md
- TESTING_GUIDE.md, TECHNICAL_DESIGN.md, and similar files

**Best Practice: Use a dedicated directory for these ephemeral files**

**Recommended approach:**
- Create a `history/` directory in the project root
- Store ALL AI-generated planning/design docs in `history/`
- Keep the repository root clean and focused on permanent project files
- Only access `history/` when explicitly asked to review past planning

**Example .gitignore entry (optional):**
```
# AI planning documents (ephemeral)
history/
```

**Benefits:**
- Clean repository root
- Clear separation between ephemeral and permanent documentation
- Easy to exclude from version control if desired
- Preserves planning history for archeological research
- Reduces noise when browsing the project

### Important Rules

- Use br for ALL task tracking
- Always use `--json` flag for programmatic use
- Link discovered work with `discovered-from` dependencies
- Check `br ready` before asking "what should I work on?"
- Store AI planning docs in `history/` directory
- Do NOT create markdown TODO lists
- Do NOT use external issue trackers
- Do NOT duplicate tracking systems
- Do NOT clutter repo root with planning documents

For more details, see README.md and QUICKSTART.md.

Read @TEAM.md

## Project Management with Mycelium

Expand Down Expand Up @@ -213,3 +79,10 @@ When working on this project:
5. Use `--json` flag for machine-readable output: `myc task list --json`
6. For mutating `br` operations, prefer `bun run brx -- <br command...>` so `br` stays synced into Mycelium automatically
7. Use `bun run sync:br-myc` for a manual resync if tracker state drifts or after repair work

<!-- TEAM_MODE:START -->
## ⚡ Team Mode is ACTIVE
IMPORTANT: Read `TEAM.md` in the project root IN FULL before processing any task.
You are operating as Tech Lead of a multi-agent team, not as a solo developer.
If you don't remember Team Mode being activated, re-read `TEAM.md` NOW — it contains all instructions.
<!-- TEAM_MODE:END -->
106 changes: 106 additions & 0 deletions MERGE_REPORT_stabilisation_into_petri.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Merge Report: Stabilisation Hotfixes into Petri

**Date:** 2026-04-01
**Branch:** `merge/stabilisation-into-petri` (transient)
**Base:** `petri` ← `stabilisation`

---

## 1. Stabilisation Hotfixes Summary

9 commits merged from `stabilisation` that were not in `petri`:

| Commit | Description | Risk to Petri |
|--------|-------------|---------------|
| `979eb8c` | **GCR in-memory edit refactor** — routines now take `GCRMain` entity instead of `Repository` | **CRITICAL** |
| `628937b` | **L2PSConsensus refactor** — updated to use new GCR `prepareAccounts`/`applyTransaction` API | HIGH |
| `5dd0a9b` | LLM-suggested fixes on GCR routines (cleanup pass) | MEDIUM |
| `fdd86f0` | **Port staggering** — RPC/Omni ports now interleaved (53551/53552, 53553/53554, ...) | LOW |
| `74a4a6e` + `f29e49d` | **TX count inversion bug fix** — success/fail arrays were swapped + Set dedup | CRITICAL |
| `b9f62d4` | GCR edit timing instrumentation | LOW |
| `b57292a` | Omni reconnection test fix | LOW |
| `e82ce9b` | Merge commit aggregating all above | — |

---

## 2. Merge Outcome

**Conflicts:** 1 file — `testing/devnet/docker-compose.yml` (port assignments)
**Resolution:** Accepted stabilisation's staggered port scheme, preserved petri env vars (`PETRI_CONSENSUS`)

**Auto-merged cleanly:**
- `src/libs/blockchain/mempool_v2.ts` — TX counting fix integrated
- `src/libs/consensus/v2/PoRBFT.ts` — new `applyTransactions` API already compatible
- `src/libs/network/endpointExecution.ts` — new GCR API adopted
- `testing/devnet/.env.example` — port defaults updated
- `testing/scripts/run-suite.ts` — test infra updates

---

## 3. Petri Code Requiring Adaptation

### 3.1 FIXED: `speculativeExecutor.ts` (CRITICAL)

**File:** `src/libs/consensus/petri/execution/speculativeExecutor.ts`

**Problem:** Was calling old GCR routine API:
```typescript
// OLD — broken after merge
GCRBalanceRoutines.apply(edit, gcrMainRepo, true)
GCRNonceRoutines.apply(edit, gcrMainRepo, true)
GCRIdentityRoutines.apply(edit, gcrMainRepo, true)
```

**Fix applied:** Refactored to use new in-memory pattern:
```typescript
// NEW — uses batch account loading + unified applyTransaction
const accounts = await HandleGCR.prepareAccounts([tx])
const applyResult = await HandleGCR.applyTransaction(accounts, tx, false, true)
```

**Benefits:**
- Consistent with all other GCR callers (L2PS, PoRBFT, endpoint execution, sync)
- Uses batch account loading (fewer DB queries)
- Proper snapshot/rollback support via `applyTransaction` internals
- Handles ALL edit types (not just balance/nonce/identity) through the unified dispatcher

### 3.2 VERIFIED: No Other Petri Files Need Changes

All other GCR callers in the codebase are already using the new API:
- `L2PSConsensus.ts` — uses `prepareAccounts` + `applyTransaction` ✅
- `PoRBFT.ts` — uses `applyTransactions` ✅
- `endpointExecution.ts` — uses `prepareAccounts` + `applyTransaction` ✅
- `Sync.ts` — uses `applyTransactions` ✅

### 3.3 VERIFIED: Port Configuration Consistent

All test/devnet configs verified consistent with the new staggered port scheme across:
- `.env.example` files
- `docker-compose.yml`
- `start-staggered.sh`
- All loadgen and test scripts

---

## 4. Action Plan

### Completed
- [x] Merge stabilisation into petri (transient branch)
- [x] Resolve docker-compose.yml port conflicts (stabilisation priority)
- [x] Fix speculativeExecutor.ts to use new GCR in-memory API
- [x] Verify all GCR callers use new pattern
- [x] Verify port scheme consistency across configs

### Recommended Follow-up
- [ ] **Run full test suite** to validate the merge doesn't break Petri consensus flows
- [ ] **Integration test speculativeExecutor** — the refactored code should produce identical delta hashes as before, but this needs devnet validation
- [ ] **Review `gcr.ts` helper methods** — some utility functions in `src/libs/blockchain/gcr/gcr.ts` still reference `gcrMainRepository` (lines ~579, 620, 716, 815). These appear to be in auxiliary/query paths, not core edit flow, but worth auditing.
- [ ] **Monitor TX counting** — the inverted success/fail fix from stabilisation is now in petri. Petri's forge loop in `petriBlockCompiler.ts` should benefit, but verify mempool metrics are correct after merge.

---

## 5. Key Architectural Insight

The GCR refactor is a **performance-critical change**: instead of N database round-trips per edit, entities are batch-loaded into a `Map<string, GCRMain>`, modified in-memory, and saved once at the end. This directly benefits Petri's continuous forge loop where many TXs are processed per round. The `speculativeExecutor` fix ensures Petri's simulation path also gets this performance improvement.

The TX count inversion bug (`74a4a6e`) was in shared code (`mempool_v2.ts`, `PoRBFT.ts`). Since Petri builds on these same code paths, this fix prevents incorrect transaction classification that could have caused consensus disagreements between nodes.
Loading
Loading