Skip to content

Commit 317f91f

Browse files
jakeleventhalclaude
andcommitted
fix(fx): keep T3's prompt text out of recorded turn.start hooks
fx echoes the whole prompt as the libfx/hook turn.start input, so the fx_subagent_hooks recording kept T3's instructions and runtime instructions there, though the transcript header says T3-owned prompt text is normalized. The recorder now applies the same placeholders to that echo as to the outbound prompt, and the fixture's one turn.start frame is rewritten the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 77b6a16 commit 317f91f

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎apps/server/scripts/record-fx-acp-replay-fixture.ts‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const decodeJson = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Unknown
3838
const HOME_PLACEHOLDER = "/home/fx-replay";
3939
const FX_INSTANCE_ID = ProviderInstanceId.make("fx");
4040
const T3_INSTRUCTIONS_BODY = /<t3_code_instructions>\n[\s\S]*?\n<\/t3_code_instructions>/u;
41+
const T3_INSTRUCTIONS_PLACEHOLDER = "<t3_code_instructions>\n<any>\n</t3_code_instructions>";
4142
const EMAIL = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/giu;
4243
const TOKEN = /\b(?:sk-|gho_|ghp_|xai-|vercel_)[A-Za-z0-9_-]{8,}\b/gu;
4344

@@ -208,10 +209,7 @@ function normalizeOutboundFrame(frame: Record<string, unknown>, runtimeInstructi
208209
isRecord(part) && typeof part.text === "string"
209210
? {
210211
...part,
211-
text: part.text.replace(
212-
T3_INSTRUCTIONS_BODY,
213-
"<t3_code_instructions>\n<any>\n</t3_code_instructions>",
214-
),
212+
text: part.text.replace(T3_INSTRUCTIONS_BODY, T3_INSTRUCTIONS_PLACEHOLDER),
215213
}
216214
: part,
217215
),
@@ -226,7 +224,10 @@ function normalizeOutboundFrame(frame: Record<string, unknown>, runtimeInstructi
226224
/** A model call's request content: up to 64 KiB per hook that T3 never reads. */
227225
const HOOK_MODEL_REQUEST_FIELDS = new Set(["messages", "instructions", "tools", "toolsJson"]);
228226

229-
function normalizeInboundFrame(frame: Record<string, unknown>): Record<string, unknown> {
227+
function normalizeInboundFrame(
228+
frame: Record<string, unknown>,
229+
runtimeInstructions: string,
230+
): Record<string, unknown> {
230231
const params = isRecord(frame.params) ? frame.params : undefined;
231232
if (frame.method === "libfx/hook" && params?.type === "model.start" && isRecord(params.data)) {
232233
const data = params.data;
@@ -240,6 +241,26 @@ function normalizeInboundFrame(frame: Record<string, unknown>): Record<string, u
240241
},
241242
};
242243
}
244+
// fx echoes the whole prompt as the turn's input, T3's own text included.
245+
if (
246+
frame.method === "libfx/hook" &&
247+
params?.type === "turn.start" &&
248+
isRecord(params.data) &&
249+
typeof params.data.input === "string"
250+
) {
251+
return {
252+
...frame,
253+
params: {
254+
...params,
255+
data: {
256+
...params.data,
257+
input: params.data.input
258+
.replace(T3_INSTRUCTIONS_BODY, T3_INSTRUCTIONS_PLACEHOLDER)
259+
.replace(runtimeInstructions, "<any>"),
260+
},
261+
},
262+
};
263+
}
243264
const update = isRecord(params?.update) ? params.update : undefined;
244265
if (
245266
update?.sessionUpdate === "available_commands_update" &&
@@ -325,7 +346,7 @@ function normalizeEntries(input: {
325346
const frame =
326347
entry.type === "expect_outbound"
327348
? normalizeOutboundFrame(entry.frame, input.runtimeInstructions)
328-
: normalizeInboundFrame(entry.frame);
349+
: normalizeInboundFrame(entry.frame, input.runtimeInstructions);
329350
return {
330351
...entry,
331352
...(entry.label === undefined ? {} : { label: replaceAll(entry.label) }),

‎apps/server/src/orchestration-v2/testkit/fixtures/fx_subagent_hooks/fx_transcript.ndjson‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{"type":"expect_outbound","label":"request:session/set_config_option","frame":{"kind":"request","method":"session/set_config_option","params":{"sessionId":"fx-session-01","configId":"mode","value":"auto"}}}
1010
{"type":"emit_inbound","label":"response:session/set_config_option","frame":{"kind":"response","method":"session/set_config_option","result":{"configOptions":[{"id":"provider","name":"Provider","category":"model","type":"select","currentValue":"codex","options":[{"value":"gateway","name":"Vercel AI Gateway"},{"value":"codex","name":"Codex subscription"},{"value":"grok","name":"Grok subscription"}]},{"id":"model","name":"Model","category":"model","type":"select","currentValue":"gpt-6.1-sol","options":[{"value":"gpt-6.1-sol","name":"gpt-6.1-sol"},{"value":"gpt-6-astra","name":"gpt-6-astra"},{"value":"gpt-6.1-terra","name":"gpt-6.1-terra"},{"value":"gpt-6-sol","name":"gpt-6-sol"},{"value":"gpt-6-luna","name":"gpt-6-luna"},{"value":"gpt-5.6-sol","name":"gpt-5.6-sol"},{"value":"gpt-5.6-terra","name":"gpt-5.6-terra"},{"value":"gpt-5.6-luna","name":"gpt-5.6-luna"},{"value":"gpt-daybreak-blue-latest","name":"gpt-daybreak-blue-latest"}]},{"id":"mode","name":"Session Mode","description":"Controls how the agent requests permission","category":"mode","type":"select","currentValue":"auto","options":[{"value":"auto","name":"Auto","description":"Check actions with an automatic safety review instead of asking","_meta":{"fx":{"permissionMode":"auto"}}},{"value":"ask","name":"Ask","description":"Request permission before making any changes","_meta":{"fx":{"permissionMode":"ask"}}},{"value":"full-access","name":"Full access","description":"Run every action without asking, outside the sandbox","_meta":{"fx":{"permissionMode":"yolo"}}}]},{"id":"effort","name":"Reasoning Effort","description":"Controls how much the model thinks before responding","category":"thought_level","type":"select","currentValue":"medium","options":[{"value":"auto","name":"default"},{"value":"low","name":"low"},{"value":"medium","name":"medium"},{"value":"high","name":"high"},{"value":"xhigh","name":"xhigh"},{"value":"max","name":"max"},{"value":"ultra","name":"ultra"}]},{"id":"fast","name":"Fast Mode","description":"Uses the model's fast lane","category":"model","type":"select","currentValue":"false","options":[{"value":"false","name":"off"},{"value":"true","name":"on"}]}]}}}
1111
{"type":"expect_outbound","label":"request:session/prompt","frame":{"kind":"request","method":"session/prompt","params":{"sessionId":"fx-session-01","prompt":[{"type":"text","text":"<t3_code_instructions>\n<any>\n</t3_code_instructions>\n\n<user_request>\nSpawn 2 subagents, one to read package.json and one to read tsconfig.json\n</user_request>"}]}}}
12-
{"type":"emit_inbound","label":"notification:libfx/hook","frame":{"kind":"notification","method":"libfx/hook","params":{"version":1,"sessionId":"fx-session-01","rootSessionId":"fx-session-01","parentSessionId":null,"sourceSessionId":null,"workId":null,"turnId":"d72093549e8e72f36a72d71ccbde93d6","executionId":"d72093549e8e72f36a72d71ccbde93d6","stepIndex":0,"timestamp":1793283383909,"type":"turn.start","data":{"resumed":false,"input":"<t3_code_instructions>\n## T3 Code interaction mode: Default\n\nPrefer making reasonable assumptions and carrying out the user's request. Ask a concise question only when a missing user decision would materially change the result. Treat this mode as active until T3 Code supplies a different interaction-mode instruction.\n</t3_code_instructions>\n\n<user_request>\nSpawn 2 subagents, one to read package.json and one to read tsconfig.json\n</user_request>\n<runtime_info>In case you're asked: you are running in T3 Code through the fx harness. No need to mention this otherwise. You can embed images, video, and audio in your response using Markdown image syntax with absolute file paths. Link any other file you produce using its absolute path so the user can open it in T3 Code's files viewer.</runtime_info>\n\n<pull_request_linking>\nLink each PR you create, take over, or push to: one link_pull_request per PR, full URL, every stack layer, as your next call. Host tools do not link for you. If linking fails, say so. Skip PRs you only read or review, and PRs named only as background. Call watch_pull_request when asked to monitor or babysit, or when work you were asked to do, such as a merge, still waits on checks or reviews, even after an earlier unwatch. Finish any needed branch update and push first, then watch and end your turn. Otherwise act now or hand back. Delegated children never watch, even if the brief says babysit. After PR work, a child's last line is: PR <full URL>, head <SHA>, checks and reviews <state>. Links and watches persist across pushes. Never wait with sleep, loops, gh --watch, Monitor, or ScheduleWakeup. Before handback, call unwatch_pull_request on any PR you watch.\n</pull_request_linking>"},"contentCaptured":true,"contentTruncated":false}}}
12+
{"type":"emit_inbound","label":"notification:libfx/hook","frame":{"kind":"notification","method":"libfx/hook","params":{"version":1,"sessionId":"fx-session-01","rootSessionId":"fx-session-01","parentSessionId":null,"sourceSessionId":null,"workId":null,"turnId":"d72093549e8e72f36a72d71ccbde93d6","executionId":"d72093549e8e72f36a72d71ccbde93d6","stepIndex":0,"timestamp":1793283383909,"type":"turn.start","data":{"resumed":false,"input":"<t3_code_instructions>\n<any>\n</t3_code_instructions>\n\n<user_request>\nSpawn 2 subagents, one to read package.json and one to read tsconfig.json\n</user_request>\n<any>"},"contentCaptured":true,"contentTruncated":false}}}
1313
{"type":"emit_inbound","label":"notification:libfx/hook","frame":{"kind":"notification","method":"libfx/hook","params":{"version":1,"sessionId":"fx-session-01","rootSessionId":"fx-session-01","parentSessionId":null,"sourceSessionId":null,"workId":null,"turnId":"d72093549e8e72f36a72d71ccbde93d6","executionId":"d72093549e8e72f36a72d71ccbde93d6","stepIndex":0,"timestamp":1793283383909,"type":"model.start","data":{"modelCallId":1,"parentCallId":null,"purpose":"title","model":"gpt-5.6-luna","toolChoice":"none","maxOutputTokens":128,"messageCount":1},"contentCaptured":true,"contentTruncated":false}}}
1414
{"type":"emit_inbound","label":"notification:libfx/hook","frame":{"kind":"notification","method":"libfx/hook","params":{"version":1,"sessionId":"fx-session-01","rootSessionId":"fx-session-01","parentSessionId":null,"sourceSessionId":null,"workId":null,"turnId":"d72093549e8e72f36a72d71ccbde93d6","executionId":"d72093549e8e72f36a72d71ccbde93d6","stepIndex":0,"timestamp":1793283383909,"type":"model.admitted","data":{"modelCallId":1},"contentCaptured":true,"contentTruncated":false}}}
1515
{"type":"emit_inbound","label":"notification:libfx/hook","frame":{"kind":"notification","method":"libfx/hook","params":{"version":1,"sessionId":"fx-session-01","rootSessionId":"fx-session-01","parentSessionId":null,"sourceSessionId":null,"workId":null,"turnId":"d72093549e8e72f36a72d71ccbde93d6","executionId":"d72093549e8e72f36a72d71ccbde93d6","stepIndex":1,"timestamp":1793283383909,"type":"step.start","data":{},"contentCaptured":true,"contentTruncated":false}}}

0 commit comments

Comments
 (0)