Skip to content

fix(init): keep the settings that validate when --force replaces an invalid config - #1510

Merged
SaulMoro merged 2 commits into
Tencent:mainfrom
pcbeingused333:fix/init-force-invalid-config
Oct 28, 2026
Merged

SaulMoro merged 2 commits into
Tencent:mainfrom
pcbeingused333:fix/init-force-invalid-config

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Summary

Refs #1500 (Part 3)

init --force over a workspace config that fails validation (for example recallEnabled: "yes") treated it as another install's config: it moved it to config.yaml.previous, even for the same team, and wrote a new config without any of the member's settings. #1458 kept the settings of a config that parses; this is the case it does not reach.

init now reads what such a file still holds. It takes the team repo the file records and every key that validates on its own. When the recorded team repo is the one init is setting up, the config is not moved aside, the keys that validate are carried into the new config as #1458 does for a readable one, and each key that does not validate is named in a warning, for example recallEnabled in …/config.yaml is "yes" (Expected boolean, received string), so it was dropped. A config that records another team repo is moved aside as before.

This covers teamai init <url> on a team repository. Single-repo mode and --http init are not changed.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Test Plan

  • npx tsc --noEmit passes
  • npm run lint passes
  • npx vitest run passes (ran the init unit tests, 115 passed, not the whole suite)
  • Added/updated tests for the change

New e2e test init-invalid-config-1500.test.ts, run against the built CLI with local team repositories: with recallEnabled: "yes" and coAuthorEnabled: false, init <same team> --force keeps coAuthorEnabled: false, names recallEnabled as dropped, prints no "another install's config" message and leaves no config.yaml.previous. With repo.remote naming another team, it still moves the config aside. The first case fails without the change and passes with it.

Related Issues

Refs #1500 (Part 3 only; Parts 1 and 2 are separate changes)

Notes for Reviewers

  • salvageConfigFile reads the file as YAML and validates each top-level key on its own with LocalConfigSchema.shape[key].safeParse; repo.remote is only used to decide whether the file belongs to this team repo. A file that is not a YAML mapping, or records no team repo, is handled exactly as before.
  • The e2e test runs the built CLI (npm run build first), like init-keeps-member-settings-1458.test.ts.

This change was made with Claude Code.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown
  • [P2 non-blocking] Preserve valid inheritUserScope when salvaging — src/init.ts:1779: For an invalid config, carriedConfig remains null, so resolveInheritUserScope receives no saved preference. settingsReinitKeeps also excludes this key. A valid inheritUserScope value therefore falls back to the default instead of surviving re-init. Pass the salvaged preference into scope resolution too.

The PR description documents sufficient testing: a representative built-CLI run covers same-team preservation and different-team config relocation. No commands from the PR were executed.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

@pcbeingused333 Thanks for taking #1500 Part 3. With the built CLI, a same-team config with recallEnabled: "yes" now keeps coAuthorEnabled: false and autoCompactTokens, names recallEnabled as dropped, and no longer says it is another install's config. A config that records another team repo is still moved aside, and an ssh-form remote counts as the same team as the https URL. This works in both workspace and user scope. Two things still block approval. Both come from the same-team path still treating the file as unreadable after the salvage.

We compared against a control: the same fixture without the bad value, which #1458 already handles. A first init A --agent claude,codex --inherit-user-scope, then the config edit and a queued learning, then init A --force:

control (valid config) this PR (config with one bad value)
inheritUserScope true gone
enabledAgents [claude, codex] gone
disabledAgents [] gone
pending-learnings/l1.md kept moved to pending-learnings.unknown
  • [P1 blocking] Four settings are still lost. inheritUserScope, enabledAgents, disabledAgents and toolRoots are read from carriedConfig, which stays null on this path (src/init.ts:1777-1786, :2419-2425, :2435). toolRoots is from the code, the other three are from the run. With --agent claude, enabledAgents becomes [claude] instead of the member's list. The issue expects these carried as for a readable config, and the CI review's inheritUserScope note is one case of this.
  • [P1 blocking] Queued learnings are set aside. The final save (src/init.ts:2444) still passes no previous config, so the queue goes to pending-learnings.unknown with "the previous install's config … could not be read". Those learnings stop being published until the member moves them back by hand.

