Skip to content

Commit 21dc714

Browse files
committed
fix(protocol): align trace schemas with v2/v3 classify rules
RecordedTrace validation now follows classify_value — numeric version selects v3, otherwise v2 — so mixed pages/states and v2 envelopes with a version field fail Schema checks before Recall import. Keep standalone trace_step as a v2|v3 union for tools that validate a single step.
1 parent 1bd27c9 commit 21dc714

11 files changed

Lines changed: 1770 additions & 306 deletions

File tree

apps/extension/src/transport/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ export interface EmulateResult {
661661
// --------------------------------------------------------------------------
662662

663663
export const TRACE_VERSION_V3 = 3;
664+
/** Logical v2 identifier. Not a wire field — v2 envelopes omit `version`. */
664665
export const TRACE_VERSION_V2 = 2;
665666
export const VOM_FORMAT_VERSION = 1;
666667

@@ -853,6 +854,7 @@ export interface TraceV3 {
853854
}
854855

855856
export type RecordedTrace = TraceV2 | TraceV3;
857+
export type RecordedStep = StepV2 | StepV3;
856858

857859
export interface RecordStartParams {
858860
session_id: string;

crates/bsk-protocol/schema/tool_record_await_result.json

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,22 @@
6464
}
6565
},
6666
"RecordedTrace": {
67-
"oneOf": [
68-
{
69-
"$ref": "#/definitions/TraceV2"
70-
},
71-
{
72-
"$ref": "#/definitions/TraceV3"
67+
"if": {
68+
"required": [
69+
"version"
70+
],
71+
"properties": {
72+
"version": {
73+
"type": "integer"
74+
}
7375
}
74-
]
76+
},
77+
"then": {
78+
"$ref": "#/definitions/TraceV3"
79+
},
80+
"else": {
81+
"$ref": "#/definitions/TraceV2"
82+
}
7583
},
7684
"RecorderInfo": {
7785
"type": "object",
@@ -834,7 +842,8 @@
834842
}
835843
},
836844
"TraceV2": {
837-
"description": "Persisted user-action trace exported by legacy `tool.record_stop` / `await`.\n\nUnknown extension fields are ignored so older traces remain readable. Mixed v2/v3 envelopes are rejected by `RecordedTrace` classification.",
845+
"title": "TraceV2",
846+
"description": "Persisted user-action trace exported by legacy `tool.record_stop` / `await`.\n\nUnknown extension fields are ignored so older traces remain readable. `states[]` and a numeric `version` are reserved for Trace v3 / `RecordedTrace` classification.",
838847
"type": "object",
839848
"required": [
840849
"entry",
@@ -868,11 +877,18 @@
868877
"null"
869878
]
870879
},
880+
"states": false,
871881
"steps": {
872882
"type": "array",
873883
"items": {
874884
"$ref": "#/definitions/StepV2"
875885
}
886+
},
887+
"version": {
888+
"description": "Numeric version selects Trace v3. Legacy v2 envelopes omit this field.",
889+
"not": {
890+
"type": "integer"
891+
}
876892
}
877893
}
878894
},

crates/bsk-protocol/schema/tool_record_stop_result.json

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,22 @@
6464
}
6565
},
6666
"RecordedTrace": {
67-
"oneOf": [
68-
{
69-
"$ref": "#/definitions/TraceV2"
70-
},
71-
{
72-
"$ref": "#/definitions/TraceV3"
67+
"if": {
68+
"required": [
69+
"version"
70+
],
71+
"properties": {
72+
"version": {
73+
"type": "integer"
74+
}
7375
}
74-
]
76+
},
77+
"then": {
78+
"$ref": "#/definitions/TraceV3"
79+
},
80+
"else": {
81+
"$ref": "#/definitions/TraceV2"
82+
}
7583
},
7684
"RecorderInfo": {
7785
"type": "object",
@@ -834,7 +842,8 @@
834842
}
835843
},
836844
"TraceV2": {
837-
"description": "Persisted user-action trace exported by legacy `tool.record_stop` / `await`.\n\nUnknown extension fields are ignored so older traces remain readable. Mixed v2/v3 envelopes are rejected by `RecordedTrace` classification.",
845+
"title": "TraceV2",
846+
"description": "Persisted user-action trace exported by legacy `tool.record_stop` / `await`.\n\nUnknown extension fields are ignored so older traces remain readable. `states[]` and a numeric `version` are reserved for Trace v3 / `RecordedTrace` classification.",
838847
"type": "object",
839848
"required": [
840849
"entry",
@@ -868,11 +877,18 @@
868877
"null"
869878
]
870879
},
880+
"states": false,
871881
"steps": {
872882
"type": "array",
873883
"items": {
874884
"$ref": "#/definitions/StepV2"
875885
}
886+
},
887+
"version": {
888+
"description": "Numeric version selects Trace v3. Legacy v2 envelopes omit this field.",
889+
"not": {
890+
"type": "integer"
891+
}
876892
}
877893
}
878894
},

crates/bsk-protocol/schema/trace.json

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"title": "RecordedTrace",
4-
"oneOf": [
5-
{
6-
"$ref": "#/definitions/TraceV2"
7-
},
8-
{
9-
"$ref": "#/definitions/TraceV3"
4+
"if": {
5+
"required": [
6+
"version"
7+
],
8+
"properties": {
9+
"version": {
10+
"type": "integer"
11+
}
1012
}
11-
],
13+
},
14+
"then": {
15+
"$ref": "#/definitions/TraceV3"
16+
},
17+
"else": {
18+
"$ref": "#/definitions/TraceV2"
19+
},
1220
"definitions": {
1321
"FillCommit": {
1422
"type": "string",
@@ -823,7 +831,8 @@
823831
}
824832
},
825833
"TraceV2": {
826-
"description": "Persisted user-action trace exported by legacy `tool.record_stop` / `await`.\n\nUnknown extension fields are ignored so older traces remain readable. Mixed v2/v3 envelopes are rejected by `RecordedTrace` classification.",
834+
"title": "TraceV2",
835+
"description": "Persisted user-action trace exported by legacy `tool.record_stop` / `await`.\n\nUnknown extension fields are ignored so older traces remain readable. `states[]` and a numeric `version` are reserved for Trace v3 / `RecordedTrace` classification.",
827836
"type": "object",
828837
"required": [
829838
"entry",
@@ -857,11 +866,18 @@
857866
"null"
858867
]
859868
},
869+
"states": false,
860870
"steps": {
861871
"type": "array",
862872
"items": {
863873
"$ref": "#/definitions/StepV2"
864874
}
875+
},
876+
"version": {
877+
"description": "Numeric version selects Trace v3. Legacy v2 envelopes omit this field.",
878+
"not": {
879+
"type": "integer"
880+
}
865881
}
866882
}
867883
},

0 commit comments

Comments
 (0)