Skip to content

fix(codex): let plugin tools see the recorded origin of a Control UI turn - #208244

Closed
LiuwqGit wants to merge 1 commit into
openclaw:mainfrom
LiuwqGit:feat/issue-208201-codex-tool-factory-provenance
Closed

LiuwqGit wants to merge 1 commit into
openclaw:mainfrom
LiuwqGit:feat/issue-208201-codex-tool-factory-provenance

Conversation

@LiuwqGit

Copy link
Copy Markdown
Contributor

AI-assisted: yes

Closes #208201

What Problem This Solves

  • Fixes an issue where plugin authors who gate a tool on verified human input would see no input origin at all on an ordinary Control UI turn: the Gateway records provenance.kind = "external_user" on the admitted message, but a contextVersion: 2 tool factory in a Codex run observed ctx.inputProvenance === undefined while ctx.senderIsOwner was true. Their integration stays disabled instead of mistaking the gap for a non-user origin.
  • Related: fix: keep WebChat input origin in native Codex prompt hooks #203467 (open) repairs the same gap for native Codex before_prompt_build hooks only; this PR covers the tool-construction boundary and does not touch that file. ClawSweeper review on the issue: "current main records external_user on ordinary WebChat input but omits it from the run context consumed by plugin tool factories", next step "preserve admitted input provenance before Codex tool factories run".

Why This Change Was Made

  • Intended outcome: Codex tool construction reads the origin the turn already recorded. resolveCodexAdmittedInputProvenance keeps an explicit producer origin (internal_system, inter_session) authoritative and otherwise falls back to the admitted user message (userTurnTranscriptRecorder.message, then its staged pending input), which is where chat.send stamps external_user for a non-synthetic client.
  • Out of scope: No change to run params, Gateway admission, prompt hooks, or tool policy inputs. Scheduled/creator authority checks read params.inputProvenance from the run and keep their undefined test, so they are untouched.
  • Highest-risk area: the value handed to createOpenClawCodingToolsAsync also feeds requester tool policy, where hasExternalRequester treats kind === "external_user" like a present sender field.
  • How is that risk mitigated? The fallback only fires for a turn whose own admitted record already says the input came from an external user, so policy sees the fact the transcript already carries rather than a new inference; a turn with neither an explicit origin nor a recorded one still constructs tools with no origin, and plugin policy that requires a verified origin keeps failing closed.

User Impact

  • Success criteria: on an authenticated Control UI turn in a Codex session, a v2 tool factory observes ctx.inputProvenance.kind === "external_user" for the same run whose stored input carries that provenance; an explicit system origin still arrives unchanged; missing provenance stays absent.
  • What should reviewers focus on? extensions/codex/src/app-server/turn-params.ts (resolveCodexAdmittedInputProvenance, next to the existing readCodexCurrentSender recorder read) and its single use in extensions/codex/src/app-server/dynamic-tool-build.ts. Regression fixtures: constructs tools with the admitted origin of an ordinary WebChat turn, ... of an explicit system origin, and constructs tools without an origin when the turn recorded none in extensions/codex/src/app-server/dynamic-tool-build.provenance.test.ts.

