Repository navigation
fix(accounts): keep tg accounts switch when config.json sets activeAccount - #63
Merged
Merged
Conversation
neoromantic
force-pushed
the
fix/per-account-cache-17
branch
from
October 22, 2026 09:48
66cb137 to
3c13b0f
Compare
Every command except tg config and tg skill makes the account named by activeAccount in config.json active at startup. tg accounts switch only changed data.db, so with the key set the switch lasted one command and the next one read the configured account's cache again. The switch now writes the new ID to activeAccount when the key is set and differs, before it touches data.db, so a config.json that can't be read or written fails the switch with nothing changed. Without the key config.json is not created and data.db alone holds the active account. -q/--quiet returned from the root setup before that startup step, unlike --format quiet, so a quiet command could use another account and skip the config check. It now runs the same step. Fixes #61 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…json The read-only test checked "changes nothing" with tg chats list, but that command's start makes activeAccount 1 active again, so it passed even when the failed switch had already written account 2 to data.db. Reading the active account straight from data.db before any other command makes the test fail if the switch updates data.db before config.json. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The root setup took the first argument without a leading dash as the subcommand, so in `tg -f pretty config set activeAccount 1` it saw "pretty", ran the strict config.json check and failed with INVALID_ARGS: tg config could not repair an invalid file with a spaced format flag, and tg skill failed on it. It now skips the value of -f/--format, as citty does when it picks the subcommand. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The startup step rethrew a read error such as EACCES, so every command except tg config and tg skill printed a Bun stack trace with no JSON error. Since -q now runs that step too, tg -q <command> crashed the same way. The read error is now a GENERAL_ERROR with details.path, and -q prints nothing. The Runtime Behavior docs said tg accounts switch fails with INVALID_ARGS or GENERAL_ERROR when config.json can't be read or written. An invalid file fails every command at start, not the switch, and the switch fails only when activeAccount has to change and the write fails; they now say so. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lently The daemon's own -q/--quiet also sets the root quiet flag. Since -q no longer skips the startup check of config.json, an invalid or unreadable file stopped `tg daemon start --quiet` with exit 3 or 1 and no output, so a supervised daemon died over a cache TTL typo with nothing in its logs. The daemon reads neither activeAccount nor any other key of config.json, so tg daemon now skips the check like tg config and tg skill; the next other command reports the file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
neoromantic
force-pushed
the
fix/accounts-switch-61
branch
from
October 22, 2026 10:59
5fc45ef to
4cd4056
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased onto main after #59 merged.
Problem
Every command except
tg configandtg skillmakes the account named byactiveAccountinconfig.jsonactive at startup.tg accounts switch --id <id>changed onlydata.db, so with the key set the switch lasted one command: the next one switched back and, since #17, read the configured account's cache.-q/--quietalso returned from the root setup before that step, unlike--format quiet, so a quiet command could use another account and skip the strict config check.Fix
tg accounts switchwrites the new ID toactiveAccountwhen the key is set and differs, before it touchesdata.db. If that write fails, the switch fails withGENERAL_ERROR(details.path) and changes neither file. Other keys stay; without the key, or with the same value, the file keeps its exact bytes and is never created.-qnow runs the same startup step as the other formats.tg daemonskips that step, astg configandtg skilldo. The daemon's own--quiet/-qalso sets the root flag, so with the step running a quiet daemon stopped silently (exit 3 or 1, no output) on an invalid or unreadableconfig.json, a file it never reads. Nowtg daemon startruns whatever the file holds, quiet or not; the next other command reports it.-f/--format. Before,tg -f pretty config set activeAccount 1sawpretty, ran the strict check and couldn't repair an invalidconfig.json;tg -f json skillfailed on one.config.jsonthat can't be read (for example for lack of permission) fails at startup withGENERAL_ERROR(details.path) instead of a Bun stack trace; under-qit prints nothing. Without this, the-qchange above would have exposed-qto that crash.activeAccountis set it wins at every start,tg accounts switchupdates it, andtg config set activeAccountor a hand edit takes effect from the next command. It lists the failure modes as they are: an invalid file fails every command excepttg config,tg skillandtg daemonwithINVALID_ARGS, an unreadable one withGENERAL_ERROR, and the switch fails only when it has to write and can't. It also notes that login doesn't write the key yet: tg auth login / login-qr don't update activeAccount in config.json, so the next command uses the configured account #62.Tests
src/__e2e__/multi-account.e2e.test.ts, one env per test, two accounts with account 1 active:config.json: the switch to 2 lasts (chats list, every cache command,messages get) and noconfig.jsonappears{activeAccount:1, cache…, note}: the switch lasts, the file becomesactiveAccount: 2with the other keys kept,tg config get activeAccountreturns 2 (red before the fix:chats listreturned account 1's chat)tg config set activeAccount 1after the switch wins from the next command-q chats listwithactiveAccount: 2applies itconfig.json: the switch fails withGENERAL_ERROR, anddata.dbstill has account 1 active when read directly, before any other command could reapplyactiveAccount(skipped as root). MovingsetActiveabove the config write makes this test fail.src/__e2e__/config.e2e.test.ts:tg config setrepairs an invalidconfig.jsonwith no flag,-q,-f prettyand--format quiet;tg -f json skill manifestruns with one (both red before the subcommand fix)tg daemon start --quiet,-qand with no flag, with an invalidconfig.json: the daemon runs and logs that there's no account;tg daemon statusreportsstopped(red before:--quietexited 3 with empty stderr)config.json:tg accounts listfails withGENERAL_ERRORanddetails.path,tg -q accounts listexits 1 with empty stderr (red before; skipped as root)bun run check,bun run testandbun run test:e2epass locally. No Telegram call changes; a live check against a test session in a temp data dir runs when the PR ships.Fixes #61
🤖 Generated with Claude Code