Skip to content

Opt-in job switching for workers who can't work - #126

Merged
Adiezc merged 1 commit into
mainfrom
feat/job-switching
Nov 27, 2026
Merged

Adiezc merged 1 commit into
mainfrom
feat/job-switching

Conversation

@Adiezc

@Adiezc Adiezc commented Nov 27, 2026

Copy link
Copy Markdown
Owner

What and why

D3: smiths go broke and never work again, so most baseline seeds lock into high tool prices with a few NPCs permanently hungry. Loans (#124) get broke workers back to work, but at normal prices the market only supports four or five of the eight smiths, so the rest stay in debt with no exit. This adds that exit.

Job switching, opt-in ([mobility] enabled = true). Each day, before anyone works, an NPC in a mobile trade (farmer, miner or blacksmith by default) that has produced nothing for 20 days moves to the trade whose members actually earn the most. "Earn" means the median of members' realised income over 30 days, scaled to the mover's skill. It moves only if that beats its own realised income by 1.5 times and by at least 5 coin a day.

Safeguards:

  • at most one move a day, the worst-off first, then a 60-day cooldown;
  • nobody moves while they're a beneficiary of a live contract, because contracts are pooled by guild.

A move keeps the NPC's coin, goods and traits, brings stock left at the old site home, and switches guild. The new guild buys any outstanding loan from the old one in coin; if it can't afford to, the NPC stays put. Professions and sites go into the state hash only while switching is on, so existing hashes are unchanged. TickStats.moves records every move. Combining switching with land claims is refused by the config, because claims belong to the gatherers who worked them at the start.

Policy files: job_switching.toml, and job_switching_and_loans.toml, which extends the loans policy. mobility. is added to the rules a policy may change.

Results (10 seeds × 1,500 days, averaged from day 365)

Off Loans Switching Both
Tools price (base 24) 37.1 19.7 29.0 20.5
Seeds within ±40% of base, second year / late 4 / 3 10 / 10 8 / 8 10 / 10
Ore output a day 13.4 16.6 15.8 17.5
NPCs hungry 3.7 3.2 0.1 0.1
Coin Gini 0.50 0.27 0.33 0.22

Switching makes about 4 moves a run: the stranded smiths become farmers. The NPCs who were permanently hungry were those smiths. It doesn't fix D1: the 20-day trigger is slow next to the 120-day mine disaster, and the ore glut is unchanged.

Two earlier designs failed, and both are documented in docs/VALIDATION.md D3:

  1. Comparing prices. Expected income at current prices, open to any worker, let farmers chase tool prices into smithing, fail to afford ore, and leave again: about 400 moves a run, and hunger rose to 21.8.
  2. Comparing earnings, but letting working NPCs move. Miners left over short unsold-stock pauses, and ore output collapsed to about 1 a day.

Only letting NPCs who can't work move made it stable.

Design review (Claude Fable 5.2 subagent). It found that my first trigger could only ever drain smiths, and that it compared crafting and gathering on biased terms. It also listed the couplings a mid-run profession change touches, each handled here:

  • the state hash didn't include profession or site;
  • stock left at the old site would be stranded;
  • loan debt would end up owed to the wrong guild;
  • guild-pooled contracts could list a member twice;
  • land claims are tied to the original gatherers.

Also fixes D3's "off" row, which said 2 of 10 seeds stay near base. Measured the same way as the other rows, it's 4 of 10 in the second year and 3 of 10 late.

How it was tested

New tests/unit/test_mobility.py:

  • off by default, with no professions in the hash;
  • every move clears both bars against the NPC's realised income, and there's at most one move a day;
  • after moves, every NPC's guild, site and site account match its trade, and guild member lists are sorted and consistent;
  • a switching world replays to the same hash, and every contract rebuilds (audit);
  • settings round-trip, and guard/merchant or claims combinations are refused;
  • the shipped scenarios leave it off;
  • (slow) the combined policy keeps tools near base and hunger below 1 on seeds 1 to 5.

Full suite: 413 passed, 1 skipped, 3 xfailed. mypy, ruff and bandit are clean. questless diff --base main shows no change, and the golden hashes are unchanged.

Checklist

  • Linked to an issue or a build-guide task (follows VALIDATION D3; no issue)
  • Tests added or updated, and they fail without the change (I ran them against main and saw them fail)
  • This is my only open pull request, and the issue is my only claim
  • uv run ruff check . and uv run ruff format --check . pass
  • uv run pytest passes (including the guarantee tests)
  • uvx bandit -r src app experiments -ll reports no medium or high findings
  • No secrets, personal data or real player data added
  • Docs updated if behaviour changed (VALIDATION, CHANGELOG, module docs)
  • AI tools used (if any) are named here, and I can explain every line: Claude Code (Claude Opus 5.5), design reviewed by a Claude Fable 5.2 subagent

🤖 Generated with Claude Code

An NPC in a farming, mining or smithing job that has produced nothing for
20 days moves to the trade whose members actually earn the most (median
realised income over 30 days, scaled to its skill), if that beats its own
by 1.5x and 5 coin a day. One move a day, 60-day cooldown, nobody moves
while on a live contract. A move keeps coin, goods and traits, brings site
stock home and changes guild; the new guild buys any loan.

Over 10 seeds x 1,500 days the stranded smiths of D3 become farmers (about
4 moves a run): hunger 3.7 -> 0.1; with loans too, tools stay near base on
10/10 seeds and the Gini falls 0.50 -> 0.22. Off by default; doesn't fix
D1; refuses to combine with land claims.

Two earlier designs churned (farmers chasing tool prices) or collapsed
mining (miners leaving over short pauses); both are documented. Design
reviewed by a Claude Fable 5.2 subagent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Economy impact (10 seeds × 6 scenarios, against origin/main)

No significant change in any metric.

Every metric that moved

Nothing moved: every metric is identical on every seed.

Runs are paired by seed. A change is significant when it is more than 2 standard errors from zero and at least 3% of the base. Generated by questless diff.

@Adiezc
Adiezc merged commit 2a0fa19 into main Nov 27, 2026
7 checks passed
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.

1 participant