Skip to content

[AUTOMATION] fix(clawpatch): address daily finding#258

Open
michiosw wants to merge 1 commit into
mainfrom
fix/clawpatch-daily-20260607T090143Z
Open

[AUTOMATION] fix(clawpatch): address daily finding#258
michiosw wants to merge 1 commit into
mainfrom
fix/clawpatch-daily-20260607T090143Z

Conversation

@michiosw

@michiosw michiosw commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Where We Are

kontext guard start installed Claude hooks before the daemon proved it could bind and serve. If startup failed after that write, Claude was left pointing at a dead local Guard hook.

Where We Want To Go

Daemon startup should only install Claude hooks after the local runtime and HTTP listener are ready. A failed start should leave ~/.claude/settings.json unchanged.

How do we get there

Bind the TCP listener before hook installation, then serve with that pre-opened listener. Add a regression test that starts the daemon with an invalid listen address and proves no Claude settings file is created. Verified with go test ./..., go vet ./..., npm exec --yes --package pnpm@10.0.0 -- pnpm install --frozen-lockfile, npm exec --yes --package pnpm@10.0.0 -- pnpm --dir web/guard-dashboard typecheck, and git diff --check.

Finding: Hook install is not rolled back when daemon startup fails

Severity: medium

Clawpatch ID: fnd_sig-feat-cli-command-56a5b2eae3-_0b3f60c190

michiosw commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@greptile-apps

greptile-apps Bot commented Jun 7, 2026

Copy link
Copy Markdown

Greptile Summary

This PR delays Claude hook installation until daemon startup has passed more checks. The main changes are:

  • Verifies Claude Code before startup but writes hooks only after runtime and TCP bind succeed.
  • Pre-binds the local dashboard listener before installing hooks.
  • Adds a regression test for avoiding hook writes when startup fails.

Confidence Score: 4/5

This is close, but the timeout regression should be fixed before merging.

  • The hook-install sequencing change addresses the intended startup failure path.

  • The new serve path drops the existing HTTP header timeout.

  • The dashboard can hold connections open indefinitely when clients send headers slowly.

  • internal/guard/cli/cli.go

Security Review

  • Resource exhaustion hardening regression in internal/guard/cli/runDaemon: replacing Server.ListenAndServe with http.Serve drops the dashboard server's HTTP header read timeout.

Important Files Changed

Filename Overview
internal/guard/cli/cli.go Moves hook installation later in daemon startup and changes dashboard serving to use a pre-bound listener.
internal/guard/cli/cli_test.go Adds a regression test for preventing Claude settings writes when daemon startup fails.

Reviews (1): Last reviewed commit: "fix(clawpatch): address daily finding" | Re-trigger Greptile

Comment thread internal/guard/cli/cli.go
_ = browser.OpenURL("http://" + *addr)
}
return localServer.ListenAndServe(*addr)
return http.Serve(listener, localServer.Handler())

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 security Restore header timeout

This change bypasses localServer.ListenAndServe, which was setting ReadHeaderTimeout to 5 seconds. The package-level http.Serve uses a zero-value server, so a client that connects to the dashboard address and slowly sends headers can keep connections open indefinitely, especially when --addr or KONTEXT_ADDR exposes the daemon beyond loopback.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2a3521ead3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/guard/cli/cli.go
_ = browser.OpenURL("http://" + *addr)
}
return localServer.ListenAndServe(*addr)
return http.Serve(listener, localServer.Handler())

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 Badge Restore read-header timeout when serving daemon

When the daemon is run with a non-loopback --addr/KONTEXT_ADDR or there is an untrusted local client, this replacement drops the ReadHeaderTimeout: 5 * time.Second that server.ListenAndServe used to apply, so slow clients can hold HTTP connections open indefinitely by trickling request headers. Please serve the pre-bound listener through an http.Server configured with the same timeout instead of calling http.Serve directly.

Useful? React with 👍 / 👎.

@michiosw michiosw changed the title fix(clawpatch): address daily finding [AUTOMATION] fix(clawpatch): address daily finding Jun 7, 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