Skip to content

[codex] Persist agent streams after response#4325

Open
caydyan wants to merge 8 commits into
stakwork:masterfrom
caydyan:codex/persist-agent-stream-after
Open

[codex] Persist agent streams after response#4325
caydyan wants to merge 8 commits into
stakwork:masterfrom
caydyan:codex/persist-agent-stream-after

Conversation

@caydyan

@caydyan caydyan commented Jun 14, 2026

Copy link
Copy Markdown

Summary

  • add an opt-in startStreamInBackground path to /api/agent that saves a STREAM artifact and schedules the remote /stream/:taskId POST in Next.js after()
  • keep existing browser-owned stream fields and direct-stream fallback for callers that do not opt in
  • wire task agent mode to opt in, consume the STREAM artifact through the existing event/log hooks, and show live streamed logs in the artifact panel
  • add a focused route unit test that proves the stream POST is delayed until the captured after() callback runs

Bounty context

This targets Sphinx bounty #4316, "persistent streaming from agent". The route now keeps the agent stream owned by Hive after the response returns, so leaving the task page does not cancel the remote stream start/drain path.

Validation

  • npx vitest run src/__tests__/unit/api/agent-background-stream.test.ts src/__tests__/unit/api/agent-rollback-logging.test.ts
  • npx eslint src/app/api/agent/route.ts 'src/app/w/[slug]/task/[...taskParams]/page.tsx' src/__tests__/unit/api/agent-background-stream.test.ts --max-warnings=999 (passes with 3 existing warnings in the task page)
  • npx tsc --noEmit --pretty false 2>&1 | rg 'src/app/api/agent/route.ts|src/app/w/\[slug\]/task/\[\.\.\.taskParams\]/page.tsx|src/__tests__/unit/api/agent-background-stream.test.ts' (no diagnostics for touched files; full repo typecheck currently reports unrelated existing test/type issues)

@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

@caydyan is attempting to deploy a commit to the Stak Team on Vercel.

A member of the Team first needs to authorize it.

@caydyan
caydyan marked this pull request as ready for review June 14, 2026 06:45
@caydyan

caydyan commented Jun 14, 2026

Copy link
Copy Markdown
Author

Ready for review after re-running the focused validation locally.

Validation rerun:

  • npx vitest run src/__tests__/unit/api/agent-background-stream.test.ts src/__tests__/unit/api/agent-rollback-logging.test.ts (3 tests passing)
  • npx eslint src/app/api/agent/route.ts 'src/app/w/[slug]/task/[...taskParams]/page.tsx' src/__tests__/unit/api/agent-background-stream.test.ts --max-warnings=999 (0 errors; existing task-page warnings only)
  • git diff --check and git diff --check origin/master...HEAD
  • filtered npx tsc --noEmit --pretty false check shows no diagnostics for touched files

The visible Vercel status is an external-contributor authorization gate (Authorization required to deploy), not a build/test failure.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch from 7c077a6 to c908f62 Compare June 14, 2026 20:49
@caydyan

caydyan commented Jun 14, 2026

Copy link
Copy Markdown
Author

Rebased on current origin/master (head c908f62345f818f973cf76e209af804e28881c01) and reran validation.

Validation:

  • npx vitest run src/__tests__/unit/api/agent-background-stream.test.ts src/__tests__/unit/api/agent-rollback-logging.test.ts (3 tests passing)
  • npx eslint src/app/api/agent/route.ts 'src/app/w/[slug]/task/[...taskParams]/page.tsx' src/__tests__/unit/api/agent-background-stream.test.ts --max-warnings=999 (0 errors; existing task-page warnings only)
  • git diff --check and git diff --check origin/master...HEAD
  • filtered npx tsc --noEmit --pretty false output has no diagnostics for touched files

The remaining visible status is the Vercel external-contributor authorization gate, not a local validation failure.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch from c908f62 to dbb2198 Compare June 14, 2026 21:46
@caydyan

caydyan commented Jun 14, 2026

Copy link
Copy Markdown
Author

Rebased on current origin/master (base 56d963cdb) and pushed updated head dbb2198a5.

Validation after rebase:

  • npx vitest run src/__tests__/unit/api/agent-background-stream.test.ts (1 test passing)
  • npx eslint src/app/api/agent/route.ts 'src/app/w/[slug]/task/[...taskParams]/page.tsx' src/__tests__/unit/api/agent-background-stream.test.ts (0 errors; existing warnings only)
  • git diff --check origin/master...HEAD

Full npm test is still locally blocked in the integration phase because TEST_DATABASE_URL/DATABASE_URL is not configured.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch from dbb2198 to 1db976d Compare June 14, 2026 22:40
@caydyan

caydyan commented Jun 14, 2026

Copy link
Copy Markdown
Author

Rebased onto current upstream master (base 2547637704d301824c6364cfcf7c7c3f4f4370df) and force-with-lease pushed head 1db976d26ccda914a54dd276f24869b7d2024dfa.

Validation after rebase:

  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts (1 passed)
  • npm run lint -- --quiet
  • git diff --check origin/master...HEAD

The PR is mergeable from the GitHub side. The remaining blocked check is Vercel authorization for an external contributor deployment.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch from 1db976d to decacaa Compare June 14, 2026 23:19
@caydyan

caydyan commented Jun 14, 2026

Copy link
Copy Markdown
Author

Rebased this PR onto current origin/master (7acd7cf3c) and force-with-lease pushed new head decacaa24.

Validation on the rebased head:

  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts (1 passed)
  • npm run lint -- --quiet
  • git diff --check origin/master...HEAD

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch from decacaa to d58f85c Compare June 15, 2026 00:06
@caydyan

caydyan commented Jun 15, 2026

Copy link
Copy Markdown
Author

Rebased onto current upstream master (base bfb24edb6) and force-with-lease pushed head d58f85c81.

Validation after rebase:

  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts (1 passed)
  • npm run lint -- --quiet
  • git diff --check origin/master...HEAD

GitHub reports the PR is mergeable; the remaining blocked status is still the Vercel external-contributor authorization gate.

@caydyan

caydyan commented Jun 15, 2026

Copy link
Copy Markdown
Author

Current-head validation on d58f85c8 after syncing with latest origin/master (bfb24edb6):

  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts (1 passed)
  • npm run lint -- --quiet
  • git diff --check origin/master...HEAD

The remaining visible blocker is still the Vercel external-contributor deployment authorization gate, not a code/test failure.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch 3 times, most recently from bde8194 to 0c97829 Compare June 15, 2026 06:02
@caydyan

caydyan commented Jun 15, 2026

Copy link
Copy Markdown
Author

Rebased this branch onto current upstream master (af2ff827) and force-with-lease pushed head 0c97829c.

Validation after rebase:

  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts — 1 test passed
  • npm run lint -- --quiet
  • git diff --check origin/master...HEAD

GitHub REST now reports the PR open, non-draft, mergeable=true, with mergeable_state=blocked; the remaining visible status is the Vercel external-contributor authorization gate, not branch drift or a code/test failure.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch 5 times, most recently from 65d3427 to 56c6590 Compare June 17, 2026 13:32
@caydyan

caydyan commented Jun 17, 2026

Copy link
Copy Markdown
Author

Rebased this PR onto current upstream master (head c3fbaa08f) and force-with-lease pushed updated head 56c6590e3.\n\nValidation after rebase:\n- npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts (1 passed)\n- npm run lint -- --quiet\n- git diff --check origin/master...HEAD\n\nGitHub reports the PR is mergeable; the remaining blocked state is still external review/deployment authorization rather than a code/test failure.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch 5 times, most recently from 9c0a394 to f9ea19d Compare June 18, 2026 09:28
@caydyan

caydyan commented Jun 18, 2026

Copy link
Copy Markdown
Author

Rebased this PR onto current upstream master (21dede4f5) and force-with-lease pushed updated head f9ea19d2f.

Validation after rebase:

  • npm ci --ignore-scripts --no-audit --no-fund
  • npx prisma generate
  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts (1 passed)
  • npm run lint -- --quiet
  • git diff --check origin/master...HEAD

GitHub now reports the branch at head f9ea19d2fc2247f4fe52f5b5842c4550a4074483, mergeable=true, with the remaining state blocked rather than behind.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch 2 times, most recently from 8f49638 to cea1be1 Compare June 19, 2026 10:03
@caydyan

caydyan commented Jun 19, 2026

Copy link
Copy Markdown
Author

Rebased this PR onto current upstream master (5e6c18a08) and force-with-lease pushed updated head cea1be10b.

Validation after rebase:

  • npm ci --ignore-scripts --no-audit --no-fund
  • npx prisma generate
  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts (1 passed)
  • npm run lint -- --quiet
  • git diff --check origin/master...HEAD

GitHub now reports the PR open/non-draft, MERGEABLE, with remaining state BLOCKED rather than BEHIND; the visible blocker remains external review/deployment authorization.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch from cea1be1 to d1c3e32 Compare June 19, 2026 10:23
@caydyan

caydyan commented Jun 19, 2026

Copy link
Copy Markdown
Author

Rebased again onto current upstream master (9fdf03e8b3e9a181118540d3bdbd7d1ae82f04cb) after the branch drifted behind, and force-with-lease pushed updated head d1c3e32bc6a0017d410f6fcf353f1476de68910b.

Validation from a clean temporary worktree:

  • npm ci --ignore-scripts --no-audit --no-fund
  • npx prisma generate
  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts
  • npm run lint -- --quiet
  • git diff --check origin/master...HEAD

GitHub now reports the PR as MERGEABLE / BLOCKED, with the branch-behind condition cleared.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch from d1c3e32 to 9389f5e Compare June 19, 2026 23:19
@caydyan

caydyan commented Jun 19, 2026

Copy link
Copy Markdown
Author

Rebased this branch onto the latest master to clear the behind-base state.

Local validation run after the rebase:

  • npx prisma generate
  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts
  • npm run lint -- --quiet
  • git diff --check upstream/master...HEAD

All passed locally.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch 2 times, most recently from 26f11ed to 73459d8 Compare June 22, 2026 03:45
@caydyan

caydyan commented Jun 22, 2026

Copy link
Copy Markdown
Author

Rebased this branch onto latest upstream master (7c12ed06) and force-with-lease pushed head 73459d86 to clear the behind-base state.

Validation on the rebased head:

  • npm ci --ignore-scripts --no-audit --no-fund
  • npx prisma generate
  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts (1 passed)
  • npm run lint -- --quiet
  • git diff --check upstream/master...HEAD

GitHub now reports the PR as MERGEABLE / BLOCKED; the remaining blocker is external review/deployment authorization rather than branch drift.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch from 73459d8 to 06a183b Compare June 22, 2026 09:32
@caydyan

caydyan commented Jun 22, 2026

Copy link
Copy Markdown
Author

Rebased this PR onto current upstream master (9e882009c) and force-with-lease pushed head 06a183b9 to clear the behind-base state again.

Validation from a clean temporary worktree:

  • npm ci --ignore-scripts --no-audit --no-fund
  • npx prisma generate
  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts (1 passed)
  • npm run lint -- --quiet
  • git diff --check origin/master...HEAD

GitHub now reports the PR as MERGEABLE / BLOCKED; the remaining blocker is still external review/deployment authorization rather than branch drift or a code/test failure.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch from 06a183b to a8127be Compare June 22, 2026 10:10
@caydyan

caydyan commented Jun 22, 2026

Copy link
Copy Markdown
Author

Rebased this PR onto current upstream master (d5b15ed) and force-with-lease pushed updated head a8127bef.

Validation from a clean temporary worktree:

  • npm ci --ignore-scripts --no-audit --no-fund
  • npx prisma generate
  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts (1 passed)
  • npm run lint -- --quiet
  • git diff --check origin/master...HEAD

GitHub now reports the PR as mergeable with the branch-drift blocker cleared again.

@caydyan
caydyan force-pushed the codex/persist-agent-stream-after branch from a8127be to b06f4d6 Compare June 22, 2026 10:59
@caydyan

caydyan commented Jun 22, 2026

Copy link
Copy Markdown
Author

Rebased this PR onto current upstream master (1e1b144) and force-with-lease pushed updated head b06f4d678 to clear the branch-behind state again.

Validation from a clean temporary worktree:

  • npm ci --ignore-scripts --no-audit --no-fund
  • npx prisma generate
  • npm run test:unit -- src/__tests__/unit/api/agent-background-stream.test.ts (1 passed)
  • npm run lint -- --quiet
  • git diff --check origin/master...HEAD

GitHub now reports the PR open/non-draft, MERGEABLE / BLOCKED; the branch-drift blocker is cleared, with the remaining blocker still external review/deployment authorization rather than a code/test failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant