Skip to content

feat: sleep mode (stop when empty, start when someone joins) - #3

Merged
codebyant merged 6 commits into
developfrom
feat/sleep-mode
Dec 2, 2026
Merged

codebyant merged 6 commits into
developfrom
feat/sleep-mode

Conversation

@codebyant

Copy link
Copy Markdown
Owner

Summary

Sleep mode per server, with two independent options the owner sets through a signed server.update_settings:

  • Stop when empty (auto_stop_minutes): the agent pings the server every 30 s and stops it after N minutes with nobody online. An unknown player count never counts as empty.
  • Start when someone joins (wake_on_join: off, anyone, whitelist): while the server is stopped, the agent answers its port with the start of the Minecraft protocol. The server list shows the cached status (icon, version, mod list) with a "sleeping" MOTD; a login gets a disconnect with the owner's text and starts the server. whitelist only wakes for names in whitelist.json (case-insensitive, no online lookup).

Protocol

  • server.update_settings accepts sleep; server.settings.updated carries it.
  • server.status.result adds sleep, sleeping, sleep_error, last_boot_ms, whitelist_count.
  • server.status.changed adds optional sleeping and sleep_error.
  • Audit entries add optional trigger (idle_stop, wake_on_join, wake_limited) and player; automatic actions use the agent's own id as account.
  • host.info.features adds sleep_mode.
  • Error codes: port_in_use, port_shared, start_failed, wake_limited (3 wakes in 10 minutes stop further wakes for the rest of the window; manual Start still works).

Security

  • The listener is the one documented exception to "the agent never opens an inbound port" (AGENTS.md updated). src/sleep/inbound-scope.test.ts fails if any other file listens.
  • It only binds the port and server-ip of one of the agent's own servers, only while it is stopped and wake_on_join is on. It speaks handshake, status, ping and login start, nothing else. The only effect of a login is starting that server.
  • Hard limits: 10 s per connection, 32 connections, 8 per address, 4096 bytes per packet, 16 KiB buffer, VarInt ≤ 5 bytes, name ≤ 16, address ≤ 255. The disconnect text is built with JSON.stringify. Client addresses are never logged.
  • Settings and the status cache live in <state>/sleep/ (0700/0600), out of reach of the server process; whitelist.json and server.properties are read with openBeneath and size limits.
  • Every start passes through beforeStart, which closes the listener before systemd starts the unit.

Validation

  • bun run lint, bun run typecheck, bun run test (703 pass), bun run build, bun run check:lib.
  • Fake-client tests for the listener: status, ping/pong, login → disconnect, whitelist refusal, transfer, legacy 0xFE ping, timeouts, size and connection limits, split frames, bind conflicts.
  • Lib tagged v1.2.0-alpha.1 for consumers.

Manual testing (pending)

End-to-end on a real machine with vanilla and Forge/NeoForge servers through a playit tunnel, before merge. Draft until then.

@codebyant
codebyant marked this pull request as ready for review December 2, 2026 17:51
@codebyant
codebyant merged commit 70abd65 into develop Dec 2, 2026
2 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