Skip to content

fix(registry): intro post preserves curated displayName (#62 follow-up) - #408

Merged
samxu01 merged 1 commit into
mainfrom
fix/intro-preserves-displayname
May 19, 2026
Merged

samxu01 merged 1 commit into
mainfrom
fix/intro-preserves-displayname

Conversation

@samxu01

@samxu01 samxu01 commented May 19, 2026

Copy link
Copy Markdown
Contributor

Follow-up to PR #406. Caught during verification — the intro flow was the other displayName-clobber path.

PR #406 fixed the direct getOrCreateAgentUser call in /api/registry/install
but missed the post-install intro path: line 362 rebound
\`displayName = installation.displayName || agent.displayName\` then forwarded
it to AgentMessageService.postMessage, which forwards it back to
getOrCreateAgentUser. End result: even when the caller doesn't pass
displayName, the intro flow still passes "Cuz 🦞" (registry default)
and Aria/Pixel/Cody's User row displayName gets sticky-dedup-suffixed
to "Cuz 🦞 (Aria)".

Verified empirically post-#406 deploy: installed openclaw/aria into a
fresh test pod without passing displayName; her User row went from
"Aria" to "Cuz 🦞 (Aria)" anyway.

Fix: in the intro flow, look up the existing User row's curated
displayName first and prefer it over installation.displayName /
agent.displayName. Falls back to the legacy chain on lookup error
(don't take down the intro flow for a transient mongo hiccup).
@samxu01
samxu01 merged commit 880069a into main May 19, 2026
1 check passed
@samxu01
samxu01 deleted the fix/intro-preserves-displayname branch May 19, 2026 01:26
samxu01 pushed a commit that referenced this pull request May 21, 2026
…tallation (#412)

PR #408 fixed the displayName-clobber on the intro-post path; this is
the matching fix for the install-path itself. Surfaced 2026-05-20 in
a fresh smoke pod: installing six existing dev-agent identities
(openclaw:theo/nova/pixel/aria/ops + codex:cody) wrote the registry-
default ('Cuz 🦞' for openclaw, 'Codex' for codex) into BOTH
AgentInstallation.displayName AND AgentProfile.name. The V2 inspector
member list reads AgentProfile FIRST, so every member rendered as
'Cuz'.

Fix: before writing either row, look up the existing User row for the
SAME (agentName, instanceId) and prefer its botMetadata.displayName.
Resolution order: explicit caller intent → existing curated identity
→ registry default. Both write seams read the same resolved value.

Regression test covers three cases.

Closes #412.

Co-Authored-By: Lily Shen <ls111@rice.edu>
samxu01 added a commit that referenced this pull request May 22, 2026
Captures the patterns CodeQL's js/sql-injection and js/nosql-injection
queries accept as sanitizers, plus the anti-patterns. Backed by the
two recent PRs:

- PR #408 — String + replace + roundtrip + test gate (canonical
  scalar-field sanitizer pattern). Used in install.ts:114-119.
- PR #413 — ObjectId.isValid + cast (canonical ObjectId-field
  sanitizer). The 5-iteration CodeQL battle that drove the
  in-memory-Set refactor for user-tainted regex captures is also
  documented as the case where the standard sanitizer chain isn't
  enough and the right move is to remove the tainted value from
  the query entirely.

Suggested by code-review feedback on PR #413: 'a pattern doc or
skill for user-tainted string into Mongoose filter is worth adding.
The five CodeQL iterations on this single PR are a cost that
future authors will pay again.'
lilyshen0722 added a commit that referenced this pull request Sep 3, 2026
…2) (#1503)

* fix(install): AgentInstallation is canonical for displayName (TASK-032)

Sam ruled TASK-032's fork on 2026-09-02: the installation owns a display
name; `User.botMetadata.displayName` is a seed for an installation that has
none, never a preference over one that does. This is the code half — the
schema doc is #1097.

Two sites in `routes/registry/install.ts` preferred the curated User row:

- `effectiveDisplayName` never consulted AgentInstallation at all, so a
  reinstall re-seeded the per-pod label from the shared User row and a name
  curated for THIS pod silently reverted. Precedence is now explicit caller
  > this pod's existing installation > User-row seed > registry default.
- the intro-post label re-queried `User.botMetadata` and put it ahead of
  `installation.displayName`. That query is dropped: the installation row was
  resolved through the full chain a few lines above, so the second lookup
  could only disagree with the row just written.

Task #62 / PR #408 is not reinstated. The User-row seed still beats the
registry default, so installing an existing identity into a NEW pod — where
no installation exists — still writes "Aria" rather than the manifest
default to both AgentInstallation.displayName and AgentProfile.name. Only
the both-are-curated case changes, and there the per-pod value wins, which
is what the read paths (agentMessageService:1461, dmService:555) already do.

The reachable shape is uninstall-then-reinstall, not install-twice: an
active row 400s at the route, so a second install meets an existing row only
on the reactivation path, where ADR-001 §3 identity continuity preserves it.
The new test covers exactly that and fails against main's install.ts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(install): stringify podId in the installation displayName lookup

CodeQL flags the re-install lookup at `install.ts` because `podId` reaches
the query straight from the request body: a JSON object there would be
interpreted as a query operator rather than a value. The route already
404s on `Pod.findById(podId)` above, so this was not reachable in
practice — but the guard is upstream and invisible at the query, and the
same file already spells the safe form at `pod: String(podId)`.

Coercing at the query makes the operator shape unconstructable regardless
of what the upstream guard does later, which is the cheaper invariant.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(install): reject a non-string podId at the entry point

@sprint-review ran the CodeQL alert rather than reading it and the
false-positive premise it was dismissed on does not hold. The premise was
that `Pod.findById(podId)` + 404 above already rejects anything that is
not a real id. Mongoose casts an operator object in a filter position
rather than throwing, so `Pod.findById({ $ne: null })` matches the first
pod in the collection and the 404 never fires.

That matters more than the one line the alert names, because `podId`
reaches four Mongoose filters on this route unchanged — `Pod.findById`,
the already-installed `AgentInstallation.findOne`, the installation
displayName lookup, and the `AgentProfile.findOneAndUpdate` upsert KEY.
Coercing at one query left the other three.

Guard at the entry point instead, in the shape `agentName` already uses
directly above. `undefined`/`null` still fall through to the existing 404
and the self-serve 400, so no legitimate path changes status code. The
`String(podId)` from the previous commit stays: it is the form CodeQL
recognises as a barrier at the site it flagged.

The new suite carries the premise as an explicit positive control, so a
later refactor cannot turn it green for the wrong reason. Without the
guard the operator object gets past the 404 and the request 500s, so the
observable behaviour today is a crash rather than a cross-pod write.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(install): state the podId guard's coverage as a position, not a count

@sprint-review enumerated the route and found six Mongoose filters where the
comment claimed four, plus one the comment miscategorised: the installation
displayName lookup is already `String()`-coerced, so it was never a raw site.
Following the helpers the number is larger again — `AgentInstallation.install`
is a `findOne` AND a `create`, `ensureAgentInPod` is a third `Pod.findById`,
and `postMessage` fans podId out further.

So the count was the wrong instrument: it is a claim about how far the reader
followed the value, with no natural stopping point, and it decays on the next
refactor. The guard is at the entry point and returns before all of them, so
the property that holds is positional. Both comment sites restated the four,
so both are corrected.

Comments only — no executable line changes. 8/8 across the two suites.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>

This branch was previously deployed

1 inactive deployment
dev — 880069a7 Deployed May 19, 2026 by samxu01 via Build + push + helm upgrade #202
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.

1 participant