Skip to content

fix(doctor): detect tracked .charter/telemetry and name the untrack fix - #316

Merged
stackbilt-admin merged 3 commits into
mainfrom
auto/bugfix/issue-306
Sep 20, 2026
Merged

stackbilt-admin merged 3 commits into
mainfrom
auto/bugfix/issue-306

Conversation

@stackbilt-admin

@stackbilt-admin stackbilt-admin commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Closes #306

Follow-up to #298 / #304.

Problem

#304 added telemetry/ to the <configPath>/.gitignore that charter bootstrap/init generate (via initializeCharter, init.ts:426), so newly bootstrapped repos no longer stage .charter/telemetry/events.ndjson. It also documented a one-time git rm -r --cached .charter/telemetry.

An ignore entry never untracks a file already in the index. Any repo bootstrapped before #304 keeps staging every appended telemetry line on each git add -A — silently, and precisely for the users who hit the original bug. The documented cleanup only helps people who go looking for it.

This is the class of drift doctor exists to catch: repo state that no longer matches what the current generator would produce.

Change

New telemetry tracking check in packages/cli/src/commands/doctor.ts:

  • Reads the git index for <configPath>/telemetry via git ls-files -- <dir>. The filesystem is never consulted for the tracked determination, so the result is identical on case-sensitive and case-insensitive checkouts.
  • Tracked → INFO, naming the tracked files and the remedy.
  • Not tracked → PASS. git ls-files throwing (unreadable index, a --config directory outside the work tree) → check omitted rather than a PASS it did not establish.
  • The path is derived from options.configPath the same way commands/telemetry.ts:52 derives it, so --config is honoured rather than .charter/ being assumed. The interpolated path is quoted, so a config directory containing a space still yields a copy-pasteable command.

Advisory, not a CI failure

The diagnostic is INFO and never fails CI. This was WARN in the first revision; review round 2 correctly rejected that, and the repo settles the question three times over:

  • doctor.ts already carries the ruling for exactly this shape (feat(adf): add source LOC budget enforcement to catch godobject drift #186): "Intentionally INFO, not WARN: doctor fails CI on any WARN, and emitting a warning here would break every repo that hasn't opted in yet."
  • docs/cli-reference.md turns it into a promise: the soft nudge "never fails an existing repo's CI on upgrade."
  • docs/cli-reference.md documents the CI incantation as bare npx charter doctor --ci --format json — exactly the invocation a WARN would newly break.

Tracked telemetry is the same class as #186: state Charter's own pre-#298 bootstrap created, which the user never opted into, surfacing on upgrade. #289's checkGateEnforcement is not a counter-precedent — it is gated on config.git.requireTrailers plus FAIL/STRICT, a strict configuration the user chose; this fires on state the tool produced.

Verified empirically, which is the whole point: with .charter/telemetry/events.ndjson force-added to this repo's index, bare doctor --ci exits 0, overall status PASS, zero WARN checks — and the condition is still reported:

INFO telemetry tracking
1 telemetry file(s) tracked by git: .charter/telemetry/events.ndjson
    Every charter run appends to this log, so each "git add -A" stages it again.
    1. Make sure "telemetry/" is ignored — by .charter/.gitignore, or any .gitignore
       already covering it — or step 2 is undone by the next "git add -A".
    2. Run: git rm -r --cached ".charter/telemetry"
    The file stays on disk, so "charter telemetry report" keeps working.

(The index was restored afterwards; git ls-files .charter/telemetry is empty again.)

Remedy ordering

The ignore entry comes before git rm -r --cached, deliberately. After the untrack the file is untracked-but-still-present, so the exact habit that caused the bug — a reflexive git add -A — re-stages it before the user reaches the last line. It is worded as a condition that may already be satisfied ("or any .gitignore already covering it"), because <configPath>/.gitignore does not exist in pre-#298 repos — it does not exist in this one, where the root .gitignore:19-20 does the work.

Placement

Inside the existing if (!adfOnly) block, next to the other <configPath>-hygiene checks (config file, patterns, policy docs), and withheld outside a git repository — matching gate enforcement (#289), which is likewise not pushed rather than reported as a vacuous PASS. .github/workflows/governance.yml:55 and the verify:adf script both pass --adf-only and are unaffected; with INFO, no doctor invocation in any repo goes red from this.

Does charter itself trigger it?

No. git ls-files .charter/telemetry and git log --all -- .charter/telemetry are both empty — it was never committed here. One correction worth recording: it is ignored by the root .gitignore (lines 19-20), not by a .charter/.gitignore, which does not exist in this repo. #304 changed the generated bootstrap template, not charter's own config dir.

Docs

docs/cli-reference.md gains a Tracked telemetry subsection under charter doctor, and the command's summary line now mentions the check. It states the advisory status explicitly, so the "never fails CI on upgrade" promise stays true as written.

Tests

packages/cli/src/__tests__/doctor-telemetry-tracked.test.ts, mirroring the fixture style of doctor-gate-enforcement.test.ts. 9 cases.

Measured, not reasoned about — the 9-case file run against each prior tree:

tree result
main (no check at all) 7 failed, 2 passed
d282fd0 (round 1, WARN + unordered remedy) 5 failed, 4 passed
HEAD 9 passed

(The first revision's 6-case file scored 4 failed / 2 passed against main.)

Red on main — genuine detectors for the original bug:

  • tracked telemetry is reported, naming git rm -r --cached ".charter/telemetry" and charter telemetry report
  • the report names the tracked file
  • on disk but untracked → PASS (guards against over-warning)
  • a custom --config directory reports the custom path, not .charter
  • a --config path containing a space stays quoted and copy-pasteable

Also red on d282fd0 — these catch the round-2 review findings specifically, so they are regression detectors for this PR's own history, not just for main:

Green on main, and honestly just guards — they encode placement decisions and detect nothing:

  • --adf-only omits the check
  • outside a git repository the check is omitted

Full suite: 931/931 passed (922 baseline + 9), pnpm run typecheck clean.

🤖 Generated with Claude Code

…ix (closes #306)

A gitignore entry never untracks a file already in the index, so repos
bootstrapped before #298 keep staging every appended telemetry line on
each "git add -A". doctor now reads the git index for <configPath>/telemetry
and prints the one-time remedy.

Withheld under --adf-only and outside a git repo, so the existing
doctor --adf-only --ci gate is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@stackbilt-admin stackbilt-admin left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

CHANGES_REQUESTED

The check itself is well built: the git-only determination is correct, the path derivation honours --config, the placement is right, and the red/green split is exactly as reported. One blocking item — an undisclosed CI behaviour change — plus four nits.

  1. [BLOCKING] The CHANGELOG reassures about the wrong gate and omits that bare doctor --ci newly fails. CHANGELOG.md:11 ends "…and is withheld outside a git repository and under --adf-only, so the existing doctor --adf-only --ci gate is unchanged." That is true and it is the misleading part: it names the one CI invocation that is unaffected and says nothing about the one that is. Traced: checkTelemetryTracking returns WARN (doctor.ts:110), hasWarn is any WARN (doctor.ts:543), and doctor.ts:559 returns EXIT_CODE.POLICY_VIOLATION when options.ciMode && hasWarn. So any downstream repo running bare charter doctor --ci with telemetry in its index goes red on upgrade. That is not a hypothetical invocation — docs/cli-reference.md:146 documents npx charter doctor --ci --format json # CI mode: exit 1 on warnings as the CI incantation. Please (a) state in the CHANGELOG that bare doctor --ci can newly fail for repos with tracked telemetry, with the one-line remedy inline, and (b) add telemetry tracking to the doctor description at docs/cli-reference.md:141, which enumerates what doctor validates and does not list it.

  2. [NIT] WARN vs INFO — the precedent cuts toward INFO, but this is defensible. doctor.ts:512-517 carries an explicit ruling on exactly this shape: "Intentionally INFO, not WARN: doctor fails CI on any WARN, and emitting a warning here would break every repo that hasn't opted in yet (#186)." And docs/cli-reference.md:186-187 turns it into a promise — the LOC-budget nudge "never fails an existing repo's CI on upgrade." Tracked telemetry is the same class: state charter's own pre-#298 bootstrap created, which the user never opted into, surfacing on upgrade. The strongest counter is #289 checkGateEnforcement (CHANGELOG.md:26), added recently as WARN with no INFO variant — but it is gated on config.git.requireTrailers && FAIL/STRICT (doctor.ts:170-174), i.e. it only fires under a strict configuration the user chose. This one fires on state the tool produced. Note also that patterns and policy docs are not a precedent here: they pre-date any current green CI, so they break nothing on upgrade. I'd demote to INFO; if you keep WARN, item 1 becomes non-negotiable.

  3. [NIT] The remedy steps are in an order that loses the race. doctor.ts:114-119 prints git rm -r --cached <dir> first and "Add telemetry/ to <configPath>/.gitignore" last. After rm --cached the file is untracked-but-present, and the habit that caused the bug in the first place — a reflexive git add -A — re-stages it before the user reaches the last line. Put the ignore entry first. Separately, <configPath>/.gitignore does not exist in pre-#298 repos (it does not exist in this one), and in repos like charter the root .gitignore:19-20 already covers telemetry, so the line is unconditional advice that is sometimes already satisfied.

  4. [NIT] The catch asserts a fact it did not establish. doctor.ts:95-102 turns a runGit throw into status: 'PASS' with details: "<dir> is not tracked by git." The check only runs inside if (inGitRepo) (doctor.ts:198-202), so a throw here means something genuinely odd — an unreadable index, or a --config path outside the work tree — and the output claims the opposite of "unknown". This is the same failure mode the PR deliberately avoids five lines later: doctor.ts:196-197 withholds the check outside a repo rather than reporting it vacuously OK. Either omit on throw, or keep PASS and word it as "could not read the git index".

  5. [NIT] Unquoted path in the remedy. doctor.ts:117 interpolates telemetryDir bare into git rm -r --cached ${telemetryDir}. A --config directory containing a space yields a command that does not copy-paste.


Verified against source, not description:

  • Path derivation — doctor.ts:88 uses path.join(configPath, 'telemetry') with backslash normalisation, matching the telemetry.ts:89/149/180 writers. options.configPath comes from --config (index.ts:130) and flows into both detection and the printed remedy. The custom-cfg/telemetry test covers it and does assert the remedy string, not just the status.
  • git as sole authority — confirmed by inspection: checkTelemetryTracking contains no fs call of any kind; the only I/O is runGit(['ls-files', '--', telemetryDir]). The case-insensitivity trap is sidestepped by construction. Stating it precisely: the tests use exact-case paths and never exercise case divergence, so this holds by construction, not by test — which is the right way round.
  • Placement — inside if (!adfOnly) alongside config file/patterns/policy docs/gate enforcement (doctor.ts:160-202). Consistent, and --adf-only genuinely omits it.
  • Not-a-git-repo — omitted, not vacuously passed, matching checkGateEnforcement's inGitRepo guard at doctor.ts:172. Cannot read as "checked and fine".
  • Remedy correctness — git rm -r --cached removes from the index and leaves the working tree file intact. readEvents (telemetry.ts:136-141) reads the file off disk via existsSync/readFileSync and never consults git, so charter telemetry report does keep working. Claim holds.
  • Pathspec precision — git ls-files -- .charter/telemetry matches at path-component boundaries, so a sibling like .charter/telemetryfoo is not caught.

Red/green, executed: reverted packages/cli/src/commands/doctor.ts to main and ran the test file — 4 failed, 2 passed, exactly as reported. The 4 failures include passes when telemetry exists on disk but is untracked, which fails pre-fix because the check is absent entirely. The 2 pre-fix passes are the --adf-only and not-a-git-repo omission guards, which pass vacuously on main for the same reason. The PR states this rather than counting them as detectors; the honesty holds. Full doctor suite: 13/13 pass with the change in place.

Working tree: the scratch copy of main's doctor.ts was written to the session scratchpad outside the repo; the source file was restored with git checkout --. git status --porcelain after restore shows only ?? .ai/context.adf and ?? .ai/context.snapshot.json. Nothing modified, committed, or pushed.

stackbilt-admin and others added 2 commits September 20, 2026 09:15
…lure

Review round 2. The condition is state Charter's own pre-#298 bootstrap
created, not anything the user opted into, so reporting it on upgrade must
not fail an existing repo's CI. doctor.ts already carries this exact ruling
for the source LOC budget nudge (#186), and docs/cli-reference.md promises
that soft nudge "never fails an existing repo's CI on upgrade" while
documenting bare "charter doctor --ci" as the CI incantation. WARN -> INFO.

Also:
- Put the .gitignore step before "git rm -r --cached": the untrack leaves
  the file on disk, so a reflexive "git add -A" re-staged it first. Worded
  as a condition that may already be satisfied, since <configPath>/.gitignore
  does not exist in pre-#298 repos.
- Omit the check when "git ls-files" throws instead of claiming a PASS it
  did not establish.
- Quote the interpolated path so a --config dir containing a space is
  copy-pasteable.
- Document the check in docs/cli-reference.md.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…acked

Only repos where someone ran "git add -A" have it in the index, and the
check reads the index, so staged-but-uncommitted counts too. "have it
committed" was false on both counts. Same conditional-truth fix applied to
the CHANGELOG entry.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@stackbilt-admin
stackbilt-admin merged commit c88747f into main Sep 20, 2026
5 checks passed
@stackbilt-admin
stackbilt-admin deleted the auto/bugfix/issue-306 branch September 20, 2026 14:21
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.

doctor: detect already-tracked .charter/telemetry and name the untrack fix

1 participant