Skip to content

fix(mount): cache scaffold reads per generation - #433

Closed
miyaontherelay wants to merge 1 commit into
mainfrom
fix/168-static-scaffold-mount-cache
Closed

fix(mount): cache scaffold reads per generation#433
miyaontherelay wants to merge 1 commit into
mainfrom
fix/168-static-scaffold-mount-cache

Conversation

@miyaontherelay

Copy link
Copy Markdown
Contributor

Related: AgentWorkforce/relayfile-cloud#168

Summary

  • retain /discovery/** and LAYOUT.md content for the lifetime of a mount generation
  • coalesce concurrent first reads so one remote request supplies all waiters
  • keep the existing TTL behavior for mutable files
  • use the existing websocket invalidation path as the generation boundary

Regression controls

  • must-not-fire: nine scaffold accesses produce one remote read
  • must-fire: generation invalidation forces the next scaffold read remote
  • concurrent access: 24 readers coalesce to one remote read
  • mutable control: ordinary content still expires and refetches

Verification

  • go test -race ./internal/mountfuse

No merge or deployment performed.

Session-Id: 01a02017-d3b0-7e20-87dd-bf1b9408ee54
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4f57f268-9f18-43fd-80f2-9ee10f592f85


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.

@github-actions

Copy link
Copy Markdown

Relayfile Eval Review

Run: .relayfile/evals/runs/2026-08-20T17-23-09-555Z-HEAD-provider
Mode: provider
Git SHA: 407536a

Passed: 4 | Needs human: 0 | Reviewable: 0 | Missing output: 0 | Failed: 0 | Skipped: 0

Human Review Cases

No reviewable human-review cases captured Relayfile output.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="internal/mountfuse/static_scaffold_cache_test.go">

<violation number="1" location="internal/mountfuse/static_scaffold_cache_test.go:66">
P3: In TestStaticScaffoldConcurrentReadsCoalesce, readFileFunc calls t.Fatalf from a reader goroutine, not the test goroutine. FailNow is only reliable on the test goroutine; calling it from other goroutines can leave goroutines running and is discouraged. Since only one path is ever passed this branch never fires, so it's a cleanliness nit rather than a behavior bug. Hoist the path check to the test body instead.</violation>
</file>

<file name="internal/mountfuse/fs.go">

<violation number="1" location="internal/mountfuse/fs.go:339">
P1: When websocket invalidation arrives during a scaffold fetch, the next read joins the old load and its completion permanently recaches the pre-invalidation content. Retire in-flight loads at the generation boundary or tag results with a generation and discard responses started before invalidation.</violation>

<violation number="2" location="internal/mountfuse/fs.go:352">
P2: When the first FUSE reader is canceled while other readers still wait, the shared `ReadFile` uses the canceled leader context and returns `context.Canceled` to every waiter. Give each coalesced load an independent lifecycle context instead of binding the remote request to one reader.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread internal/mountfuse/fs.go
}
delete(s.fileCache, remotePath)
}
if existing, ok := s.fileLoads[remotePath]; ok {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: When websocket invalidation arrives during a scaffold fetch, the next read joins the old load and its completion permanently recaches the pre-invalidation content. Retire in-flight loads at the generation boundary or tag results with a generation and discard responses started before invalidation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/mountfuse/fs.go, line 339:

<comment>When websocket invalidation arrives during a scaffold fetch, the next read joins the old load and its completion permanently recaches the pre-invalidation content. Retire in-flight loads at the generation boundary or tag results with a generation and discard responses started before invalidation.</comment>

<file context>
@@ -303,12 +311,68 @@ func (s *fsState) getFile(remotePath string) (mountsync.RemoteFile, bool) {
+		}
+		delete(s.fileCache, remotePath)
+	}
+	if existing, ok := s.fileLoads[remotePath]; ok {
+		s.cacheMu.Unlock()
+		select {
</file context>

Comment thread internal/mountfuse/fs.go
s.fileLoads[remotePath] = load
s.cacheMu.Unlock()

file, err := s.client.ReadFile(ctx, s.workspaceID, remotePath)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: When the first FUSE reader is canceled while other readers still wait, the shared ReadFile uses the canceled leader context and returns context.Canceled to every waiter. Give each coalesced load an independent lifecycle context instead of binding the remote request to one reader.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/mountfuse/fs.go, line 352:

<comment>When the first FUSE reader is canceled while other readers still wait, the shared `ReadFile` uses the canceled leader context and returns `context.Canceled` to every waiter. Give each coalesced load an independent lifecycle context instead of binding the remote request to one reader.</comment>

<file context>
@@ -303,12 +311,68 @@ func (s *fsState) getFile(remotePath string) (mountsync.RemoteFile, bool) {
+	s.fileLoads[remotePath] = load
 	s.cacheMu.Unlock()
+
+	file, err := s.client.ReadFile(ctx, s.workspaceID, remotePath)
+	if err == nil {
+		file.Path = normalizeRemotePath(file.Path)
</file context>

}
}

func TestStaticScaffoldConcurrentReadsCoalesce(t *testing.T) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: In TestStaticScaffoldConcurrentReadsCoalesce, readFileFunc calls t.Fatalf from a reader goroutine, not the test goroutine. FailNow is only reliable on the test goroutine; calling it from other goroutines can leave goroutines running and is discouraged. Since only one path is ever passed this branch never fires, so it's a cleanliness nit rather than a behavior bug. Hoist the path check to the test body instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/mountfuse/static_scaffold_cache_test.go, line 66:

<comment>In TestStaticScaffoldConcurrentReadsCoalesce, readFileFunc calls t.Fatalf from a reader goroutine, not the test goroutine. FailNow is only reliable on the test goroutine; calling it from other goroutines can leave goroutines running and is discouraged. Since only one path is ever passed this branch never fires, so it's a cleanliness nit rather than a behavior bug. Hoist the path check to the test body instead.</comment>

<file context>
@@ -0,0 +1,152 @@
+	}
+}
+
+func TestStaticScaffoldConcurrentReadsCoalesce(t *testing.T) {
+	const scaffoldPath = "/discovery/google-mail/LAYOUT.md"
+	started := make(chan struct{})
</file context>

@khaliqgant khaliqgant closed this Aug 20, 2026
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