Skip to content

fix: keep guild spec order and refresh the manager row on relaunch (0.8.1) - #77

Merged
milliondreams merged 5 commits into
rustic-ai:mainfrom
milliondreams:fix/guild-store-0.8.1
Nov 28, 2026
Merged

milliondreams merged 5 commits into
rustic-ai:mainfrom
milliondreams:fix/guild-store-0.8.1

Conversation

@milliondreams

Copy link
Copy Markdown
Contributor

Fixes two bugs found while testing Rustic Studio on Forge 0.8.0, and bumps the version to 0.8.1.

Guilds launched from a client lost their spec order

Bootstrap built the stored guild by hand instead of through the store's mapper. So the position and spec_data columns added in 0.8.0 for rusticai-core 1.5 were never set on this path. Every guild launched from Studio or the API was stored with all agents and routes at position 0, and read back in ID order instead of spec order. The guild row also had no spec_data.

  • buildModels now uses store.FromGuildSpec, as the manager API's ensure path already does.
  • Bootstrap finishes the spec before building the rows: it settles the guild ID, rewrites default agent IDs and derives the state manager config first, so the stored spec_data matches what is launched.
  • FORGE_STATIC_GUILD_ID now applies to the spec itself. It only set the stored guild's ID, so the spawned manager and the agent IDs still used the authored ID. This matches what the docs already said.

Guilds already stored keep their rows. Ones with every position at 0 read back in ID order, which is also what rusticai-core does after its migration.

Relaunching a guild logged a 409 from the guild manager

Every relaunch logged:

manager api POST /manager/guilds/<id>/agents/ensure failed (409): agent id already exists with a different specification

This predates 0.8.0; it is also in logs from 0.7.5.

Cause: the guild manager registers its own row with ensure_agent, and its spec always differs on a relaunch. Its properties hold the manager API address, which changes whenever Forge gets a new port (Studio picks one on each launch). They also hold the guild spec it was spawned with, which a relaunch rebuilds from the stored rows.

Effect: the 409 aborted launch_guild_agents before it marked the guild STARTING and before it sent the first health report.

Changes:

  • When the guild's own manager ensures an existing row, Forge updates the row, keeping its position and status. Every other agent still gets 409 for a changed spec, including one that reuses the manager's ID with a different class.
  • The manager's row never stores manager_api_token. The guild API returns stored agent specs, so the token was readable by anyone who could read the guild. Each spawn passes the token from Forge's environment, so nothing needs the stored copy.
  • The manager is spawned with a guild spec that leaves itself out. A relaunch rebuilds that spec from the stored rows, which include the manager's own row. With the row now refreshed, each relaunch would otherwise nest the previous manager spec one level deeper.

Rows written by earlier versions are rewritten correctly on their next relaunch.

Also included

  • The TestRaftElector_Failover fix. The 0.8.0 release run failed on this test, which fails about 1 in 30 runs, before and after the raft 1.8.0 upgrade.
    • Cause: the test shut the leader down once the leader's own configuration listed all voters, but one follower could still hold an older configuration. Raft rejects votes from candidates outside a node's own configuration, so no node could win the election.
    • Fix: the test now waits until every node lists all voters.
    • Check: it passed 60 of 60 runs.
  • Version 0.8.1 in version.go, pyproject.toml, uv.lock and the TypeScript client.

Testing

  • New tests:
    • Bootstrap keeps the spec order, mark_forwarded and spec_data (with IDs that sort opposite to the spec, so ID order can't pass).
    • FORGE_STATIC_GUILD_ID reaches the spawned manager and the agent IDs.
    • The manager's row is refreshed without its token, keeping position and status.
    • Other agents, and a manager ID with the wrong class, still get 409.
    • The manager's spawned guild spec leaves the manager out.
  • The refresh and token tests fail against the old handler.
  • go test ./... passes, and golangci-lint 2.15.0 reports 0 issues.
  • The Python contract tests (pytest tests/contract) pass.
  • Rustic Studio, run on this build against a Forge home that has guilds from 0.7.5 and 0.8.0, through three restarts on new ports:
    • There were no 409s, and every guild reached running and replied.
    • Each manager row has the current address and no token, and its size stays the same across relaunches.
    • A newly launched UI Component Demo App stores its agents and routes in blueprint order, and all 16 component types render.

TestRaftElector_Failover shut the leader down once the leader's own
configuration listed all three voters. A configuration change commits
once a majority has it, so one follower could still hold the older
configuration without the third node. Raft rejects votes from
candidates outside a node's own configuration, so neither remaining
node could win an election and the test timed out. It failed about
1 in 30 runs, before and after the raft 1.8.0 upgrade.

Wait until every node's configuration lists all voters instead.
Bootstrap built the stored guild by hand instead of through the
store's mapper, so the position and spec_data columns added for
rusticai-core 1.5 were never set on this path. Every guild launched
from a client was stored with all agents and routes at position 0,
read back in ID order rather than spec order, and kept no spec_data
on the guild row.

- Build the rows with store.FromGuildSpec, as the manager API's ensure
  path already does.
- Finish the spec before building them: settle the guild ID, rewrite
  default agent IDs and derive the state manager config first, so the
  stored spec_data matches what is launched.
- Apply FORGE_STATIC_GUILD_ID to the spec itself. It only set the
  stored guild's ID, so the spawned manager and agent IDs still used
  the authored ID.

Guilds already stored keep their rows; ones with every position at 0
read back in ID order, as rusticai-core does after its migration.
Every relaunch of a guild logged "manager api POST .../agents/ensure
failed (409): agent id already exists with a different specification".
The guild manager registers its own row with ensure_agent, and its spec
always differs from the stored one on a relaunch: its properties carry
the manager API address, which changes whenever Forge gets a new port
(Rustic Studio picks one on each launch), and the guild spec it was
spawned with, which a relaunch rebuilds from the stored rows. The 409
aborted launch_guild_agents before it marked the guild starting and
sent its first health report.

- When the guild's own manager agent ensures an existing row, update
  the row to the new spec, keeping its position and status. Every other
  agent still gets 409 for a changed spec, including one that reuses
  the manager's ID with another class.
- Never store manager_api_token in the manager's row. The guild API
  returns stored agent specs, and each spawn passes the token from
  Forge's environment, so nothing needs the stored copy. Rows that
  already hold it are rewritten without it on the next relaunch.
A relaunch spawns the guild manager with a guild spec rebuilt from the
stored rows, and those include the manager's own row. So the manager's
guild_spec property held the previous manager spec, which held its own
guild_spec. With the manager's row now refreshed on each relaunch, the
spec would gain a level of nesting every time.

Build the manager's spawn request from the guild spec without the
manager agent. Rows that already nest an older spec are rewritten
without it on the next relaunch.
@milliondreams
milliondreams merged commit 87e89da into rustic-ai:main Nov 28, 2026
13 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