Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(server): server-stamped task data shapes (stacked on #5219) #5316

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 2 commits intot3code/native-subagent-observability fromrefs/pull/5316/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Note

Stacked on #5219 — merges into t3code/native-subagent-observability, not main.

Follow-up to the subagent observability PR: three write-time data-shape changes that let read-time complexity retire. Still zero migrations — everything rides payload_json and the existing activity_id upsert.

Problem

The client fold compensates for append-only lifecycle rows at several points:

  • Progress ticks append (2,700+ rows in a live dev DB vs ~400 start/terminal rows), so a large fleet's ticks can evict its own task.started rows out of the 500-row retention window — degrading the roster on full reload.
  • Agent-vs-background classification is derived independently in three places (client fold denylist + legacy-marker heuristics, web session-logic, server liveness registry) that must agree.

Solution

  • Progress upserts. task.progress / agent-owned tool.progress persist under stable ids (task-progress:<taskId>), so each tick replaces the last through the existing upsert + replace-by-id apply in the projector and client reducer. One progress row per task; retention pressure from progress disappears.
  • agentKind stamp. Ingestion stamps "agent" | "background" into every task linkage payload via classifyTaskAgentKind (new in contracts). Clients trust the stamp; the fold's denylist and marker sniffing remain only as a fallback for pre-stamp rows.
  • Canonical task-type sets. MONITOR_TASK_TYPES / INERT_TASK_TYPES move to contracts; ThreadBackgroundLiveness consumes them instead of keeping its own copies.

Tests: classify unit tests in contracts, stamp-trust fold tests, ingestion suites updated for the stable ids (216 orchestration tests green).


Built by Claude Fable 5 via Claude Code.


Note

Medium Risk Changes activity identity and upsert semantics for progress rows, plus agent roster classification that affects UI and liveness; legacy unstamped rows rely on fallback behavior.

Overview Progress activities now upsert instead of appending: task.progress and agent-owned tool.progress persist under stable ids (task-progress:<taskId>, tool-progress:<taskId>), so each tick replaces one row and large fleets no longer flood the 500-row activity retention window.

Agent vs background classification is centralized in contracts via classifyTaskAgentKind, shared MONITOR_TASK_TYPES / INERT_TASK_TYPES, and an agentKind stamp on every task linkage payload at ingestion. The client fold trusts agentKind === "agent" and drops the denylist and pipeline-marker heuristics; rows without a stamp keep legacy work-log behavior. ThreadBackgroundLiveness imports the same contract sets instead of local copies.

Tests and fixtures were updated for stable progress ids and stamped payloads.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ea06fbf8c3ee3e7cd79350f2e3097d1d66e7951b. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Stamp server-classified agentKind onto task activity payloads and stabilize progress activity IDs

  • Adds classifyTaskAgentKind to packages/contracts/src/providerRuntime.ts to classify tasks as 'agent' or 'background' using a shared denylist, replacing local copies in server and client.
  • The ingestion layer in apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts now stamps agentKind onto persisted task.* activity payloads, making rows self-describing for downstream consumers.
  • task.progress and tool.progress activities are now upserted under stable per-task IDs (task-progress:{taskId}, tool-progress:{taskId}) instead of per-event IDs, keeping only the latest heartbeat row and preventing progress storms from evicting start/terminal rows.
  • subagentRuntime.isBackgroundTaskActivity in packages/client-runtime/src/state/subagentRuntime.ts now reads payload.agentKind directly instead of applying a denylist heuristic.
  • Behavioral Change: unstamped (legacy) rows are treated as background by the client classifier, so any pre-stamp rows without agentKind will be excluded from the agent roster.
Macroscope summarized ea06fbf.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 48483c3e-2a87-4448-8be1-1c54860e037b

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. @@ -554,4 +565,10 @@
      554565 case "task.progress": {
      555566 return [
      556567 {
      557- id: event.eventId,
      568+ // Stable per-task id: progress is "latest state", not history, so
      569+ // each tick REPLACES the last via the activity upsert (PK + the
      570+ // replace-by-id apply in projector and client reducer). Keeps one
      571+ // progress row per task instead of thousands, so a large fleet's
      572+ // ticks can no longer evict its own start/terminal rows out of
      573+ // the 500-row retention window.
      574+ id: EventId.make(`task-progress:${event.payload.taskId}`),

      🟠 High Layers/ProviderRuntimeIngestion.ts:574

      task-progress:${event.payload.taskId} and tool-progress:${event.payload.taskId} are not scoped by thread, so the same task ID in two threads produces the same activity ID. Because activity_id is the global primary key and the upsert updates thread_id, a progress event in the second thread overwrites the first thread's row, corrupting both threads' persisted activity views. Include event.threadId in these IDs so they are globally unique.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts around line 574:
      
      `task-progress:${event.payload.taskId}` and `tool-progress:${event.payload.taskId}` are not scoped by thread, so the same task ID in two threads produces the same activity ID. Because `activity_id` is the global primary key and the upsert updates `thread_id`, a progress event in the second thread overwrites the first thread's row, corrupting both threads' persisted activity views. Include `event.threadId` in these IDs so they are globally unique.
    4. Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 498881e316b1ccf561acd5125cd6dffa60d688f9. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -314,4 +316,13 @@
      314316 * client folds survive activity retention; absent fields stay absent.
      315317 */
      316318 function taskLinkageActivityFields(payload: Record<string, unknown>): Record<string, unknown> {
      317- const fields: Record<string, unknown> = {};
      319+ const fields: Record<string, unknown> = {
      320+ // Server-stamped classification: persisted rows are self-describing, so
      321+ // clients trust the stamp instead of re-deriving agent-vs-background
      322+ // from taskType denylists and marker heuristics (legacy rows without a
      323+ // stamp keep the client fallback).
      324+ agentKind: classifyTaskAgentKind({
      325+ taskType: typeof payload.taskType === "string" ? payload.taskType : undefined,
      326+ agentId: typeof payload.agentId === "string" ? payload.agentId : undefined,
      327+ }),
      328+ };

      Partial rows flip agentKind stamp

      Medium Severity

      taskLinkageActivityFields always stamps agentKind from the current event only via classifyTaskAgentKind, which treats a missing taskType as agent. Progress and terminal rows often omit linkage that was present on start, so a shell, monitor, or plan can be stamped agent on later rows. Clients trust that stamp outright, so those tasks can enter the Agents roster and work-log spawn CTAs even when an earlier background start row exists or was retained.

      Additional Locations (2)
      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 498881e316b1ccf561acd5125cd6dffa60d688f9. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -554,4 +565,10 @@
      554565 case "task.progress": {
      555566 return [
      556567 {
      557- id: event.eventId,
      568+ // Stable per-task id: progress is "latest state", not history, so
      569+ // each tick REPLACES the last via the activity upsert (PK + the
      570+ // replace-by-id apply in projector and client reducer). Keeps one
      571+ // progress row per task instead of thousands, so a large fleet's
      572+ // ticks can no longer evict its own start/terminal rows out of
      573+ // the 500-row retention window.
      574+ id: EventId.make(`task-progress:${event.payload.taskId}`),

      Stable progress IDs collide globally

      High Severity

      task.progress and agent-owned tool.progress now persist under task-progress:${taskId} / tool-progress:${taskId}, but projection_thread_activities.activity_id is a global primary key whose upsert also rewrites thread_id. taskId is only session-scoped, so two threads that share a task id fight over one row: progress moves or vanishes across threads on snapshot reload.

      Additional Locations (1)
      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 498881e316b1ccf561acd5125cd6dffa60d688f9. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      2 blocking correctness issues found. Multiple unresolved review comments identify high-severity bugs: progress event IDs lack thread scoping (risking cross-thread data corruption), partial rows may receive incorrect agentKind stamps, and legacy pre-stamp rows are broken. These data integrity concerns require human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. @@ -133,21 +117 @@
      133- * roster (review finding: old "tailing logs" tasks appeared as running
      134- * subagents after upgrading). Every new emitter marks its rows: Claude
      135- * repeats linkage (role/model/toolUseId) on all task.* rows, workflow
      136- * members carry parentAgentId/agentIndex, Codex children carry
      137- * timelineBypass/agentPath.
      138- */
      139-function hasAgentPipelineMarker(payload: Record<string, unknown>): boolean {
      140- return (
      141- payload.timelineBypass === true ||
      142- typeof payload.role === "string" ||
      143- typeof payload.model === "string" ||
      144- typeof payload.parentAgentId === "string" ||
      145- typeof payload.agentPath === "string" ||
      146- typeof payload.workflowName === "string" ||
      147- typeof payload.toolUseId === "string" ||
      148- typeof payload.agentIndex === "number"
      149- );
      150-}
      151-
      152-/** True when this activity's payload describes a non-agent background task. */
      153117 export function isBackgroundTaskActivity(payload: Record<string, unknown>): boolean {
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium state/subagentRuntime.ts:117

      isBackgroundTaskActivity returns true for every payload without agentKind, so persisted agent rows from pre-stamp servers — e.g. a task.started with taskType: "local_agent" or a workflow member carrying parentAgentId — fail the background guards in foldSubagentActivities and vanish from the Agents roster on reload. agentKind is optional in the persisted contract, so unstamped rows should fall back to the legacy task-type/marker classifier instead of being unconditionally treated as background.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @packages/client-runtime/src/state/subagentRuntime.ts around line 117:
      
      `isBackgroundTaskActivity` returns `true` for every payload without `agentKind`, so persisted agent rows from pre-stamp servers — e.g. a `task.started` with `taskType: "local_agent"` or a workflow member carrying `parentAgentId` — fail the background guards in `foldSubagentActivities` and vanish from the Agents roster on reload. `agentKind` is optional in the persisted contract, so unstamped rows should fall back to the legacy task-type/marker classifier instead of being unconditionally treated as background.

Sign in to join this conversation.