Skip to content

fix(telemetry): the activation-funnel read no longer mints installation_id on a GET (abilityai/trinity-enterprise#545) - #2663

Merged
vybe merged 5 commits into
devfrom
feature/545-funnel-non-minting-read
Sep 9, 2026
Merged

vybe merged 5 commits into
devfrom
feature/545-funnel-non-minting-read

Conversation

@webmixgamer

@webmixgamer webmixgamer commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • GET /api/enterprise/telemetry/funnel reached the OSS get_or_create_installation_id, so on an install whose id was never minted the first admin open of Settings → Activation created the durable identity row from a read path — the get_or_create_*-on-a-read class (learnings 2026-08-05), third occurrence after Canary Slack alerts don't say which instance fired them #1987 and the ent#190 benchmark read.
  • OSS gains the non-minting read twin services/operator_intake_service.get_installation_id beside the writer: the stored id or None; blank / non-string reads as None; a read failure propagates rather than rendering as "not minted". The enterprise funnel read switches to it in its own PR (landing order below).
  • The writers' accessor mints through the write-once claim insert_setting_if_absent instead of an upsert — two workers that SELECT-miss together land one id and the loser reads the winner's back — closing the SELECT-then-upsert race Canary Slack alerts don't say which instance fired them #1987 recorded as pre-existing.
  • ActivationFunnelPanel.vue renders the footer through the pure funnelFormat.js with three honest states: minted; not minted for the backend's explicit null, naming the one writer an operator can actually reach (the updates opt-in under Settings → General — the wizard's first product event only fires on an empty fleet or ?onboarding=1); unavailable for an absent or malformed value. The touched line's two ink halves move onto the contract's ladder, count-neutral for the raw-colour ratchet.

Changes

  • src/backend/services/operator_intake_service.py — get_installation_id (new) and the claim-shape mint; services/instance_identity.py docstring follows (it had recorded the race as pre-existing).
  • src/frontend/src/components/settings/ActivationFunnelPanel.vue, src/frontend/src/components/settings/funnelFormat.js (new).
  • Tests: tests/unit/test_operator_intake.py (+9: read twin, read-only store, propagated read failure, writer and reader as one key, the racing claim), src/frontend/tests/unit/funnelFormat.spec.js (new: the three states, no blank phrase, a panel-wiring guard); tests/registry.json gains the intake file.
  • Docs: requirements §43.1 / §45, docs/memory/architecture/backend.md, feature-flows/telemetry-sharing.md, feature-flows/first-time-setup.md, the flows index, docs/PRODUCT_EVENTS.md, a learnings entry (the never-mint sentinel belongs on the write sink; a static guard covers what no fixture can), and the CSO diff report (no findings).

Cross-repo landing order

  1. This PR → dev. It moves no gitlink.
  2. The enterprise PR (draft until this one is on dev — enterprise CI checks out public dev, and its suite imports get_installation_id): the funnel read on the read twin, ActivationFunnel.installation_id nullable on the wire, tests/test_545_funnel_never_mints.py over a real throwaway store, the ent#190 fixture's sentinel moved onto the write sink. Linked in a comment below once opened.
  3. A chore(enterprise): bump the submodule pointer (fd25b47 -> …) PR on dev after 2 merges.

Until step 3 lands, the panel's not-minted branch is dormant: a pre-bump backend always answers a string, which renders exactly as today.

Test Plan

  • pytest tests/unit — 15023 passed, 28 skipped; the single red is the pre-existing test_1920 guard trip that only occurs on a clone with the enterprise submodule mounted (registered in the debt inbox; cannot occur on CI)
  • Enterprise suite on the private branch under seeds 106 / 7 / 2026 — 393 passed, 5 skipped each
  • vitest run — 2541 passed including both ratchets; check:tokens; vite build
  • Playwright smoke set against a live stack — 80 / 81; the one failure is an Agent Detail timing flake that passes 3 / 3 in isolation, on a page this diff cannot reach
  • /verify-local, full: backend + agent images built and import-smoked, clean boot with migrations, a real agent healthy on the agent network, integration 70 passed / 13 skipped / 2 registered deselects — pass
  • Live proof on a local instance: delete the id → the funnel answers null with the key present → the setting stays absent afterwards (no re-mint) → the restore round-trips verbatim; the footer eyeballed in both states
  • /review — no critical findings; /cso --diff — no findings

Refs abilityai/trinity-enterprise#545 — deliberately not a closing keyword: this public PR alone leaves the mint-on-read live (the caller sits in the submodule), so the issue is closed by Abilityai/trinity-enterprise#570 (Fixes #545 there, same repo) when the enterprise half lands.

🤖 Generated with Claude Code

