Skip to content

[REF-1474] fix: make PTC tool call IDs Bedrock-safe#2262

Merged
alchemistklk merged 1 commit into
mainfrom
ptc-tool-call-id-pr
Mar 3, 2026
Merged

[REF-1474] fix: make PTC tool call IDs Bedrock-safe#2262
alchemistklk merged 1 commit into
mainfrom
ptc-tool-call-id-pr

Conversation

@nettee

@nettee nettee commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes Bedrock compatibility issues caused by PTC tool call IDs containing :. New PTC IDs now use a Bedrock-safe format while preserving compatibility for legacy records.

Changes

  • Changed tool execution call ID generation from type:uuid to type_uuid
  • Added a shared helper to generate tool execution call IDs for ptc and standalone
  • Updated action message DTO PTC detection to support both legacy ptc: and new ptc_ prefixes
  • Added and marked implemented spec documentation for REF-1474

Summary by CodeRabbit

  • Bug Fixes

    • Improved detection of PTC tool call IDs to recognize both legacy ("ptc:") and new ("ptc_") prefixes, preserving backward compatibility and reducing validation errors.
  • New Features

    • Added a standardized Bedrock-safe tool call ID generator that emits underscore-separated IDs to avoid colon-related validation issues.
  • Documentation

    • Added a specification outlining the compatibility approach, rollout plan, and edge-case handling.

@linear

linear Bot commented Mar 2, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Mar 2, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Update introduces a Bedrock-safe PTC tool call ID generator that uses an underscore separator, switches the tool execution service to use it, and adjusts DTO detection to accept both legacy ptc: and new ptc_ prefixes; a spec document describing the change was added.

Changes

Cohort / File(s) Summary
Tool Call ID Generation
apps/api/src/modules/tool/ptc/tool-call-id.ts, apps/api/src/modules/tool/ptc/tool-execution.service.ts
Add ToolExecutionCallType and generateToolExecutionCallId() producing {callType}_{uuid}; tool-execution.service replaced inline :{uuid} construction with the new generator and updated JSDoc.
PTC Detection Logic
apps/api/src/modules/action/action.dto.ts
actionMessagePO2DTO's isPtc detection now recognizes both ptc: and ptc_ prefixes to include legacy and new IDs.
Specification
specs/change/20260302-bedrock-compatible-ptc-tool-call-id/spec.md
New spec documenting Bedrock compatibility issue, design, implementation plan, rollout, and edge-case handling for underscore-separated PTC IDs.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client as Client
  participant PTCService as PTC Execute Service
  participant IDGen as Tool Call ID Generator
  participant DB as Persistence
  participant Replay as Replay/History

  Client->>PTCService: request execute PTC
  PTCService->>IDGen: generateToolExecutionCallId('ptc')
  IDGen-->>PTCService: returns "ptc_<uuid>"
  PTCService->>DB: persist tool_call_result/action_message with toolCallId
  DB-->>Replay: store record (legacy ":" IDs remain unchanged)
  Replay->>PTCService: replay history (no normalization)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • alchemistklk
  • mrcfps

Poem

🐰 I hopped through lines and changed a sign,
Colon to underscore, tidy and fine.
UUIDs nestled, safe and bright,
Bedrock-friendly through day and night.
A small nibble, a safer bite.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: making PTC tool call IDs Bedrock-safe by switching from colon to underscore format.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ptc-tool-call-id-pr

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Mar 2, 2026

Copy link
Copy Markdown

Deploying refly-branch-test with  Cloudflare Pages  Cloudflare Pages

Latest commit: 998578f
Status: ✅  Deploy successful!
Preview URL: https://8ccbf22a.refly-branch-test.pages.dev
Branch Preview URL: https://ptc-tool-call-id-pr.refly-branch-test.pages.dev

View logs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
apps/api/src/modules/tool/ptc/tool-call-id.ts (1)

5-6: Add JSDoc for the exported generator function.

A short JSDoc block will document the Bedrock-safe format contract for callers.

