fix(grok): skills, reasoning, plan mode, usage, and stalled turns #7638
Closed1xpixi(GitHub profile, opens in a new tab)wants to merge 24 commits into
main fromrefs/pull/7638/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/provider/acp/AcpRuntimeModel.ts line 534OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -426,0 +514,21 @@514+}515+516+export interface AcpToolCallEmitDecision {517+ readonly emit: boolean;518+ readonly skippedSinceEmit: number;519+}520+521+export function decideToolCallUpdateEmission(522+ input: AcpToolCallEmitDecisionInput,523+): AcpToolCallEmitDecision {524+ const { previous, next, lastEmittedDetailLength, skippedSinceEmit } = input;525+ if (next.status === "completed" || next.status === "failed") {526+ return { emit: true, skippedSinceEmit: 0 };527+ }528+ if (!next.detail) {529+ return { emit: false, skippedSinceEmit };530+ }531+ if (previous === undefined || previous.title !== next.title) {532+ return { emit: true, skippedSinceEmit: 0 };533+ }534+ if (previous.detail === next.detail) {apps/server/src/provider/acp/AcpRuntimeModel.ts line 353OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -267,15 +318,10 @@318+267319 function extractTextContentFromToolCallContent(268320 content: ReadonlyArray<EffectAcpSchema.ToolCallContent> | null | undefined,269-): string | undefined {270- if (!content) return undefined;321+): ExtractedToolCallContent {322+ if (!content) {323+ return { text: undefined, content: undefined };324+ }271325 const chunks: Array<string> = [];272326 for (const entry of content) {273- if (entry.type !== "content") {274- continue;275- }276- const nestedContent = entry.content;277- if (nestedContent.type !== "text") {278- continue;279- }280- const text = nestedContent.text.trim();281- if (text.length > 0) {327+ const text = toolCallContentText(entry)?.trim();apps/server/src/provider/acp/AcpRuntimeModel.ts line 344OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -280,6 +327,18 @@280- const text = nestedContent.text.trim();281- if (text.length > 0) {327+ const text = toolCallContentText(entry)?.trim();328+ if (text) {282329 chunks.push(text);283330 }284331 }285- return chunks.length > 0 ? chunks.join("\n") : undefined;332+ if (chunks.length === 0) {333+ return { text: undefined, content };334+ }335+ const joined = chunks.join("\n");336+ if (joined.length <= TOOL_CALL_CONTENT_MAX_CHARS) {337+ return { text: joined, content };338+ }339+ const bounded = boundToolCallOutputText(joined);340+ // Collapse the text entries into a single bounded one at the final contributing text entry,341+ // and leave every other entry kind (diffs, images, resource links) in its original relative342+ // order. The retained tail came from that text entry, so placing it there also preserves its343+ // ordering relative to interleaved non-text content and ignores later blank text entries.344+ const lastContributingTextIndex = content.reduce(apps/server/src/provider/acp/XAiAcpExtension.ts lines 304 to 317OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -198,0 +297,21 @@297+298+ const rawInput = data.rawInput;299+ if (isRecord(rawInput)) {300+ const filePath =301+ (typeof rawInput.file_path === "string" ? rawInput.file_path : undefined) ??302+ (typeof rawInput.path === "string" ? rawInput.path : undefined);303+ const content = typeof rawInput.content === "string" ? rawInput.content : undefined;304+ if (isGrokPlanMarkdownPath(filePath) && content && content.trim().length > 0) {305+ return content.trim();306+ }307+ }308+309+ const content = data.content;310+ if (Array.isArray(content)) {311+ for (const block of content) {312+ if (!isRecord(block) || block.type !== "diff") {313+ continue;314+ }315+ const path = typeof block.path === "string" ? block.path : undefined;316+ const newText = typeof block.newText === "string" ? block.newText : undefined;317+ if (isGrokPlanMarkdownPath(path) && newText && newText.trim().length > 0) {apps/server/src/provider/Layers/GrokAdapter.ts line 1322OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -855,3 +1319,4 @@8551319 rawPayload: event.rawPayload,8561320 }),8571321 );1322+ if (isGrokEnterPlanModeToolCall(event.toolCall)) {apps/server/src/provider/acp/AcpRuntimeModel.ts lines 528 to 533OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -426,0 +513,21 @@513+ readonly skippedSinceEmit: number;514+}515+516+export interface AcpToolCallEmitDecision {517+ readonly emit: boolean;518+ readonly skippedSinceEmit: number;519+}520+521+export function decideToolCallUpdateEmission(522+ input: AcpToolCallEmitDecisionInput,523+): AcpToolCallEmitDecision {524+ const { previous, next, lastEmittedDetailLength, skippedSinceEmit } = input;525+ if (next.status === "completed" || next.status === "failed") {526+ return { emit: true, skippedSinceEmit: 0 };527+ }528+ if (!next.detail) {529+ return { emit: false, skippedSinceEmit };530+ }531+ if (previous === undefined || previous.title !== next.title) {532+ return { emit: true, skippedSinceEmit: 0 };533+ }apps/server/src/provider/acp/XAiAcpExtension.ts line 284OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -198,0 +264,21 @@264+ outcome: "abandoned",265+ feedback:266+ feedback ??267+ "The client captured your proposed plan. Stop here and wait for the user's feedback or implementation request in a later turn.",268+ };269+}270+271+/**272+ * True when a path is Grok's session plan file under `~/.grok/sessions/.../plan.md`.273+ * Deliberately does not match workspace files named `plan.md` (e.g. docs/plan.md).274+ */275+export function isGrokPlanMarkdownPath(path: string | undefined | null): boolean {276+ if (typeof path !== "string") {277+ return false;278+ }279+ const normalized = path.trim().replace(/\\/g, "/");280+ if (normalized.length === 0 || !normalized.endsWith("/plan.md")) {281+ return false;282+ }283+ // Session layout: ~/.grok/sessions/<encoded-cwd>/<session-id>/plan.md284+ return normalized.includes("/.grok/sessions/");
- apps/server/src/provider/Layers/GrokAdapter.ts lines 474 to 477OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -296,0 +457,21 @@457+ }458+ ctx.livenessUpdatesInFlight += 1;459+ try {460+ const activityAtNanos = yield* Clock.currentTimeNanos;461+ if (ctx.livenessTurnId !== turnId || ctx.interruptedTurnIds.has(turnId)) {462+ return;463+ }464+ if (event._tag === "ToolCallUpdated") {465+ if (event.toolCall.status === "completed" || event.toolCall.status === "failed") {466+ ctx.activeToolCallIds.delete(event.toolCall.toolCallId);467+ } else {468+ // A tool update without a terminal status receives a longer469+ // deadline so a long-running tool is not mistaken for a stall.470+ ctx.activeToolCallIds.add(event.toolCall.toolCallId);471+ }472+ }473+ ctx.lastTurnActivityAtNanos = activityAtNanos;474+ yield* signalTurnLiveness(ctx, turnId);475+ } finally {476+ ctx.livenessUpdatesInFlight = Math.max(0, ctx.livenessUpdatesInFlight - 1);477+ }apps/server/src/provider/acp/AcpRuntimeModel.ts lines 381 to 407OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -278,8 +391,17 @@278391 continue;279392 }280- const text = nestedContent.text.trim();281- if (text.length > 0) {282- chunks.push(text);393+ if (textRanges.length > 0) {394+ offset += 1;283395 }396+ const start = offset;397+ const end = offset + text.length;398+ textRanges.push({ index, start, end, text });399+ offset = end;284400 }285- return chunks.length > 0 ? chunks.join("\n") : undefined;401+ const tailStart = Math.max(0, offset - tail.length);402+ let markerPending = true;403+ return content.flatMap((entry, index) => {404+ if (toolCallContentText(entry) === undefined) {405+ return [entry];406+ }407+ const range = textRanges.find((item) => item.index === index);apps/server/src/provider/acp/AcpRuntimeModel.ts lines 636 to 638Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -426,0 +614,21 @@614+ if (typeof value === "string") {615+ rawOutputChars += value.length;616+ }617+ }618+ }619+ return Math.max(state.detail?.length ?? 0, contentChars, rawOutputChars);620+}621+622+export function decideToolCallUpdateEmission(623+ input: AcpToolCallEmitDecisionInput,624+): AcpToolCallEmitDecision {625+ const { previous, next, lastEmittedDetailLength, skippedSinceEmit } = input;626+ if (next.status === "completed" || next.status === "failed") {627+ return { emit: true, skippedSinceEmit: 0 };628+ }629+ if (previous === undefined || previous.title !== next.title) {630+ return { emit: true, skippedSinceEmit: 0 };631+ }632+ if (previous.detail === next.detail && toolCallOutputUnchanged(previous, next)) {633+ return { emit: false, skippedSinceEmit };634+ }
- apps/server/src/provider/acp/XAiAcpExtension.ts line 297OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -198,0 +277,21 @@277+ */278+export function isGrokPlanMarkdownPath(path: string | undefined | null): boolean {279+ if (typeof path !== "string") {280+ return false;281+ }282+ const normalized = path.trim().replace(/\\/g, "/");283+ if (normalized.length === 0 || !normalized.endsWith("/plan.md")) {284+ return false;285+ }286+ const home = NodeOS.homedir().replace(/\\/g, "/").replace(/\/+$/, "");287+ const prefixes = [`${home}/.grok/sessions/`, "~/.grok/sessions/"];288+ const haystack = process.platform === "win32" ? normalized.toLowerCase() : normalized;289+ return prefixes.some((prefix) => {290+ const needle = process.platform === "win32" ? prefix.toLowerCase() : prefix;291+ if (!haystack.startsWith(needle)) {292+ return false;293+ }294+ const rest = haystack.slice(needle.length);295+ // Session layout: ~/.grok/sessions/<encoded-cwd>/<session-id>/plan.md296+ return rest !== "plan.md" && rest.endsWith("plan.md");297+ });apps/server/src/provider/acp/XAiAcpExtension.ts line 330OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -198,0 +310,21 @@310+311+ const rawInput = data.rawInput;312+ if (isRecord(rawInput)) {313+ const filePath =314+ (typeof rawInput.file_path === "string" ? rawInput.file_path : undefined) ??315+ (typeof rawInput.path === "string" ? rawInput.path : undefined);316+ const content = typeof rawInput.content === "string" ? rawInput.content : undefined;317+ if (isGrokPlanMarkdownPath(filePath) && content !== undefined) {318+ return content.trim();319+ }320+ }321+322+ const content = data.content;323+ if (Array.isArray(content)) {324+ for (const block of content) {325+ if (!isRecord(block) || block.type !== "diff") {326+ continue;327+ }328+ const path = typeof block.path === "string" ? block.path : undefined;329+ const newText = typeof block.newText === "string" ? block.newText : undefined;330+ if (isGrokPlanMarkdownPath(path) && newText !== undefined) {
- apps/server/src/provider/acp/XAiAcpExtension.ts lines 350 to 350Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -198,0 +312,21 @@312+export function isGrokPlanMarkdownPath(path: string | undefined | null): boolean {313+ if (typeof path !== "string") {314+ return false;315+ }316+ const normalized = path.trim().replace(/\\/g, "/");317+ if (normalized.length === 0 || !normalized.endsWith("/plan.md")) {318+ return false;319+ }320+ const haystack = process.platform === "win32" ? normalized.toLowerCase() : normalized;321+ for (const prefix of grokPlanSessionPrefixes()) {322+ const needle = process.platform === "win32" ? prefix.toLowerCase() : prefix;323+ if (!haystack.startsWith(needle)) {324+ continue;325+ }326+ const rest = haystack.slice(needle.length);327+ // Session layout: <home>/.grok/sessions/<encoded-cwd>/<session-id>/plan.md328+ if (rest !== "plan.md" && rest.endsWith("plan.md")) {329+ return true;330+ }331+ }332+ return CANONICAL_HOME_GROK_SESSION_PATH.test(haystack);
- apps/server/src/provider/acp/XAiAcpExtension.ts lines 304 to 304OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -198,0 +284,21 @@284+ return;285+ }286+ prefixes.add(nestedGrokDir ? `${root}/.grok/sessions/` : `${root}/sessions/`);287+}288+289+function grokPlanSessionPrefixes(): ReadonlySet<string> {290+ const prefixes = new Set<string>();291+ addGrokSessionPrefix(prefixes, NodeOS.homedir(), true);292+ addGrokSessionPrefix(prefixes, "~", true);293+ addGrokSessionPrefix(prefixes, process.env.HOME ?? "", true);294+ addGrokSessionPrefix(prefixes, process.env.USERPROFILE ?? "", true);295+ // ACP mock and isolated Grok spawns use a HOME that is not the server process home.296+ addGrokSessionPrefix(prefixes, "/tmp/mock-home", true);297+ const grokHome = process.env.GROK_HOME ?? "";298+ addGrokSessionPrefix(prefixes, grokHome, false);299+ addGrokSessionPrefix(prefixes, grokHome, true);300+ return prefixes;301+}302+303+const CANONICAL_HOME_GROK_SESSION_PATH =304+ /^(?:\/home\/[^/]+|\/Users\/[^/]+|[a-zA-Z]:\/Users\/[^/]+)\/\.grok\/sessions\/.+\/plan\.md$/i;
1xpixi(GitHub profile, opens in a new tab) changed the title
- apps/server/src/provider/acp/XAiAcpExtension.ts lines 328 to 330OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -198,0 +310,21 @@310+/**311+ * True when a path is Grok's session plan file under a Grok home312+ * (`~/.grok/sessions/.../plan.md`, `$HOME/.grok/sessions/...`, or `$GROK_HOME/sessions/...`).313+ * Deliberately does not match workspace files named `plan.md` (e.g. docs/plan.md314+ * or a repo-local `.grok/sessions/.../plan.md`).315+ */316+export function isGrokPlanMarkdownPath(path: string | undefined | null): boolean {317+ if (typeof path !== "string") {318+ return false;319+ }320+ const normalized = path.trim().replace(/\\/g, "/");321+ if (322+ normalized.length === 0 ||323+ !normalized.endsWith("/plan.md") ||324+ pathHasTraversalSegment(normalized)325+ ) {326+ return false;327+ }328+ const haystack = process.platform === "win32" ? normalized.toLowerCase() : normalized;329+ for (const prefix of grokPlanSessionPrefixes()) {330+ const needle = process.platform === "win32" ? prefix.toLowerCase() : prefix;
- @@ -1,2 +1,6 @@11 # T3 Code223+ [!IMPORTANT]4+ This is a **Grok reliability fork** of [pingdotgg/t3code](https://github.com/pingdotgg/t3code). Upstream Grok Build in T3 hung, cancelled **Always allow**, hid plan cards, skipped usage and skills, and flooded the server with tool output. The rest of this README is upstream's. The list below is what this fork changes.5+6+## What's fixed in this fork
t3dotgg(GitHub profile, opens in a new tab) closed this
t3dotgg(GitHub profile, opens in a new tab) reopened this
- apps/server/src/provider/acp/GrokAcpSupport.ts line 179Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -97,11 +153,17 @@153+ readonly currentReasoningEffort?: string | undefined;97154 readonly requestedModelId: string | undefined;155+ readonly requestedReasoningEffort?: string | undefined;98156 readonly mapError: (cause: EffectAcpErrors.AcpError) => E;99157 }): Effect.Effect<string | undefined, E> {100- const shouldSwitchModel =158+ const modelChanged =101159 input.requestedModelId !== undefined && input.requestedModelId !== input.currentModelId;102- if (!shouldSwitchModel) {160+ const reasoningEffort = normalizeGrokReasoningEffort(input.requestedReasoningEffort);161+ const reasoningEffortChanged =162+ input.requestedModelId !== undefined && reasoningEffort !== input.currentReasoningEffort;163+ const targetModelId = input.requestedModelId ?? input.currentModelId;164+ if ((!modelChanged && !reasoningEffortChanged) || targetModelId === undefined) {103165 return Effect.succeed(input.currentModelId);104166 }105167 return input.runtime106- .setSessionModel(input.requestedModelId)107- .pipe(Effect.mapError(input.mapError), Effect.as(input.requestedModelId));168+ .setSessionModel(targetModelId, reasoningEffort !== undefined ? { reasoningEffort } : undefined)169+ .pipe(Effect.mapError(input.mapError), Effect.as(targetModelId));
- @@ -495,3 +860,17 @@495860 );496861 });497862863+ /** Surface Grok plan.md as T3's proposed-plan card (while writing + on exit). */864+ const emitProposedPlanCompleted = (865+ ctx: GrokSessionContext,866+ turnId: TurnId | undefined,867+ stamp: { readonly eventId: EventId; readonly createdAt: string },868+ planMarkdown: string,869+ raw: { readonly method: string; readonly payload: unknown },870+ ) =>871+ Effect.gen(function* () {872+ const trimmed = planMarkdown.trim();873+ if (trimmed.length === 0) {874+ ctx.lastKnownProposedPlanMarkdown = "";875+ ctx.lastKnownProposedPlanTurnId = turnId;876+ return;
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.




Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
e5d88314-b4f1-49af-8718-b200cab33c79You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.