Skip to content

fix(orchestrator): prioritize real thread CWD in workspace selection and read renamed SQLite thread names - #912

Merged
kxn merged 1 commit into
kxn:masterfrom
footballqq:fix/headless-pool-workspace-thread-selection
Sep 11, 2026
Merged

kxn merged 1 commit into
kxn:masterfrom
footballqq:fix/headless-pool-workspace-thread-selection

Conversation

@openclawq

Copy link
Copy Markdown
Contributor

Summary

This PR addresses two critical issues where sessions (specifically renamed sessions like /rename svmnew0910 or sessions under active workspaces like svmpy) fail to display properly in /use and /list target pickers:

  1. SQLite Renamed Threads (threads.name) Support:

    • In modern Codex SQLite schemas, /rename updates the threads.name column while leaving threads.title as the initial long prompt summary.
    • internal/codexstate/sqlite_threads.go previously only queried title, resulting in renamed sessions retaining their old generated names.
    • Added schema column detection to select COALESCE(NULLIF(name, ''), title) AS title.
  2. Managed Headless Pool Workspace Key Contamination Fix:

    • When preheating managed headless instances running in the background state directory (e.g., ~/.local/state/codex-remote), receiving an EventThreadsSnapshot previously overwrote unrelated thread records' WorkspaceKey to the headless instance's workspace root.
    • Downstream session filtering (threadBelongsToInstanceWorkspace and threadWorkspaceKeyFromRecord) previously prioritized thread.WorkspaceKey over thread.CWD, causing sessions located in workspaces like svmpy to be filtered out (0/50 matching) whenever their key was contaminated.
    • Fixed EventThreadsSnapshot to avoid contaminating thread workspace keys with unrelated instance roots.
    • Fixed threadBelongsToInstanceWorkspace and threadWorkspaceKeyFromRecord to prioritize the thread's real physical CWD and detect cross-workspace hierarchy mismatches.

Changes

  • internal/codexstate/sqlite_threads.go:
    • Dynamically check for name column on threads table via PRAGMA table_info.
    • Fallback cleanly to title when name does not exist.
    • Added unit test TestSQLiteThreadCatalogPrefersRenamedNameColumn.
  • internal/core/orchestrator/service.go:
    • Preserve thread's real CWD workspace mapping in EventThreadsSnapshot when !cwdBelongsToInstanceWorkspace(inst, thread.CWD).
  • internal/core/orchestrator/service_surface_selection.go:
    • Prioritize thread.CWD over potentially contaminated WorkspaceKey in threadBelongsToInstanceWorkspace.
  • internal/core/orchestrator/service_thread_global.go:
    • Reconcile threadWorkspaceKeyFromRecord against thread.CWD hierarchy.
  • internal/core/orchestrator/service_target_picker_polluted_workspace_test.go:
    • Unit tests verifying target picker options inclusion and snapshot isolation.
  • docs/implemented/headless-pool-workspace-thread-selection-fix.md & docs/README.md:
    • Full architecture analysis and lifecycle documentation.

Verification

  • go test -v ./internal/codexstate -run TestSQLiteThreadCatalogPrefersRenamedNameColumn (PASS)
  • go test -v ./internal/core/orchestrator -run "TestTargetPickerSessionOptionsIncludesThreadsWithCrossInstancePollutedWorkspaceKey|TestEventThreadsSnapshotDoesNotPolluteThreadWorkspaceKeyFromUnrelatedInstance" (PASS)
  • bash scripts/check/pre-commit.sh (PASS)

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.

2 participants