Skip to content

fix: use Object.hasOwn instead of in operator in usage bar translator#98139

Closed
zhangLei99586 wants to merge 2 commits into
openclaw:mainfrom
zhangLei99586:fix/in-operator-prototype
Closed

fix: use Object.hasOwn instead of in operator in usage bar translator#98139
zhangLei99586 wants to merge 2 commits into
openclaw:mainfrom
zhangLei99586:fix/in-operator-prototype

Conversation

@zhangLei99586

@zhangLei99586 zhangLei99586 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Related: #98466

What Problem This Solves

key in table checks prototype chain — toString/constructor match Object.prototype instead of fallthrough.

Why This Change Was Made

Replace key in table with Object.hasOwn(table, key) in alias + case table lookup (2 lines).

User Impact

Fixes incorrect usage bar rendering when keys coincide with prototype names.

Evidence

Runtime terminal proof (Node v24.13.1):

screenshot

  • 15/15 tests passed + 2 new regression tests (translator.test.ts)
  • renderUsageBar(tpl, {m:"toString"}) → "owned-value" — Object.hasOwn verified

@clawsweeper

clawsweeper Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed July 1, 2026, 5:14 AM ET / 09:14 UTC.

Summary
The PR changes usage-bar alias and map lookups from prototype-chain membership checks to Object.hasOwn and adds prototype-key regression tests.

PR surface: Source 0, Tests +25. Total +25 across 2 files.

Reproducibility: yes. Source inspection of current main and v2026.6.11 shows prototype-chain in checks on user-authored alias and map case tables, so keys like toString and constructor can take the wrong lookup path.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #98466
Summary: The linked issue is the canonical report for the usage-bar prototype-chain lookup bug; this PR is one candidate fix, and another open PR overlaps the same root cause.

Members:

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

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🦪 silver shellfish
Result: blocked by patch quality or review findings.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Make the alias regression test type-safe by giving the template or alias table a narrowed type before mutating it.
  • Rerun the focused translator test and test type check after the test setup change.

Risk before merge

  • [P1] Strict test type checking should fail until the alias regression setup narrows or constructs a typed alias table before mutation.

Maintainer options:

  1. Decide the mitigation before merge
    Keep the Object.hasOwn production fix, but make the alias regression setup type-safe before merging this PR.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] There is one narrow mechanical test typing blocker that an automated repair can fix on the PR branch without changing the production lookup behavior.

Security
Cleared: The diff only narrows usage-bar lookup behavior and adds tests; it does not touch dependencies, workflows, permissions, secrets, package metadata, or code execution paths.

Review findings

  • [P1] Type the alias table before mutating it — src/auto-reply/usage-bar/translator.test.ts:71
Review details

Best possible solution:

Keep the Object.hasOwn production fix, but make the alias regression setup type-safe before merging this PR.

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

Yes. Source inspection of current main and v2026.6.11 shows prototype-chain in checks on user-authored alias and map case tables, so keys like toString and constructor can take the wrong lookup path.

Is this the best way to solve the issue?

Mostly yes. The production Object.hasOwn change is the narrow maintainable fix, but the PR should only merge after the alias regression setup is made type-safe.

Full review comments:

  • [P1] Type the alias table before mutating it — src/auto-reply/usage-bar/translator.test.ts:71
    tpl() returns UsageBarTemplate, which is just Record<string, unknown>, so t.aliases remains unknown here. Strict test type checking should reject this property chain; construct a typed template shape or narrow the alias table before assigning toString.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against f3ac874fd215.

Label changes

Label justifications:

  • P3: This is a low-blast-radius usage-footer edge-case bugfix rather than an urgent runtime outage.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦞 diamond lobster and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (screenshot): The PR body/comment include a terminal screenshot, inspected locally, showing after-fix renderUsageBar behavior for the prototype-key alias and map paths.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body/comment include a terminal screenshot, inspected locally, showing after-fix renderUsageBar behavior for the prototype-key alias and map paths.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR body/comment include a terminal screenshot, inspected locally, showing after-fix renderUsageBar behavior for the prototype-key alias and map paths.
Evidence reviewed

PR surface:

Source 0, Tests +25. Total +25 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 1 25 0 +25
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 28 3 +25

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/auto-reply/usage-bar/translator.test.ts.
  • [P1] pnpm check:test-types.

What I checked:

Likely related people:

  • Peetiegonzalez: Merged PR metadata for the native templated usage footer lists commits by this account that introduced the translator engine, tests, and template contract used by this bug path. (role: usage renderer commit author; confidence: high; commits: 505539c89929, f1cca6ee2716, ba7275e95974; files: src/auto-reply/usage-bar/translator.ts, src/auto-reply/usage-bar/translator.test.ts, src/auto-reply/usage-bar/template.ts)
  • Marvinthebored: GitHub search and PR metadata identify this account as the author of the merged native usage footer renderer and built-in footer PRs that define this usage-template surface. (role: feature PR author; confidence: high; commits: 505539c89929, b07d4c79ba16; files: src/auto-reply/usage-bar/translator.ts, src/auto-reply/usage-bar/default-template.ts, docs/concepts/usage-tracking.md)
  • obviyus: This account merged the native usage footer renderer PR and authored several follow-up commits tightening the usage footer template behavior and docs/tests. (role: merger and recent usage-template contributor; confidence: high; commits: d3688d978b23, 89b7e837d14d, 071c82355309; files: src/auto-reply/usage-bar/translator.ts, src/auto-reply/usage-bar/default-template.ts, docs/concepts/usage-tracking.md)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jun 30, 2026

@zhangLei99586 zhangLei99586 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@clawsweeper re-review

@zhangLei99586

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@zhangLei99586

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

The 'in' operator checks the prototype chain, so keys like 'toString',
'valueOf', or 'constructor' would incorrectly match inherited properties
on vocabulary alias tables and segment case tables.

Replace with Object.hasOwn() which only checks own properties.
Add focused tests proving Object.hasOwn correctly distinguishes own
properties from inherited Object.prototype keys (toString, constructor)
in both alias vocabulary lookup and segment case table lookup.
@zhangLei99586
zhangLei99586 force-pushed the fix/in-operator-prototype branch from c9d9f0e to 94a5d9b Compare July 1, 2026 06:30
@zhangLei99586

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@zhangLei99586

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@zhangLei99586

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

1 similar comment
@zhangLei99586

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@zhangLei99586

Copy link
Copy Markdown
Contributor Author

Runtime behavior proof — terminal output from after-fix execution:

proof

@zhangLei99586

Copy link
Copy Markdown
Contributor Author

Runtime behavior proof (terminal output):

proof

@zhangLei99586

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

2 similar comments
@zhangLei99586

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@zhangLei99586

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. labels Jul 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Thanks for the patch. I’m closing this because the same usage-bar Object.hasOwn fix for #98466 has already landed through the canonical PR #98503, merged as 73e6a62.

This branch now overlaps the landed implementation, so keeping it open would just create duplicate churn.

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

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants