Repository navigation
doctor: a re-init fix on a --managed host keeps --managed (follow-up to #845) - #858
Merged
Merged
Conversation
#845) On a host set up with init --managed, only the hook checks' fixes (D-HOOKS-MANAGED, D-HOOKS-PRESENT, D-HOOKS-VENV) named --managed. The other re-init fixes, D-PROCESS-BOUNDARY, D-CODE-TRUST, D-UNIT-HARDENING, D-TAILER-CONFIG among them, ended without it, so a person who followed one ran init without --managed: init wrote its hooks into the agent's own ~/.claude/settings.json, which the agent can edit, and took them out of the root-owned managed file. With the Tracekit plugin on, each call was then decided twice. Without --managed-only, init also turned off the allowManagedHooksOnly an init with it had turned on. collect() now adds --managed to every re-init fix when init's hooks are in Claude Code's managed settings, and --managed-only when init recorded it there (its _tracekit_allowManagedHooksOnly marker; an admin's own allowManagedHooksOnly has no marker, and init leaves it). The hook checks' fix no longer adds its own, so it names --managed once. --no-hooks and --agent stay as #845 left them. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
LoopGlitch26
enabled auto-merge (squash)
November 15, 2026 01:57
LoopGlitch26
added a commit
that referenced
this pull request
Nov 15, 2026
Conflicts: #858's squash (f32c2fe) against this branch's later edits of the same hunks, kept as this branch has them (a superset of #858's), and main's jcode and Kiro CLI changes: cli.py keeps both --project [DIR] and jcode's user-config refusal; docs/doctor.md keeps this branch's D-HOOKS-PRESENT and D-HOOKS-MANAGED rows and main's D-HOOKS-EVENT and D-HOOKS-ORDER rows. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
LoopGlitch26
added a commit
that referenced
this pull request
Nov 15, 2026
* doctor: a re-init fix on a --managed host keeps --managed (follow-up to #845) On a host set up with init --managed, only the hook checks' fixes (D-HOOKS-MANAGED, D-HOOKS-PRESENT, D-HOOKS-VENV) named --managed. The other re-init fixes, D-PROCESS-BOUNDARY, D-CODE-TRUST, D-UNIT-HARDENING, D-TAILER-CONFIG among them, ended without it, so a person who followed one ran init without --managed: init wrote its hooks into the agent's own ~/.claude/settings.json, which the agent can edit, and took them out of the root-owned managed file. With the Tracekit plugin on, each call was then decided twice. Without --managed-only, init also turned off the allowManagedHooksOnly an init with it had turned on. collect() now adds --managed to every re-init fix when init's hooks are in Claude Code's managed settings, and --managed-only when init recorded it there (its _tracekit_allowManagedHooksOnly marker; an admin's own allowManagedHooksOnly has no marker, and init leaves it). The hook checks' fix no longer adds its own, so it names --managed once. --no-hooks and --agent stay as #845 left them. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com> * doctor: re-init advice keeps init's own flags (follow-up to #858) A fix that re-ran system init gave back init's agent, --no-hooks and --managed only. Following one on a host set up with --policy, --harness, --approver, --egress and the like rewrote signer.yaml with init's defaults (its own policy, no harness binding), and doctor didn't say. - init --v2 records the rest of its flags in client.json (hooks.init_flags, and the directory of a --project init); v1 init records its own at the top level. Doctor reads them from that root-owned file only and gives them back shell-quoted. A host whose client.json predates the record gets a fix that says doctor can't tell init's flags, instead of a re-init that drops them. - v1: V1_REINIT never named --managed; doctor now gives v1 init's flags too, and --managed where the managed settings hold v1 hooks on an older host. - D-HOOKS-PRESENT no longer fails "every call is decided twice" on an init --managed host with allowManagedHooksOnly on when only the agent's own settings enable the plugin (Claude Code doesn't run it then). On a managed host its fix no longer names tracekit uninstall, which never takes managed hooks out. - D-SYSTEM-CONFIG keeps --managed when the managed settings hold init's v2 hooks. - --managed-only is given again only while init's marker is there and allowManagedHooksOnly is still on, init's own rule. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com> * doctor: re-init fixes run from the clone; init takes --project DIR (review of #860) - init --project [DIR]: a re-init fix for a --project host named the directory and had the person run `sudo python3 -m tracekit init` there, in the agent's own repo, where -m imports a planted tracekit/ before the release's, as root. init now takes the directory (no DIR keeps the working directory), init records it, and the fix runs from the root-owned clone like every other re-init. - --harness is recorded as given (absolute, symlinks kept), not as its resolved real path, which a package upgrade removes or leaves pointing at the old binary. The signer still binds the resolved program. - --managed-only is recorded (v1 and v2). When allowManagedHooksOnly is off now (an admin, or MDM replacing the managed file), the fix keeps it and says to drop it only if it was turned off on purpose; a fix's own --managed-only isn't given twice. - --i-understand-agent-is-privileged, --no-witness and --public-witness aren't recorded or replayed. - migrate --system keeps v1's init_flags. - install no longer imports doctor's private helpers: install.reinit_flags and install.setting are shared. doctor --config with no client.json says there is none. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com> * doctor: keep --harness as given only where root alone can repoint it (re-review of #860) - harness_spec kept the given path, links and all, but trusted_file checks only the real path's chain: a link in a directory the agent's user can write could be repointed before a re-init, which then bound any root-owned program. The given path is now kept only when every directory its lookup reads, its links' targets included, is root-owned and not group- or world-writable; else init records the real path. - The no-record note names --project DIR: a bare --project run from the release's clone puts the hooks in the clone. - uninstall takes --project [DIR] as init does, and dev init's plugin check reads DIR's .claude (and doesn't take a named project's .claude for a user config root, as it didn't the working directory's). Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com> * cli: --project [DIR] resolves against os.getcwd() as init runs, on every OS CI's py3.9 Windows job failed five init --dev --v2 --project tests: the hooks went into the checkout, not the test's working directory. --project with no DIR went through os.path.abspath(".") at run time, and on Windows abspath asks the OS for the working directory (nt._getfullpathname) instead of calling os.getcwd(), which those tests patch to set it and which the code read before --project took a DIR. DIR is now joined to os.getcwd() and normalized, as POSIX abspath does. A test stands in an abspath that ignores a patched os.getcwd, as Windows' does, and checks a parser built before a chdir. The two CliProject tests compare against os.path.abspath of the input (C:\srv\my repo on Windows). Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com> * tests: HarnessSpec skips on Windows, as this file's other system-mode tests do CI's py3.13 windows-latest job failed it: resolve_harness couldn't take the temp script's "#!/bin/sh" interpreter, as Python 3.13's ntpath.isabs no longer counts a drive-less rooted path. Harness binding is system mode's, which _require_system refuses on Windows before any harness code runs. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com> --------- Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
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.
Follow-up to #845.
What went wrong
On a host set up with
init --managed, only the hook checks' fixes (D-HOOKS-MANAGED, D-HOOKS-PRESENT, D-HOOKS-VENV) named--managed. The other re-init fixes ended without it, including those for D-PROCESS-BOUNDARY, D-CODE-TRUST, D-UNIT-HARDENING and D-TAILER-CONFIG. Someone who followed one of them ran init without--managed, and then:~/.claude/settings.json, which the agent can edit (tracekit/install.py,init_system_v2);_remove_v2_hookstook them out of the recorded managed file, which is root-owned;--managed-only, init without that flag also turnedallowManagedHooksOnlyback off.#845 fixed the same kind of bug for
--no-hooksand--agent.The fix
collect()builds the flags that every re-init fix gets. It now adds--managedwhen init's hooks are in Claude Code's managed settings (install.MANAGED_SETTINGS). It also adds--managed-onlywhen init turnedallowManagedHooksOnlyon: init records that with the_tracekit_allowManagedHooksOnlymarker in that file. If an admin turnedallowManagedHooksOnlyon, there is no marker, and init leaves the setting alone, so the fix doesn't add the flag.v2_checks' hook fix no longer adds--manageditself, so D-HOOKS-MANAGED's fix names it once. The--no-hooksand--agentrules from #845 are unchanged.Tests
tests/test_doctor_v2.py:NoHooksChosen.test_the_reinit_fix_keeps_inits_agent_and_no_hooks: the managed case used to expect an empty suffix. New subtests:--managed, and no--no-hooks;install.install_managed(managed_only=True)):--managed --managed-only;allowManagedHooksOnly(no init marker):--managedonly;--agent codex, unchanged.ManagedHooks: the hook-check fixes now end at the plain re-init, becausecollect()adds--managed. This pins that D-HOOKS-MANAGED doesn't name it twice. The managed-only half oftest_the_fix_keeps_managed_only_and_runs_on_macosmoved into the collect test above, and the macOS half is nowtest_the_fix_runs_on_macos.Fail-first: I ran the new test file against origin/main's
tracekit/doctor.py(138950f), copied into a scratch tree. All 5 managed subtests fail. The 6 subtests without managed settings pass, so their behaviour is unchanged. The 4 updatedManagedHooksassertions also fail on main, wherev2_checksstill adds its own--managed.Runs on this branch:
tests/test_doctor_v2.pyandtests/test_docs.py: 140 passed, 220 subtests passed.make lint: clean.eval/e16_doctor.py): 57/57 flagged, gate PASS.make test-ts lint build test):make test: a session restart stopped it at 93%, with 5011 passed, 445 skipped and 0 failed. I re-ran the remaining files,tests/test_view_ui.pythroughtests/test_yamlmini.py: 420 passed.Before and after, run as a user would
I ran real
doctor.collect()on scratch system-mode hosts, once against origin/main and once against this branch, with the import path checked each time. Only client.json and the agent user are mocked; the plugin check,v2_checksand the fix rewrite run as shipped. In the output below,<REINIT>stands forfrom a root-owned clone of the release (https://github.com/Cygnux-Labs/Tracekit/wiki/Deploy#laptop-system-mode), sudo /usr/bin/python3 -m tracekit init --v2 --user <agent-user> --experimental-macos.Host (a),
init --managedwith the plugin on. Before:After:
Host (d),
init --managed --managed-onlywith the plugin on. Its managed file was written byinstall.install_managed(managed_only=True)and holds the marker. Before, the suffixes were['', ' --managed --managed-only'], and only D-HOOKS-MANAGED and D-HOOKS-VENV had both flags. After, all six re-init rows end in--managed --managed-only.The other hosts are unchanged: (b)
init --no-hookswith the plugin on gives[' --no-hooks'], and (c)init --agent codex --no-hooksgives[' --agent codex --no-hooks']. No fix names--managedtwice.Not checked: a real root
init --managedon Linux, then following the new fix. The scratch run checks the advice doctor prints, not what init does with it.