Using the salvaged config as carriedConfig, and as the previous config at the final save, whenever it records this team repo would fix both. The e2e test would catch them with enabledAgents and a queued learning in its fixture.

  • [P3 nit] salvageConfigFile casts with as LocalConfig an object that may lack username. That matters once the salvaged config reaches code that expects a full one.
  • [P3 nit] A nested setting such as workflows is dropped whole when one of its subfields is wrong.

tsc, lint and the 115 init unit tests pass. The new e2e file passes 2/2 here, also with a symlinked TMPDIR, and its first case fails on main. CI hasn't run on this PR yet. #1509 and #1512 merge cleanly with it.

@SaulMoro
SaulMoro self-requested a review October 28, 2026 08:58
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review and the control table. Both blockers are fixed in a18293c:

  • A config that does not validate but records this team repo is now used as carriedConfig, so inheritUserScope, enabledAgents, disabledAgents and toolRoots are carried as for a readable config (this also covers the CI note on inheritUserScope).
  • The same salvaged config is the previous config at the final save, so the queued learnings stay in pending-learnings/ instead of moving to pending-learnings.unknown.
  • salvageConfigFile no longer casts away a missing username (it fills an empty one) and keeps a valid repo.kind.

The e2e file has a new case with enabledAgents: [claude, codex], inheritUserScope: true and a queued learning in the fixture; it fails on the previous commit and passes now, with the other two cases and the 115 init unit tests still green. The nested-setting nit (workflows dropped whole) is left as is: salvaging below the top-level keys would need a per-schema walk, so it seems better as a separate change if you want it.

This reply and the code change were prepared by an AI agent (Claude) working for the PR author.

@github-actions

Copy link
Copy Markdown

No new findings in the specified diff.

  • Resolved: The earlier inheritUserScope finding is fixed: same-team salvage now passes the saved preference into scope resolution, with an added e2e assertion.
  • Testing: The PR description documents sufficient testing—a representative built-CLI run covers same-team preservation and different-team config relocation.

Only the diff was read; no PR code was run, built, or installed.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

@pcbeingused333 Thanks, approving a18293c4.

  • Settings carried. With the built CLI, a toolRoots entry added to the fixture, and three same-team cases (workspace without --agent, workspace with --agent claude, user scope), the config after init --force matches the control run with a valid config. That covers inheritUserScope, enabledAgents, disabledAgents and toolRoots.
  • Queued learnings. l1.md stays in pending-learnings/ in all three cases and with an ssh-form remote, and your new e2e case fails on 2d2888b3. A config that records another team repo is still moved aside.
  • Checks. On a merge with current main (with #1509 and #1512), build, tsc, lint, the 118 init unit tests, and the e2e files for this PR and #1458 (7/7) pass. CI is green at this head.

The CI review reported no new findings, and we agree. We accept leaving a nested setting with one bad subfield as a separate change, as you suggested.

Optional:

  • [P3 nit] The try/catch around the second resolveInheritUserScope call (src/init.ts:1884-1890) can't fire, since it gets the same inputs as the first call at :1786, which already passed.

@SaulMoro
SaulMoro merged commit 56320ab into Tencent:main Oct 28, 2026
18 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…nvalid config (Tencent#1510)

init --force over a config that fails validation but records this team repo no longer treats it as another install's. It keeps the config in place, carries every key that validates on its own, including inheritUserScope, enabledAgents, disabledAgents and toolRoots, keeps queued learnings, and names each dropped key in a warning. A config that records another team repo is moved aside as before.

Refs Tencent#1500
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.

3 participants