debug-orchestration
Skill4 starsChanged 9 months agoMITView on GitHub
Diagnose and fix nondeterminism errors in the duroxide orchestration. Covers the replay model, common violations, and how to audit orchestration code for determinism.
- Reads credentials
In this repository22 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- duroxide-orchestration-versioningSkill
- add-activitySkill
- add-eventSkill
- add-testSkill
- add-toolSkill
- agent-versioningSkill
- azure-ps-test-runner-vmSkill
- debug-testSkill
- horizondb-idiosyncrasiesSkill
- horizon-facts-eval-sweepSkill
- investigate-duroxide-runtimeSkill
- pilotswarm-aks-deploySkill
- pilotswarm-aks-resetSkill
- pilotswarm-new-env-deploySkill
- pilotswarm-perfSkill
- pilotswarm-portal-app-regSkill
- pilotswarm-portal-auth-assignmentsSkill
- pilotswarm-releaseSkill
- pilotswarm-tuiSkill
- pilotswarm-vpn-client-profileSkill
- schema-migrationSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
If the issue is about live worker routing, session-affined activity placement, hydration/dehydration traces, or cross-pod runtime evidence …
- Distinctive: line 21
If they don't match → nondeterminism error → orchestration fails.
- Distinctive: line 95
If you see pods in an unexpected namespace or from a different ReplicaSet, that's the culprit.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Debug Orchestration Nondeterminism
If the issue is about live worker routing, session-affined activity placement, hydration/dehydration traces, or cross-pod runtime evidence rather than replay-safe code shape, use the sibling skill .github/skills/investigate-duroxide-runtime/SKILL.md.
Duroxide replays the orchestration generator from the beginning on every new event. The generator must produce the exact same sequence of yielded actions during replay as during original execution. A mismatch causes:
nondeterministic: custom status mismatch: action=CallActivity { ... } vs event=CustomStatusUpdated { ... }How replay works
- Duroxide stores every action (yield) result in a history log.
- On replay, it feeds stored results back into the generator at each
yield. - It compares each yielded action descriptor with the stored history event.
- If they don't match → nondeterminism error → orchestration fails.
setCustomStatus() is also recorded in history as CustomStatusUpdated. It's fire-and-forget (no yield), but its position relative to yields matters.
Diagnosis steps
- Read the error message carefully. It tells you:
- What the orchestration tried to do (
action=CallActivity { name: "X" }) - What the history expected (
event=CustomStatusUpdated { ... })
- What the orchestration tried to do (
- Find the divergence point. The orchestration took a different code path during replay. Look for:
Date.now()used in a condition before a yield orsetCustomStatus()Math.random()orcrypto.randomUUID()in control flow- Any I/O (fetch, fs, database) done directly in the generator
setCustomStatus()that moved relative to a yield
- Trace the yield sequence. Number every
yieldandsetCustomStatus()call inorchestration.ts. During replay, the Nth yield must match the Nth history event.
Common bugs and fixes
| Bug | Fix |
Date.now() in condition before yield | Use yield ctx.utcNow() — deterministic, replay-safe |
Math.random() for IDs | Use yield ctx.newGuid() |
| Direct I/O in generator | Wrap in an activity (ctx.scheduleActivity()) |
setTimeout / setInterval | Use yield ctx.scheduleTimer(ms) |
setCustomStatus() order changed | Ensure it appears at the same position relative to yields |
| Redeployed with changed yields | Freeze the released handler and register a new orchestration version. Deploys never reset the database. |
Deterministic alternatives
| Non-deterministic | Deterministic equivalent |
Date.now() | yield ctx.utcNow() |
new Date() | yield ctx.utcNow() (returns ms, wrap with new Date(ms) if needed) |
Math.random() | yield ctx.newGuid() |
crypto.randomUUID() | yield ctx.newGuid() |
setTimeout(fn, ms) | yield ctx.scheduleTimer(ms) |
fetch() / any I/O | yield ctx.scheduleActivity("name", input) |
The setCustomStatus trap
setCustomStatus() doesn't require a yield, but duroxide records it as a CustomStatusUpdated event in the history. This means:
// Original execution: condition is false → no activity yield → setCustomStatus
if (Date.now() > threshold) { // ← non-deterministic!
yield someActivity(); // recorded as CallActivity
}
setStatus("idle"); // recorded as CustomStatusUpdated
// Replay: condition is NOW true → activity yield → mismatch!
// Replay expects CustomStatusUpdated but gets CallActivityThe fix: use yield ctx.utcNow() for any time-based branching.
Runaway / leaky deployments
A very common cause of nondeterminism is old workers from a previous deployment still running in the same cluster, connected to the same database. This happens when:
- A previous deployment used a different Kubernetes namespace (e.g.
copilot-sdkvscopilot-runtime) and was never cleaned up. - A rolling update left old ReplicaSet pods running alongside new ones during the transition.
- Manual
kubectl runor port-forward sessions left orphaned pods polling the same database.
Old workers run old orchestration code but process orchestrations that were started (or replayed) by the new code. The yield sequences differ → nondeterminism error.
Diagnosis
# Check ALL namespaces for worker pods — not just the expected one
kubectl get pods --all-namespaces -l app.kubernetes.io/component=worker --no-headersIf you see pods in an unexpected namespace or from a different ReplicaSet, that's the culprit.
Fix
# Delete the old deployment and namespace
kubectl delete deployment copilot-runtime-worker -n <old-namespace>
kubectl delete namespace <old-namespace> --wait=false
# Reset the database to clear any tainted history
NODE_TLS_REJECT_UNAUTHORIZED=0 node --env-file=.env.remote scripts/db-reset.js --yes
# Restart current workers
kubectl rollout restart deployment/copilot-runtime-worker -n copilot-runtimeAfter fixing
- Reset the database — existing orchestrations have stale history:
NODE_TLS_REJECT_UNAUTHORIZED=0 node --env-file=.env.remote scripts/db-reset.js --yes - Redeploy — or use the full deploy script:
./scripts/deploy-aks.sh
Key files
- src/orchestration.ts — the orchestration generator (audit this for determinism)
- src/session-proxy.ts — activity definitions (safe — activities run outside replay)
- scripts/deploy-aks.sh — deploy with DB reset
- scripts/db-reset.js — standalone DB reset
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