📝 Proposed update
+/**
+ * Generates a Bedrock-safe tool execution call ID in the format `{callType}_{uuid}`.
+ */
 export const generateToolExecutionCallId = (callType: ToolExecutionCallType): string => {
   return `${callType}_${randomUUID()}`;
 };

As per coding guidelines, **/*.{js,ts,jsx,tsx}: Use JSDoc style comments for functions and classes in JavaScript/TypeScript.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api/src/modules/tool/ptc/tool-call-id.ts` around lines 5 - 6, Add a
JSDoc block above the exported function generateToolExecutionCallId describing
its purpose, parameters, return value, and the Bedrock-safe format contract;
include a one-line summary, `@param` for callType (type ToolExecutionCallType)
explaining allowed values, and `@returns` noting it returns a string in the format
"<callType>_<UUID>" (UUID generated via randomUUID) so callers know the exact
format and safety guarantees.
apps/api/src/modules/action/action.dto.ts (1)

49-49: Extract PTC prefixes into a shared constant/helper.

Line 49 hardcodes 'ptc:' and 'ptc_'. Centralizing these avoids format drift between ID generation and detection.

♻️ Proposed refactor
+const PTC_TOOL_CALL_PREFIXES = ['ptc:', 'ptc_'] as const;
+
 export function actionMessagePO2DTO(message: ActionMessageModel): ActionMessage {
-  const isPtc = message.toolCallId?.startsWith('ptc:') || message.toolCallId?.startsWith('ptc_');
+  const isPtc = PTC_TOOL_CALL_PREFIXES.some(
+    (prefix) => message.toolCallId?.startsWith(prefix) ?? false,
+  );
   return {

As per coding guidelines, Avoid magic numbers and strings - use named constants in TypeScript/JavaScript.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api/src/modules/action/action.dto.ts` at line 49, The code in
action.dto.ts computes isPtc using hardcoded strings ('ptc:' and 'ptc_')—extract
these into a shared constant or helper to avoid magic strings and format drift:
create a named constant (e.g., PTC_PREFIXES or PTC_PREFIX_SET) or a helper
function (e.g., isPtcId(toolCallId: string)) in a common utils/constants module,
replace the inline startsWith checks that reference message.toolCallId and the
local isPtc variable with a call to that helper or a check against the shared
constant, and update any other places that generate or validate PTC IDs to use
the same constant/helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@specs/change/20260302-bedrock-compatible-ptc-tool-call-id/spec.md`:
- Line 59: The spec currently contradicts itself about legacy replay
normalization: the "two-layer fix" phrase referencing "replay-time
normalization" conflicts with later statements that "normalization is not
implemented." Choose one consistent decision and update all mentions
accordingly—either (A) state that source-format correction is applied and
replay-time normalization for legacy IDs will be implemented (replace "not
implemented" language in the sections that reference Lines 73 and 117-118 with a
plan and brief implementation note), or (B) state that only source-format
correction is applied and explicitly remove/replace any claims of replay-time
normalization (remove "two-layer fix" wording and update the lines mentioning
normalization). Locate and edit the phrases "two-layer fix", "replay-time
normalization", and "legacy replay normalization" so the spec consistently
reflects the chosen approach across the sections that currently conflict.

---

Nitpick comments:
In `@apps/api/src/modules/action/action.dto.ts`:
- Line 49: The code in action.dto.ts computes isPtc using hardcoded strings
('ptc:' and 'ptc_')—extract these into a shared constant or helper to avoid
magic strings and format drift: create a named constant (e.g., PTC_PREFIXES or
PTC_PREFIX_SET) or a helper function (e.g., isPtcId(toolCallId: string)) in a
common utils/constants module, replace the inline startsWith checks that
reference message.toolCallId and the local isPtc variable with a call to that
helper or a check against the shared constant, and update any other places that
generate or validate PTC IDs to use the same constant/helper.

In `@apps/api/src/modules/tool/ptc/tool-call-id.ts`:
- Around line 5-6: Add a JSDoc block above the exported function
generateToolExecutionCallId describing its purpose, parameters, return value,
and the Bedrock-safe format contract; include a one-line summary, `@param` for
callType (type ToolExecutionCallType) explaining allowed values, and `@returns`
noting it returns a string in the format "<callType>_<UUID>" (UUID generated via
randomUUID) so callers know the exact format and safety guarantees.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b38f4b7 and b9a737b.

📒 Files selected for processing (4)
  • apps/api/src/modules/action/action.dto.ts
  • apps/api/src/modules/tool/ptc/tool-call-id.ts
  • apps/api/src/modules/tool/ptc/tool-execution.service.ts
  • specs/change/20260302-bedrock-compatible-ptc-tool-call-id/spec.md

Comment thread specs/change/20260302-bedrock-compatible-ptc-tool-call-id/spec.md Outdated
- change PTC call ID generation from colon format to underscore format for Bedrock compatibility\n- centralize call ID creation in a shared helper used by tool execution\n- keep action message PTC detection compatible with both legacy ptc: and new ptc_ IDs\n- add implemented spec document for REF-1474
@nettee nettee force-pushed the ptc-tool-call-id-pr branch from 339b404 to 998578f Compare March 2, 2026 12:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
specs/change/20260302-bedrock-compatible-ptc-tool-call-id/spec.md (1)

73-73: Consider making external references self-contained.

Lines 73 and 117 reference external context ("per approval" and "based on implementation checkpoint decision") that isn't documented within the spec. While not incorrect, making these self-contained would improve clarity for future readers.

📝 Optional wording improvements for self-containment
-2. Keep replay behavior unchanged (per approval: no legacy ID normalization).
+2. Keep replay behavior unchanged (no legacy ID normalization to avoid complexity).
-  - Legacy historical IDs are **not** normalized at replay time, based on implementation checkpoint decision.
+  - Legacy historical IDs are **not** normalized at replay time (deferred to reduce implementation scope).

Also applies to: 117-117

Also applies to: 117-117

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@specs/change/20260302-bedrock-compatible-ptc-tool-call-id/spec.md` at line
73, The spec references external context in the phrases "Keep replay behavior
unchanged (per approval: no legacy ID normalization)" and "based on
implementation checkpoint decision"; replace those parenthetical notes with
self-contained statements that either summarize the decision and its rationale
or link to an internal appendix section in this document (e.g., add a short
explanation like "approved by the design committee on [date]: replay retains
legacy IDs; no normalization" or "per implementation checkpoint: decision to
retain legacy ID behavior for compatibility") so readers can understand the
constraint without external context and add an internal reference section if
needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@specs/change/20260302-bedrock-compatible-ptc-tool-call-id/spec.md`:
- Line 73: The spec references external context in the phrases "Keep replay
behavior unchanged (per approval: no legacy ID normalization)" and "based on
implementation checkpoint decision"; replace those parenthetical notes with
self-contained statements that either summarize the decision and its rationale
or link to an internal appendix section in this document (e.g., add a short
explanation like "approved by the design committee on [date]: replay retains
legacy IDs; no normalization" or "per implementation checkpoint: decision to
retain legacy ID behavior for compatibility") so readers can understand the
constraint without external context and add an internal reference section if
needed.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 339b404 and 998578f.

📒 Files selected for processing (4)
  • apps/api/src/modules/action/action.dto.ts
  • apps/api/src/modules/tool/ptc/tool-call-id.ts
  • apps/api/src/modules/tool/ptc/tool-execution.service.ts
  • specs/change/20260302-bedrock-compatible-ptc-tool-call-id/spec.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/api/src/modules/tool/ptc/tool-call-id.ts
  • apps/api/src/modules/tool/ptc/tool-execution.service.ts
  • apps/api/src/modules/action/action.dto.ts

@alchemistklk alchemistklk merged commit 2a6fc1c into main Mar 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants