Skip to content

[Bug] Compiler loses __proto__ keys in object variable defaults #102

Open

Description

@BichengWang

Description

A quoted __proto__ dictionary key disappears from a mutable object default during compilation. With an object value, the compiler changes the default object's prototype instead of creating an own property. No parser, schema, lint, or compiler diagnostic is returned.

Steps to Reproduce

  1. Check out salesforce/agentscript at ace15eb2dc75564fd9e214385ac045c539056770 (current main).
  2. Parse the source below with @agentscript/parser, convert it with new Dialect().parse(mappingNode, AgentforceSchema), and run the Agentforce defaultRules() through LintEngine with agentforceSchemaContext.
  3. Pass the parsed value to compile() and inspect the payload entry in output.agent_version.state_variables, before any camelCase conversion.

Expected Behavior

The default has an own __proto__ property and serializes as:

{"__proto__":{"marker":"kept"},"normal":{"n":1}}

Actual Behavior

The default serializes as:

{"normal":{"n":1}}

Object.hasOwn(payload.default, '__proto__') is false, while Object.getPrototypeOf(payload.default).marker is "kept". A scalar value ("__proto__": "kept") is also lost. A "constructor": {"marker": "kept"} control retains its own key and value.

Environment

  • Node.js: 22.20.0
  • pnpm: 10.34.6
  • OS: macOS 27.0.1, arm64
  • Package: @agentscript/compiler, source checkout at the commit above
  • Parser: default JavaScript backend

Minimal Reproduction

config:
    agent_name: "TestBot"
    agent_type: "AgentforceServiceAgent"
access:
    default_agent_user: "test@example.com"
variables:
    payload: mutable object = {"__proto__": {"marker": "kept"}, "normal": {"n": 1}}
start_agent main:
    description: "Test"
    reasoning:
        instructions: ->
            | {!@variables.payload}

Additional Context

extractDictExpression() in packages/compiler/src/ast-helpers.ts assigns entries with result[key] = value on an ordinary object. For __proto__, that invokes the inherited setter. This is a different path from #88/#89: the loss is already present in the snake_case output of compile(), without calling snakeKeysToCamel. The dictionaries here are nonempty, so this also differs from #101's empty-dictionary loss.

Reproduced offline with assertions on object/scalar __proto__ values and the constructor control. The existing compiler suite passed (1,113 passed, 3 skipped), and the required TypeScript package builds passed. The standard dependency build was blocked by the missing tree-sitter CLI; no native-parser or full monorepo checks were run. No fix is included.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions