Skip to content

Add moving mob singleton audit cleanup - #227

Merged
Mattie merged 6 commits into
masterfrom
codex/moving-mob-singleton-audit
Jun 23, 2026
Merged

Add moving mob singleton audit cleanup#227
Mattie merged 6 commits into
masterfrom
codex/moving-mob-singleton-audit

Conversation

@Mattie

@Mattie Mattie commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary

Adds guarded audit and cleanup tooling for moving mob singleton drift, then hardens dryad and Zar runtime movement so stale room-object copies do not accumulate again.

Changes

  • Add kyrgame.moving_mobs audit/cleanup service for dryad object 45, Zar/dragon object 52, and tracker-only brownie/elf state.
  • Add backend CLI and root wrapper for audit, cleanup dry-run, and confirmed cleanup apply.
  • Harden dryad movement to re-anchor from the real source room, normalize duplicates, and emit audit telemetry on drift.
  • Harden Zar startup and relocation placement to remove stale dragons outside the active tracker/destination room.
  • Extend /admin/mobs with backward-compatible singleton diagnostics.
  • Block admin item drops for singleton moving mob objects 45 and 52.
  • Update the porting plan checklist.

Motivation & Context

Intent

Admins need a safe way to inspect and repair moving mob singleton drift without racing the scheduler or manually editing room object arrays. Dryad had accumulated many persisted copies in live data, so this change adds explicit diagnostics, a confirmation-token cleanup flow, and runtime guards to prevent re-orphaning.

Context

  • Issue / ticket: none
  • Legacy parity / constraints / related work:
    • Zar and dryad behavior remains anchored to legacy animation routines in legacy/KYRANIM.C.
    • Runtime tracker state is treated as authoritative for canonical moving mob location.
    • Cleanup is explicit and confirmation-gated; ordinary startup does not silently repair historical dryad copies.

Legacy code being ported

  • Source (legacy) locations:
    • legacy/KYRANIM.Cinianm, chkzar, rmvzar, pzinlc, dryads
  • New locations:
    • backend/kyrgame/world/animation_tick_system.pyZarDragonRoutine, DryadWanderRoutine
    • backend/kyrgame/moving_mobs.py — audit and guarded cleanup service
    • backend/kyrgame/scripts/audit_moving_mobs.py — backend CLI
    • tools/mob_audit.py — repo-root wrapper
  • Intentional differences from legacy behavior:
    • Runtime guards remove stale singleton copies when tracker/object state drifts, instead of allowing duplicate dryads/dragons to persist.
    • Admin drops of singleton moving mob objects are rejected and routed to the audit/cleanup tool.
  • Known missing pieces / follow-ups:
    • Continue watching moving mob audits through longer live scheduler windows after merge.

Testing

  • cd legacy && make -f ELWKYR (Worldgroup build)
  • .venv\Scripts\python.exe -m pytest backend\tests\test_moving_mob_audit.py backend\tests\world\test_animation_tick_system.py backend\tests\world\test_animation_tick_runtime_bridge.py backend\tests\test_runtime_tick_scheduler.py backend\tests\test_admin_endpoints.py
  • cd backend && python -m kyrgame.scripts.package_content --output ../legacy/Dist/offline-content.json
  • .venv\Scripts\python.exe tools\mob_audit.py --help
  • git diff --check

Details:

  • Targeted backend suite: 75 passed.
  • Live repair completed with backend stopped, a verified Postgres backup, cleanup dry-run, confirmed cleanup apply, and post-restart audits.
  • Latest live audit after scheduler movement: dryad copy_count=1, Zar/dragon copy_count=1, both tracker-aligned with singleton_status=ok.
  • Backup: .local-backups/postgres/kyrgame-local-20260622-120843.dump
  • Latest audit snapshot: .local-backups/moving-mobs/audit-final-latest-20260622-121608.json

Manual E2E Demo Checklist

  • Start backend and frontend.
  • Run python -m kyrgame.scripts.audit_moving_mobs audit --format table and confirm dryad/Zar each show one copy and ok.
  • Visit the admin mob tracker and confirm dryad/Zar diagnostics include copy count, object rooms, tracker room, and singleton status.
  • Try to admin-drop dryad or object 45 and confirm the request is rejected with guidance to use the audit/cleanup tool.
  • Wait through at least one dryad tick and one Zar relocation opportunity, then re-run audit to confirm no orphan copies appear.

Risk & Rollback

  • Risk level: medium
  • Rollback plan:
    • Revert this PR to remove the CLI/admin/runtime changes.
    • For live data, restore from the verified .local-backups/postgres/kyrgame-local-20260622-120843.dump backup if the cleanup needs to be undone.

UI Changes

  • Screenshots / description:
    • No visual UI changes. Admin mob tracker JSON now includes additional singleton diagnostic fields.

@Mattie
Mattie marked this pull request as ready for review June 22, 2026 19:36
@Mattie
Mattie requested a review from Copilot June 22, 2026 19:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5be3e459dd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/kyrgame/moving_mobs.py
Comment thread backend/kyrgame/moving_mobs.py Outdated
Comment thread backend/kyrgame/world/animation_tick_system.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds moving-mob singleton audit/cleanup tooling and runtime safeguards to detect and prevent dryad/Zar (dragon) room-object drift, and surfaces diagnostics through admin endpoints and a CLI wrapper.

Changes:

  • Introduces kyrgame.moving_mobs audit + confirmation-gated cleanup flow, plus a backend CLI (kyrgame.scripts.audit_moving_mobs) and repo-root wrapper (tools/mob_audit.py).
  • Hardens runtime movement: dryad re-anchors when tracker origin is missing and emits drift audit telemetry; Zar initialization/relocation clears stale dragons outside the active room.
  • Extends /admin/mobs with singleton diagnostics and blocks admin drops of singleton mob objects (45/52); adds focused tests.

Manual E2E Demo Checklist

  • Run python -m kyrgame.scripts.audit_moving_mobs audit --format table and confirm dryad/Zar each show copy_count=1 and singleton_status=ok.
  • Visit /admin/mobs and confirm singleton fields (copy count, object_rooms, tracker_room_id, singleton_status) populate for dryad/Zar.
  • Attempt admin-drop of dryad / object 45 (and Zar/dragon 52) and confirm it is rejected with guidance to use the audit/cleanup tool.
  • Wait through at least one dryad tick and one Zar relocation opportunity, then re-run audit to confirm no orphan copies appear.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/mob_audit.py Adds repo-root wrapper that imports and runs the backend audit/cleanup CLI.
docs/PORTING_PLAN.md Checks off the moving-mob singleton audit/cleanup work in the porting plan.
backend/tests/world/test_animation_tick_system.py Adds coverage for dryad re-anchoring drift handling and stale-dragon removal during Zar init/relocation.
backend/tests/test_moving_mob_audit.py Adds end-to-end tests for audit output, dry-run vs confirmed apply, and wrapper import behavior.
backend/tests/test_admin_endpoints.py Extends /admin/mobs assertions for singleton diagnostics and verifies admin-drop rejection for singleton mobs.
backend/kyrgame/world/animation_tick_system.py Implements dryad re-anchoring + drift audit events; adds Zar stale-dragon cleanup and room-id enumeration support.
backend/kyrgame/webapp.py Replaces ad-hoc room scanning with moving_mobs audit for admin diagnostics; blocks singleton mob drops.
backend/kyrgame/scripts/audit_moving_mobs.py Adds CLI entrypoint for audit and confirmation-gated cleanup with table/json output.
backend/kyrgame/runtime.py Wires room-id enumeration into animation routines to support drift cleanup/hardening.
backend/kyrgame/moving_mobs.py New audit/cleanup service defining singleton mob specs, proposed cleanup changes, and confirmation tokens.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/kyrgame/scripts/audit_moving_mobs.py Outdated
Comment thread backend/kyrgame/moving_mobs.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b894719cd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/kyrgame/moving_mobs.py Outdated
Comment thread backend/kyrgame/world/animation_tick_system.py
@Mattie Mattie changed the title [codex] Add moving mob singleton audit cleanup Add moving mob singleton audit cleanup Jun 23, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 526b2c49d0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/kyrgame/moving_mobs.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread backend/kyrgame/webapp.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b854d3ee9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/kyrgame/moving_mobs.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread backend/kyrgame/runtime.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c47061e390

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/kyrgame/moving_mobs.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Comment thread backend/kyrgame/world/animation_tick_system.py
Comment thread backend/kyrgame/scripts/audit_moving_mobs.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

@Mattie
Mattie merged commit 1a28e68 into master Jun 23, 2026
1 check passed
@Mattie
Mattie deleted the codex/moving-mob-singleton-audit branch June 23, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants