Feature - Implemented Update State after Hagnks

fronobulax

Developer
Staff member
For reasons lost in the mists of time, I pull everything from Hagnk's as soon as the character is out of Ronin. After I do that and run the Maximizer, trying to implement the Maximizer instructions fails because there are items marked "pull & equip" and they are no longer in Hagnk's to be pulled. I seem to recall that manually refreshing the inventory would correct this but since that memory is pre-Crimb0 2016 it is certainly suspect.

In any event with r17710 I removed all, then moved a couple items to my DC, ran the Maximizer and noticed it suggested pulling and equipping one of the items that I had just put in the DC. Refreshing the inventory did not resolve the issue.

I would like this not to happen - specifically if the Maximizer suggests pulling something then the item should be in Hangk's to pull.

My uninformed suggestion would be to have KoLmafia refresh the inventory after a "take all" from Hangk's. (My "take all" is almost always via the relay browser in case that is relevant). If that is not feasible because of the time the command often takes, then an explicit command I could issue that forces KoLmafia to refresh it's idea of what is in Hangk's would work.
 

Veracity

Developer
Staff member
StorageRequest.parseTransfer:

Code:
		if ( action.equals( "pullall" ) )
		{
			// Hagnk leans back and yells something
			// ugnigntelligible to a group of Knob Goblin teegnage
			// delignquegnts, who go and grab all of your stuff
			// from storage and bring it to you.

			if ( responseText.contains( "go and grab all of your stuff" ) )
			{
				KoLConstants.storage.clear();
				KoLConstants.freepulls.clear();
				KoLCharacter.setStorageMeat( 0 );

				// Doing a "pull all" in Hagnk's does not tell
				// you what went into inventory and what went
				// into the closet.

				InventoryManager.refresh();
				ClosetRequest.refresh();
				NamedListenerRegistry.fireChange( "(coinmaster)" );

				// If we are still in a Trendy run or are pulling only
				// "favorite things", we may have left items in storage.

				if ( KoLCharacter.isTrendy() || KoLCharacter.getRestricted() || urlString.contains( "favonly=1" ) )
				{
					StorageRequest.refresh();
					KoLCharacter.updateStatus();
					return true;
				}

				transfer = true;
			}
		}
...

		if ( transfer )
		{
			KoLCharacter.updateStatus();
		}
We already update inventory and closet when you pull all. Which is to say, there should be no need for "an explicit command to refresh what is in Hagnks". That said, the "refresh" button on either of the Storage panels in the Item Manager does that.

You say there "are items marked pull and equip" in the Maximizer.

Did you have the Maximizer already open?
With a previously run maximization?
Do you have it in a tab?
 

lostcalpolydude

Developer
Staff member
How do you pull all from Hagnk's? I added a fix for KoL timing out when doing that (using the "pull all" command), which worked for me. Then I discovered it wasn't working for people that clicked the button in the relay browser, because that uses inventory.php instead of storage.php, and I believe I fixed that.

So, KoLmafia is already supposed to be doing what you ask for, and you'll need to provide more details about what you're doing that fails to trigger it. It might require a debug log from your next pull all attempt.

The Maximizer is really just a symptom of the actual bug, so it isn't particularly relevant.
 

lostcalpolydude

Developer
Staff member
Veracity, that block of code is actually useless now that KoL just returns a 504 error if you pull everything (unless you have very little to pull, at least). The code to handle that error is in GenericRequest.
 

Veracity

Developer
Staff member
Code:
			if ( this.responseCode == 504 &&
			     ( this.baseURLString.equals( "storage.php" ) ||
				 ( this.baseURLString.equals( "inventory.php" ) && this.formURLString.contains( "action=pullall" ) ) ) )
			{
				// Likely a pullall request that timed out
				PauseObject pauser = new PauseObject();
				KoLmafia.updateDisplay( "Waiting 20 seconds for KoL to finish processing..." );
				pauser.pause( 20 * 1000 );
				KoLConstants.storage.clear();
				KoLConstants.freepulls.clear();
				KoLConstants.nopulls.clear();
				InventoryManager.refresh();
				ClosetRequest.refresh();
				return true;
			}
(Most of ) the code I listed from StorageRequest should be put into its own function and called from that 504 handler.

I'll make a little submit.
 
Last edited:

fronobulax

Developer
Staff member
I use the relay browser to pull all. The Maximizer is in a Tab. It sounds like I might have stumbled on something. I'll turn on debug logging next run I finish,
 

fronobulax

Developer
Staff member
r17718

I turned on debugging, took all from hagnk's via the relay browser, waited until the browser page updated with the Hangk's is empty screen and turned off debugging. I did not see anything interesting but I will post if it is still of interest.

