Skip to content

Fix org self-growth loop 500 when employees are already active - #46

Closed
XYAIStudio wants to merge 2 commits into
mainfrom
cursor/fix-org-loop-active-promote-0e68
Closed

XYAIStudio wants to merge 2 commits into
mainfrom
cursor/fix-org-loop-active-promote-0e68

Conversation

@XYAIStudio

@XYAIStudio XYAIStudio commented Sep 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

POST /api/org-module/loop/run crashed with INTERNAL_ERROR 500 when the self-growth loop tried to promote colleagues that were already active (typical on a deployed org, or when the same slug is imported twice). The lifecycle FSM only allows active → shadow|offboard, so _promote's blind active → market step raised ValueError: cannot move active → market.

This change:

  • Walks the happy-path ladder (market → recruit → shadow → active) only along allowed edges.
  • If a colleague is already at/beyond the intended stage (e.g. already active), the step is a skip/noop recorded in the loop proof notes.
  • Illegal pairs never call transition; leftover ValueErrors from the loop are mapped to 400 instead of an opaque 500.
  • Duplicate employee slugs in one run are de-duplicated before promotion.

「运行自增长循环」on an already-deployed org should now complete successfully with skip notes instead of a toast 500.

Target branch

  • Base is develop (feature / fix — default)
  • Base is main (requested for this fix)

Type of change

  • Bug fix

Test plan

  • _promote on an already-active employee succeeds without ValueError and records a skip note
  • _promote on offboard skips illegal transitions instead of raising
  • _promote from shadow still reaches active
  • run_growth_loop succeeds when import leaves employees active
  • Lifecycle FSM helpers (can_transition, already_at_or_beyond) cover active → market
  • i18n note localization for skip strings
  • uv run pytest tests/unit/test_org_loop.py tests/unit/test_lifecycle.py tests/unit/test_org_notes.py tests/unit/i18n tests/e2e/test_org_growth_loop.py — 87 passed
  • uv run mypy --strict on the touched modules — clean
  • Re-run「运行自增长循环」on a tenant whose employees are already active — expect 200 + skip notes, not 500

Checklist

  • Updated CHANGELOG.md
  • README / docs updated (if needed) — not needed
Open in Web Open in Cursor 

cursoragent and others added 2 commits September 17, 2026 12:04
The loop's _promote always tried draft→market→…→active. Colleagues
already at active (or other illegal pairs) raised ValueError and the
API surfaced INTERNAL_ERROR. Skip already-reached and illegal edges,
record them in the proof notes, and map leftover ValueError to 400.

Co-authored-by: XYAI Labs <haoboy8@gmail.com>
Co-authored-by: XYAI Labs <haoboy8@gmail.com>
@XYAIStudio

Copy link
Copy Markdown
Owner Author

Superseded by #47 (includes the active→market loop skip fix).

@XYAIStudio XYAIStudio closed this Sep 17, 2026
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