You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/10/10 10:53:57 UTC

(maka) branch main updated: refactor(runtime-host): consolidate the private byte-limit helpers into the protocol codec (#5887)

This is an automated email from the ASF dual-hosted git repository.

Astro-Han pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/maka.git


The following commit(s) were added to refs/heads/main by this push:
     new f628acf861 refactor(runtime-host): consolidate the private byte-limit helpers into the protocol codec (#5887)
f628acf861 is described below

commit f628acf861585e4cf4e7aa9539bb4f04398da6b6
Author: 小七 <gg...@gmail.com>
AuthorDate: Sat Oct 10 18:53:51 2026 +0800

    refactor(runtime-host): consolidate the private byte-limit helpers into the protocol codec (#5887)
    
    turn.ts、message.ts、session-continuity.ts 各自维护一份逐字相同的
    requireEncodedByteLimit 私有副本,与 protocol/codec.ts 的公共实现并存。
    三处改为从 codec.js 导入公共实现,删除私有副本(3 files, +3/-36)。
    
    行为披露:超限时的协议错误 message 文本从 `Invalid <label>` 变为
    `<label> exceeds byte limit`(codec 公共实现的既有文案)。接受/拒绝
    判定、错误类型(RuntimeHostProtocolError)与 code(invalid_frame)均
    不变;全仓无测试或消费方断言旧文案。JSON.stringify 失败与 undefined
    两条路径两版本文案本就逐字相同。
    
    #5038 读写放大清单的 byte-limit helper 整合项。packages/core 的
    skill-invocation.ts 存在变体副本(无 label 参数、UTF8.encode 计长),
    因依赖方向(core 不依赖 runtime-host)不在本单范围。
    
    Refs #5038
    Generated-by: GLM-5.3-Flash (ZCode)
    Merge remote-tracking branch 'upstream/main' into refactor/byte-limit-integration
    chore(runtime-host): declare the byte-limit consolidation as a protocol-compatible change
    
    The epoch guard counts the three touched protocol files as a protocol
    change and demands an epoch past 201. The change deletes three private
    requireEncodedByteLimit copies in favor of the shared codec
    implementation: no wire shape, field, key, error code, or accepted
    value changes; the only observable difference is the over-limit error
    message wording, which no test or consumer pins. Declared per the
    protocol-compatible-changes README instead of burning an epoch.
    
    Refs #5038
    Generated-by: GLM-5.3-Flash (ZCode)
---
 .../byte-limit-helper-consolidation.json                    |  9 +++++++++
 packages/runtime-host/src/protocol/message.ts               | 13 +------------
 packages/runtime-host/src/protocol/session-continuity.ts    | 13 +------------
 packages/runtime-host/src/protocol/turn.ts                  | 13 +------------
 4 files changed, 12 insertions(+), 36 deletions(-)

diff --git a/packages/runtime-host/protocol-compatible-changes/byte-limit-helper-consolidation.json b/packages/runtime-host/protocol-compatible-changes/byte-limit-helper-consolidation.json
new file mode 100644
index 0000000000..06b81519f6
--- /dev/null
+++ b/packages/runtime-host/protocol-compatible-changes/byte-limit-helper-consolidation.json
@@ -0,0 +1,9 @@
+{
+  "epoch": 201,
+  "files": [
+    "packages/runtime-host/src/protocol/message.ts",
+    "packages/runtime-host/src/protocol/session-continuity.ts",
+    "packages/runtime-host/src/protocol/turn.ts"
+  ],
+  "reason": "Consolidates three byte-identical private requireEncodedByteLimit copies onto the shared codec implementation. Accept/reject behavior, the error type and the invalid_frame code are unchanged; the only observable difference is the over-limit error message wording (Invalid <label> becomes <label> exceeds byte limit), which no test or consumer pins. No wire shape, field, key, error code, or accepted value changes."
+}
diff --git a/packages/runtime-host/src/protocol/message.ts b/packages/runtime-host/src/protocol/message.ts
index 7b147c8c45..31c4bc2233 100644
--- a/packages/runtime-host/src/protocol/message.ts
+++ b/packages/runtime-host/src/protocol/message.ts
@@ -21,6 +21,7 @@ import { invalidProtocolFrame } from './errors.js';
 import {
   assertExactKeys,
   requireCount,
+  requireEncodedByteLimit,
   requireEntityId,
   requireExactRecord,
   requireId,
@@ -575,15 +576,3 @@ function assertUniqueQueueEntries(
     messageIds.add(entry.messageId);
   }
 }
-
-function requireEncodedByteLimit(value: unknown, label: string, maxBytes: number): void {
-  let encoded: string | undefined;
-  try {
-    encoded = JSON.stringify(value);
-  } catch {
-    throw invalidProtocolFrame(`Invalid ${label}`);
-  }
-  if (encoded === undefined || Buffer.byteLength(encoded, 'utf8') > maxBytes) {
-    throw invalidProtocolFrame(`Invalid ${label}`);
-  }
-}
diff --git a/packages/runtime-host/src/protocol/session-continuity.ts b/packages/runtime-host/src/protocol/session-continuity.ts
index f376c04519..1ef4609d3b 100644
--- a/packages/runtime-host/src/protocol/session-continuity.ts
+++ b/packages/runtime-host/src/protocol/session-continuity.ts
@@ -25,6 +25,7 @@ import type { SessionStatus } from '@maka/core/session';
 import {
   assertExactKeys,
   requireCount,
+  requireEncodedByteLimit,
   requireEntityId,
   requireExactRecord,
   requireId,
@@ -1110,18 +1111,6 @@ function requireUtf8BoundedString(value: unknown, label: string, maxBytes: numbe
   return value;
 }
 
-function requireEncodedByteLimit(value: unknown, label: string, maxBytes: number): void {
-  let encoded: string | undefined;
-  try {
-    encoded = JSON.stringify(value);
-  } catch {
-    throw invalidProtocolFrame(`Invalid ${label}`);
-  }
-  if (encoded === undefined || Buffer.byteLength(encoded, 'utf8') > maxBytes) {
-    throw invalidProtocolFrame(`Invalid ${label}`);
-  }
-}
-
 /**
  * Read against the one list rather than a copy of it.
  *
diff --git a/packages/runtime-host/src/protocol/turn.ts b/packages/runtime-host/src/protocol/turn.ts
index 8bd3b7bc51..4f17aeb198 100644
--- a/packages/runtime-host/src/protocol/turn.ts
+++ b/packages/runtime-host/src/protocol/turn.ts
@@ -41,6 +41,7 @@ import { invalidProtocolFrame } from './errors.js';
 import {
   assertExactKeys,
   requireCount,
+  requireEncodedByteLimit,
   requireEntityId,
   requireExactRecord,
   requireShapedRecord,
@@ -473,18 +474,6 @@ function requireUtf8String(
   return value;
 }
 
-function requireEncodedByteLimit(value: unknown, label: string, maxBytes: number): void {
-  let encoded: string | undefined;
-  try {
-    encoded = JSON.stringify(value);
-  } catch {
-    throw invalidProtocolFrame(`Invalid ${label}`);
-  }
-  if (encoded === undefined || Buffer.byteLength(encoded, 'utf8') > maxBytes) {
-    throw invalidProtocolFrame(`Invalid ${label}`);
-  }
-}
-
 function decodeTurnQueryInput(value: unknown): TurnQueryInput {
   const record = requireExactRecord(value, 'turn.query input', ['sessionId', 'turnId']);
   return {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org