webmixgamer and others added 2 commits September 9, 2026 17:42
…on_id on a GET (Abilityai/trinity-enterprise#545)

`GET /api/enterprise/telemetry/funnel` reached the OSS `get_or_create_installation_id`, so on an install whose id was never minted the first admin open of Settings → Activation created the durable identity row from a read path — the get_or_create_*-on-a-read class (ledger 2026-08-05), third occurrence after #1987 and the ent#190 benchmark read.

OSS half of the fix:
- `services/operator_intake_service.get_installation_id` — the non-minting read twin: the stored id or None; blank/non-string reads as None; a read failure propagates rather than rendering as "not minted". The enterprise funnel read switches to it in the private repo.
- The writers' accessor mints through the write-once claim `insert_setting_if_absent` instead of an upsert, so two workers that SELECT-miss together land one id and the loser reads the winner's back — closing the race #1987 recorded as pre-existing. Its docstring in `instance_identity.py` follows.
- `ActivationFunnelPanel.vue` renders the footer through the pure `funnelFormat.js` with three honest states — minted, not minted for the backend's explicit null (naming the one writer an operator can reach, the updates opt-in under Settings → General), unavailable for an absent or malformed value — and the touched line's two ink halves move onto the contract's ladder (count-neutral for the raw-colour ratchet).
- Tests: nine OSS cases (read twin, read-only store, propagated read failure, writer and reader as one key, the racing claim) and sixteen vitest cases plus a panel-wiring guard; `test_operator_intake.py` registered in tests/registry.json.
- Docs: requirements §43.1/§45, the backend architecture entry, the telemetry-sharing and first-time-setup flows, the index row, PRODUCT_EVENTS, a learnings entry (the sentinel belongs on the write sink; a static guard covers what no fixture can), and the CSO diff report (no findings).

The enterprise half — the funnel read on the read twin, `installation_id` nullable on the wire, the never-mint suite over a real store — lands through the submodule pointer after its own PR; this commit moves no gitlink.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@webmixgamer webmixgamer added the ui PR touches the frontend UI — triggers Playwright e2e tests label Sep 9, 2026
@webmixgamer

Copy link
Copy Markdown
Contributor Author

Enterprise half: Abilityai/trinity-enterprise#570 (draft until this PR is on dev; its CI checks out public dev and imports get_installation_id). After #570 merges, a chore(enterprise): bump the submodule pointer (fd25b47 -> …) PR on dev carries it.

@webmixgamer
webmixgamer requested a review from vybe September 9, 2026 17:32
@vybe

vybe commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

merge-train 2026-09-09: not on this train. The read-side rework is right and the tests genuinely bite (I reverted operator_intake_service.py to base and re-ran: 10 failed, 14 passed). One critical, verified against the real SQLite layer rather than the FakeDB.

The blank-row self-heal is destroyed, and the function can return "" permanently — src/backend/services/operator_intake_service.py:130-131

db.insert_setting_if_absent(_INSTALLATION_ID_KEY, str(uuid.uuid4()))
return db.get_setting_value(_INSTALLATION_ID_KEY, "") or ""

Given a system_settings row installation_id whose value is the empty string: existing is "" → falsy → falls through to mint; insert_setting_if_absent hits the PK conflict and does nothing; the read-back returns "". Forever, on every subsequent call.

[HEAD] stored before: ''   get_or_create -> ''                                      SELF-HEALED: False
[BASE] stored before: ''   get_or_create -> 'da729a58-5fdf-41bf-a8d1-5d11c8609245'  SELF-HEALED: True

dev heals this today; the PR removes that. Blast radius of the "": routers/product_events.py:76 keys every product event on the empty string — including the activation funnel this PR is about — and db/product_events.py:35 just persists, no validation. operator_intake_service.py:196 posts "installation_id": "" as the once-per-install correlation key. instance_identity.py:153 does ""[:8], so every canary alert from that install is permanently unlabelled. The declared contract is still -> str with a docstring promising "never regenerated".

Reachable via PUT /api/settings/installation_id {"value": ""} — the catch-all at routers/settings.py:2985 has ~12 if key == blocks and none for installation_id, and SystemSettingUpdate.value is a bare str with no min_length. Also via a partial restore or a manual DB edit.

This reads as an oversight rather than a judgement call, because the read twin at :151 explicitly handles blank values and is parametrized over ["", " ", None, 42, b"bytes"] — the blank case was reasoned about on one side and not carried to the other.

A shape that keeps the race-closing claim and the self-heal:

new_id = str(uuid.uuid4())
db.insert_setting_if_absent(_INSTALLATION_ID_KEY, new_id)
stored = db.get_setting_value(_INSTALLATION_ID_KEY, "")
if not stored:                      # blank row: the claim cannot overwrite it
    db.set_setting(_INSTALLATION_ID_KEY, new_id)
    stored = new_id
return stored

(" " is unaffected — whitespace is truthy at :120 and short-circuits identically on both branches. The regression is specific to "".) It needs a write-side test; the suite currently has the read-side blank cases only, which is why this shipped green.

Two things worth tracking while it is open:

  1. get_installation_id has zero consumers in OSS. Full-tree grep across src/backend, src/frontend, src/mcp-server and docker returns only its own definition, one docstring cross-reference, and tests. The actual mint-on-read is src/backend/enterprise/backend/telemetry/service.py:85, inside the submodule. On public dev standing alone, ent#545 is still live — which the body documents honestly, but it means Fixes abilityai/trinity-enterprise#545 will auto-close ent#545 at the next dev → main release. If enterprise#570 (draft, base main) or the pointer bump slips past that release, the issue closes while the bug ships. Worth weakening the keyword until the enterprise half is ready to land in the same release.
  2. Two docs assert the fixed state in the present tense without the caveat — docs/PRODUCT_EVENTS.md ("only ever read by the Activation panel") and docs/memory/requirements/lifecycle-observability.md §43.1 ("every read-shaped path … uses the non-minting twin"). Neither is true until the submodule bump. feature-flows.md does disclose it, so the omission is inconsistent rather than systematic.

Minor: funnelFormat.spec.js:72-74's second wiring guard is negative-only (not.toMatch ×2) and passes vacuously on an absent panel file — covered in practice by the positive assertion at :68-69, but a negative-only guard is not itself evidence.

Rides the next train once the self-heal is restored.

… row again — the claim cannot overwrite one (ent#545 review)

The first cut's write-once claim destroyed the pre-ent#545 self-heal: with a stored "" the SELECT-miss fell through to a claim the PRIMARY KEY refuses, and the read-back returned "" — forever — keying every product event, the intake POST and the canary label on the empty string. Reproduced against the real SQLite settings layer (blank row → '' stored, unhealed; whitespace row returned verbatim).

- `get_or_create_installation_id` now reads through the twin, claims on a miss, reads back, and — only when the row exists but holds nothing usable (the empty string, whitespace, a non-string: exactly what `get_installation_id` refuses) — heals it through the upsert, the one place `set_setting` is right, so the two accessors agree on what "minted" means. A healthy row is returned verbatim with no write; two workers healing the same corrupt row is last-write-wins, as it always was for that row.
- Tests: the corrupt-row heal parametrised over "", "   ", None and 42 on the FakeDB (healed IN the store, the read twin agrees, stable afterwards); a healthy row returned verbatim with a store that refuses writes; and the same proof on the REAL settings layer for "" and "   " — the shape that found the regression, since a stub that auto-succeeds passes with the bug intact.
- The PR body's closing keyword is weakened to `Refs`: this public PR alone leaves the mint-on-read live (its caller is in the submodule), so ent#545 is closed by trinity-enterprise#570's same-repo `Fixes` when the enterprise half lands. `docs/PRODUCT_EVENTS.md` and requirements §43.1 now state the rule with that pointer instead of asserting the fixed state in the present tense.
- `funnelFormat.spec.js`: the wiring guard gets a positive anchor on the exact assignment before its two negatives, so it cannot pass vacuously on an absent file.
- `tests/registry.json` re-serialised with the file's original ASCII escaping, so the #2618 entry is byte-identical again and the diff is purely additive.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@webmixgamer

Copy link
Copy Markdown
Contributor Author

Thanks — the critical is real and is fixed in a77e2fd, verified the way you found it.

Before, on the real SQLite settings layer (the first cut): blank row '' → get_or_create returned '' and the row stayed ''; whitespace row ' ' returned verbatim.
After (a77e2fd), same harness:

no row                 -> fresh uuid   stored=same  stable=True
blank row ''           -> fresh uuid   stored=same  stable=True  healed=True
whitespace row '   '   -> fresh uuid   stored=same  stable=True  healed=True
healthy row            -> verbatim     stored=same  stable=True  no write

Shape: read through the twin → claim on a miss → read back → heal through the upsert only when the row exists but holds what the read twin refuses ("", whitespace, non-string), so the two accessors agree on "minted"; a healthy row never reaches that branch. Whitespace is healed too, deliberately — the reader already treated it as not minted, so the writer returning it verbatim was the same asymmetry one step over. Write-side tests added on the FakeDB (parametrised over "", " ", None, 42; healed in the store, twin agrees, stable) and on the real SettingsOperations layer for "" and " ".

Tracking items: (1) closing keyword weakened to Refs in the body — ent#545 closes via #570's same-repo Fixes when the enterprise half lands; (2) PRODUCT_EVENTS.md and requirements §43.1 now state the rule with the pointer to #570 instead of the present tense. Minor: the spec's wiring guard has a positive anchor before its negatives. Also re-serialised tests/registry.json with its original escaping so the #2618 line is byte-identical again.

… previous re-serialisation escaped 84 unrelated lines (ent#545 review follow-up)

The a77e2fd re-dump used ensure_ascii, but only the #2618 entry carried escapes; the rest of the file is literal UTF-8, so 84 lines changed that this PR never meant to touch. The entry is now inserted by text into dev's bytes: the diff against dev is one new entry and the comma that joins it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@webmixgamer

Copy link
Copy Markdown
Contributor Author

Correction to my comment above: the tests/registry.json re-serialisation in a77e2fd was wrong, not "byte-identical again" — it escaped 84 unrelated lines (the file is literal UTF-8; only the #2618 entry had escapes). 32ead63 rebuilds the file from dev's exact bytes plus the one new entry, so the registry diff is now +12 / -0 against dev: the entry and the comma that joins it.

… plumbing (ent#545)

The guard asserted the import and the computed call, but nothing tied
`installFooter` to the DOM. Replacing the footer span with static text
while leaving `const installFooter = computed(...)` intact kept all 16
tests green -- the declared-but-unrendered shape that #2659 is about,
one inch from where the guard already looked.

Verified both directions: the assertion passes on the branch as-is, and
fails when the render is stripped.

merge-train: mechanical, per the merge-train note on the PR.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Lts14MGxLdPU5tvxL6CfAo
@vybe

vybe commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

merge-train 2026-09-09: on the train, and merging. The critical is fixed and I proved it the same way it was found rather than reading the diff — splicing the ejected first-cut body back into get_or_create_installation_id fails 6 tests, including both test_the_real_settings_layer_heals_a_blank_row cases against real SettingsOperations. 31 passed restored. The registry rebuild in 32ead637 checks out at +12 / −0 with every dev line verbatim, and all three tracking items landed: the keyword is correctly weakened to Refs (closing ent#545 from here would close it while the mint-on-read still ships), and both docs now carry the #570 caveat instead of the present tense.

The frontend half is genuinely wired — installIdFooter → installFooter → {{ installFooter.text }} in the template, fed from r.data?.installation_id. This is not the inert-client-half shape that took out three PRs earlier today.

One mechanical commit pushed to your branch — 854529ca. The wiring guard pinned the import and the computed call, but nothing tied the computed to the DOM. I replaced the footer span with static text, left const installFooter = computed(...) intact, and got 16/16 green — the declared-but-unrendered shape, one inch from where your guard was already looking. The fix is one line in the existing it:

expect(panel).toMatch(/\{\{\s*installFooter\.text\s*\}\}/)

Verified both directions: green on your branch as-is, red when the render is stripped. Your positive-anchor rewrite was the right instinct — this just carries it the last inch. Revert it freely if you'd rather shape it differently.

Three things not blocking the merge, on the record:

  1. The heal branch returns its own candidate, not the observed stored value (operator_intake_service.py:143-144). Two workers healing the same corrupt row both set_setting different UUIDs; the loser returns an id that is not what landed, so one product event or canary label can key on an orphan. Bounded, converging, and non-regressive — dev behaves identically for a blank row, and your comment says so explicitly. return get_installation_id() or new_id would converge it the way the claim path one screen above already does. Your call, not the train's, since you documented the choice.
  2. PUT /api/settings/installation_id is unguarded, and the heal is now load-bearing on it staying that way. Asymmetric with feat: record install provenance (DO Marketplace) + first-run HTTPS/VPN hardening guide #2380's treatment of install_source — the same write-once install provenance, blocked at both the route and the sink. Filed separately; the second-order note is that the natural hardening would make the heal raise and 500 the product-event POST.
  3. The committed CSO report describes the first cut. Its scope line is vs dev @ 3fa11329 and it asserts the id is minted "through a PRIMARY-KEY-enforced claim instead of a last-write-wins upsert" — the shipped code retains one on the heal branch at :143 — while item 36 reasons from insert_setting_if_absent deliberately skipping set_setting's sink guards, which the heal now goes through. No security consequence (installation_id matches none of _CREDENTIAL_SUFFIXES, and I confirmed the write passes the ent#435 guard), but the artifact now misdescribes its own diff. Worth a regenerate whenever you next run /cso --diff on this branch.

Also noted for whoever reads the record later: get_installation_id ships with zero OSS callers until #570 and the pointer bump land — that is the documented landing order, not drift. ent#545 will not auto-promote, so it needs status-in-dev by hand.

Merging once your required checks come back green on 854529ca.

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

merge-train 2026-09-09: validated at lane B. Ejection critical fixed and mutation-proven against real SettingsOperations; no criticals from /validate-pr or /review; 24/24 checks green on 854529c including regression diff.

@vybe
vybe merged commit 5a0cb00 into dev Sep 9, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants