Repository navigation
Fix Greptile review findings from onboarding batch (#430–#433) - #434
Conversation
Five review findings from the just-merged onboarding batch, addressed together because they cluster around the same onboard/uninstall UX and the SDK exporter/backfill idempotency touched in that batch. #432 (P1): the combination path double-ran the Codex backfill and printed the closing home banner up to three times. `_onboard_codex` ran its own backfill AND printed the banner, `_onboard_claude_code` printed the banner too, and `_onboard_combination` did both again. Fix: give both per-path sub-onboarders a `standalone: bool = True` parameter. The combination flow passes `standalone=False`, which suppresses each sub-onboarder's own Codex backfill and closing banner — so the backfill runs exactly once (in the combination leg) and the banner prints exactly once (at the very end). Single-path flows keep `standalone=True` and are unchanged. #430 (P1): after a successful `pipx uninstall tokenjam`, the venv is gone, so the printed reinstall hint `pipx upgrade tokenjam` would fail ("not installed"). Added `_package_fresh_install_hint()` (bare `pipx install` / `pip install`) and use it only on the successful-removal path. The upgrade/--force hint stays where it belongs — when the package REMAINS (a plain install would no-op there). #430 (P2): `--remove-package` help text overstated ("runs pipx/pip uninstall") — for non-pipx installs it only PRINTS the command. Reworded the help + option text and the interactive confirm prompt so they say "runs" for pipx and "prints … for you to run" for pip/venv. #431 (P2): a whitespace-only ingest secret was truthy, so `TjHttpExporter` built `Authorization: Bearer ` — the same illegal header value the empty case already guards against. Now guard on `.strip()` so a blank secret omits the header entirely. #433 (P2): `ingest_codex` issued one `SELECT 1 FROM spans WHERE span_id=$1` per span. Aligned it with the Claude Code path's bulk idempotency by reusing `core.backfill._existing_span_ids` — one chunked `WHERE span_id IN (...)` per session partitions new-vs-existing spans, replacing the per-span existence SELECT. Backends without a `conn` (InMemoryBackend) fall back to plain inserts and let the PRIMARY KEY conflict skip duplicates. Tests: combination path backfills each source ONCE and prints the banner ONCE (TestCombinationPathNoDoubleRun); after-removal reinstall hint is `pipx install` not upgrade; prompt wording matches install type; whitespace-only secret omits the Authorization header; a DuckDB-backed idempotency test exercises the new bulk `_existing_span_ids` path. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015e3DZGhb1R5sXX2x52Y2Ar
|
| Filename | Overview |
|---|---|
| tokenjam/cli/cmd_onboard.py | Adds standalone: bool = True to both sub-onboarders; combination flow correctly suppresses per-leg backfill and banner, runs each exactly once. Minor: closing _print_setup_complete_home() in combination path is hardcoded to zero-sessions framing. |
| tokenjam/cli/cmd_uninstall.py | Adds _package_fresh_install_hint() for the post-removal path; _installed_via_pipx() checks sys.executable so it remains correct even after the venv is deleted in-process. |
| tokenjam/sdk/http_exporter.py | Whitespace-only secrets now skip the Authorization header via .strip() guard, but the raw unstripped value is still used in the header interpolation, so a leading-space non-empty secret would still produce an illegal double-space header. |
| tokenjam/core/ingest_adapters/codex.py | Per-span SELECT replaced with single chunked bulk _existing_span_ids call; InMemoryBackend fallback is clean; no circular import. |
| tests/unit/test_onboard_path_branch.py | New TestCombinationPathNoDoubleRun covers banner-once, backfill-once, standalone=False propagation, and the Codex-only variant. |
| tests/unit/test_backfill_codex.py | Adds DuckDB-backed idempotency test exercising the new bulk path; complements the existing InMemoryBackend test. |
| tests/unit/test_http_exporter_auth.py | Parametrize extended to whitespace variants; assertion updated to not v.startswith("Bearer ") which is more thorough than the prior equality check. |
| tests/integration/test_cli_uninstall.py | Two new tests verify fresh-install hint after removal and prompt wording per install type. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[tj onboard combination] --> B{uses_cc?}
B -- yes --> C["_onboard_claude_code(standalone=False)"]
B -- no --> D{uses_codex?}
C --> D
D -- yes --> E["_onboard_codex(standalone=False)"]
E --> F["_try_backfill_codex() runs ONCE"]
D -- no --> G{uses_sdk?}
F --> G
G -- yes --> H[_print_instrument_agent_snippet]
G -- no --> I["_print_setup_complete_home() prints ONCE"]
H --> I
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[tj onboard combination] --> B{uses_cc?}
B -- yes --> C["_onboard_claude_code(standalone=False)"]
B -- no --> D{uses_codex?}
C --> D
D -- yes --> E["_onboard_codex(standalone=False)"]
E --> F["_try_backfill_codex() runs ONCE"]
D -- no --> G{uses_sdk?}
F --> G
G -- yes --> H[_print_instrument_agent_snippet]
G -- no --> I["_print_setup_complete_home() prints ONCE"]
H --> I
Comments Outside Diff (1)
-
tokenjam/cli/cmd_onboard.py, line 1791 (link)Combination banner always shows zero sessions backfilled
_print_setup_complete_home()is called with no arguments, sosessions_backfilled=0andhas_data=Falseare hard-coded for every combination run. If the Claude Code or Codex backfills found sessions, the banner will still read as if nothing was backfilled. Individual per-leg console lines do show the real counts, but the closing home screen does not. The combination-leg_cx_has/_cx_nvariables from_try_backfill_codexare currently discarded; wiring the largest leg result intosessions_backfilled=/has_data=would keep the banner consistent.Prompt To Fix With AI
This is a comment left during a code review. Path: tokenjam/cli/cmd_onboard.py Line: 1791 Comment: **Combination banner always shows zero sessions backfilled** `_print_setup_complete_home()` is called with no arguments, so `sessions_backfilled=0` and `has_data=False` are hard-coded for every combination run. If the Claude Code or Codex backfills found sessions, the banner will still read as if nothing was backfilled. Individual per-leg console lines do show the real counts, but the closing home screen does not. The combination-leg `_cx_has` / `_cx_n` variables from `_try_backfill_codex` are currently discarded; wiring the largest leg result into `sessions_backfilled=` / `has_data=` would keep the banner consistent. How can I resolve this? If you propose a fix, please make it concise.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
tokenjam/sdk/http_exporter.py:35-36
**`Authorization` header sent with untrimmed whitespace secret**
The guard `self._ingest_secret.strip()` correctly blocks whitespace-only strings, but the header is still built from the raw `self._ingest_secret` value. A secret like `" realtoken"` (leading space) passes the `.strip()` truthiness check and produces `"Bearer realtoken"` (double space), which is an illegal HTTP header value for the same reason as `"Bearer "`. Stripping before storing, or at least before the `f"Bearer {…}"` interpolation, closes this gap.
### Issue 2 of 2
tokenjam/cli/cmd_onboard.py:1791
**Combination banner always shows zero sessions backfilled**
`_print_setup_complete_home()` is called with no arguments, so `sessions_backfilled=0` and `has_data=False` are hard-coded for every combination run. If the Claude Code or Codex backfills found sessions, the banner will still read as if nothing was backfilled. Individual per-leg console lines do show the real counts, but the closing home screen does not. The combination-leg `_cx_has` / `_cx_n` variables from `_try_backfill_codex` are currently discarded; wiring the largest leg result into `sessions_backfilled=` / `has_data=` would keep the banner consistent.
Reviews (1): Last reviewed commit: "fix: resolve Greptile review findings fr..." | Re-trigger Greptile
| if self._ingest_secret.strip(): | ||
| self._headers["Authorization"] = f"Bearer {self._ingest_secret}" |
There was a problem hiding this comment.
Authorization header sent with untrimmed whitespace secret
The guard self._ingest_secret.strip() correctly blocks whitespace-only strings, but the header is still built from the raw self._ingest_secret value. A secret like " realtoken" (leading space) passes the .strip() truthiness check and produces "Bearer realtoken" (double space), which is an illegal HTTP header value for the same reason as "Bearer ". Stripping before storing, or at least before the f"Bearer {…}" interpolation, closes this gap.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/sdk/http_exporter.py
Line: 35-36
Comment:
**`Authorization` header sent with untrimmed whitespace secret**
The guard `self._ingest_secret.strip()` correctly blocks whitespace-only strings, but the header is still built from the raw `self._ingest_secret` value. A secret like `" realtoken"` (leading space) passes the `.strip()` truthiness check and produces `"Bearer realtoken"` (double space), which is an illegal HTTP header value for the same reason as `"Bearer "`. Stripping before storing, or at least before the `f"Bearer {…}"` interpolation, closes this gap.
How can I resolve this? If you propose a fix, please make it concise.
Addresses the five Greptile review findings raised on the just-merged onboarding batch (#430–#433). Grouped into one PR because they cluster around the same onboard/uninstall UX plus the SDK exporter/backfill idempotency touched in that batch.
Summary
pipx install, notpipx upgrade(Fix: clarify uninstall/reinstall two-step + optional package removal #430).--remove-packagehelp + prompt wording now matches what actually happens per install type (Fix: clarify uninstall/reinstall two-step + optional package removal #430).Authorizationheader instead of sendingBearer(Fix tj ping: omit empty Bearer header so the test span is delivered #431).ingest_codexuses the bulk idempotency check the Claude Code path uses, replacing the per-span SELECT ([feature] Addtj backfill codex— Codex CLI rollout session backfill #433).[#432 P1] Combination path double-ran backfill + printed the banner up to 3×
_onboard_codexcalled_try_backfill_codexinternally and printed_print_setup_complete_home;_onboard_claude_codealso printed the banner;_onboard_combinationthen ran the Codex backfill AND printed the banner again. Net: Codex backfill ran twice, banner printed up to three times.Fix: added
standalone: bool = Trueto both_onboard_claude_codeand_onboard_codex. The combination flow passesstandalone=False, which suppresses each sub-onboarder's own Codex backfill and closing banner. The combination leg runs the Codex backfill exactly once and prints the banner exactly once at the end. Single-path flows (--claude-code/--codexalone) keepstandalone=Trueand are unchanged — they still backfill + print once. Both Codex return points (the "already configured" fast path and the main path) honor the flag.[#430 P1] Wrong reinstall hint after successful package removal
After
pipx uninstall tokenjamsucceeds the venv is gone, sopipx upgrade tokenjamfails ("not installed"). Added_package_fresh_install_hint()(barepipx install/pip install) used only on the successful-removal path. The existing_package_reinstall_hint()(upgrade /--force) stays where it's correct — when the package REMAINS in place (a plain install no-ops there).[#430 P2]
--remove-packagehelp + prompt wordingThe help said "runs pipx/pip uninstall" but for non-pipx installs it only PRINTS the command. Reworded the option help and the interactive confirm prompt so they say "runs" for pipx-managed installs and "prints … for you to run" for pip/venv installs.
[#431 P2] Whitespace-only ingest secret
if self._ingest_secret:was truthy for" ", producingBearer— the same illegal header value the empty case already guards. Now guard on.strip()so a blank/whitespace-only secret omits theAuthorizationheader.[#433 P2] Per-span SELECT idempotency in
ingest_codexingest_codexissued oneSELECT 1 FROM spans WHERE span_id=$1per span. Aligned it with the Claude Code path (core.backfill._insert_session_idempotent) by reusing that module's_existing_span_idshelper — one chunkedWHERE span_id IN (...)per session partitions new-vs-existing spans, replacing the per-span existence SELECT. Backends without aconn(InMemoryBackend) fall back to plain inserts and let the PRIMARY KEY conflict skip duplicates. Straightforward reuse of the existing shared helper (no raw-SQL duplication; inserts still go throughdb.insert_span), so this was done here rather than deferred. No circular import (backfilldoes not import fromingest_adapters.codex).Tests / Verification
tests/unit/test_onboard_path_branch.py::TestCombinationPathNoDoubleRun— the key one: combination path backfills Codex ONCE, prints the banner ONCE (incl. a Codex-only variant), and calls both sub-onboarders withstandalone=False.tests/integration/test_cli_uninstall.py— after a successful removal the reinstall hint ispipx install(and NOTpipx upgrade); prompt wording matches install type.tests/unit/test_http_exporter_auth.py— whitespace-only secrets (" ","\t","\n", …) omit theAuthorizationheader.tests/unit/test_backfill_codex.py— a DuckDB-backed idempotency test exercises the new bulk_existing_span_idspath (the existing idempotency test used InMemoryBackend, which hits the fallback branch).ruff check tokenjam/clean;mypyclean on the four touched source files. 184 tests pass in the onboard/backfill/codex/exporter/uninstall sweep.What's NOT in this PR
F401unused-import warnings intests/unit/test_onboard_path_branch.py(backfill_mod) andtests/integration/test_cli_uninstall.py(subprocess) — present before this change, out of scope.tokenjam/itself is ruff-clean.🤖 Generated with Claude Code