Skip to content

Large integers get rounded in harness tool input and the pretty JSON views #2992

Backlog

Description

@abhiramshaji-cyber

Description

Hey team, hope you're doing well! Really nice work on #2807, stringifyJson already keeps every digit for tool results at transcript.tsx#L100, and paymentContext.ts goes out of its way not to reserialize the caller's JSON. I noticed a few views that still reformat JSON with JSON.stringify(JSON.parse(text)), so integers above 2^53 show up rounded there.

These views are where people read what their agent actually did. compactJson in transcript.tsx#L76-L82 puts streamed tool input on one line, and it runs on every tool input at L194. The runtime and gateway invoke screens also build their ctrl+v pretty view the same way (runtime screen.tsx#L294, gateway screen.tsx#L313).

compactJson and its callers
compactJson and its callers, Functions view in Architect

Steps to Reproduce

  1. Run agentcore harness invoke --id <harness-id> to open the chat.
  2. Ask something that makes the agent call a tool with input like {"id": 1750000000000000001}.
  3. When the tool block stops, applyEvent runs compactJson on the input, which parses and reserializes it.

I didn't have a harness that returns a tool input like that, so I fed applyEvent the same stream events directly on v1.x (71bc760):

const turn = newTurn();
for (const e of [
  { messageStart: { role: "assistant" } },
  {
    contentBlockStart: {
      contentBlockIndex: 0,
      start: { toolUse: { toolUseId: "tu-1", name: "lookup" } },
    },
  },
  {
    contentBlockDelta: {
      contentBlockIndex: 0,
      delta: { toolUse: { input: '{"id": 1750000000000000001}' } },
    },
  },
  { contentBlockStop: { contentBlockIndex: 0 } },
])
  applyEvent(turn, e);
console.log(turn.items[0].input);

The runtime and gateway pretty views go through the same JSON.stringify(JSON.parse(...)) round trip after pressing ctrl+v on a JSON response; I read those from the source rather than running them.

Expected Behavior

The digits stay exactly as the agent sent them, only the whitespace changes.

Actual Behavior

The script above prints:

{"id":1750000000000000000}

The last digits get rounded to the nearest double. For the tool input there is no raw view to fall back to, so the real value is gone from the transcript. Since invokeHarnessTurn in operation.ts folds events through the same applyEvent and --prompt prints the resulting transcript, the one shot output should carry the rounded input too.

CLI Version

1.6.0 (v1.x at 71bc760)

Operating System

macOS

Additional Context

From what I can tell stringifyJson alone can't help here, because the digits are already lost at JSON.parse. Two options I can think of:

  1. Parse with a reviver that reads context.source for unsafe integers. The catch is that engines allows Node 20.12.0, which doesn't pass context.source.
  2. Reformat the whitespace without parsing numbers at all, so the original text is kept as is.

Which one would you prefer, or is there a better way I'm missing? Happy to open a PR for whichever fits best. Thanks so much!

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