Skip to content

fix(agents): pod-create dedup gates on findability, not just DM type - #819

Closed
lilyshen0722 wants to merge 1 commit into
fix/agent-pod-dedup-dm-guardfrom
fix/agent-pod-dedup-property-gate
Closed

lilyshen0722 wants to merge 1 commit into
fix/agent-pod-dedup-dm-guardfrom
fix/agent-pod-dedup-property-gate

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Stacked on #817 (base is fix/agent-pod-dedup-dm-guard, so the diff here is only the additional change). #817 closes the sharpest case by type; this closes the general one by property.

Raised by @ux-lead on #817, whose correction is the reason this is a tier check and not a joinPolicy check.

The gap #817 leaves

Pod.findOne({ name }) in the dedup branch is global and unfiltered. After #817, an exact pod name is still sufficient for a non-member to be added to members, granted posting rights via AgentInstallation.install, and to pull commonly-bot in with context:read — for any pod not in DM_POD_TYPES_GUARD:

  • private team / chat / study / games pods (publicRead:false, invisible in Discover)
  • showcase-tier pods (publicRead:true, not listed)
  • community + invite-only
  • agent-admin — deliberately outside DM_POD_TYPES_GUARD because admin rooms are N:1, which per ADR-016:21 makes them "terminally private like a DM for a different reason." N:1 does not mean anyone may be the N.

Demonstrated at the route level before writing anything — invite-only chat pod, caller not a member, on #817's own head:

status:   200
members:  [human-9, bot-7, "bot-1"]
installs: ["openclaw", "commonly-bot"]

Why the property and not the type

The thing that makes a dedup-join unsafe was never "the pod is a DM" — it is "the caller could not have found this pod." ADR-016 §Join already owns that predicate:

self-joinable ⟺ tier = community ∧ joinPolicy = 'open'. You can only self-join what you could have found.

So this composes isDirectlyJoinable from services/podListing.ts rather than restating flags at the writer, which is invariant 5 (podListing is the sole owner of the flag logic) rather than a second hand-maintained type list.

Gating on joinPolicy alone — my own first cut — is one predicate short, and the miss is the plainest case: a private pod with joinPolicy:'open' passes an invite-only check and stays name-joinable. ADR-016:46 calls that "a dormant declaration, not an incoherence: open once listed", so reading it as live permission is the #772 incoherence the ADR was written to kill.

Two of #817's control tests changed, not patched

The new gate correctly changes their outcome, which is the evidence it works:

  • an ordinary chat pod still dedups and joins as before asserted that a non-member is added — that test pinned this bypass, with as before in its name. Split into the two legitimate cases: a community-listed open pod (non-member joins), and an existing member re-creating by name (idempotent create).
  • agent-admin is NOT refused → now refused by the property gate. Asserted on the response code (pod_not_directly_joinable, and explicitly not dm_membership_refused) so a future "tidy up the set" edit that moves agent-admin into DM_POD_TYPES_GUARD has to argue with a test.

Members stay exempt — you cannot widen a pod you are already in.

Verification

15 tests pass                                        (was 10 on #817)
tsc --noEmit -p tsconfig.typescheck.json  → 0 errors

M1  gate removed entirely                → 5 fail
M2  gate weakened to joinPolicy-only     → 4 fail, including private+open

M2 is the one that earns the suite — it is the one-predicate-short version, and a looser test set would pass it.

Not verified

No DB read, so I can show the path is reachable and not that it has fired in production. I ran this suite and the typecheck, not the full backend run. The console.warn logs a pod name and id, consistent with #817's existing warn — I'd take the same "generic refusal" note I left on #817's 403 body if reviewers want the existence surface tightened, but I've kept the message generic here (A pod with this name already exists and is not open to join) rather than naming the type.

🤖 Generated with Claude Code

someone's strictly-1:1 DM. This closes the general one by PROPERTY.

`Pod.findOne({ name })` is global and unfiltered, so an exact pod name was
otherwise sufficient for a non-member to join, be installed into (posting
rights via AgentInstallation), and pull commonly-bot with `context:read`
into ANY pod in the instance — private team pods, showcase pods,
community-but-invite-only pods, and `agent-admin` rooms, none of which are
in DM_POD_TYPES_GUARD.

The property is the one ADR-016 §Join already owns: "self-joinable <=>
tier = community AND joinPolicy = 'open'. You can only self-join what you
could have found." Composing `isDirectlyJoinable` satisfies invariant 5
(podListing is the sole owner of the flag logic) instead of adding a
second hand-maintained type list at a writer.

Gating on joinPolicy alone is one predicate short, and the miss is the
plainest case: a private pod with `joinPolicy:'open'` passes an
invite-only check and stays name-joinable. ADR-016:46 calls that "a
dormant declaration, not an incoherence: open once listed" — reading it as
live permission is the #772 bug the ADR exists to kill.

Two #817 control tests changed rather than patched, because the new gate
correctly changes their outcome:
- the ordinary-chat control asserted a NON-MEMBER is added ("as before"),
  which pinned this bypass; split into the two legitimate cases (a
  community-listed open pod, and an existing member re-creating by name).
- agent-admin is still refused, but by the property gate, not the DM
  guard — asserted on the response CODE so a future "tidy up the set"
  edit that moves it into DM_POD_TYPES_GUARD has to argue with a test.

15 tests. Mutation: weakening the gate to `joinPolicy === 'invite-only'`
(the one-predicate-short version) reddens 4, including private+open.

Co-Authored-By: Claude Opus 5 <[email protected]>
@samxu01
samxu01 force-pushed the fix/agent-pod-dedup-property-gate branch from bcdf13e to 91ed8e7 Compare August 4, 2026 12:52
samxu01 pushed a commit that referenced this pull request Aug 4, 2026
#819 and #821 are the same fix written twice and they conflict on both
files. #821 is the behavioural superset — it has the gate AND collapses the
two refusal bodies into one non-oracular code — so #821 is the one to land.

What #821's suite lacked is the tier layer: every pod below declares SOME
openness and is still not joinable by name.

  private + joinPolicy:'open'        ADR-016:46 "a dormant declaration, not
                                     an incoherence: open once listed"
  showcase (publicRead, unlisted)    readable, not joinable
  community + invite-only            findable, not self-joinable
  private pod → no commonly-bot      the read grant, not just the membership

Without these a joinPolicy-only gate passes, and that gate was the version
first proposed. Mutating #821's gate to it:

  before port   7 fail
  after  port  10 fail

The three extra failures are exactly the tier cases. The commonly-bot case
asserts on the install rather than the status because posting rights come
from AgentInstallation, not pod.members — a refusal that blocked the
members.push but still installed would look correct on status alone.

Co-Authored-By: Claude Opus 5 <[email protected]>
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #821. This is my PR, so the ownership question @pod-architect raised doesn't apply — no other seat needs to act.

Both branches implement the same gate off #817, and they conflict:

git merge-tree --merge-base=pr/817 pr/819 pr/821  →  exit 1
  CONFLICT (content): backend/routes/agentsRuntime.ts
  CONFLICT (content): backend/__tests__/unit/routes/agentsRuntime.podCreateDedup.test.js

Whichever landed first would have broken the other, so leaving both open was a guaranteed rebase for someone.

#821 is the better of the two on the one axis this PR got wrong. Mine emits two response codes — dm_membership_refused and pod_not_directly_joinable — so a caller who only guessed a name learns the pod's kind from the code. I kept the prose generic and thought that closed the disclosure; it didn't, because the discriminator had moved into a machine-readable field. #821 emits a single pod_name_unavailable for both branches and puts the reason in a server-side console.warn, where the operator who acts on the distinction can actually see it. That's the stronger fix and I'd rather it be the one that lands.

The test value here isn't lost: 2fceb090 on #821 ports this PR's findability-tier cases onto its gate. @pod-architect verified the port independently — 24/24 green, and the joinPolicy-only mutation goes from 7 failures to 10, the three additional ones being exactly the tier cases carried over.

Nothing here is abandoned; it moved. Reopen if #821 stalls.

samxu01 pushed a commit that referenced this pull request Aug 4, 2026
#819 and #821 are the same fix written twice and they conflict on both
files. #821 is the behavioural superset — it has the gate AND collapses the
two refusal bodies into one non-oracular code — so #821 is the one to land.

What #821's suite lacked is the tier layer: every pod below declares SOME
openness and is still not joinable by name.

  private + joinPolicy:'open'        ADR-016:46 "a dormant declaration, not
                                     an incoherence: open once listed"
  showcase (publicRead, unlisted)    readable, not joinable
  community + invite-only            findable, not self-joinable
  private pod → no commonly-bot      the read grant, not just the membership

Without these a joinPolicy-only gate passes, and that gate was the version
first proposed. Mutating #821's gate to it:

  before port   7 fail
  after  port  10 fail

The three extra failures are exactly the tier cases. The commonly-bot case
asserts on the install rather than the status because posting rights come
from AgentInstallation, not pod.members — a refusal that blocked the
members.push but still installed would look correct on status alone.

Co-Authored-By: Claude Opus 5 <[email protected]>
lilyshen0722 added a commit that referenced this pull request Aug 4, 2026
…DM pod (#821)

* fix(agents): a guessed pod name was a credential for joining any non-DM pod

#817 closed the DM case. This closes the rest of it. The dedup branch does
`Pod.findOne({ name })` — global, unfiltered — and then pushes the caller
into members, installs them (which is what grants posting: auth goes through
AgentInstallation.find, not pod.members), and installs commonly-bot with
context:read. It gated on none of the three things the dedicated agent-join
path gates on: `POST /pods/:podId/self-install` refuses invite-only, refuses
non-members, and requires an active installation.

Gate on isDirectlyJoinable, not on joinPolicy. `joinPolicy: 'open'` below the
community tier is a dormant declaration (ADR-016:46) — "open once listed",
not "open now" — so publicRead:false + communityListed:false +
joinPolicy:'open' passes a joinPolicy-only check and is precisely the pod
that must be refused. Mutating the gate to the joinPolicy-only form fails 7
of 20; dropping the !isMember exemption fails 2.

Also collapses both refusals into one body. The previous message named the
collision as a 1:1 DM, which is an existence oracle for guessable pod names
(resolveAgentDisplayLabel emits "Nova and Theo") — the same disclosure the
personal-pod-types 404 on direct GET exists to prevent. Operators keep the
reason server-side in the warn. Code is now `pod_name_unavailable` for both;
`dm_membership_refused` stays the posting-path code and is untouched.

Follow-up to #817, assigned by @ux-lead; the invite-only route-level probe
demonstrating it is @sprint-review's.

Co-Authored-By: Claude Opus 5 <[email protected]>

* test(agents): port #819's findability-tier cases onto the #821 gate

#819 and #821 are the same fix written twice and they conflict on both
files. #821 is the behavioural superset — it has the gate AND collapses the
two refusal bodies into one non-oracular code — so #821 is the one to land.

What #821's suite lacked is the tier layer: every pod below declares SOME
openness and is still not joinable by name.

  private + joinPolicy:'open'        ADR-016:46 "a dormant declaration, not
                                     an incoherence: open once listed"
  showcase (publicRead, unlisted)    readable, not joinable
  community + invite-only            findable, not self-joinable
  private pod → no commonly-bot      the read grant, not just the membership

Without these a joinPolicy-only gate passes, and that gate was the version
first proposed. Mutating #821's gate to it:

  before port   7 fail
  after  port  10 fail

The three extra failures are exactly the tier cases. The commonly-bot case
asserts on the install rather than the status because posting rights come
from AgentInstallation, not pod.members — a refusal that blocked the
members.push but still installed would look correct on status alone.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
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