Evidence

  • Real environment tested: worktree aispace/worktrees/issue-208201 at base 03cdb2cef17, real Codex extension tool construction through buildDynamicTools.
  • Exact steps or commands run after this patch:
    # GREEN + format/lint/typecheck after the fix
    bash skills/fix-pr/scripts/validate.sh \
      extensions/codex/src/app-server/dynamic-tool-build.ts \
      extensions/codex/src/app-server/turn-params.ts \
      extensions/codex/src/app-server/dynamic-tool-build.provenance.test.ts
  • Evidence after fix:
    ✓ dynamic-tool-build.provenance.test.ts > constructs tools with the admitted origin of an ordinary WebChat turn 686ms
    ✓ dynamic-tool-build.provenance.test.ts > constructs tools with the admitted origin of an explicit system origin 19ms
    ✓ dynamic-tool-build.provenance.test.ts > constructs tools without an origin when the turn recorded none 21ms
    [test] passed 2 Vitest shards in 286.56s   # provenance + dynamic-tool-build + turn-params tests
    [validate] 全部通过 ✅                      # oxfmt, oxlint, vitest, tsgo:core
    
  • Observed result after fix: tool construction now receives { kind: "external_user", sourceChannel: "webchat" } for an admitted Control UI turn that carries no explicit run origin, and { kind: "internal_system", sourceTool: "restart" } is still passed through verbatim when the run supplies one.
  • Before evidence: on the unpatched base the same three fixtures (first written inside dynamic-tool-build.test.ts, then moved to the sibling file above because the repo's line-cap ratchet forbids growing that baseline file) fail with AssertionError: expected undefined to deeply equal { kind: 'external_user', sourceChannel: 'webchat' } — Tests 1 failed | 2 passed | 77 skipped (80). The two control cases already passed on base, which pins the change to the missing-fallback path.
  • What was not tested: no live Gateway/Control UI run and no real Codex model turn were executed here (Linux workspace, no authenticated Control UI session); the shipped-path observation in the report comes from the reporter's macOS build. Hosted CI lanes are pending on this PR.
  • Proof tier: L2 (focused regression on the real extension tool-construction path, RED on base and GREEN on head).

…turn

An ordinary Control UI turn stamps external_user on its admitted message but
leaves the run without an explicit origin, so a v2 plugin tool factory observed
no inputProvenance while senderIsOwner was true. Codex tool construction now
falls back to the origin the admitted input already recorded; an explicit
producer origin keeps precedence, and a turn with neither fact still constructs
tools without one so plugin policy keeps failing closed.

Fixes openclaw#208201
@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 29, 2026
@clawsweeper

clawsweeper Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded by #208252, which addresses the same tool-factory provenance gap with live Control UI/Codex proof while preserving tool-policy inputs.

Root-cause cluster
Relationship: superseded
Canonical: #208252
Summary: The replacement owns the same remaining factory-provenance repair; prompt-hook propagation remains a separate consumer.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Consolidate the repair in #208252 and retain the original report until that fix merges.

The same work is tracked in #208252. ClawSweeper will close this if the final checks pass. Please continue the discussion there.

Review details

Best possible solution:

Consolidate the repair in #208252 and retain the original report until that fix merges.

Do we have a high-confidence way to reproduce the issue?

The admitted-message producer and current-main factory forwarding establish the missing-field path, supported by the reporter’s official-build observation and contributor-reported red/green regression; this review executed no target code.

Is this the best way to solve the issue?

The replacement repairs the same observable problem at the host metadata boundary while retaining explicit provenance precedence and existing tool-policy inputs.

Security review:

Security review cleared: No concrete unauthorized effect or supply-chain regression was established.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit c034670 adds extensions/codex/src/app-server/turn-params.ts:25 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c034670b7299; files: extensions/codex/src/app-server/turn-params.ts)
  • computment: Raw commit d09b4bb adds extensions/codex/src/app-server/turn-params.ts:40 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: d09b4bb20a8e; files: extensions/codex/src/app-server/turn-params.ts)

Codex review notes: model internal, reasoning medium; reviewed against 39d230cc35fc.

@LiuwqGit

Copy link
Copy Markdown
Contributor Author

Follow-up pass on head 4e244fb4edb5. Two findings; no commits pushed.

1. This PR is superseded by #208252, which is now merged — no further work here.

#208252 landed in main as 767c5172581 (fix: let Codex plugin tools recognize direct Control UI input, Closes #208201 — the same report). It repairs the gap at the host boundary instead of inside the Codex extension: captureHarnessToolConstructionFacts derives recordedInputProvenance from the admitted turn's transcript recorder when the run carries no explicit origin, host-capability.ts spreads it into the tool-construction options, and resolveOpenClawPluginToolInputs falls back to it (options.inputProvenance ?? options.recordedInputProvenance), so a Codex v2 tool factory now receives ctx.inputProvenance.kind === "external_user" on a direct Control UI turn. Its host-capability.test.ts cases cover direct input, explicit system origin, internal retry and unattributed input through the pluginId: "codex" host.

That is the same observable behavior this branch produced extension-locally in turn-params.ts / dynamic-tool-build.ts, so rebasing and pushing forward would only add a second implementation of a fix already in main. I'm leaving the close to ClawSweeper/maintainers rather than churning the branch.

2. The red openclaw/ci-gate is not caused by this diff: no CI lane was ever dispatched for this head.

On 4e244fb4edb5 the check list holds only the 13 pull_request_target/review checks — zero CI workflow lanes (check-lint*, check-test-types, checks-node-*) — and gh run list --commit 4e244fb4… shows no CI run at all, only Auto response / ClawSweeper Dispatch / Security Review. ci-gate reports "CI must complete successfully", so it cannot turn green while no lane runs.

Same shape on the other cross-repository (fork) PRs opened today — #208265 and #208267 both have 0 CI lane checks — while PRs whose head branch lives in openclaw/openclaw got lanes normally in the same window (#208254: 18, #208259: 14, #208263: 5). For reference, my fork PRs merged last week did run CI (#201430: 13 lanes, ci-gate pass; #198598: 21 lanes, pass), so fork-side CI dispatch looks gated/broken repo-wide since then. Flagging it in case it is unnoticed; nothing in this branch can change it.

@vincentkoc vincentkoc self-assigned this Nov 30, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Superseded by #208252, now merged and covering the same tool-factory provenance gap. Prompt-hook work remains in #203467. Thanks for the regression coverage.

@vincentkoc vincentkoc closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex plugin tool factory does not receive external_user provenance on authenticated Control UI turns

2 participants