# WG Paid / MGTS — Working Rules

**Updated:** 2026-08-24  
**Purpose:** minimal normative operating/release rules. This file states what to do, not the historical incidents that taught the rule.

## 1. Source-of-truth model

```text
Latest ZIP
= current working material/source picture

Project Sources
= compact current architecture, plans and operating rules

VM130 retained/public old history
= non-normative historical evidence
```

Before querying a machine for static information, check current Latest and Project Sources first.

## 2. No new mechanism by default

Before creating any helper, oracle, publication path, release path, evidence format, SSH model or gate ordering:

> Prove that the existing accepted canonical mechanism cannot perform the task.

If it can, reuse it.

## 3. Nearest accepted skeleton

Every new STEP starts from the closest accepted workflow-v2 STEP/bundle structure applicable to the same class and touched machine. Do not hand-design a fresh release workflow.

## 4. Minimal delta

Before build, explicitly state:

```text
WHAT CHANGES?
WHAT DOES NOT CHANGE?
WHICH MACHINE OWNS THE CHANGE?
WHAT NEW RISK DOES THIS DELTA INTRODUCE?
```

If scope expands during implementation, stop and reconsider rather than automatically adding work.

## 5. Test only the introduced risk

A STEP tests the risk introduced by its own delta. Already-proven neighboring subsystems are not automatic closure requirements.

Examples:

- auth/UI change does not re-run five-egress recovery;
- selector allocator change does not re-test SMTP/browser onboarding;
- documentation/publication change does not probe runtime machines unless a current dynamic fact is genuinely required.

Use `05_WG_PAID_MGTS_PROVEN_INVARIANTS.md` before adding regression work.

## 6. Read-only machine query filter

Before every production read-only command ask:

> Is this fact dynamic and unavailable/reliably unknowable from current Latest + Project Sources?

Query production only if yes.

Legitimate dynamic examples: current handshakes/counters, current service state, current DB rows, present egress health.

Not legitimate when current source already answers it: script contents, selector mapping, installed project helpers, static config/source structure, release helper behavior.

## 7. STEP classes

- **Class A** — read-only/docs/publication.
- **Class B** — source/config/security/runtime change without intended business DB mutation.
- **Class C** — live business DB mutation; encrypted non-public backup and explicit `PERSIST` or `RESTORE` contract required.
- **Class D** — network/reboot/long-running; detached/snapshot/long-test rules apply.

Intended trusted production rows use `PERSIST`; do not restore them merely because synthetic Class C tests used `RESTORE`.

## 8. Bundle/delivery contract

- one canonical STEP ZIP;
- main launch/bootstrap block inline in chat, not separate `.txt`;
- `installer.sha256` digest-only;
- workflow-v2 fields/layout exactly as accepted by current VM130 tools;
- `tests/exact-worker.sh` and mandatory fixture contract where required;
- final delivered ZIP bytes must pass the applicable current gates before delivery.

## 9. Final-byte gate

On the exact ZIP handed to the user:

```text
ZIP SHA
-> independent extract
-> manifest verify
-> router-release-contract
-> mandatory fixtures/exact-worker
-> bundle gate / R17
-> R19 policy
-> R20 policy
-> applicable static/syntax/selftests
```

Then user-side VM130 `router-step-bootstrap --verify-only` is the authoritative environment gate before mutation.

## 10. Mutation/core boundary

Before core acceptance, rollback may restore according to the STEP contract.

After authoritative core/runtime/source state is accepted, a late reporting/publication/finalization failure is:

```text
STOP + CONTINUATION_REQUIRED
```

not automatic rollback of the accepted core.

Continuation begins from actual accepted state; never replay an obsolete mutation revision merely to obtain a clean report.

## 11. Machine Git/source close

For touched managed source:

```text
live managed source
-> Machine Git validation
-> commit
-> push GitHub main
-> remote verify
-> VM130 independent HTTPS checkout
-> exact commit/tree/file-count verify
-> Git archive from downloaded checkout
-> canonical source publication
-> Latest
```

Do not substitute live-machine tar or local-only mirror for the canonical GitHub roundtrip.

## 12. PASS/STOP closure

Every accepted STEP and every genuinely started STOP that produced execution evidence must use the existing canonical finalization path and end with applicable report/evidence plus fresh complete Latest + SHA256.

A pre-start transfer/verify-only rejection with no execution evidence does not need a fake STOP publication.

Preserve the original failure RC; rollback/finalization success must never turn a failed installer into exit 0.

## 13. Incoming/retention hygiene

`/home/ops/incoming` is a working queue, not history.

Canonical retained locations:

```text
/opt/router-ops/state/retained-step-zips/<STEP>/<SHA256>.zip
/opt/router-ops/state/retained-latest/<LATEST_SHA256>/WG_PAID_MGTS_LATEST_<timestamp>.zip
```

Do not require an old Latest to remain in incoming. Historical proof binds to retained immutable bytes/SHA, not ephemeral `.unpack-*` or rotating `/latest/` URLs.

## 14. Publication/history rule

`reports.secret-studio.ru/latest/` is moving current publication, not a durable historical locator. Historical project/source snapshots belong on VM130 in immutable old/retained storage and are explicitly non-normative.

Do not copy long history back into active Project Sources.

## 15. Remote scripting

- avoid fragile nested shell/SQL quoting;
- use quoted heredoc/stdin-safe transport or versioned worker files;
- use `ssh -n` for nested OpenWrt SSH where outer stdin matters;
- with `pipefail`, avoid `head -1` SIGPIPE traps; prefer `sed -n '1p'`;
- expected HTTP statuses such as `202` are not judged solely by BusyBox `wget` RC.

## 16. Secrets/public boundary

Never print/publish raw passwords, private keys, PSKs, magic tokens or private credential material for proof.

Secrets do not belong in chat, Git, bundle payloads, reports, Project Sources or Latest. Prove path/owner/mode/boundary/authenticated behavior instead.

Class C DB backups are encrypted and non-public.

## 17. Public/auth boundary

- public access proxy exposes intended auth/account routes only;
- `/v2/admin/*` and `/v2/agent/*` remain non-public;
- magic token travels in URL fragment, browser clears history/address before consume request;
- monitoring probes are read-only unless the STEP explicitly tests mutation;
- DDN/external witness is used only where true public-path risk requires it.

## 18. Network/provider invariants

- provider endpoint exact IP:port is not stable; verify structure/alignment instead;
- snapshot name length <=40, prefer <=32, validate before VM stop;
- already-proven R20Q-S zero-healthy recovery is not casually repeated.

## 19. New-chat anti-drift

Start from:

```text
00 current state
-> 01 architecture/machines
-> 03 local plan
-> current Latest
-> exact touched-machine source if a change is actually being designed
-> 04 working rules + 05 proven invariants
```

Do not design a STEP before current state and ownership are clear.
