Store the person uuid the master issues, so renames keep our identity

The welcome now carries a personId; it lands in the instance_id setting
and rides on every hello and HTTP report from then on. The master keys
the person by that uuid, so changing instance_name moves our history to
the new name instead of starting a stranger. Read-only in Settings on
purpose — editing it by hand would detach this machine from its person.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Brandon Li
2026-09-02 12:07:25 -05:00
co-authored by Claude Fable 5
parent de9cbffd83
commit a088381749
6 changed files with 39 additions and 5 deletions
+9 -1
View File
@@ -15,7 +15,7 @@
* master you control, and prefer https so it cannot be redirected in transit.
*/
import { getSetting, getInstruments, getRunnerHeartbeat, RUNNER_TIMEOUT_MS } from './db';
import { getSetting, setSetting, getInstruments, getRunnerHeartbeat, RUNNER_TIMEOUT_MS } from './db';
import { runTrade, startScheduler, stopScheduler, getSchedulerStatus } from './auto-trade';
import { FIRMS, automationKey } from './automations';
import { POINT_VALUES } from './trading-logic';
@@ -217,9 +217,14 @@ function connect() {
s.ready = false;
socket.addEventListener('open', () => {
// The stored uuid, once the master has issued one — it, not the name,
// is who this instance is, so renaming instance_name keeps the same
// person (and their accounting history) on the master.
const instanceId = getSetting('instance_id');
socket.send(JSON.stringify({
type: 'hello',
instance,
id: instanceId || undefined,
capabilities: collectCapabilities(),
} satisfies InstanceMessage));
});
@@ -235,6 +240,9 @@ function connect() {
if (msg.type === 'welcome') {
s.ready = true;
s.attempt = 0;
if (msg.personId && msg.personId !== getSetting('instance_id')) {
setSetting('instance_id', msg.personId);
}
console.log(`[master-link] connected to ${url} as "${instance}"`);
return;
}