I went into the Item Manager and it did not seem to know about anything I had just pulled. Specifically the closet was empty even though something (KoL via the Hangk's page?) told me items were pulled and put in the closet. Checked the Maximizer and it had Pull & Equip choices. I pressed Refresh Inventory did not see any change in the Closet so pressed it again, at which point I saw closet items and the Maximizer. I am not certain two presses were necessary. i may have been impatient.

In any event, unless moving a pulled item to the DC before refreshing Inventory somehow interferes with refreshing inventory, this may be a case of some things take too long. So this can be a FR for KoLmafia to determine that a relay initiated pull has finished and refresh inventory when it is completed.

That said, I'm not sure how that could be detected and wonder if a workaround would be a relay script the monitored the state of Hangk's and triggered a refresh when it changed. Given that the browser seems to understand that it is waiting this could be resolved by user patience.
 

lostcalpolydude

Developer
Staff member
My current code just assumes that waiting 20 seconds after the 504 error is returned is long enough. Waiting longer has a good chance of fixing this, but something more resilient is probably needed.
 

Veracity

Developer
Staff member
He didn't see a 504 error: "I turned on debugging, took all from hagnk's via the relay browser, waited until the browser page updated with the Hangk's is empty screen and turned off debugging."

I think the clue is your observation that emptying storage from the Relay Browser is done via inventory.php, not storage.php. ResponseTextParser only calls the code to refresh things after emptying storage for storage.php.

Revision 17720 will call StorageRequest.parseTransfer() for inventory.php with action=pullall.
 

King Beanface

New member
I was having the same issue for months. Pretty much just logged out and back in after a hagnk's pull all to fix. I'll be finished this run in 2 days maximum and will try on 17720 with debug on and see if we're any further ahead.
 
I didn't think to turn on debugging, but here's the gCLI output I've seen the last few times I've broken the prism:

Code:
[737] Freeing King Ralph
Encounter: Finally Human
Now walking on the Accordion Thief road.
Loading character status...
Retrieving character data...
Updating inventory...
Retrieving familiar data...
Familiar data retrieved.
Refreshing session data...
Synchronizing moon data...
Loading character status...
Retrieving character data...
Updating inventory...
Examining Meat in closet...
Updating closet...
Retrieving quest data...
Retrieving familiar data...
Familiar data retrieved.
Retrieving campground data...
Examining Meat and pulls in storage...
Updating storage...
You are currently a member of KOL Addicts
Session data refreshed.
CCS set to default
Emptying storage...
[COLOR="#FF0000"]Server returned response code 504 (Gateway Time-out) for storage.php
Server returned response code 504 (Gateway Time-out) for newchatmessages.php[/COLOR]

The first line of my King Freed script is cli_execute("pull all"); There's definitely still a 504 happening during Hagnk's-emptying. I'll remember to enable debugging on my next ascension, if it'd be more helpful.
 
Last edited:

zarqon

Well-known member
My kingLiberatedScript is simply "hagnk all; call login", but it never makes it to running the login script.

Oddly, calling "hagnk all" a first time, then aborting during the wait and calling it a second time, even just a few seconds after the first, seems to result in a quick response.

Not sure if these anecdotes are helpful; but sharing in case they are.
 

Bale

Minion
My kingLiberatedScript -- perhaps foolishly -- uses visit_url( "storage.php?action=pullall&pwd" ); and never encountered this problem.
 

lostcalpolydude

Developer
Staff member
My kingLiberatedScript -- perhaps foolishly -- uses visit_url( "storage.php?action=pullall&pwd" ); and never encountered this problem.

Do you have thousands of items in storage when you do that? I would expect most of the point of your OCD script is to avoid having that happen, and with a small amount of items KoL responds quickly enough that there's no issue.
 

Bale

Minion
Code:
> ashq int i; foreach it in $items[] if(storage_amount(it) > 0) i++; print("Number of different items in inventory: "+i);

Number of different items in inventory: 1189

Yeah, that could be the cause of the difference. Point taken.
 

Crowther

Active member
Last few runs I've had some problems coming out of Gelatinous Noob. I haven't been able to drink a Lucky Lindy from the command line and after pulling stuff from Hangk's, mafia wrongly thinks my closet is empty. I have stuff that goes directly from Hangk's to my closet and yet "closet list" shows nothing.

I don't know for sure this is Noob related. Last run I finally figured out why so many items were being purchased when I already had them (wasteful, but pocket change for me). I was able to confirm that it happened again this run, so I wanted to post a warning. Sorry if it isn't related to this path. That's not as easy to check.
 

fronobulax

Developer
Staff member
Last few runs I've had some problems coming out of Gelatinous Noob. I haven't been able to drink a Lucky Lindy from the command line and after pulling stuff from Hangk's, mafia wrongly thinks my closet is empty. I have stuff that goes directly from Hangk's to my closet and yet "closet list" shows nothing.

I don't know for sure this is Noob related. Last run I finally figured out why so many items were being purchased when I already had them (wasteful, but pocket change for me). I was able to confirm that it happened again this run, so I wanted to post a warning. Sorry if it isn't related to this path. That's not as easy to check.

There are concerns being investigated about the status of the inventory after pulling everything from Hagnk's. The general symptom is that the inventory is not up to date and needs to be manually refreshed. It seems to be related to timing and the more stuff in Hangk's the more the problem is observed. I have personally made the problem go away by using the relay browser to pull everything and not interacting with mafia until the browser reports successful completion. Is it possible this is what you are seeing?
 

Crowther

Active member
There are concerns being investigated about the status of the inventory after pulling everything from Hagnk's. The general symptom is that the inventory is not up to date and needs to be manually refreshed. It seems to be related to timing and the more stuff in Hangk's the more the problem is observed. I have personally made the problem go away by using the relay browser to pull everything and not interacting with mafia until the browser reports successful completion. Is it possible this is what you are seeing?
Yes. That's likely it. I used the CLI to pull from Hagnk's.
 

lostcalpolydude

Developer
Staff member
I checked this out today. From using "pull all", I have a debug log with
Code:
Requesting: https://www.kingdomofloathing.com/storage.php?action=pullall
I realized that the code I added isn't running at all, since the first thing it should do is print that it's waiting 40 seconds, and that message just doesn't show up.

Some more testing leads me to find that formURLString is storage.php, and not storage.php?action=pullall as I would expect. That's enough figured out for me to fix this issue, but it really doesn't seem right...
 
Top