Repository navigation
Replies: 2 comments
|
Addendum — the same V8-only comparison is mirrored in four source files, so here is the complete diff (whitespace-normalized comparison at each site). External PRs are not accepted per CONTRIBUTING.md, so it is posted here for the team to apply if useful: diff --git a/packages/core/tools/src/json-schema.ts b/packages/core/tools/src/json-schema.ts
index c064fb2..5c5cf02 100644
--- a/packages/core/tools/src/json-schema.ts
+++ b/packages/core/tools/src/json-schema.ts
@@ -95,7 +95,7 @@ function hasIntrinsicConstructor(prototype: object, name: 'Array' | 'Object'): b
try {
return constructor.name === name
&& constructor.prototype === prototype
- && Function.prototype.toString.call(constructor) === `function ${name}() { [native code] }`
+ && Function.prototype.toString.call(constructor).replace(/\s+/g, ' ').trim() === `function ${name}() { [native code] }`
} catch {
return false
}
diff --git a/packages/extensions/cordis-host-runner/src/guard.ts b/packages/extensions/cordis-host-runner/src/guard.ts
index fb882c6..fedda46 100644
--- a/packages/extensions/cordis-host-runner/src/guard.ts
+++ b/packages/extensions/cordis-host-runner/src/guard.ts
@@ -47,7 +47,7 @@ function hasIntrinsicConstructor(prototype: object, name: 'Array' | 'Object'): b
try {
return constructor.name === name
&& constructor.prototype === prototype
- && Function.prototype.toString.call(constructor) === `function ${name}() { [native code] }`
+ && Function.prototype.toString.call(constructor).replace(/\s+/g, ' ').trim() === `function ${name}() { [native code] }`
} catch {
return false
}
diff --git a/packages/ptc-runtime/ptc-runtime-node/src/json-wire.ts b/packages/ptc-runtime/ptc-runtime-node/src/json-wire.ts
index 2a15d68..5a6fe5f 100644
--- a/packages/ptc-runtime/ptc-runtime-node/src/json-wire.ts
+++ b/packages/ptc-runtime/ptc-runtime-node/src/json-wire.ts
@@ -87,7 +87,7 @@ function hasIntrinsicConstructor(prototype: object, name: 'Array' | 'Object'): b
try {
return constructor.name === name
&& constructor.prototype === prototype
- && intrinsicReflectApply(intrinsicFunctionToString, constructor, []) === `function ${name}() { [native code] }`
+ && intrinsicReflectApply(intrinsicFunctionToString, constructor, []).replace(/\s+/g, ' ').trim() === `function ${name}() { [native code] }`
} catch {
return false
}
diff --git a/packages/util/values/src/index.ts b/packages/util/values/src/index.ts
index 908f4f8..fd4bdcf 100644
--- a/packages/util/values/src/index.ts
+++ b/packages/util/values/src/index.ts
@@ -22,7 +22,7 @@ function hasIntrinsicConstructor(prototype: object, name: 'Array' | 'Object'): b
try {
return constructor.name === name
&& constructor.prototype === prototype
- && Function.prototype.toString.call(constructor) === `function ${name}() { [native code] }`
+ && Function.prototype.toString.call(constructor).replace(/\s+/g, ' ').trim() === `function ${name}() { [native code] }`
} catch {
return false
} |
|
Two things that may be useful to anyone applying a fix here — both about delivery and non-regression, not re-deriving the root cause. 1. Verify the fix in the served bundle, not just the sourceThe validator is inlined three times in the bundle the browser actually loads, and the page Fetching the real URLs the page references and counting the copies: A single stale/cached chunk would keep the bug alive even after a correct source fix — worth 2. Regression scope: keep the
|
Uh oh!
There was an error while loading. Please reload this page.
TL;DR — Firefox only:
hasIntrinsicConstructor()comparesFunction.prototype.toString.call(constructor)to V8's exact single-line native-code form (function Object() { [native code] }). SpiderMonkey formats native functions multi-line (function Object() {\n [native code]\n}), so the comparison fails, every plain object is classified as "not losslessly JSON-serializable", and a client-side validation insideexpandAssistantStream()throws — which aborts the whole session open. In the Web UI that shows up as coming back to a running thread → transcript disappears → "Loading history…" forever. Chromium is unaffected.中文简版:Firefox 的
Function.prototype.toString对原生函数返回多行文本(function Object() {\n [native code]\n}),而hasIntrinsicConstructor()用 V8 单行格式做严格比较,导致普通对象被判为"不是可无损 JSON 序列化",客户端在expandAssistantStream()抛错、打开会话整体失败 —— 表现就是切回正在运行的会话时只剩 “Loading history…”。Chromium 不受影响。建议把比较改为忽略空白(见下方 diff)。Environment
npm latest), Web profile,--profile web --trusted-host <host>Steps to reproduce
The transcript disappears and only “Loading history…” is shown, with no error banner. Switching back to an already-finished thread works, so it only affects a thread whose last attempt is unsettled (running now, or interrupted by a restart) — that is the path that re-expands and validates the compact assistant stream together with the live frames.
Console output
(The sidebar catches it, logs
Sidebar Session opening failed, and leaves the view inopenState === "loading"— thechat.loadingHistorybranch — with no error state, so there is nothing to click but reload/restart.)Root cause
packages/util/values/src/index.ts(0.1.7-rc.2):The last condition is not engine-independent. Measured:
Function.prototype.toString.call(Object)"function Object() { [native code] }""function Object() {\n [native code]\n}"Cascade in Firefox:
hasIntrinsicConstructor→ false →isIntrinsicObjectPrototype→ false →hasPlainObjectPrototype({})→ false →walkJsonValue(value, detach)returnsundefinedfor any plain object or array →snapshotJsonValue()→snapshotChunk()throws →validateRecord()throws →expandAssistantStream()throws → the client's session-open rejects → “Loading history…”.Evidence that the data is fine: the rejected value is trivially JSON —
— plain
Object.prototype, not frozen, extensible, own keystype,index,blockType, no symbols,string/number/string. With the client instrumented at the throw site,walkJsonValue(chunk, false)returnsundefinedfor it, while every rule the function documents (finite numbers, no-0, plain prototypes, dense arrays, enumerable string keys, no cycles) is satisfied.The same V8-only comparison is mirrored in four more places, so those JSON checks are equally engine-bound (they are Node-side today, but they are copied into browsers/VM realms too):
packages/core/tools/src/json-schema.ts:91packages/extensions/cordis-host-runner/src/guard.ts:43packages/ptc-runtime/ptc-runtime-node/src/json-wire.ts:83packages/workflow/workflow-ptc/src/guest-source.ts(the generated guest source)Suggested fix
Normalize whitespace before comparing (identical semantics for V8, and correct for SpiderMonkey and any other engine that pretty-prints native code):
A regression test can simulate another engine without leaving V8, e.g. patch
Function.prototype.toStringto return the multi-line native form for intrinsics and assert thatisJsonValue({ a: 1 })/isPlainJsonRecord({})/isJsonSchemaRecord({})still pass, and that exotic values (new Date(), class instances,-0, sparse arrays) still fail.Workaround (verified)
Two build-time patches to
dsh-api-session-controller/lib/client.jsfor operators on a packaged install:validateRecord()call inexpandAssistantStream()so one bad record is skipped with aconsole.warninstead of aborting the whole open (this alone keeps the UI usable).Verified on the repro in Firefox: with (1) the running thread renders again after switching back (no record dropped, no console error); with (2) alone the thread renders and logs
[dsh] skipped an invalid assistant-stream record: {"type":"chunk","chunkType":"block-start"}, i.e. one stream record is dropped.I read
CONTRIBUTING.md— understood that external PRs are not accepted right now, so this is a report rather than a pull request. Happy to provide packet/console captures, the instrumented dumps, or a patch file if useful.All reactions