Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix: block native Grok resume when --cwd overrides the session directory

Cursor Agent3fbf84744643
diff --git a/cli/beacon/internal/handoff/grok_test.go b/cli/beacon/internal/handoff/grok_test.go
index c9876325..c1bc50f7 100644
--- a/cli/beacon/internal/handoff/grok_test.go
+++ b/cli/beacon/internal/handoff/grok_test.go
@@ -152,15 +152,23 @@ func TestPlanResumeReopensAGrokSessionByItsID(t *testing.T) {
for _, tc := range []struct {
name string
edit func(*Session)
+ opts func(*PlanOptions)
reason string
}{
- {"subagent", func(s *Session) { s.Subagent = true }, ReasonNotResumable},
- {"gone", func(s *Session) { s.SourcePath = filepath.Join(t.TempDir(), "missing") }, ReasonSessionGone},
+ {"subagent", func(s *Session) { s.Subagent = true }, nil, ReasonNotResumable},
+ {"gone", func(s *Session) { s.SourcePath = filepath.Join(t.TempDir(), "missing") }, nil, ReasonSessionGone},
+ {"cwd override", nil, func(o *PlanOptions) { o.Dir = t.TempDir() }, ReasonNotResumable},
} {
t.Run(tc.name, func(t *testing.T) {
s := session
- tc.edit(&s)
- plan, err := PlanResume(s, PlanOptions{BriefPath: brief, LookPath: installed("grok")})
+ if tc.edit != nil {
+ tc.edit(&s)
+ }
+ opts := PlanOptions{BriefPath: brief, LookPath: installed("grok")}
+ if tc.opts != nil {
+ tc.opts(&opts)
+ }
+ plan, err := PlanResume(s, opts)
if err != nil {
t.Fatalf("PlanResume: %v", err)
}
diff --git a/cli/beacon/internal/handoff/resume.go b/cli/beacon/internal/handoff/resume.go
index bafdced4..a0e13684 100644
--- a/cli/beacon/internal/handoff/resume.go
+++ b/cli/beacon/internal/handoff/resume.go
@@ -130,6 +130,9 @@ func nativeBlocker(session Session, target string, opts PlanOptions) string {
return ReasonFromRuntimeLog
}
command, _ := commandFor(target)
+ if command.CwdScopedResume && opts.Dir != "" && opts.Dir != session.Directory {
+ return ReasonNotResumable
+ }
if command.Resume == nil {
return ReasonNotResumable
}
diff --git a/cli/beacon/internal/handoff/runtimes.go b/cli/beacon/internal/handoff/runtimes.go
index cf355172..6a6bf6b0 100644
--- a/cli/beacon/internal/handoff/runtimes.go
+++ b/cli/beacon/internal/handoff/runtimes.go
@@ -47,6 +47,10 @@ type runtimeCommand struct {
// Env overrides the runtime's environment: a variable set to a value is set, one set to "" is
// removed. It holds switches only, never credentials, because the plan prints it.
Env map[string]string
+ // CwdScopedResume is true when the runtime looks up a session id under its working directory.
+ // A --cwd override that differs from the session's recorded directory makes native resume
+ // impossible, because the id will not be found under the new directory.
+ CwdScopedResume bool
}
// Harness names, as the endpoint event schema spells them.
@@ -163,7 +167,8 @@ var runtimes = []Runtime{
// reopens runs in the mode that asks, whatever the config says; the user can still change
// the mode inside the TUI.
Command: &runtimeCommand{
- Executable: "grok",
+ Executable: "grok",
+ CwdScopedResume: true,
Resume: func(s Session) ([]string, bool) {
// A subagent is a child of the session that spawned it, not one a person reopens.
if s.Subagent {