Skip to content

ADFA-4199 facility to disable webserver's pebble cache#1357

Merged
hal-eisen-adfa merged 8 commits into
stagefrom
ADFA-Facility-to-disable-webserver's-Pebble-cache
Jun 4, 2026
Merged

ADFA-4199 facility to disable webserver's pebble cache#1357
hal-eisen-adfa merged 8 commits into
stagefrom
ADFA-Facility-to-disable-webserver's-Pebble-cache

Conversation

@jimturner-adfa
Copy link
Copy Markdown
Collaborator

Clear the Pebble Cache (Code On the Go's cache) if the file
CodeOnTheGo.webserver.cs0
is in /sdcard/Download

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 199bf03e-b46d-406e-b554-eeef46ca9d4d

📥 Commits

Reviewing files that changed from the base of the PR and between f12d1be and 0798d61.

📒 Files selected for processing (1)
  • app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
✅ Files skipped from review due to trivial changes (1)
  • app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt

📝 Walkthrough

Release Notes

Feature Addition

  • Pebble Template Cache Clearing Facility: Added ability to clear the webserver's Pebble template cache by placing a marker file (CodeOnTheGo.webserver.cs0) in /sdcard/Download
    • When the marker file exists at server startup, cache clearing is enabled
    • The template cache is cleared on each bookshelf endpoint (/pr/bs) request
    • Cache clearing flag is frozen at startup; server restart required to pick up changes to the marker file

Implementation Details

  • Added clearCacheEnablePath configuration property to ServerConfig
  • Added clearCacheEnabled boolean flag that checks marker file existence at initialization
  • Integrated cache-clearing logic in handleBsEndpoint() method

Risk/Best Practice Violations

  • Ad-hoc Feature Flag Pattern: Similar to the existing experiments flag, this implementation uses file-based marker files for feature control rather than a centralized configuration system. A TODO comment in the code indicates this should be centralized (noted by developer DS on 9-Feb-2026)
  • Runtime Behavior Tied to Filesystem State: The cache-clearing behavior depends on file presence but is frozen at server startup, creating potential confusion if users expect dynamic toggling without server restart
  • Sparse Testing Coverage: No apparent unit or integration tests added for the cache-clearing functionality

Walkthrough

Only whitespace/formatting changed in WebServer.kt: a space was added inside an if condition and an extra blank line was inserted near realHandleBsEndpoint. No code logic, control flow, signatures, or public declarations were modified.

Changes

Whitespace edits in WebServer.kt

Layer / File(s) Summary
Whitespace adjustments in WebServer.kt
app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Adds a space inside the if (!isCursorOneRow(...)) condition and inserts an extra blank line near the end of realHandleBsEndpoint/surrounding area. No functional changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

Suggested reviewers

  • jatezzz
  • hal-eisen-adfa
  • davidschachterADFA

Poem

🐰 I nudged a space, hopped a line or two,

Quiet as dusk, the code looks new,
No bug disturbed, no flow re-spun,
Just tidy fur beneath the sun. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title mentions disabling webserver's pebble cache, but the actual changes only involve whitespace/formatting with no functional modifications to cache-related logic. Either implement the cache-disabling functionality described in the title, or retitle the PR to accurately reflect the whitespace-only changes made.
Description check ⚠️ Warning The description describes clearing Pebble cache based on a marker file, but the actual code changes only modify whitespace/formatting with no cache-clearing logic implemented. Implement the described cache-clearing functionality or revise the description to match the actual whitespace-only formatting changes in the code.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ADFA-Facility-to-disable-webserver's-Pebble-cache

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt (1)

72-72: 💤 Low value

Non-atomic read-modify-write on bookshelfTemplateId in concurrent context.

bookshelfTemplateId is a mutable var accessed from realHandleBsEndpoint which can be called by multiple request-handling threads. The check-then-set pattern at lines 759-771 is racy. While functionally benign (same value is always written), consider using AtomicInteger or synchronization for clarity and correctness.

♻️ Suggested fix using AtomicInteger
-    private          var bookshelfTemplateId : Int = -1;
+    private          val bookshelfTemplateId = java.util.concurrent.atomic.AtomicInteger(-1)

Then update the usage in realHandleBsEndpoint:

// Check if template ID is cached
if (bookshelfTemplateId.get() == -1) {
    // ... query database ...
    bookshelfTemplateId.compareAndSet(-1, cursor.getInt(0))
}
val templateId = bookshelfTemplateId.get()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt` at line
72, The field bookshelfTemplateId is mutated non-atomically and read from
realHandleBsEndpoint by concurrent request threads; replace the Int var with an
AtomicInteger (or guard accesses with a synchronized block) and update all
reads/writes in realHandleBsEndpoint to use AtomicInteger.get(),
compareAndSet(-1, newValue) when caching the DB result, and AtomicInteger.get()
when reading the templateId to use—this eliminates the racy check-then-set on
bookshelfTemplateId.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt`:
- Around line 776-784: The catch in WebServer.kt currently logs and sends an
error response but does not stop further processing, allowing code after the
try/catch (which uses jsonText) to run with jsonText uninitialized; modify the
catch block in the request-handling method so that after calling
sendError(writer, output, 500, "Internal Server Error", e.message ?: "") it
immediately returns false (or otherwise exits the handler) to prevent reaching
instantiatePebbleTemplate(...) and using jsonText, ensuring cursor.close() still
runs in finally.
- Around line 490-492: The unconditional debug call "log.debug(\"context =
${context}\")" in WebServer.kt should be gated like other debug logs to avoid
interpolation overhead; wrap it with the existing debug check (e.g., use
log.isDebugEnabled or the file's debugEnabled pattern) or use a lazy/logging API
that defers message construction, referencing the "log.debug" call and the
"context" value so the message is only constructed and emitted when debugging is
enabled.
- Around line 759-771: The code reassigns the variable cursor when fetching the
'bookshelf' template ID, leaking the earlier cursor resource; before calling
database.rawQuery("SELECT id FROM Templates WHERE name = 'bookshelf'") reclose
the existing cursor (or use a new variable like templateCursor) so the original
cursor is closed, then proceed to check cursor.count, moveToFirst(), and set
bookshelfTemplateId; ensure the finally block still closes whichever cursor
variable(s) are used and that sendError and the rest of the logic remain
unchanged.

---

Nitpick comments:
In `@app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt`:
- Line 72: The field bookshelfTemplateId is mutated non-atomically and read from
realHandleBsEndpoint by concurrent request threads; replace the Int var with an
AtomicInteger (or guard accesses with a synchronized block) and update all
reads/writes in realHandleBsEndpoint to use AtomicInteger.get(),
compareAndSet(-1, newValue) when caching the DB result, and AtomicInteger.get()
when reading the templateId to use—this eliminates the racy check-then-set on
bookshelfTemplateId.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9380d000-c893-4a8f-a865-2aa7f2e0c81a

📥 Commits

Reviewing files that changed from the base of the PR and between 4f206c6 and ed5ab9c.

📒 Files selected for processing (1)
  • app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt

Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt Outdated
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt Outdated
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt Outdated
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
jatezzz
jatezzz previously requested changes Jun 4, 2026
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt Outdated
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt Outdated
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt Outdated
@hal-eisen-adfa hal-eisen-adfa changed the title Adfa facility to disable webserver's pebble cache ADFA-4199 facility to disable webserver's pebble cache Jun 4, 2026
@hal-eisen-adfa hal-eisen-adfa dismissed stale reviews from jatezzz and dara-abijo-adfa June 4, 2026 23:38

Done

@hal-eisen-adfa hal-eisen-adfa merged commit d71e643 into stage Jun 4, 2026
2 checks passed
@hal-eisen-adfa hal-eisen-adfa deleted the ADFA-Facility-to-disable-webserver's-Pebble-cache branch June 4, 2026 23:39
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.

5 participants