Skip to content

fix(harness): key a new session's first turn by its session id - #375

Merged
pdettori merged 1 commit into
rossoctl:mainfrom
pdettori:fix/turn-new-session-workspace-key
Sep 30, 2026
Merged

pdettori merged 1 commit into
rossoctl:mainfrom
pdettori:fix/turn-new-session-workspace-key

Conversation

@pdettori

Copy link
Copy Markdown
Member

Summary

fix(harness): key a new session's first turn by its session id

executeTurn opens the session before it leases a sandbox, so that a missing session 404s before any pool work (pinned by turn-session-before-lease.test.ts). But it leased with input.sessionId, which is undefined when /turn omits it. acquireTurnSandbox then keyed the workspace by the per-turn lease holder, anon:<uuid>.

Two failures followed:

  • The microVM tier refused the key. Seen on the KVM rig while running VM demo D: wire the P4 microVM worker into P6 and run its first real harness turn #369's P4 turns: every tool call of a new session's first turn failed with
    invalid-workspace-key: workspace_key "anon:…" must match [A-Za-z0-9][A-Za-z0-9._-]{0,127}.
  • Turn 1's work was lost to later turns. On any tier that keys workspaces, turn 1 wrote into a workspace no later turn opens, because turn 2 is keyed by the real session id.

Authenticated turns are not affected: the token names an existing session, so sessionId is set.

The fix leases under opened.sessionManager.getSessionId(), the same id the response returns. Every /turn entry point goes through executeTurn: sync unauthenticated, sync authenticated, and SSE.

Tests

  • New: harness/test/turn-new-session-workspace-key.test.ts. It fails on main, receiving anon:<uuid>.
  • Updated: the "anonymous turn" case in harness/test/turn-lease-holder.test.ts. It pinned the anon: fallback on the premise that such a turn has no continuity to preserve, but every such turn creates a session the client then continues. The concerns the old case guarded still hold: the key is neither a shared anon workspace nor empty.
  • Results: harness 502 passed / 5 skipped; knative-server 415 passed; make typecheck and make lint clean.
  • Live: verified on the KVM rig. With this fix applied, VM demo D: wire the P4 microVM worker into P6 and run its first real harness turn #369's P4 smoke run passed every check. Without it, session A's first turn failed as above.

Notes

  • acquireTurnSandbox keeps its sessionId ?? holderId fallback and its "anonymous turn" comment. executeTurn, its only non-test caller, no longer reaches that path. Happy to tighten the parameter to string in this PR if preferred.

Refs #369 (needed by its P4 tier).

🤖 Generated with Claude Code

executeTurn opens the session before leasing a sandbox, but leased with
input.sessionId, which is undefined when /turn omits it. acquireTurnSandbox
then keyed the workspace by the per-turn lease holder (anon:<uuid>): the
microVM tier refuses that key, so every tool call of a new session's first
turn failed, and on any keyed tier turn 1 wrote into a workspace no later
turn of the session opened. Lease under the opened session's id instead.

Found on the KVM rig while running rossoctl#369's P4 turns.
Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Self-review — GitHub won't let the author approve.) Clean, well-scoped fix. executeTurn now leases under opened.sessionManager.getSessionId() instead of input.sessionId (undefined for a new session), which fixes both the microVM invalid-workspace-key failure and the turn-1 workspace orphaning. The new regression test fails on main and pins the correct key; the updated lease-holder test still guards the original concerns (no shared anon workspace, no empty key). Verified getSessionId() on the real SessionManager, confirmed executeTurn is the sole non-test caller of acquireTurnSandbox, and ran the three relevant test files locally — all pass. LGTM.

Commits: 1 commit, signed-off ✓
CI: all checks green

Comment thread harness/src/run-turn.ts
// The OPENED session's id, not input.sessionId: a /turn that omitted it has just been given one by
// openTurnSession, and leasing under `undefined` keyed the workspace by the per-turn lease holder
// (`anon:<uuid>`) -- a key the microVM tier refuses, and one no later turn of the session reuses.
const acquired = await acquireTurnSandbox(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: with this change, acquireTurnSandbox's sessionId ?? holderId fallback and its "anonymous turn" comment are effectively dead code — its only production caller now always passes a real session id. Worth tightening the parameter to string (and updating that comment) in a follow-up so the anon: fallback can't silently return via a future call site.

@pdettori
pdettori merged commit 6836941 into rossoctl:main Sep 30, 2026
13 checks passed
@pdettori
pdettori deleted the fix/turn-new-session-workspace-key branch September 30, 2026 19:50
pdettori added a commit to pdettori/moca that referenced this pull request Sep 30, 2026
Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
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