[Bug] Compiler drops nested empty objects from variable defaults

Open Beginner friendly
#101 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@amazingjoe is already working on this.

Since Nov 14, 2026.

  • #114 by @amazingjoe — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
backend, testing

Research direction

Start with packages/compiler/src/ast-helpers.ts, especially extractDictExpression() and its callers that extract object defaults and array values. Reproduce the issue with the provided source and inspect output.agent_version.state_variables. Done when nested empty objects remain in both the payload and items defaults, with regression coverage for those cases.

Written by the indexing model from the issue text.

Description

Description

Empty objects inside object and list variable defaults disappear during compilation. This removes object properties and changes list lengths and element positions without a diagnostic.

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 the compiler's compile() and inspect output.agent_version.state_variables.

Expected Behavior

The payload default remains {"empty": {}, "full": {"n": 1}}, and the items default remains [{}, {"n": 1}, {}].

Actual Behavior

The compiler emits:

{"developer_name": "payload", "default": {"full": {"n": 1}}}
{"developer_name": "items", "default": [{"n": 1}]}

The parser, schema, lint engine, and compiler return no diagnostics for this source. A standalone mutable object = {} retains its empty default, and a list[string] = ["a", "b"] retains both elements.

Environment

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

Minimal Reproduction

config:
    agent_name: "TestBot"
    agent_type: "AgentforceServiceAgent"
access:
    default_agent_user: "[email protected]"
variables:
    payload: mutable object = {"empty": {}, "full": {"n": 1}}
    items: mutable list[object] = [{}, {"n": 1}, {}]
start_agent main:
    description: "Test"
    reasoning:
        instructions: ->
            | {[email protected]} {[email protected]}

Additional Context

extractDictExpression() in packages/compiler/src/ast-helpers.ts returns undefined for an empty dictionary. Its caller omits dictionary values that are undefined, and extractExpressionValue() filters them out of arrays. The same helper handles default extraction, so an empty dictionary is treated as a missing value when nested.

Reproduced offline through parse → schema → lint → compile, with assertions on both corrupted defaults and the standalone-object/string-list controls. The existing compiler suite passes (1,113 passed, 3 skipped), so it does not catch these cases. The standard dependency build was blocked by the missing tree-sitter CLI; the required TypeScript packages were built directly. No fix is included in this report.

Dominant language
TypeScript
Stars
279
Forks
55
Avg merge
1d 12h
Merged PRs (30d)
7

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from salesforce/agentscript

All issues in salesforce/agentscript

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.